// 付款确认书信息
<template>
  <dym-form :formValue.sync="form"
            :componentList="componentList"
            :editModel="'E'"
            @selectChanged="selectChanged">
  </dym-form>
</template>
<script>
import componentsApi from '@/api/componentsApi'
import { dymForm, SelectProductName, SelectCoreEnterpriseCascade, SelectFinancialInstitutionsCascade, SelectPrimitiveRightsHolderCascade, SelectAssetsService, SelectPeriodsCascade, SelectAssetsServiceCascade } from 'newepoch-components'
export default {
  components: {
    dymForm
  },
  props: {
    assetCodeForm: {
      type: Object,
      default () {
        return {}
      }
    },
    roleAuthority: {
      type: Array
    },
    initFlag: {
      type: Boolean,
      default () {
        return false
      }
    }
  },
  data () {
    const { factoringBusinessInfo } = this.$i18n.messages[this.$i18n.locale]
    return {
      componentList: [
        // 产品名称
        {
          label: factoringBusinessInfo.product_name,
          value: 'projectId',
          disabled: false,
          componentName: SelectProductName,
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          prop: 'projectId',
          name: 'project',
          showFlag: true
        },
        // 核心企业
        {
          label: factoringBusinessInfo.core_enterprise,
          value: 'coreEnterpriseId',
          disabled: false,
          componentName: SelectCoreEnterpriseCascade,
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'coreEnterpriseId',
          queryName: 'projectId',
          queryValue: 'projectId',
          name: 'coreEnterprise',
          showFlag: true
        },
        // 计划管理人/再保理银行
        {
          label: factoringBusinessInfo.planning_manager,
          value: 'planOrBankId',
          disabled: false,
          componentName: SelectFinancialInstitutionsCascade,
          cols: [8, 8, 8, 8],
          labelWidth: '170px',
          prop: 'planOrBankId',
          queryName: 'projectId',
          queryValue: 'projectId',
          name: 'planOrBank',
          showFlag: true
        },
        // 期数
        {
          label: factoringBusinessInfo.periods,
          value: 'specialPlanId',
          disabled: false,
          componentName: SelectPeriodsCascade,
          placeholder: '请选择数据',
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          queryName: 'projectId',
          queryValue: 'projectId',
          prop: 'specialPlanId',
          name: 'specialPlanPeriods',
          showFlag: true
        },
        // 原始权益人
        {
          label: factoringBusinessInfo.initial_equity_owner,
          value: 'initialOwnersId',
          disabled: false,
          componentName: SelectPrimitiveRightsHolderCascade,
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'initialOwnersId',
          queryName: 'projectId',
          queryValue: 'projectId',
          name: 'initialOwners',
          showFlag: true
        },
        // 资产服务机构
        {
          label: factoringBusinessInfo.assest_service,
          value: 'assetServiceId',
          disabled: false,
          componentName: SelectAssetsServiceCascade,
          cols: [8, 8, 8, 8],
          labelWidth: '170px',
          queryName: 'projectId',
          queryValue: 'projectId',
          prop: 'assetServiceId',
          name: 'assetService',
          showFlag: true
        },
        // 付款确认书编号
        {
          label: factoringBusinessInfo.pay_code,
          value: 'assetCode',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          prop: 'assetCode',
          showFlag: true
        },
        // 供应商名称
        {
          label: factoringBusinessInfo.creditor,
          value: 'creditor',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'creditor',
          showFlag: true
        },
        // 项目公司名称
        {
          label: factoringBusinessInfo.project_company,
          value: 'debtor',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '170px',
          prop: 'debtor',
          showFlag: true
        },
        // 收款人名称
        {
          label: factoringBusinessInfo.payee_name,
          value: 'receiverName',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          prop: 'receiverName',
          showFlag: true
        },
        // 收款人开户行
        {
          label: factoringBusinessInfo.payee_bank,
          value: 'receiverBank',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'receiverBank',
          showFlag: true
        },
        // 收款人账号
        {
          label: factoringBusinessInfo.payee_account,
          value: 'receiverBankAccount',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '170px',
          prop: 'receiverBankAccount',
          showFlag: true
        },
        // 账款到期日
        {
          label: factoringBusinessInfo.amount_due_date,
          value: 'dueDate',
          disabled: false,
          componentName: 'el-date-picker',
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          prop: 'dueDate',
          showFlag: true
        },
        // 应收账款金额
        {
          label: factoringBusinessInfo.account_receivable,
          value: 'factoringMoney',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'factoringMoney',
          showFlag: true
        },
        // 商务合同名称
        {
          label: factoringBusinessInfo.business_contract_name,
          value: 'bussContractName',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '170px',
          prop: 'bussContractName',
          showFlag: true
        },
        // 商务合同编号
        {
          label: factoringBusinessInfo.business_contract_number,
          value: 'bussContractCode',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          prop: 'bussContractCode',
          showFlag: true
        },
        // 区域
        {
          label: factoringBusinessInfo.area,
          value: 'coreAreaName',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'coreArea',
          showFlag: true
        },
        // 区域编号
        {
          label: factoringBusinessInfo.area_number,
          value: 'regionCode',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '170px',
          prop: 'regionCode',
          showFlag: true
        },
        // 区域专员
        {
          label: factoringBusinessInfo.regional_commissioner,
          value: 'coreAreaAttacheName',
          disabled: true,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          prop: 'coreAreaAttacheName',
          showFlag: true
        },
        // 保理专员
        {
          label: factoringBusinessInfo.factoring_commissioner,
          value: 'customerAccountName',
          disabled: true,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'customerAccountName',
          showFlag: true
        },
        // 基础合同名称
        {
          label: factoringBusinessInfo.basic_contract_name,
          value: 'basicContractName',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '170px',
          prop: 'basicContractName',
          showFlag: true
        },
        // 基础合同编号
        {
          label: factoringBusinessInfo.basic_contract_num,
          value: 'basicContractCode',
          disabled: false,
          componentName: 'el-input',
          cols: [8, 8, 8, 8],
          labelWidth: '125px',
          prop: 'basicContractCode',
          showFlag: true
        },
        // 保理申请日期
        {
          label: factoringBusinessInfo.factoring_application_date,
          value: 'factoringApplyTime',
          disabled: false,
          componentName: 'el-date-picker',
          cols: [8, 8, 8, 8],
          labelWidth: '110px',
          prop: 'factoringApplyTime',
          showFlag: true
        }
      ],
      form: {},
      clearFlag: false
    }
  },
  methods: {
    // 根据ID获取产品类别
    getTypeById () {
      componentsApi.productenterprise.getclassify({ projectId: this.form.projectId }).then(res => {
        let disabled = res.data ? res.data.productType : '2'
        this.$set(this.componentList[3], 'placeholder', disabled !== '1' ? '' : '请选择数据')
        this.$set(this.componentList[3], 'disabled', disabled !== '1')
        this.$emit('changeRules', 'specialPlanId', [{ required: disabled === '1', trigger: 'change', message: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].factoringBusinessInfo.periods }])
        this.form.productType = res.data.productType
      })
    },
    selectChanged (val) {
      if (!this.UtilJs.isEmpty(val.projectInfo)) {
        this.getTypeById()
        this.form.projectName = val.projectInfo.projectName
      }
      if (!this.UtilJs.isEmpty(val.coreEnterpriseInfo)) {
        this.form.coreEnterpriseName = val.coreEnterpriseInfo.enterpriseName
      }
      if (!this.UtilJs.isEmpty(val.planOrBankInfo)) {
        this.form.planOrBankName = val.planOrBankInfo.enterpriseName
      }
      if (!this.UtilJs.isEmpty(val.initialOwnersInfo)) {
        this.form.initialOwnersName = val.initialOwnersInfo.enterpriseName
      }
      if (!this.UtilJs.isEmpty(val.assetServiceInfo)) {
        this.form.assetServiceName = val.assetServiceInfo.enterpriseName
      }
      if (!this.UtilJs.isEmpty(val.specialPlanPeriodsInfo)) {
        this.form.specialPlanPeriods = val.specialPlanPeriodsInfo.specialPlanPeriods
      }
    }
  },
  watch: {
    // 初始化数据
    initFlag (val) {
      if (val) {
        this.componentList.forEach((item, index) => {
          this.roleAuthority.forEach(value => {
            if (value.columnCode === item.prop) {
              if (value.roleAuthority === 2) {
                this.$set(this.componentList[index], 'disabled', false)
              } else if (value.roleAuthority === 1) {
                this.$set(this.componentList[index], 'disabled', true)
              } else if (value.roleAuthority === 0) {
                this.$set(this.componentList[index], 'showFlag', false)
              }
            }
          })
        })
        this.form = this.assetCodeForm
        if (!this.UtilJs.isEmpty(this.assetCodeForm.productType)) {
          this.$set(this.componentList[3], 'placeholder', this.assetCodeForm.productType + '' !== '1' ? '' : '请选择数据')
          this.$set(this.componentList[3], 'disabled', this.assetCodeForm.productType + '' !== '1')
          this.$emit('changeRules', 'specialPlanId', [{ required: this.assetCodeForm.productType + '' === '1', trigger: 'change', message: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].factoringBusinessInfo.periods }])
        }
        this.clearFlag = false
      }
    },
    'form.projectId' (now, old) {
      if (!this.clearFlag) {
        this.clearFlag = true
        return
      }
      if (now !== old && this.clearFlag) {
        this.$set(this.form, 'coreEnterpriseId', '')
        this.$set(this.form, 'coreEnterpriseName', '')
        this.$set(this.form, 'planOrBankId', '')
        this.$set(this.form, 'planOrBankName', '')
        this.$set(this.form, 'specialPlanId', '')
        this.$set(this.form, 'specialPlanPeriods', '')
        this.$set(this.form, 'initialOwnersId', '')
        this.$set(this.form, 'initialOwnersName', '')
        this.$set(this.form, 'assetServiceId', '')
        this.$set(this.form, 'assetServiceName', '')
      }
    }
  }
}
</script>
