<template>
  <div class="sign-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="desc"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="files"
          :upload-params="{}"
          :file-data="ruleForm.files"
          :upload-from-orange-status="true"
          placeholder="请上传已签文件"
          disabled
        />
      </el-form-item>
      <cy-info-title>审批结论</cy-info-title>
      <el-form-item label="审批结论：" prop="approvalConclusion">
        <el-radio-group v-model="ruleForm.approvalConclusion" :disabled="disabled">
          <el-radio label="pass">通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="审批意见："
        style="width: 100%;"
        class="textarea-content"
        prop="approvalComments"
      >
        <el-input v-model="ruleForm.approvalComments" type="textarea" style="width: 100%;" rows="3" clearable :disabled="disabled"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    deatailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      key: 0,
      ruleForm: {
        approvalConclusion: 'pass',
        approvalComments: '',
        files: []
      },
      rules: {
        approvalConclusion: [
          { required: true, message: '请选择审批结论', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        if (this.deatailsInfo && Object.keys(newV).length) {
          const { approvalConclusion, approvalComments, files } = JSON.parse(JSON.stringify(newV))
          this.ruleForm.approvalConclusion = approvalConclusion || 'pass'
          this.ruleForm.approvalComments = approvalComments
          this.ruleForm.files = files || []
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            const { taskId, id, taskName } = this.$route.query
            const params = {
              approvalConclusion: this.ruleForm.approvalConclusion,
              approvalComments: this.ruleForm.approvalComments,
              taskId
            }
            if (taskName === '签署审核') {
              params.cSalesContractManagementId = id
            }
            if (taskName === '变更签署审核') {
              params.businessKey = id
            }
            resolve(params)
          } else {
            reject()
          }
        })
      })
    }
  }
}
</script>

<style  scoped>

</style>
