<template>
  <div class="contract-approval-content">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="top" class="rule-form-orange">
      <cy-info-title>电子签合同</cy-info-title>
      <el-form-item label="合同文件" style="width: 100%">
        <cy-upload
          ref="fileStorage"
          :upload-params="{}"
          :file-data="detailsInfo.fileStorageList"
          :upload-from-orange-status="true"
          disabled
          placeholder="请上传附件"
          style="width: 100%"
        />
        <div class="download-box" @click="downloadFile">
          <i class="iconfont icon-xiazai"></i>
        </div>

      </el-form-item>
      <cy-info-title>审批结论</cy-info-title>
      <el-form-item label="审批结论" prop="conclusion">
        <el-radio-group v-model="ruleForm.conclusion" :disabled="disabled">
          <el-radio label="pass">通过</el-radio>
          <el-radio label="back">退回</el-radio>
          <el-radio label="vite">否决</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="审批意见"
        :rules="[
          { required: ruleForm.conclusion === 'back' || ruleForm.conclusion === 'veto', message: '请输入审批意见', trigger: 'blur' }
        ]"
        prop="suggestion"
        style="width: 100%"
      >
        <el-input v-model="ruleForm.suggestion" :disabled="disabled" placeholder="请输入审批意见" clearable />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { contractApprovalDownload } from '@/api/financingManage'
import { exportFile } from '@/utils'
export default {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    detailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        conclusion: '',
        suggestion: ''
      },
      rules: {
        conclusion: [{ required: true, message: '请选择签署结论', trigger: 'change' }]
      }
    }
  },
  watch: {
    detailsInfo: {
      handler(newV) {
        if (newV === undefined) return
        const { conclusion, suggestion } = newV
        this.ruleForm = {
          conclusion,
          suggestion
        }
        this.$refs.ruleForm.resetFields()
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    downloadFile() {
      const { contractInfoId } = this.detailsInfo
      contractApprovalDownload({ contractInfoId }).then((data) => {
        exportFile(data)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.download-box {
  position: absolute;
  top: 20%;
  right: 30px;
  z-index: 10;
  width: 30px;
  text-align: center;
}
</style>
