<template>
  <div class="margin-refund-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="refundDeposit">
        <el-radio-group v-model="ruleForm.refundDeposit">
          <el-radio :label="1">确认</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        class="two-form-item"
        label="保证金金额："
        prop="amount"
        disabled
      >
        <cy-amount-input
          v-model="ruleForm.amount"
          class="two-form-item"
          :clearable="false"
          :disabled="true"
        />
      </el-form-item>
      <el-form-item
        label="退还凭证："
        prop="desc"
        style="width: 100%;"
        class="form-required"
      >
        <cy-upload
          ref="biddingRefundFile"
          :upload-params="{
            mouldName: 'biddingRefundFile'
          }"
          :file-data="ruleForm.biddingRefundFile"
          :upload-from-orange-status="true"
          placeholder="请上传退还凭证"
        />
      </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: {
        refundDeposit: 1,
        amount: '',
        biddingRefundFile: []
      },
      rules: {
        refundDeposit: [
          { required: true, message: '请选择保证金退款', trigger: 'change' }
        ],
        amount: [
          { required: true, message: '请输入保证金金额', trigger: 'blur' }
        ]

      }
    }
  },
  created() {
    const { openAmount, type } = this.$route.query
    if (type === 'edit') {
      this.ruleForm.amount = openAmount
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        const { refundDeposit, depositAmount, fileStorageList } = JSON.parse(JSON.stringify(newV))
        this.ruleForm = {
          refundDeposit,
          amount: depositAmount,
          biddingRefundFile: fileStorageList || []
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            resolve(this.ruleForm)
          } else {
            reject()
          }
        })
      })
    },
    getParams() {
      return new Promise((resolve, reject) => {
        const biddingRefundList = this.$refs.biddingRefundFile.getFileLists
        if (!biddingRefundList.length) {
          this.$message.warning('请上传退还凭证')
          return
        }
        const { id, taskId } = this.$route.query
        const params = {
          refundDeposit: this.ruleForm.refundDeposit,
          depositAmount: this.ruleForm.amount,
          biddingBasicInfoId: id,
          taskId,
          fileIds: biddingRefundList.map(item => item.id)
        }
        resolve(params)
      })
    }
  }
}
</script>

<style  scoped>

</style>
