<template>
  <div class="app-container">
    <div class="title-container">
      <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
    </div>
    <y-page-list-layout :page-list="pageData" :page-para="listQuery" :get-page-list="getPage">
      <template slot="left">
        <MoreSearchBar business="PERSONAL_BUSINESS" :nodes="personalNodes" :handlerName="false"
          @fliterSearch="fliterSearch" @resetParams="resetParams" :listQuery="listQuery">
          <template v-slot:otherButton>
            <el-button class="filter-item" round @click="showAllLabel()">显示全部列</el-button>
            <PermissionButton menu-code="_views_personal_batch_allot" class-name="filter-item" type="danger"
              icon="el-icon-paperclip" :page-jump="false" round @click="openBatchAllotDialog()" />
            <PermissionButton menu-code="_views_personal_batch_commit_bookbinding_stamp" class-name="filter-item"
              type="danger" icon="el-icon-paperclip" :page-jump="false" round @click="openBatchCommitDialog()" />
              <PermissionButton menu-code="_views_personal_batch_in_rep" class-name="filter-item"
              type="warning" icon="el-icon-paperclip" :page-jump="false" round @click="openBatchInRepDialog()" />
              <PermissionButton menu-code="_views_personal_batch_out_rep" class-name="filter-item"
              type="warning" icon="el-icon-paperclip" :page-jump="false" round @click="openBatchOutRepDialog()" />
          </template>
        </MoreSearchBar>
      </template>
      <parentTable ref="table" v-loading="listLoading" :data="pageData.records" slot="table" style="width: 100%;"
        @headerClick="switchHeader">
        <el-table-column label="项目编号" align="center" width="150" v-if="!hiddenLabels.includes('orderId')" prop="orderId">
          <template slot-scope="{row}">
            <span class="enableClick" @click="toDetail(row)" @contextmenu.prevent="$doCopy(row.orderId)">{{ row.orderId
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="坐落" align="center" width="300" v-if="!hiddenLabels.includes('location')" prop="location">
          <template slot-scope="{row}">
            <span class="enableClick" @click="toDetail(row)">{{ row.location }}</span>
          </template>
        </el-table-column>
        <el-table-column label="当前节点" align="center" width="130" v-if="!hiddenLabels.includes('currentNodeName')"
          prop="currentNodeName">
          <template slot-scope="{row}">
            <span>{{ row.nodeName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="处理人" align="center" width="130" v-if="!hiddenLabels.includes('handlerName')"
          prop="handlerName">
          <template slot-scope="{row}">
            <span>{{ row.handlerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="面积" align="center" width="130" v-if="!hiddenLabels.includes('acreage')" prop="acreage">
          <template slot-scope="{row}">
            <span>{{ row.acreage ? row.acreage + '平' : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="单价" align="center" width="130" v-if="!hiddenLabels.includes('price')" prop="price">
          <template slot-scope="{row}">
            <span>{{ row.price ? row.price + '元' : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="总价" align="center" width="130" v-if="!hiddenLabels.includes('amount')" prop="amount">
          <template slot-scope="{row}">
            <span>{{ row.amount ? (row.amount / 10000).toFixed(2) + '万' : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center" width="130" v-if="!hiddenLabels.includes('clientName')"
          prop="clientName">
          <template slot-scope="{row}">
            <span>{{ row.clientName ? row.clientName : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="业务来源" align="center" width="130" v-if="!hiddenLabels.includes('clientSubName')"
          prop="clientSubName">
          <template slot-scope="{row}">
            <span>{{ row.clientSubName ? row.clientSubName : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="中介" align="center" width="130" v-if="!hiddenLabels.includes('agent')" prop="agent">
          <template slot-scope="{row}">
            <span>{{ row.agent ? row.agent : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人" align="center" width="130" v-if="!hiddenLabels.includes('contactName')"
          prop="contactName">
          <template slot-scope="{row}">
            <span>{{ row.contactName ? row.contactName : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人电话" align="center" width="130" v-if="!hiddenLabels.includes('contactTel')"
          prop="contactTel">
          <template slot-scope="{row}">
            <span>{{ row.contactTel ? row.contactTel : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="委托人" align="center" v-if="!hiddenLabels.includes('bailorA')" prop="bailorA">
          <template slot-scope="{row}">
            <span>{{ row.bailorA == null ? (row.bailorB ? row.bailorB : '-') : row.bailorA }}</span>
          </template>
        </el-table-column>
        <el-table-column label="委托人电话" align="center" width="130" v-if="!hiddenLabels.includes('bailoraTel')"
          prop="bailoraTel">
          <template slot-scope="{row}">
            <span>{{ row.bailorATel == null ? (row.bailorBTel ? row.bailorBTel : '-') : row.bailorATel }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户经理" align="center" v-if="!hiddenLabels.includes('clientManager')" prop="clientManager">
          <template slot-scope="{row}">
            <span>{{ row.clientManager }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实勘人" align="center" width="130" v-if="!hiddenLabels.includes('outwardStaffName')"
          prop="outwardStaffName">
          <template slot-scope="{row}">
            <span>{{ row.outwardStaffName ? row.outwardStaffName : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="内业人员" align="center" width="130" v-if="!hiddenLabels.includes('inwardStaffName')"
          prop="inwardStaffName">
          <template slot-scope="{row}">
            <span>{{ row.inwardStaffName ? row.inwardStaffName : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="定价人员" align="center" width="130" v-if="!hiddenLabels.includes('pricingStaffName')"
          prop="pricingStaffName">
          <template slot-scope="{row}">
            <span>{{ row.pricingStaffName ? row.pricingStaffName : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" align="center" width="110" v-if="!hiddenLabels.includes('created')" prop="created">
          <template slot-scope="{row}">
            {{ row.created }}
          </template>
        </el-table-column>
        <el-table-column label="节点生成时间" align="center" width="110" v-if="!hiddenLabels.includes('nodeCreated')"
          prop="nodeCreated">
          <template slot-scope="{row}">
            {{ row.nodeCreated }}
          </template>
        </el-table-column>
        <el-table-column label="最新备注" align="center" width="150" v-if="!hiddenLabels.includes('comments')"
          prop="comments">
          <template slot-scope="{row}">
            <span>{{ row.comments ? row.comments : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="140" fixed="right">
          <template slot-scope="{row}">
            <el-button type="text" @click="toDetail(row)">办理</el-button>
            <el-button type="text" @click="transfer(row.taskId)">转交</el-button>
          </template>
        </el-table-column>
      </parentTable>
    </y-page-list-layout>
    <el-dialog :visible.sync="batchAllotDialogVisible" width="90%" center top="10vh" custom-class="doWarehouseClass"
      @closed="getPage">
      <div>
        <el-divider content-position="left">
          <span>订单关键字搜索:
            <el-input v-model="orderKeyword" placeholder="关键字..." clearable style="width: 270px;" />
          </span>
        </el-divider>
        <div class="outwardStaff-div">
          <el-button style="margin-top: 10px;margin-left: 2px;" type="info" size="mini" plain
            v-for="(user, index) in outwardUsers" :key="index" @click="batchAllot(user)">{{ user.name }}</el-button>
        </div>
      </div>
      <y-page-list-layout :page-list="allotOrderData" :page-para="allotOrderQuery" :get-page-list="getAllotOrderList">
        <template slot="left">
        </template>
        <parentTable ref="table" :clickRowToPick="true" :data="allotOrderData.records" slot="table" style="width: 100%;"
          :selectionChange="handleSelectionChange">
          <el-table-column align="center" type="selection" claimOrders width="100" border="true">
          </el-table-column>
          <el-table-column label="坐落" align="center" width="400">
            <template slot-scope="{row}">
              <span>{{ row.location }}</span>
            </template>
          </el-table-column>
          <el-table-column label="项目编号" align="center">
            <template slot-scope="{row}">
              <span>{{ row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column label="客户名称" align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientName == null ? '-' : row.clientName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="业务来源" align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientSubName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系人" align="center">
            <template slot-scope="{row}">
              <span>{{ row.contactName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系人电话" align="center">
            <template slot-scope="{row}">
              <span>{{ row.contactTel }}</span>
            </template>
          </el-table-column>
          <el-table-column label="委托人1" align="center">
            <template slot-scope="{row}">
              <span>{{ row.bailorA ? row.bailorA : '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="委托人2" align="center">
            <template slot-scope="{row}">
              <span>{{ row.bailorB ? row.bailorB : '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="客户经理" align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientManager == null ? '-' : row.clientManager }}</span>
            </template>
          </el-table-column>
          <el-table-column label="中介" align="center">
            <template slot-scope="{row}">
              <span>{{ row.agent == null ? '-' : row.agent }}</span>
            </template>
          </el-table-column>
          <el-table-column label="最新备注" align="center" width="150"
          prop="comments">
          <template slot-scope="{row}">
            <span>{{ row.comments ? row.comments : '-' }}</span>
          </template>
        </el-table-column>
        </parentTable>
      </y-page-list-layout>
    </el-dialog>
    <TransferDialog :transferDialogVisible="visible" @parentFalse="parentFalse()" @getPage="getPage()"
      :recordId="recordId"></TransferDialog>
    <el-dialog :visible.sync="batchCommitDialog" width="90%">
      <y-page-list-layout :page-list="batchCommitPageData" :page-para="batchCommitListQuery"
        :get-page-list="selectBatchCommitPage">
        <template slot="left">
          <el-select v-model="batchCommitListQuery.nodeCode" placeholder="产品类型" clearable filterable 
            class="filter-item" style="float: left;">
            <el-option label="意见书装订盖章" value="STATEMENT_BOOKBINDING_STAMP" />
            <el-option label="报告装订盖章" value="REPORT_BOOKBINDING_STAMP" />
            <el-option label="复评函装订盖章" value="LETTER_BOOKBINDING_STAMP" />
          </el-select>
          <el-input style="margin-left: 20px;width: 300px;float: left;" class="filter-item"
            v-model="batchCommitListQuery.keyWord" placeholder="项目编号/报告号/项目名称/业务来源" clearable>
          </el-input>
          <el-button class="filter-item" style="margin-left: 10px;float: left;" type="primary"
            @click="searchBatchCommitList()" round>搜索
          </el-button>
          <el-button class="filter-item" style="margin-left: 10px;float: left;" type="danger" @click="batchCommitNode()"
            round>提交选中流程
          </el-button>
        </template>
        <parentTable :clickRowToPick="true" ref="table" v-loading="listLoading" :data="batchCommitPageData.records"
          slot="table" style="width: 100%;height: 800px;" :selectionChange="handleSelectionChangeBatchCommit">
          <el-table-column align="center" type="selection" claimOrders width="50" border="true">
          </el-table-column>
          <el-table-column label="坐落" align="center" >
            <template slot-scope="{row}">
              <span>{{ row.location }}</span>
            </template>
          </el-table-column>
          <el-table-column label="节点名称" align="center" width="120">
            <template slot-scope="{row}">
              <span>{{ row.nodeName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="项目编号" align="center">
            <template slot-scope="{row}">
              <span>{{ row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column label="客户名称" align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientName == null ? '-' : row.clientName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="业务来源" align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientSubName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系人" align="center">
            <template slot-scope="{row}">
              <span>{{ row.contactName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系人电话" align="center">
            <template slot-scope="{row}">
              <span>{{ row.contactTel }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="委托人1" align="center">
            <template slot-scope="{row}">
              <span>{{ row.bailorA ? row.bailorA : '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="委托人2" align="center">
            <template slot-scope="{row}">
              <span>{{ row.bailorB ? row.bailorB : '-' }}</span>
            </template>
          </el-table-column> -->
          <el-table-column label="客户经理" align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientManager == null ? '-' : row.clientManager }}</span>
            </template>
          </el-table-column>
          <el-table-column label="中介" align="center">
            <template slot-scope="{row}">
              <span>{{ row.agent == null ? '-' : row.agent }}</span>
            </template>
          </el-table-column>
        </parentTable>
      </y-page-list-layout>
    </el-dialog>
    <el-dialog :visible.sync="batchInRepDialogVisible" width="90%" center top="10vh" custom-class="doWarehouseClass" @closed="cleanNodeClientName()">
        <span style="font-size: 20px; font-weight: bold;">待入库任务：{{ inRepTasks.length }}条</span>
        <el-select v-model="inRepNodeCode" placeholder="流程节点" clearable filterable style="margin-left: 30px;" @change="personalInRepTask()"
            class="filter-item">
            <el-option label="意见书入库" value="STATEMENT_IN" />
            <el-option label="报告入库" value="REPORT_IN" />
            <el-option label="复评函入库" value="LETTER_IN" />
        </el-select>
        <el-input v-model="clientName" placeholder="客户名称" clearable style="width: 15%; margin-left: 30px;"  @change="personalInRepTask()" class="filter-item"></el-input>
        <el-button type="danger" style="float: right;" @click="doBatchInRep()">点击入库</el-button>
      <parentTable  :clickRowToPick="true" :data="inRepTasks" style="width: 100%; margin-top: 10px;"
      :selectionChange="handInRep">
          <el-table-column align="center" type="selection" claimOrders width="100" border="true">
          </el-table-column>
        <el-table-column label="项目编号" align="center" width="150" prop="orderId">
        </el-table-column>
        <el-table-column label="坐落" align="center"  prop="location">
        </el-table-column>
        <el-table-column label="当前节点" align="center" width="130" prop="nodeName">
        </el-table-column>
        <el-table-column label="处理人" align="center" width="130" prop="handlerName">
        </el-table-column>
        <el-table-column label="面积" align="center" width="130" prop="acreage">
        </el-table-column>
        <el-table-column label="单价" align="center" width="130"  prop="price" >
        </el-table-column>
        <el-table-column label="总价" align="center" width="130"  prop="amount">
        </el-table-column>
        <el-table-column label="客户名称" align="center" width="130" 
          prop="clientName">
        </el-table-column>
        <el-table-column label="业务来源" align="center" width="130" prop="clientSubName">
        </el-table-column>
      </parentTable>
    </el-dialog>
    <el-dialog :visible.sync="batchOutRepDialogVisible" width="90%" center top="10vh" custom-class="doWarehouseClass" @closed="cleanNodeClientName()">
      <span style="font-size: 20px; font-weight: bold;">待出库任务：{{ outRepTasks.length }}条</span>
      <el-select v-model="outRepNodeCode" placeholder="流程节点" clearable filterable style="margin-left: 30px;" @change="personalOutRepTask()"
            class="filter-item">
            <el-option label="意见书出库" value="STATEMENT_OUT" />
            <el-option label="报告出库" value="REPORT_OUT" />
            <el-option label="复评函出库" value="LETTER_OUT" />
        </el-select>
        <el-input v-model="clientName" placeholder="客户名称" clearable style="width: 15%; margin-left: 30px;"  @change="personalOutRepTask()" class="filter-item"></el-input>
      <el-button type="danger" style="float: right;" @click="doBatchOutRep()">点击出库</el-button>
      <parentTable  :clickRowToPick="true" :data="outRepTasks" style="width: 100%; margin-top: 10px;"
      :selectionChange="handOutRep">
          <el-table-column align="center" type="selection" claimOrders width="100" border="true">
          </el-table-column>
        <el-table-column label="项目编号" align="center" width="150" prop="orderId">
        </el-table-column>
        <el-table-column label="坐落" align="center"  prop="location">
        </el-table-column>
        <el-table-column label="当前节点" align="center" width="130" prop="nodeName">
        </el-table-column>
        <el-table-column label="处理人" align="center" width="130" prop="handlerName">
        </el-table-column>
        <el-table-column label="面积" align="center" width="130" prop="acreage">
        </el-table-column>
        <el-table-column label="单价" align="center" width="130"  prop="price" >
        </el-table-column>
        <el-table-column label="总价" align="center" width="130"  prop="amount">
        </el-table-column>
        <el-table-column label="客户名称" align="center" width="130" 
          prop="clientName">
        </el-table-column>
        <el-table-column label="业务来源" align="center" width="130" prop="clientSubName">
        </el-table-column>
      </parentTable>
    </el-dialog>
  </div>
</template>
<script>
import YPageListLayout from '@/components/YPageListLayout'
import Breadcrumb from '@/components/Breadcrumb'
import PermissionButton from '@/components/PermissionButton/PermissionButton'
import MoreSearchBar from '@/components/MoreSearchBar'
import TransferDialog from '@/components/TaskTransferDialog'
import { getCookie, setCookie, removeCookie } from '@/utils/auth'

export default {
  name: 'personalTodoList',
  components: {
    Breadcrumb,
    YPageListLayout,
    PermissionButton,
    MoreSearchBar,
    TransferDialog
  },

  data() {
    return {
      pageData: { records: [] },
      listLoading: false,
      listQuery: {
        page: 1,
        size: 10,
        current: 1,
        descs: null,
        ascs: null,
        keyword: null,
        startDate: null,
        endDate: null,
      },
      personalNodes: [],
      visible: false,
      recordId: null,
      batchAllotDialogVisible: false,
      allotOrderQuery: {
        page: 1,
        size: 10,
        descs: 'id',
        keyword: null
      },
      allotOrderData: { records: [] },
      outwardUsers: [],
      batchOrders: [],
      orderKeyword: null,
      hiddenLabels: [],
      batchCommitDialog: false,
      workNodeCommits: [],
      batchCommitListQuery: {
        page: 1,
        size: 10,
        current: 1,
        keyWord: null,
        getNodeIsBookbindingStamp: false
      },
      batchCommitPageData: { records: [] },
      batchInRepDialogVisible:false,
      batchOutRepDialogVisible:false,
      inRepTasks:[],
      outRepTasks:[],
      inRepCommit:[],
      outRepCommit:[],
      inRepNodeCode:null,
      outRepNodeCode:null,
      clientName:null,
      stmpNode:null
    }

  },
  watch: {
    orderKeyword: {
      handler(nv, ov) {
        this.allotOrderQuery.keyword = nv;
        this.getAllotOrderList();
      },
      deep: true
    },
  }, 
  created() {
    if (getCookie("personalTodoList-hiddenLabels") != undefined) {
      this.hiddenLabels = JSON.parse(getCookie("personalTodoList-hiddenLabels"))
    }
    this.getPage();
    this.getNodeEnum();
  },
  methods: {
    getPage() {
      if (getCookie('personalTodoList') != undefined) {
        this.listQuery.size = parseInt(getCookie('personalTodoList'));
      }
      this.$api.workNodeTaskRecord.personalTaskTodoList(this.listQuery).then(res => {
        if (res.code === 200) {
          this.pageData = res.data;
        }
      })
    },
    // 当前用户待办分页查询
    selectBatchCommitPage() {
      this.$api.workNodeTaskRecord.personalTaskTodoList(this.batchCommitListQuery).then(res => {
        if (res.code === 200) {
          this.batchCommitPageData = res.data;
        }
      })
    },
    // 条件查询
    searchBatchCommitList() {
      // 重置分页
      this.batchCommitListQuery.page = 1
      this.batchCommitListQuery.size = 10
      this.selectBatchCommitPage()
    },
    openBatchCommitDialog() {
      this.batchCommitListQuery.getNodeIsBookbindingStamp = true;
      this.selectBatchCommitPage();
      this.batchCommitDialog = true;
    },

    getNodeEnum() {
      this.$api.workNode.nodesByBusiness("PERSONAL_BUSINESS").then(res => {
        if (res.code === 200) {
          this.personalNodes = res.data;
        }
      })
    },

    fliterSearch(params) {
      this.$api.workNodeTaskRecord.personalTaskTodoList(params).then(res => {
        if (res.code === 200) {
          this.pageData = res.data;
        }
      })
    },

    resetParams() {
      this.$router.push({ query: {} });
      this.listQuery = {
        current: 1,
        size: 10,
        descs: 'created',
      }
      this.getPage();
    },
    searchList() {
      // 重置分页
      this.listQuery.page = 1
      this.listQuery.size = 10
      this.getPage()
    },

    toDetail(row) {
      const nodeCode = row.nodeCode;
      if (nodeCode === 'REPORT_OUT_APPLY' || nodeCode === 'LETTER_OUT_APPLY') {
        this.$router.push(`/personal/my/order?todoBusinessId=${row.businessId}&orderId=${row.orderId}&tId=${row.taskId}&cId=${row.currentNodeId}`)
      }
      else if (nodeCode === 'REPORT_OUT_DEPARTMENT_CHECK' || nodeCode === 'LETTER_OUT_DEPARTMENT_CHECK') {
        this.$router.push(`/out/warehouse/check?todoBusinessId=${row.businessId}&sNo=${row.orderId}&tId=${row.taskId}&cId=${row.currentNodeId}&nCode=${row.nodeCode}&businessType=PERSONAL_BUSINESS`)
      }
      else if (row.nodeCode === 'BUSINESS_ARCHIVING') {
        this.$router.push(`/personal/toSaveFile`)
        return;
      } else if (row.nodeCode === 'STATEMENT_IN' || row.nodeCode === 'STATEMENT_OUT' ||
        row.nodeCode === 'REPORT_IN' || row.nodeCode === 'REPORT_OUT' ||
        row.nodeCode === 'LETTER_IN' || row.nodeCode === 'LETTER_OUT') {
        this.$router.push(`/major/production/in?openDialog=${true}`)
      }
      else {
        this.$router.push(`/personal/todo?id=${row.businessId}&currentNodeCode=${row.nodeCode}&orderId=${row.orderId}&doWorkflow=${true}&isOnline=${row.isOnline}&back=${'/personal/todo/list'}`)
        // window.open(this.$router.resolve(`/personal/todo?id=${row.businessId}&currentNodeCode=${row.nodeCode}&orderId=${row.orderId}&doWorkflow=${true}&isOnline=${row.isOnline}&back=${'/personal/todo/list'}`).href,
        // '_blank');
      }
    },

    parentFalse() {
      this.visible = false;
    },
    transfer(recordId) {
      this.visible = true;
      this.recordId = recordId;
    },
    openBatchAllotDialog() {
      this.batchAllotDialogVisible = true;
      this.getAllotOrderList();
      this.getOutWardUsers();
    },
    getOutWardUsers() {
      this.$api.user.postUser("个贷外业岗").then(res => {
        if (res.code === 200) {
          this.outwardUsers = res.data;
        }
      })
    },
    handleSelectionChange(val) {
      let pickeds = [];
      for (let i in val) {
        let picked = new Object();
        picked.id = val[i].id;
        picked.currentNodeId = val[i].currentNodeId;
        picked.orderId = val[i].orderId;
        picked.nodeId = val[i].nodeId;
        pickeds.push(picked);
      }
      this.batchOrders = pickeds;
    },
    getAllotOrderList() {
      this.$api.personal.waitingAllotOrder(this.allotOrderQuery).then(res => {
        if (res.code === 200) {
          this.allotOrderData = res.data;
        }
      })
    },
    batchAllot(user) {
      if (!user || this.batchOrders.length === 0) {
        this.$message.error('请先勾选订单后再指定外业人员');
        return;
      }
      this.$confirm('确定将所选订单分配给【' + user.name + '】?').then(() => {
        let param = new Object();
        param.id = user.id;
        param.orders = this.batchOrders
        this.$api.personal.batchAllotOrder(param).then(res => {
          if (res.code === 200) {
            this.$notify({
              title: '提示',
              message: '分单成功！',
              type: 'success',
              duration: 1000
            });

            this.batchOrders = [];
            this.getAllotOrderList();
          }

        })
      }).catch(() => {
        this.$message.error('取消分单');
      });

    },
    switchHeader(data) {
      this.hiddenLabels.push(data);
      setCookie("personalTodoList-hiddenLabels", this.hiddenLabels);
    },
    showAllLabel() {
      removeCookie("personalTodoList-hiddenLabels");
      location.reload();
    },
    // 批量提交流程节点
    batchCommitNode() {
      if (this.workNodeCommits.length > 0) {
        this.$confirm('确认批量提交已选中流程?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.workflow.batchCommit(this.workNodeCommits).then(res => {
            if (res.code === 200 && res.data) {
              this.$notify({
                title: '成功',
                message: '工作流节点批量提交成功。',
                type: 'success',
                duration: 2000
              });
              this.getPage();
              this.selectBatchCommitPage();
            } else {
              this.$notify({
                title: '失败',
                message: res.message,
                type: 'error',
                duration: 2000
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消批量提交'
          });
        });
      } else {
        this.$notify.error({
          title: '错误',
          message: '请选择至少一条流程再提交!'
        });
      }
    },
    handleSelectionChangeBatchCommit(val) {
      let pickedCommits = [];
      for (let i in val) {
        let commit = new Object();
        commit.instanceNodeId = val[i].currentNodeId;
        commit.state = "PASS";
        commit.comments = "批量提交装订盖章节点";
        commit.businessSubId = val[i].orderId;
        pickedCommits.push(commit);
      }
      this.workNodeCommits = pickedCommits;
    },
    personalInRepTask(){
      this.$api.workNodeTaskRecord.getPersonalInRepTask(this.inRepNodeCode,this.clientName).then(res=>{
        if (res.code===200){
          this.inRepTasks = res.data;
        }
      })
    },
    personalOutRepTask(){
      this.$api.workNodeTaskRecord.getPersonalOutRepTask(this.outRepNodeCode,this.clientName).then(res=>{
        if (res.code===200){
          this.outRepTasks = res.data;
        }
      })
    },
    openBatchInRepDialog(){
      this.batchInRepDialogVisible = true;
      this.personalInRepTask();
    },
    openBatchOutRepDialog(){
      this.batchOutRepDialogVisible = true;
      this.personalOutRepTask();
    },
    doBatchInRep(){
      if (this.inRepCommit.length > 0) {
        this.$confirm('确认批量提交已选中流程?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.workflow.batchCommit(this.inRepCommit).then(res => {
            if (res.code === 200 && res.data) {
              this.$notify({
                title: '成功',
                message: '工作流节点批量提交成功。',
                type: 'success',
                duration: 2000
              });
              this.getPage();
              this.personalInRepTask();
            } else {
              this.$notify({
                title: '失败',
                message: res.message,
                type: 'error',
                duration: 2000
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消批量提交'
          });
        });
      } else {
        this.$notify.error({
          title: '错误',
          message: '请选择至少一条流程再提交!'
        });
      }
    },
    handInRep(val){
      let pickedCommits = [];
      for (let i in val) {
        let commit = new Object();
        commit.instanceNodeId = val[i].currentNodeId;
        commit.state = "PASS";
        commit.comments = "批量入库";
        commit.businessSubId = val[i].orderId;
        pickedCommits.push(commit);
      }
      this.inRepCommit = pickedCommits;
    },
    doBatchOutRep(){
      if (this.outRepCommit.length > 0) {
        this.$confirm('确认批量提交已选中流程?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$api.workflow.batchCommit(this.outRepCommit).then(res => {
            if (res.code === 200 && res.data) {
              this.$notify({
                title: '成功',
                message: '工作流节点批量提交成功。',
                type: 'success',
                duration: 2000
              });
              this.getPage();
              this.personalOutRepTask();
            } else {
              this.$notify({
                title: '失败',
                message: res.message,
                type: 'error',
                duration: 2000
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消批量提交'
          });
        });
      } else {
        this.$notify.error({
          title: '错误',
          message: '请选择至少一条流程再提交!'
        });
      }
    },
    handOutRep(val){
      let pickedCommits = [];
      for (let i in val) {
        let commit = new Object();
        commit.instanceNodeId = val[i].currentNodeId;
        commit.state = "PASS";
        commit.comments = "批量出库";
        commit.businessId  = val[i].businessId;
        commit.businessSubId = val[i].orderId;
        commit.nodeCode = 'REPORT_OUT';
        pickedCommits.push(commit);
      }
      this.outRepCommit = pickedCommits;
    },
    cleanNodeClientName(){
      this.clientName = null;
      this.inRepNodeCode = null;
      this.outRepNodeCode = null;
    }


  },

}
</script>
<style lang="scss" scoped>
/deep/.doWarehouseClass {
  border-radius: 10px;
}

.outwardStaff-div {
  width: 100%;
  padding-left: 17px;
}

.enableClick:hover {
  color: #1890ff;
  cursor: pointer;
}
</style>
