<template>
  <div class="shipping-tally">
    <el-row type="flex" style="margin-top: 15px; margin-bottom: 15px" justify="center">
      <el-col :xs="24" :sm="24" :md="24" :lg="20" :xl="22">
        <el-card>
          <el-descriptions :column="4" border>
            <el-descriptions-item :label="$t('自编号')">
              {{shipmentObj.selfNo}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('运输方式')">
              <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="shipmentObj.transportType" />
            </el-descriptions-item>
            <el-descriptions-item :label="$t('始发地')">
              {{getCityName(shipmentObj.startWarehouseId)}}
            </el-descriptions-item>
            <el-descriptions-item :label="$t('目的地')">
              {{getCityName(shipmentObj.destWarehouseId)}}
            </el-descriptions-item>
          </el-descriptions>
        </el-card>

        <el-row style="margin-top: 15px">
          <el-row class="table-title">
            <div>
              <el-button :disabled="shipmentObj.approvaling" size="small" type="primary" @click="()=>tallyClick('batch')">{{$t('批量理货')}}</el-button>
              <el-button :disabled="shipmentObj.approvaling" size="small" type="primary" @click="()=>removeClick('batch')">{{$t('批量移出')}}</el-button>
            </div>
            <div>
              <template>
                <el-input v-model="qrCode" :placeholder="$t('请输入二维码/条码编号')" clearable></el-input>
                <el-button type="primary" @click="handlerBatchCreate()">{{$t('确定')}}</el-button>
                <el-button type="primary" @click="handlerClick('batchInput',$t('批量输入'))">{{$t('批量输入')}}</el-button>
                <el-button type="primary" @click="handlerClick('correction',$t('理货纠错'))">{{$t('理货纠错')}}</el-button>
                <el-button type="primary" @click="handlerClick('correctionOrder',$t('批量理货纠错'))">{{$t('批量理货纠错')}}</el-button>
              </template>
            </div>

          </el-row>
          <el-row style="margin-top: 5px">
            <el-table border :data="tallyList" @select="checkboxSelect" @select-all="checkboxSelect" max-height="600px">
              <el-table-column type="selection" align="center" width="55" fixed="left" />
              <el-table-column align="center" :label="$t('序号')" width="50" prop="tidanNum" />
              <el-table-column :label="$t('订单号')" align="center" prop="orderNo">
                <template slot-scope="scope">
                  <div>
                    {{scope.row.orderNo}}
                  </div>
                  <div style="color:blue;fontWeight:bold;">
                    {{ scope.row.isExternalWarehouse === 1 ? ('('+$t('外部仓')+')') : ''}}
                  </div>
                  <div style="color:red;fontWeight:bold;">
                    {{ scope.row.adjustToDestWarehouseId > 0 ? ('('+$t('调仓')+')') : ''}}
                  </div>
                  <div style="display: flex;flex-wrap: wrap;" v-if="scope.row.advanceType">
                    <el-button @click="deleteSpecial(item.value,scope.row.orderId)"  size="mini" style="margin-left: 20px" type="danger" circle v-for="(item,index) in specialRendering(scope.row.advanceType)" :key="index">{{item.symbol}}</el-button>
                  </div>
                </template>
              </el-table-column>
              <el-table-column :label="$t('商品信息')" width="250px" align="center" prop="">
                <template slot-scope="{row}">
                  {{$l(row,'prodTitle')}}
                </template>
              </el-table-column>
              <el-table-column :label="$t('备案')" align="center" prop="feeType">
                <template slot-scope="{row}">
                  <template v-if="row.brandName">{{row.brandName}}</template>
                  <dict-tag v-else :type="DICT_TYPE.ECW_IS_BRAND" :value="row.feeType" />
                </template>
              </el-table-column>
              <el-table-column :label="$t('报关方式')" align="center" prop="customsType">
                <template slot-scope="scope">
                  <div :class="scope.row.customsType !== 1 ? 'custom_type_red' : ''">
                    <dict-tag :type="DICT_TYPE.ECW_CUSTOMS_TYPE" :value="scope.row.customsType" />
                  </div>
                </template>
              </el-table-column>
              <el-table-column :label="$t('品牌')" align="center">
                <template v-if="scope.row.brandName && scope.row.brandName!=='无' && scope.row.brandName!=='无牌'" slot-scope="scope">
                  <template v-if="scope.row.brandName">{{scope.row.brandName}}</template>
                  <dict-tag v-else :type="DICT_TYPE.ECW_IS_BRAND" :value="scope.row.brand" />
                </template>
              </el-table-column>
              <el-table-column :label="$t('包装类型')" align="center" prop="">
                <template slot-scope="scope">
                  <span v-for="(unit,index) in scope.row.units.split(',')" :key="index">
                    <dict-tag :type="DICT_TYPE.ECW_PACKAGING_TYPE" :value="unit" /><span v-if="index<scope.row.units.split(',').length-1">, </span>
                  </span>
                </template>
              </el-table-column>
              <el-table-column :label="$t('特性')" align="center" prop="warehouseInAttrNameList" width="120">
                <template slot-scope="scope">
                  {{scope.row.warehouseInAttrNameList?scope.row.warehouseInAttrNameList.toString():""}}
                </template>
              </el-table-column>
              <el-table-column :label="$t('关联单')" align="center" prop="hasRelationOrder" width="120">
                <template slot-scope="scope">
                  <el-link type="primary" v-if="scope.row.hasRelationOrder" @click.native="showRelatedOrder(scope.row)">{{ $t('有') }}</el-link>
                  <span v-else>{{ $t('无') }}</span>
                </template>
              </el-table-column>
              <el-table-column :label="$t('计划/已理')" align="center" prop="warehouseInInfo.cartonsNum">
                <template slot-scope="scope">
                  <el-link type="primary" @click.native="orderClick(scope.row)">
                    {{scope.row.num}}/{{scope.row.installNum}} <span v-if="scope.row.mixStatus === 1">（{{$t('混箱')}}）</span>
                  </el-link>
                  <div style="color:blue;fontWeight:bold;">
                    {{ scope.row.multiSpecification === true ? '(多规格)' : ''}}
                  </div>
                </template>
              </el-table-column>
              <el-table-column :label="$t('纸箱尺寸')" align="center" prop="warehouseInInfo.boxGauge">
              </el-table-column>
              <el-table-column :label="$t('体积')" align="center" prop="warehouseInInfo.volume">
              </el-table-column>
              <el-table-column :label="$t('重量')" align="center" prop="warehouseInInfo.weight">
              </el-table-column>
              <el-table-column :label="$t('数量（个）')" align="center" prop="quantity"></el-table-column>
              <el-table-column :label="$t('储位')" align="center" prop="positionNo" width="250px">
                <template slot-scope="scope">
                  {{notset(scope.row.positionNo)}}
                </template>
              </el-table-column>
              <el-table-column :label="$t('状态')" align="center" prop="tallyStatus">
                <template slot-scope="scope">
                  {{scope.row.tallyStatus === 1 ? $t('已理货') : $t('未理货')}}
                </template>
              </el-table-column>
              <el-table-column :label="$t('理货时间')" align="center" prop="tallyTime">
                <template slot-scope="scope">
                  {{formatDate(scope.row.tallyTime,'YYYY-MM-DD HH:mm:ss')}}
                </template>
              </el-table-column>
              <el-table-column :label="$t('操作')" align="center" width="160" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="scope">
                  <el-button :disabled="shipmentObj.approvaling" type="text" size="small" @click="tallyClick('single',scope.row)">{{$t('理货')}}</el-button>
                  <el-button :disabled="shipmentObj.approvaling" type="text" size="small" @click="removeClick('single',scope.row)">{{$t('移出')}}</el-button>
                  <el-button type="text" size="small" @click="currentTurnExceptionOrder=scope.row">{{$t('转异')}}</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-row>
        </el-row>

        <el-row style="margin-top: 15px" class="operate-button">
          <el-button size="small" type="primary" @click="supplementClick('supplementOrder',$t('补单'))">{{$t('补单')}}</el-button>
          <el-button :disabled="shipmentObj.approvaling" size="small" type="primary" @click="tallyFinish">{{$t('完成理货')}}</el-button>
          <el-button size="small" @click="cancel">{{$t('取消')}}</el-button>
        </el-row>
      </el-col>
    </el-row>
    <!-- 对话框 -->
    <el-dialog custom-class="shipping-dialog" :title="dialogConfig.title" :visible.sync="dialogConfig.dialogVisible" :fullscreen="dialogConfig.fullscreen" :width="dialogConfig.width" :modal-append-to-body=false append-to-body>
      <!-- 补单 -->
      <supplementOrder v-if="dialogConfig.type === 'supplementOrder' && dialogConfig.dialogVisible" v-bind="$attrs" :shipmentObj="shipmentObj" @supplementFinish="supplementFinish" />
      <batchTally v-if="dialogConfig.type !== 'supplementOrder' && dialogConfig.dialogVisible" v-bind="$attrs" @closeDialog="closeDialog" :type="dialogConfig.type" :tallyRows="tallyRows" :shipmentObj="shipmentObj" />
    </el-dialog>
    <warehouse-detail :order="order" :orderItemId="showWarehouseInItemId" v-if="showWarehouseInItemId" @close="showWarehouseInItemId=null" />
    <exception
      v-if="currentTurnExceptionOrder"
      :orderNo="currentTurnExceptionOrder.orderNo"
      :orderId="currentTurnExceptionOrder.orderId"
      append-to-body
      @cancel="currentTurnExceptionOrder=null"
      @success="currentTurnExceptionOrder=null" />
    <!-- 对话框 -->
    <el-dialog custom-class="shipping-dialog" :title="checkDialogConfig.title" :visible.sync="checkDialogConfig.dialogVisible" :fullscreen="checkDialogConfig.fullscreen" :width="checkDialogConfig.width" :modal-append-to-body=false append-to-body>
      <!-- 已装未装订单 -->
      <template v-if="checkDialogConfig.type === 'orderTable'">
        <el-table :data="orderList" height="500px" border>
          <el-table-column :label="$t('已理')" align="center" prop="loadTag" />
          <el-table-column :label="$t('未理')" align="center" prop="unloadTag" />
        </el-table>
      </template>
      <!-- 理货纠错 -->
      <template v-if="checkDialogConfig.type === 'correction' && checkDialogConfig.dialogVisible">
        <el-form ref="correctionForm" :rules="rules" :model="correctionObj" label-position="top">
          <el-form-item :label="$t('理货纠错（二维码/条形码编号）')" prop="qrCode">
            <el-input v-model="correctionObj.qrCode" :placeholder="$t('请输入二维码/条形码编号')" clearable />
          </el-form-item>
        </el-form>
        <el-row class="operate-button">
          <el-button type="primary" @click="delCheck()">{{$t('提交')}}</el-button>
          <el-button @click="closeDialog2">{{$t('取消')}}</el-button>
        </el-row>
      </template>
      <!-- 批量理货纠错（订单号） -->
      <template v-if="checkDialogConfig.type === 'correctionOrder' && checkDialogConfig.dialogVisible">
        <el-form ref="orderForm" :rules="rules" :model="orderObj" label-position="top">
          <el-form-item :label="$t('理货纠错') +'（' + $t('订单号') + '）'" prop="orderNo">
            <el-input type="textarea" :rows="3" v-model="orderObj.orderNo" :placeholder="$t('请输入，多个以逗号分隔')" clearable />
          </el-form-item>
        </el-form>
        <el-row class="operate-button">
          <el-button type="primary" @click="batchDelCheck()">{{$t('提交')}}</el-button>
          <el-button @click="closeDialog2">{{$t('取消')}}</el-button>
        </el-row>
      </template>
      <!-- 理货批量输入 -->
      <template v-if="checkDialogConfig.type === 'batchInput' && checkDialogConfig.dialogVisible">
        <el-form ref="batchForm" :rules="rules" :model="batchObj">
          <el-form-item label="" prop="qrCode" class="two-element">
            <el-input v-model="batchObj.qrCode" :placeholder="$t('请输入订单号')" clearable />
            <el-button style="marginLeft:10px;" type="primary" @click="queryOrderInfo">{{$t('确定')}}</el-button>
          </el-form-item>

          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('订单号')">
                {{boxOrderInfo.orderNo}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('箱数')">
                <el-input-number v-if="boxOrderInfo.isExternalWarehouse === 1" v-model="batchObj.boxNum" :min="0" :max="boxOrderInfo.num" />
                <template v-else>
                  {{boxOrderInfo.num}}
                </template>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('方数')">
                {{getTotlContent(boxOrderInfo, ['volume'])}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('重量')">
                {{getTotlContent(boxOrderInfo, ['weight'])}}
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
        <el-row class="operate-button">
          <el-button type="primary" :disabled="boxOrderInfo.orderId ? false : true" @click="batchLoad">{{$t('提交')}}</el-button>
          <el-button @click="closeDialog2">{{$t('取消')}}</el-button>
        </el-row>
      </template>
    </el-dialog>
    <realated-order :order="order" :orderItemId="showRelatedItemId" v-if="showRelatedItemId" @close="showRelatedItemId=null"></realated-order>
  </div>
</template>

<script>
import supplementOrder from "../cabinet/supplementOrder.vue";
import batchTally from "./batchTally.vue";
import { getTallyList, tallyRemove, tallyCommit, getOrderDetailByBoxNo } from "@/api/ecw/boxSea";
import { checkInfoSingleCreate, checkInfoBatchCreate, getOrderTagList, checkInfoSingleDelete, checkInfoBatchDelete } from "@/api/ecw/boxAir";
import { formatDate, serviceMsg, getTotlContent } from "../../utils";
import WarehouseDetail from "./warehouseDetail";
import RealatedOrder from "../../../shippingSea/nodePage/tally/realatedOrder.vue";
import {getOrder, orderSpecialNeed} from "@/api/ecw/order";
import Exception from "@/views/ecw/box/components/Exception.vue";

export default {
  name: "tally",
  inheritAttrs: false,
  components: {
    Exception,
    supplementOrder,
    batchTally,
    WarehouseDetail,
    RealatedOrder,
  },
  props: {
    shipmentObj: Object,
  },
  data() {
    return {
      showWarehouseInItemId: null,
      showRelatedItemId: null,
      order: null,
      tallyList: [],
      // 理货数据
      tallyRows: [],
      // 勾选行
      selectedRows: [],
      // 弹窗配置
      dialogConfig: {
        title: "",
        dialogVisible: false,
        width: "30%",
        type: "",
        fullscreen: false,
      },
      // 当前转异订单
      currentTurnExceptionOrder: null,
      // 二维码/条码编号
      qrCode: "",
      // 批量输入
      batchObj: {
        boxNum: 0,
      },
      // 批量纠错（订单号）
      orderObj: {},
      // 纠错
      correctionObj: {},
      // 弹窗配置
      dialogConfig: {
        title: "",
        dialogVisible: false,
        width: "30%",
        type: "",
        fullscreen: false,
      },
      checkDialogConfig: {
        title: "",
        dialogVisible: false,
        width: "30%",
        type: "",
        fullscreen: false,
      },
      // 订单信息
      boxOrderInfo: {},
      rules: {
        qrCode: [
          { required: true, message: this.$t("必填"), trigger: "change" },
        ],
        orderNo: [
          { required: true, message: this.$t("必填"), trigger: "change" },
        ],
      },
      // 已理/未理
      orderList: [],
      checkOrderList: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 格式化日期
    formatDate,
    getTotlContent,
    //去重
    notset(string){
      if(!string) return string
      let arr = string.split(',')
      arr = arr.filter((item,index)=>{return arr.indexOf(item)==index})
      return arr.toString()
    },
    // 查询理货列表
    getList() {
      getTallyList({ shipmentId: this.shipmentObj.id }).then((res) => {
        this.checkOrderList = res.data
        let list = [];
        res.data.forEach((item) => {
          item.orderItemList.forEach((oItem) => {
            let warehouseInInfo = {};
            if (oItem.warehouseInInfo) {
              warehouseInInfo = JSON.parse(oItem.warehouseInInfo ?? {});
            }

            list.push({
              ...oItem,
              warehouseInInfo,
              advanceType:oItem.advanceType,
              multiSpecification: oItem.multiSpecification,
              positionNo: oItem.positionNo,
              tallyStatus: item.tallyStatus,
              tallyTime: item.tallyTime,
              installNum: item.installNum,
              hasRelationOrder: item.hasRelationOrder
            });
          });
        });
        // let relist = []
        // list.forEach(l=>{
        //   let index = relist.findIndex(i=>i.orderId == l.orderId && i.positionNo == l.positionNo)
        //   if(index == -1){
        //     relist.push(l)
        //   }else{
        //     relist[index].warehouseInInfo.cartonsNum = parseInt(relist[index].warehouseInInfo.cartonsNum)+parseInt(l.warehouseInInfo.cartonsNum)
        //   }
        // })
        this.tallyList = list;
      });
    },
    specialRendering(val){
      console.log('val', val)
      if(val !== undefined){
        let i = val.split(',')
        return this.getDictDatas(this.DICT_TYPE.ORDER_SPECIAL_NEEDS).filter(e => {
          return i.indexOf(e.value) > -1
        }).map(item => {
          // 打字开头的用最后一个字，否则取第一个字
          item.symbol = item.label[0] == '打' ? item.label[item.label.length-1]: item.label[0]
          return item
        })
      }
    },
    deleteSpecial(id,orderId){
      this.$confirm(this.$t('确定删除此特需么?')).then(() => {
        return orderSpecialNeed({orderId:orderId,advanceType:id})
      }).then(() => {
        this.getList()
      })
    },
    // 选中
    checkboxSelect(selection) {
      this.selectedRows = selection;
    },
    /** 点击补单 */
    supplementClick(type, title) {
      this.shipmentObj.isTally = 1
      this.showDialog(type);
    },
    /* 补单完成 */
    supplementFinish() {
      this.closeDialog();
    },
    // 理货点击
    tallyClick(type, data) {
        if(this.shipmentObj.approvaling){
            return this.$message.error(this.$t('业务待审核，暂不能操作'))
        }
      if (type === "batch") {
        if (this.selectedRows.length === 0) {
          this.$message.error(this.$t("请选择需要理货的订单"));
          return;
        }
        this.tallyRows = this.selectedRows;
        this.showDialog("batchTally");
      } else {
        this.tallyRows = [data];
        this.showDialog("singleTally");
      }
    },
    // 移出点击
    removeClick(type, data) {
      let orderNos = [],
        orderIds = [];
      if (type === "batch") {
        if (this.selectedRows.length === 0) {
          this.$message.error(this.$t("请选择需要移出的订单"));
          return;
        }
        orderNos = [...new Set(this.selectedRows.map((item) => item.orderNo))];
        orderIds = this.selectedRows.map((item) => item.orderId);
      } else {
        orderNos = [data.orderNo];
        orderIds = [data.orderId];
      }

      let msgTitle = this.$t("您确定要将 {no} 移出 {selfNo} 吗？", {
        no: orderNos.join("，"),
        selfNo: this.shipmentObj.selfNo,
      });

      this.$confirm(msgTitle, this.$t("提示"), {
        type: "warning",
      })
        .then((_) => {
          let param = {
            orderIdLIst: orderIds,
            shipmentId: this.shipmentObj.id,
          }
          tallyRemove(param).then((res) => {
            serviceMsg(res, this).then(() => {
              this.getList();
            });
          }).catch((res) => {
        if (res.code === 666) {
              this.$confirm("<div style='max-height:500px;overflow:auto'>"+res.msg+this.$t('是否需要一起移出?')+"</div>", this.$t("提示"), {
                dangerouslyUseHTMLString: true,
                distinguishCancelAndClose: true,
                confirmButtonText: '确定移出',
                cancelButtonText: '仅移出当前订单'
              })
                .then((_) => {
                  tallyRemove({ ...param, deleteType: 2 }).then((res) => {
                    serviceMsg(res, this).then(() => {
                      this.getList();
                    });
                  });
                })
                .catch(action => {
                  if(action =='cancel'){
                    tallyRemove({ ...param, deleteType: 1 }).then((res) => {
                      serviceMsg(res, this).then(() => {
                        this.getList();
                      });
                    });
                  }
                });
            }
      });
        })
        .catch((_) => {});
    },
    // 关闭弹窗
    closeDialog(type) {
      this.$set(this.dialogConfig, "dialogVisible", false);
      if (type === "query") {
        this.getList();
      }
    },
    // 打开弹窗
    showDialog(type) {
      switch (type) {
        case "supplementOrder":
          this.$set(this.dialogConfig, "fullscreen", true);
          this.$set(this.dialogConfig, "title", this.$t("补单"));
          break;
        case "batchTally":
        this.$set(this.dialogConfig, "fullscreen", false);
          this.$set(this.dialogConfig, "title", this.$t("批量理货"));
          this.$set(this.dialogConfig, "width", "500px");
          break;
        case "singleTally":
          this.$set(this.dialogConfig, "fullscreen", false);
          this.$set(this.dialogConfig, "title", this.$t("理货确认"));
          this.$set(this.dialogConfig, "width", "500px");
          break;
      }
      this.$set(this.dialogConfig, "type", type);
      this.$set(this.dialogConfig, "dialogVisible", true);
    },
    /** 取消 */
    cancel(type) {
      this.$emit("closeDialog", type);
    },
    // 理货完成
    tallyFinish() {
      let flag = false
      let orderNo = ''
      this.checkOrderList.forEach(item=>{
        if(item.installNum != item.num){
          flag = true
          orderNo = orderNo + '《' + item.orderNo + '》'
        }
      })
      if(flag){
        this.$message.error(this.$t(`订单号${orderNo}未完成理货,请完成全部订单理货后重试`));
        return;
      }
      tallyCommit({ shipmentId: this.shipmentObj.id }).then((res) => {
        serviceMsg(res, this).then(() => {
          this.$emit("closeDialog", "submit");
        });
      });
    },
    // 显示入仓记录
    showWarehouseLogs(row) {
      getOrder(row.orderId).then((response) => {
        this.order = response.data;
        this.showWarehouseInItemId = row.orderItemId;
      });
    },
    // 显示关联单
    showRelatedOrder(row) {
      this.showRelatedItemId = row.orderId
    },
    /** 表格订单号点击 */
    orderClick(row) {
      getOrderTagList({ orderId: row.orderId, type: 0 }).then((res) => {
        const { data = {} } = res;
        this.orderList = [];
        // 取最长的list
        let dataLength = data.loadList.length;
        if (data.unLoadList.length > dataLength) {
          dataLength = data.unLoadList.length;
        }

        // 组装数据，用一个table组件渲染
        for (let index = 0; index < dataLength; index++) {
          this.orderList.push({
            loadTag: data.loadList[index],
            unloadTag: data.unLoadList[index],
          });
        }
      });
      this.shwoDialog({
        type: "orderTable",
        title: row.selfNo,
      });
    },
    /** 点击事件统一入口 */
    handlerClick(type, title) {
      this.shwoDialog({ type, title });
    },
    /** 弹窗事件 */
    shwoDialog(config) {
      this.$set(this.checkDialogConfig, "title", config.title);
      this.$set(this.checkDialogConfig, "type", config.type);
      switch (config.type) {
        case "orderTable":
          this.$set(this.checkDialogConfig, "fullscreen", false);
          break;
        case "batchInput":
          this.$set(this.checkDialogConfig, "fullscreen", false);
          this.batchObj = { boxNum: 0 };
          this.boxOrderInfo = {};
          break;
        case "correction":
          this.$set(this.checkDialogConfig, "fullscreen", false);
          this.correctionObj = {};
          break;
        case "correctionOrder":
          this.$set(this.checkDialogConfig, "fullscreen", false);
          this.orderObj = {};
          break;
      }
      this.$set(this.checkDialogConfig, "dialogVisible", true);
    },
    /** 关闭弹窗 */
    closeDialog2() {
      this.$set(this.checkDialogConfig, "dialogVisible", false);
    },
    /* 创建理货标签 */
    handlerBatchCreate() {
      if (!this.qrCode) {
        this.$message.error(this.$t("请输入二维码/条码编号"));
        return;
      }
      let params = {
        shipmentId: this.shipmentObj.id,
        type: 0,
      };
      params.orderNumCode = this.qrCode;
      checkInfoSingleCreate(params).then((res) => {
        serviceMsg(res, this).then(() => {
          this.qrCode = "";
          this.getList();
        });
      });
    },
    queryOrderInfo() {
      this.$refs["batchForm"].validate((valid) => {
        if (valid) {
          getOrderDetailByBoxNo({
            orderNumCode: this.batchObj.qrCode,
            shipmentId: this.shipmentObj.id,
          }).then((res) => {
            const { data } = res;
            this.boxOrderInfo = data;
            this.batchObj.boxNum = Number(data.num);
          });
        }
      });
    },
    /**批量创建理货标签 */
    batchLoad() {
      if (!this.boxOrderInfo.orderId) {
        this.$message.error(this.$t("请输入订单号"));
        return;
      }
      if (this.batchObj.boxNum === 0) {
        this.$message.error(this.$t("箱数不能为0"));
        return;
      }

      let params = {
        orderId: this.boxOrderInfo.orderId,
        orderNo: this.boxOrderInfo.orderNo,
        shipmentId: this.shipmentObj.id,
        type: 0
      };
      checkInfoBatchCreate(params).then((res) => {
        serviceMsg(res, this).then(() => {
          this.closeDialog2();
          this.boxOrderInfo = {};
          this.getList();
        });
      });
    },
    /**理货纠错 */
    delCheck() {
      if (!this.correctionObj.qrCode) {
        this.$message.error(this.$t("请输入二维码/条码编号"));
        return;
      }
      let params = {
        shipmentId: this.shipmentObj.id,
        type: 0,
        orderNumCode: this.correctionObj.qrCode
      };
      checkInfoSingleDelete(params).then((res) => {
        serviceMsg(res, this).then(() => {
          this.closeDialog2();
          this.getList();
        });
      });
    },
    /**批量理货纠错 */
    batchDelCheck() {
      if (!this.orderObj.orderNo) {
        this.$message.error(this.$t("请输入订单号"));
        return;
      }
      let params = {
        shipmentId: this.shipmentObj.id,
        type: 0,
        orderNo: this.orderObj.orderNo
      };
      checkInfoBatchDelete(params).then((res) => {
        serviceMsg(res, this).then(() => {
          this.closeDialog2();
          this.getList();
        });
      });
    }
  },
  computed: {
    /* 获取仓库 */
    getCityName() {
      return (id) => {
        let arr = this.$attrs.warehouseList.filter((item) => item.id == id);
        return arr.length > 0 ? this.$l(arr[0], "title") : this.$t("无");
      };
    },
  },
};
</script>

<style lang="scss" scoped>
.table-title {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  > div:first-child {
    flex: 1;
    font-size: 16px;
  }
  > div:last-child {
    display: flex;
    > .el-input {
      margin-right: 10px;
    }
  }
}
</style>
