<template>
  <div class="margin-collection-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="depositCollection">
        <el-radio-group v-model="ruleForm.depositCollection">
          <el-radio :label="1">确认</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        class="two-form-item"
        label="保证金金额："
        prop="amount"
      >
        <cy-amount-input
          v-model="ruleForm.amount"
          placeholder="请输入保证金金额"
          :clearable="false"
          :disabled="true"
        />
      </el-form-item>
      <el-form-item label="说明" prop="comments" style="width: 100%;">
        <el-input v-model="ruleForm.comments" :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: {
        depositCollection: 1,
        comments: '',
        amount: ''
      },
      rules: {
        depositCollection: [
          { required: true, message: '请选择保证金收款', trigger: 'change' }
        ],
        comments: [
          { required: true, message: '请输入说明', trigger: 'blur' }
        ]

      }
    }
  },
  created() {
    const { openAmount, type } = this.$route.query
    if (type === 'edit') {
      this.ruleForm.amount = openAmount
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        const { depositCollection, depositAmount, comments } = JSON.parse(JSON.stringify(newV))
        this.ruleForm = {
          depositCollection,
          amount: depositAmount,
          comments
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            const { id, taskId } = this.$route.query
            const { depositCollection, comments } = this.ruleForm
            const params = {
              depositCollection,
              comments,
              biddingBasicInfoId: id,
              taskId
            }
            resolve(params)
          } else {
            reject()
          }
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
