<template>
    <div>
        <up-down-layout :handleFlag.sync="handleFlag">
<!--            <search-form :componentList="componentList" :formValue.sync="searchFormQueryParas"-->
<!--                         @handleFilter="handleFilter" @clearParam="clearParam" slot="query">-->
          <search-form
            :componentList="componentList"
            :formValue.sync="queryParas"
            searchPerms="search"
            resetPerms="reset"
            slot="query"
            v-model="queryParas"
            @handleFilter="handleFilter"
            @clearParam="clearParam">
          </search-form>
            <template slot="table">
                <el-form :show-message="false">
                    <data-table :showSelection="true"
                                v-bind="elHeightObj"
                                :selectedRows.sync="backData"
                                @selectRowChange="selectionData"
                                @getTableData = "getTableData"
                                :sourceData.sync="sourceData"
                                :loadCount.sync="loadCount"
                                :columns="columns"
                                :api="api"
                                operateBtnLayout=""
                                :queryParas="queryParas" :menuFlag="true"
                                :border="true"  :stripe="true">
                        <template slot="headButton" slot-scope="scope">
                            <el-row>
                                <el-col :span="24" class="textRight">
                                    <auth-button type="primary" size="medium" :label="$t('traceMgr.viewBusinessData')" @click="showBusinessDataStatisticsDialog()" class="iconfont iconzuopintoupiao"></auth-button>
                                    <auth-button type="primary" size="medium" :label="$t('traceMgr.previewOfAssignmentResults')" @click="showDistributionOrderPreviewDialog()" class="iconfont iconyulan-copy-copy"></auth-button>
                                    <auth-button type="primary" size="medium" :label="$t('traceMgr.preImportOrder')" @click="showImportPreDistributionOrderDialog()" class="iconfont icondaochu1"></auth-button>
                                    <auth-button type="primary" size="medium" :label="$t('traceMgr.distribution')" @click="showDistributionOrderDialog(scope.row)" class="iconfont iconfenpei1"></auth-button>
                                    <auth-button type="primary" size="medium" :label="$t('traceMgr.confirmDistribution')" @click="confirmDistribution()" class="iconfont iconxinzeng1"></auth-button>
                                    <auth-button type="primary" size="medium" :label="$t('traceMgr.delete')" @click="deleteBtn()" class="iconfont iconshanchu"></auth-button>
                                </el-col>
                            </el-row>
                        </template>
                        <template slot="factoringCommissioner" slot-scope="scope">
                            <!--                            @selectChanged="selectChanged"-->
                            <!--保理专员赋值-->
                            <select-factoring-commissioner v-model="scope.data.row.factoringUserId" :name="scope.data.$index + '|' + scope.data.row.factoringUserId"  @selectChanged="selectChanged"></select-factoring-commissioner>
                        </template>
                        <template slot="formerFactoringCommissioner" slot-scope="scope">
                            <el-tooltip placement="top">
                                <div slot="content">{{scope.data.row.formerFactoringCommissioner}}</div>
                                <span>{{scope.data.row.formerFactoringCommissioner}}</span>
                            </el-tooltip>
                        </template>
                        <template slot="oldFactoringUserName"  slot-scope="scope">
                          <el-tooltip placement="top">
                            <div slot="content"  v-if="scope.data.row.oldCoreEnterpriseName !== ''">{{scope.data.row.oldCoreEnterpriseName}}</div>
                          </el-tooltip>
                          <span>{{scope.data.row.oldFactoringUserName}}</span>
                        </template>
                        <template slot="orderNum"  slot-scope="scope">
                          <el-tooltip placement="left-start">
                            <div slot="content">
                              <el-table
                                v-bind="elHeightObj"
                                :data="orderListData"
                                v-loading="loading2"
                                :element-loading-text="$t('traceMgr.loading')"
                                element-loading-spinner="el-icon-loading"
                                element-loading-background="rgba(255, 255, 255, 1)"
                                style="width: 100%">
                                <el-table-column
                                  prop="assetCode"
                                  align="center"
                                  :label="$t('traceMgr.orderNumber')"
                                  width="180">
                                </el-table-column>
                                <el-table-column
                                  prop="factoringMoney"
                                  align="center"
                                  :label="$t('traceMgr.factoringAmount')"
                                  width="180">
                                </el-table-column>
                              </el-table>
                            </div>
                            <span  @mouseenter="onMouse(scope.data.row)" @mouseleave="onLeave">{{scope.data.row.orderNum}}</span>
                          </el-tooltip>
                        </template>
                    </data-table>
                </el-form>
            </template>
        </up-down-layout>
        <business-data-statistics-dialog :visible.sync="businessDataStatisticsDialog" :form="form" :orderType=orderType :editModel="editModel"></business-data-statistics-dialog>
        <distribution-order-dialog ref="disOrDialog" :handler="handler" :form="company" :visible.sync="distributionOrderDialog" :orderType="orderType" :editModel="editModel"></distribution-order-dialog>
        <distribution-order-preview-dialog ref="previewOrderDialog" :form="form" :queryParas="queryParas" :visible.sync="distributionOrderPreviewDialog" :editModel="editModel"></distribution-order-preview-dialog>
        <import-pre-distribution-order-dialog :visible.sync="importPreDistributionOrderDialog"></import-pre-distribution-order-dialog>
        <confirm-distribution-order-dialog :confirmData="company" :form="form" :handler="handler" :orderType="orderType" :visible.sync="confirmDistributionOrderDialog"></confirm-distribution-order-dialog>
        <template>
          <DialogEdit  :footerBtnShow="false" :form="form" editModel="V"   :visible.sync="confirmDialog" :title="$t('common.tip')" width="35%" :close-on-click-modal="false" class="el-dialog--center">
            <p class="text-center">
              {{$t('traceMgr.text1')}}
              {{currentCreditor}}
              {{$t('traceMgr.text2')}}
              {{num}}
              {{$t('traceMgr.text3')}}
            </p>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary" size="medium" :loading="loading" @click="taskSure">{{$t('common.yes')}}</el-button>
              <el-button type="button" size="medium" @click="closeSure()">{{$t('common.no')}}</el-button>
            </div>
          </DialogEdit>
        </template>
    </div>
</template>

<script>
import { DataTable, searchForm, upDownLayout, authButton, SelectCoreEnterprise, SelectFactoringCommissioner, SelectFinancialInstitutions, SelectPeriodsCascade, SelectSupplier, DialogEdit } from 'newepoch-components'
import DatePicker from '@/components/element/DatePick'
import EnterpriseOperationDifficulty from '@/components/element/EnterpriseOperationDifficulty'
import BusinessDataStatisticsDialog from './businessDataStatisticsDialog'
import DistributionOrderDialog from './distributionOrderDialog'
import DistributionOrderPreviewDialog from './distributionOrderPreviewDialog'
import SelectFlag from '@/components/tracemgr/common/SelectFlag'
import tracemgrApi from '@/api/tracemgrApi'
import importPreDistributionOrderDialog from './importPreDistributionOrderDialog'
import confirmDistributionOrderDialog from './confirmDistributionOrderDialog'
import mixin from '@/pages/mixin.js'
import BasePage from '@/pages/basePage'
import * as format from '@/filters/index'

export default {
  extends: new BasePage(),
  mixins: [mixin],
  components: {
    format,
    DataTable,
    searchForm,
    upDownLayout,
    authButton,
    SelectCoreEnterprise,
    SelectFactoringCommissioner,
    SelectFinancialInstitutions,
    SelectPeriodsCascade,
    SelectSupplier,
    DatePicker,
    EnterpriseOperationDifficulty,
    BusinessDataStatisticsDialog,
    DistributionOrderDialog,
    DistributionOrderPreviewDialog,
    SelectFlag,
    tracemgrApi,
    importPreDistributionOrderDialog,
    confirmDistributionOrderDialog,
    DialogEdit
  },
  data () {
    return {
      tableData: [],
      tableDataCopy: [],
      loading: false,
      confirmDialog: false,
      currentCreditor: '',
      valueData: {},
      num: 0,
      loading2: false,
      loadCount: 0,
      orderListData: [],
      handleFlag: true,
      businessDataStatisticsDialog: false,
      confirmDistributionOrderDialog: false,
      distributionOrderDialog: false,
      distributionOrderPreviewDialog: false,
      importPreDistributionOrderDialog: false,
      sourceData: [],
      editModel: '',
      company: [],
      tableApi: {},
      item: {},
      form: {},
      orderType: '2',
      allocationStatus1: this.$i18n.messages[this.$i18n.locale].traceMgr.allocationStatus1,
      allocationStatus2: this.$i18n.messages[this.$i18n.locale].traceMgr.allocationStatus2,
      allocationStatus3: this.$i18n.messages[this.$i18n.locale].traceMgr.allocationStatus3,
      no: this.$i18n.messages[this.$i18n.locale].common.no,
      yes: this.$i18n.messages[this.$i18n.locale].common.yes,
      headOffice: this.$i18n.messages[this.$i18n.locale].traceMgr.headOffice,
      groupBuying: this.$i18n.messages[this.$i18n.locale].traceMgr.groupBuying,
      branch: this.$i18n.messages[this.$i18n.locale].traceMgr.branch,
      low: this.$i18n.messages[this.$i18n.locale].traceMgr.low,
      central: this.$i18n.messages[this.$i18n.locale].traceMgr.central,
      high: this.$i18n.messages[this.$i18n.locale].traceMgr.high,
      elecSeal: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.elecSeal,
      sealType: this.$i18n.messages[this.$i18n.locale].baoLiWorkbenchOrderTrack.sealType,
      elecSealAndsealType: this.$i18n.messages[this.$i18n.locale].traceMgr.elecSealAndsealType,
      stateEnterprise: this.$i18n.messages[this.$i18n.locale].traceMgr.stateEnterprise,
      privateEnterprise: this.$i18n.messages[this.$i18n.locale].traceMgr.privateEnterprise,
      jointVenture: this.$i18n.messages[this.$i18n.locale].traceMgr.jointVenture,
      buildSystem: this.$i18n.messages[this.$i18n.locale].traceMgr.buildSystem,
      individualHousehold: this.$i18n.messages[this.$i18n.locale].traceMgr.individualHousehold,
      queryParas: {
        pageIndex: 1,
        pageSize: 10,
        optDifficultyLevel: ['', ''],
        allocationStatus: ['1', '2'],
        creditorId: '',
        creditor: '',
        factoringUserId: '',
        oldFactoringUserId: '',
        stampWay: '',
        enterpriseId: '',
        planningManagerId: '',
        specialPlanPeriods: '',
        applyReallocationFlag: '',
        factoringApplyTime: '',
        enterpriseType: '',
        addTime: '',
        orderType: '2' // 订单类型(1:正式分配订单 / 2:预分配订单)
      },
      searchFormQueryParas: {

      },
      componentList: [
        // 分配状态
        {
          value: 'allocationStatus',
          disabled: false,
          componentName: 'SelectDictionary',
          multiple: true,
          dictTypeCode: 'tracemgr_order_allocation_status',
          name: 'allocationStatus',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.assignmentStatus,
          cols: [24, 24, 24, 24],
          prop: 'allocationStatus',
          labelWidth: '125px'
        },
        // 供应商名称
        {
          value: 'creditor',
          disabled: false,
          componentName: 'el-input',
          name: 'creditor',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.supplierName,
          cols: [24, 24, 24, 24],
          prop: 'creditor',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input,
          labelWidth: '160px'
        },
        // 保理专员
        {
          value: 'factoringUserId',
          disabled: false,
          multiple: true,
          componentName: SelectFactoringCommissioner,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringCommissioner,
          cols: [24, 24, 24, 24],
          prop: 'factoringUserId',
          labelWidth: '160px'
        },
        // 原保理专员
        {
          value: 'oldFactoringUserId',
          disabled: false,
          multiple: true,
          componentName: SelectFactoringCommissioner,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.formerFactoringCommissioner,
          cols: [24, 24, 24, 24],
          prop: 'oldFactoringUserId',
          labelWidth: '125px'
        },
        // 企业操作难度
        {
          value: 'optDifficultyLevel',
          disabled: false,
          componentName: EnterpriseOperationDifficulty,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.enterpriseOperationDifficulty,
          labelWidth: '160px'
        },
        // 盖章类型
        {
          value: 'stampWay',
          disabled: false,
          multiple: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZD0081',
          name: 'stampWay',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.sealType,
          cols: [24, 24, 24, 24],
          prop: 'stampWay',
          labelWidth: '160px'
        },
        // 核心企业
        {
          value: 'enterpriseId',
          disabled: false,
          multiple: true,
          componentName: SelectCoreEnterprise,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.coreEnterprise,
          cols: [24, 24, 24, 24],
          prop: 'enterpriseId',
          labelWidth: '125px'
        },
        // 计划管理人/再保理银行
        {
          value: 'planningManagerId',
          disabled: false,
          multiple: true,
          componentName: SelectFinancialInstitutions,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.financialInstitutions,
          cols: [24, 24, 24, 24],
          prop: 'planningManagerId',
          labelWidth: '160px'
        },
        // 期数
        {
          value: 'specialPlanPeriods',
          componentName: SelectFlag,
          multiple: true,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.periodsCascade,
          labelWidth: '160px',
          options: [{ label: 1, value: 1 }, { label: 2, value: 2 }, { label: 3, value: 3 }, { label: 4, value: 4 }, { label: 5, value: 5 }, { label: 6, value: 6 },
            { label: 7, value: 7 }, { label: 8, value: 8 }, { label: 9, value: 9 }, { label: 10, value: 10 }, { label: 11, value: 11 }, { label: 12, value: 12 },
            { label: 13, value: 13 }, { label: 14, value: 14 }, { label: 15, value: 15 }, { label: 16, value: 16 }, { label: 17, value: 17 }, { label: 18, value: 18 },
            { label: 19, value: 19 }, { label: 20, value: 20 }, { label: 21, value: 21 }, { label: 22, value: 22 }, { label: 23, value: 23 }, { label: 24, value: 24 },
            { label: 25, value: 25 }, { label: 26, value: 26 }, { label: 27, value: 27 }, { label: 28, value: 28 }, { label: 29, value: 29 }, { label: 30, value: 30 },
            { label: 31, value: 31 }, { label: 32, value: 32 }, { label: 33, value: 33 }, { label: 34, value: 34 }, { label: 35, value: 35 }, { label: 36, value: 36 },
            { label: 37, value: 37 }, { label: 38, value: 38 }, { label: 39, value: 39 }, { label: 40, value: 40 }, { label: 41, value: 41 }, { label: 42, value: 42 },
            { label: 43, value: 43 }, { label: 44, value: 44 }, { label: 45, value: 45 }, { label: 46, value: 46 }, { label: 47, value: 47 }, { label: 48, value: 48 },
            { label: 49, value: 49 }, { label: 50, value: 50 }]
        },

        /* {
                 value: 'specialPlanPeriods',
                 disabled: false,
                 componentName: 'el-input',
                 name: 'specialPlanPeriods',
                 label: this.$i18n.messages[this.$i18n.locale].traceMgr.periodsCascade,
                 cols: [24, 24, 24, 24],
                 prop: 'specialPlanPeriods',
                 placeholder: this.$i18n.messages[this.$i18n.locale].common.input,
                 labelWidth: '160px'
               }, */
        // 是否申请重新分配
        {
          value: 'applyReallocationFlag',
          disabled: false,
          multiple: true,
          componentName: SelectFlag,
          // dictTypeCode: 'ZD0088',
          name: 'applyReallocationFlag',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.whetherToApplyForReallocation,
          cols: [24, 24, 24, 24],
          prop: 'applyReallocationFlag',
          labelWidth: '125px',
          options: [{ label: this.$i18n.messages[this.$i18n.locale].common.no, value: 0 }, { label: this.$i18n.messages[this.$i18n.locale].common.yes, value: 1 }]
        },
        // 提单日期
        {
          value: 'factoringApplyTime',
          disabled: false,
          componentName: DatePicker,
          name: 'factoringApplyTime',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.billImportOfLadingDate,
          cols: [24, 24, 24, 24],
          prop: 'factoringApplyTime',
          type: 'daterange',
          format: 'yyyy-MM-dd',
          labelWidth: '160px'
        },
        // 供应商类型
        {
          value: 'enterpriseType',
          disabled: false,
          multiple: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'tracemgr_supplier_type',
          name: 'enterpriseType',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.supplierType,
          cols: [24, 24, 24, 24],
          prop: 'enterpriseType',
          labelWidth: '160px'
        }
        // ,
        // // 导入时间
        // {
        //   value: 'addTime',
        //   disabled: false,
        //   componentName: DatePicker,
        //   name: 'addTime',
        //   label: this.$i18n.messages[this.$i18n.locale].traceMgr.importTime,
        //   cols: [24, 24, 24, 24],
        //   prop: 'addTime',
        //   type: 'daterange',
        //   format: 'yyyy-MM-dd',
        //   labelWidth: '160px'
        // }
      ],
      columns: [
        // 分配状态
        {
          prop: 'allocationStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.assignmentStatus,
          width: '120px',
          format: function (row) {
            if (row.allocationStatus === '1') {
              return '待分配'
            } else if (row.allocationStatus === '2') {
              return '分配中'
            } else if (row.allocationStatus === '3') {
              return '已分配'
            }
          }
        },
        // 供应商名称
        {
          prop: 'creditor',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.supplierName,
          width: '120'
        },
        // 订单数量
        {
          prop: 'orderNum',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.orderQuantity,
          slot: true,
          width: '120px'
        },
        // 待分配订单总数
        {
          prop: 'waitNum',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.totalOrdersToBeAllocated,
          width: '120px'
        },
        // 保理金额
        {
          prop: 'factoringMoney',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringAmount,
          width: '120px',
          format: (row) => {
            if (row.factoringMoney === undefined || row.factoringMoney === '') {
              return ''
            }
            return format.thousandFilter(row.factoringMoney) + '元'
          }
        },
        // 区域
        {
          prop: 'coreAreaName',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.region,
          width: '120px',
          format: function (row) {
            if (row.coreAreaName === 'null') {
              return ''
            } else {
              return row.coreAreaName
            }
          }
        },
        // 供应商类型
        {
          prop: 'enterpriseType',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.supplierType,
          width: '100px',
          format: function (row) {
            if (row.enterpriseType === '1') {
              return '总部'
            } else if (row.enterpriseType === '2') {
              return '集采'
            } else if (row.enterpriseType === '3') {
              return '分部'
            }
          }
        },
        // 保理专员
        {
          prop: 'factoringCommissioner',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringCommissioner,
          slot: true,
          width: '200px'
        },
        // 原保理专员
        {
          prop: 'oldFactoringUserName',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.formerFactoringCommissioner,
          slot: true,
          width: '200px'
        },
        // 企业性质
        {
          prop: 'enterpriseNature',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.natureOfEnterprise,
          width: '100px',
          format: function (row) {
            if (row.enterpriseNature === '1') {
              return '国企'
            } else if (row.enterpriseNature === '2') {
              return '私企'
            } else if (row.enterpriseNature === '3') {
              return '合资'
            } else if (row.enterpriseNature === '4') {
              return '中建系'
            } else if (row.enterpriseNature === '5') {
              return '个体户'
            }
          }
        },
        // 企业操作难度
        {
          prop: 'optDifficultyLevel',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.enterpriseOperationDifficulty,
          width: '120px',
          format: (row) => {
            if (row.optDifficultyLevel === '1') {
              return '低'
            } else if (row.optDifficultyLevel === '2') {
              return '中'
            } else if (row.optDifficultyLevel === '3') {
              return '高'
            }
          }
        },
        // 对接人数量
        {
          prop: 'counterpartNum',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.numberOfCounterpart,
          width: '90px'
        },
        // 盖章方式
        {
          prop: 'stampWay',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.stampingMethod,
          width: '120px',
          format: function (row) {
            if (row.stampWay === '1') {
              return '电子章'
            } else if (row.stampWay === '2') {
              return '鲜章'
            } else if (row.stampWay === '1,2' || row.stampWay === '2,1') {
              return '电子章&鲜章'
            }
          }
        },
        // 核心企业
        {
          prop: 'coreEnterpriseName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.coreEnterprise,
          width: '120px'
        },
        // 计划管理人/再保理银行
        {
          prop: 'planOrBankName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.financialInstitutions,
          width: '180px'
        },
        // 期数/提单日期
        {
          prop: 'periodDate',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.periodDate,
          width: '120px'
        },
        // 分配类型
        {
          prop: 'allocationType',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.allocationType,
          width: '120px'
        },
        // 是否申请重新分配
        {
          prop: 'applyReallocationFlag',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.whetherToApplyForReallocation,
          width: '140px',
          format: function (row) {
            if (row.applyReallocationFlag === '0') {
              return '否'
            } else if (row.applyReallocationFlag === '1') {
              return '是'
            }
          }
        }
      ]
    }
  },
  methods: {
    taskSure () {
      debugger
      let $this = this
      $this.loading = true
      tracemgrApi['formalOrderList'].temporarySave($this.valueData).then(res => {
        if (res.data) {
          this.confirmDialog = false
          $this.success(this.$i18n.messages[this.$i18n.locale].common.saveSuccess)
          this.handler()
        } else {
          this.confirmDialog = false
          $this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.saveFailedMakeSure)
        }
      }).catch(() => {
        this.confirmDialog = false
        $this.error(this.$i18n.messages[this.$i18n.locale].common.saveFailed)
      })
      this.confirmDialog = false
      $this.num = 0
      $this.currentCreditor = ''
      $this.loading = false
    },
    closeSure () {
      this.confirmDialog = false
      this.num = 0
      this.currentCreditor = ''
      this.loading = false
      for (let i = 0; i < this.tableData.length; i++) {
        this.tableData[i].factoringUserId = this.tableDataCopy[i]
      }
    },
    onMouse: function (val) {
      val.orderType = this.orderType
      let $this = this
      this.loading2 = true
      tracemgrApi['formalOrderList'].getOrderList(val).then(res => {
        if (res.data.length > 0) {
          $this.orderListData = res.data
          this.loading2 = false
        } else {
          $this.orderListData = []
          this.loading2 = false
        }
      }).catch(() => {
        this.loading2 = false
        $this.error(this.$i18n.messages[this.$i18n.locale].common.saveFailed)
      })
      this.seen = true
    },
    onLeave: function () {
      debugger
      this.seen = false
    },
    handler () {
      this.handleFilter()
    },
    handleFilter () {
      this.loadCount = this.loadCount + 1
    },
    clearParam () {
      for (let key in this.searchFormQueryParas) {
        this.searchFormQueryParas[key] = ''
      }
      this.queryParas = {
        pageIndex: 1,
        pageSize: 10,
        optDifficultyLevel: ['', ''],
        orderType: '2',
        allocationStatus: ['1', '2']
      }
    },
    changeValue: function (val) {
      this.$set(this.queryParas, 'optDifficultyLevel', val)
    },
    showBusinessDataStatisticsDialog () {
      this.businessDataStatisticsDialog = true
    },
    showDistributionOrderDialog (value) {
      if (this.company.length === 0) {
        this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.leastSelectOne)
        return
      }
      this.$refs.disOrDialog.selectData(this.company)
      this.distributionOrderDialog = true
    },
    showDistributionOrderPreviewDialog () {
      this.$refs.previewOrderDialog.searchData(this.queryParas)
      this.distributionOrderPreviewDialog = true
    },
    showImportPreDistributionOrderDialog () {
      this.importPreDistributionOrderDialog = true
    },
    selectionData (value) {
      this.company = value
    },
    backData () {
    },
    confirmDistribution () {
      if (this.company.length === 0) {
        this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.leastSelectOne)
        return
      }
      let flag = true
      this.company.forEach((item, index) => {
        if (flag) {
          if (item.allocationStatus !== '2') {
            flag = false
            this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.errorMessage)
          }
        }
      })
      debugger
      if (flag) {
        this.confirmDistributionOrderDialog = true
      }
    },
    deleteBtn () {
      if (this.company.length === 0) {
        this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.leastSelectOne)
        return
      }
      let keyIds = ''
      let assetCodes = ''
      let asset = []
      let ifsImports = ''
      let ifs = []
      let showData = ''
      let delIds = []
      let ids = ''
      this.company.forEach((item, index) => {
        keyIds += item.keyId + ','
        assetCodes += item.assetCode + ','
        ifsImports += item.ifsImport + ','
      })
      asset = assetCodes.split(',')
      ifs = ifsImports.split(',')
      delIds = keyIds.split(',')
      ifs.forEach((item, index) => {
        if (item === '1') {
          ids += delIds[index] + ','
        }
        if (item === '0') {
          showData += asset[index] + ','
        }
      })
      if (ids === '') {
        this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.errorMessage2)
        return
      }
      let msg = this.$i18n.messages[this.$i18n.locale].traceMgr.errorMessage3
      // if (showData !== '') {
      //   msg = '此操作将永久删除该数据, 是否继续？ 订单：' + showData + '为非导入数据，不执行删除操作！'
      // }
      this.$confirm(msg, this.$i18n.messages[this.$i18n.locale].common.tip, {
        confirmButtonText: this.$i18n.messages[this.$i18n.locale].traceMgr.sure,
        cancelButtonText: this.$i18n.messages[this.$i18n.locale].approval.cancel,
        type: 'warning'
      }).then(() => {
        if (showData !== '') {
          this.warning(this.$i18n.messages[this.$i18n.locale].traceMgr.errorMessage4 + showData + this.$i18n.messages[this.$i18n.locale].traceMgr.errorMessage5)
        }
        tracemgrApi['preDistributionOrderList'].deleteData({ keyIds: ids }).then(res => {
          if (res.data) {
            // this.success(this.$i18n.messages[this.$i18n.locale].common.deleteSuccess)
            this.handleFilter()
            this.$message({
              type: 'success',
              message: this.$i18n.messages[this.$i18n.locale].common.deleteSuccess
            })
          } else {
            this.error(this.$i18n.messages[this.$i18n.locale].common.deleteFailed)
          }
        }).catch(() => {
          this.error(this.$i18n.messages[this.$i18n.locale].common.deleteFailed)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: this.$i18n.messages[this.$i18n.locale].traceMgr.errorMessage6
        })
      })
    },
    queryData () {

    },
    selectChanged (v, a, b) {
      if (v !== '') {
        let $this = this
        let aa = a.split('|')
        let param = { }
        let val = []
        // let flag = false
        let item = this.sourceData[aa[0]]
        let name = b.nickName
        // 如果选择的保理专员和数据比对是同一个就不做修改
        if (aa[1] === v) {
          // return // this.error('请确认，当前记录已经修改为:' + item.factoringUserName)
        }
        let currentStatus = item.allocationStatus
        // 获取当前数据记录的供应商的状态，以及相同供应商的记录
        let currentCreditorId = item.creditorId
        $this.currentCreditor = item.creditor
        let numer = 0
        // 新增需求
        this.sourceData.forEach((im, index) => {
          // 1、（当前页条数）若当前操作记录，状态已经是已分配，在点选择修改专员时，“相同供应商”的都做保理专员修改
          if (currentStatus === '3') {
            if (currentCreditorId === im.creditorId) {
              param = { productId: im.productId, productName: im.productName, creditorId: im.creditorId, factoringUserId: v, factoringUserName: name, assetCode: im.assetCode }
              val.push(param)
              numer++
            }
          }
          // 2、（当前页条数）若当前操作记录，状态不是已分配，在修改保理专员时，对“相同供应商非已分配”状态的数据，做保理专员修改操作
          if (currentStatus !== '3') {
            if (currentCreditorId === im.creditorId && im.allocationStatus !== '3') {
              param = { productId: im.productId, productName: im.productName, creditorId: im.creditorId, factoringUserId: v, factoringUserName: name, assetCode: im.assetCode }
              val.push(param)
              numer++
            }
          }
        })
        let data = { list: val, orderType: this.orderType, mode: '1' }
        $this.valueData = data
        if (numer > 0) {
          numer = numer - 1
          // numer等于0  只有一条数据，不弹出提示框，直接分配
          if (numer === 0) {
            tracemgrApi['formalOrderList'].temporarySave(data).then(res => {
              if (res.data) {
                this.confirmDialog = false
                $this.success(this.$i18n.messages[this.$i18n.locale].common.saveSuccess)
                this.handler()
              } else {
                this.confirmDialog = false
                $this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.saveFailedMakeSure)
              }
            }).catch(() => {
              this.confirmDialog = false
              $this.error(this.$i18n.messages[this.$i18n.locale].common.saveFailed)
            })
          }
          // numer 大于0  多条需要提示是否分配
          if (numer > 0) {
            // 显示其他数量
            $this.num = numer
            this.confirmDialog = true
          }
        }
      }
    },
    getTableData (data) {
      this.tableDataCopy = []
      this.tableData = data
      for (let i = 0; i < data.length; i++) {
        this.tableDataCopy.push(data[i].factoringUserId)
      }
    }
  },
  mounted () {
    this.handleFilter()
  },
  computed: {
    api () {
      return tracemgrApi['preDistributionOrderList']
    }
  }
}
</script>
