<template>
  <div class="examine-content">
    <el-form ref="ruleForm" :model="ruleForm" :key="key" :rules="rules" label-width="150px" label-position="left" class="rule-form">
      <div class="info-title">审批结论</div>
      <el-form-item label="审批结论：" prop="approvalConclusion">
        <el-radio-group v-model="ruleForm.approvalConclusion" :disabled="disabled">
          <el-radio label="pass">通过</el-radio>
          <el-radio label="veto">拒绝</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="approvalComments"
        :rules="[
            { required: ruleForm.approvalConclusion === 'back' ||  ruleForm.approvalConclusion === 'veto', message: '请输入审批意见', trigger: 'blur' }
        ]"
      >
        <el-input type="textarea" :disabled="disabled" v-model="ruleForm.approvalComments" style="width: 100%;" rows="3" clearable></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
module.exports = {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    deatailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        approvalConclusion: 'pass',
        approvalComments: ''
      },
      key: 0,
      rules: {
        approvalConclusion: [
          { required: true, message: '请选择审批结论', trigger: 'change' },
        ]
      }
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        const { approvalConclusion, approvalComments } = JSON.parse(JSON.stringify(newV))
        this.ruleForm.approvalConclusion = approvalConclusion
        this.ruleForm.approvalComments = approvalComments
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getSubmit() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if(valid) {
            resolve(this.ruleForm)
          }else {
            reject()
          }
        })
      })
    }
  },
}
</script>

<style scoped>

</style>
