<template>
  <!-- 供包 -->
  <div class="pickDistribution">
    <a-spin :spinning="spinning">
      <workFlow
        class="bottomclass"
        ref="workFlow"
        :formData="formData"
        :title="pageTitie"
        :disableItem="disableItem"
        :formItems="formItems"
        :leftSpan="leftSpan"
        :rightSpan="rightSpan"
        :btnEventArray="btnEventArray"
      >
        <template v-slot:rightTblae>
          <div style="margin-left: 20px">
            <!-- <p-grid-form ref="right" :items="rightitems"> </p-grid-form> -->

            <p-card title="波次不完整绑定">
              <span slot="extra">
                <p-button style="margin-right: 10px" @click="incompleteBindingShowmode">显示详情</p-button>
              </span>
              <p-grid-form ref="incompleteBinding" :items="incompleteBindingItems"> </p-grid-form>
            </p-card>
            <div class="imgClass">
              <div class="scanCodeTable">
                <h2>易错商品</h2>
                <p-grid-form ref="scan" :items="items"> </p-grid-form>
                <p-table
                  v-show="show"
                  ref="scanCode"
                  :columns="scanCodeColumns"
                  rowKey="lotId"
                  :scroll="{ y: 150 }"
                  :rowSelectType="1"
                  :autoLoad="false"
                  :hasRowSelectCheck="true"
                  :dataSource="ScanList"
                  auto-width
                  bordered
                >
                  <template slot="operator" slot-scope="text, record">
                    <a @click="del(text)"> 删除 </a>
                  </template>
                </p-table>
              </div>

              <div class="taskInfo">
                <div class="title">
                  <div>上一条任务信息</div>
                  <p-grid-form ref="scan1" :items="showitems"> </p-grid-form>
                </div>

                <p-grid-form v-show="show1" ref="lastItem" :span="8" :items="taskInfoItems" />
              </div>
            </div>
          </div>
        </template>
      </workFlow>
    </a-spin>

    <p-modal title="明细任务选择" width="80%" :visible="itemModel" :confirm-loading="confirmLoading" @ok="itemModelOk" @cancel="itemModel = false">
      <p-table
        ref="logTable2"
        :columns="Modelcolumns"
        rowKey="billNolotId"
        :rowSelectType="1"
        :autoLoad="false"
        :hasRowSelectCheck="true"
        @selectChange="selectChange"
        :dataSource="itemList"
        auto-width
        bordered
      />
    </p-modal>

    <p-modal title="查看当前品种任务" width="80%" :visible="ViewitemModel" :confirm-loading="confirmLoading" @ok="ViewitemModel = false" @cancel="ViewitemModel = false">
      <p-table
        ref="logTable2"
        :columns="Modelcolumns2"
        rowKey="outboundDetailId"
        :rowSelectType="false"
        :remoteUrl="remoteUrlModel"
        :remoteParams="remoteParams"
        :dataSource="itemList1"
        auto-width
        bordered
      />
    </p-modal>

    <p-modal title="商品选择" width="80%" :visible="itemVisible" @ok="itemVisibleOk" @cancel="itemVisible = false">
      <p-table ref="logTable2" :columns="itemColumns" rowKey="itemId" hasRowSelectCheck :selectedRowKeys.sync="itemSelectKeys" :rowSelectType="1" :dataSource.sync="itemList" auto-width bordered />
    </p-modal>
    <p-modal title="纸质票据供包" width="80%" :visible="noteConfirmView" :destroyOnClose="true" :confirm-loading="confirmLoading" @ok="noteConfirmOk" @cancel="noteConfirmView = false">
      <p-grid-form ref="noteConfirm" :span="8" :items="noteConfirmItem" />
    </p-modal>

    <p-modal title="作业波次绑定情况" width="80%" :visible="incompleteBindingVisible" @ok="incompleteBindingVisible = false" @cancel="incompleteBindingVisible = false">
      <p-table :columns="incompleteBindingColumns" rowKey="itemId" :rowSelectType="false" :pagination="false" :dataSource.sync="incompleteBindingList" auto-width bordered />
    </p-modal>
  </div>
</template>
<script>
import {
  doPrintTask,
  getStationTask,
  stationConfirm,
  getImageUrl,
  getAlarm,
  getAGVlist,
  stationConfirmIp,
  checkAllotment,
  allotmentOrder,
  allotmentConfirm,
  allotmentConfirmCheck,
  noteConfirm,
  scanCodeGetItem,
  waveBindCondition,
} from "./api/index.js";
import { formItems, tableColumns, queryItems, prinTableColumns, Modelcolumns, Modelcolumns2, taskInfoItems, items, showitems, rightitems, noteConfirmItem } from "./js/config";
import throttle from "./js/utils";
import workFlow from "../components/workFlow/index.vue";
import PModalTable from "../components/modal-table/src/modalTable.vue";
import workerLogin from "../components/workFlow/index.vue";
import { setStationCode, getStationCode } from "@/views/util";
import imgList from "../components/imagelist";
import { returnGoodsShelf } from "../111/api/index.js";
const baseUrl = "/qneis_";
export default {
  components: {},
  name: "sxStoreCheck",
  // mixins: [SetStation],
  components: { workFlow, PModalTable, workerLogin, imgList },
  data() {
    return {
      incompleteBindingList: [],
      incompleteBindingColumns: [
        { title: "波次号", key: "waveNo", ellipsis: true, dataIndex: "waveNo", align: "center" },
        { title: "订单总数", key: "orderNum", ellipsis: true, dataIndex: "orderNum", align: "center" },
        { title: "完成订单", key: "finishOrderNum", ellipsis: true, dataIndex: "finishOrderNum", align: "center" },
        { title: "已绑定订单", key: "bindOrderNum", ellipsis: true, dataIndex: "bindOrderNum", align: "center" },
        { title: "未绑定订单", key: "unbindOrderNum", ellipsis: true, dataIndex: "unbindOrderNum", align: "center" },
      ],
      incompleteBindingVisible: false,
      incompleteBindingItems: [
        { type: "number", name: "length", placeholder: "", className: "input-md-red", labelCol: { span: 12 }, wrapperCol: { span: 12 }, label: "波次数", disabled: true, span: 6, value: "" },
        { type: "number", name: "unbindOrderNum", placeholder: "", labelCol: { span: 12 }, wrapperCol: { span: 12 }, className: "input-md-red", label: "剩余订单", span: 6, value: "", disabled: true },
      ], //波次不完整绑定 表单
      itemVisible: false,
      show: false,
      show1: false,
      initData: {
        autoOffer: "",
        cargoOwnerName: "",
        checkTaskNo: "",
        code: "",
        countryOrigin: "",
        drugSupervisionCode: "",
        expireDate: "",
        goodsId: "",
        id: "",
        itemCode: "",
        itemHealthApprovalNbr: "",
        itemHealthListedLicensor: "",
        itemHealthSuperviseflag: "",
        itemId: "",
        itemName: "",
        lotNo: "",
        manufacturerName: "",

        outboundDetailId: "",
        outboundId: "",
        pickTaskId: "",
        pieceUom: "",
        planOfferQty: "",
        planQty: "",
        produceDate: "",
        source: "",
        specification: "",

        waveNo: "",
        gridNo: "",
        wavoNo: "",
      },
      noteConfirmView: false,
      items: items(this),
      showitems: showitems(this),
      rightitems: rightitems(this),
      noteConfirmItem: noteConfirmItem(this),
      remoteParams: {},
      remoteUrlModel: {
        url: baseUrl + "/api/v1/pc/allotmentOrderShow",
        methods: "get",
      },
      //   'goodsName',
      dataSource: [],
      scanCodeColumns: [
        { title: "复核条码(监管码/条形码)", key: "code", ellipsis: true, dataIndex: "code", align: "center" },
        {
          title: "操作",
          key: "operator",
          //   width: 140,
          scopedSlots: { customRender: "operator" },
        },
      ],
      itemColumns: [
        { title: "商品名称", key: "itemName", ellipsis: true, dataIndex: "itemName", align: "center" },
        { title: "商品条码", key: "itemCode", ellipsis: true, dataIndex: "itemCode", align: "center" },
        { title: "商品规格", key: "itemSpec", ellipsis: true, dataIndex: "itemSpec", align: "center" },
        { title: "itemId", key: "itemId", ellipsis: true, dataIndex: "itemId", align: "center", hidden: true },
      ],
      itemList: [],
      code: null,
      itemSelectKeys: [],
      //   planQty
      disableItem: [
        "itemId",
        "lotId", //planQty
        "waveNo",
        "billNo",
        "outboundId",
        "outboundDetailId",
        "createTime",
        "priority",
        "planOfferQty",
        "offerQty",
        "itemCode",
        "itemName",
        "manufacturerName",
        "specification",
        "pieceUom",
        "lotNo",
        "produceDate",
        "expireDate",
        "countryOrigin",
        "itemHealthApprovalNbr",
        "cargoOwnerName",
        "itemHealthListedLicensor",
        "itemHealthSuperviseflag",
        "source",
        "companyName",
      ],
      formItems: formItems(this),
      taskInfoItems: taskInfoItems(this),
      tableColumns,
      Modelcolumns,
      Modelcolumns2,
      prinTableColumns,
      formData: {},
      tableList: [],
      itemList1: [],
      tabLoding: false,
      confirmLoading: false,
      loginVisible: false,
      btnEventArray: [
        // { label: '标签打印',type: 'primary', click: () => {this.printItem()} },
        // { label: '标签补打',type: 'primary', click: () => {this.print()} },
        // { label: '拣选确认',type: 'primary', click: () => {this.pickConfirm()} },
      ],
      pageTitie: "拣选分拨",
      queryItems: queryItems(this),
      uniqueKey: "id",
      remoteMethod: "post",
      remoteUrl: "/kz/sxkPick/getRepeatPrintTaskInfo",
      autoLoad: true,
      visible: false,
      printNum: 1,
      selectedRows: [],
      leftSpan: 12,
      rightSpan: 12,
      checkStatus: false,
      data: {},
      stationNo: "",
      progressInfo: {
        current: 0,
        total: 0,
      },
      spinning: false,
      message: "",
      // backPic: 'https://img0.baidu.com/it/u=3147834171,2094854237&fm=253&fmt=auto&app=138&f=JPEG?w=642&h=500',
      backPic: "",
      tiemID: null,
      titleStatus: false,
      setTimeoutWarn: null,
      apsMessage: "",
      visibleAps: false,
      imgList: {},
      webscoketIp: "127.0.0.1:8882",
      checkAllotmentState: true, //供包站台校验状态
      itemList: [],
      item: {},
      itemModel: false,
      ViewitemModel: false,
      selectedRows: [],
      ScanList: [],
      ScanListNOhealthSuperviseflag: [],
      lastItem: {},
      itemId: null,
      timer: null,
      websockType: false, //websock状态
    };
  },
  created() {
    // this.getWebscoketIp()
    this.initWebSocket();

    let that = this;
    document.onkeydown = function (e) {
      var e = window.event || e;
      console.log(e.code);
      if (e.code == "Space" && e.preventDefault) {
        console.log(111212);
        // that.clickDebounce(e,that)
        window.event.preventDefault();

        if (!that.websockType) {
          that.$message.warning("websock未连接成功!");
          return;
        }
        that.websocketsend("cmd-check");

        // clearTimeout(this.tiemID)
        // this.tiemID = setTimeout(()=> {
        //   console.log('tiemID')
        //   e.preventDefault()
        //   that.taskDetail()
        // },2000)
      }
    };
  },
  destroyed() {
    document.onkeydown = null;
    clearInterval(this.timer);
  },
  watch: {
    ScanList(val) {
      console.log(val);
    },
  },
  mounted() {
    this.$nextTick(() => {
      let { username, nickname } = this.$store.getters.userInfo;
      this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ username, nickname });
    });
    this.waveBindConditionFun();
    this.timer = setInterval(() => {
        this.waveBindConditionFun();
    }, 10000);
  },
  methods: {
    async waveBindConditionFun() {
      try {
        let res = await waveBindCondition();
        if (res.success) {
          this.incompleteBindingList = res.data;
          let length = this.incompleteBindingList.length;
          let unbindOrderNum = this.incompleteBindingList.reduce((total, item) => {
            return total + item.unbindOrderNum;
          }, 0);
          console.log(length, unbindOrderNum, "===");
          this.$refs.incompleteBinding.form.setFieldsValue({ length, unbindOrderNum });

          console.log(res);
        } else {
          this.$exception(res);
        }
      } catch (error) {
        this.$exception(error);
      }
    },
    //波次不完成绑定弹窗
    incompleteBindingShowmode() {
      this.incompleteBindingVisible = true;
    },
    itemVisibleOk() {
      console.log(arguments);
      let that = this;
      console.log(this.itemSelectKeys, "===");
      if (!this.itemSelectKeys > 0) {
        this.$message.warning("请选择商品");
        return;
      } else {
        this.itemId = this.itemSelectKeys[0];
        this.allotmentOrder({ code: that.code });
        this.itemVisible = false;
      }
    },
    //扫描商品
    async scanCodeGetItem(code) {
      console.log(code);
      this.code = code;
      try {
        let res = await scanCodeGetItem({ code });
        if (res.success) {
          console.log(res);
          if (res.data.length > 1) {
            // itemList
            this.itemVisible = true;
            this.itemList = res.data;
          } else {
            let { itemId } = res.data[0];
            this.itemId = itemId;
            this.allotmentOrder({ code });
          }
        } else {
          this.$exception(res);
        }
      } catch (error) {
        this.$exception(error);
      }
    },
    showTable() {
      return this.show ? "隐藏" : "显示";
    },
    async noteConfirmOk() {
      this.spinning = true;
      let data = this.$refs.noteConfirm.form.getFieldsValue();
      let { stationNo } = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();
      try {
        let res = await noteConfirm({ ...data, stationNo });
        this.spinning = false;
        if (res.success) {
          this.$message.success(res.message);
          this.noteConfirmView = false;
          //   this.remoteParams = { ...this.remoteParams }
        } else {
          this.$exception(res);
        }
      } catch (error) {
        this.$exception(error);
      }
    },
    noteConfirm() {
      //   if (!Object.keys(this.item).length > 0) {
      //     return this.$message.error('请选择需要确认的订单')
      //   }
      let { stationNo } = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();
      if (!stationNo) {
        return this.$message.error("请输入供包口!");
      }
      this.noteConfirmView = true;
      this.$nextTick(() => {
        this.websocketsend("cmd-check");
      });
    },

    del(text) {
      let that = this;
      console.log(text.code);
      let item = text.code;
      //   return
      this.$confirm({
        title: "确定是否要删除?",
        content: "",
        async onOk() {
          let index = that.ScanList.map((i) => i.code).indexOf(item); // 找到要删除的项的索引位置
          if (index > -1) {
            that.ScanList.splice(index, 1); // 删除该项
            that.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: that.ScanList.length });
          }
        },
        onCancel() {},
      });
    },
    //扫描监管码
    scanCode(code) {
      let data = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();
      console.log(data);
      let { itemHealthSuperviseflag } = data;
      if (itemHealthSuperviseflag == "1") {
        if (!code) {
          this.$message.warning("监管码重复");
          this.$refs.scan.form.setFieldsValue({ scanCode: "" });
          //    focusByName
          this.$refs.scan.form.focusByName("scanCode");
          return;
        }

        let arr = this.ScanList.map((i) => i.code);
        let value = code;
        if (arr.indexOf(value) !== -1) {
          this.$message.warning("监管码重复");
          this.$refs.scan.form.setFieldsValue({ scanCode: "" });
          this.$refs.scan.form.focusByName("scanCode");
          return;
        }

        if (code.length != 20) {
          this.$message.warning("请扫描监20位监管码");
          this.$refs.scan.form.setFieldsValue({ scanCode: "" });
          this.$refs.scan.form.focusByName("scanCode");
          return;
        }
        this.ScanList.push({ code });
      } else {
        // this.ScanList.push({ code })
        this.ScanListNOhealthSuperviseflag.push({ code });
      }
      this.$refs.scan.form.setFieldsValue({ scanCode: "" });
      this.$refs.scan.form.focusByName("scanCode");
      if (itemHealthSuperviseflag) {
        this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: this.ScanList.length });
      } else {
        this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: this.ScanListNOhealthSuperviseflag.length });
      }

      let { autoOffer, planOfferQty, planQty } = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();
      if (autoOffer && planQty == planOfferQty) {
        this.checkConfirm();
      }

      this.$refs.workFlow.$refs.formTarget.form.focusByName("code");
    },
    scanCodeList(list) {
      let data = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();
      //   console.log(data)
      let { itemHealthSuperviseflag } = data;
      let arr = this.ScanList.map((i) => i.code);
      list.forEach((value) => {
        if (arr.indexOf(value) !== -1) {
          this.$message.warning(`监管码重复${value}`);
          this.$refs.scan.form.setFieldsValue({ scanCode: "" });
          this.$refs.scan.form.focusByName("scanCode");
          return;
        }
      });
      console.log(list, "====");
      list = list.filter((item) => !arr.includes(item));
      if (itemHealthSuperviseflag == "1") {
        let arr = this.ScanList.map((i) => i.code);
        // let value = code
        // arr1 = arr1.filter(item => !arr2.includes(item));

        this.ScanList = this.ScanList.concat(
          list.map((item) => {
            return { code: item };
          })
        );
        console.log(this.ScanList, "this.ScanList");
      } else {
        // this.ScanList.push({ code })
        this.ScanListNOhealthSuperviseflag = this.ScanListNOhealthSuperviseflag.concat(
          list.map((item) => {
            return { code: item };
          })
        );
        console.log(this.ScanListNOhealthSuperviseflag, "ScanListNOhealthSuperviseflag");
      }

      if (itemHealthSuperviseflag) {
        this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: this.ScanList.length });
      } else {
        this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: this.ScanListNOhealthSuperviseflag.length });
      }

      let { autoOffer, planOfferQty, planQty } = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();
      if (planQty > planOfferQty) {
        this.$message.warning("扫码数量大于计划数量!");
      }
      if (autoOffer && planQty >= planOfferQty) {
        this.checkConfirm();
      }
      this.$refs.workFlow.$refs.formTarget.form.focusByName("code");
    },
    itemModelOk() {
      console.log(this.selectedRows);
      if (this.selectedRows.length) {
        this.item = this.selectedRows[0];
        this.allotmentOrder(this.item);
        this.itemModel = false;
      }
    },
    selectChange(selectedRowKeys, selectedRows) {
      this.selectedRows = selectedRows;
    },
    //2）供包站台索取商品任务
    async allotmentOrder(data) {
      let { username, nickname } = this.$store.getters.userInfo;
      this.spinning = true;
      try {
        let res = await allotmentOrder({ ...data, itemId: this.itemId, userId: username });
        this.spinning = false;
        if (res.success) {
          console.log(res);
          if (res.data && res.data.length == 1) {
            this.item = res.data[0];
            this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ ...this.item, username, nickname, planQty: 0 });
            // this.$refs.right.form.setFieldsValue({ ...this.item })
            this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: this.ScanList.length });
            return;
          }

          if (res.data && res.data.length > 1) {
            // billNo  lotId
            res.data.forEach((i) => {
              i.billNolotId = i.billNo + i.lotId;
            });
            this.itemList = res.data;
            this.itemModel = true;
            console.log(1212);
            return;
          }

          if (!res.data || res.data.length == 0) {
            this.$message.warning(res.message);

            this.$refs.workFlow.$refs.formTarget.form.setFieldsValue(this.initData);

            // this.$refs.right.form.setFieldsValue(this.initData)
            this.item = {};
            this.itemList = [];
            return;
          }
        } else {
          this.$message.warning(res.message);
          this.$refs.workFlow.$refs.formTarget.form.setFieldsValue(this.initData);
          //   this.$refs.right.form.setFieldsValue(this.initData)
          this.item = {};
          this.itemList = [];
          return;
        }
      } catch (error) {
        this.$exception(error);
      }
    },
    //供包站台校验
    async checkAllotment(stationNo) {
      this.spinning = true;
      try {
        let res = await checkAllotment({ stationNo });
        this.spinning = false;
        if (res.success) {
          this.$message.success(res.message);
          this.checkAllotmentState = true;
        } else {
          this.checkAllotmentState = false;
          this.$exception(res);
        }
      } catch (error) {
        this.$exception(error);
      }
    },
    debounce(func, wait) {
      let timeout;
      return function () {
        let context = this;
        let args = arguments;
        if (timeout) clearTimeout(timeout);
        let callNow = !timeout;
        timeout = setTimeout(() => {
          timeout = null;
        }, wait);
        if (callNow) func.apply(context, args);
      };
    },
    clickDebounce: throttle((e, that) => {
      console.log("throttle");
      e.preventDefault();
      that.taskDetail();
    }, 1000),
    resetMessage() {
      this.message = "";
    },

    getWebscoketIp(data) {
      stationConfirmIp(data).then((res) => {
        if (res.success) {
          this.webscoketIp = res.data.enterpriseId;
        } else {
          this.$message.error(res.message);
        }
      });
    },

    btnDisabled(bool) {
      let row = this.formItems.find((item) => {
        return item.type == "buttonGroup";
      });
      row.options[2].disabled = bool;
    },
    focusFun(data) {
      if (!data) return;
      this.$nextTick(() => {
        this.$refs.workFlow.$refs.formTarget.$refs.list.$refs[data].$el.querySelector("input").focus();
      });
    },
    isSupervised() {
      this.loginVisible = true;
    },
    getImageUrl() {
      const params = {
        itemcode: this.$refs.workFlow.$refs.formTarget.form.getFieldsValue().itemCode,
      };
      this.backPic = "";
      getImageUrl(params).then((res) => {
        if (res.resultData) {
          if (res.resultData.url) {
            this.backPic = res.resultData.url;
          }
        }
      });
    },
    initWebSocket() {
      //初始化weosocket
      const wsuri = "ws://" + this.webscoketIp;
      this.websock = new WebSocket(wsuri);
      this.websock.onmessage = this.websocketonmessage;
      this.websock.onopen = this.websocketonopen;
      this.websock.onerror = this.websocketonerror;
      this.websock.onclose = this.websocketclose;
    },
    websocketonopen() {
      console.log("websocketonopen");
      this.websockType = true;
      this.$message.success("连接成功");

      //连接建立之后执行send方法发送数据
      // let actions = 'cmd-check';
      this.websocketsend("cmd-check");
    },
    websocketonerror() {
      //连接建立失败重连
      this.websockType = false;
      this.initWebSocket();
    },
    websocketonmessage(e) {
      let formdata = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();

      let { itemHealthSuperviseflag } = formdata;
      //数据接收
      console.log(e, "eeeee");
      let data = e.data.replace(/\u0000/g, "");
      if (data == "NoRead") {
        this.$message.error("未读取到数据");
        return;
      }
      console.log(data);

      let str = data;
      if (this.noteConfirmView && str) {
        this.$refs.noteConfirm.form.setFieldsValue({ billNo: str });
        return;
      }
      console.log(str, "strstr");

      if (str.includes(";")) {
        let list = str.split(";");
        if (itemHealthSuperviseflag) {
          list = list.filter((i) => i.length == 20 && i[0] == 8);
        }
        console.log(list);
        // return;
        if (list.length > 0) {
          this.scanCodeList(list);
        }

        // return
      } else {
        this.scanCode(str, itemHealthSuperviseflag);
      }
      this.$refs.workFlow.$refs.formTarget.form.focusByName("code");
    },

    websocketsend(Data) {
      //数据发送
      this.websock.send(Data);
    },
    websocketclose(e) {
      //关闭
      console.log("断开连接", e);
      //   this.$message.warning('连接已断开')
    },
    taskDetail() {
      //连接建立之后执行send方法发送数据

      if (!this.websockType) {
        this.$message.warning("websock未连接成功!");
        return;
      }
      this.websocketsend("cmd-check");
    },

    loginResult(status) {
      this.checkStatus = status;
    },
    async checkConfirm() {
      let that = this;
      let form = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();

      let { planOfferQty, planQty } = form;
      if (planQty > planOfferQty) {
        this.$message.warning("扫码数量大于计划数量!");
        this.ScanList = [];
        this.ScanListNOhealthSuperviseflag = [];
        return;
      }
      console.log(form);
      let { itemHealthSuperviseflag } = form;
      if (!Object.keys(this.item).length > 0) {
        return this.$message.error("请选择需要确认的订单");
      }

      if (this.ScanList.length == 0 && itemHealthSuperviseflag) {
        return this.$message.error("请先扫监管码!");
      }

      let data = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();
      //   const { type, value } = this.data
      console.log(data);

      try {
        this.spinning = true;
        let res = await allotmentConfirmCheck({ ...data, drugSupervisionCode: this.ScanList.map((i) => i.code) });
        this.spinning = false;
        if (res.success) {
          if (res.data) {
            this.$confirm({
              title: "提示",
              //   content: res.data,
              content: (h) => {
                return h("p", { style: { fontSize: "40px", color: "red" } }, res.data);
              },

              width: "60%",
              cancelText: "取消",
              okText: "确认",
              async onOk() {
                that.allotmentConfirmFun();
              },
              onCancel() {
                that.$refs.workFlow.$refs.formTarget.form.setFieldsValue(that.initData);
                that.ScanList = [];
                that.ScanListNOhealthSuperviseflag = [];
              },
            });
          } else {
            that.allotmentConfirmFun();
          }
        } else {
          that.$exception(res);
        }
      } catch (error) {
        that.$exception(error);
      }

      //   try {
      //     this.spinning = true;
      //     let res = await allotmentConfirm({ ...data, drugSupervisionCode: this.ScanList.map((i) => i.code) });
      //     this.spinning = false;
      //     this.$refs.workFlow.$refs.formTarget.form.focusByName("code");
      //     if (res.success) {
      //       this.allotmentOrder(this.item);
      //       this.lastItem = this.item;
      //       this.$refs.lastItem.form.setFieldsValue(this.lastItem);
      //       this.ScanList = [];
      //       this.ScanListNOhealthSuperviseflag = [];
      //       this.$message.success(res.message);
      //     } else {
      //       this.ScanList = [];
      //       this.ScanListNOhealthSuperviseflag = [];
      //       this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: 0 });
      //       this.$exception(res);
      //     }
      //   } catch (error) {
      //     this.$refs.workFlow.$refs.formTarget.form.focusByName("code");
      //     this.$exception(error);
      //   }

      return;
      var r = /^[1-9]\d*|0$/; //非负整数
      let flag = r.test(checkNum);
      if (!flag) {
        this.$message.error("实际数量必须是正整数");
        return;
      }
      const params = {
        checkNum,
        pickTaskId,
        stationNo,
        containerNo,
        type,
        value,
      };
      if (checkNum == 0) {
        if (this.checkStatus) {
          this.btnDisabled(true);
          this.stationConfirm(params);
        } else {
          this.$message.error("请先进行解锁操作");
        }
      } else {
        this.btnDisabled(true);
        this.stationConfirm(params);
      }
    },
    async allotmentConfirmFun() {
      let data = this.$refs.workFlow.$refs.formTarget.form.getFieldsValue();

      try {
        this.spinning = true;
        let res = await allotmentConfirm({ ...data, drugSupervisionCode: this.ScanList.map((i) => i.code) });
        this.spinning = false;
        this.$refs.workFlow.$refs.formTarget.form.focusByName("code");
        if (res.success) {
          this.allotmentOrder(this.item);
          this.lastItem = this.item;
          this.$refs.lastItem.form.setFieldsValue(this.lastItem);
          this.ScanList = [];
          this.ScanListNOhealthSuperviseflag = [];
          this.$message.success(res.message);
        } else {
          this.ScanList = [];
          this.ScanListNOhealthSuperviseflag = [];
          this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ planQty: 0 });
          this.$exception(res);
        }
      } catch (error) {
        this.$refs.workFlow.$refs.formTarget.form.focusByName("code");
        this.$exception(error);
      }
    },
    stationConfirm(params) {
      this.spinning = true;
      stationConfirm(params).then((res) => {
        this.spinning = false;
        this.btnDisabled(false);
        if (res.success) {
          this.backPic = "";
          this.resetMessage();
          this.$message.success(res.message);
          if (res.code == "300") {
            this.message = res.message;
          }
          this.titleStatus = res.data?.easyMiss == "1" ? true : false;
          this.focusFun("containerNo");
          if (res.data && JSON.stringify(res.data) !== "{}") {
            this.$refs.workFlow.$refs.formTarget.form.setFieldsValue(res.data);
            this.progressInfo.current = res.data.current;
            this.progressInfo.total = res.data.total;
            this.getImageUrl();
            return;
          }
          // this.imgList = {}
          this.progressInfo.current = 0;
          this.progressInfo.total = 0;
          //   this.$refs.workFlow.$refs.formTarget.form.resetFields()
          this.$refs.workFlow.$refs.formTarget.form.setFieldsValue(this.initData);
          this.$refs.workFlow.$refs.formTarget.form.setFieldsValue({ stationNo: this.stationNo });
          this.checkStatus = false;
        } else {
          this.$message.error(res.message);
          this.message = res.message;
        }
      });
    },

    onSelectedChange(data) {
      this.selectedRows = data.rows;
    },
    OnCancel() {
      this.visible = false;
      this.selectedRows = [];
      this.printNum = 1;
    },
    handleOkDetail() {
      const params = {
        num: this.printNum,
        params: this.selectedRows,
      };
      doPrintTask(params).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
          this.selectedRows = [];
          this.printNum = 1;
          this.visible = false;
        } else {
          this.$message.error(res.message);
          this.message = res.message;
        }
      });

      this.visible = false;
    },
    //获取箱子顺序
    arraySort(list) {
      console.log(list);
      let data = {
        1: [],
        2: [],
        3: [],
        4: [],
      };
      if (!list) {
        return;
      }
      list.forEach((i) => {
        data[i.layer].push(i);
      });
      console.log(data);
      // this.boxList = data
      return data;
    },
  },
};
</script>
<style lang="less">
.ant-input.ant-input-disabled {
  color: #108ee9;
}
.inputClass {
  width: 120px;
}
.pickDistribution {
  position: relative;
  .ant-card-body {
    // padding-bottom: 240px;
    background: #fff;
  }
}
.imgClass {
  //   position: absolute;
  z-index: 10;
  top: 500px;
  right: 30px;
  display: flex;
  //   justify-content: space-between;
  flex-wrap: wrap;
  // background: #108ee9;
  background-clip: border-box;
  //   height: 350px;
  //   width: 800px;
  //   border: 1px solid #108ee9;
}
.imgbox {
  z-index: 12;
  height: 100%;
  background-size: cover;
}
.bottomclass {
  // padding-bottom: 300px;
}
.imgListClass {
  position: absolute;
  z-index: 10;
  top: 500px;
  right: 505px;
  display: inline-block;
  // background: #108ee9;
  background-clip: border-box;
  // height: 300px;
  width: 300px;
}
.progressInfo {
  font-size: 20px;
}
.header {
  display: flex;
}
.message {
  font-size: 20px;
  margin-right: 50px;
  position: relative;
  top: 5px;
  color: red;
  font-weight: bold;
}
.scanCodeTable,
.taskInfo {
  padding: 20px;
  margin-left: 20px;
  width: 100%;
}
.taskInfo {
  border: 1px dashed yellow;
  .title {
    display: flex;
    padding: 10upx;
    div {
      width: 100%;
      font-size: 30px;
      font-weight: 500;
    }
  }
}
</style>
