<template>
  <div style="padding-top: 20px">
    <div class="filter-container">
      <!--      <el-input size="mini" v-model="search.keyWord" placeholder="关键字" style="width: 200px;" class="filter-item"/>-->
      <el-select multiple size="mini" v-model="productVal" style="width: 350px" clearable filterable placeholder="产品类型"
                 value-key="id"
                 @change="productInfoChange">
        <el-option
          v-for="item in productList"
          :key="item.id"
          :label="item.productName"
          :value="item.id">
        </el-option>
      </el-select>
      <el-input size="mini" v-model="search.orderName" placeholder="印品名称" style="width: 150px;" class="filter-item"/>
      <el-input size="mini" v-model="search.paperName" placeholder="纸张名称" style="width: 150px;" class="filter-item"/>
      <el-input type="number" size="mini" v-model="search.paperSuttle" placeholder="克重" style="width: 80px;"
                class="filter-item"/>
      <el-button size="mini" class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <el-checkbox size="small" @change="checkLock" v-model="LockBtn" label="本人已锁定" border></el-checkbox>
      <el-checkbox style="margin-left: -20px" size="small" @change="checkState" v-model="processStateBtn"
                   label="搜索未处理文件" border></el-checkbox>
      <el-button
        class="filter-item"
        style="margin-left: 10px;"
        type="warning"
        size="mini"
        @click="lockWorkPartsHandle">
        订单锁定
      </el-button>
      <el-button
        class="filter-item"
        style="margin-left: 10px;"
        type="success"
        size="mini"
        @click="unLockWorkPartsHandle">
        订单解锁
      </el-button>
      <el-button
        class="filter-item"
        style="margin-left: 10px;"
        type="primary"
        size="mini"
        @click="handleEdition">
        手动组版
      </el-button>
      <el-button size="mini" type="primary" icon="el-icon-refresh" @click="tableRefresh">刷新</el-button>
      <el-tooltip content="查看修图已分配,未分配订单列表" placement="top">
        <el-button @click="clilkDispatchOrder" size="mini" type="warning">查看修图已分配...</el-button>
      </el-tooltip>
    </div>
    <div class="hline-table">
      <u-table
        ref="plTable"
        :height="height"
        row-key="id"
        v-loading="listLoading"
        size="mini"
        use-virtual
        @row-contextmenu="rowContextmenu"
        @row-click="handleClickTableRow"
        :row-class-name="tableRowClassName"
        :big-data-checkbox="checked"
        showBodyOverflow="title"
        showHeaderOverflow="title"
        :span-method="handleSameMerge"
        :row-height="rowHeight"
        border>
        <el-table-column align="center" type="selection" width="45" :selectable="selectable"/>
        <el-table-column prop="class_label" label="订单信息" width="185">
          <template slot-scope="{row}">
            <div v-if="row.class_label.split(',').length>3">
              <span>{{ row.class_label.split(",")[0] }}<span v-if="row.businessKind==3"
                                                             style="display: inline-block;color: red">(补{{ row.rePrintIndex }})</span></span>
              <span>{{ row.class_label.split(",")[1] }}</span>
              <span>{{ row.class_label.split(",")[2] }}</span>
            </div>
            <div v-else>
              <span>{{ row.class_label.split(",")[0] }}<span v-if="row.businessKind==3"
                                                             style="display: inline-block;color: red">(补{{ row.rePrintIndex }})</span></span>&nbsp;<i v-show="spanLabel!=row.id"
                                                                       style="cursor: pointer"
                                                                       @click.stop="openLabel(row)"
                                                                       class="el-icon-arrow-down"></i>
              <span v-show="spanLabel==row.id">{{ row.class_label.split(",")[1] }}</span>
              <span v-show="spanLabel==row.id">{{ row.class_label.split(",")[2] }}</span>&nbsp;<i
              v-show="spanLabel==row.id" style="cursor: pointer" @click.stop="closeLabel" class="el-icon-arrow-up"></i>
            </div>


          </template>
        </el-table-column>
        <el-table-column label="标记" width="90">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.idFileProcessMan<=0" style="cursor: pointer" size="small"
                    @click.stop="getOrderStep(scope.row)" class="iconfont" title="查看脚印" type="danger">&#xe6ba
            </el-tag>
            <el-tag v-if="scope.row.idFileProcessMan>0" style="cursor: pointer" size="small"
                    @click.stop="getOrderStep(scope.row)" class="iconfont" title="查看脚印" type="success">&#xe6ba
            </el-tag>
            <el-tooltip v-if="scope.row.voidPrintBillCode!='' &&  scope.row.voidPrintBillCode!=undefined"
                        class="item" effect="dark" :content="'原单号：' + scope.row.voidPrintBillCode" placement="top-start">
              <i style="color: #c20303;cursor: pointer;width: auto"   class="el-icon-delete-solid">有退回</i>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column label="产品类型" width="120">
          <template slot-scope="scope">
            <span></span>
            <a href="javascript:;" style="color: #67C23A"
               @click.stop="openDetail(scope.row)">{{ scope.row.orderPart.partName }}</a>
          </template>
        </el-table-column>


        <el-table-column
          width="125"
          label="订单审核时间"
        >
          <template slot-scope="{row}">
            <span v-if="row.checkDateLong">{{ row.checkDateLong | getLongTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="尺寸"
        >
          <template slot-scope="{row}">
            <span
              v-if="row.orderPart.partSizeDesc!='' &&row.orderPart.partSizeDesc!=null && row.orderPart.partSizeDesc!=undefined ">{{
                row.orderPart.partSizeDesc
              }}</span>
            <span v-else>{{ row.orderPart.partSize }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="40px"
          label="握口"
        >
          <template slot-scope="{row}">
            <span>{{row.orderPart.holdSize}}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="50"
          label="印数"
        >
          <template slot-scope="{row}">
            <span>{{ row.workPartQty }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="35"
          label="P数"
        >
          <template slot-scope="{row}">
            <span>{{ row.orderPart.pageQty }}</span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="纸张" width="100">
          <template slot-scope="scope">
            <span v-html="$options.filters.getEllipsis(scope.row.paperName)"></span>
          </template>
        </el-table-column>
        <el-table-column label="克数" width="60">
          <template slot-scope="scope">
            <span>{{ scope.row.orderPart.paperSuttle }}克</span>
          </template>
        </el-table-column>
        <el-table-column
          width="50px"
          label="面数"
        >
          <template slot-scope="{row}">
            <span style="color: #e4493c;font-weight: normal !important;" v-if="row.orderPart.faceCount==2">双面</span>
            <span style="color: #0077aa;font-weight: normal !important;" v-else-if="row.orderPart.faceCount==1">单面</span>
          </template>
        </el-table-column>
        <el-table-column
          width="60px"
          label="样式"
        >
          <template slot-scope="{row}">
            <span style="color: #409EFF;font-weight: normal !important;" v-if="row.orderPart.bookStyle==1">竖版</span>
            <span style="color: #F56C6C;font-weight: normal !important;" v-if="row.orderPart.bookStyle==2">横版</span>
            <span style="color: #0c4c99;font-weight: normal !important;" v-if="row.orderPart.bookStyle==3">直角</span>
            <span style="color: #d640ff;font-weight: normal !important;" v-if="row.orderPart.bookStyle==4">异形</span>
            <span style="color: #c640ff;font-weight: normal !important;" v-if="row.orderPart.bookStyle==5">刷胶胶左</span>
            <span style="color: #43f169;font-weight: normal !important;" v-if="row.orderPart.bookStyle==6">刷胶胶天</span>
          </template>
        </el-table-column>
        <el-table-column
          label="客户交货时间"
        >
          <template slot-scope="{row}">
            <span v-if="row.deliverDate">{{ row.deliverDate | getDeliverDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="180px"
          show-overflow-tooltip
          label="后工"
        >
          <template slot-scope="{row}">
            <span> {{ row.orderPart.allProcessStr }}</span>
          </template>
        </el-table-column>
        <el-table-column
          width="120px"
          label="客户"
        >
          <template slot-scope="{row}">
            <el-tooltip :content="row.clientName" placement="top-start" effect="light">
              <span class="ellipsis"> {{ row.clientName }}</span>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          label="锁定人"
          width="60px"
        >
          <template slot-scope="{row}">
            <span> {{ row.lockMan }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="生产备注"
          width="300px"
        >
          <template slot-scope="{row}">
            <el-popover
              placement="top-start"
              width="400"
              trigger="hover"
              :content="row.orderMemo">
              <span slot="reference" style="width: 200px" class="ellipsis"> {{ row.orderMemo }}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          label="款数"
          width="50px"
        >
          <template slot-scope="{row}">
            <span>{{ row.kindCount }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="发货备注"
          width="150px"
        >
          <template slot-scope="{row}">
            <el-popover
              placement="top-start"
              width="400"
              trigger="hover"
              :content="row.sendMemo">
              <span slot="reference" style="width: 200px" class="ellipsis"> {{ row.sendMemo }}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="订单消息" width="270">
          <template slot-scope="scope">
            <el-button size="mini" circle style="display: inline-block" icon="el-icon-circle-plus-outline"
                       @click.stop="openMessage(scope.row)"></el-button>
            <el-popover
              placement="top-start"
              width="400"
              trigger="hover"
              :content="scope.row.orderMessage">
              <a slot="reference" href="javascript:;" style="width: 230px;display: inline-block;vertical-align:middle"
                 class="ellipsis" @click.stop="openMessage(scope.row)">{{ scope.row.orderMessage }}</a>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          label="印刷要求"
          width="120px"
        >
          <template slot-scope="{row}">
            <span> {{ row.printRequire }}</span>
          </template>
        </el-table-column>
      </u-table>
    </div>

    <context-button v-if="menuVisible" @foo="foo" ref="contextbutton" @handleOne="handleOne" @handleTwo="handleTwo"
                    @handleThree="handleThree" @handleFour="handleFour"></context-button>
    <el-dialog title="订单详情" :close-on-click-modal="false" class="orderDetailDialog" :visible.sync="detailVisible"
               top="10px" width="1200px">
      <order-detail ref="orderDetail"></order-detail>
    </el-dialog>
    <el-drawer
      title="订单脚印"
      :reverse="true"
      :visible.sync="drawer"
      :with-header="false">
      <el-timeline style="width: 90%;margin-top: 20px">
        <el-timeline-item v-for="step in stepList"
                          :timestamp="timeString ? (step.workTime).substring(0,19):step.workMan+'  '+(step.workTime).substring(0,19)"
                          placement="top">
          <el-card class="stepList">
            <h4 style="margin: 5px 0">{{ step.workMemo }}</h4>
            <p>{{ step.workExplain }}</p>
          </el-card>
        </el-timeline-item>

      </el-timeline>
    </el-drawer>
    <el-dialog width="1200px" title="查看修图已分配,未分配订单列表" :visible.sync="orderTableVisible">
      <el-table
        size="mini"
        :data="tableDataOrder"
        row-key="id"
        border
        style="margin-top: 10px"
        ref="orderTable"
        :row-style="customRowStyle"
        default-expand-all>
        <el-table-column
          label="序号"
          fixed
          align="center"
          width="50"
          type="index">
          <template slot-scope="scope">
            <span>{{ (listDataOrder.page - 1) * listDataOrder.pageSize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="printOrder.orderCode"
          label="订单编号"
          width="100">
          <template slot-scope="{row}">
            <a href="javascript:;" style="color: #20a0ff"
               @click="getOrderStepUed(row.printOrder)">{{ row.printOrder.orderCode }}</a>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="printOrder.orderName"
          label="印品名称"
          width="110">
          <template slot-scope="{row}">
            <a href="javascript:;" style="color: #20a0ff" @click="openDetailUed(row.printOrder)">{{
                row.printOrder.orderName
              }}</a>
          </template>
        </el-table-column>
        <el-table-column
          prop="printOrder.productSize"
          label="成品尺寸"
          width="150">
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="printOrder.clientName"
          label="客户名称"
          width="100">
        </el-table-column>
        <el-table-column
          prop="printOrder.saleWorkTeamName"
          label="所属业务组"></el-table-column>
        <el-table-column
          label="状态">
          <template slot-scope="{row}">
            <el-tag size="mini" v-if="row.workStatus == 0">未分配</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 1">已分配</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 102">已退回</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 100">已完成</el-tag>
            <el-tag size="mini" v-else-if="row.workStatus == 103">直接完成</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="userName"
          label="修图人"></el-table-column>
        <el-table-column
          prop="processCount"
          label="处理次数"></el-table-column>
        <el-table-column
          prop="pCount"
          width="65"
          label="订单P数"></el-table-column>
        <el-table-column
          prop="printOrder.partCount"
          width="65"
          label="部件数量"></el-table-column>
        <el-table-column
          prop="processMemo"
          width="100"
          show-overflow-tooltip
          label="退回原因"></el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="printOrder.productName"
          label="产品类型"></el-table-column>
        <el-table-column
          prop="printOrder.orderMoneyTotal"
          width="65"
          label="订单金额"></el-table-column>
        <el-table-column label="文件描述" show-overflow-tooltip>
          <template slot-scope="{row}">
            <el-link :href="row.printOrder.originFileLink" target="_blank" style="color: #20a0ff">
              {{ row.printOrder.fileDescription }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column
          width="125"
          label="分配时间">
          <template slot-scope="{row}">
            <span v-if="row.dispatchTime"> {{ row.dispatchTime | getTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="printOrder.orderMemo"
          label="生产备注"></el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="printOrder.allProcessStr"
          label="订单后工"></el-table-column>
      </el-table>
      <pagination
        v-show="listDataOrder.total>0"
        :total="listDataOrder.total"
        :page.sync="listDataOrder.page"
        :limit.sync="listDataOrder.pageSize"
        @pagination="getList"/>
    </el-dialog>
    <el-drawer
      title="订单消息"
      :reverse="true"
      :visible.sync="memoDrawer"
      size="600px">
      <order-message @handleAddBreed="handleAddBreed" ref="orderMessage"></order-message>
    </el-drawer>
    <el-dialog width="1200px" top="50" title="手动版式" :visible.sync="dialogTableVisible ">
      <el-row :gutter="10">
        <el-col :span="24">
          <el-card  style="margin-top: -30px" class="box-card">
            <span style="display: block;margin-bottom: 7px;margin-top: -7px">订单列表</span>
            <div class="table-con">
              <el-table
                ref="editionTable"
                max-height="500"
                @row-click="handleClickTableRowEdition"
                row-key="id"
                @selection-change="handleSelectionChangeEdition"
                border
                @select='onTableSelect'
                size="mini"
                :data="gridData">
                <el-table-column :selectable="checkboxT"
                                 type="selection" width="40"></el-table-column>
                <el-table-column
                  label="id"
                  width="80"
                >
                  <template slot-scope="{row}">
                    <span>{{ row.id | getRowId }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="标记" width="90">
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.idFileProcessMan<=0" style="cursor: pointer" size="small"
                            @click.stop="getOrderStep(scope.row)" class="iconfont" title="查看脚印" type="danger">&#xe6ba
                    </el-tag>
                    <el-tag v-if="scope.row.idFileProcessMan>0" style="cursor: pointer" size="small"
                            @click.stop="getOrderStep(scope.row)" class="iconfont" title="查看脚印" type="success">&#xe6ba
                    </el-tag>
                    <el-tooltip v-if="scope.row.voidPrintBillCode!='' &&  scope.row.voidPrintBillCode!=undefined"
                                class="item" effect="dark" :content="'原单号：' + scope.row.voidPrintBillCode" placement="top-start">
                      <i style="color: #c20303;cursor: pointer;width: auto"   class="el-icon-delete-solid">有退回</i>
                    </el-tooltip>
                  </template>
                </el-table-column>
                <el-table-column label="部件名称" width="110">
                  <template slot-scope="{row}">
                     <span>{{ row.orderPart.partName }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="尺寸"
                  width="100"
                >
                  <template slot-scope="{row}">
                     <span>{{ row.orderPart.partSize }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="印数"
                  width="80"
                >
                  <template slot-scope="{row}">
                     <span>{{ row.workPartQty }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  width="60"
                  label="P数"
                >
                  <template slot-scope="{row}">
                    <span>{{ row.orderPart.pageQty }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  show-overflow-tooltip
                  label="纸张"
                  width="150"
                >
                  <template slot-scope="{row}">
                     <span> {{ row.paperName }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  width="40px"
                  label="握口"
                >
                  <template slot-scope="{row}">
                    <span>{{row.orderPart.holdSize}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="克重"
                  width="40"
                >
                  <template slot-scope="{row}">
                     <span>{{ row.orderPart.paperSuttle }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  width="50px"
                  label="面数"
                >
                  <template slot-scope="{row}">
                    <span style="color: #e4493c;font-weight: normal !important;" v-if="row.orderPart.faceCount==2">双面</span>
                    <span style="color: #0077aa;font-weight: normal !important;" v-else-if="row.orderPart.faceCount==1">单面</span>
                  </template>
                </el-table-column>
                <el-table-column
                  width="70"
                  label="样式"
                >
                  <template slot-scope="{row}">
                    <span style="color: #409EFF" v-if="row.orderPart.bookStyle==1">竖版</span>
                    <span style="color: #F56C6C" v-if="row.orderPart.bookStyle==2">横版</span>
                    <span style="color: #0c4c99" v-if="row.orderPart.bookStyle==3">直角</span>
                    <span style="color: #d640ff" v-if="row.orderPart.bookStyle==4">异形</span>
                    <span style="color: #c640ff" v-if="row.orderPart.bookStyle==5">刷胶胶左</span>
                    <span style="color: #43f169" v-if="row.orderPart.bookStyle==6">刷胶胶天</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="后工"
                  width="150"
                >
                  <template slot-scope="{row}">
                    <span>{{ row.orderPart.allProcessStr }}</span>
                  </template>
                </el-table-column>

              </el-table>
            </div>

          </el-card>

        </el-col>
        <el-col :span="24">
          <div style="margin: 20px 0;">
            <!--            <el-button icon="el-icon-bottom" @click="handleCommand" size="mini">增加部件</el-button>-->
            <!--            <el-select  @change="addFormat(valueFormat)" style="width: 110px" size="mini" v-model="valueFormat" placeholder="增加部件">-->
            <!--              <el-option-->
            <!--                key="999"-->
            <!--                @click="addFormatExisting"-->
            <!--                label="新建部件"-->
            <!--                value="999">-->
            <!--              </el-option>-->
            <!--              <el-option-->
            <!--                v-if="formatArray.length>0"-->
            <!--                v-for="(item,indexItem) in formatArray"-->
            <!--                :key="indexItem"-->
            <!--                :label="'增加到第'+(indexItem+1)+'套'"-->
            <!--                :value="indexItem">-->
            <!--              </el-option>-->
            <!--            </el-select>-->
            <el-dropdown @command="handleCommand" size="medium">
              <el-button size="mini">
                增加部件<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">新 建 部 件</el-dropdown-item>
                <el-dropdown-item
                  v-if="formatArray.length>0"
                  v-for="(item,indexItem) in formatArray"
                  :key="indexItem"
                  :command="indexItem"
                >增加到第{{ indexItem + 1 }}套
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <el-button @click="automateHandle" size="mini">自动处理</el-button>
            <el-button size="mini">复制并粘贴</el-button>
            <el-button @click="allRecallFormat" icon="el-icon-arrow-up" size="mini">全部撤回</el-button>
          </div>
        </el-col>
        <el-col :span="24">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>版式</span>
            </div>
            <div>
              <el-row :gutter="10">
                <el-col :span="24">
                  <div
                    style="border-bottom: 1px solid #ddd;padding: 10px;padding-bottom: 5px;margin-top: -8px;"
                    v-for="(item,indexItem) in formatArray"
                    :key="item.indexItem"
                  >
                    <div><span style="line-height: 28px;font-size: 14px;color: #333">第{{ indexItem + 1 }}套</span>
                      <el-button @click="recallFormat(item,indexItem)" icon="el-icon-top" size="mini" plain>撤回部件
                      </el-button>
                    </div>
                    <div
                      style="margin-left: 10px;"
                      v-for="(order,index) in item"
                      :key="order.index"
                    >
                      <span style="line-height: 28px;font-size: 14px;color: #333">{{ order.orderPart.partName }}&nbsp;&nbsp;{{
                          order.paperTypeName
                        }}</span>
                    </div>
                  </div>
                </el-col>
              </el-row>

            </div>
          </el-card>
        </el-col>

      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible  = false">取 消</el-button>
        <el-button :disabled="btnDisabled" type="primary" @click="handleBreedReq">确 定</el-button>
      </div>
    </el-dialog>
    <order-step ref="orderStep"></order-step>
  </div>
</template>

<script>
import Vue from 'vue';
import UmyUi from 'umy-ui'
import 'umy-ui/lib/theme-chalk/index.css';// 引入样式u-mycss
Vue.use(UmyUi);
import {
  getInfo, lockWorkParts, unLockWorkParts,
  buildPrintBillExclusive
} from '@/api/printbill/editionList.js'
import {
  getOrderStepList,
  getSimpleProductInfoList
} from '@/api/order/orderList.js'
import {mapGetters} from 'vuex'
import OrderDetail from '@/components/orderDetail/orderDetail';
import {getPrintOrderList} from "@/api/specialEdition/dispatchOrder";
import OrderMessage from "@/components/orderMessage/orderMessage";
import contextButton from './contextButton/index.vue'
import {removeBillData} from '@/utils/auth'
import OrderStep from '@/components/orderStep/orderStep'

export default {
  name: "list",
  computed: {
    ...mapGetters([
      'name',
      'loginName',
      "userId"
    ]),
  },
  components: {
    OrderMessage,
    contextButton,
    OrderDetail,
    OrderStep
  },
  data() {
    return {
      typeAuto: 999,
      timeString: "",
      ids: "",
      tempIndex: [],
      arr1: [],
      arr2: [],
      btnDisabled: false,
      dialogTableVisible: false,
      formatArray: [],
      gridData: [],
      memoDrawer: false,
      rowData: {},
      stepList: [],
      drawer: false,
      htmlPrintRequire: "",
      orderTableVisible: false,
      tableDataOrder: [],
      detailVisible: false,
      menuVisible: false,
      multipleSelectionEdition: [],
      multipleSelection: [],
      processStateBtn: false,
      productList: [],
      spanLabel: 9999,
      LockBtn: false,
      tableData: [],
      list: [],
      productVal: [],
      listData: {
        total: 0,
        page: 1,
        pageSize: 300
      },
      listDataOrder: {
        total: 0,
        page: 1,
        pageSize: 20
      },
      search: {
        idProduct: "",
        orderName: "",
        paperName: "",
        paperSuttle: "",
        processState: ""
      },
      listLoading: false,
      checked: true,
      height: 760,
      rowHeight: 28
    }
  },
  mounted() {
    if (localStorage.getItem('productVal') == undefined || localStorage.getItem('productVal') == null || localStorage.getItem('productVal') == "") {
      this.productVal = [];
    } else {
      this.productVal = JSON.parse(localStorage.getItem('productVal'))
    }
    // 设置表格数据
    this.getTableInfo();
    removeBillData();
  },
  methods: {
    //手动组版
    handleEdition() {
      const _that = this;
      _that.formatArray = [];
      _that.htmlPrintRequire = "";
      _that.gridData.forEach(arrayItem => {
        _that.$set(arrayItem, 'isChecked', false);
      })
      _that.gridData = [];

      // console.log(_that.$store.state.tagsView);
      // return
      for (let i = 0; i < _that.$store.state.tagsView.cachedViews.length; i++) {
        var datas = _that.$store.state.tagsView.cachedViews[i];
        if (datas == "createPrintBill") {
          _that.$message("施工单正在新建中,请先处理未完成的任务！");
          return
        }
      }
      // alert("1")
      _that.multipleSelection = _that.$refs.plTable.getCheckboxRecords();
      // console.log(_that.$refs.plTable.getCheckboxRecords());
      if (_that.multipleSelection.length <= 0) {
        _that.$message("先选择订单");
        return
      }
      _that.multipleSelectionEdition.forEach(arrayItem => {
        _that.$set(arrayItem, 'isChecked', false);
      })
      for (let i = 0; i < _that.multipleSelection.length; i++) {
        _that.$set(_that.multipleSelection[i], 'isChecked', false);
        if (_that.multipleSelection[i].lockFlag != 1) {
          _that.$message({
            showClose: true,
            message: '选择的订单中有未锁定的订单！',
            type: 'warning'
          });
          return
        }
      }
      var getSelectionArray = [];
      if (_that.multipleSelection.length > 1) {
        for (let i = 0; i < _that.multipleSelection.length; i++) {
          var dataItem = _that.multipleSelection[i];
          if (dataItem.printRequire != null && dataItem.printRequire != undefined && dataItem.printRequire != "") {
            if (dataItem.printRequire.indexOf("严格追样") != -1 || dataItem.printRequire.indexOf("客户跟机") != -1) {
              getSelectionArray.push(dataItem)
            }

          }

        }
      }
      // console.log(getSelectionArray);
      if (getSelectionArray.length > 0) {
        _that.dialogTableVisible = false;
        var html = "";
        for (let i = 0; i < getSelectionArray.length; i++) {

          html += getSelectionArray[i].orderCode + ":" + getSelectionArray[i].printRequire + "<br>"
        }
        _that.htmlPrintRequire = html;
        // console.log(html);
        _that.$confirm(_that.htmlPrintRequire, '存在下列印刷要求的订单，是否并单', {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          _that.dialogTableVisible = true;
        });
      } else {
        _that.dialogTableVisible = true;
      }
      // console.log(workPartListArray);
      _that.gridData = _that.getItems(_that.multipleSelection);
      // console.log("_that.gridData",_that.gridData);

      _that.arr1 = [];
      _that.arr1.push(_that.copyDeep(_that.gridData));
      // console.log("_that.arr1",_that.arr1);
    },
    //订单解锁
    unLockWorkPartsHandle() {
      const _that = this;
      _that.multipleSelection = _that.$refs.plTable.getCheckboxRecords();
      if (_that.multipleSelection.length <= 0) {
        _that.$message("先选择订单");
        return
      }
      _that.$confirm('此操作将解锁订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'success'
      }).then(() => {
        _that.ids = _that.unique(_that.getIds(_that.multipleSelection)).toString();
        // console.log(_that.ids);
        var data = {
          "ids": _that.ids
        }
        unLockWorkParts(data).then(response => {
          // console.log(_that.multipleSelection);
          if (response.httpCode == 200) {
            _that.lockData(response.data.refreshIdList, 0);
            _that.$message.success("解锁成功");
          }
        }).catch(err => {
          // _that.$message.error(err)
        })
      }).catch(() => {
      });
    },
    //订单锁定
    lockWorkPartsHandle() {
      const _that = this;
      _that.multipleSelection = _that.$refs.plTable.getCheckboxRecords();
      if (_that.multipleSelection.length <= 0) {
        _that.$message("先选择订单");
        return
      }

      _that.$confirm('此操作将锁定订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        _that.ids = _that.unique(_that.getIds(_that.multipleSelection)).toString();
        // console.log(_that.ids);
        var data = {
          "ids": _that.ids
        }
        lockWorkParts(data).then(response => {
          if (response.httpCode == 200) {
            _that.lockData(response.data.workPartList, 1);
            _that.$message.success("订单锁定成功");
          }
        }).catch(err => {
          _that.$message.error(err)
        })
      }).catch(() => {
      });


    },
    //获取列表
    getTableInfo() {
      const _that = this;
      _that.listLoading = true;
      _that.LockBtn = false;
      // idProduct:"",
      //   orderName:"",
      //   paperName:"",
      //   paperSuttle:"",
      //   processState:false,
      var dataSearch = {};
      var ids = []
      for (let i = 0; i < _that.productVal.length; i++) {
        var datas = _that.productVal[i];
        ids.push(datas)
      }
      var idRemotes = ids.join(',');
      if (_that.productVal.length > 0) {
        dataSearch["idShouldProducts"] = idRemotes;
      }
      if (_that.search.orderName != "") {
        dataSearch["orderName"] = _that.search.orderName;
      }
      if (_that.search.paperName != "") {
        dataSearch["paperName"] = _that.search.paperName;
      }
      if (_that.search.paperSuttle != "") {
        dataSearch["paperSuttle"] = _that.search.paperSuttle;
      }
      if (_that.processStateBtn) {
        dataSearch["processState"] = -1;
      } else {
        dataSearch["processState"] = 2;
      }
      dataSearch["postPDF"] = 1;
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      // console.log("1111",dataSearch);
      var data = {
        "params": JSON.stringify(dataSearch),
        "page": JSON.stringify(page),
      }
      // console.log(data);
      getInfo(data).then(response => {
        _that.listData.total = response.total;
        _that.list = _that.list.concat(response.data);
        // console.log(_that.list);
        // 默认勾选已锁定的订单
        _that.listLoading = false;
        _that.$nextTick(() => {
          _that.$refs.plTable.reloadData(_that.tableData);
          _that.tableData.forEach((row, index) => {
            if (row.lockFlag == 1 && row.idLockMan == _that.$store.state.user.userId) {
              _that.$refs.plTable.toggleRowSelection([
                {
                  row: _that.tableData[index],
                  selected: true
                }
              ])
            }
          })

        })
        _that.getProductInfo();//获取产品类型列表
        // _that.$nextTick(() => {
        //   _that.tableData.forEach(row => {
        //       _that.$refs.fileTable.toggleRowSelection(row, false);
        //   })
        // })
      }).catch(err => {
        _that.listLoading = false
      })
    },
    lockData(data, type) {
      const _that = this;

      for (let i = 0; i < data.length; i++) {
        for (let j = 0; j < _that.tableData.length; j++) {
          if (type == 1) {
            if (data[i].id == _that.tableData[j].id) {
              //锁定
              _that.$set(_that.tableData[j], 'lockFlag', data[i].lockFlag);

              _that.$set(_that.tableData[j], 'idLockMan', data[i].idLockMan);
              _that.$set(_that.tableData[j], 'lockMan', data[i].lockMan);
              if (data[i].idLockMan == _that.$store.state.user.userId) {
                _that.$set(_that.tableData[j], 'isChecked', true);
                _that.$refs.plTable.toggleRowSelection([
                  {
                    row: _that.tableData[j],
                    selected: true
                  }
                ])
              } else {
                _that.$set(_that.tableData[j], 'isChecked', false);
                // _that.$refs.fileTable.toggleRowSelection(_that.tableData[j], false);
                _that.$refs.plTable.toggleRowSelection([
                  {
                    row: _that.tableData[j],
                    selected: false
                  }
                ])
              }
            }

          } else {
            //解锁

            if (data[i] == _that.tableData[j].id) {
              //解锁
              _that.$set(_that.tableData[j], 'lockFlag', 0);
              _that.$set(_that.tableData[j], 'isChecked', false);
              _that.$set(_that.tableData[j], 'idLockMan', 0);
              _that.$set(_that.tableData[j], 'lockMan', "");
              // _that.$refs.fileTable.toggleRowSelection(_that.tableData[j], false);
              _that.$refs.plTable.toggleRowSelection([
                {
                  row: _that.tableData[j],
                  selected: false
                }
              ])
            }

          }
        }
      }
    },
    selectable(row, index) {
      var _that = this;
      if (row.idFileProcessMan <= 0) {
        return false
      } else {
        if (row.lockFlag == 1 && _that.$store.state.user.userId != row.idLockMan) {
          return false
        } else {
          return true
        }
      }
    },
    allSelection() {
      this.$refs.plTable.toggleAllSelection()
    },
    clearSelection() {
      this.$refs.plTable.clearSelection()
    },
    // 适用于多量的数据选中
    partRowSelections(state) {
      //获取前面的500条数据。实际场景自己去给你要选中的数据
      let data = this.datas.slice(0, 500)
      // data是数据，state是选中还是取消选中
      this.$refs.plTable.partRowSelections(data, state)
    },
    // 适用于少量的数据选中,如果你要选择大量数据，请使用partRowSelections方法。
    toggleSelection(rows, type) {
      if (rows) {
        rows.forEach(row => {
          // 注意： 勾选方法与element不同哦
          // this.$refs.plTable.toggleRowSelection(row); // element表格是这样写的
          // 我们得这样写

          // 如果是固定选中
          if (type === '固定选中') {
            // toggleRowSelection方法参数不懂得去看文档api哦
            this.$refs.plTable.toggleRowSelection([
              {
                row: row,
                selected: true
              }
            ])
            // 下面这是切换选中
          } else {
            this.$refs.plTable.toggleRowSelection([
              {
                row: row
              }
            ])
          }
        });
      } else {
        this.$refs.plTable.clearSelection();
      }
    },
    // 获取复选框选中的行
    getCheckboxRecords() {
      console.log(this.$refs.plTable.getCheckboxRecords())
    },
    // 从 tempIndex 获取当前 row 需要合并的行数
    handleSameMerge({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 1) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 0) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 2) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 4) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 16) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 13) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 15) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 16) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 18) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 19) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 20) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
      if (columnIndex === 21) {
        return {
          rowspan: this.tempIndex[rowIndex],
          colspan: 1
        };
      }
    },
    tableRowClassName({row, rowIndex}) {
      var _that = this;
      if (_that.LockBtn) {
        if (row.lockFlag == 1 && row.idLockMan == _that.$store.state.user.userId) {
          return 'warning-row';
        } else {
          return 'warning-rowLock'
        }
      } else {
        if (row.lockFlag == 1 && row.idLockMan != _that.$store.state.user.userId) {
          return 'danger-row';
        } else if (row.indexSort % 2 == 0 && row.lockFlag != 1) {
          return "info-row";
        } else if (row.lockFlag == 1 && row.idLockMan == _that.$store.state.user.userId) {
          return 'warning-row';
        }
        return '';
      }

    },
    handleClickTableRow(row, event, column) {
      const _that = this;
      // console.log("444",_that.tableData);
      if (row.lockFlag == 1 && row.idLockMan != _that.$store.state.user.userId) {
        return
      }
      if (row.idFileProcessMan <= 0) {
        return
      }
      for (let i = 0; i < _that.tableData.length; i++) {
        if (row.idOrder == _that.tableData[i].idOrder) {
          // _that.$refs.plTable.partRowSelections(_that.tableData[i],"固定选中");
          _that.$refs.plTable.toggleRowSelection([
            {
              row: _that.tableData[i]
            }
          ])
        }

      }

      // _that.$refs.fileTable.toggleRowSelection(row);
    },
    openLabel(row) {
      // console.log(row);
      this.spanLabel = row.id;
    },
    closeLabel() {
      this.spanLabel = 9999;
    },
    productInfoChange(val) {
      // console.log(val);
      this.productVal = val;
      localStorage.setItem("productVal", JSON.stringify(this.productVal));
    },
    // 获取产品类型
    getProductInfo() {
      const _that = this
      var data = {}
      // console.log(data);
      getSimpleProductInfoList(data).then(response => {
        // console.log(response)
        const data = response.data
        _that.productList = data
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    //搜索
    searchData() {
      const _that = this;
      _that.listData.page = 1;
      _that.tableData = [];
      _that.list = [];
      _that.getTableInfo()
    },
    checkLock(val) {
      const _that = this;
      _that.processStateBtn = false;
      var dataLocked = [];
      let tempMergeIndex = [];
      let pos;
      if (_that.LockBtn) {
        for (let i = 0; i < _that.tableData.length; i++) {
          var dataItem = _that.tableData[i];
          if (dataItem.lockFlag == 1 && dataItem.idLockMan == _that.$store.state.user.userId) {
            dataLocked.push(dataItem)
          }
        }
        for (let i = 0; i < dataLocked.length; i++) {
          if (i === 0) {
            tempMergeIndex.push(1);
            pos = 0;
          } else {
            if (dataLocked[i].flag && (dataLocked[i].flag === dataLocked[i - 1].flag)) {
              tempMergeIndex[pos] += 1;
              tempMergeIndex.push(0);
            } else {
              tempMergeIndex.push(1);
              pos = i;
            }
          }
        }

        _that.tempIndex = tempMergeIndex
        _that.$refs.plTable.reloadData(dataLocked);
        dataLocked.forEach((row, index) => {
          _that.$refs.plTable.toggleRowSelection([
            {
              row: dataLocked[index],
              selected: true
            }
          ])

        })
      } else {
        for (let i = 0; i < _that.tableData.length; i++) {
          if (i === 0) {
            tempMergeIndex.push(1);
            pos = 0;
          } else {
            if (_that.tableData[i].flag && (_that.tableData[i].flag === _that.tableData[i - 1].flag)) {
              tempMergeIndex[pos] += 1;
              tempMergeIndex.push(0);
            } else {
              tempMergeIndex.push(1);
              pos = i;
            }
          }
        }

        this.tempIndex = tempMergeIndex;
        _that.$refs.plTable.reloadData(_that.tableData);
        _that.tableData.forEach((row, index) => {
          if (row.lockFlag == 1 && row.idLockMan == _that.$store.state.user.userId) {
            _that.$refs.plTable.toggleRowSelection([
              {
                row: _that.tableData[index],
                selected: true
              }
            ])
          }
        })
      }

    },
    checkState(val) {
      // console.log(val);
      const _that = this;
      _that.LockBtn = false;
      _that.listData.page = 1;
      _that.tableData = [];
      _that.list = [];
      _that.getTableInfo();
    },
    getIds(data) {
      const _that = this;
      var idArray = [];
      for (let i = 0; i < data.length; i++) {
        var datas = data[i];
        for (let j = 0; j < _that.tableData.length; j++) {
          if (data[i].idOrder == _that.tableData[j].idOrder) {
            idArray.push(_that.tableData[j].id)
          }
        }
      }
      return idArray
    },
    unique(arr) {
      return Array.from(new Set(arr))
    },
    //刷新表格
    tableRefresh() {
      this.$nextTick(() => {
        this.$router.replace({
          path: '/redirect' + "/printbill/editionList"
        })
        // this.$router.push(fullPath)
      })
    },
    clilkDispatchOrder() {
      this.orderTableVisible = true;
      this.getList();
    },
    rowContextmenu(row, column, event) {
      this.menuVisible = false;
      this.menuVisible = true;
      // if (row.lockFlag == 0) {
      //   this.$refs.fileTable.toggleRowSelection(row);
      // }
      // 阻止右键默认行为
      event.preventDefault()
      this.$nextTick(() => {
        this.$refs.contextbutton.init(row, column, event)
      })
    },
    handleOne(row) {
      const _that = this;
      // console.log(_that.multipleSelection);
      _that.multipleSelection = _that.$refs.plTable.getCheckboxRecords();
      if (_that.multipleSelection.length <= 0) {
        _that.$message("先选择订单");
        return
      }
      _that.ids = _that.unique(_that.getIds(_that.multipleSelection)).toString();
      var data = {
        "ids": _that.ids
      }
      lockWorkParts(data).then(response => {
        if (response.httpCode == 200) {
          _that.lockData(response.data.workPartList, 1);
          _that.$message.success("订单锁定成功");
        }


        // _that.$nextTick(() => {
        //   _that.$router.replace({
        //     path: '/redirect' + "/printbill/editionList"
        //   })
        //   // this.$router.push(fullPath)
        // })
        // _that.multipleSelection.forEach(arrayItem => {
        //   _that.$set(arrayItem, 'lockFlag', "1");
        //   _that.$set(arrayItem, 'isChecked', true);
        // })
      }).catch(err => {
        // _that.$message.error(err)
      })
    },

    handleTwo(row) {
      const _that = this;
      _that.multipleSelection = _that.$refs.plTable.getCheckboxRecords();
      if (_that.multipleSelection.length <= 0) {
        _that.$message("先选择订单");
        return
      }
      _that.ids = _that.unique(_that.getIds(_that.multipleSelection)).toString();
      var data = {
        "ids": _that.ids
      }
      unLockWorkParts(data).then(response => {
        if (response.httpCode == 200) {
          _that.lockData(response.data.refreshIdList, 0);
          _that.$message.success("解锁成功");
        }
        // _that.$nextTick(() => {
        //   _that.$router.replace({
        //     path: '/redirect' + "/printbill/editionList"
        //   })
        //   // this.$router.push(fullPath)
        // })
        // _that.multipleSelection.forEach(arrayItem => {
        //   _that.$set(arrayItem, 'lockFlag', "0");
        //   _that.$set(arrayItem, 'isChecked', false);
        //   _that.$set(arrayItem, 'idLockMan', 0);
        // })

      }).catch(err => {
        // _that.$message.error(err)
      })
    },
    handleThree() {
      // console.log('点击菜单三')
      const _that = this;
      _that.$refs.plTable.clearSelection();
      _that.tableData.forEach(row => {
        if (row.lockFlag == 1 && row.idLockMan == _that.$store.state.user.userId) {
          // console.log(row);
          _that.$refs.plTable.toggleRowSelection([
            {
              row: row
            }
          ])
        }
      })
    },
    handleFour() {
      // console.log('点击菜单四')
      const _that = this;
      _that.$refs.plTable.clearSelection();
      _that.tableData.forEach(row => {

        if (row.lockFlag == 0 && row.idFileProcessMan > 0) {
          // console.log(row);
          _that.$refs.plTable.toggleRowSelection([
            {
              row: row
            }
          ])
        }
      })
    },
    // 获取脚印
    getOrderStep(row) {
      const _that = this
      _that.drawer = true
      var data = {
        idOrder: row.idOrder
      }
      // console.log(data);
      getOrderStepList(data).then(response => {
        // console.log(response)
        const data = response.data
        _that.stepList = data
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    // 获取脚印
    getOrderStepUed(row) {
      const _that = this
      _that.$refs.orderStep.idOrder = row.id
      _that.$refs.orderStep.getOrderStep()
    },
    customRowStyle({row, rowIndex}) {
      if (row.processMemo != '' && row.processMemo != null) {
        return {
          background: '#e5b6b6'
        }
      }
    },
    getList() {
      var _that = this
      var params = {
        dispatchStates: "0,1"
      }
      var page = {
        pageIndex: _that.listDataOrder.page,
        pageSize: _that.listDataOrder.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      // console.log(data);
      getPrintOrderList(data).then(response => {
        // console.log(response)
        const data = response.data
        // //  组合表单数据
        _that.tableDataOrder = data;
        _that.listDataOrder.total = response.total
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    handleAddBreed(breedMsg) {
      // console.log("3123123123",breedMsg);
      const _that = this;
      this.memoDrawer = false;
      this.rowData.orderMessage = breedMsg;
    },
    foo() { // 取消鼠标监听事件 菜单栏
      this.menuVisible = false
      document.removeEventListener('click', this.foo)
    },
    // 订单消息
    openMessage(row) {
      var _that = this
      _that.memoDrawer = true;
      _that.rowData = row;
      _that.$nextTick(function () {
        // console.log(_that.$refs.orderMemo);
        _that.$refs.orderMessage.idOrder = row.idOrder
        _that.$refs.orderMessage.getList()
      })
    },
    openDetail(row) {
      var _that = this
      _that.detailVisible = true
      _that.$nextTick(() => {
        _that.$refs.orderDetail.idOrder = row.idOrder
        _that.$refs.orderDetail.getInfo()
      })
    },
    openDetailUed(row) {
      var _that = this
      _that.detailVisible = true
      _that.$nextTick(() => {
        _that.$refs.orderDetail.idOrder = row.id
        _that.$refs.orderDetail.getInfo()
      })
    },
    getItems(data) {
      const _that = this;
      var itemArray = [];
      for (let i = 0; i < data.length; i++) {
        var datas = data[i];
        for (let j = 0; j < _that.tableData.length; j++) {
          if (data[i].orderPart.partIndex == 0) {
            if (data[i].idOrder == _that.tableData[j].idOrder) {
              itemArray.push(_that.tableData[j])
            }
          }


        }
      }
      // console.log(itemArray);
      var c = itemArray.reverse().filter(function (item, index) {
        var _index = itemArray.findIndex(function (_item) {
          return item.id == _item.id;
        });
        return index == _index;
      });
      return c.reverse()
    },
    copyDeep(templateData) {
      // templateData 是要复制的数组或对象，这样的数组或者对象就是指向新的地址的
      return JSON.parse(JSON.stringify(templateData));
    },
    handleClickTableRowEdition(row, event, column) {
      const _that = this;
      if (row.isChecked) {
        return
      }
      // _that.$set(row , 'isChecked',  true)
      // console.log("3123123123123",row);
      for (let i = 0; i < _that.gridData.length; i++) {
        var datas = _that.gridData[i];
        if(row.idOrder==datas.idOrder){
          _that.$refs.editionTable.toggleRowSelection(datas);

        }
      }

    },
    onTableSelect(rows, row) {
      var _that = this;
      let selected = rows.length && rows.indexOf(row) !== -1
      // console.log("111",selected);
      // console.log("222",row);
      // console.log("333",_that.gridData);

      if(selected){
        for (let i = 0; i < _that.gridData.length; i++) {
          var datas = _that.gridData[i];
          // console.log("111",row.idOrder);
          // console.log("222",datas.idOrder);
          if(row.idOrder==datas.idOrder){
            _that.$nextTick( ()=>{
              _that.$refs.editionTable.toggleRowSelection(_that.gridData[i],true);
            })

          }
        }
      }else {
        for (let i = 0; i < _that.gridData.length; i++) {
          var datas = _that.gridData[i];
          if(row.idOrder==datas.idOrder){
            _that.$nextTick( ()=>{
              _that.$refs.editionTable.toggleRowSelection(_that.gridData[i],false);
            })

          }
        }
      }
    },
    handleSelectionChangeEdition(rows) {
      var _that = this;
      _that.multipleSelectionEdition = rows;
    },
    checkboxT(row, index) {
      if (row.isChecked) {
        return false;
      } else {
        return true;
      }
    },
    //增加部件
    handleCommand(command) {
      const _that = this;
      var dataArray = [];
      _that.typeAuto = 1;
      _that.multipleSelectionEdition.forEach(arrayItem => {
        // console.log("arrayItem",arrayItem);
        if (arrayItem.isChecked) {

        } else {
          _that.$set(arrayItem, 'isChecked', true);
          dataArray.push(arrayItem);
        }
      })
      // console.log("dataArray",dataArray);
      if (dataArray.length <= 0) {
        _that.$message("先选择订单");
        return
      }
      if (command == "a") {
        _that.formatArray.push(dataArray);
      } else {
        for (let i = 0; i < dataArray.length; i++) {
          _that.formatArray[command].push(dataArray[i]);
        }
      }

      // var arr1Data =  _that.formatArray;


    },
    //自动处理
    automateHandle() {
      const _that = this;
      _that.typeAuto = 2;
      _that.formatArray = [];
      // console.log("111",_that.arr1[0]);
      if (_that.multipleSelectionEdition.length <= 0) {
        _that.gridData.forEach(arrayItem => {
          _that.$set(arrayItem, 'isChecked', true);
        });
        for (var i = 0; i < _that.arr1[0].length; i++) {
          _that.$set(_that.arr1[0][i], 'isChecked', true);
          for (var j = i + 1; j < _that.arr1[0].length; j++) {
            if (_that.arr1[0][i].orderPart.paperTypeName == _that.arr1[0][j].orderPart.paperTypeName && _that.arr1[0][i].orderPart.paperSuttle == _that.arr1[0][j].orderPart.paperSuttle) {         //第一个等同于第二个，splice方法删除第二个
              _that.arr1[0][i].id = _that.arr1[0][i].id + "," + _that.arr1[0][j].id
              _that.arr1[0].splice(j, 1);
              j--;
            }
          }
        }
        _that.arr2 = _that.arr1[0].sort(function (a, b) {
          return b.orderPart.paperSuttle - a.orderPart.paperSuttle
        })
      } else {
        _that.multipleSelectionEdition.forEach(arrayItem => {
          _that.$set(arrayItem, 'isChecked', true);
        });
        _that.arr3 = JSON.parse(JSON.stringify(_that.multipleSelectionEdition));
        for (var i = 0; i < _that.arr3.length; i++) {
          _that.$set(_that.arr3[i], 'isChecked', true);
          for (var j = i + 1; j < _that.arr3.length; j++) {
            if (_that.arr3[i].orderPart.paperTypeName == _that.arr3[j].orderPart.paperTypeName && _that.arr3[i].orderPart.paperSuttle == _that.arr3[j].orderPart.paperSuttle) {         //第一个等同于第二个，splice方法删除第二个
              _that.arr3[i].id = _that.arr3[i].id + "," + _that.arr3[j].id
              _that.arr3.splice(j, 1);
              j--;
            }
          }
        }
        _that.arr2 = _that.arr3.sort(function (a, b) {
          return b.orderPart.paperSuttle - a.orderPart.paperSuttle
        })
      }


      // let arr2 = _that.gridData.sort(function(a,b){
      //   return b.orderPart.paperSuttle-a.orderPart.paperSuttle
      // })
      //
      // console.log("_that.multipleSelectionEdition",_that.multipleSelectionEdition);


      // console.log("arr2",_that.arr2);
      const s = new Set() //实例化对象
      _that.arr2.forEach(item => s.add(item.paperTypeName)) //添加值（Set可以去掉重复数据）
      let newData = Array.from({length: s.size}, () => []) //创建指定长度数组并添值
      _that.arr2.forEach(item => {
        let index = [...s].indexOf(item.paperTypeName) //找到指定下标
        newData[index].push(item) //添加数据
      })
      // console.log("newData",newData)
      _that.formatArray = newData;
      // console.log("_that.formatArray333",_that.formatArray);
    },
    //全部撤回
    allRecallFormat() {
      const _that = this;
      _that.formatArray = [];
      _that.gridData.forEach(arrayItem => {
        _that.$set(arrayItem, 'isChecked', false);
      })
    },
    //部分撤回
    recallFormat(item, index) {
      const _that = this;

      var ids = "";
      for (let i = 0; i < item.length; i++) {
        ids += item[i].id + ",";
      }
      _that.gridData.forEach(itemData => {

        if ((ids + ",").indexOf(itemData.id + ",") != -1) {
          _that.$set(itemData, 'isChecked', false);
        }
      })
      _that.$nextTick(() => {
        _that.formatArray.splice(index, 1);
      })
      // console.log(_that.formatArray);
      // for (let i = 0; i < item.length; i++) {
      //   for (let j = 0; j < _that.gridData.length; j++) {
      //     //
      //     console.log(_that.gridData[j].id + ",");
      //     if ((_that.gridData[j].id+",").indexOf(item[i].id+",")!=-1 ) {
      //       _that.$set(_that.gridData[j], 'isChecked', false);
      //     }
      //   }
      // }
    },
    handleBreedReq() {
      const _that = this;
      var dataArray = [];
      if (_that.formatArray.length <= 0) {
        _that.$message("部件不能为空");
        return
      }
      var htmlStr = "";
      for (let i = 0; i < _that.multipleSelectionEdition.length; i++) {
        var  datasItem  = _that.multipleSelectionEdition[i];
        htmlStr+=datasItem.orderPart.allProcessStr
      }
      console.log(htmlStr);
      if (htmlStr.indexOf('哑') !== -1 && htmlStr.indexOf('亮') !== -1) {
        _that.$confirm('选择的订单工艺中存在不同类型工艺, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          _that.confirmBreedReq();
        }).catch(() => {

        });
      }else {
        _that.confirmBreedReq();
      }
    },
    confirmBreedReq(){
      const _that = this;
      // console.log(_that.formatArray);
      if (_that.typeAuto == 1) {
        _that.formatArray.forEach(arr1Data => {
          for (var i = 0; i < arr1Data.length; i++) {
            for (var j = i + 1; j < arr1Data.length; j++) {
              if (arr1Data[i].orderPart.paperTypeName == arr1Data[j].orderPart.paperTypeName && arr1Data[i].orderPart.paperSuttle == arr1Data[j].orderPart.paperSuttle) {         //第一个等同于第二个，splice方法删除第二个
                arr1Data[i].id = arr1Data[i].id + "," + arr1Data[j].id
                arr1Data.splice(j, 1);
                j--;
              }
            }
          }
        })
      }
      var dataArray = [];
      for (let i = 0; i < _that.formatArray.length; i++) {
        var breedReqList = {
          breedName: "",
          idWorkPartStr: ""
        };
        var ids = Array.from(_that.formatArray[i], ({id}) => id);
        // console.log(ids.toString());
        // var datas = _that.formatArray[i];
        // console.log(datas);

        // var ids = [];
        // for (let j = 0; j < datas.length; j++) {
        //   // console.log(datas[j].id);
        //   ids.push(datas[j].id);
        //   breedReqList.breedName = datas[j].orderPart.partName;
        // }
        // idArray.push(ids);
        // // console.log(idArray);
        //
        // breedReqList.idWorkPartStr = idArray.toString();
        //
        // dataArray.push(breedReqList);
        var paperTypeName = Array.from(_that.formatArray[i], ({paperTypeName}) => paperTypeName);
        // console.log("paperName",paperName.toString());
        // console.log(_that.formatArray[i][0]);
        breedReqList.breedName = "第" + (i + 1) + "套版" + "(" + paperTypeName + ")";
        breedReqList.idWorkPartStr = ids.toString();
        dataArray.push(breedReqList);
      }

      // console.log("dataArray",dataArray);
      // return
      _that.btnDisabled = true;
      var data = {
        "breedReqList": JSON.stringify(dataArray)
      }
      buildPrintBillExclusive(data).then(response => {
        _that.$message.success("组版成功,页面跳转中");
        _that.listData.page = 1;
        _that.tableData = [];
        _that.list = [];
        _that.getTableInfo();
        _that.dialogTableVisible = false;
        var bill = response.data;
        localStorage.setItem("bill", JSON.stringify(response.data));
        // _that.$router.push({path:'/printbill/createPrintBill/'+bill.id,query:{id:bill.id,clientName:bill.billName}})
        _that.$router.push({
          path: '/printbill/createPrintBill/',
          query: {id: bill.id, containsOrderIds: bill.containsOrderIds, clientName: bill.billName}
        })
        _that.btnDisabled = false;
      }).catch(err => {
        _that.btnDisabled = false;
        // _that.$message.error(err)
      })
    },
  },
  watch: {
    list: {
      handler(nv) {
        //处理订单信息
        // console.log(nv)
        // console.log(this.listData.page);
        let arr = [];
        let tempMergeIndex = [];
        let pos;
        nv.forEach((item, i) => {
          // console.log("111111",item)
          if (item.workPartList && item.workPartList.length) {
            if (item.workPartList.length > 1) {
              let sourceArr = item.workPartList.map(_ => {
                return {
                  ..._,
                  flag: i + '',
                  class_label: '单号:' + item.orderCode + ',\n' + '名称:' + item.productName + ',\n' + '印品名称:' + item.orderName + ',\n',
                  idFileProcessMan: item.idFileProcessMan,//判断文件有木有处理完成字段
                  checkDateLong: item.checkDateLong,//订单审核时间
                  printRequire: item.printRequire,//印刷要求
                  orderCode: item.orderCode,//订单编号
                  kindCount: item.kindCount,//款数
                  sendMemo: item.sendMemo,//发货备注
                  voidPrintBillCode:item.voidPrintBillCode,//作废标记
                  businessKind: item.businessKind,//判断补印订单
                  rePrintIndex: item.rePrintIndex,//补印次数
                  indexSort: i
                };
              });
              arr.push(...sourceArr);
            } else {
              let sourceArr = item.workPartList.map(_ => {
                return {
                  ..._,
                  flag: i + '',
                  class_label: '单号:' + item.orderCode + ',\n' + '名称:' + item.productName + ',\n' + '印品名称:' + item.orderName,
                  idFileProcessMan: item.idFileProcessMan,//判断文件有木有处理完成字段
                  checkDateLong: item.checkDateLong,//订单审核时间
                  printRequire: item.printRequire,//印刷要求
                  orderCode: item.orderCode,//订单编号
                  kindCount: item.kindCount,//款数
                  sendMemo: item.sendMemo,//发货备注
                  voidPrintBillCode:item.voidPrintBillCode,//作废标记
                  businessKind: item.businessKind,//判断补印订单
                  rePrintIndex: item.rePrintIndex,//补印次数
                  indexSort: i
                };
              });
              arr.push(...sourceArr);
            }


          } else {
            arr.push(item);
          }
        });
        this.tableData = this.tableData.concat(arr);
        // if(this.disabledData){
        //   if(this.tableData.length >= this.listData.total){
        //     this.disabledData = true;
        //   }
        // }

        // console.log("this.tableData",this.tableData);
        // 处理arr，生成一个与行数相同的数组记录每一行设置的合并数
        for (let i = 0; i < this.tableData.length; i++) {
          if (i === 0) {
            tempMergeIndex.push(1);
            pos = 0;
          } else {
            if (this.tableData[i].flag && (this.tableData[i].flag === this.tableData[i - 1].flag)) {
              tempMergeIndex[pos] += 1;
              tempMergeIndex.push(0);
            } else {
              tempMergeIndex.push(1);
              pos = i;
            }
          }
        }

        this.tempIndex = tempMergeIndex;
        // console.log(this.tempIndex);
      },
      deep: true,
      immediate: true
    }
  }
}
</script>
<style>
.demo-table-expand {
  margin-bottom: -1px;
}


/*.table-con .el-table__header-wrapper  .el-checkbox{*/
/*  display:none*/
/*}*/
.area-select .area-selected-trigger {
  padding: 0px 20px 7px 12px !important;
}

.area-select {
  height: 40px !important;
}

.el-table__expanded-cell {
  padding: 0px !important;
  padding-left: 97px !important;
}

.expand-table {
  border-bottom: none !important;
}

.hline-table .el-table .cell {
  white-space: pre-line;
}


.hline-table .el-table .info-row {
  background: #F6F6F6;
}

.hline-table .el-table .warning-row {
  color: #409EFF !important;
  font-weight: bold;
  /*background: yellow !important;*/
}

/*.hline-table .el-table .warning-row a {*/
/*  color: #409EFF !important;*/
/*  font-weight: bold;*/
/*  !*background: yellow !important;*!*/
/*}*/
/*//'warning-rowLock'*/
.hline-table .el-table .warning-rowLock {
  display: none;
}

.hline-table .el-table .success-row {
  background: #f0f9eb !important;
}

.hline-table .el-table .danger-row {
  color: #F56C6C !important;
}

/*.hline-table .el-table .danger-row a{*/
/*  color: #F56C6C !important;*/
/*}*/
.hline-table .el-table .cell {
  line-height: 16px;
}

/*.hline-tabletr{pointer-events: none; }*/
.el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(0, 0, 0, 0) !important;
}
</style>

<style lang="scss" scoped>
::v-deep .hline-table .el-table__body tr.current-row > td {
  background-color: transparent !important;
}

::v-deep .plTableBox .el-table--mini td, .plTableBox .el-table--mini th {
  padding: 0px 0 !important;
}

::v-deep .el-table__fixed {

  bottom: 15px !important;

}

::v-deep .el-select__tags {
  flex-wrap: unset;
  overflow: auto;
}

.card-tit {
  float: left;
  height: 100%;
  min-height: 200px;
  max-height: 200px;
  font-size: 14px;
  color: #7c7c7c;
  width: 20px;
  margin: 0 auto;
  line-height: 20px;
  padding: 20px;
  padding-left: 10px;
  border-right: 1px solid #ddd;
}

.area-select {
  height: 40px;
}

.filter-container {
  margin-bottom: 15px;
}

.print-tit {
  color: #7c7c7c;
}

.print-con {
  color: #333;
}

.item-print {
  margin-bottom: 10px;
}

.el-timeline {
  padding: 0px;
  padding-top: 15px;
}

.itemli {
  display: block;
  float: left;
  padding: 5px;
  font-size: 14px;
  color: #333;
  border-bottom: 1px solid #ddd;
  border-left: 1px solid #ddd;
  border-right: 1px solid #ddd;
}

.itemTh {
  display: block;
  padding: 5px;
  float: left;
  font-size: 12px;
  color: #7c7c7c;
  border-bottom: 1px solid #ddd;
  border-left: 1px solid #ddd;
  border-right: 1px solid #ddd;
}

.table-imiate .itemTh:nth-child(1) {
  width: 60px;
}

.table-imiate .itemTh:nth-child(2) {
  width: 150px;
}

.bg {
  background: #EBEEF5;
  color: #409EFF;
  padding-left: 5px;
}
</style>
