<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="fileStorage"
          :file-data="detailInfo.fileStorages"
          :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="isView">
          <el-radio label="pass">通过</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="approvalComment"
        :rules="[
          { required: ruleForm.approvalConclusion === 'back', message: '请输入审批意见', trigger: 'blur' }
        ]"
      >
        <el-input v-model="ruleForm.approvalComment" type="textarea" style="width: 100%;" rows="3" clearable :disabled="isView"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      key: 0,
      ruleForm: {
        approvalConclusion: 'pass',
        approvalComment: ''
      },
      rules: {
        approvalConclusion: [
          { required: true, message: '请选择审批结论', trigger: 'change' }
        ]
      },
      detailInfo: {}
    }
  },
  props: ["info", "isView"],
  mounted() {
    if(!this.isView) {
      this.getDetail()
    }
  },
  methods: {
    getDetail() {
      request({
        url: this.$route.params.isChange ? '/purchContract/change/final/approval' : '/purchContract/final/approval/add',
        params: this.$route.params.isChange ? { businessKey: this.$route.params.infoId } : { id: this.$route.params.infoId },
        method: 'get'
      }).then(({ data }) => {
        this.detailInfo = { ...data }
        this.detailInfo.fileStorages = data.fileStorageList || filestorages || []
      })
    },
    validate() {
      return new Promise((res, rej) => {
        this.$refs.ruleForm.validate(flag => {
          if(flag) {
            res(this.ruleForm)
          } else {
            rej()
          }
        })
      })
    }
  },
  watch: {
    'info.mathId': {
      handler(newV) {
        if (newV) {
          Object.keys(this.ruleForm).forEach(key => {
            if(this.info[key]) {
              this.ruleForm[key] = this.info[key] || ''
            }
          })
          this.detailInfo.fileStorages = this.info.fileStorageList || filestorages || []
        }
      },
      immediate: true
    }
  }
}
</script>

<style  scoped>

</style>
