<template>
  <div class="innerCheck-detail" ref="detailView" :class="screen ? 'screen' : ''">
    <div ref="Main" class="innerCheck-operate">
      <p-spin :spinning="spinning">
        <!-- 顶部工具条 -->
        <div class="innerCheck-toolbar">
          <a-space>
            <p-button @click="F1KeyUp" type="primary">F1商品确认</p-button>
            <!-- <p-button @click='F2KeyUp' type='primary'>F2拼箱</p-button> -->
            <p-button @click="F3KeyUp" type="primary">F3关箱</p-button>
            <!-- <p-button @click='F5KeyUp' type='primary'>F5刷新</p-button> -->
            <p-button @click="F4KeyUp" :disabled="!superoisedBtn" type="primary">F4扫描监管码</p-button>
            <p-button @click="F6KeyUp" :disabled="!superoisedBtn" type="primary">F6扫描序列号</p-button>
            <!-- <p-button v-if='saveBtnStatus' @click='saveInnerCheckDetails' :disabled='dataSource.length === 0'
                      type='primary'>F6保存
            </p-button> -->
            <p-button @click="printHandler" type="primary">打印标签</p-button>
            <p-button @click="F8KeyUp" type="primary">F8任务查看</p-button>
            <!-- <p-button @click='F9KeyUp' type='primary'>F9差异记录</p-button> -->
            <!--<p-button @click='F10KeyUp' type='primary'>F10复核取消</p-button>-->
            <span style="font-size: 18px; color: red">{{ currLclNo }}</span>
          </a-space>
          <a-space>
            <div style="font-weight: bold">
              <!--                          <a-checkbox :checked='printBoxDetail' @change='changePrintBoxDetail'>是否打印拼箱明细</a-checkbox>-->
              <a-icon style="margin-right: 5px" type="desktop" />
              工作台: {{ stationCode }}
            </div>
            <p-button @click="changePage">退出</p-button>
            <span class="screen-box">
              <a-icon @click="Fullscreen" class="iconqp" style="font-size: 25px; color: white" type="arrows-alt" />
            </span>
          </a-space>
        </div>
        <!-- 中间主体 -->
        <div class="detail-content">
          <div class="detail-scanBox">
            <div class="detail-scanBox-item">
              <span class="label">容器:</span>
              <div class="content">
                <a-input
                  ref="inputContainerCode"
                  size="large"
                  v-model.trim="containerCodeValue"
                  allowClear
                  @pressEnter="enterContainer"
                  placeholder="请扫描容器"
                />
              </div>
            </div>
            <div class="detail-scanBox-item">
              <span class="label">扫码:</span>
              <div class="content">
                <a-input
                  ref="inputitemBarCode"
                  size="large"
                  v-model.trim="itemBarcodeValue"
                  allowClear
                  @pressEnter="enterBarcode"
                  placeholder="请扫描条码/编码/助记码"
                />
              </div>
            </div>
            <div class="detail-message">
              <div class="detail-message-icon" v-show="scan == 0">
                <div class="detail-message-text">请扫描容器</div>
              </div>
              <div class="detail-message-icon" v-show="scan == 1">
                <div class="detail-message-text">请扫码</div>
              </div>
              <div class="detail-message-icon" v-show="scan == 2">
                <div class="detail-message-text">OK</div>
              </div>
              <div class="detail-message-icon err" v-show="scan == 3">
                <div class="detail-message-text">扫码错误</div>
              </div>
              <div class="detail-message-icon ok" v-show="scan == 4">
                <div class="detail-message-text">复核完成</div>
              </div>
            </div>
            <div class="detail-total">
              <div class="detail-total-left">
                <div class="container-field-item">
                  <div class="field-item-label">已检查：</div>
                  <div class="field-item-content">{{ containerVO.checkedNum }}</div>
                </div>
                <div class="container-field-item">
                  <div class="field-item-label">已冲红：</div>
                  <div class="field-item-content">{{ containerVO.redNum ? containerVO.redNum : 0 }}</div>
                </div>
                <div class="container-field-item">
                  <div class="field-item-label">总数量：</div>
                  <div class="field-item-content">{{ containerVO.totalNum }}</div>
                </div>
              </div>
              <div class="detail-total-right">
                <div class="container-field-item">
                  <div class="field-item-label">品种总数：</div>
                  <div class="field-item-content">
                    {{ `${containerVO.checkedVarieties}/${containerVO.totalVarieties}` }}
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="detail-info">
            <div class="detail-info-item border">
              <a-row class="field-wrap">
                <a-col :span="12" class="field-item">
                  <div class="field-item-label">货主名称：</div>
                  <div class="field-item-content">{{ billDetail.consignorName }}</div>
                </a-col>
                <a-col :span="6" class="field-item">
                  <div class="field-item-label">订单编码：</div>
                  <div class="field-item-content">{{ billDetail.billGroupId }}</div>
                </a-col>
                <a-col :span="6" class="field-item">
                  <div class="field-item-label">业务员:</div>
                  <div class="field-item-content">
                    {{ itemsDetail.salespersonName ? itemsDetail.salespersonName : "" }}
                  </div>
                </a-col>
              </a-row>
              <a-row class="field-wrap">
                <a-col :span="12" class="field-item">
                  <div class="field-item-label">客户名称：</div>
                  <div class="field-item-content">{{ billDetail.shipperName }}</div>
                </a-col>
                <a-col :span="6" class="field-item">
                  <div class="field-item-label">账期类型：</div>
                  <div class="field-item-content">{{ itemsDetail.paymentType }}</div>
                </a-col>
                <a-col :span="6" class="field-item">
                  <div class="field-item-label">开票员：</div>
                  <div class="field-item-content">{{ itemsDetail.createby }}</div>
                </a-col>
              </a-row>
              <a-row class="field-wrap">
                <a-col :span="18" class="field-item">
                  <div class="field-item-label">备注：</div>
                  <div class="field-item-content">{{ itemsDetail.remark }}</div>
                </a-col>
                <a-col :span="6" v-if="isEndBox == 1" class="field-item">
                  <h1 style="color: red" class="field-item-content">当前容器号为尾箱！</h1>
                </a-col>
              </a-row>
            </div>
            <div class="detail-info-item">
              <a-row class="field-wrap">
                <a-col :span="16" class="field-item">
                  <div class="field-item-label">商品名称：</div>
                  <div class="field-item-content">{{ itemsDetail.itemName }}</div>
                </a-col>
                <a-col :span="8" class="field-item">
                  <div class="field-item-label">计划数量：</div>
                  <div class="field-item-content">{{ currentCheckInfoVo.qty }}</div>
                </a-col>
                <a-col :span="16" class="field-item">
                  <div class="field-item-label">生产厂家：</div>
                  <div class="field-item-content">{{ itemsDetail.manufacturerId }}</div>
                </a-col>
                <a-col :span="8" class="field-item">
                  <div class="field-item-label">已拣数量：</div>
                  <div class="field-item-content red">{{ currentCheckInfoVo.pickQty }}</div>
                </a-col>
                <a-col :span="16" class="field-item">
                  <div class="field-item-label">规格：</div>
                  <div class="field-item-content">{{ itemsDetail.specification }}</div>
                </a-col>
                <a-col :span="8" class="field-item">
                  <div class="field-item-label">复核数量：</div>
                  <div class="field-item-content red">{{ currentCheckInfoVo.checkQty }}</div>
                </a-col>
                <a-col :span="16" class="field-item">
                  <div class="field-item-label">批号：</div>
                  <div class="field-item-content red">{{ currentCheckInfoVo.lotNo }}</div>
                </a-col>
                <a-col :span="8" class="field-item">
                  <div class="field-item-label">复核数量(双人)：</div>
                  <div class="field-item-content red">{{ itemsDetail.check2Qty }}</div>
                </a-col>
                <a-col :span="24" class="field-item">
                  <div class="field-item-label">贵重品：</div>
                  <div class="field-item-content red">
                    {{
                      currentCheckInfoVo.itemIsValuable === "1"
                        ? "是"
                        : currentCheckInfoVo.itemIsValuable === "1"
                        ? "否"
                        : ""
                    }}
                  </div>
                </a-col>
                <a-col :span="16" class="field-item">
                  <div class="field-item-label">单位：</div>
                  <div class="field-item-content">
                    {{
                      itemsDetail.uom
                        ? itemsDetail.uom +
                          "," +
                          itemsDetail.productionDate.substring(0, 10) +
                          "," +
                          itemsDetail.expiredDate.substring(0, 10)
                        : ""
                    }}
                  </div>
                </a-col>
                <a-col :span="8" class="field-item">
                  <div class="field-item-label">是否双人复核：</div>
                  <div class="field-item-content red">
                    {{
                      itemsDetail.itemHealthIsDouble == "1" ? "是" : itemsDetail.itemHealthIsDouble == "0" ? "否" : ""
                    }}
                  </div>
                </a-col>
              </a-row>
            </div>
          </div>
        </div>
        <!-- 底部明细表格 -->
        <div class="detail-table">
          <p-table
            dragle
            bordered
            hasRowSelectCheck
            size="small"
            :columns="columns"
            :dataSource="dataSource"
            rowKey="_oid"
            :pagination="100"
            :rowSelectType="2"
            :scroll="{ x: true, y: 250 }"
            :selectedRowKeys.sync="selectedRowKeys"
            @dblclickRow="dblclickRow"
            :rowClassName="rowClassName"
          >
            <div slot="action" slot-scope="text">
              <a @click.stop="bartNoCheck(text)">冲红</a>
              <!-- <a class='ml-10' @click.stop='itemDet(text)'>商品维护</a> -->
              <a class="ml-10" @click.stop="showSplit(text)">拆分</a>
            </div>
          </p-table>
        </div>
        <!-- 标签补打条-->
        <div class="print-box">
          <a-space :style="{ marginBottom: '6px' }">
            <div style="display: inline-block; width: 95%">
              <a-input
                v-model.trim="billGroupIdValue"
                allowClear
                @pressEnter="enterLclinfo"
                placeholder="请输入订单编码补打"
              />
            </div>
            <template v-if="barcodeDListMore.lcls.length < 8">
              <p-button
                @click="viewLcninfo(item)"
                v-for="item in barcodeDListMore.lcls"
                :key="item.index"
                :type="item.lclNo === barcodeDListMore.currLclNo ? 'danger' : 'primary'"
              >
                {{ item.lclNo == 0 ? "整" : item.type == 1 ? `整${item.lclNo}` : "拼" + item.lclNo }}
              </p-button>
            </template>
            <template v-if="barcodeDListMore.lcls.length > 7">
              <p-button
                @click="viewLcninfo(item)"
                v-for="item in barcodeDList.lcls"
                :key="item.index"
                :type="item.lclNo === barcodeDList.currLclNo ? 'danger' : 'primary'"
              >
                {{ item.lclNo == 0 ? "整" : item.type == 1 ? `整${item.lclNo}` : "拼" + item.lclNo }}
              </p-button>
            </template>
            <a v-if="barcodeDListMore.lcls.length > 7" @click="moreview">更多</a>
          </a-space>
        </div>
      </p-spin>
    </div>
    <!-- 解锁弹窗 -->
    <workerLogin
      :loginVisible="loginVisible"
      :isSupervisedData="isSupervisedData"
      @loginResult="loginResult"
      @handleCancel="loginhandleCancel"
    />
    <!-- 拼箱弹窗 -->
    <a-modal
      width="700px"
      title=""
      ok-text="打印"
      :visible="LCLinfoVisible"
      :confirm-loading="confirmLoading"
      @cancel="handleCancel"
    >
      <template slot="footer">
        <div v-if="isCaseOrPiece" class="printclass">
          <span>打印份数:</span>
          <p-input style="width: 60px; margin-left: 5px" class="printinput" v-model="printNum" type="number" />
        </div>
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" @click="handleOkPrint('2')">打印</a-button>
        <!--        <a-button type='primary' v-if='!isCaseOrPiece' @click='handleDetailPrint'>明细打印</a-button>-->
        <!--        <a-button type='primary' v-if='!isCaseOrPiece' @click='deleteLcl'>拼箱删除</a-button>-->
        <a-button type="primary" v-if="!isCaseOrPiece" @click="eidthandleOk">确认</a-button>
      </template>
      <p style="margin-top: 35px; padding-right: 10px">
        <lCLinfo
          ref="lCLtable"
          v-if="LCLinfoVisible"
          :isCaseOrPiece="isCaseOrPiece"
          :makeUpStatus="makeUpStatus"
          :data="lCLdata"
          :selectedRows="selectedRowsLcninfo"
        />
      </p>
    </a-modal>
    <!-- 补打拼箱弹窗 -->
    <a-modal
      :getContainer="(triggerNode) => $refs.detailView"
      width="700px"
      title=""
      ok-text="打印"
      :visible="makeUpinfoVisible"
      :confirm-loading="confirmLoading"
      @cancel="handleCancel"
    >
      <template slot="footer">
        <div v-if="isCaseOrPiece" class="printclass">
          <span>打印份数:</span>
          <p-input-number
            style="width: 60px; margin-left: 5px"
            class="printinput"
            :min="0"
            :precision="0"
            v-model="printNum"
            type="number"
          />
        </div>
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" @click="handleOkPrint('2')">打印</a-button>
        <!--        <a-button type='primary' v-if='!isCaseOrPiece' @click='handleDetailPrint'>明细打印</a-button>-->
      </template>
      <p style="margin-top: 35px; padding-right: 10px">
        <lCLinfo
          ref="lCLtable"
          v-if="makeUpinfoVisible"
          :isCaseOrPiece="isCaseOrPiece"
          :makeUpStatus="makeUpStatus"
          :data="lCLdata"
          :selectedRows="selectedRowsLcninfo"
        />
      </p>
    </a-modal>
    <!-- 红冲弹窗 -->
    <a-modal
      :getContainer="(triggerNode) => $refs.detailView"
      title=""
      :visible="HCVisible"
      :confirm-loading="confirmLoading"
      @ok="handleOkHC"
      @cancel="handleCancelHC"
    >
      <p-grid-form ref="modelForm" :span="20" :label-col="{ span: 8 }" :items="items" />
    </a-modal>
    <!-- 拼箱展示弹窗 -->
    <a-modal
      :getContainer="(triggerNode) => $refs.detailView"
      title=""
      width="600px"
      :footer="null"
      :visible="LCLVisible"
      :confirm-loading="confirmLoading"
      @ok="handleCancel"
      @cancel="LCLhandleCancel"
    >
      <p style="margin-top: 35px; padding-right: 10px">
        <p-button
          @click="viewLcninfo(item)"
          style="margin: 10px"
          v-for="item in barcodeDListMore.lcls"
          :key="item.index"
          :type="item.lclNo === barcodeDListMore.currLclNo ? 'danger' : 'primary'"
        >
          {{ item.lclNo == 0 ? "整" : item.type == 1 ? `整${item.lclNo}` : "拼" + item.lclNo }}
        </p-button>
      </p>
    </a-modal>
    <!-- 补打拼箱展示弹窗 -->
    <a-modal
      :getContainer="(triggerNode) => $refs.detailView"
      title="补打拼箱展示"
      width="600px"
      :footer="null"
      :visible="makeUpVisible"
      :confirm-loading="confirmLoading"
      @cancel="makeUphandleCancel"
      @ok="handleCancel"
    >
      <p style="padding-right: 10px">
        <p-button
          @click="viewLcninfo(item, true)"
          style="margin: 10px"
          v-for="item in makeUpData.lcls"
          :key="item.index"
          :type="item.lclNo === makeUpData.currLclNo ? 'danger' : 'primary'"
        >
          {{ item.lclNo == 0 ? "整" : item.type == 1 ? `整${item.lclNo}` : "拼" + item.lclNo }}
        </p-button>
      </p>
    </a-modal>
    <!-- 扫描监管码弹窗 -->
    <scanCode v-model="scanVisible" :stage="stage" :scanTable="scanTableList" />

    <!-- <scanCode v-model="scanVisible" :stage="stage" :scanTable="scanTableList" /> -->

    <IsSeque-code :stage="stage" v-model="IsSequeVisible" ref="IsSeque" :scanTable="scanTableList"></IsSeque-code>
    <p-modal
      title="商品维护"
      :visible="maintainVisible"
      :dialogStyle="{ top: '20px' }"
      :width="'90%'"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <div class="box-p20-bg">
        <Editor
          v-if="maintainVisible"
          ref="itemsEditor"
          :detailItem="detailItem"
          :isSingle="true"
          @changeStep="handleItemsComplete"
        />
      </div>
    </p-modal>
    <!-- 扫描序列号 -->
    <p-modal
      title="扫描序列号"
      width="500px"
      :visible="visible_container"
      :enlargeable="true"
      :draggable="true"
      centered
      @cancel="xlhandleCancel"
      :footer="null"
    >
      <p-input
        ref="scan"
        size="large"
        v-model="xlcontainerCode"
        placeholder="请扫描序列号"
        @pressEnter="pressEnter"
        allowClear
      >
        <a-icon slot="prefix" type="scan" />
      </p-input>
    </p-modal>

    <a-modal v-model="fxVisible" title="" @ok="handleOk">
      <template #footer>
        <a-button key="submit" type="primary" @click="fxhandleOk">封箱F9</a-button>
        <a-button key="back" @click="fxhandleCancel">等待F10</a-button>
      </template>
      <h1>{{ fxMessage }}</h1>
    </a-modal>

    <!-- 容器号 -->
    <containerdialog
      v-if="containerdialogvisible"
      v-model="containerdialogvisible"
      :containerArray="containerArray"
      @clickContainer="clickContainer"
    />
    <!-- 差异处理 -->
    <differenceDialog
      v-if="differenceVisible"
      v-model="differenceVisible"
      :differenceData="differenceData"
      :differenceObj="differenceObj"
    />
    <!-- 明细拆分 -->
    <detailSplitModal
      v-if="showSplitModal"
      :visible.sync="showSplitModal"
      :splitRecord="splitRecord"
      @success="detailSplit"
    />
    <!-- 查看任务 -->
    <viewtasksModel
      :stationCode="stationCode"
      :ViewTasksVisible="ViewTasksVisible"
      @setContainerCodeValue="setContainerCodeValue"
      @hideModel="hideModel"
    />
  </div>
</template>
<script>
import { mapActions } from "vuex";
import { setColumns, printcolumns, items } from "./components/config";
import lCLinfo from "./components/LCLinfo";
import workerLogin from "./components/workerLogin";
import scanCode from "../../components/scanCode.vue";
// src/views/kzyWMS/inBound/quality/billEditor/components/IsSequeCode.vue

import IsSequeCode from "../../components/IsSequeCode.vue";
import containerdialog from "./components/containerdialog.vue";
import differenceDialog from "./components/differenceDialog.vue";
import { toPrintServer, tempType } from "@/views/kzyWMS/utils/printServer.js";
import Editor from "../../../basedata/goodsManager/editor.vue";
import viewtasksModel from "./components/viewtaskModel/viewtasksModel.vue";
import viewTaksMixin from "./components/viewtaskModel/viewTaksMixin.js";
import detailSplitModal from "./components/detailSplitModal";
import keyUpMixin from "./mixins/keyUpMixin";
import {
  getItemConfirm,
  checkLclBarcode,
  LclQuery,
  getPrintInfo,
  getDetailPrintInfo,
  eidtlclNum,
  postpieceBreak,
  deleteLclNo,
  pagebyRelated,
  search_noPage,
  isSupervised,
  getWholePrintInfo,
  postsaveInnerCheckDetails,
  queryFuncRoomPrintList,
  innerPrintLabel,
  innerCheckConfig,
  getContainer2,
  saveRedhc2,
  getItemnum2,
  pickTaskCancel,
  checkContainerConfirm,
  pickTaskDetailSplit,
} from "./api";

export default {
  name: "checkDetail",
  components: {
    lCLinfo,
    workerLogin,
    scanCode,
    Editor,
    containerdialog,
    differenceDialog,
    viewtasksModel,
    detailSplitModal,
    "IsSeque-code": IsSequeCode,
  },
  mixins: [viewTaksMixin, keyUpMixin],
  props: {
    // 是否全屏
    screen: {
      type: Boolean,
      default: false,
    },
    // 复核台信息
    stationInfo: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      IsSequeVisible: false,
      // 明细拆分
      showSplitModal: false,
      splitRecord: {},

      columns: setColumns(this),
      rowSelectType: false,
      boxTypevalue: "",
      selectedRowKeys: [], //当前选中行id 0021145181,
      promise_res2: null,
      printDataVisibal: false,
      scan: 0,
      orderInfo: { askFor: 0, choose: 0, reviewed: 0, confirmed: 0, complete: 0, billGroupId: "", containerCode: "" },
      containerVO: {
        checkedLot: 0, //已经检查的批号
        checkedNum: 0, //已检数量
        checkedVarieties: 0, //已经检查的品种数量
        containerCode: null,
        totalLot: 0,
        orderUncheckedTaskNum: 0, // 订单待复合数
        totalNum: 0, //总数量
        totalVarieties: 0, //总品种
        unCheckedLot: 0,
        unCheckedNum: 0,
        unCheckedVarieties: 0,
      },
      currentCheckInfoVo: {},
      dataSource: [],
      itemsDetail: {
        itemName: null,
        manufacturerId: null,
        specification: null,
        billCode: null,
        lotNo: null,
        itemHealthIsDouble: null,
        cargoOwnerName: null,
        qty: 0,
        pickQty: 0,
        checkQty: 0,
        check2Qty: 0,
      },
      billDetail: {
        billGroupId: "",
        consignorName: "",
        shipperName: "",
      },
      itemsData: {
        billGroupId: "",
        containerCode: "",
        itemBarcode: "",
        lclNo: "",
        pickTaskDId: "",
        qty: 1,
        stationCode: "14",
        stationId: "",
        userNames: [],
        pickTaskId: "",
      },
      batchNum: "",
      form: this.$form.createForm(this),
      loginform: this.$form.createForm(this),
      items: items(this),
      printcolumns: printcolumns,
      printData: [],
      itemId: "",
      loginVisible: false,
      confirmLoading: false,
      LCLinfoVisible: false,
      HCVisible: false,
      LCLVisible: false,
      isShow: 1,
      spinning: false,
      resData: {},
      itemCode: "",
      videoDom: "",
      ContainerCodefocus: null,
      itemBarCodefocus: null,
      doubleCheck: [],
      lclNo: "",
      barcodeDListMore: { lcls: [] },
      barcodeDList: {
        lcls: [],
      },
      lCLdata: {},
      makeUpData: { lcls: [] },
      makeUpVisible: false,
      makeUpStatus: false,
      makeUpinfoVisible: false,
      stempStatus: {
        containerstatus: false,
        goodsInfoStatus: false,
      },
      isSupervisedData: {},
      itemHealthIsDouble: "",
      editStatus: false,
      refData: {},
      scanTableList: [],
      scanVisible: false,
      selectedRowsLcninfo: [],
      workertwo: {},
      superoisedBtn: true,
      stage: 2, //扫码阶段：0=入库质检 1=PC拣货 2=PC内复核 3=PC外复核 4=补录 5=PDA拣货 6=PDA内复核 7=PDA外复核
      tiemID: null,
      timer: null,
      isCaseOrPiece: false,
      printNum: 1, //整件打印份数
      shipperName: "",

      maintainVisible: false,
      detailItem: null,
      containerdialogvisible: false,
      containerArray: [],
      saveBtnStatus: true,
      containerCodeValue: "",
      itemBarcodeValue: "",
      lastitemBarcodeValue: "",
      billGroupIdValue: "",

      differenceVisible: false,
      differenceData: [],
      differenceObj: {},
      pickTaskId: {},
      ViewTasksVisible: false, //查看任务显示
      checkPickTaskList: [],

      // 是否打印拼箱明细
      printBoxDetail: false,

      // 缓存复核商品数据
      cacheCheckItem: null,
      visible_container: false,
      xlcontainerCode: "",
      fxVisible: false,
      fxMessage: "",
      isEndBox: "",
    };
  },
  created() {
    // 是否打印拼箱明细
    this.printBoxDetail = localStorage.getItem("printBoxDetail") == "1" ? true : false;

    // 获取上方左侧工作台信息
    this.workbench();
    this.pushUserInfo();
    this.itemsData.stationCode = this.stationCode;
    this.itemsData.stationId = this.stationId;
    this.itemsData.workCode = this.$store.getters.userInfo.employeeNo;
    this.itemsData.warehouseId = this.warehouse.warehouseId;
    // this.isShowSupervised() // 判断监管码弹窗是否显示
  },
  mounted() {
    this.$refs.inputContainerCode.focus();
  },
  computed: {
    // 从选择站台中带出
    stationCode() {
      return this.stationInfo.stationCode;
    },
    stationId() {
      return this.stationInfo.stationId;
    },
    isDoubleCheck() {
      return this.stationInfo.isDoubleCheck;
    },
    checkUser() {
      return this.$store.state.outBound.checkPerson;
    },
    warehouse() {
      return this.$store.getters.warehouse || {};
    },
    userInfo() {
      return this.$store.getters.userInfo || {};
    },
    // 当前的配箱号
    currLclNo() {
      const { lcls, currLclNo } = this.barcodeDListMore || {};
      const curLcl = lcls?.find((_) => _.lclNo === currLclNo) || {};
      const { lclNo = "", type } = curLcl;
      if (lclNo == 0) return "整";
      return type == 1 ? `整${lclNo}` : `拼${lclNo}`;
    },
    // 当前拼箱号
    currentLclNo() {
      const { lcls, currLclNo } = this.barcodeDListMore || {};
      const curLcl = lcls?.find((_) => _.lclNo === currLclNo) || {};
      const { lclNo = "" } = curLcl;
      return lclNo;
    },
  },
  methods: {
    ...mapActions(["CheckLoginIn"]),
    // 修改是否打印拼箱明细
    changePrintBoxDetail(event) {
      this.printBoxDetail = event.target.checked;
      const printBoxDetailFlag = this.printBoxDetail ? "1" : "0";
      localStorage.setItem("printBoxDetail", printBoxDetailFlag);
    },
    // 刷新页面
    reloadPage() {
      location.reload();
    },
    // 全屏
    Fullscreen() {
      this.$emit("fullscreenEven");
    },
    differentRecord() {
      if (this.dataSource === 0) {
        this.$message.error("请获取容器商品数据");
        return;
      }
      const selectedRowKeys = this.selectedRowKeys;
      const selectedRows = this.dataSource.filter((_) => selectedRowKeys.includes(_._oid));
      this.differenceData = selectedRows;
      this.differenceObj = {
        stationId: this.itemsData.stationId,
        containerCode: this.itemsData.containerCode,
        pickTaskId: this.itemsData.pickTaskId,
      };
      this.differenceVisible = true;
    },
    checkOutCancel() {
      if (this.dataSource === 0) {
        this.$message.error("请先扫描容器获取数据!");
        return;
      }
      const isDoubleCheck = this.isDoubleCheck;
      const selectedRowKeys = this.selectedRowKeys;
      const selectedRows = this.dataSource.filter((_) => selectedRowKeys.includes(_._oid));

      let params = {};
      if (selectedRows.length > 0) {
        const pickTaskDId = selectedRows.map((item) => item.pickTaskDId).join(",");
        params = {
          pickTaskDId,
          itemHealthIsDouble: isDoubleCheck,
          pickTaskHId: this.itemsData.pickTaskId,
        };
      } else {
        params = {
          pickTaskDId: this.checkPickTaskList.join(","),
          itemHealthIsDouble: isDoubleCheck,
          pickTaskHId: this.itemsData.pickTaskId,
        };
      }
      pickTaskCancel(params).then((res) => {
        if (res.success) {
          this.enterContainer(); //扫描容器号
          this.$message.success(res.message);
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 双击复核
    dblclickRow(event, activeID, rowRecord) {
      this.currentCheckInfoVo = rowRecord; //展示即将复核的数据
      const { itemCode } = rowRecord;
      this.itemBarcodeValue = itemCode;
      this.enterBarcode();
    },
    async dbClickIsSupervise(list) {
      let SuperviseStatus = list.every((item) => {
        return item.isSupervise == 0;
      });
      if (SuperviseStatus) {
        this.$message.info("无需扫描监管码");
        return;
      }
      let SupervisedList = list;
      let isSupervisedStatus;
      if (SupervisedList.length > 0) {
        if (SupervisedList[0].isSupervise == 1) {
          isSupervisedStatus = await this.isSupervised(SupervisedList, null, false);
        }
        if (SupervisedList[0].isSupervise == 2) {
          isSupervisedStatus = await this.isSupervised(SupervisedList, null, true);
        }

        // console.log(isSupervisedStatus);
        if (isSupervisedStatus) {
          return;
        }
      }
    },
    pushUserInfo() {
      if (this.doubleCheck.length > 0) {
        this.doubleCheck.forEach((items) => {
          console.log(items);
          console.log(this.checkUser);
          if (items.userId !== this.checkUser.userId) {
            this.doubleCheck.push(this.checkUser);
            this.itemsData.userNames.push(this.checkUser.username);
          } else {
            this.$message.error("请不要重复登录");
          }
        });
      } else {
        this.doubleCheck.push(this.checkUser);
        this.itemsData.userNames.push(this.checkUser.username);
      }
    },
    isShowSupervised() {
      let _this = this;
      innerCheckConfig({ warehouseId: this.warehouse.warehouseId }).then((res) => {
        if (res.data.scanSupervisionCodeStage == 2 || res.data.scanSupervisionCodeStage == 3) {
          _this.superoisedBtn = true;
        }
        _this.saveBtnStatus = res.data.pickWay == "0" ? true : false;
      });
    },

    async isScanCode(data) {
      let type = await this.getDetailData().then((params) => {
        console.log(params.rqcLinesDTOList);
        if (!params.rqcLinesDTOList) return;
        let list = params.rqcLinesDTOList.filter((i) => i.isSupervise != 0).map((i) => i.isSupervise);
        console.log(list);
        list = [...new Set(list)];
        console.log(list);
        if (list.length > 1) {
          this.$message.warning("选中行扫描类型不一致 不能同时选中!");
          return false;
        } else {
          return true;
        }
      });
      console.log(type);
      return type;
    },
    async isSupervised(data, checkCode, type) {
      let list = data.map((item) => {
        const obj = {
          ...item,
          pieceQty: item.pickQty - (item.redQty ? item.redQty : 0),
          refBillId: item.billCode, //拣选任务主表id
          refBillLineId: item.pickTaskDId, //拣选任务明细id
        };
        return obj;
      });
      list = list.filter((i) => i.pieceQty > 0);
      let res = await isSupervised(list);
      if (res.success) {
        this.scanTableList = data.filter((item) => {
          item.refBillId = item.billCode;
          item.refBillLineId = item.pickTaskDId;
          item.pieceQty = item.pickQty - (item.redQty ? item.redQty : 0);
          item.itemNum = item.itemCode;
          item.itemSpecs = item.specification;
          item.containerCode = this.itemsData.containerCode;
          item.srcCode = item.billCode;
          item.manufacturerLotNum = item.lotNo;
          return item.isSupervise;
        });
        if (res.data !== true && list.length) {
          this.showScanModel(this.scanTableList, type);
          return false;
        } else if (checkCode == "checkCode") {
          this.showScanModel(this.scanTableList, type);
          return false;
        } else {
          // this.$message.error('监管码已经全部扫描完成');
          return true;
        }
      }
    },
    showScanModel(list, type) {
      console.log(type);
      if (!list.length) return;
      let data = list.filter((i) => i.isSupervise != 0).map((i) => i.isSupervise);
      console.log(data);
      data = [...new Set(data)];
      console.log(data);
      if (data.length > 1) {
        this.$message.warning("选中行扫描类型不一致 不能同时选中!");
        return false;
      }
      let isSupervise = list[0].isSupervise || null; //
      if (type == undefined) {
        isSupervise == 1 ? (type = false) : (type = true);
      }
      //   if (!type && list[0]) {
      // this.$message.error(`没有需要扫描${isSupervise == 1 ? "监管码" : "序列号"}的数据!`);
      // return;
      //   }
      //   if (type && list[0] && isSupervise != 2) {
      //     this.$message.error("没有需要扫描序列号的数据!");
      //     // return;
      //   }
      //   console.log(list, type);
      if (type && list[0] && isSupervise == 2) {
        this.IsSequeVisible = true;
      }

      if (!type && list[0] && isSupervise == 1) {
        this.scanVisible = true;
      }
    },
    resetData() {
      this.selectedRowKeys = []; //复核确认后清空商品勾选数据
      this.itemsDetail = {};
      this.billDetail = {};
      this.isEndBox = ""; //是否为尾箱
      this.containerVO = {
        totalNum: 0,
        orderUncheckedTaskNum: 0,
        checkedNum: 0,
        totalVarieties: 0,
        checkedVarieties: 0,
        checkedLot: 0,
      };
      this.dataSource = [];
      this.cacheCheckItem = null;
      this.containerCodeValue = "";
      this.itemBarcodeValue = "";
      this.billGroupIdValue = "";
      this.$refs.inputContainerCode.stateValue = "";
      this.$refs.inputitemBarCode.stateValue = "";
      this.barcodeDListMore = { lcls: [] };
      this.barcodeDList = { lcls: [] };
    },
    itemDet(data) {
      this.detailItem = { itemId: data.itemId };
      this.maintainVisible = true;
    },
    // 获取上方左侧工作台信息
    workbench() {
      const params = {
        num: "innerCheckTaskQuery",
        params: {
          warehouseId: this.warehouse.warehouseId,
          stationCode: this.stationCode,
        },
      };
      search_noPage(params).then((res) => {
        // 状态 0：待索取askFor  1：待拣选choose 2：待复核索取reviewed   3.待复核确认confirmed  10：完成complete
        // status: "1"  totalNum: 1
        const hashMap = {
          0: "askFor",
          1: "choose",
          2: "reviewed",
          3: "confirmed",
          10: "complete",
        };
        const orderInfo = {};
        if (res.data && res.data.success && res.data.data) {
          res.data.data.forEach((item) => {
            const key = hashMap[item.status];
            if (key) orderInfo[key] = item.totalNum;
          });
          this.orderInfo = orderInfo;
        }
      });
    },
    resultColumns(taskDetail) {
      this.columns.forEach((column) => {
        const key = column.dataIndex;
        if (!key) return;
        taskDetail.forEach((taskDetailRecord) => {
          taskDetailRecord._oid = taskDetailRecord.barcodeDId + "-" + taskDetailRecord.pickTaskDId;
          //   if (!taskDetailRecord?.pieceQty) {
          //     taskDetailRecord.pieceQty =
          //       taskDetailRecord.pickQty - (taskDetailRecord.redQty ? taskDetailRecord.redQty : 0);
          //   }

          if (typeof taskDetailRecord[key] === "undefined" || taskDetailRecord[key] == null) {
            taskDetailRecord[key] = column.type === "number" ? 0 : "";
          }
        });
      });
      return taskDetail;
    },
    //复核完后的数据填充
    detailDataFilled(res) {
      //获取拼箱号
      this.lclNoDataFun(res.data);
      this.selectedRowKeys = []; // 清空勾选数据
      //上方右侧容器信息
      this.containerVO = res.data.containerInfo;
      //最下方表格数据
      setTimeout(() => {
        this.dataSource = this.resultColumns(res.data.innerCheckTaskDVOS);
      }, 0);
      //  以下过滤主键商品id找到当前行 ，赋值给右上角展示面板
      this.stempStatus.containerstatus = true;
      this.itemsData.billGroupId = res.data.billGroupId; //订单分组id (必填)
      this.shipperName = res.data.shipperName; // 获取客户名称
    },
    printHandler() {
      // printFlag，0不打印，1打印
      const params = {
        billGroupId: this.itemsData.billGroupId,
        containerCode: this.containerCodeValue,
        lclNo: this.lclNo,
        printFlag: "1",
      };
      const warehouseId = this.warehouse.warehouseId;
      innerPrintLabel(params).then((res) => {
        toPrintServer(res.data.data, warehouseId, "itemList.dataMark").then((res) => {
          if (!res.success) {
            this.$exception(res);
            return;
          }
          this.$message.success(res.message);
        });
      });
    },
    // left join 右表，商品信息
    two_promise(params) {
      return new Promise((reslove, reject) => {
        pagebyRelated(params).then((res) => {
          this.spinning = false;
          if (res.data.success) {
            this.promise_res2 = res.data;
            // console.log('this.promise_res2:',this.promise_res2)
            return reslove(res.data);
          } else {
            return reject(res.message);
          }
        });
      });
    },
    //处理容器数据
    containerData(res) {
      this.detailDataFilled(res);
      this.itemsData.containerCode = this.containerCodeValue;
      this.billDetail.billGroupId = res.data.billGroupId;
      this.billDetail.consignorName = res.data.consignorName;
      this.billDetail.shipperName = res.data.shipperName;
      this.dataSource = this.resultColumns(res.data.innerCheckTaskDVOS);
    },
    // 扫描容器号
    enterContainer(e) {
      this.scan = 1;
      this.spinning = true;
      this.itemBarcodeValue = "";
      this.$refs.inputContainerCode.blur();
      const isDoubleCheck = this.isDoubleCheck;
      const params = {
        warehouseId: this.itemsData.warehouseId,
        containerCode: this.containerCodeValue,
        stationCode: this.itemsData.stationCode,
        lclNo: this.lclNo,
        isDoubleCheck,
      };
      getContainer2(params)
        .then((res) => {
          this.spinning = false;
          if (res.success) {
            this.detailDataFilled(res);
            const resData = res.data;
            // 判断容器全部扫完，提示弹出复核确认
            console.log("this.containerVO", this.containerVO);
            if (this.containerVO.checkedNum == this.containerVO.totalNum) {
              this.scan = 4;
              this.$message.success("当前容器商品已全部复核完成！");
            }
            this.$refs.inputitemBarCode.focus();
            this.itemsData.containerCode = this.containerCodeValue;
            this.itemsData.pickTaskId = resData.pickTaskHId;
            this.billDetail.billGroupId = resData.billGroupId;
            this.billDetail.consignorName = resData.consignorName;
            this.billDetail.shipperName = resData.shipperName;
            this.isEndBox = resData.isEndBox;
            this.dataSource = this.resultColumns(resData.innerCheckTaskDVOS);
            console.log(this.dataSource, "======");
            this.itemsDetail = {}; //切换容器时,清空商品数据
            this.currentCheckInfoVo = {}; //切换容器时,清空商品数据
          } else {
            this.$message.error(res.message);
          }
        })
        .catch((err) => {
          console.log("promise捕获错误：", err);
        });
    },
    // 查询商品编码
    enterBarcode(e) {
      if (!this.stempStatus.containerstatus) {
        this.$message.error("请扫描容器号");
        return;
      }
      const itemBarcodeValue = String(this.itemBarcodeValue).trim();
      let lastitemBarcodeValue = this.lastitemBarcodeValue;
      console.log(this.dataSource);
      let rowRecord = this.dataSource.find((i) => i.itemCode == itemBarcodeValue);
      //   itemBarcodeValue
      console.log(rowRecord);
      if (rowRecord) {
        this.currentCheckInfoVo = rowRecord;
        this.itemsDetail = rowRecord;
      }
      if (itemBarcodeValue != lastitemBarcodeValue) {
        this.lastitemBarcodeValue = itemBarcodeValue;
        return;
      }

      //   return;
      // 在明细中查找匹配的物料
      const scanItem = this.dataSource.find((item) => {
        // 找行id的逻辑是，根据商品找到list，顺序判断商品的复核数量 + 冲红数量等于拣货数量的跳过，
        // 复核数量有两个字段，cherqty，checher2qty,是二次复核的时候选checker2qty,否则选checkQty
        // 判断是否扫描过
        const isDoubleCheck = this.isDoubleCheck;
        const compareQty = String(isDoubleCheck) === "0" ? item.checkQty + item.redQty : item.check2Qty + item.redQty;
        if (Number(compareQty) === Number(item.pickQty)) return false;
        const { itemBarcode, pieceBarcode, caseBarcode, barCode, barcodeOld, itemCode, itemAssistantCode } = item;

        const flag1 = [itemBarcode, pieceBarcode, caseBarcode, barCode, barcodeOld].includes(itemBarcodeValue);
        const flag2 = itemCode?.includes(itemBarcodeValue);
        const flag3 = itemAssistantCode?.includes(itemBarcodeValue);
        return flag1 || flag2 || flag3;
      });
      // 未找到匹配的物料
      if (!scanItem) {
        this.scan = 3;
        this.itemsDetail = this.dataSource[0];
        this.itemsDetail.shipperName = this.shipperName; //给商品信息 客户名称赋值
        return;
      }
      this.itemsDetail = scanItem;
      this.itemsDetail.shipperName = this.shipperName; //给商品信息 客户名称赋值
      const { itemId, redQty, pickQty, innerCheckDId, itemCode, pickTaskDId } = scanItem;
      let checkPickTaskDDTOList = [];
      let checkList = [];
      this.dataSource.forEach((item) => {
        if (item.itemId == itemId) {
          this.checkPickTaskList.push(item.pickTaskDId);
          checkList.push(item);
          checkPickTaskDDTOList.push({
            pickTaskDId: item.pickTaskDId,
            qty: item.pickQty - (item.redQty ? item.redQty : 0),
          });
        }
      });
      this.scan = 2;
      // 让当前选中
      this.selectedRowKeys.length = 0;
      // 复核任务/数量复核商品 接口/inner/check/item/number
      console.log(this.containerCodeValue);
      const params = {
        workCode: this.userInfo.employeeNo, //员工号
        isDoubleCheck: this.isDoubleCheck, //是否双人复核
        lclNo: this.lclNo, //当前拼箱号
        qty: pickQty - (redQty ? redQty : 0), //拣货数量
        innerCheckDId: innerCheckDId, //内复核明细行id
        containerCode: this.containerCodeValue, //当前拣货容器号
        stationCode: this.itemsData.stationCode, //复核台编号
        billGroupId: this.itemsData.billGroupId, //订单分组id
        itemCode: itemCode,
        pickTaskDId: pickTaskDId,
        warehouseId: this.itemsData.warehouseId,
        checkPickTaskDDTOList,
      };

      // 执行商品复核
      this.checkItemHandler(params);
      checkList = checkList.filter((item) => item.isSupervise);
      if (checkList.length) {
        this.dbClickIsSupervise(checkList);
      }
    },
    // 执行商品复核操作
    checkItemHandler(params) {
      let checkItem;
      // 取出缓存的待复核商品入参
      checkItem = this.cacheCheckItem;
      this.$nextTick(() => {
        // 将传入的复核放入缓存
        this.cacheCheckItem = params;
      });
      if (!params) return;
      this.spinning = true;
      return (
        getItemnum2(params)
          //   return getItemnum2(checkItem)
          .then((res) => {
            this.spinning = false;
            if (res.success) {
              console.log(this.itemBarcodeValue);
              this.detailDataFilled(res);
              this.currentCheckInfoVo = res.data.currentCheckInfoVo;

              let lotNo = res.data.currentCheckInfoVo.lotAndNumList.map((item) => {
                const { lotNo, num } = item;
                return `${lotNo}(${num})`;
              });

              this.currentCheckInfoVo.lotNo = lotNo.join(",");

              // this.enterContainer(null, 'scanningItem') //扫描容器号
              this.itemBarcodeValue = "";
              this.$refs.inputitemBarCode.stateValue = "";
              //聚焦扫码框
              this.$refs.inputitemBarCode.focus();
              //遍历当前复核商品明细
              // const currentRow = res.data.innerCheckTaskDVOS.filter(item => item.pickTaskDId == pickTaskDId)
              // this.itemsDetail.check2Qty = currentRow[0].check2Qty
              // this.itemsDetail.checkQty = currentRow[0].checkQty
              this.scan = 2; // 将扫描状态置为OK.
              // this.enterBarcode();			//自动/手动扫描商品编码
              //判断是否需要扫序列号
              //   if (currentRow.itemIsSeque == 1) {
              // this.visible_container = true
              //   }

              console.log("准备扫描下一条商品条码前：", res);
            } else {
              this.$exception(res);
            }
          })
          .finally(() => {
            this.spinning = false;
          })
      );
    },
    enterLclinfo() {
      const params = {
        stationCode: this.itemsData.stationCode,
        billGroupId: this.billGroupIdValue,
      };
      LclQuery(params).then((res) => {
        if (res.success) {
          if (!res.data) return;
          this.makeUpData = res.data;
          this.makeUpVisible = true;
          // if (res.data.lcls.length > 7) {
          // 	let arr = [];
          // 	res.data.lcls.forEach((item, index) => {
          // 		if (index < 7) {
          // 			arr.push(item);
          // 		}
          // 	});

          // 	this.barcodeDList = { currLclNo: res.data.currLclNo, lcls: arr };
          // }
          // this.barcodeDListMore = res.data;
        }
      });
      //   }
      // })
    },
    rowClassName(record, index) {
      // 找行id的逻辑是，根据商品找到list，顺序判断商品的复核数量 + 冲红数量等于拣货数量的跳过，
      // 复核数量有两个字段，cherqty，checher2qty,是二次复核的时候选checker2qty,否则选checkQty
      const isDoubleCheck = this.isDoubleCheck;
      const { checkQty, check2Qty, redQty, pickQty } = record;
      const compareCheckQty = isDoubleCheck == "0" ? checkQty : check2Qty;
      //   compareCheckQty + redQty === pickQty
      if (compareCheckQty == null) {
        compareCheckQty = 0;
      }
      let arr = this.dataSource.filter((item) => {
        return item.itemCode == record.itemCode;
      });

      if (compareCheckQty + redQty === pickQty) {
        return "rowColorGray";
      } else {
        if (arr.length > 1 && compareCheckQty + redQty !== pickQty) {
          return "rowYellow";
        }
        return "Ndefault";
      }
      //判断是否有相同的商品，如果有列表显示黄色

      //   return compareCheckQty + redQty === pickQty ? "rowColorGray" : "Ndefault";
    },
    VueDebounce() {
      clearTimeout(this.tiemID);
      this.tiemID = setTimeout(() => {
        console.log("执行节流函数");
      }, 1000);
    },
    clickContainer(data) {
      // this.form.setFieldsValue({ containerCode: data })
      // this.containerCodeValue = data
      this.containerCodeValue = data;
      this.$refs.inputContainerCode.stateValue = data;
    },
    async checkConfirm() {
      let SupervisedList = this.dataSource.filter((item) => item.isSupervise >= "1");
      if (SupervisedList.length > 0) {
        let isSupervisedStatus = await this.isSupervised(SupervisedList);
        if (!isSupervisedStatus) {
          return;
        }
      }
      this.confirmFun();
    },
    confirmFun() {
      // 复核确认
      let params = this.itemsData;
      params.innerCheckTaskDVOS = this.dataSource;
      params.boxType = this.boxTypevalue ? this.boxTypevalue : "";
      params.operateCode = this.userInfo.employeeNo;
      let _this = this;
      checkContainerConfirm(params).then((res) => {
        if (res.success) {
          // _this.barcodeDListMore = {lcls: []}
          // _this.barcodeDList = {lcls: []}
          _this.$message.success(res.message);
          if (res.data.isShow == 1) {
            this.fxVisible = true;
            this.fxMessage = res.data.msg;
          } else {
            _this.resetData();
          }
          if (res.data && res.data.length > 0) {
            _this.containerArray = res.data;
            _this.containerdialogvisible = true;
          }
          // 清空容器码
          _this.form.setFieldsValue({ containerCode: "" });
          _this.$refs.inputContainerCode.focus();
          this.currentCheckInfoVo = {};
        } else {
          _this.$exception(res);
        }
      });
    },
    fxhandleOk() {
      //封箱
      this.currentPrint("reset");
      this.fxVisible = false;
    },
    fxhandleCancel() {
      this.resetData();
      this.fxVisible = false;
    },
    wholepiecesplit() {
      if (!this.stempStatus.containerstatus) {
        this.$message.error("请扫描容器号");
        return;
      }
      const params = {
        stationCode: this.itemsData.stationCode,
        billGroupId: this.itemsData.billGroupId,
        containerCode: this.itemsData.containerCode,
      };
      postpieceBreak(params).then((res) => {
        if (res.success) {
          this.enterContainer(); //扫描容器号
          this.$message.success(res.message);
          // this.viewQuery()
        } else {
          this.$message.error(res.message);
        }
      });
    },

    currentPrint(type) {
      if (this.barcodeDListMore.currLclNo) {
        let lclNo = this.barcodeDListMore.currLclNo;
        let row = this.barcodeDListMore.lcls.find((item) => {
          return item.lclNo == lclNo;
        });
        let params = {
          stationCode: this.itemsData.stationCode,
          containerCode: this.itemsData.containerCode,
          billGroupId: row.billGroupId,
          lclNo: lclNo,
        };
        getPrintInfo({ ...params, printFlag: "0" });
        getPrintInfo({ ...params, printFlag: "1" }).then((res) => {
          // this.viewQuery()
          toPrintServer(res.data.data, this.warehouse.warehouseId, tempType.assimble_tag).then((res) => {
            if (!res.success) {
              this.$exception(res);
              return;
            }
            this.$message.success(res.message);
          });
        });
        if (type == "reset") {
          //复核确认后封箱
          this.resetData();
        }

        // 打印拼箱明细
        // if (this.printBoxDetail) {
        //   getDetailPrintInfo(params).then((res) => {
        //     toPrintServer(res.data.data, this.warehouse.warehouseId, tempType.pxmx).then((res) => {
        //       if (!res.success) {
        //         this.$exception(res)
        //         return
        //       }
        //       this.$message.success(res.message)
        //     })
        //   })
        // }
      }
    },
    async printEvent(type) {
      //type = 1-封箱,2-拼箱
      //   await this.checkItemHandler(null);
      //判断是封箱还是拼箱
      if (type == 1) {
        // itemHealthIsDouble:"0"   0 否，1是
        // let canClose = false;
        // let dataSource = this.dataSource.filter((i) => {
        //   let { checkQty, check2Qty, redQty, pickQty, isDoubleCheck } = i;
        //   let compareCheckQty = isDoubleCheck == "0" ? checkQty : check2Qty;
        //   if (compareCheckQty + redQty === pickQty) {
        //     return true;
        //   } else {
        //     return false;
        //   }
        // });
        // console.log(dataSource);
        // if (dataSource.length == 0) {
        //   canClose = true;
        // }

        // dataSource.forEach((i) => {
        //   console.log(i);
        //   if (i.isDoubleCheck == 1 && !i.checker1 && i.redQty != i.qty) {
        //     canClose = true;
        //   }
        // });
        // if (canClose) {
        //   this.$message.warning("双入复核商品未完成,不能关箱!");
        //   return;
        // }

        this.currentPrint();
      }
      let status = this.dataSource.every((item) => {
        return item.flowStatus == 5;
      });
      //
      if (status && type == 1) {
        return;
      }
      //
      // this.tableVisible = true;
      // const params = {
      //   containerCode: this.itemsData.containerCode,
      //   stationCode: this.itemsData.stationCode,
      //   billGroupId: this.itemsData.billGroupId
      // }
      // checkLclBarcode(params).then((res) => {
      //   console.log(res)
      //   if (res.success) {
      //     this.printData = res.data.barcodeDList
      //     this.lclNo = res.data.lclNo
      //     this.enterContainer() //扫描容器号
      //   }
      // })
    },
    viewQuery() {
      // if (!this.stempStatus.goodsInfoStatus ) {
      //   this.$message.error('请扫描商品条码')
      //   return
      // }
      const params = {
        stationCode: this.itemsData.stationCode,
        billGroupId: this.itemsData.billGroupId,
        containerCode: this.itemsData.containerCode,
        lclNo: this.lclNo,
      };
      LclQuery(params).then((res) => {
        if (res.success) {
          if (!res.data) {
            //   this.$message.error(res.message);
            this.barcodeDListMore.lcls = [];
            return;
          }
          if (res.data.lcls.length > 7) {
            let arr = [];
            res.data.lcls.forEach((item, index) => {
              if (index < 7) {
                arr.push(item);
              }
            });

            this.barcodeDList = { currLclNo: res.data.currLclNo, lcls: arr };
          }
          this.barcodeDListMore = res.data;
        }
      });
    },
    lclNoDataFun(res) {
      if (!res.lclVO) {
        this.barcodeDListMore.lcls = [];
        return;
      }
      this.lclNo = res.lclVO.currLclNo;
      if (res.lclVO.lcls.length > 7) {
        let arr = [];
        res.lclVO.lcls.forEach((item, index) => {
          if (index < 7) {
            arr.push(item);
          }
        });

        this.barcodeDList = { currLclNo: res.lclVO.currLclNo, lcls: arr };
      }
      this.barcodeDListMore = res.lclVO;
    },
    wholePrint(pickTaskDId) {
      this.$message.success("自动打印整单");
      const warehouseId = this.warehouse.warehouseId;
      const params = {
        warehouseId,
        type: 0, //"type":"类型：0-拣货 1-补货"
        pickTaskDIds: [pickTaskDId],
      };
      getWholePrintInfo(params).then((res) => {
        toPrintServer(res.data[0].data, warehouseId, tempType.pick_tag).then((res) => {
          if (!res.success) {
            this.$exception(res);
            return;
          }
          this.$message.success(res.message);
        });
      });
    },
    deleteLcl() {
      let _this = this;
      let lclRow = this.barcodeDListMore.lcls.find((item) => {
        return (item.lclNo = this.$refs.lCLtable.data.lclNo);
      });
      console.log(lclRow);
      if (lclRow.status != "1") {
        this.deleteLCLFun();
        return;
      }
      this.$confirm({
        title: "拼箱删除",
        content: "该拼箱已打印,您确定要删除吗？",
        // getContainer: () => {
        //   return _this.$refs.detailView
        // },
        onOk: () => {
          // _this.tableVisible = false;
          this.deleteLCLFun();
        },
        onCancel() {},
      });
    },
    deleteLCLFun() {
      this.LCLinfoVisible = false;
      const params = {
        containerCode: this.itemsData.containerCode,
        stationCode: this.$refs.lCLtable.data.stationCode,
        billGroupId: this.$refs.lCLtable.data.billGroupId,
        lclNo: this.$refs.lCLtable.data.lclNo,
      };
      deleteLclNo(params).then((res) => {
        if (res.success) {
          // this.viewQuery()
          this.enterContainer(); //扫描容器号
          this.$message.success(res.message);
        } else {
          this.$message.error(res.message);
        }
      });
    },
    handleDetailPrint() {
      // this.tableVisible = false;
      // this.LCLinfoVisible = false;
      console.log(this.$refs.lCLtable);
      const params = {
        stationCode: this.$refs.lCLtable.data.stationCode,
        billGroupId: this.$refs.lCLtable.data.billGroupId,
        containerCode: this.$refs.lCLtable.data.containerCode,
        lclNo: this.$refs.lCLtable.data.lclNo,
      };
      getDetailPrintInfo(params).then((res) => {
        toPrintServer(res.data.data, this.warehouse.warehouseId, tempType.pxmx).then((res) => {
          if (!res.success) {
            this.$exception(res);
            return;
          }
          this.$message.success(res.message);
        });
      });
    },
    async handleOkPrint() {
      // this.tableVisible = false;
      // this.LCLinfoVisible = false;
      //   console.log(this.$refs.lCLtable)
      let params = {
        stationCode: this.itemsData.stationCode,
        containerCode: this.itemsData.containerCode,
        billGroupId: this.$refs.lCLtable.data.billGroupId,
        lclNo: this.lCLdata.lclNo,
      };
      console.log(this.lCLdata.lclNo, "this.lclNo");
      for (const key in params) {
        if (Object.hasOwnProperty.call(params, key)) {
          if (!params[key]) {
            delete params[key];
          }
        }
      }
      if (this.isCaseOrPiece) {
        let list = this.$refs.lCLtable.selectedListRowKeys;
        let wholelist = this.$refs.lCLtable.selectedPickTaskIdRows;
        let barcodeDList = this.$refs.lCLtable.selectedListRows;

        let barcodeIds = barcodeDList.map((i) => i.barcodeId);
        // console.log(list,'this.$refs.selectedListRowsthis.$refs.selectedListRows')
        if (list.length < 1) {
          this.$message.error("请至少选择一条数据");
          return;
        }
        let params = {
          warehouseId: this.warehouse.warehouseId,
          type: 0, //"type":"类型：0-拣货 1-补货"
          pickTaskDIds: wholelist,
          barcodeIds,
        };
        console.log(params);
        // return
        if (this.printNum < 1) {
          this.$message.error("打印数量必须大于0");
          return;
        }
        if (this.printNum % 1 !== 0) {
          this.$message.error("请输入整数");
          return;
        }
        // 		if (!(/(^[1-9]\d*$)/.test(this.printNum))) {
        //            this.$message.error('输入的不是正整数');
        // 　　　　　　return false;
        // 　　　　 }
        const hookFun = (params) => {
          params.count = this.printNum;
          return params;
        };
        getWholePrintInfo(params).then((res) => {
          // this.viewQuery()
          this.$refs.lCLtable.data.status = "1";
          toPrintServer(res.data[0].data, this.warehouse.warehouseId, tempType.pick_tag, null, hookFun).then((res) => {
            if (!res.success) {
              this.$exception(res);
              return;
            }
            this.$message.success(res.message);
            //打印次数添加
            list.forEach((item) => {
              this.$refs.lCLtable.dataSource.forEach((t) => {
                if (t.barcodeDId == item) {
                  t.printCount = t.printCount + Number(this.printNum);
                }
              });
            });
          });
        });
      } else {
        getPrintInfo({ ...params, printFlag: "1" }).then((res) => {
          console.log(res.data.data);
          this.$refs.lCLtable.data.status = "1";
          // this.viewQuery()
          toPrintServer(res.data.data, this.warehouse.warehouseId, tempType.assimble_tag).then((res) => {
            if (!res.success) {
              this.$exception(res);
              return;
            }
            //打印次数添加
            this.$refs.lCLtable.dataSource.forEach((t) => {
              t.printCount = t.printCount + 1;
            });
            this.$message.success(res.message);
          });
        });
      }
    },
    eidthandleOk() {
      this.LCLinfoVisible = false;
      const data = this.$refs.lCLtable.data;
      const list = this.$refs.lCLtable.dataSource;
      if (list.length < 1) {
        return;
      }
      const params = list.map((item) => {
        return {
          billGroupId: this.itemsData.billGroupId,
          lclNo: data.lclNo,
          itemCode: item.itemCode,
          itemId: item.itemId,
          containerCode: item.containerCode,
          pickTaskDId: item.pickTaskDId,
          qty: item.qty,
        };
      });
      console.log(this.$refs.lCLtable);
      eidtlclNum(params).then((res) => {
        if (res.success) {
          // this.viewQuery()
          this.enterContainer(); //扫描容器号
          this.$message.success(res.message);
        } else {
          this.$message.error(res.message);
        }
      });
    },
    xlhandleCancel() {
      this.visible_container = false;
    },
    //扫描序列号
    pressEnter() {},
    handleOkHC() {
      this.HCVisible = true;
      let redQty = this.$refs.modelForm.form.getFieldsValue().redQty;
      if (redQty % 1 !== 0) {
        this.$message.error("红冲数量必为整数");
        return;
      }
      let _this = this;
      this.$refs.modelForm.form.validateFields((err, values) => {
        if (!err) {
          console.log(values);
          this.$confirm({
            title: "冲红",
            content: "商品冲红后需要重新调整拼箱数量,您确定要冲红吗？",
            getContainer: () => {
              return _this.$refs.detailView;
            },
            onOk() {
              _this.itemsData.redReason = values.redReason;
              _this.itemsData.redQty = values.redQty;
              _this.itemsData.redDoMethod = values.redDoMethod;
              _this.itemsData = { ..._this.itemsData, ..._this.workertwo };
              const isDoubleCheck = _this.isDoubleCheck; //是否双人复核
              const lclNo = _this.lclNo; //当前拼箱号
              const params = { ..._this.itemsData, ..._this.resData, isDoubleCheck, lclNo };
              saveRedhc2(params).then((res) => {
                if (res.success) {
                  if (!res.data.innerCheckTaskDVOS) {
                    //整单红冲等同于复核确认
                    _this.$message.success(res.message);
                    _this.HCVisible = false;
                    _this.resetData();
                    _this.barcodeDListMore = { lcls: [] };
                    _this.barcodeDList = { lcls: [] };
                    _this.$message.success(res.message);
                    if (res.data && res.data.length > 0) {
                      _this.containerArray = res.data;
                      _this.containerdialogvisible = true;
                    }
                    // 清空容器码
                    _this.form.setFieldsValue({ containerCode: "" });
                    return;
                  }
                  const currentNum = res.data.innerCheckTaskDVOS[0].redQty;
                  const redReason = res.data.innerCheckTaskDVOS[0].redReason;
                  const itemid = res.data.innerCheckTaskDVOS[0].itemId;
                  _this.dataSource.forEach((item) => {
                    if (item.itemId == itemid) {
                      item.redQty = currentNum;
                      item.redReason = redReason;
                    }
                  });
                  _this.$refs.modelForm.form.resetFields();
                  _this.itemsDetail = res.data.innerCheckTaskDVOS[0];
                  _this.itemsDetail.shipperName = _this.shipperName; //给商品信息 客户名称赋值
                  // _this.viewQuery()
                  _this.HCVisible = false;
                  _this.containerData(res); // 代替获取容器刷新页面数据
                  // _this.enterContainer()
                  _this.$message.success(res.message);
                } else {
                  _this.$message.error(res.message);
                }
              });
            },
            onCancel() {},
          });
        }
      });
    },
    //拼箱号修改保存
    saveInnerCheckDetails() {
      if (this.selectedRowKeys.length === 0) {
        this.$message.error("请至少选择一条数据");
        return;
      }
      const selectedRowKeys = this.selectedRowKeys;
      const selectedRows = this.dataSource.filter((_) => selectedRowKeys.includes(_._oid));
      const params = {
        ...this.itemsData,
        innerCheckTaskDVOS: selectedRows,
      };
      postsaveInnerCheckDetails(params).then((res) => {
        this.enterContainer(); //扫描容器号
        if (res.success) {
          this.$message.success(res.message);
        } else {
          this.$message.error(res.message);
        }
      });
    },
    bartNoCheck(data) {
      console.log(data);
      const compareCheckQty = this.isDoubleCheck == "0" ? data.checkQty : data.check2Qty;
      if (compareCheckQty + data.redQty == data.pickQty) {
        this.$message.error("已复核商品不能进行冲红!");
        return;
      }

      this.isSupervisedData = {
        specialWorkType: "内复核红冲",
        warehouseId: this.warehouse.warehouseId,
      };
      this.loginVisible = true;
      this.resData = {
        billId: data.billId,
        billDId: data.billDId,
        srcId: data.srcId,
        srcLineId: data.srcLineId,
        pickTaskDId: data.pickTaskDId,
      };
      this.refData = this.$refs.detailView;
      this.itemsData.itemCode = data.itemCode;
    },
    loginhandleCancel() {
      this.loginVisible = false;
    },
    handleCancel() {
      this.makeUpinfoVisible = false;
      this.LCLinfoVisible = false;
      this.HCVisible = false;
      this.maintainVisible = false;
    },
    handleCancelHC() {
      this.HCVisible = false;
    },
    makeUphandleCancel() {
      this.makeUpVisible = false;
    },
    LCLhandleCancel() {
      this.LCLVisible = false;
    },
    loginResult(data, value) {
      if (!data) {
        this.workertwo = {
          workCode: value.workercode,
          userId: "",
          username: value.workercode,
        };
        console.log(value);
        this.loginVisible = data;
        this.HCVisible = true;
      }
    },
    moreview() {
      this.LCLVisible = true;
    },
    loginevent() {
      this.loginform.validateFields((err, values) => {
        if (!err) {
          values.businesstype = this.stationInfo.businesstype;
          values.worktype = this.stationInfo.worktype;
          values.stationCode = this.stationCode;
          values.warehouseId = this.warehouse.warehouseId;
          console.log(values);
          this.confirmLoading = true;
          this.CheckLoginIn(values)
            .then((res) => {
              this.pushUserInfo();
              this.confirmLoading = false;
              this.loginVisible = false;
              this.HCVisible = true;
            })
            .catch((error) => {
              this.$message.error("登录失败");
            });
        }
      });
    },
    // 扫描监管码
    checkSuperviseCode(type) {
      if (!this.stempStatus.containerstatus) {
        this.$message.error("请扫描容器号");
        return;
      }
      const selectedRowKeys = this.selectedRowKeys;
      const selectedRows = this.dataSource.filter((_) => selectedRowKeys.includes(_._oid));
      console.log(selectedRows, "=======");
      // 判断是否当前一行扫码自动弹出
      let SupervisedList = selectedRows.filter((item) => item.isSupervise >= "1");
      if (SupervisedList.length === 0) {
        this.$message.error("请至少选择一条可用数据");
        return;
      }
      this.isSupervised(SupervisedList, "checkCode", type);
    },
    viewLcninfo(data, status) {
      this.LCLVisible = false;
      this.isCaseOrPiece = data.lclNo == 0 || data.type == 1 ? true : false;
      const selectedRowKeys = this.selectedRowKeys;
      const selectedRows = this.dataSource.filter((_) => selectedRowKeys.includes(_._oid));
      if (!status) {
        this.LCLinfoVisible = true;
        if (selectedRows.length > 0) {
          this.selectedRowsLcninfo = selectedRows.map((item) => {
            return {
              lotNo: item.lotNo,
              barcodeDId: "_cusId" + Math.random() * 10000,
              barcodeId: item.barcodeId,
              itemCode: item.itemCode,
              itemName: item.itemName,
              itemId: item.itemId,
              containerCode: this.itemsData.containerCode,
              pickTaskDId: item.pickTaskDId,
              qty: 0,
            };
          });
          let obj = {};
          this.selectedRowsLcninfo = this.selectedRowsLcninfo.reduce((item, next) => {
            if (!obj[next.pickTaskDId]) {
              item.push(next);
              obj[next.pickTaskDId] = true;
            }
            return item;
          }, []);
        } else {
          this.selectedRowsLcninfo = [];
        }
      } else {
        this.makeUpinfoVisible = true;
      }
      this.makeUpStatus = !!status;
      console.log("this.selectedRowsLcninfo", this.selectedRowsLcninfo);
      this.lCLdata = data;
    },
    changePage() {
      this.$emit("changePage", 1);
    },

    /* 商品维护 */
    handleOk(e) {
      this.$refs.itemsEditor.getDetailData();
    },
    handleItemsComplete() {
      this.maintainVisible = false;
    },
    showSplit(record) {
      const { qty, pickQty, checkQty, redQty, check2Qty } = record;
      if (qty <= 1) {
        this.$message.error("数量大于1的明细才可以进行拆分!");
        return;
      }
      const compareQty = String(this.isDoubleCheck) === "0" ? checkQty + redQty : check2Qty + redQty;
      if (Number(compareQty) === Number(pickQty)) {
        this.$message.error("当前明细不可拆分!");
        return;
      }
      this.splitRecord = record;
      this.showSplitModal = true;
    },
    detailSplit(qty) {
      const workCode = this.$store.getters.userInfo.employeeNo;
      this.splitRecord.qty = qty;
      const { pickTaskDId, itemCode } = this.splitRecord;
      const lclNo = this.currentLclNo;
      const isDoubleCheck = this.isDoubleCheck;
      const params = {
        pickTaskDId,
        qty,
        itemCode,
        lclNo,
        workCode,
        isDoubleCheck,
      };
      pickTaskDetailSplit(params).then((res) => {
        if (res.success) {
          this.splitRecord = {};
          this.showSplitModal = false;
          this.enterContainer();
        } else {
          this.$message.error(res.message);
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
@import "./style/detail.less";

.innerCheck-detail {
  /deep/ .ant-result-title {
    font-size: 30px;
    color: #52c41a;
  }

  /deep/ .ant-card-head-title {
    font-size: 16px;
    color: #666666;
  }

  /deep/ .ant-descriptions-title {
    font-size: 20px;
    color: #1890ff;
  }
}

.printclass {
  display: inline-block;
  width: 120px;
  margin: 0 5px;

  .printinput {
    width: 60px;
    margin-left: 5px;
  }
}
</style>
