<template>
  <!--跟单记录表-->
  <div>
    <up-down-layout :handleFlag.sync="handleFlag">
      <!--搜索表单-->
      <search-form
                   @clearParam="clearParam"
                   @handleFilter="handleFilter()"
                   searchPerms="search"
                   @getTableData = "getTableData"
                   resetPerms="reset"
                   :formValue.sync="queryParas"
                   v-model="queryParas"
                   :componentList="componentList"
                   slot="query">
      </search-form>
      <!--数据列表-->
      <template slot="table">
        <data-table :menuCode="menuId"
                    :cellStyle="cellStyle"
                    :border="true"
                    :stripe="true"
                    :menuFlag="true"
                    :queryParas="queryParas"
                    :api="api"
                    :handleFlag.sync="handleFlag"
                    :showSelection="true"
                    @selectRowChange="selectionData"
                    v-bind="elHeightObj"
                    :sourceData.sync="formTableData.sourceData"
                    :loadCount.sync="loadCount"
                    :columns="columns"
                    :operateBtnLayout="operateBtnLayout">

          <!--按钮-->
          <template slot="headButton">
            <el-col :span="24" class="textRight">
              <auth-button type="primary" size="medium" @click="batchFilling()"
                           :label="$t('traceMgr.batchFilling')" class="iconfont iconpiliangbanli"></auth-button>
              <auth-button type="primary" size="medium" @click="initiatingCancellation()"
                           :label="$t('traceMgr.initiatingCancellation')" class="iconfont iconfaqituidan"></auth-button>
              <auth-button type="primary" size="medium" @click="batch_export()"
                           :label="$t('common.export')" class="iconfont icondaochu"></auth-button>
              <auth-button type="primary" size="medium" @click="directSave()" :loading="saveLoading"
                           :label="$t('common.save')" class="iconfont iconbaocun11"></auth-button>
            </el-col>
          </template>

          <!--操作-->
          <el-table-column :label="$t('common.operate')" align="center" fixed="right" :width="180">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" :content="$t('common.OrderRecord')" placement="top">
                <el-button @click="openFactoringDialog(scope.row)" class="iconfont iconlvli" circle size="mini">
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
          <!--tracemgr_regional_commissioner_status-->
          <template slot="regionalCommissionerStatus" slot-scope="scope" v-if="scope.data.row.businessProcessState!=undefined && scope.data.row.businessProcessState!=''">
            <select-commissioner-status @focus="getFocus"   :queryParas="{sysStatuCode:scope.data.row.businessProcessState}" @selectChanged="saveStatusChange" v-model="scope.data.row.regionalCommissionerStatus"></select-commissioner-status>
          </template>

<!--          <template slot="regionalCommissionerRemarks" slot-scope="scope">-->
<!--            <el-input type="textarea" @focus="getFocus"  :rows="2" size="mini" v-model="scope.data.row.regionalCommissionerRemarks" @change="saveStatusChange" maxlength="100"></el-input>-->
<!--          </template>-->

          <template slot="regionalCommissionerRemarks"  slot-scope="scope">
            <el-tooltip placement="top"  v-if="scope.data.row.regionalCommissionerRemarks !== ''&& scope.data.row.regionalCommissionerRemarks !== null && scope.data.row.regionalCommissionerRemarks !== undefined">
              <div slot="content" >{{scope.data.row.regionalCommissionerRemarks}}</div>
              <span>
                <el-input type="textarea" @focus="getFocus"  :rows="2" size="mini" v-model="scope.data.row.regionalCommissionerRemarks" @change="saveStatusChange" maxlength="100"></el-input>
              </span>
            </el-tooltip>
            <el-input  v-if="scope.data.row.regionalCommissionerRemarks === '' || scope.data.row.regionalCommissionerRemarks === null || scope.data.row.regionalCommissionerRemarks === undefined" type="textarea" @focus="getFocus"  :rows="2" size="mini" v-model="scope.data.row.regionalCommissionerRemarks" @change="saveStatusChange" maxlength="100"></el-input>
          </template>

          <template slot="supplierCollectionInformation"  slot-scope="scope">
            <el-tooltip placement="top">
              <div slot="content"  v-if="scope.data.row.supplierCollectionInformation !== ''">{{scope.data.row.supplierCollectionInformation}}</div>
              <span>{{scope.data.row.supplierCollectionInformation}}</span>
            </el-tooltip>
          </template>
        </data-table>
      </template>
    </up-down-layout>
    <pre-refund-view :visible.sync="preRefundVisible" :form="item" :api="api" :resume_list="resume_list" preType="Pause"
                     @success="preRefundSuccess" editModel="V"
    ></pre-refund-view>
    <accountProof :visible.sync="fileListShow" :needComplete="true" :item="item" :editModel="editModel"></accountProof>
    <batch-operation-dialog :reload="reload" :visible.sync="dialogShow" :needComplete="true" :item="item"
                            :editModel="editModel"></batch-operation-dialog>
    <factoringInfoDetail :visible.sync="factoringInfoDialogShow" :keyId="assetInfoId" :needComplete="true" :title="$t('common.OrderRecord')"   :editModel="editModel"></factoringInfoDetail>
<!--    <supplierFile :visible.sync="factoringInfoDialogShow"></supplierFile>-->
    <!--加急订单 弹窗-->
    <!--        <manager-groups-urgentOrderList :visible.sync="urgentOrderList_show" :item="item" :needComplete="needComplete" :editModel="editModel" :form="item" @updateData="updateData"></manager-groups-urgentOrderList>-->
    <!--<batchOperationDialog></batchOperationDialog>-->
  </div>
</template>

<script>
import {
  DataTable,
  searchForm,
  SelectProductName,
  SelectCoreEnterprise,
  upDownLayout,
  SelectAddress,
  authButton,
  btnImport,
  btnBatchUpload,
  btnDownload,
  SelectAreaCommissioner,
  btnUpload,
  SelectDictionary,
  SelectSmallArea,
  BaseSelect, SelectPlanManager, SelectPeriodsCascade, SelectFactoringCommissioner, factoringInfoDetail
} from 'newepoch-components'
import taskDialog from '@/components/tracemgr/regionalCommissioner/TaskTable/confirmRightSealNotice/taskDialog.vue'
import accountProof
  from '@/components/tracemgr/factoringCommissioner/taskTable/taskManagement/situationDescriptionDialog.vue'
import tracemgrApi from '@/api/tracemgrApi.js'
import supplierFile from '@/components/tracemgr/factoringCommissioner/taskTable/abnormalHandle/abnormalHandlePage'
import preRefundView from '@/pages/tuidan/chargeback/factoring-refund/preRefundView'
import batchOperationDaterange
  from '@/components/tracemgr/regionalCommissioner/workbench/orderTrack/batchOperationDaterange.vue'
import batchOperationDialog
  from '@/components/tracemgr/regionalCommissioner/workbench/orderTrack/batchOperationDialog.vue'
import commissionerStatusForBusinessProcess
  from '@/components/tracemgr/regionalCommissioner/workbench/orderTrack/commissionerStatusForBusinessProcess.vue'
import BasePage from '@/pages/basePage'
import SelectCommissionerStatus from '@/components/tracemgr/common/SelectCommissionerStatus'
import * as format from '@/filters/index'
import mixin from '@/pages/mixin'
import fileApi from '@/api/fileApi.js'
import { downFile } from '@/utils/devUtils'
import SelectFlag from '@/components/tracemgr/common/SelectFlag'

export default {
  props: {
    checkDataSourceList: {
      type: Boolean
    }
  },
  extends: new BasePage(),
  mixins: [mixin],
  name: 'orderTrackList',
  components: {
    SelectDictionary,
    BaseSelect,
    preRefundView,
    tracemgrApi,
    SelectPlanManager,
    SelectPeriodsCascade,
    supplierFile,
    format,
    SelectCommissionerStatus,
    factoringInfoDetail,
    commissionerStatusForBusinessProcess,
    DataTable,
    batchOperationDaterange,
    searchForm,
    SelectProductName,
    batchOperationDialog,
    upDownLayout,
    SelectAddress,
    taskDialog,
    accountProof,
    authButton,
    btnImport,
    btnBatchUpload,
    btnDownload,
    btnUpload,
    SelectFactoringCommissioner,
    SelectFlag,
    SelectAreaCommissioner
  },
  data () {
    return {
      item: {
        keyId: '',
        data: [],
        name: ''
      },
      userHaveFocus: false,
      loginId: '',
      assetInfoId: '',
      preRefundItem: {},
      preRefundVisible: false,
      resume_list: [],
      tableApi: {},
      dialogShow: false,
      sourceData: {},
      fileListShow: false,
      urgentOrderList_show: false,
      TheRegionalCommissionerStatusId: '',
      remarks: '',
      factoringInfoDialogShow: false,
      taskDialogShow: false,
      saveLoading: false,
      queryParas: {
        isLending: '0', // 默认为放款
        pageIndex: 1, // 当前页
        pageSize: 10,
        sectionNumber: '',
        paymentConfirmationNo: '',
        theRegionalCommissionerStatus: '',
        coreEnterprise: '',
        financialInstitutions: '',
        periods: '',
        region: '',
        nameOfProjectCompany: '',
        supplierName: '',
        businessProcessState: '',
        factoringCommissioner: '',
        factoringCommissionerStatus: '',
        fileStatus: '',
        fileState: '',
        dateOfBaoLi: '',
        abnormalSituation: '',
        regionalCommissionerId: [this.$store.getters.userId]
      },
      componentList: [
        //= =================1==================
        // 区域编号
        {
          value: 'sectionNumber',
          componentName: 'el-input',
          name: 'sectionNumber',
          label: this.$i18n.messages[this.$i18n.locale].common.sectionNumber,
          prop: 'sectionNumber',
          labelWidth: '100px',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].common.sectionNumber
        },
        // 付款确认书编号
        {
          value: 'paymentConfirmationNo',
          componentName: 'el-input',
          name: 'paymentConfirmationNo',
          label: this.$i18n.messages[this.$i18n.locale].common.paymentConfirmationNo,
          prop: 'paymentConfirmationNo',
          labelWidth: '160px',
          maxlength: 60,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].common.paymentConfirmationNo
        },
        // 区域专员状态
        {
          value: 'theRegionalCommissionerStatus',
          disabled: false,
          componentName: SelectDictionary,
          dictTypeCode: 'tracemgr_factoring_commissioner_status',
          multiple: true,
          name: 'theRegionalCommissionerStatus',
          label: this.$i18n.messages[this.$i18n.locale].common.TheRegionalCommissionerStatus,
          prop: 'theRegionalCommissionerStatus',
          filterable: true,
          labelWidth: '160px'
        },

        //= =================2==================
        // 核心企业
        {
          value: 'coreEnterprise',
          disabled: false,
          componentName: SelectCoreEnterprise,
          label: this.$i18n.messages[this.$i18n.locale].common.coreEnterprise,
          prop: 'coreEnterprise',
          labelWidth: '100px',
          multiple: true
        },
        // 计划管理人/再保理银行
        {
          value: 'financialInstitutions',
          componentName: SelectPlanManager,
          name: 'financialInstitutions',
          multiple: true,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.financialInstitutions,
          prop: 'financialInstitutions',
          labelWidth: '160px'
        },
        // 期数
        {
          value: 'periods',
          name: 'periods',
          label: this.$i18n.messages[this.$i18n.locale].common.periods,
          cols: [24, 24, 24, 24],
          prop: 'periods',
          labelWidth: '160px',
          componentName: SelectFlag,
          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 }],
          multiple: true
        },

        //= =================3==================
        // 区域
        {
          value: 'region',
          componentName: SelectSmallArea,
          disabled: false,
          name: 'region',
          multiple: true,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.region,
          prop: 'region',
          labelWidth: '100px'
        },
        // 项目公司名称
        {
          value: 'nameOfProjectCompany',
          disabled: false,
          maxlength: 60,
          componentName: 'el-input',
          name: 'nameOfProjectCompany',
          label: this.$i18n.messages[this.$i18n.locale].common.nameOfProjectCompany,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].common.nameOfProjectCompany,
          prop: 'nameOfProjectCompany',
          labelWidth: '160px'
        },
        // 供应商名称
        {
          value: 'supplierName',
          disabled: false,
          componentName: 'el-input',
          name: 'supplierName',
          label: this.$i18n.messages[this.$i18n.locale].common.supplierName,
          prop: 'supplierName',
          labelWidth: '160px',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].common.supplierName
        },

        //= =================4==================
        // 业务流程状态
        {
          value: 'businessProcessState',
          disabled: false,
          componentName: 'SelectDictionary',
          multiple: true,
          dictTypeCode: 'tracemgr_business_process_status',
          name: 'businessProcessState',
          label: this.$i18n.messages[this.$i18n.locale].common.businessProcessState,
          prop: 'businessProcessState',
          filterable: true,
          labelWidth: '100px'
        },
        // 保理专员
        {
          value: 'factoringCommissioner',
          componentName: SelectFactoringCommissioner,
          multiple: true,
          name: 'factoringCommissioner',
          dictTypeCode: 'tracemgr_abnormal_status',
          label: this.$i18n.messages[this.$i18n.locale].common.factoringCommissioner,
          prop: 'factoringCommissioner',
          labelWidth: '160px'
          // type: 'daterange'
        },
        // 保理专员状态
        {
          value: 'factoringCommissionerStatus',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'tracemgr_factoring_commissioner_status',
          multiple: true,
          name: 'factoringCommissionerStatus',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringCommissionerStatus,
          prop: 'factoringCommissionerStatus',
          filterable: true,
          labelWidth: '160px'
        },

        //= =================5==================
        // 履约文件状态
        {
          value: 'fileStatus',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'performance_document_status',
          name: 'fileStatus',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.fileStatus,
          prop: 'fileStatus',
          multiple: true,
          labelWidth: '100px'
        },
        // 确权文件状态
        {
          value: 'fileState',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'tracemgr_confirmation_document_status',
          name: 'fileState',
          label: this.$i18n.messages[this.$i18n.locale].common.QQFileStatus,
          prop: 'fileState',
          multiple: true,
          filterable: true,
          labelWidth: '160px'
        },
        // 保利申请日期
        {
          value: 'dateOfBaoLi',
          disabled: false,
          componentName: batchOperationDaterange,
          name: 'dateOfBaoLi',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.dateOfApplication,
          prop: 'dateOfBaoLi',
          type: 'daterange',
          format: 'yyyy-MM-dd',
          placeholder: this.$i18n.messages[this.$i18n.locale].traceMgr.startAndEndTime,
          labelWidth: '160px'
        },

        //= =================6==================
        // 异常情况
        {
          value: 'abnormalSituation',
          disabled: false,
          componentName: 'SelectDictionary',
          multiple: true,
          dictTypeCode: 'tracemgr_abnormal_situation',
          name: 'abnormalSituation',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.abnormalSituation,
          prop: 'abnormalSituation',
          labelWidth: '100px'
        },
        {
          value: 'regionalCommissionerId',
          componentName: SelectAreaCommissioner,
          label: this.$i18n.messages[this.$i18n.locale].common.theRegionalCommissioner,
          labelWidth: '160px',
          multiple: true,
          filterable: true
        },
        // 是否已放款
        {
          value: 'isLending',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'yes_or_no_dangan',
          name: 'isLending',
          label: this.$i18n.messages[this.$i18n.locale].common.isLending,
          prop: 'isLending',
          labelWidth: '160px'
        }
      ],
      handleFlag: true,
      // 保理专员状态所有的key-value
      factoringCommissionerStatusArray: [],
      formTableData: {
        sourceData: []
      },
      selectedRows: [],
      loadPage: 'getList',
      loadCount: 0,
      operateBtnLayout: '',
      // 表头
      columns: [
        // 付款确认书编号
        {
          prop: 'paymentConfirmationNo',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.paymentConfirmationNo,
          showOverflowTooltip: true,
          width: '240px',
          fixed: 'left'
        },
        // 区域
        {
          prop: 'district',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.district,
          showOverflowTooltip: true,
          width: 100,
          fixed: 'left'
        },
        // 项目公司
        {
          prop: 'projectCompany',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.projectCompany,
          showOverflowTooltip: true,
          width: 200
        },
        // 区域编号
        {
          prop: 'sectionNumber',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.sectionNumber,
          showOverflowTooltip: true,
          width: '100px'
        },
        // 区域专员
        {
          prop: 'customerTypeName',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.theRegionalCommissioner,
          showOverflowTooltip: true,
          width: 150
        },
        // 业务流程状态
        {
          prop: 'businessProcessName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.businessProcessState,
          showOverflowTooltip: true,
          width: '220px',
          format: (row) => {
            if (row.businessProcessStateName !== null && row.businessProcessStateName !== '' && row.businessProcessStateName !== undefined) {
              return row.businessProcessStateName.replace(/[,]/g, ',\r\n')
            }
          }
        },
        // 区域专员状态
        {
          prop: 'regionalCommissionerStatus',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.TheRegionalCommissionerStatus,
          showOverflowTooltip: true,
          width: '200px',
          slot: true
        },
        // 区域专员备注
        {
          prop: 'regionalCommissionerRemarks',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].common.TheRegionalCommissionerRemarks,
          showOverflowTooltip: true,
          width: 250,
          slot: true
        },
        // 核心企业
        {
          prop: 'coreEnterprise',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.coreEnterprise,
          showOverflowTooltip: true,
          width: '200px'
        },
        // 计划管理人/再保理银行
        {
          prop: 'financialInstitutions',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.financialInstitutions,
          showOverflowTooltip: true,
          width: '200px'
        },
        // 产品
        {
          prop: 'product',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.product,
          showOverflowTooltip: true,
          width: 200
        },
        // 期数
        {
          prop: 'periods',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.periods,
          showOverflowTooltip: true,
          width: '50px'
        },
        // 供应商
        {
          prop: 'supplier',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.supplier,
          showOverflowTooltip: true,
          width: '200px'
        },
        // 应收账款金额
        {
          prop: 'amountOfReceivables',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.amountOfReceivables,
          showOverflowTooltip: true,
          width: '200px',
          format: (row) => {
            if (row.amountOfReceivables === undefined || row.amountOfReceivables === '') {
              return ''
            }
            return format.thousandFilter(row.amountOfReceivables) + '元'
          }
        },
        // 发票号码
        {
          prop: 'invoiceNum',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.invoiceNum,
          showOverflowTooltip: true,
          width: '200px'
        },
        // 供应商收款信息
        {
          prop: 'supplierCollectionInformation',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.SupplierCollectionInformation,
          // showOverflowTooltip: true,
          slot: true,
          width: '200px'
        },
        // 保理专员
        {
          prop: 'factoringCommissioner',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringCommissioner,
          showOverflowTooltip: true,
          width: '200px'
        },
        // 保理专员状态
        {
          prop: 'factoringCommissionerStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringCommissionerStatus,
          showOverflowTooltip: true,
          width: '200px',
          format: (row) => {
            if (row.factoringCommissionerStatus === '' || row.factoringCommissionerStatus === undefined || row.factoringCommissionerStatus === null) {
              return ''
            } else {
              let factoringCommissionerStatus = this.factoringCommissionerStatusArray.find(val => { return val && val.k === row.factoringCommissionerStatus })
              if (factoringCommissionerStatus) {
                return factoringCommissionerStatus.v
              } else {
                return ''
              }
            }
          }
        },
        // 保理专员备注
        {
          prop: 'commissionerRemarks',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.CommissionerRemarks,
          showOverflowTooltip: true,
          width: '300px',
          slot: true
        },
        // 履约文件状态
        {
          prop: 'fileStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.fileStatus,
          showOverflowTooltip: true,
          width: '120px',
          format: (row) => {
            if (row.fileStatus !== '0') {
              return format.formatDict(row.fileStatus + '', 'performance_document_status')
            }
          }
        },
        // 确权文件状态
        {
          prop: 'fileState',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.QQFileStatus,
          showOverflowTooltip: true,
          width: '120px',
          format: (row) => {
            return format.formatDict(row.fileState + '', 'tracemgr_confirmation_document_status')
          }
        },
        // 保理费率
        {
          prop: 'baoLiRate',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.BAOLIRate,
          showOverflowTooltip: true,
          width: '100px'
        },
        // 保理申请日期
        {
          prop: 'dateOfBaoLi',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.dateOfApplication,
          showOverflowTooltip: true,
          width: '120px'
        },
        // 异常情况
        {
          prop: 'abnormalStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.abnormalStatus,
          showOverflowTooltip: true,
          // format: (row) => {
          //   return format.formatDict(row.abnormalStatus + '' === 'undefined' ? '' : row.abnormalStatus + '', 'tracemgr_abnormal_situation')
          // },
          width: '200px',
          fixed: 'right'
        }
      ],
      dataChanged: true,
      selectData: false,
      user: []
    }
  },
  watch: {
    'formTableData.sourceData': {
      deep: true,
      handler: function () {
        if (this.selectData) {
          this.dataChanged = false
          this.selectData = false
        } else {
          this.dataChanged = true
        }
        if (this.dataChanged) {
          for (const argument of this.formTableData.sourceData) {
            if (argument.regionalCommissionerRemarksCopy === '') {
              argument.regionalCommissionerRemarksCopy = undefined
            }
            if (argument.regionalCommissionerRemarks === '') {
              argument.regionalCommissionerRemarks = undefined
            }

            if (argument.regionalCommissionerRemarks !== argument.regionalCommissionerRemarksCopy) {
              this.$emit('listData', true)
              return
            }
          }
        }

        this.$emit('listMessageColse', false)
      }
    }
  },
  created () {
    this.getFactoringCommissionerStatus()
  },
  methods: {
    // 重置检索表单
    clearParam () {
      this.user = []
      this.user.push(this.$store.getters.userId)
      this.queryParas = {
        pageIndex: 1,
        pageSize: 10,
        sectionNumber: '',
        paymentConfirmationNo: '',
        theRegionalCommissionerStatus: [],
        coreEnterprise: [],
        financialInstitutions: [],
        periods: [],
        region: [],
        nameOfProjectCompany: '',
        supplierName: '',
        businessProcessState: [],
        factoringCommissioner: [],
        factoringCommissionerStatus: [],
        fileStatus: [],
        fileState: [],
        dateOfBaoLi: '',
        abnormalSituation: [],
        isLending: '0',
        regionalCommissionerId: this.user
      }
    },
    batchFilling () {
      let selectedRows = this.selectedRows
      let orderArr = []
      if (selectedRows.length > 0) {
        // 循环选中的列
        for (var i = 0; i < selectedRows.length; i++) {
          let item = selectedRows[i]
          if (item.businessProcessState === undefined ||
              item.businessProcessState === null ||
              item.businessProcessState === ''
          ) {
            this.warning(this.$i18n.messages[this.$i18n.locale].common.emptyDataNotOperating)
            return
          } else if (i > 0 && (orderArr[0].businessProcessState !== item.businessProcessState)) {
            this.warning(this.$i18n.messages[this.$i18n.locale].common.sameTalent)
            return
          } else {
            // 封装数据
            orderArr.push({
              keyId: item.assetInfoId,
              coreAreaAttache: item.coreAreaAttache,
              businessProcessState: item.businessProcessState,
              assetCode: item.assetCode,
              assetPoolId: item.assetPoolId,
              status: item.regionalCommissionerStatus,
              remark: item.regionalCommissionerRemarks,
              dealPersonType: '2'
            })
          }
        }
        this.item.data = orderArr
        this.item.keyId = orderArr[0].businessProcessState
        this.dialogShow = true
      } else {
        this.error(this.$i18n.messages[this.$i18n.locale].common.alarmDel)
      }
    },
    initiatingCancellation () {
      if (!this.selectedRows.length) return this.warning(this.$i18n.messages[this.$i18n.locale].traceMgr.notHavneData)
      this.resume_list = []
      this.selectedRows.forEach(item => {
        let data = {
          assetInfoId: item.assetInfoId,
          assetPoolId: item.assetPoolId,
          projectName: item.product,
          coreEnterpriseName: item.coreEnterprise,
          planOrBankName: item.financialInstitutions,
          specialPlanPeriods: item.periods,
          regionCode: item.sectionNumber,
          assetCode: item.paymentConfirmationNo,
          debtor: item.projectCompany,
          creditor: item.supplier,
          factoringMoney: item.amountOfReceivables,
          factoringRate: (parseFloat(item.baoLiRate.split('%')[0]) / 100).toFixed(4)
        }
        this.resume_list.push(data)
      })
      this.preRefundVisible = true
    },
    batch_export () {
      let $this = this
      $this.loading = true
      tracemgrApi['orderTrackApi'].excelExport(this.queryParas).then(res => {
        if (res.success) {
          fileApi.file.download({ keyId: res.data }).then(res => {
            downFile(res)
            $this.loading = false
          }).catch(() => {
            $this.loading = false
          })
        } else {
          $this.loading = false
          $this.error(this.$i18n.messages[this.$i18n.locale].ladingManageList.exportFaile)
        }
      }).catch(() => {
        $this.loading = false
      })
    },
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      return ''
    },
    preRefundSuccess () { // 退单成功的回调
      this.loadCount++
    },
    reload: function () {
      this.handleFilter()
    },
    directSave: function () {
      let orderArr = []
      let $this = this
      this.formTableData.sourceData.forEach(item => {
        // 封装数据
        orderArr.push({
          keyId: item.assetInfoId,
          assetCode: item.assetCode,
          assetPoolId: item.assetPoolId,
          coreAreaAttache: item.coreAreaAttache,
          status: item.regionalCommissionerStatus,
          remark: item.regionalCommissionerRemarks,
          dealPersonType: '2'
        })
      })
      this.saveLoading = true
      tracemgrApi['batchOperationApi'].batchSave(orderArr).then(res => {
        if (res.data) {
          this.success(this.$i18n.messages[this.$i18n.locale].common.saveSuccess)
          this.dialogVisible = false
          $this.saveLoading = false
          this.$emit('setNeedSave', false)
          this.handleFilter()
        } else {
          $this.saveLoading = false
        }
      }, res => {
        $this.saveLoading = false
      })
    },
    openFactoringDialog: function (row) {
      this.assetInfoId = ''
      this.assetInfoId = row.assetInfoId
      this.item = row
      this.factoringInfoDialogShow = true
    },
    // 查询列表中保理专员状态所有的key-value
    getFactoringCommissionerStatus () {
      tracemgrApi['commonApi'].getCommissionerStatusList().then(res => {
        if (res) {
          this.factoringCommissionerStatusArray = res.data
        }
      })
    },
    handleFilter () {
      this.selectData = true
      this.loadCount = this.loadCount + 1
    },
    saveStatusChange () {
      if (this.userHaveFocus) {
        this.$emit('setNeedSave', true)
      }
    },
    getTableData () {
      this.$emit('setNeedSave', false)
      this.userHaveFocus = false
    },
    getFocus () {
      this.userHaveFocus = true
    }
  },
  mounted () {
    this.selectData = true
    // let list = this.componentList
    // tracemgrApi['orderTrackApi'].getLoginId().then(item => {
    //   tracemgrApi['orderTrackListApi'].getfactoringCommissionerList().then(res => {
    //     let data = []
    //     // let userId = item.data.userId
    //     let flag = true
    //     for (let i = 0; i < res.data.length; i++) {
    //       let r = res.data[i]
    //       if (flag && r.userId === item.data.userId) {
    //         const o = { value: r.userId, label: r.nickName }
    //         data.splice(0, 0, o)
    //         flag = false
    //         continue
    //       }
    //       const o = { value: r.userId, label: r.nickName }
    //       data.push(o)
    //     }
    //
    //     let obj = {
    //       value: 'regionalCommissionerId',
    //       componentName: SelectFlag,
    //       label: this.$i18n.messages[this.$i18n.locale].common.theRegionalCommissioner,
    //       labelWidth: '160px',
    //       options: data,
    //       multiple: true,
    //       filterable: true
    //     }
    //
    //     this.user = [item.data.userId]
    //     this.queryParas = { regionalCommissionerId: [item.data.userId], pageIndex: 1, pageSize: 10 }
    //     this.componentList.splice(16, 0, obj)
    //
    //     this.handleFilter()
    //   })
    // })
    this.handleFilter()
  },
  computed: {
    api () {
      return tracemgrApi['batchOperationApi']
    }
  }
}
</script>
<style scoped>
    @import '~@/styles/tracemgr/factoringCommissioner/workbench/orderTrack/orderTrackList.scss'
</style>
