<!--导入-->
<template>
  <div>
    <dialog-edit ref="dialog" :visible.sync="dialogVisible" :title="$t('common.import')" width="1200px" :api="api" :form="importEditform" :editModel="editModel"
                 :formRules="formRules" @onSaved="save" :autoSave="false" :loading="okBtnloading" :menuCode="menuCode" savePerms="reflseSaveBtn" :openPerms="true">
      <el-collapse v-model="activeNames" @change="handleChange">
        <el-collapse-item title="保理提单信息" name="1">
          <dym-form :formValue.sync="importEditform" :componentList="componentList" @selectChanged="importEditselectChanged"></dym-form>
          <el-form-item :label="$t('ladingPlanManageList.importFile')" prop="fileName" label-width="170px" :rules="this.selectionData.length > 0 ? [] : [{ required: true, message: '请导入文件' }]">
            <!--        <el-row>-->
            <el-col :xs="24" :sm="24" :md="24" :lg="24">
              <div class="uploadInfoFile">
                <el-input :disabled="true" v-model="importEditform.fileName" class="importCss"></el-input>
                <btn-auto-import size="" :importName="$t('ladingManageList.importFile')"
                                 :menuCode="menuCode" perms="ImportFile" :openPerms="true"
                                 @upload="upload"></btn-auto-import>
                <span class="tipInfoStyle">{{'上传文件单元格格式必需为文本（避免引起不必要的异常）'}}</span>
              </div>
            </el-col>
            <!--        </el-row>-->
          </el-form-item>
        </el-collapse-item>
      </el-collapse>
      <el-form :model="formTableData" ref="formTableData" :show-message="false">
        <div>
          <data-table
            ref="dataTable"
            :btnCreate="false"
            :queryParas="queryParas"
            :operateBtnLayout="''"
            @getTableData="getTableData"
            :max-height="maxHeight"
            :columns="columns"
            loadPage="preList"
            :sourceData="formTableData.sourceData"
            :api="api"
            :showSelection="true"
            @selectRowChange="selectRowChange"
            :loadCount="loadCount">
            <!--失败原因-->
            <template slot="failReason" slot-scope="scope">
  <!--            <el-input v-model="scope.data.row.failReason"></el-input>-->
              <span-plus :text="scope.data.row.failReason" :index="scope.data.$index" :ref="'spanPlus' + scope.data.$index"></span-plus>
            </template>
            <!--供应商-->
            <template slot="creditor" slot-scope="scope">
              <el-input v-model="scope.data.row.creditor"></el-input>
            </template>
            <template slot="creditorCreditCode" slot-scope="scope">
              <el-form-item :prop="'sourceData.' + scope.data.$index + '.creditorCreditCode'" :rules="ifCheck(scope.data.$index) ? formRules.numberElgCheck : []" class="margin-bottom0">
                <el-input v-model="scope.data.row.creditorCreditCode"></el-input>
              </el-form-item>
            </template>
            <!--收款人名称-->
            <template slot="receiverName" slot-scope="scope">
              <el-input v-model="scope.data.row.receiverName"></el-input>
            </template>
            <!--项目名称-->
            <template slot="projectContractName" slot-scope="scope">
              <el-input v-model="scope.data.row.projectContractName"></el-input>
            </template>
            <!--区域编号-->
            <template slot="regionCode" slot-scope="scope">
              <el-input v-model="scope.data.row.regionCode"></el-input>
            </template>
            <!--应收账款金额 - 保理金额-->
            <template slot="factoringMoney" slot-scope="scope">
              <el-form-item :prop="'sourceData.' + scope.data.$index + '.factoringMoney'" :rules="ifCheck(scope.data.$index) ? formRules.rulesAmountCheck : []" class="margin-bottom0">
                <el-input v-model="scope.data.row.factoringMoney" :placeholder="$t('guideSheetManage.inputJine')"></el-input>
              </el-form-item>
            </template>
            <!--账款到期日-->
            <template slot="dueDate" slot-scope="scope">
              <el-form-item :prop="'sourceData.' + scope.data.$index + '.dueDate'" class="margin-bottom0">
                <el-date-picker class="dymForm" type="date" v-model="scope.data.row.dueDate"></el-date-picker>
              </el-form-item>
            </template>
            <!--项目公司名称 - 债务人-->
            <template slot="debtor" slot-scope="scope">
              <el-input v-model="scope.data.row.debtor"></el-input>
            </template>
            <!--开户行-->
            <template slot="receiverBank" slot-scope="scope">
              <el-input v-model="scope.data.row.receiverBank"></el-input>
            </template>
            <!--收款账号-->
            <template slot="receiverBankAccount" slot-scope="scope">
              <el-input v-model="scope.data.row.receiverBankAccount"></el-input>
            </template>
            <!--收款账号-->
            <template slot="basicContractName" slot-scope="scope">
              <el-input v-model="scope.data.row.basicContractName"></el-input>
            </template>
            <!--合同名称-->
            <template slot="basicContractCode" slot-scope="scope">
              <el-input v-model="scope.data.row.basicContractCode"></el-input>
            </template>
            <!--合同编号-->
            <template slot="invoiceNo" slot-scope="scope">
              <el-input v-model="scope.data.row.invoiceNo"></el-input>
            </template>
            <!--发票金额-->
            <template slot="taxExcludingAmount" slot-scope="scope">
              <el-form-item :prop="'sourceData.' + scope.data.$index + '.taxExcludingAmount'" :rules="ifCheck(scope.data.$index) ? formRules.rulesAmountCheck : []" class="margin-bottom0">
                <el-input v-model="scope.data.row.taxExcludingAmount" :placeholder="$t('guideSheetManage.inputJine')"></el-input>
              </el-form-item>
            </template>
            <!--供应商联系人-->
            <template slot="supplierContactName" slot-scope="scope">
              <el-input v-model="scope.data.row.supplierContactName"></el-input>
            </template>
            <!--供应商联系电话-->
            <template slot="supplierContactTel" slot-scope="scope">
              <el-input v-model="scope.data.row.supplierContactTel"></el-input>
            </template>
            <!--区域联系人-->
            <template slot="areaContactName" slot-scope="scope">
              <el-input v-model="scope.data.row.areaContactName"></el-input>
            </template>
            <!--区域联系电话-->
            <template slot="areaContactTel" slot-scope="scope">
              <el-input v-model="scope.data.row.areaContactTel"></el-input>
            </template>
            <!--项目联系人-->
            <template slot="projectContactName" slot-scope="scope">
              <el-input v-model="scope.data.row.projectContactName"></el-input>
            </template>
            <!--项目联系电话-->
            <template slot="projectContactTel" slot-scope="scope">
              <el-input v-model="scope.data.row.projectContactTel"></el-input>
            </template>
          </data-table>
        </div>
      </el-form>
    </dialog-edit>
    <import-result-edit :visible.sync="resultFlag" :editModel="resultModel" :form="resultItem"></import-result-edit>
  </div>
</template>

<script>
import { DialogEdit, dymForm, DataTable, authButton, SelectProductName, SelectCoreEnterpriseCascade, SelectFinancialInstitutionsCascade,
  SelectAssetsServiceCascade, SelectPrimitiveRightsHolderCascade, SpanPlus,
  btnAutoImport, SelectPeriodsCascade } from 'newepoch-components'
import BaseEditPage from '@/pages/baseEditPage'
import ladingManageApi from '@/api/ladingManageApi'
import ImportResultEdit from '@/pages/shouji/ladingManage/importResultEdit.vue'
import componentsApi from '@/api/componentsApi'
import * as format from '@/filters/index'
import qs from 'qs'
import { regExp } from '@/validator/index'

export default {
  extends: new BaseEditPage(''),
  // name: 'importEditCopy',
  components: {
    DialogEdit,
    dymForm,
    authButton,
    DataTable,
    btnAutoImport,
    ImportResultEdit,
    SpanPlus
  },
  props: {
    code: {
      type: String
    },
    menuCode: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      maxHeight: 330,
      activeNames: '1',
      // 选中的行数据
      selectRowIndex: [],
      loadCount: 0, // 加载数
      selectionData: [], // 选择数据
      // 总数居
      formTableData: {
        sourceData: []
      },
      queryParas: {
        pageIndex: 1,
        pageSize: 10
      }, // 查询条件
      columns: [
        // 失败原因
        {
          prop: 'failReason',
          align: 'left',
          width: '200px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].guideSheetManage.failtInfo
        },
        {
          // 表格中的序号
          prop: 'num',
          align: 'left',
          width: '200px',
          label: this.$i18n.messages[this.$i18n.locale].guideSheetManage.tableNum
        },
        {
          // 供应商
          prop: 'creditor',
          align: 'left',
          width: '200px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].guideSheetManage.supplierName
        },
        {
          // 三证合一代码
          prop: 'creditorCreditCode',
          align: 'left',
          width: '200px',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].guideSheetManage.threeToOne
        },
        // 收款人名称
        {
          prop: 'receiverName',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.payee,
          width: '200px'
        },
        // 项目名称
        {
          prop: 'projectContractName',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectName,
          width: '200px'
        },
        // 区域编号
        {
          prop: 'regionCode',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaCode,
          width: '200px'
        },
        // 应收账款金额 - 保理金额
        {
          prop: 'factoringMoney',
          align: 'right',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.accountReceivable,
          width: '180px',
          format: (row) => { return format.thousandFilter(row.factoringMoney) }
        },
        // 账款到期日
        {
          prop: 'dueDate',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.dueDateInfo,
          width: '180px',
          slot: true
        },
        // // 账款到期日
        // {
        //   prop: 'dueDate',
        //   align: 'right',
        //   label: this.$i18n.messages[this.$i18n.locale].ladingManageList.invoiceAmount,
        //   width: '150px',
        //   slot: true
        //   // format: (row) => { return format.thousandFilter(row.taxExcludingAmount) }
        // },
        // 项目公司名称 - 债务人
        {
          prop: 'debtor',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectCompanyName,
          width: '200px'
        },
        // 开户行
        {
          prop: 'receiverBank',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.openingBank,
          width: '200px'
        },
        // 收款账号
        {
          prop: 'receiverBankAccount',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.payAccount,
          width: '200px'
        },
        // 合同名称
        {
          prop: 'basicContractName',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.contractName,
          width: '200px'
        },
        // 合同编号
        {
          prop: 'basicContractCode',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.contractNum,
          width: '200px'
        },
        // 发票号码
        {
          prop: 'invoiceNo',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.invoiceNum,
          width: '200px'
        },
        // 发票金额
        {
          prop: 'taxExcludingAmount',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.invoiceAmount,
          width: '150px',
          slot: true,
          format: (row) => { return format.thousandFilter(row.taxExcludingAmount) }
        },
        // 供应商联系人
        {
          prop: 'supplierContactName',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.supplierContactName,
          width: '150px',
          slot: true
        },
        // 供应商联系电话
        {
          prop: 'supplierContactTel',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.supplierContactTel,
          width: '150px',
          slot: true
        },
        // 区域联系人
        {
          prop: 'areaContactName',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaContactName,
          width: '150px',
          slot: true
        },
        // 区域联系电话
        {
          prop: 'areaContactTel',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.areaContactTel,
          width: '150px',
          slot: true
        },
        // 项目联系人
        {
          prop: 'projectContactName',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectContactName,
          width: '150px',
          slot: true
        },
        // 项目联系电话
        {
          prop: 'projectContactTel',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.projectContactTel,
          width: '150px',
          slot: true
        },
        // 修改时间
        {
          prop: 'modifyTime',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].ladingManageList.importModifyTime,
          width: '150px',
          format: (row) => {
            return format.formatDate(row.modifyTime, 'yyyy-MM-dd hh:mm')
          }
        }
      ],
      resultFlag: false,
      resultModel: '',
      resultItem: {},
      okBtnloading: false, // 保存按钮转圈圈
      // formdata 块
      importEditform: {},
      fm: new FormData(),
      formRules: {
        projectId: [{
          required: true,
          // message: '请选择产品名称',
          message: this.$i18n.messages[this.$i18n.locale].ladingNoticeManage.selectproductName,
          trigger: 'change'
        }],
        specialPlanId: [{
          required: true,
          message: this.$i18n.messages[this.$i18n.locale].ladingNoticeManage.selectspecialPlanPeriods,
          trigger: 'change'
        }],
        coreEnterpriseId: [{
          required: true,
          // message: '请选择核心企业',
          message: this.$i18n.messages[this.$i18n.locale].ladingNoticeManage.selectcoreEnterprise,
          trigger: 'change'
        }],
        planningManagerId: [{
          required: true,
          // message: '请选择计划管理人/再保理银行',
          message: this.$i18n.messages[this.$i18n.locale].ladingNoticeManage.selectplanningManagerName,
          trigger: 'change'
        }],
        ladingType: [{
          required: true,
          // message: '请选择提单类型',
          message: this.$i18n.messages[this.$i18n.locale].ladingNoticeManage.selectladingType,
          trigger: 'change'
        }],
        assetServiceId: [{
          required: true,
          // message: '请选择资产服务机构',
          message: this.$i18n.messages[this.$i18n.locale].ladingNoticeManage.selectassetServiceOrgan,
          trigger: 'change'
        }],
        initialOwnersId: [{
          required: true,
          // message: '请选择原始权益人',
          message: this.$i18n.messages[this.$i18n.locale].ladingNoticeManage.selectrightsHolder,
          trigger: 'change'
        }],
        batchDateData: [{
          required: true,
          // message: '请选择批次日期',
          message: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.pleaseSelectBatchDateTime,
          trigger: 'change'
        }],
        rulesAmountCheck: [{
          validator: this.accountCheck,
          trigger: 'change'
        }],
        // 数字英文检查
        numberElgCheck: [{
          validator: this.elgCheck,
          trigger: 'change'
        }]
      },
      componentList: [
        // 产品名称
        {
          label: this.$i18n.messages[this.$i18n.locale].common.productName,
          value: 'projectId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          componentName: SelectProductName,
          prop: 'projectId',
          name: 'projectId',
          labelWidth: '170px'
        },
        // 期数
        {
          label: this.$i18n.messages[this.$i18n.locale].common.periodsNum,
          value: 'specialPlanId',
          disabled: false,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          componentName: SelectPeriodsCascade,
          queryName: 'projectId',
          queryValue: 'projectId',
          prop: 'specialPlanId',
          name: 'specialPlanId',
          labelWidth: '170px'
        },
        // 核心企业
        {
          label: this.$i18n.messages[this.$i18n.locale].common.coreEnterprises,
          value: 'coreEnterpriseId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          componentName: SelectCoreEnterpriseCascade,
          queryName: 'projectId',
          queryValue: 'projectId',
          prop: 'coreEnterpriseId',
          name: 'coreEnterpriseId',
          labelWidth: '170px'
        },
        // 计划管理人/再保理银行
        {
          label: this.$i18n.messages[this.$i18n.locale].common.refactorBank,
          value: 'planningManagerId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          queryName: 'projectId',
          queryValue: 'projectId',
          componentName: SelectFinancialInstitutionsCascade,
          prop: 'planningManagerId',
          name: 'planningManagerId',
          labelWidth: '170px'
        },
        // 提单类型
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.ladingType,
          value: 'ladingType',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZD0100',
          store: this.$store,
          prop: 'ladingType',
          labelWidth: '170px'
        },
        // 资产服务机构
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.assetServiceOrgan,
          value: 'assetServiceId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          componentName: SelectAssetsServiceCascade,
          queryName: 'projectId',
          queryValue: 'projectId',
          prop: 'assetServiceId',
          name: 'assetServiceId',
          labelWidth: '170px'
        },
        // 原始权益人
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.rightsHolder,
          value: 'initialOwnersId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          componentName: SelectPrimitiveRightsHolderCascade,
          queryName: 'projectId',
          queryValue: 'projectId',
          prop: 'initialOwnersId',
          name: 'initialOwnersId',
          labelWidth: '170px'
        },
        // 批次信息
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.batchInfo,
          value: 'batchInfo',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 8, 8, 8],
          componentName: 'el-input',
          prop: 'batchInfo',
          maxlength: 100,
          labelWidth: '170px'
        }
      ],
      batchInfoDate: [
        // 批次信息
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.batchInfo,
          value: 'batchInfo',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 8, 8, 8],
          componentName: 'el-input',
          maxlength: 100,
          prop: 'batchInfo',
          labelWidth: '170px'
        },
        // 批次日期
        {
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.batchDateTime,
          value: 'batchDateData',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 8, 8, 8],
          componentName: 'el-date-picker',
          prop: 'batchDateData',
          labelWidth: '170px'
        }
      ]
    }
  },
  computed: {
    api: function () {
      return ladingManageApi.ladingManageList
    }
  },
  methods: {
    handleChange (val) {
      if (val.length === 1) {
        this.$nextTick(() => {
          this.maxHeight = 330
        })
      } else {
        this.maxHeight = 450
      }
    },
    getTableData (data) {
      data.forEach(it => {
        it.dueDate = format.formatDateTpcModify(it.dueDate)
      })
      this.$set(this.formTableData, 'sourceData', data)
      this.formTableData.sourceData.forEach(it => {
        if (it.factoringMoney.toString() === '0') {
          it.factoringMoney = ''
        }
        if (it.taxExcludingAmount.toString() === '0') {
          it.taxExcludingAmount = ''
        }
      })
      this.$nextTick(() => {
        Object.keys(this.$refs).forEach(it => {
          if (it.indexOf('spanPlus') >= 0 && this.$refs[it] && this.$refs[it].countLines) {
            this.$refs[it].moreFlag = this.$refs[it].countLines()
          }
        })
        this.$refs.formTableData.clearValidate()
      })
    },
    accountCheck (rule, value, callback) {
      if (regExp.predictLadingAmount.test(value)) {
        callback()
      } else {
        callback(new Error(''))
      }
    },
    elgCheck (rule, value, callback) {
      if (this.UtilJs.isEmpty(value) || regExp.numberAndEnglish.test(value)) {
        callback()
      } else {
        callback(new Error(''))
      }
    },
    // 是否拥有校验
    ifCheck (index) {
      let as = this.selectRowIndex.length !== 0 && this.selectRowIndex.some(it => it === index)
      return as
    },
    // 选择表格
    selectRowChange (data) {
      this.selectRowIndex = []
      this.selectionData = data
      this.formTableData.sourceData.forEach((it, index) => {
        if (this.selectionData.some(it1 => it1.keyId === it.keyId)) {
          this.selectRowIndex.push(index)
        }
      })
      this.$nextTick(() => {
        if (this.$refs.dialog && this.$refs.dialog.$refs.editForm) {
          this.$refs.dialog.$refs.editForm.clearValidate()
        }
      })
    },
    importEditselectChanged (obj, index) {
      if (obj.projectIdInfo) {
        this.importEditform.projectName = obj.projectIdInfo.projectName
        this.clearInfoList()
      }
      if (obj.specialPlanIdInfo) {
        this.importEditform.specialPlanPeriods = obj.specialPlanIdInfo.specialPlanPeriods
      }
      if (obj.coreEnterpriseIdInfo) {
        this.importEditform.coreEnterpriseName = obj.coreEnterpriseIdInfo.enterpriseName
      }
      if (obj.planningManagerIdInfo) {
        this.importEditform.planningManagerName = obj.planningManagerIdInfo.enterpriseName
      }
      if (obj.assetServiceIdInfo) {
        this.importEditform.assetServiceName = obj.assetServiceIdInfo.enterpriseName
      }
      if (obj.initialOwnersIdInfo) {
        this.importEditform.initialOwnersName = obj.initialOwnersIdInfo.enterpriseName
      }
      if (Object.keys(obj).some(it => it === 'projectIdInfo')) {
        this.clearInfoList()
        if (this.importEditform.projectId) {
          this.getTypeById()
        } else {
          this.formRules.specialPlanId[0].required = true
          this.componentList[1].disabled = false
        }
      }
    },
    upload (file) {
      this.fm = new FormData()
      // this.importEditform.fileName = file.name
      this.$set(this.importEditform, 'fileName', file.name)
      // this.importEditform.importSource = '10' // 导入来源
      this.$set(this.importEditform, 'importSource', 10)
      this.fm.append('file', file)
      // this.importEditform.file = file
    },
    // 无选择保存
    noSelectSave () {
      let parmas = qs.stringify(this.importEditform)
      ladingManageApi.ladingManageList.import(this.fm, parmas).then(res => {
        if (res && res.success && res.data) {
          this.resultItem = Object.assign({}, res.data)
          this.resultFlag = true
          // $this.dialogVisible = false
          this.$emit('close')
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.importFileFaile)
        }
      }).finally(() => {
        this.okBtnloading = false
      })
    },
    // 有选择保存
    selectSave () {
      this.okBtnloading = true
      let result = JSON.parse(JSON.stringify(this.importEditform))
      if (result.fileName) {
        delete result.fileName
      }
      if (result.batchDateData) {
        delete result.batchDateData
      }
      result.assetLadingImportInfoByTableDTOList = JSON.parse(JSON.stringify(this.selectionData))
      result.assetLadingImportInfoByTableDTOList.forEach(it => {
        delete it.failReason
        delete it.num
        // delete it.supplierContact
      })
      this.api.assetTable(result).then(res => {
        if (res && res.success && res.data) {
          this.resultItem = Object.assign({}, res.data)
          this.resultFlag = true
          // $this.dialogVisible = false
          this.$emit('close')
        } else {
          this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.importFileFaile)
        }
      }).finally(() => {
        this.okBtnloading = false
      })
    },
    save () {
      this.okBtnloading = true
      this.importEditform.noticeStatus = '0'
      delete this.importEditform.file
      if (!this.importEditform.specialPlanPeriods) {
        this.importEditform.specialPlanPeriods = '0'
      }
      this.importEditform.importSource = this.code
      this.importEditform.userName = this.$store.state.user.user.userName
      if (this.importEditform.isAbs === '2') {
        this.importEditform.batchDate = new Date(this.importEditform.batchDateData).getTime()
        if (isNaN(this.importEditform.batchDate) || this.importEditform.batchDate === 0) {
          delete this.importEditform.batchDate
        }
      } else {
        delete this.importEditform.batchDate
        delete this.importEditform.batchDateData
      }
      if (this.selectionData.length > 0) {
        this.$refs.formTableData.clearValidate()
        this.$refs.formTableData.validate((valid) => {
          if (valid) {
            this.selectSave()
          } else {
            this.okBtnloading = false
            this.warning(this.$i18n.messages[this.$i18n.locale].guideSheetManage.datatableCheckInfo)
          }
        })
      } else {
        this.noSelectSave()
      }
    },
    // 根据ID获取产品类别
    getTypeById () {
      componentsApi.productenterprise.getclassify({ projectId: this.importEditform.projectId }).then(res => {
        this.importEditform.isAbs = res.data ? res.data.productType : '2'
        this.selectChange(this.importEditform.isAbs)
      })
    },
    clearInfoList () {
      this.$set(this.importEditform, 'specialPlanId', '')
      this.$set(this.importEditform, 'coreEnterpriseId', '')
      this.$set(this.importEditform, 'planningManagerId', '')
      this.$set(this.importEditform, 'assetServiceId', '')
      this.$set(this.importEditform, 'initialOwnersId', '')
      delete this.importEditform.specialPlanId
      delete this.importEditform.coreEnterpriseId
      delete this.importEditform.planningManagerId
      delete this.importEditform.assetServiceId
      delete this.importEditform.initialOwnersId
      this.$nextTick(() => {
        if (this.$refs.dialog && this.$refs.dialog.$refs.editForm) {
          this.$refs.dialog.$refs.editForm.clearValidate()
        }
      })
    },
    // 改变选择信息、日期
    selectChange (isAbs) {
      this.formRules.specialPlanId[0].required = isAbs === '1'
      this.componentList[1].disabled = isAbs !== '1'
      if (isAbs === '1') {
        // 期数-->批次信息
        this.componentList[7] = this.batchInfoDate[0]
      } else {
        // 日期-->批次日期
        this.componentList[7] = this.batchInfoDate[1]
      }
    }
    // 获取原因数据
    // getPreData () {
    //   this.$refs.dataTable.vLoading = true
    //   ladingManageApi.ladingManageList.preList().then((res) => {
    //     if (res && res.success) {
    //       this.formTableData.sourceData.length = 0
    //       res.data.forEach(it => {
    //         if (!this.UtilJs.isEmpty(it.creditor) && !this.UtilJs.isEmpty(it.debtor) && !this.UtilJs.isEmpty(it.factoringMoney) && it.factoringMoney !== 0) {
    //           if (!it.threeToOne) {
    //             this.$set(it, 'threeToOne', '')
    //           }
    //           this.formTableData.sourceData.push(it)
    //         }
    //       })
    //     }
    //   }).finally((res) => {
    //     this.$refs.dataTable.vLoading = false
    //   })
    // }
  },
  watch: {
    dialogVisible (newVal) {
      if (newVal) {
        this.okBtnloading = false
        this.selectChange('1')
        this.importEditform = Object.assign({}, this.form)
        this.$nextTick(() => {
          // this.getPreData()
          this.loadCount += 1
        })
      } else {
        this.activeNames = ['1']
        this.maxHeight = 330
      }
    },
    resultFlag (n, o) {
      if (o && !n) {
        this.loadCount += 1
        // this.getPreData()
      }
    }
  }
}
</script>

<style lang="scss" scoped src="@/styles/shouji/ladingManage/importEdit.scss">
</style>
