<template>
  <div class="foundation-info">
    <cy-info-title>基础信息</cy-info-title>
    <el-form
      ref="ruleForm"
      :key="key"
      :model="ruleForm"
      :rules="rules"
      class="rule-form-orange"
      label-width="150px"
      label-position="top"
    >
      <el-form-item label="业务编号：" prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.businessNo"
          placeholder="请输入业务编号"
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>
      <el-form-item label="保理合同编号：" prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.contractNo"
          placeholder="请输入保理合同编号"
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>
      <el-form-item label="保理申请人：" prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.applicantName"
          placeholder="请输入保理申请人"
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码：" prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.applicantSocialCreditCode"
          placeholder="请输入统一社会信用代码"
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>
      <el-form-item label="额度支用批次：" prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.quotaDisburseBatch"
          placeholder="请输入额度支用批次"
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>
      <el-form-item label="业务经理 " prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.projectManager"
          placeholder="请输入业务经理 "
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>
      <el-form-item label="还款账号" prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.productType"
          placeholder="请输入还款账号"
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>
      <el-form-item label="还款账户名" prop="enterpriseCustomerInfoId">
        <el-input
          v-model="ruleForm.projectManager"
          placeholder="请输入还款账户名"
          :disabled="disabled || isDisabled"
          clearable
        />
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    foundationInfo: {
      type: Object,
      default: () => {}
    },
    // type:  planChange: 计划变更
    type: {
      type: String,
      default: ''
    },
    // 变更类型数据
    changeList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      ruleForm: {},
      rules: {},
      key: 0
    }
  },
  computed: {
    ...mapGetters(['constant']),
    isDisabled() {
      return this.type === 'planChange'
    }
  },
  watch: {
    foundationInfo: {
      handler(newV) {
        if (Object.keys(newV).length) {
          this.ruleForm = JSON.parse(JSON.stringify(newV))
          this.ruleForm = {
            // changeType: '',
            // acceleration: false,
            // changeReason: '',
            ...this.ruleForm
          }
          this.key += 1
        }
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.$store.dispatch('getConstant', ['factoringProducts'])
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            const fileStorage = this.$refs.fileStorage.getFileLists
            if (this.changeTypeRequired && !fileStorage.length) {
              this.$message.warning('请上传附件')
              reject()
              return
            }
            const { id, changeType, changeReason, acceleration } = this.ruleForm
            const params = {
              basic: {
                id
              },
              changeType: {
                id: changeType
              },
              changeReason,
              acceleration,
              fileStorageIdList: fileStorage.map(item => item.id)
            }
            resolve(params)
          } else {
            reject()
            return false
          }
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
