<template>
  <div class="guarantee-confirm-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="tenderMethod">
        <el-radio-group v-model="ruleForm.tenderMethod" :disabled="disabled">
          <el-radio :label="0">线下装订</el-radio>
          <el-radio :label="1">线上上传</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="投标保证方式" prop="bidGuaranteeMethod">
        <el-radio-group v-model="ruleForm.bidGuaranteeMethod" :disabled="disabled">
          <el-radio :label="0">保证金</el-radio>
          <el-radio :label="1">保函</el-radio>
          <el-radio :label="2">其他</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        v-if="ruleForm.bidGuaranteeMethod === 1"
        label="保函文件："
        prop="desc"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="biddingGuaranteeLetterFile"
          :upload-params="{
            mouldName: 'biddingGuaranteeLetterFile'
          }"
          :file-data="ruleForm.biddingGuaranteeLetterFile"
          :upload-from-orange-status="true"
          placeholder="请上传保函文件"
          :disabled="disabled"
        />
      </el-form-item>
      <el-form-item
        v-if="ruleForm.bidGuaranteeMethod === 0"
        label="保证金金额："
        prop="depositAmount"
        style="width: 100%;"
        :rules="[
          { required: ruleForm.bidGuaranteeMethod === 0, message: '请输入保证金金额', trigger: 'blur' }
        ]"
      >
        <cy-amount-input v-model="ruleForm.depositAmount" :disabled="disabled" />
      </el-form-item>
      <el-form-item
        v-if="ruleForm.bidGuaranteeMethod === 0"
        label="支付凭证："
        prop="desc"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="biddingPaymentVoucherFile"
          :upload-params="{
            mouldName: 'biddingPaymentVoucherFile'
          }"
          :file-data="ruleForm.biddingPaymentVoucherFile"
          :upload-from-orange-status="true"
          placeholder="请上传支付凭证"
          :disabled="disabled"
        />
      </el-form-item>
      <!-- <el-form-item
        label="投标说明："
        prop="desc"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="bidingDescriptionFile"
          :upload-params="{
            mouldName: 'bidingDescriptionFile'
          }"
          :file-data="ruleForm.bidingDescriptionFile"
          :upload-from-orange-status="true"
          placeholder="请上传投标说明"
          :disabled="disabled"
        />
      </el-form-item> -->
    </el-form>
  </div>
</template>

<script>
module.exports = {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    deatailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      key: 0,
      uploadParams: {},
      ruleForm: {
        tenderMethod: '',
        bidGuaranteeMethod: '',
        biddingGuaranteeLetterFile: [],
        biddingPaymentVoucherFile: []
        // bidingDescriptionFile: []
      },
      rules: {
        tenderMethod: [
          { required: true, message: '请选择投标方式', trigger: 'change' }
        ],
        bidGuaranteeMethod: [
          { required: true, message: '请选择投标保证方式', trigger: 'change' }
        ]

      }
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        const { tenderMethod, bidGuaranteeMethod, depositAmount, guaranteeLetterFiles, paymentVoucherFiles } = JSON.parse(JSON.stringify(newV))
        this.ruleForm = {
          tenderMethod,
          bidGuaranteeMethod,
          depositAmount,
          biddingGuaranteeLetterFile: guaranteeLetterFiles || [],
          biddingPaymentVoucherFile: paymentVoucherFiles || []
          // bidingDescriptionFile: bidDescriptionFiles || []
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            // const bidingDescriptionList = this.$refs.bidingDescriptionFile.getFileLists
            // if (!bidingDescriptionList.length) {
            //   this.$message.warning('请上传招标说明')
            //   return
            // }
            const { id, taskId } = this.$route.query
            const params = {
              tenderMethod: this.ruleForm.tenderMethod,
              bidGuaranteeMethod: this.ruleForm.bidGuaranteeMethod,
              biddingBasicInfoId: id,
              taskId
              // bidDescriptionFileIds: bidingDescriptionList.map(item => item.id)
            }
            if (this.ruleForm.bidGuaranteeMethod === 0) {
              const biddingPaymentVoucherList = this.$refs.biddingPaymentVoucherFile.getFileLists
              if (!biddingPaymentVoucherList.length) {
                this.$message.warning('请上传支付凭证')
                return
              }
              params.depositAmount = this.ruleForm.depositAmount
              params.paymentVoucherFileIds = biddingPaymentVoucherList.map(item => item.id)
            }
            if (this.ruleForm.bidGuaranteeMethod === 1) {
              const biddingGuaranteeLetterList = this.$refs.biddingGuaranteeLetterFile.getFileLists
              if (!biddingGuaranteeLetterList.length) {
                this.$message.warning('请上传保函文件')
                return
              }
              params.guaranteeLetterFileIds = biddingGuaranteeLetterList.map(item => item.id)
            }
            resolve(params)
          } else {
            reject()
          }
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
