<template>
  <div class="template-review-content">
    <el-form ref="ruleForm" :key="key" :model="ruleForm" :rules="rules" label-width="150px" label-position="top" class="rule-form-orange">
      <cy-info-title>审批结论</cy-info-title>
      <el-form-item label="审批结论：" prop="conclusion">
        <el-radio-group v-model="ruleForm.conclusion" :disabled="disabled">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="0">驳回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="审批意见："
        style="width: 100%;"
        class="textarea-content"
        prop="comments"
        :rules="[
          { required: ruleForm.conclusion === 0, message: '请输入审批意见', trigger: 'blur' }
        ]"
      >
        <el-input
          v-model="ruleForm.comments"
          type="textarea"
          style="width: 100%;"
          rows="3"
          clearable
          :disabled="disabled"
        >
        </el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

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

<style  scoped>

</style>
