<template>
  <div class="cooperation-box">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >
      <el-form-item label="本次拟合作金额（万元）" prop="cooperationAmount">
        <cy-amount-input
          v-model="ruleForm.cooperationAmount"
          placeholder="请输入本次拟合作金额（万元）"
          unit-name="CNY"
          is-unit
          :disabled="disabled"
        />
      </el-form-item>
      <el-form-item label="月供货峰值（万元）" prop="peakValue">
        <cy-amount-input
          v-model="ruleForm.peakValue"
          placeholder="请输入月供货峰值（万元）"
          unit-name="CNY"
          is-unit
          :disabled="disabled"
        />
      </el-form-item>
      <el-form-item label="预估账期(月)" prop="estimatedAccountingPeriod">
        <cy-number-input
          v-model="ruleForm.estimatedAccountingPeriod"
          placeholder="请输入预估账期（月）"
          :disabled="disabled"
        />
      </el-form-item>
      <el-form-item label="本次用款高峰值（万元）" prop="highPeakUsage">
        <cy-amount-input
          v-model="ruleForm.highPeakUsage"
          placeholder="请输入本次用款高峰值（万元）"
          unit-name="CNY"
          is-unit
          :disabled="disabled"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    cooperation: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ruleForm: {
        cooperationAmount: '',
        peakValue: '',
        estimatedAccountingPeriod: '',
        highPeakUsage: ''
      },
      rules: {
        cooperationAmount: [
          { required: true, message: '请输入本次拟合作金额', trigger: 'blur' }
        ],
        peakValue: [
          { required: true, message: '请输入月供货峰值', trigger: 'blur' }
        ],
        estimatedAccountingPeriod: [
          { required: true, message: '请输入预估账期', trigger: 'blur' }
        ],
        highPeakUsage: [
          { required: true, message: '请输入本次用款高峰值', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    cooperation: {
      handler(newV) {
        if (newV && Object.keys(newV)) {
          this.ruleForm = {
            ...newV
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    // 提交参数
    passData(type) {
      return new Promise((resolve, reject) => {
        if (type === 'submit' || type === 'assess') {
          this.$refs.ruleFormRef.validate(valid => {
            if (valid) {
              return resolve(this.ruleForm)
            } else {
              reject()
              return false
            }
          })
        } else {
          resolve(this.ruleForm)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.cooperation-box {
padding: 10px 15px;
}
</style>
