<template>
  <div class="acceptance-conclusion">
    <cy-info-title>审批结论</cy-info-title>
    <el-form ref="ruleForm" :key="key" :model="ruleForm" :rules="rules" label-width="150px" label-position="top" class="rule-form-orange">
      <el-form-item label="审批结论：" prop="approvalConclusion">
        <el-radio-group v-model="ruleForm.approvalConclusion">
          <el-radio label="pass" :disabled="disabled">通过</el-radio>
          <el-radio v-show="show || type === 'businessReview'" label="back" :disabled="disabled">退回</el-radio>
          <el-radio v-if="type !== 'businessReview'" label="veto" :disabled="disabled">否决</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" type="textarea" style="width: 100%;" rows="3" clearable :disabled="disabled"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {
  },
  props: {
    disabled: {
      type: Boolean
    },
    signConform: {
      type: Object,
      default: () => {}
    },
    deatailsInfo: {
      type: Object,
      default: () => {}
    },
    type: {
      type: String,
      default: '' // 'businessReview' 业务审核
    }
  },
  data() {
    return {
      key: 0,
      show: true,
      ruleForm: {
        approvalConclusion: '',
        approvalComment: ''
      },
      rules: {
        approvalConclusion: [
          { required: true, message: '请选择审批结论', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        if (newV && Object.keys(newV).length) {
          const { approvalConclusion, approvalComment } = JSON.parse(JSON.stringify(newV))
          this.ruleForm.approvalConclusion = approvalConclusion
          this.ruleForm.approvalComment = approvalComment
        }
      },
      immediate: true,
      deep: true
    },
    signConform: {
      handler(newV) {
        if (newV && Object.keys(newV).length) {
          const { show } = JSON.parse(JSON.stringify(newV))
          this.show = show
        }
      },
      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 lang="scss"  scoped>
.acceptance-conclusion {
    .el-form {
      padding: 10px 20px;
    }
    }
</style>
