<template>
    <div>
      <up-down-layout :handleFlag.sync="handleFlag" id="taskListUpDownLayout" :bottomHeight="21" ref="taskListUpDownLayout">
        <search-form
          @clearParam="clearParam"
          @handleFilter="handleFilter"
          searchPerms="search"
          resetPerms="reset"
          :formValue.sync="queryParas"
          v-model="queryParas"
          :componentList="componentList"
          slot="query">
        </search-form>
        <template slot="table">
          <data-table :api="api" :menuCode="menuId" :cellStyle="cellStyle" id="taskList"
                      :border="true" :stripe="true" :menuFlag="true" v-bind="elHeightObj"
                      :handleFlag.sync="handleFlag" :showSelection="false" :queryParas="queryParas"
                      :sourceData.sync="sourceData"
                      :loadCount.sync="loadCount" :columns="columns" :operateBtnLayout="operateBtnLayout">
            <el-table-column :label="$t('common.operate')" align="center" fixed="right" :width="100">
              <template slot-scope="scope">
                <el-tooltip class="item" effect="dark" :content="$t('common.Handle')" placement="top">
                  <el-button v-if="scope.row.taskType === $t('traceMgr.generateTheSituationDialog') || scope.row.taskHandleStatus !== '3' || getTracemgrDebugger()" circle size="mini"  @click="showView(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="lawFirmVisible" :close="closeLawFirms" :editModel="editModel" :api="dialogApi" :taskId="taskId" :assetCode="assetCode" :assetInfoId="assetInfoId" :lawFirmTaskType="lawFirmTaskType" :supplierId="creditorId"></law-firm-task-dialog>
      <!--线上审核反馈处理-->
      <online-task-dialog :visible.sync="onLineTaskVisible" :taskId="taskId" :assetCode="assetCode" :instanceId="instanceId" :assetInfoId="assetInfoId" :createTime="createTime" :taskType="taskType" :supplierId="creditorId"></online-task-dialog>
      <!--项目公司资料补寄-->
      <supplement-file-in-pool :visible.sync="supplementVisible" :fileStampWay="fileStampWay" :supplierId="creditorId" :bpmId="taskId" :assetCode="assetCode" :instanceId="instanceId"  :assetInfoId="assetInfoId"></supplement-file-in-pool>
      <!--补出账审核任务-->
      <supplementary-account-audit :visible.sync="supplementaryAccountAuditVisible" :taskId="taskId" :assetCode="assetCode" :args="args" :assetInfoId="assetInfoId" :assetPoolId="assetPoolId"></supplementary-account-audit>
      <!--   生成情况说明   -->
      <generate-the-situation :visible.sync="generateVisible" :supplierId="creditorId" :assetInfoId="assetInfoId" :factType="'1'" :form="form" @updateData="updateData"></generate-the-situation>
      <!-- 中登异常-->
      <abnormal-handle-page :assetInfoId="assetInfoId" :signFign="signFign" :visible.sync="abnormalHandleVisible" @updateData="updateData"></abnormal-handle-page>
    </div>
</template>

<script>
import BasePage from '@/pages/basePage'
import * as format from '@/filters/index'
import mixin from '@/pages/mixin'
import { DataTable, searchForm, upDownLayout } from 'newepoch-components'
import DatePicker from '@/components/element/DatePick.vue'
import tracemgrApi from '@/api/tracemgrApi'
import SelectFlag from '@/components/tracemgr/common/SelectFlag'
import SelectUsers from '@/components/element/SelectUsers'
/* 履约文件上传任务办理页面 */
import uploadPerformanceFile from '@/components/tracemgr/regionalCommissioner/TaskTable/uploadPerformanceFile/taskDialog.vue'
/* 线上审核反馈处理 */
import onlineTaskDialog from '@/components/tracemgr/regionalCommissioner/TaskTable/onlineAudit/taskDialog.vue'
/* 项目公司资料补寄 */
import supplementFileInPool from '@/components/tracemgr/regionalCommissioner/TaskTable/supplemenFileInPool/taskDialog.vue'
/* 律所反馈 */
import lawFirmTaskDialog from '@/components/tracemgr/factoringCommissioner/taskTable/lawFirm/taskDialog.vue'
/* 原件补寄 */
import OriginalPost from '@/components/tracemgr/regionalCommissioner/TaskTable/originalSupplementaryMail/taskDialog'
/* 客户信息 */
import CustomerInfo from '@/components/tracemgr/regionalCommissioner/TaskTable/customerInfoMainte/taskDialog'
/* 确权文件通知 */
import taskDialog from '@/components/tracemgr/regionalCommissioner/TaskTable/confirmRightSealNotice/taskDialog'
/* 补出账审核任务 */
import supplementaryAccountAudit from '@/components/tracemgr/regionalCommissioner/TaskTable/supplementaryAccountAudit/taskDialog'
import supplementaryAccountInfo from '@/components/tracemgr/factoringCommissioner/taskTable/supplementaryAccountInfo/taskDialog'
import abnormalHandlePage from '@/components/tracemgr/regionalCommissioner/TaskTable/abnormalHandle/abnormalHandlePage'
import generateTheSituation from '@/components/tracemgr/regionalCommissioner/TaskTable/generateTheSituation/taskDialog.vue'
export default {
  extends: new BasePage(),
  name: 'regionalCommissionerTaskList',
  mixins: [mixin],
  components: {
    searchForm,
    DatePicker,
    format,
    DataTable,
    lawFirmTaskDialog,
    taskDialog,
    abnormalHandlePage,
    CustomerInfo,
    OriginalPost,
    uploadPerformanceFile,
    upDownLayout,
    generateTheSituation,
    onlineTaskDialog,
    supplementFileInPool,
    tracemgrApi,
    SelectFlag,
    SelectUsers,
    supplementaryAccountAudit,
    supplementaryAccountInfo
  },
  data: function () {
    return {
      elOtherHeight: 150,
      fileStampWay: '',
      tableId: 'taskList',
      taskType: '',
      lawFirmTaskType: '',
      sourceData: [],
      args: '',
      generateVisible: false,
      creditorId: '',
      createTime: '',
      openStatus: false,
      assetInfoId: '',
      abnormalHandleVisible: false,
      assetPoolId: '',
      assetCode: '',
      instanceId: '',
      taskId: '',
      type: '',
      lawFirmVisible: false,
      onLineTaskVisible: false,
      supplementVisible: false,
      supplementaryAccountAuditVisible: false,
      supplementaryAccountInfoVisible: false,
      dialogApi: '',
      form: {},
      editModel: 'V',
      operateBtnLayout: '',
      signFign: '',
      loadCount: 0,
      currentTotal: '',
      loadPage: 'getPage',
      showDetail: false,
      componentName: 'first',
      priority: '',
      enterpriseName: '',
      operationField: [],
      operationType: [],
      operationTime: '',
      createHistoryTime: '',
      item: {},
      queryParas: {
        pageIndex: 1,
        pageSize: 10,
        type: 1
      },
      componentList: [
        // 任务类型
        {
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskType,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.selectInfo,
          value: 'taskType',
          dictTypeCode: 'tracemgr_abnormal_type_for_regional_task_table',
          componentName: 'SelectDictionary',
          multiple: true,
          filterable: true,
          labelWidth: '70px'
        },
        // 发起方
        {
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.initiator,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.selectInfo,
          value: 'initiator',
          componentName: SelectUsers
        },
        // 任务处理状态
        {
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskHandleStatus,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.selectInfo,
          value: 'taskHandleStatus',
          dictTypeCode: 'tracemgr_bpm_task_status',
          componentName: 'SelectDictionary'
        },
        // 任务详情
        {
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskDetail,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.input,
          value: 'taskDetail',
          componentName: 'el-input',
          store: this.$store,
          labelWidth: '70px'
        }
      ],
      showOperation: true,
      selectedRows: [],
      handleFlag: true,
      columns: [
        // 任务类型
        {
          prop: 'taskType',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskType,
          showOverflowTooltip: true,
          width: '180px'
        },
        // 任务详情
        {
          prop: 'taskDetail',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskDetail,
          showOverflowTooltip: true,
          format: (row) => {
            if (row.taskDetail !== null && row.taskDetail !== '' && row.taskDetail !== undefined) {
              return row.taskDetail.replace(/[，]/g, '\r\n')
            }
          },
          width: '240px'
        },
        // 发起方
        {
          prop: 'initiator',
          align: 'center',
          width: '150px',
          showOverflowTooltip: true,
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.initiator
        },
        // 任务处理状态
        {
          prop: 'taskHandleStatus',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskHandleStatus,
          showOverflowTooltip: true,
          width: '120px',
          format: (row) => {
            return format.formatDict(row.taskHandleStatus, 'tracemgr_bpm_task_status')
          }
        },
        // 任务发起时间
        {
          prop: 'taskStartTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskStartTime,
          showOverflowTooltip: true,
          width: 150
        },
        // 任务截至时间
        {
          prop: 'taskEndDate',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.taskEndDate,
          showOverflowTooltip: true,
          width: '150px'
        }
      ]
    }
  },
  computed: {
    api () {
      return tracemgrApi['taskList']
    }
  },
  mounted: function () {
    this.handleFilter()
    this.openStatus = true
  },
  methods: {
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      if (row.stillError && row.stillError > 0) {
        return 'background-color: #FFF5F4 ; color: #F65A4B'
      } else {
        return ''
      }
    },
    showView: function (row) {
      if (row.taskHandleStatus === '1' && row.taskType !== this.$i18n.messages[this.$i18n.locale].traceMgr.abnormalHandleName) {
        tracemgrApi['taskList'].claim({ 'taskId': row.taskId }).then(res => {
          if (res.data) {
            row.taskHandleStatus = '2'
            this.showViewClassify(row)
          } else {
            this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.claimFailed)
          }
        })
      } else {
        this.showViewClassify(row)
      }
    },
    showViewClassify: function (row) {
      if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.onlineTaskDialog) {
        this.taskId = row.taskId
        this.assetCode = row.assetCode
        this.instanceId = row.instanceId
        this.assetInfoId = row.assetInfoId
        this.createTime = row.taskStartTime
        this.creditorId = row.creditorId
        this.taskType = row.taskType
        this.onLineTaskVisible = true
      } else if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.lawFirmTaskDialog) {
        this.taskId = row.taskId
        this.assetCode = row.assetCode
        this.assetInfoId = row.assetInfoId
        this.creditorId = row.creditorId
        this.lawFirmTaskType = this.$i18n.messages[this.$i18n.locale].common.theRegionalCommissioner
        this.lawFirmVisible = true
      } else if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.supplementFileInPool) {
        this.fileStampWay = row.fileStampWay
        this.taskId = row.taskId
        this.creditorId = row.creditorId
        this.assetCode = row.assetCode
        this.instanceId = row.instanceId
        this.assetInfoId = row.assetInfoId
        this.supplementVisible = true
      } else if (row.taskType === this.$i18n.messages[this.$i18n.locale].baoLiWorkbenchOrderTrack.abnormalZljb) {
        this.taskId = row.taskId
        this.creditorId = row.creditorId
        this.assetCode = row.assetCode
        this.instanceId = row.instanceId
        this.assetInfoId = row.assetInfoId
        this.supplementVisible = true
      } else if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.supplementaryAccountAuditDialogv) {
        this.taskId = row.taskId
        this.assetCode = row.assetCode
        this.assetInfoId = row.assetInfoId
        this.assetPoolId = row.assetPoolId
        this.args = row.args
        this.supplementaryAccountAuditVisible = true
      } else if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.generateTheSituationDialog) {
        this.form = Object.assign({}, row)
        this.generateVisible = true
      }
      if (row.taskType === this.$i18n.messages[this.$i18n.locale].traceMgr.abnormalHandleName) {
        this.assetInfoId = ''
        this.signFign = '2'
        this.assetInfoId = row.assetInfoId

        // 更新中登异常状态
        let params = {
          assetInfoId: row.assetInfoId,
          abnormalType: 1,
          dealPersonType: 2,
          dealStatus: 2
        }
        tracemgrApi['fcTaskTablePage'].updateAbnormalOrderStatus(params).then(res => {
          this.abnormalHandleVisible = true
        })
      }
    },
    handleFilter () {
      this.loadCount = this.loadCount + 1
    },
    updateData: function () {
      this.handleFilter()
    },
    close () {
      this.onLineTaskVisible = false
    },
    closeLawFirms () {
      this.lawFirmVisible = false
    },
    initLayout: function () {
      this.initStyle()
    },
    getTracemgrDebugger () {
      return document.getElementById('app').getAttribute('tracemgrDebugger')
    }
  }
}
</script>

<style lang="scss" scoped>
    @import './src/styles/tracemgr/regionalCommissioner/taskTable/taskList.scss';
</style>
