<template>
  <div class="assess">
    <el-form ref="ruleForm" :key="key" :model="ruleForm" :rules="rules" label-position="top" label-width="120px" class="rule-form-orange">
      <el-form-item label="审批结论：" prop="approvalConclusion">
        <el-radio-group v-model="ruleForm.approvalConclusion" :disabled="disabled" @change="conclusionChange">
          <el-radio label="pass">通过</el-radio>
          <el-radio label="back">退回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="审批意见："
        style="width: 100%;"
        class="textarea-content"
        prop="approvalComment"
        :rules="[
          { required: ruleForm.approvalConclusion === 'back' || ruleForm.approvalConclusion === 'veto', message: '请输入审批意见', trigger: 'blur' }
        ]"
      >
        <el-input v-model="ruleForm.approvalComment" :disabled="disabled" type="textarea" style="width: 100%;" rows="3" clearable></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    detailsInfo: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ruleForm: {
        approvalConclusion: '',
        approvalComment: ''
      },
      rules: {
        approvalConclusion: [
          { required: true, message: '请选择审批结论', trigger: 'change' }
        ]
      },
      key: 0
    }
  },
  watch: {
    detailsInfo: {
      handler(newV) {
        if (newV && Object.keys(newV).length) {
          const { approvalConclusion, approvalComment } = JSON.parse(JSON.stringify(newV))
          this.ruleForm.approvalConclusion = approvalConclusion
          this.ruleForm.approvalComment = approvalComment
          this.key += 1
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    conclusionChange(val) {
      this.$emit('conclusionChange', val)
    },
    getSubmit(type) {
      return new Promise((resolve, reject) => {
        const { approvalConclusion, approvalComment } = this.ruleForm
        const params = {
          approvalConclusion,
          approvalComment
        }
        if (type === 'temp') {
          resolve(params)
        } else {
          this.$refs.ruleForm.validate(valid => {
            if (valid) {
              resolve(params)
            } else {
              reject()
            }
          })
        }
      })
    }
  }

}
</script>

<style lang="scss" scoped>
.assess {

}
</style>
