<template>
  <view class="wrap">
	  <view class="search-header">
	    <scanlistener
	    v-if="showScanlistener"
	    suffixIcon="scan"
	    v-model="keyword"
	  	:focus="focusStart"
	    :placeholder="$t('请扫描条形码')"
		
	    @iconClick="()=>{scanCode('loading')}"
	    @confirm="searchCode"
	    @submit="keyword=$event;searchCode()"
	    ></scanlistener>
	  </view>
	   
    <view style="height: 60px; background: #2f4dae"></view>
    <view class="content-wrap">
      <view class="title">
        <view class="title-label">
          <view>{{$t('自编号')}}:{{selfNo}}</view>
          <view>{{$t('合包箱号')}}:{{pkgNum}}</view>
        </view>
        <view>
          <button size="mini" type="primary" @click="goSearch">{{$t('搜索')}}</button>
        </view>
      </view>
      <view class="flex tabs">
        <template v-for="item in tabs">
          <button size="mini" :type="currentType == item.type ? 'primary' : null" @click="changeTab(item)">{{item.label}}</button>
        </template>
      </view>
      <view class="search-info" v-if="searchKeyword" >
        {{$t('当前搜索')}}：{{searchKeyword}}
        <uni-icons class="icon" type="close" size="30" color="#666" @click="searchKeyword = null"></uni-icons>
      </view>
      <view class="flex justify-between action-bar">
        <view class="left flex align-center">
          <image v-if="allChecked" src="@/static/images/radio-true.png" class="radio" @click="toggleCheckAll"></image>
          <image v-else src="@/static/images/radio-false.png" class="radio" @click="toggleCheckAll"></image>
          {{$t('全选')}}
        </view>
        <view class="right">
          <button type="primary" size="mini" v-if="currentType === 0" @click="batchPack">{{$t('批量装箱')}}</button>
          <button type="primary" size="mini" v-else @click="batchRemove">{{$t('批量移出合包')}}</button>
        </view>
      </view>

      <view class="info-wrap">
        <empty v-if="!list.length"></empty>
        <view v-if="filteredList.length" v-for="(item, index) in filteredList" :key="index" class="item">
          <view :class="'order-' + item.orderNo == heightLightId ? 'bg-yellow info-content' : 'bg-white info-content'">
            <view>
              <view>
                <view class="label">
                  <image v-if="item.checked" src="@/static/images/radio-true.png" class="radio" @click="toggleChecked(item)"></image>
                  <image v-else src="@/static/images/radio-false.png" class="radio" @click="toggleChecked(item)"></image>
                  {{$t('序号')}}:
                </view>
                <view class="content">
                  {{ index + 1 }}
                </view>
              </view>
            </view>
            <view>
              <view>
                <view class="label">{{$t('订单号')}}: </view>
                <view class="content">
                  <text class="text-blue" @tap="showOrderDetail(true, item.orderId)">{{item.orderNo}}</text>
                  <!-- 调仓 -->
                  <text style="color:blue;fontWeight:bold;margin: 0 3px;">
                    {{ item.isExternalWarehouse === 1 ? ('('+$t('外部仓')+')') : ''}}
                  </text>
                  <text style="color:red;fontWeight:bold;margin: 0 3px;">
                    {{ item.adjustToDestWarehouseId > 0 ? ('('+$t('调仓')+')') : ''}}
                  </text>
                  <!-- 品牌 -->
                  <text v-if="item.orderItemDOS&&item.orderItemDOS.some(ele => [$t('无牌'), $t('有牌'), $t('中性')][ele.feeType] !== $t('无牌'))" style="color:red;fontWeight:bold;margin: 0 3px;">{{ $t('有牌') }}</text>
                  <!-- 特性 -->
                  <text style="color:red;fontWeight:bold;">{{ getProductAttrsByIds(uniqueProductAttrs(item.orderItemDOS, 'warehouseInProdAttrIds')) }}</text>
                  <!-- 报关方式 -->
                  <text v-if="item.customsType !== '1'">
                    <dict-tag :type="DICT_TYPE.ECW_CUSTOMS_TYPE" :value="item.customsType" style="color:red;fontWeight:bold;margin: 0 3px;" />
                  </text>
                  <!-- 包装类型 -->
                  <text v-for="(unit, index) in item.units.split(',')" :key="index" style="color:red;fontWeight:bold;margin: 0 3px;">
                    <dict-tag :type="DICT_TYPE.ECW_PACKAGING_TYPE" :value="unit" />{{ index!== item.units.split(',').length-1 ? ',':'' }}
                  </text>
                  <!-- 关联单 -->
                  <text v-if="item.hasRelationOrder" style="color:red;fontWeight:bold;" @tap="relatedClick(item.orderId)">{{$t('关联单')}}</text>
                  <!-- 混箱 -->
                  <text v-if="item.mixStatus === 1" style="color:red;fontWeight:bold;margin: 0 3px;" @tap="showMixOrder(item)">{{$t('混箱')}}</text>
                </view>
              </view>
            </view>
            <view>
              <view>
                <view class="label">{{$t('商品信息')}}: </view>
                <view class="content">
                  <div v-for="(prod, index) in item.orderItemDOS" :key="item.orderItemId">
                    {{index + 1}}、{{ $l(prod, 'prodTitle') }}
                  </div>
                </view>
              </view>
            </view>
            <view>
              <view>
                <view class="label">{{$t('纸箱尺寸')}}: </view>
                <view class="content">
                  <div v-for="item in item.orderItemDOS.filter(item => !!item.warehouseInInfoVO)" :key="item.orderItemId">
                    {{ item.warehouseInInfoVO.boxGauge }}
                  </div>
                </view>
              </view>
              <view>
                <view class="label">{{$t('计划/实装')}}: </view>
				<view class="content text-blue" @tap="showNoGoodsList(true,item.orderId)">{{ item.sumNum||0}}/{{item.installNum||0}}{{$t('箱')}}</view>
              </view>
            </view>
            <view>
              <view>
                <view class="label">{{$t('入仓重量')}}: </view>
                <view class="content">{{ item.sumWeight || 0 }}kg</view>
              </view>
              <view>
                <view class="label">{{$t('入仓体积')}}: </view>
                <view class="content">{{ item.sumVolume || 0 }}m³</view>
              </view>
            </view>
            <view>
              <view>
                <view class="label">{{$t('入仓个数')}}: </view>
                <view class="content">{{ item.sumQuantity  || 0 }}</view>
              </view>
              <view>
                <view class="label">{{$t('储位')}}: </view>
                <view class="content">
                  <div v-for="item in item.orderItemDOS.filter(item => !!item.warehouseInInfoVO).filter(item => !!item.warehouseInInfoVO)" :key="item.orderItemId">
                    {{ notset(getpositionNo(item.warehouseInInfoVO.orderLocationMergeVOSet)) }}
                  </div>
                </view>
              </view>
            </view>
            <view>
              <view style="flex:2">
                <view class="label">{{$t('理货时间')}}: </view>
                <view class="content">
                  {{item.tallyTime?formatDate(item.tallyTime, true):'/'}}
                </view>
              </view>
              <view style="display: block; text-align: right">
                <button v-if="currentType === 0" size="mini" type="warn" @click="pack(item)" style="margin: auto">{{$t('装箱')}}</button>
                <button v-else size="mini" type="warn" @click="remove(item)" style="margin: auto">{{ $t('移出合包') }}</button>
              </view>
            </view>
          </view>
        </view>
      </view>
	  <view class="padding-xl" v-if="currentType===1">
	    <block>
	  	  <view class="flex">
			  <view class="flex-sub" >
				<button class="cu-btn block bg-yellow margin-tb-sm lg" @click="showBatch(true)">{{$t('批量输入')}}</button>
			  </view>
	  		<view class="flex-sub" style="padding-left: 40px;">
	  		  <button class="cu-btn block bg-red margin-tb-sm lg" @click="showErrorCorrection(true)">{{$t('装箱纠错')}}</button>
	  		</view>
	  	  </view>
	      <view class="flex">
	        <view class="flex-sub">
	          <button type="primary" @click="finish">{{$t('封箱')}}</button>
	        </view>
	      </view>
	    </block>
	  </view>
    </view>
	<!-- 未合包装箱 -->
	<view class="cu-modal" :class="noTallyAir ? 'show' : ''" style="z-index: 900;">
	  <view class="cu-dialog">
	    <view class="cu-bar bg-white justify-end bottom-line">
	      <view class="content title-bolder" style="width:100%;">{{$t('未合包装箱')}}</view>
	    </view>
	    <scroll-view scroll-y="true" style="height: 400px;">
	        <view class="item-content" v-for="(v, index) in noTallyAirList" :key="index">
	            <view>{{v}}</view>
	        </view>
	    </scroll-view>

	    <view class="cu-bar bg-white justify-end top-line">
	      <view class="action"><button class="cu-btn bg-grey" @tap="showNoGoodsList(false)">{{$t('返回')}}</button></view>
	    </view>
	  </view>
	</view>
  
  <mix-order-list ref="mixOrderList" />
  <!-- 订单详情弹窗 -->
  <OrderDetailModal :orderDetailModal="orderDetailModal" :orderDetail="orderDetail" @close="showOrderDetail"></OrderDetailModal>

	<!-- 批量输入 -->
	<view class="cu-modal" :class="batchModal ? 'show' : ''" style="z-index: 900;">
	  <view class="cu-dialog">
	    <view class="cu-bar bg-white justify-end bottom-line">
	      <view class="content title-bolder">{{$t('批量输入')}}</view>
	    </view>
	    <view>
	      <view>
	        <view class="cu-bar bg-white search">
	          <view class="search-form round">
				<!-- 通过batchModal来判断是否显示弹窗，否则会和页面上的其他扫码狂冲突 -->
	            <scanlistener
	            v-if="showScanlistener && batchModal && !errorModal"
	            suffixIcon="scan"
	            :placeholder="$t('请扫描订单号')"
	            v-model="scanNumber"
	            @iconClick="()=>{scanCode('batchScan')}"
	            @confirm="batchScan"
	            @submit="scanNumber=$event;batchScan()"
	            style="width: 100%"
	            ></scanlistener>
	          </view>
	        </view>
	        <view>
	          <view class="cu-form-group">
	            <text class="title">{{$t('订单号')}}:</text>
	            <text class="content">{{ batchOrderInfo.orderNo }}</text>
	          </view>
	          <view class="cu-form-group">
	            <text class="title">{{$t('箱数')}}:</text>
	            <input v-if="batchOrderInfo.isExternalWarehouse === 1" class="text-right" type="number" v-model.number="batchOrderInfo.num" :placeholder="$t('输入箱数')" />
	            <text v-else class="content">{{ batchOrderInfo.num }}箱</text>

	          </view>
	          <view class="cu-form-group">
	            <text class="title">{{$t('方数')}}:</text>
	            <text class="content">{{ batchOrderInfo.volume | toFixed }}m³</text>
	          </view>
	          <view class="cu-form-group">
	            <text class="title">{{$t('重量')}}:</text>
	            <text class="content">{{ batchOrderInfo.weight | toFixed }}kg</text>
	          </view>
	          <view class="cu-form-group">
	            <text class="title">{{$t('储位')}}:</text>
	            <text class="content">{{ batchOrderInfo.positionNo }}</text>
	          </view>
	        </view>
	      </view>
	    </view>
	    <view class="cu-bar bg-white justify-end top-line">
	      <view class="action">
	        <button class="cu-btn bg-green" @tap="submitBatch">{{ $t('确认') }}</button>
	        <button class="cu-btn bg-grey margin-left" @tap="showBatch(false)">{{$t('返回')}}</button>
	      </view>
	    </view>
	  </view>
	</view>

	<!-- 理货纠错 -->
	<view class="cu-modal" :class="errorModal ? 'show' : ''" style="z-index: 900;">
	  <view class="cu-dialog">
	    <view class="cu-bar bg-white justify-end bottom-line">
	      <view class="content title-bolder">{{$t('装箱纠错')}}</view>
	    </view>
	    <view>
	      <view class="cu-bar bg-white search">
	        <view class="search-form round">
	          <!-- <uni-easyinput suffixIcon="scan" :placeholder="$t('请扫描订单号')" v-model="unloadNumber" @iconClick="()=>{scanCode('unloadConfirm')}" @confirm="unloadConfirm"></uni-easyinput> -->
			  <scanlistener
			  v-if="showScanlistener && !batchModal && errorModal"
			  suffixIcon="scan"
			  :placeholder="$t('请扫描订单号')"
			  v-model="unloadNumber"
			  @iconClick="()=>{scanCode('unloadConfirm')}"
			  @confirm="unloadConfirm"
			  @submit="unloadNumber=$event;unloadConfirm()"
			  darkIcon
			  style="width:calc(100% - 10px); "
			  :styles="{color:'#333'}"
			  ></scanlistener>
			</view>
	      </view>
	      <view>
	        <view class="cu-form-group">
	          <text class="title">{{$t('订单号')}}:</text>
	          <text class="content">{{ unloadConfirmNumber }}</text>
	        </view>
	        <view class="cu-form-group">
	          <text class="title">{{$t('标签号')}}:</text>
	          <input class="text-right" :placeholder="$t('开始')" type="number" v-model="unloadSubNumberBegin" />
	          <text class="text-bold">-</text>
	          <input class="text-right" :placeholder="$t('结束')" type="number" v-model="unloadSubNumberEnd" />
	        </view>
	      </view>
	    </view>
	    <view class="cu-bar bg-white justify-end top-line">
	      <view class="action">
	        <button class="cu-btn bg-green" @tap="unload">{{ $t('确认') }}</button>
	        <button class="cu-btn bg-grey margin-left" @tap="showErrorCorrection(false)">{{$t('返回')}}</button>
	      </view>
	    </view>
	  </view>
	</view>
    <!--
    /**
       * https://zentao.test.jdshangmen.com/bug-view-6070.html
       * pda合包装箱-未装箱或已装箱的封箱换下接口
       * 封箱有单独接口 ecw/box-merge-pkg/closeMergePkg
       * 未装箱那里的封箱调用的ecw/box-merge-pkg/update接口
       * 所以通过type传递识别参数
       */
       -->
    <seal :pkg-id="pkgId"
          :shipment-id="shipmentId"
          :type="currentType"
          v-if="showSealDialog"
          @cancel="showSealDialog=false"
          @success="onSealSuccess"></seal>
  </view>
</template>

<script>
import {uniIcons} from '@dcloudio/uni-ui';
import {
  createMergePkgOrder, createMergePkgOrderBatch, finishMergePkg,
  getPkgPageByPkgId, getUnPkgPage, removeMergePkg, removeMergePkgBatch,
  scanOrderNoCreate, listByOrderId
} from "./api";
import {   batchCreateMore,batchDeleteMore,singleCreate,orderTagList } from "../tallyAir/api";
import { getOrderDetail, getOrderDetailByBoxNo } from "../loading/api";
import EditMergePkgDialog from "@/pages/mergePkg/components/editMergePkgDialog.vue";
import OrderDetailModal from "@/components/order-detail-modal/index.vue"
import MixOrderList from "@/pages/tally/mixOrderList.vue";
import util from '@/util/util'
import { msg, alert } from "@/util/tools";
import Seal from "@/pages/mergePkg/components/seal.vue";
import Empty from "@/pages/mergePkg/components/empty.vue";
import * as types from "../../store/mutations-types.js";
import {getProductAttrList} from "@/api/system";

export default {
  components: { Empty, Seal, EditMergePkgDialog, uniIcons, OrderDetailModal, MixOrderList },
  filters:{
    toFixed(val){
      return Number(val).toFixed(2)
    }
  },
  data() {
    return {
      productAttrList:[],
      // 出货Id
      shipmentId: null,
      // 自编号
      selfNo: null,
      // 合包编号
      pkgNum: null,
      // 合包编号ID
      pkgId: null,
      // 当前类型 0 未装箱，1 已装箱
      currentType: 0,
      submitting: false,
      // 合包列表
      list: [],
      // 搜索订单(本地筛选订单)
      searchKeyword: null,
      // 是否显示封箱弹层
      showSealDialog: false,
      /* 订单详情 */
      orderDetailModal: false,
      orderDetail: {},
	  keyword: "",
	   //未理货箱号
	   noTallyAir:false,
	   noTallyAirList:[],
	  /* 批量输入 */
	  batchModal: false,
	  scanNumber: "",
	  batchOrderInfo: {},
    orderId: null,
	  /* 装柜纠错 */
	  errorModal: false,
	  unloadNumber: "",
	  unloadConfirmNumber: "",
	  unloadSubNumberBegin: "",
	  unloadSubNumberEnd: "",
	  isFocus:false,
	  focusStart: false,
	  focusError:false,
	  /* 高亮 */
	  heightLightId: "",
	  onHideFlag: false,
    }
  },
  computed:{
    getStatusText(status){
      return status => {
        return ['', this.$t('未装箱'), this.$t('装箱中'), this.$t('已封箱')][status]
      }
    },
    tabs(){
      return [
        {
          type: 0,
          label: this.$t('未装箱列表')
        },
        {
          type: 1,
          label: this.$t('已装箱列表')
        }
      ]
    },
    // 是否被全部选中
    allChecked(){
      return this.list.length && this.list.every(item => item.checked)
    },
    filteredList(){
      if(!this.searchKeyword)return this.list
      return this.list.filter(item => {
        return item.orderNo.includes(this.searchKeyword)
      })
    }
  },
  onLoad: function(option) {
    uni.setNavigationBarTitle({
      title: this.$t('装箱')
    })
    this.shipmentId = +option.shipmentId
    this.selfNo = option.selfNo || '-'
    this.pkgNum = option.pkgNum
    this.pkgId = +option.pkgId

    this.getData()

    getProductAttrList().then(data => {
      this.productAttrList = data
    })
  },
  methods: {
    formatDate: util.formatDate,
    getData(){
      if(this.currentType===0){
        return this.getUnPkgPage()
      }else this.getPkgPageByPkgId()
    },
    // 获得未装箱列表
    getUnPkgPage(){
      getUnPkgPage({shipmentId: this.shipmentId, rows: 1000}).then(res => {
        this.list = res.list || []
      })
    },
    // 获得已装箱列表
    getPkgPageByPkgId(){
      getPkgPageByPkgId({id: this.pkgId, shipmentId: this.shipmentId, rows: 1000}).then(res => {
        this.list = res.list || []
      })
    },
    changeTab(tabItem){
      this.currentType = tabItem.type
      this.getData()
    },
    // 勾选
    toggleChecked(item){
      console.log('changeCheckbox', item)
      this.$set(item, 'checked', !item.checked)
    },
    toggleCheckAll(){
      let status = !this.allChecked
      this.list.forEach(item => {
        this.$set(item, 'checked', status)
      })
    },
    /* 跳转到关联单 */
    relatedClick(orderNo) {
      uni.navigateTo({
        url: `../tally/relatedOrder?orderId=${orderNo}&selfNo=${this.selfNo}`,
      });
    },
    // 显示混箱明细
    showMixOrder(row) {
      this.orderId = row.orderId;
      this.$refs.mixOrderList.showDetail(row);
    },
    /* 过滤包装类型 */
    uniqueArr(arr) {
      return arr.filter((obj, index, self) =>
      index === self.findIndex((t) => t.unit === obj.unit));
    },
    // 过滤商品特性
    uniqueProductAttrs(arr, field) {
      let uniqueValues = [...new Set(arr.map(item => item[field].split(',')).flat())];
      return uniqueValues.join(',')
    },
    // 获取商品特性文本
    getProductAttrsByIds(ids){
      if(!ids) return ''
      const result = []
      ids.split(',').forEach(e => {
        this.productAttrList.forEach(f => {
          if (parseInt(e) === f.id && this.$l(f, 'attrName') !== '普货') {
            result.push(this.$l(f, 'attrName'))
          }
        })
      })
      console.log('result', result)
      return result.join('、')
    },
    /* 显示订单详情 */
    showOrderDetail(show, id) {
      this.orderDetailModal = show;
      if (show) {
        this.getOrderDetail(id);
      }
    },
    /* 读取订单详情 */
    getOrderDetail(id) {
      return new Promise((resolve, reject) => {
        getOrderDetail(id).then((data) => {
          //订单信息
          this.orderDetail = data;
          listByOrderId({ orderId: id }).then((data) => {
            let positionNos = data.map((item) => {
              return `${item.warehouseName ?? ""}${item.areaName ?? ""}${
                item.locationName ?? ""
              }`;
            });
            this.$set(this.orderDetail, "positionNo", positionNos.join(","));
          });
        });
      });
    },
    // 装箱
    pack(item){
	  if(item.customsType!=='1'){
		return msg(this.$t('订单非我司全代，不允许合包'))
	  }	
      createMergePkgOrder({
        orderId: item.orderId,
        pkgId: this.pkgId
      }).then(res =>{
        msg(this.$t('装箱成功'))
        this.getData()
      })
    },
    // 批量装箱
    async batchPack(){
      let checked = this.list.filter(item => !!item.checked)
      if(!checked.length){
        return msg(this.$t('请选择要装箱的订单'))
      }
      uni.showLoading({
        title: this.$t('装箱中')
      })
      checked = checked.map(item => {
        return {
          orderId: item.orderId,
          pkgId: this.pkgId
        }
      })
      createMergePkgOrderBatch(checked).then(res =>{
        alert(this.$t('批量装箱成功'))
        this.getData()
      }).finally(() =>{
        uni.hideLoading()
      })
    },
    // 移出合包
    remove(item){
      removeMergePkg(item.orderId, this.pkgId).then(res =>{
        msg(this.$t('移出合包成功'))
        this.getData()
      })
    },
    // 批量移出合包
    batchRemove(){
      let checked = this.list.filter(item => !!item.checked)
      checked=  checked.map(item => {
        return {
          orderId: item.orderId,
          pkgId: this.pkgId
        }
      })
      removeMergePkgBatch(checked).then(res =>{
        alert(this.$t('批量移出合包成功'))
        this.getData()
      })
    },
    // 封箱（完成合包）
    finish(){
      let isFinish = false
      let orderNo = ''
      this.list.forEach(item=>{
        if(item.sumNum>item.installNum){
          isFinish = true
          if(!orderNo){
            orderNo = item.orderNo
          }
        }
      })
      console.log(orderNo)
      if(isFinish){
        return msg(this.$t('订单号'+orderNo+'未完成装箱,请完成全部订单装箱后重试'))
      }
      this.showSealDialog = true
    },
    // 封箱成功
    onSealSuccess(){
      // this.getData()
      this.showSealDialog = false
	  uni.navigateTo({
	    url: `./detail?id=${this.shipmentId }&selfNo=${this.selfNo}`,
	  });
    },
    // 下面两个方法从后台复制过来,用于显示储位
    notset(string) {
      if (!string) return string
      let arr = string.split(',')
      arr = arr.filter((item, index) => {
        return arr.indexOf(item) == index
      })
      return arr.toString()
    },
    getpositionNo(arr){
      if(!arr) return arr
      let data = []
      arr.forEach(item=>{
        data.push(item.areaName+item.locationName)
      })
      return data.toString()
    },
	//未合包装箱列表
	showNoGoodsList(show,orderId=0) {
	   this.noTallyAir = show;
	   if(show){
		   this.noTallyAirList = []
		   orderTagList(orderId,1).then(data=>{
			   if(data&&data.unLoadList){
				   this.noTallyAirList = data.unLoadList
			   }
		   })
	   }
	},
	scanCode(type) {
	  uni.scanCode({
	    success: (res) => {
	      switch (type) {
	        case "batchScan":
	          this.scanNumber = res.result;
	          this.batchScan();
	          break;
	        case "loading":
	          this.keyword = res.result;
	          //this.getData();
			  
			 
			  scanOrderNoCreate({"orderNo":this.keyword,"pkgNum":this.pkgNum,shipmentId: this.shipmentId}).then(data=>{
				  msg(this.$t('装箱成功'))
				  this.currentType =1
				  this.getData()
				  
				  
			  })
			  
	          break;
	        case "unloadConfirm":
	          this.unloadNumber = res.result;
	          this.unloadConfirm();
	          break;
	      }
	    },
	  });
	},
	searchCode() {
	 
		setTimeout(this.getDetialOfSelfNO, 100)
		
	},
	
	/* 显示装柜纠错 */
	showErrorCorrection(show) {
	  this.errorModal = show;
	  this.unloadNumber = "";
	  this.unloadConfirmNumber = "";
	  this.unloadSubNumberBegin = "";
	  this.unloadSubNumberEnd = "";
	},
	/* 显示批量输入 */
	showBatch(show) {
	  this.scanNumber = "";
	  this.batchModal = show;
	},
	/* 消息提示与loading */
	showMessageAndReload(message) {
	  this.$store.dispatch(types.SHOW_TOAST, {
	    msg: message,
	  });
	  setTimeout(() => {
	    this.getData();
	  }, 1000);
	},
	getDetialOfSelfNO(){
		scanOrderNoCreate({"orderNo":this.keyword,"pkgNum":this.pkgNum,shipmentId: this.shipmentId}).then(data=>{
						  msg(this.$t('装箱成功'))
						  this.currentType =1
						  this.getData()
						  
		}) .catch((data) => {
			   //其它错误
			   this.$store.dispatch("SHOW_TOAST", {
			     msg: data.msg,
			   }); 
		});
		// singleCreate({pkgId:this.pkgId,type:1,shipmentId: this.shipmentId,orderNumCode:this.keyword}).then((data)=>{
		// 	 this.showMessageAndReload("合包成功");
		// 	 let mainNumber = this.keyword.substring(
		// 	   0,
		// 	   this.keyword.lastIndexOf("-")
		// 	 );
		// 	 if (this.heightLightId != "order-" + mainNumber.toUpperCase()) {
		// 	     setTimeout(() => {
		// 	       this.heightLightId = "order-" +  mainNumber.toUpperCase();
		// 	     }, 1500);
		// 	   }
		// 	   this.ScanSuccess();
		// 	   this.currentType = 1
		// 	   //清空
		// 	   this.keyword = "";
		// 	 })
		// 	 .catch((data) => {
		// 	   //其它错误
		// 	   this.$store.dispatch("SHOW_TOAST", {
		// 	     msg: data.msg,
		// 	   });
		// 	   //清空
		// 	   this.keyword = "";

		// 	   this.ScanError();
		// 	});
            
		// tallyPage({selfNo:this.keyword}).then((data) => {
		// 	if(data.list.length>0){
		// 		this.shipmentId = data.list[0].id
		// 		this.getLoadDetail();
		// 	}
		// })
	},
	/* 确认装柜纠错订单 */
	unloadConfirm() {
	  this.focusError = false;
	  // 扫码速度过快，可能导致取值不完整，所以延迟执行
	  setTimeout(this.unloadConfirmReal, 100);
	},
	unloadConfirmReal() {
	  this.unloadNumber = util.getQrCode(this.unloadNumber);
	  getOrderDetailByBoxNo({
	    orderNumCode: this.unloadNumber,
	    shipmentId: this.shipmentId,
	  }).then((res) => {
	    const { orderNo } = res;
	    if (orderNo) {
	      // 替换掉真实的订单号
	      let numbers = this.unloadNumber.replace(orderNo, "");
	      numbers = numbers.split("-"); // 去掉箱号
	      //自动按后面箱号输入范围
	      if (numbers.length > 1) {
	        this.unloadSubNumberBegin = numbers[numbers.length - 1];
	        this.unloadSubNumberEnd = numbers[numbers.length - 1];
	      }else{
			  this.unloadSubNumberBegin = 1;
			  this.unloadSubNumberEnd = res.num
		  }
	      this.unloadConfirmNumber = orderNo;
	    }
	  });
	  this.focusError = true;
	},
	/* 批量扫描-读取信息 */
	batchScan() {
		  console.log(111)
	  this.isFocus = false;
	  setTimeout(this.batchScanReal, 100);
	},
	batchScanReal() {
	  this.isFocus = true;
	  this.scanNumber = util.getQrCode(this.scanNumber);
	  this.batchOrderInfo = {};
	  getOrderDetailByBoxNo({
	    orderNumCode: this.scanNumber,
	    shipmentId: this.shipmentId,
	  })
	    .then((data) => {
	      this.batchOrderInfo = {
	        orderId: data.orderId,
	        orderNo: data.orderNo,
	        isExternalWarehouse: data.isExternalWarehouse,
	        num: data.num,
	        volume: data.volume,
	        weight: data.weight,
	      };
	      listByOrderId({ orderId: data.orderId }).then((data) => {
	        let positionNos = [...(new Set(data.map((item) => {
	          return `${item.warehouseName ?? ""}${item.areaName ?? ""}${item.locationName ?? ""}`;
	        })))];
	        this.$set(this.batchOrderInfo, "positionNo", positionNos.join(","));
	      });
	    })
	    .catch(() => {
	      this.scanNumber = "";
	    });
	},
	  /* 批量装柜 */
	  submitBatch() {
		 
	    batchCreateMore({
	      orderId: this.batchOrderInfo.orderId,
	      orderNo: this.batchOrderInfo.orderNo !=null?  this.batchOrderInfo.orderNo : this.scanNumber,
	      pkgId: this.pkgId,
		  shipmentId: this.shipmentId,
	      type: 1
	    }).then((data) => {
	      if (data) {
	        this.showMessageAndReload(this.$t("批量合包装箱成功"));
	        this.showBatch(false);
	        this.batchOrderInfo = {};
	        this.scanNumber = "";
			this.getData()
	      }
	    });
	    //清空密码
	    this.batchLoadPassword = "";
	  },
	/* 删除装柜 */
	unload() {
	  if (
	    this.unloadConfirmNumber &&
	    this.unloadSubNumberBegin &&
	    this.unloadSubNumberEnd
	  ) {
	    batchDeleteMore({
	      orderNo: this.unloadConfirmNumber,
	      pkgId: this.pkgId,
		  shipmentId: this.shipmentId,
	      startNo: parseInt(this.unloadSubNumberBegin),
	      endNo: parseInt(this.unloadSubNumberEnd),
		  type:1
	    }).then((data) => {
	      if (data) {
	        this.showMessageAndReload(this.$t("装箱纠错成功"));
	        this.showErrorCorrection(false);
	        this.unloadNumber = "";
	        this.unloadConfirmNumber = "";
	        this.unloadSubNumberBegin = "";
	        this.unloadSubNumberEnd = "";
			this.getData()
	      }
	    });
	  } else {
	    this.$store.dispatch(types.SHOW_TOAST, {
	      msg: this.$t("请输入或扫描正确订单号与标签号"),
	    });
	    this.unloadNumber = "";
	    this.unloadConfirmNumber = "";
	    this.unloadSubNumberBegin = "";
	    this.unloadSubNumberEnd = "";
	  }
	},
    goSearch(){
      uni.navigateTo({
        url: `./search`
      })
    },
    search(keyword){
      this.searchKeyword = keyword
    }
  }
}
</script>

<style lang="scss" scoped>
.tabs{
  margin-top: 10rpx;
  button{
    flex: 1;
  }
}
.mr-10{
  margin-right: 10rpx;
}
.flex-1{
  flex: 1;
}
.justify-between{
  justify-content: space-between;
}
.item{
  border: 1px solid #eee;
  border-radius: 5px;
  padding: 20rpx;
}
.radio{
  width: 50rpx;
  height: 50rpx;
  vertical-align: center;
  margin-right: 10rpx;
}
.action-bar{
  margin: 20rpx 0;
}
.search-header {
  // padding-bottom: 0px;
  ::v-deep .uni-easyinput__content {
    border-radius: 20px;
    padding-right: 10px;
    background: rgba($color: #fff, $alpha: 0.5) !important;
    border: none;
  }

  ::v-deep .uni-input-placeholder {
    padding-left: 8px;
    color: #b2c9f3;
  }

  ::v-deep .uni-input-input {
    padding-left: 8px;
  }
}
.wrap {
  padding-bottom: 120px;
  .content-wrap {
    margin: -75px 0 0;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    background: #fff;
    min-height: calc(100vh - 69px - 120px);
    padding: 0 16px 8px;
    .title {
      display: flex;
      font-size: 18px;
      border-bottom: 0.5px solid #eee;
      padding: 20rpx 0;
      .title-label {
        font-weight: bold;
        line-height: 1.2;
      }
      > view + view {
        margin-left: auto;
        color: #69696b;
      }
    }
    .info-wrap {
      .info-header {
        display: flex;
        font-size: 16px;
        line-height: 40px;
        .header-title {
          font-weight: bold;
        }
        .header-status {
          margin-left: auto;
          color: #50ddae;
        }
      }
      .info-content {
        > view {
          display: flex;
          margin-bottom: 8px;
          > view {
            flex: 1;
            display: flex;
            .label {
              color: #000;
              font-weight: bold;
              white-space: nowrap;
              align-items: flex-start;
              display: flex;
            }
            .content {
              color: #706d71;
              padding-left: 4px;
            }
          }
        }
      }
      .info-card {
        margin: 10px 0px 0px !important;
        .card-btn {
          border-top: 0.5px solid #eee;
          margin-top: 4px;
          padding: 8px;
          overflow: hidden;
          padding-bottom: 0;
          > view {
            float: right;
            height: 32px;
          }
          .mini-btn {
            border-radius: 20px;
            border: 1px solid #007aff;
          }
          .mini-btn + .mini-btn {
            color: #007aff;
            margin-left: 24px;
          }
        }
      }
    }
  }
}
.text-blue{
	color: #007aff !important;
}
 .item-content {
    text-align: left;
    padding: 10px 20px 0px 20px;

    &.noPadding {
      padding: 0;
    }

    > view {
      display: flex;
      padding: 4px 0;

      > view {
        flex: 1;
        word-break: break-all;
        padding-left: 4px;
      }
    }
  }
 .search-info{
   padding: 10px 0;
   display: flex;
   align-items: center;
   .icon{
     margin-left: 10px;
   }
 }
</style>
