<template>
  <!--业务流程任务-->
  <div>
    <up-down-layout :handleFlag.sync="handleFlag">

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

          <!--按钮-->
          <template slot="headButton">
            <el-col :span="24" class="textRight">
              <el-dropdown class="marginRight1">
                <el-button type="primary" size="medium" class="iconfont iconlianjie">
                  {{$t('traceMgr.oftenLink')}}<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native="oftenLink(item.linksUrl)" v-for="item in otLinks" :key="item.linksName">{{item.linksName}}</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <auth-button type="primary" size="medium" @click="initiateTask"
                           :label="$t('common.initiateTask')" class="iconfont iconfaqi"></auth-button>
              <auth-button type="primary" size="medium" @click="togetherDeal"
                           :label="$t('traceMgr.togetherDeal')" class="iconfont iconhebing"></auth-button>
            </el-col>
          </template>

          <!--操作-->
          <el-table-column :label="$t('common.operate')" align="center" fixed="right">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" :content="$t('approval.columnName')" placement="top">
                <el-button v-if="scope.row.taskStatus !== '3' || scope.row.taskType === $t('traceMgr.generateTheSituation') || getTracemgrDebugger()" circle size="mini" @click="doAction(scope.row)" class="iconfont iconbanli-active"></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </data-table>
      </template>
    </up-down-layout>
    <!-- 律所反馈 -->
    <law-firm-task-dialog :visible.sync="lawFirmTaskDialogShow" :assetInfoId="assetInfoId" :taskId="taskId" :assetCode="assetCode" :lawFirmTaskType="lawFirmTaskType" :handler="handler"></law-firm-task-dialog>

    <!--通知供应商盖章-->
    <supplier-seal-notice :visible.sync="sealNoticeVisible"  :form="form"  :handler="handler"></supplier-seal-notice>
    <!--线上审核反馈-->
    <online-audit :visible.sync="onlineAuditVisible" :taskName="taskType" :supplierId="creditorId" :instanceId="instanceId" :createTime="createTime" :assetCode="assetCode" :taskId="taskId" :handler="handler"></online-audit>
    <!--   发起任务   -->
    <sanning-copy-receiving-dialog :serviceTask="false" :pageFlag="true" :visible.sync="sanningDialogShow" :form="form"></sanning-copy-receiving-dialog>

    <!--   通知供应商核对及补充资料   -->
    <supplier-supplementary-information  :visible.sync="checkDialogShow"   :form="form" :handler="handler"></supplier-supplementary-information>
    <!--   资料补寄异常   -->
    <supplier-file :visible.sync="supplierFileDialogShow" :form="form" :handler="handler"></supplier-file>

    <!--   添加供应商联系人   -->
    <add-supplier :visible.sync="addSupplierDialogShow"    :form="form"  :handler="handler"></add-supplier>
    <!--   生成情况说明   -->
    <generate-the-situation :visible.sync="generateVisible" :supplierId="creditorId" :factType="'2'" :form="form" :handler="handler" @updateData="updateData"></generate-the-situation>
    <!--   补出账确认任务   -->
    <supplementary-account-info :visible.sync="supplementaryVisible" :assetCode="assetCode" :args="args" :handler="handler" :assetInfoId="assetInfoId" :taskId="taskId" :assetPoolId="assetPoolId"></supplementary-account-info>
    <!-- 中登异常-->
    <abnormal-handle-page :assetInfoId="assetInfoId" :signFign="signFign" :assetCode="assetCode" :form="form" @updateData="updateData" :visible.sync="abnormalHandleVisible" ></abnormal-handle-page>

  </div>
</template>

<script>
import {
  DataTable,
  searchForm,
  SelectProductName,
  upDownLayout,
  SelectAddress,
  authButton,
  btnImport,
  btnBatchUpload,
  btnDownload,
  btnUpload,
  SelectDictionary,
  BaseSelect,
  SelectFinancialInstitutions,
  SelectCoreEnterprise
} from 'newepoch-components'
import supplierSealNotice from '@/components/tracemgr/factoringCommissioner/taskTable/supplierSealNotice/taskDialog'
import onlineAudit from '@/components/tracemgr/factoringCommissioner/taskTable/onlineAudit/taskDialog'
import taskDialog from '@/components/tracemgr/regionalCommissioner/TaskTable/confirmRightSealNotice/taskDialog.vue'
import batchOperationDaterange from '@/components/tracemgr/regionalCommissioner/workbench/orderTrack/batchOperationDaterange.vue'
import BasePage from '@/pages/basePage'
import tracemgrApi from '@/api/tracemgrApi'
import * as format from '@/filters/index'
import mixin from '@/pages/mixin'
import DatePicker from '@/components/element/DatePick.vue'
import amountFactoring from '@/components/element/amountFactoring.vue'
import lawFirmTaskDialog from '@/components/tracemgr/factoringCommissioner/taskTable/lawFirm/taskDialog.vue'
import sanningCopyReceivingDialog from '@/components/tracemgr/factoringCommissioner/workbench/orderTrack/sanningCopyReceivingDialog'
import SelectFlag from '@/components/tracemgr/common/SelectFlag'
import supplierSupplementaryInformation from '@/components/tracemgr/factoringCommissioner/taskTable/supplierSupplementaryInformation/taskDialog'
import supplierFile from '@/components/tracemgr/factoringCommissioner/taskTable/supplemenFile/fileList'
import addSupplier from '@/components/tracemgr/factoringCommissioner/taskTable/addSupplierContact/taskDialog'
import abnormalHandlePage from '@/components/tracemgr/factoringCommissioner/taskTable/abnormalHandle/abnormalHandlePage'
import generateTheSituation from '@/components/tracemgr/factoringCommissioner/taskTable/generateTheSituation/taskDialog'
import supplementaryAccountInfo from '@/components/tracemgr/factoringCommissioner/taskTable/supplementaryAccountInfo/taskDialog'
export default {
  extends: new BasePage(),
  mixins: [mixin],
  components: {
    supplierSealNotice,
    onlineAudit,
    sanningCopyReceivingDialog,
    SelectDictionary,
    BaseSelect,
    format,
    DataTable,
    batchOperationDaterange,
    searchForm,
    SelectProductName,
    abnormalHandlePage,
    upDownLayout,
    SelectAddress,
    taskDialog,
    tracemgrApi,
    authButton,
    btnImport,
    btnBatchUpload,
    btnDownload,
    btnUpload,
    SelectFlag,
    amountFactoring,
    lawFirmTaskDialog,
    SelectCoreEnterprise,
    supplierSupplementaryInformation,
    supplierFile,
    addSupplier,
    generateTheSituation,
    supplementaryAccountInfo
  },
  name: 'BusinessProcessTaskDialog',
  data () {
    return {
      lawFirmTaskType: '',
      taskType: '',
      addSupplierDialogComp: 'addSupplierDialogComp',
      assetInfoId: '',
      assetPoolId: '',
      createTime: '',
      checckDialogShow: false,
      assetCodeArr: [],
      signFign: '',
      selectRows: [],
      assetCodes: [],
      args: '',
      abnormalHandleVisible: false,
      generateVisible: false,
      supplementaryVisible: false,
      addSupplierDialogShow: false,
      supplierFileDialogShow: false,
      checkDialogShow: false,
      assetCode: '',
      creditorId: '',
      paramArray: [],
      instanceId: '',
      taskId: '',
      assetsId: '',
      form: {},
      popoverVisible: false,
      sanningDialogShow: false,
      nowSelectRow: [],
      lawFirmTaskDialogShow: false,
      sealNoticeVisible: false,
      onlineAuditVisible: false,
      tableLabel: this.$i18n.messages[this.$i18n.locale].common.operate,
      searchList: [
        // 核心企业
        {
          value: 'coreCompanyId',
          componentName: SelectCoreEnterprise,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.coreEnterprise,
          store: this.$store,
          labelWidth: '110px',
          multiple: true
        },
        // 计划管理人/再保理银行
        {
          value: 'financialInstitutionsId',
          disabled: false,
          componentName: SelectFinancialInstitutions,
          name: 'coreEnterpriseCascade',
          queryName: 'financialInstitutionsId',
          queryValue: 'financialInstitutionsId',
          label: this.$i18n.messages[this.$i18n.locale].common.programManager,
          cols: [24, 24, 24, 24],
          prop: 'financialInstitutionsId',
          labelWidth: '160px',
          multiple: true
        },
        // 期数
        {
          value: 'periodsCascadeId',
          componentName: SelectFlag,
          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 }],
          multiple: true
        },
        // 付款确认书编号
        {
          value: 'assetCode',
          componentName: 'el-input',
          label: this.$i18n.messages[this.$i18n.locale].common.paymentConfirmationNo,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].common.paymentConfirmationNo,
          labelWidth: '110px',
          clearable: true,
          maxlength: 40
        },
        // 供应商名称
        {
          value: 'creditor',
          componentName: 'el-input',
          label: this.$i18n.messages[this.$i18n.locale].common.supplierName,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input + this.$i18n.messages[this.$i18n.locale].common.supplierName,
          labelWidth: '160px',
          clearable: true,
          maxlength: 40
        },
        // 项目公司名称
        {
          value: 'debtor',
          componentName: 'el-input',
          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,
          labelWidth: '160px',
          clearable: true,
          maxlength: 40
        },
        // 保理金额
        {
          value: 'amount',
          componentName: amountFactoring,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringAmount,
          labelWidth: '110px'
        },
        // 任务类型
        {
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskType,
          value: 'taskType',
          labelWidth: '160px',
          dictTypeCode: 'tracemgr_abnormal_type_for_factoring_task_table', // 下拉值
          filterable: true,
          componentName: 'SelectDictionary',
          multiple: true
        },
        // 任务处理状态
        {
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskStatus,
          value: 'taskStatus',
          labelWidth: '160px',
          dictTypeCode: 'tracemgr_bpm_task_status', // 下拉值
          componentName: 'SelectDictionary'
        },
        // 任务发起时间
        {
          label: this.$i18n.messages[this.$i18n.locale].common.taskInitiationTime,
          value: 'startTime',
          componentName: DatePicker,
          type: 'daterange', // date ,week ,month ,year
          format: 'yyyy-MM-dd',
          labelWidth: '110px'
        },
        // 任务截止时间
        {
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskEndTime,
          value: 'taskEndTime',
          componentName: DatePicker,
          type: 'daterange',
          format: 'yyyy-MM-dd',
          labelWidth: '160px'
        }
      ],
      handleFlag: true,
      formTableData: {
        sourceData: []
      },
      loadCount: 0,
      operateBtnLayout: '',
      // 表头
      columns: [
        {
          prop: 'productInfo',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.productInformation,
          showOverflowTooltip: true,
          format: function (row) {
            if (row.specialPlanPeriods !== '' && row.specialPlanPeriods !== undefined) {
              return row.productInfo + '-' + row.specialPlanPeriods
            } else {
              return row.productInfo
            }
          },
          width: '400px'
        },
        {
          prop: 'assetCode',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.paymentConfirmationNo,
          showOverflowTooltip: true,
          width: '250px',
          sortable: true
        },
        {
          prop: 'creditor',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.supplierName,
          showOverflowTooltip: true,
          width: '200px',
          sortable: true
        },
        {
          prop: 'debtor',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.projectCompany,
          showOverflowTooltip: true,
          width: '200px',
          sortable: true
        },
        {
          prop: 'factoringMoney',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringAmount,
          showOverflowTooltip: true,
          width: '200px',
          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].common.district,
          showOverflowTooltip: true,
          format: function (row) {
            if (row.coreAreaName === '' || row.coreAreaName === undefined) {
              return ''
            } else {
              return format.formatDict(row.coreAreaName + '', 'ZD0018')
            }
          },
          width: '200px'
        },
        {
          prop: 'regionCode',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.sectionNumber,
          showOverflowTooltip: true,
          width: '100px'
        },
        {
          prop: 'taskType',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskType,
          showOverflowTooltip: true,
          width: '200px',
          sortable: true
        },
        {
          prop: 'taskStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskStatus,
          showOverflowTooltip: true,
          format: function (row) {
            // if (row.taskMainStatus === '3') {
            //   return format.formatDict('4', 'tracemgr_abnormal_status')
            // } else
            if (row.taskStatus === '1' || row.taskStatus === undefined || row.taskStatus === null) {
              return format.formatDict('1', 'tracemgr_bpm_task_status')
            } else if (row.taskStatus === '2') {
              return format.formatDict('2', 'tracemgr_bpm_task_status')
            } else if (row.taskStatus === '3') {
              return format.formatDict('3', 'tracemgr_bpm_task_status')
            }
          },
          width: '150px'
        },
        {
          prop: 'startTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].common.taskInitiationTime,
          showOverflowTooltip: true,
          width: '200px',
          sortable: true
        },
        {
          prop: 'taskEndTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskEndTime,
          showOverflowTooltip: true,
          width: '200px',
          sortable: true
        },
        {
          prop: 'taskSpendTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskSpendTime,
          showOverflowTooltip: true,
          format: function (row) {
            if (row.status === '1') {
              return '——'
            } else {
              return row.taskSpendTime
            }
          },
          width: '150px',
          sortable: true
        }
      ],
      spanArr: [],
      sIdx: 0,
      position: 0,
      sameRowArr: [],
      otLinks: [],
      queryParas: {
        pageIndex: 1,
        pageSize: 10,
        coreCompanyId: '',
        financialInstitutionsId: '',
        periodsCascadeId: '',
        paymentConfirmationNo: '',
        supplierName: '',
        enterpriseName: '',
        amount: ['', ''],
        taskType: '',
        taskStatus: '',
        TaskInitiationTime: '',
        taskEndTime: ''
      },
      taskTypeArr: []
    }
  },
  methods: {
    getTableData: function () {
      this.spanArr = []
      this.sameRowArr = []
    },
    // 获取选中的行
    selectionData (val) {
      this.nowSelectRow = val
      // for (let j = 0; j < val.length; j++) {
      //   for (let i = 0; i < this.spanArr[this.formTableData.sourceData.indexOf(val[j])]; i++) {
      //     this.nowSelectRow.push(this.formTableData.sourceData[this.formTableData.sourceData.indexOf(val[j]) + i])
      //   }
      // }
    },
    clearParam () {
      this.queryParas = {
        pageIndex: 1,
        pageSize: 10,
        amount: ['', '']
      }
    },
    changeValue: function (val) {
      this.$set(this.queryParas, 'amount', val)
    },
    // 合并单元格
    mergedCell: function ({ row, column, rowIndex, columnIndex }) {
      if (this.spanArr.length === 0) {
        this.getSpanArr()
      }
      if (columnIndex === 1) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex === 2) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex === 3) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex === 4) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex === 5) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex === 6) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
      if (columnIndex === 7) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },
    getSpanArr () {
      this.spanArr = [] // 避免表格错乱！
      this.sIdx = 0
      let $this = this
      this.formTableData.sourceData.forEach((item, index) => {
        item.index = index
        if (index === 0) {
          $this.spanArr.push(1)
          $this.position = 0
          $this.sameRowArr.push([index])
        } else {
          if ($this.formTableData.sourceData[index].assetCode === $this.formTableData.sourceData[index - 1].assetCode) { // 这里是要合并行
            $this.spanArr[this.position] += 1
            $this.spanArr.push(0)
            $this.sameRowArr[$this.sIdx].push(index)
          } else {
            $this.spanArr.push(1)
            $this.position = index
            $this.sIdx += 1
            $this.sameRowArr.push([index])
          }
        }
      })
    },
    doAction (row) {
      if (row.taskStatus === '1' && row.taskType !== this.$i18n.messages[this.$i18n.locale].traceMgr.abnormalHandle) {
        let taskId = { taskId: row.taskId }
        // 领取任务
        tracemgrApi['fcTaskTablePage'].claimTask(taskId).then(res => {
          if (res.data) {
            this.handleFilter()
            this.handleTask(row, res)
          } else {
            this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.claimTaskErroeMessage)
          }
        })
      } else {
        this.handleTask(row, null)
      }
      // this.onlineAuditVisible = true
      // this.handleTask(row, null)
    },
    // 打开常用连接
    oftenLink (url) {
      window.open(url, '_blank')
    },
    // 发起任务
    initiateTask () {
      // if (this.nowSelectRow.length > 1) {
      //   this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.pleaseSelectOne)
      //   return
      // } else if (this.nowSelectRow.length === 0) {
      //   this.error(this.$i18n.messages[this.$i18n.locale].common.alarmDel)
      //   return
      // }
      // if (this.nowSelectRow[0].stampWay !== '1') {
      //   this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.notFresh)
      //   return
      // }
      // if (this.nowSelectRow[0].businessProcessStatus !== '1') {
      //   this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.notStatus)
      //   return
      // }
      this.sanningDialogShow = true
    },
    // 合并办理
    togetherDeal () {
      if (this.nowSelectRow.length <= 1) {
        this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.pleaseSelectTowRow)
        return
      }
      this.form = {}
      this.form.param = []
      // 同一供应商和同一异常任务类型才能合并办理
      for (let i = 0; i < this.nowSelectRow.length; i++) {
        // 如果没选或只选择了一条数据 返回

        for (let j = 0; j < this.nowSelectRow.length; j++) {
          // 双重for循环 让每条数据都相互对比 有不一样的供应商就返回
          if (this.nowSelectRow[i].creditor !== this.nowSelectRow[j].creditor) {
            this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.supplierDifferent)
            return
          }
          // 有不一样的异常任务类型也返回
          if (this.nowSelectRow[i].taskType !== this.nowSelectRow[j].taskType) {
            this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.taskTypeDifferent)
            return
          }
        }

        if (this.nowSelectRow[i].taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.law) {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.noLaw)
          return
        }
        if (this.nowSelectRow[i].taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.expressFile) {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.noExpressFile)
          return
        }
        if (this.nowSelectRow[i].taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.onlineAuditFeedback) {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.noOnlineAuditFeedback)
          return
        }
        if (this.nowSelectRow[i].taskType === this.$i18n.messages[this.$i18n.locale].common.chinaClearException) {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.noChinaClearException)
          return
        }
        if (this.nowSelectRow[i].taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.generateTheSituation) {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.noGenerateTheSituation)
          return
        }

        // 如果合并办理中存在已办理或者已完成的任务，则不允许操作
        if (this.nowSelectRow[i].taskStatus === 3 || this.nowSelectRow[i].taskStatus === '3' || this.nowSelectRow[i].taskStatus === 4 || this.nowSelectRow[i].taskStatus === '4') {
          this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.MESSAGE_001 + this.nowSelectRow[i].assetCode + this.$i18n.messages[this.$i18n.locale].traceMgr.MESSAGE_002)
          return
        }
      }
      // 开始合并办理
      // 未领取的任务id
      let needclaimTaskId = []
      for (let y = 0; y < this.nowSelectRow.length; y++) {
        if (this.nowSelectRow[y].taskStatus === '1') {
          needclaimTaskId.push(this.nowSelectRow[y].taskId)
        }
        this.form.param.push({
          assetCode: this.nowSelectRow[y].assetCode,
          taskId: this.nowSelectRow[y].taskId,
          taskType: this.nowSelectRow[y].taskType,
          creditorId: this.nowSelectRow[y].creditorId,
          assetInfoId: this.nowSelectRow[y].assetInfoId
        })
      }
      // 添加供应商ID
      this.form.supplierId = this.nowSelectRow[0].creditorId
      // 领取任务
      if (needclaimTaskId.length !== 0) {
        tracemgrApi['fcTaskTablePage'].claimTask({ taskId: needclaimTaskId.join() }).then(res => {
          //  如果检查任务中有【已完成】 或者  【不存在的taks任务那么不进入办理页面】
          if (res.data) {
            this.handleFilter()
            this.BH_handleTask()
          } else {
            this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.claimTaskErroeMessage)
          }
        })
      } else {
        this.BH_handleTask()
      }
    },
    BH_handleTask () {
      //  通知供应商盖章
      if (this.form.param[0].taskType === this.$i18n.messages[this.$i18n.locale].common.notifySupplierStamp) {
        this.sealNoticeVisible = true
      }
      // 通知供应商核对信息
      if (this.form.param[0].taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.informSupplier) {
        this.checkDialogShow = true
      }
      // 添加供应商
      if (this.form.param[0].taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.addSupplierContact) {
        this.addSupplierDialogShow = true
      }
    },
    handleTask (row, res) {
      this.doHandleTask(row)
    },
    doHandleTask (row) {
      let $this = this
      $this.form.param = []
      if (row.taskType === $this.$i18n.messages[this.$i18n.locale].common.notifySupplierStamp) {
        let item = {}
        item.taskId = row.taskId
        item.assetCode = row.assetCode
        $this.form.param.push(item)
        $this.form.supplierId = row.creditorId
        $this.sealNoticeVisible = true
        return
      }
      if (row.taskType === $this.$i18n.messages[this.$i18n.locale].traceMgr.onlineAuditFeedback) {
        $this.createTime = row.startTime
        $this.assetCode = row.assetCode
        $this.instanceId = row.assetInfoId
        $this.taskId = row.taskId
        $this.creditorId = row.creditorId
        $this.taskType = row.taskType
        $this.onlineAuditVisible = true
        return
      }
      if (row.taskType === $this.$i18n.messages[this.$i18n.locale].traceMgr.informSupplier) {
        let item = {}
        item.taskId = row.taskId
        item.creditorId = row.creditorId
        item.assetCode = row.assetCode
        item.assetInfoId = row.assetInfoId
        $this.form.param.push(Object.assign({}, item))
        $this.checkDialogShow = true
        return
      }
      if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.addSupplierContact) {
        let item = {}
        item.taskId = row.taskId
        item.creditorId = row.creditorId
        item.assetCode = row.assetCode
        $this.form.param = []
        $this.form.param.push(Object.assign({}, item))
        $this.addSupplierDialogShow = true
        return
      }
      if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.expressFile) {
        $this.form = Object.assign({}, row)
        $this.supplierFileDialogShow = true
        return
      }
      if (row.taskType === $this.$i18n.messages[this.$i18n.locale].traceMgr.lawFirmService) {
        $this.assetCode = row.assetCode
        $this.taskId = row.taskId
        $this.assetInfoId = row.assetInfoId
        $this.lawFirmTaskType = this.$i18n.messages[this.$i18n.locale].common.factoringCommissioner
        $this.lawFirmTaskDialogShow = true
        return
      }
      if (row.taskType === $this.$i18n.messages[this.$i18n.locale].traceMgr.generateTheSituation) {
        $this.form = Object.assign({}, row)
        $this.generateVisible = true
        return
      }
      if (row.taskType === $this.$i18n.messages[this.$i18n.locale].traceMgr.supplementary01) {
        $this.args = row.args
        $this.assetCode = row.assetCode
        $this.taskId = row.taskId
        $this.assetInfoId = row.assetInfoId
        $this.assetPoolId = row.assetPoolId
        $this.form = row
        $this.supplementaryVisible = true
      }
      // 中登异常
      if (row.taskType === $this.$i18n.messages[this.$i18n.locale].traceMgr.abnormalHandle) {
        $this.assetInfoId = ''
        $this.signFign = '1'
        $this.form.assetCode = row.assetCode
        $this.assetInfoId = row.assetInfoId
        $this.form = row
        // 更新中登异常状态
        let params = {
          assetInfoId: row.assetInfoId,
          abnormalType: 1,
          dealPersonType: 1,
          dealStatus: 2
        }
        tracemgrApi['fcTaskTablePage'].updateAbnormalOrderStatus(params).then(res => {
          $this.abnormalHandleVisible = true
        })
      }
      // if (this.row.taskType === '中登异常') {
      //   this.onlineAuditVisible = true
      // }
      // } else {
      //   $this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.claimTaskFail)
      // }
    },
    closeLawFirmTaskDialog () {
      this.lawFirmTaskDialogShow = !this.lawFirmTaskDialogShow
    },
    closeSanningDialog () {
      this.sanningDialogShow = !this.sanningDialogShow
    },
    close (visibleFlag) {
      this.visibleFlag = !this.visibleFlag
    },
    updateData: function () {
      this.handleFilter()
    },
    handler () {
      let that = this
      setTimeout(function () {
        that.handleFilter()
      }, 1000)
    },
    handleFilter () {
      this.spanArr = []
      this.sameRowArr = []
      this.loadCount = this.loadCount + 1
      // 取出任务类型的中文
      // for (let i = 0; i < this.taskTypeArr.length; i++) {
      //   if (this.queryParas.taskType === this.taskTypeArr[i].dictId) {
      //     this.queryParas.taskType = this.taskTypeArr[i].dictName
      //     break
      //   }
      // }
    },
    getTracemgrDebugger () {
      return document.getElementById('app').getAttribute('tracemgrDebugger')
    }
  },
  mounted () {
    this.handleFilter()
    // 查找发起链接
    tracemgrApi['fcTaskTablePage'].getOtlinks().then(res => {
      this.otLinks = res.data
    })
    // 去字典接口查询任务类型的list
    this.$store.dispatch('GetDictionary', { dictTypeCode: 'tracemgr_abnormal_type_for_factoring_task_table' }).then(res => {
      this.taskTypeArr = res
    })
  },
  computed: {
    api () {
      return tracemgrApi['fcTaskTablePage']
    }
  },
  watch: {
    'formTableData.sourceData': {
      deep: true,
      handler: function () {
        this.spanArr = []
        this.sameRowArr = []
      }
    }
  }
}
</script>
