<template>
  <div class="audit-conclusion">
    <cy-info-title>审核结论</cy-info-title>
    <el-form ref="ruleForm" :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="审核意见"
        prop="approvalComment"
        :rules="[
          { required: ruleForm.approvalConclusion === 'back', message: '请输入审批意见', trigger: 'blur' }
        ]"
        style="width: 100%;"
      >
        <el-input v-model="ruleForm.approvalComment" type="textarea" :rows="3" :disabled="disabled" />
      </el-form-item>
    </el-form>
  </div>
</template>

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

<style lang="scss" scoped>

</style>
