<template>
  <div class="win-bidding-content">
    <div class="info-title">投标信息</div>
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px" label-position="left" class="rule-form">
      <el-form-item label="保证金金额：" prop="depositAmount" style="width: 100%">
        <cy-amount-input
          v-model="ruleForm.depositAmount"
          placeholder="请输入保证金金额"
          :disabled="disabled"
          :is-unit="true"
          unit-name="元"
        >
        </cy-amount-input>
      </el-form-item>
      <div class="form-upload-box">
        <div class="form-upload-name form-required" style="min-width: 150px;">
          支付凭证：
        </div>
        <cy-upload
          :disabled="disabled"
          ref="paymentVoucher"
          :upload-params="uploadParams"
          :file-data="ruleForm.paymentVoucher"
          :upload-from-status="true"
          placeholder="请上传支付投标保证金银行回单"
        >
        </cy-upload>
      </div>
      <div class="form-upload-box">
        <div class="form-upload-name form-required" style="min-width: 150px;">
          投标凭证：
        </div>
        <cy-upload
          :disabled="disabled"
          ref="tenderDocuments"
          :upload-params="uploadParams"
          :file-data="ruleForm.tenderDocuments"
          :upload-from-status="true"
          placeholder="请上传已完成投标的截图或照片"
        >
        </cy-upload>
      </div>
      <div class="info-title">中标信息</div>
      <el-form-item label=" 是否中标：" prop="winTheBidding" style="width: 100%">
        <el-radio-group v-model="ruleForm.winTheBidding" :disabled="disabled" class="form-radio-border">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <div class="form-upload-box" v-if="ruleForm.winTheBidding">
        <div class="form-upload-name form-required" style="min-width: 150px;">
          中标通知书：
        </div>
        <cy-upload
          :disabled="disabled"
          ref="bidWinningNotice"
          :upload-params="uploadParams"
          :file-data="ruleForm.bidWinningNotice"
          :upload-from-status="true"
          placeholder="请上传中标通知书"
        >
        </cy-upload>
      </div>
    </el-form>
  </div>
</template>

<script>
module.exports = {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    deatailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleForm: {
        depositAmount: '',
        winTheBidding: '',
        paymentVoucher: [],
        tenderDocuments: [],
        bidWinningNotice: [],
      },
      rules: {
        depositAmount: [
          { required: true, message: '请输入保证金金额', trigger: 'blur' }
        ],
        winTheBidding: [
          { required: true, message: '请选择是否中标', trigger: 'change' }
        ]
      },
      uploadParams: {
        mouldName: 'BusinessManagement',
      }
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        if(newV) {
          const { depositAmount, winTheBidding, paymentVoucher, tenderDocuments, bidWinningNotice} = JSON.parse(JSON.stringify(newV))
          this.ruleForm = {
            depositAmount,
            winTheBidding,
            paymentVoucher,
            tenderDocuments,
            bidWinningNotice
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getSubmit() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if(valid) {
            const paymentVoucher = this.$refs.paymentVoucher.getFileLists
            const tenderDocuments = this.$refs.tenderDocuments.getFileLists
            if(!paymentVoucher.length) {
              this.$message.warning('请上传支付投标保证金银行回单')
              return
            }
            if(!tenderDocuments.length) {
              this.$message.warning('请上传已完成投标的截图或照片')
              return
            }
            let params = {
              ...this.ruleForm,
              paymentVoucher: paymentVoucher.map(item => { return { id: item.id}}),
              tenderDocuments: tenderDocuments.map(item => { return { id: item.id}})
            }
            if(this.ruleForm.winTheBidding) {
              const bidWinningNotice = this.$refs.bidWinningNotice.getFileLists
              if(!bidWinningNotice.length) {
                this.$message.warning('请上传中标通知书')
                return
              }
              params.bidWinningNotice = bidWinningNotice.map(item => { return { id: item.id}})
            }
            resolve(params)
          }else {
            reject()
          }
        })
      })
    },
  },
}
</script>

<style scoped>

</style>
