<template>
    <el-form ref="formRef" :model="form" :rules="rules" :disabled="disabled" label-width="110px">
        <div class="dialog-title">{{ titleMap[handler] }}</div>
        <el-row>
            <template v-if="handler == 'agree'">
                <el-col :span="12">
                    <el-form-item label="是否入库" prop="isInWh">
                        <el-radio-group v-model="form.isInWh" @change="form.inWhType = null">
                            <el-radio v-for="(label, key) in whetherDic" :key="key" :label="label" :value="parseInt(key)"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="分值（0-10）" :prop="!isMaster && 'score'">
                        <el-input-number v-model="form.score" :min="0" :max="10" :step="0.1" :precision="2" :controls="false" placeholder="请输入分值"></el-input-number>
                    </el-form-item>
                </el-col>
                <el-col v-if="form.isInWh == 1" :span="12">
                    <el-form-item label="入库类型" prop="inWhType">
                        <el-select v-model="form.inWhType" placeholder="请选择入库类型">
                            <el-option v-for="item in storageTypeDic" :key="item" :label="item" :value="item"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </template>

            <el-col v-else :span="24">
                <el-form-item label="意见" prop="remark">
                    <el-input v-model="form.remark" type="textarea" :rows="4" placeholder="请输入意见"></el-input>
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>
</template>

<script>
import API from "@/api/policy/share";
import { storageTypeDic, whetherDic } from "./main";

export default {
    props: {
        isMaster: { type: Boolean, default: false },
        handler: { type: String, default: "agree" },
        disabled: { type: Boolean, default: true },
        rowData: { type: Object, default: () => {} }
    },

    data() {
        return {
            storageTypeDic, whetherDic,
            titleMap: {
                agree: "考核评分",
                refuse: "退回意见"
            },

            form: {
                score: null,
                isInWh: 0,
                inWhType: null
            },

            rules: {
                score: [{ required: true, message: "请输入分值" }],
                isInWh: [{ required: true }],
                inWhType: [{ required: true, message: "请选择入库类型" }],
                // remark: [{ required: true, message: "请输入退回意见" }]
            },
        }
    },

    watch: {
        rowData: {
            deep: true,
            handler(value) {
                if (value.id) {
                    this.form = Object.assign({}, this.rowData);
                }
            }
        }
    },

    mounted() {
        this.form = Object.assign({}, this.rowData);
    },

    methods: {
        submit() {
            this.$refs.formRef.validate(valid => {
                if (valid) {
                    API[this.handler](this.form).then(() => {
                        ElMessage.success("操作成功");
                        this.visible = false;
                        this.$emit("success");
                    });
                } else {
                    return false;
                }
            });
        }
    }
}
</script>

<style lang="scss" scoped>
.dialog-title {
  margin-bottom: 15px;
  font-size: 15px;
  font-weight: 600;
  color: var(--el-text-color-primary);
}

.el-input-number {
  width: 100%;

  :deep(.el-input) .el-input__wrapper {
    padding: 1px 11px;

    .el-input__inner {
      text-align: unset;
    }
  }
}
</style>