<template>
  <div class="bond-content">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="150px" label-position="left" class="rule-form">
      <div class="info-title">退款确认</div>
      <el-form-item label="保证金退还：" prop="refundDeposit" style="width: 100%">
        <el-radio-group v-model="ruleForm.refundDeposit" :disabled="disabled" class="form-radio-border">
          <el-radio :label="1">确认</el-radio>
        </el-radio-group>
      </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="returnVoucher"
          :upload-params="uploadParams"
          :file-data="ruleForm.returnVoucher"
          :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: {
        refundDeposit: 1,
        returnVoucher: []
      },
      rules: {
        refundDeposit: [
          { required: true, message: '请选择保证金退还', trigger: 'change' },
        ]
      },
      uploadParams: {
        mouldName: 'BusinessManagement',
      }
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        if(newV) {
          const { refundDeposit, returnVoucher } = JSON.parse(JSON.stringify(newV))
          this.ruleForm.refundDeposit = refundDeposit
          this.ruleForm.returnVoucher = returnVoucher
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getSubmit() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if(valid) {
            const returnVoucher = this.$refs.returnVoucher.getFileLists
            if(!returnVoucher.length) {
              this.$message.warning('请上传退还保证金银行回单')
              return
            }
            const params = {
             ...this.ruleForm,
             returnVoucher: returnVoucher.map(item => { return { id: item.id }})
            }
            resolve(params)
          }else {
            reject()
          }
        })
      })
    }
  },
}
</script>

<style scoped>

</style>
