<!-- 拣货出库 -->
<template>
    <view class="shpage">
        <!-- 标题栏 -->
        <view class="mianheade mianheade2" @click="goback()">
            <image src="../../static/img/n_baiback.png" class="blacBackico"></image>
            <text class="pagetitle">拣货出库</text>
        </view>
        <!-- 固定内容-->
        <view class="sh_gdInfo">
            <view
                class="item"
                :class="{ itembg2: ckOrderVal }"
                :style="{
                    'pointer-events': ckOrderVal ? 'none' : ''
                }"
            >
                <!-- <view class="it">
					<text class="t1">仓库:</text>
					<text class="t2">{{ warehouseName }}</text>
				</view> -->
                <view>
                    <view class="it">
                        <text class="" style="font-size: 14px">
                            <text class="redtag">*</text>
                            仓库:
                        </text>
                        <w-select
                            class="wwselectit"
                            v-model="warehouseName"
                            defaultValue="请选择"
                            :list="warehouseList"
                            valueName="name"
                            keyName="name"
                            @change="ckchange"
                            ref="wselectck"
						
                        ></w-select>
                    </view>
                </view>
            </view>
            <view
                class="item"
                :class="{
                    itembg2:
                        !warehouseName ||
                        (ckfsVal == '按箱拣货' && boxstrList.length > 0) ||
                        (ckfsVal == '按产品拣货' && xlhstrList.length > 0) ||
                        (ckfsVal == '按产品拣货' && itboxTag)
                }"
                :style="{
                    'pointer-events':
                        !warehouseName ||
                        (ckfsVal == '按箱拣货' && boxstrList.length > 0) ||
                        (ckfsVal == '按产品拣货' && xlhstrList.length > 0) ||
                        (ckfsVal == '按产品拣货' && itboxTag)
                            ? 'none'
                            : ''
                }"
            >
                <view class="it itsp">
                    <text class="t1">
                        <text class="redtag">*</text>
                        出库单号:
                    </text>
                    <w-select
                        style="margin-left: 20rpx; flex: 1"
                        v-model.trim="ckOrderVal"
                        defaultValue="模糊搜索"
                        :list="ckSelectlist"
                        valueName="billNo"
                        keyName="billNo"
                        @change="ckSelectchange"
                        :showClose="true"
                        :focus="focusInput == 'orderinput'"
                        @focus="focusInput = 'orderinput'"
                        :filterable="filterable"
                        :pagingSet="pagingSet"
                        @onBottomPage="onBottomPage"
                        :pageNo="pageNo"
                        :loadingFlag="loadingFlag"
                        :wselectTotal="cklisttotal"
                        @clearnFn="clearnFn"
                        selectTag="ckdhselect"
                    ></w-select>
                </view>
            </view>
            <view
                class="item"
                :class="{ itembg2: (ckfsVal == '按箱拣货' && boxstrList.length > 0) || (ckfsVal == '按产品拣货' && xlhstrList.length > 0) || YiJiannum > 0 || !fid || !ckOrderVal }"
                :style="{
                    'pointer-events':
                        (ckfsVal == '按箱拣货' && boxstrList.length > 0) || (ckfsVal == '按产品拣货' && xlhstrList.length > 0) || YiJiannum > 0 || !fid || !ckOrderVal ? 'none' : ''
                }"
            >
                <view class="it itsp">
                    <text class="t1">
                        <text class="redtag">*</text>
                        出库方式:
                    </text>
                    <w-select
					    ref="ckfsWselect"
                        style="margin-left: 20rpx; flex: 1"
                        v-model="ckfsVal"
                        defaultValue="请选择"
                        :list="ckfsSelectlist"
                        valueName="name"
                        keyName="name"
                        @change="ckfsSelectchange"
                    ></w-select>
                </view>
            </view>
            <view class="item" :class="{ itembg2: !ckfsVal || !ckOrderVal }" :style="{ 'pointer-events': !ckfsVal || !ckOrderVal ? 'none' : '' }" v-if="ckfsVal == '按箱拣货'">
                <view class="it itsp">
                    <text class="t1">
                        <text class="redtag" v-if="ckfsVal == '按箱拣货'">*</text>
                        箱号:
                    </text>
                    <input
                        v-model.trim="xhNo"
                        class="inpt1"
                        type="text"
                        @focus="inputfocus($event, 'box')"
                        @blur="inputblur($event, '')"
                        @confirm="inputConfirm($event, 'box')"
                        :focus="focusInput == 'box'"
                    />
                    <image src="../../static/img/smico.png" class="searchico" @click="scanImg('box')"></image>
                </view>
            </view>
            <view class="item" :class="{ itembg2: !ckfsVal || !ckOrderVal }" :style="{ 'pointer-events': !ckfsVal || !ckOrderVal ? 'none' : '' }" v-if="ckfsVal == '按产品拣货'">
                <view class="it itsp">
                    <text class="t1">序列号:</text>
                    <input
                        v-model="xlhVal"
                        class="inpt1"
                        type="text"
                        @focus="inputfocus($event, 'xlh')"
                        @blur="inputblur($event, '')"
                        @confirm="inputConfirm($event, 'xlh')"
                        :focus="focusInput == 'xlh'"
                    />
                    <image src="../../static/img/smico.png" class="searchico" @click="scanImg('xlh')"></image>
                </view>
            </view>
            <view class="item" :class="{ itembg2: !ckfsVal || ckfsVal == '按箱拣货' }" :style="{ 'pointer-events': !ckfsVal || ckfsVal == '按箱拣货' ? 'none' : '' }">
                <view class="it" >
                    <text class="t1">已拣数量:</text>
                    <text class="t1 tpleft">{{ dqYJnum }}</text>
                </view>
            </view>
            <view class="item item2">
                <view class="it2">
                    <text class="t1">{{ YingJianum }}</text>
                    <text class="t2">应拣</text>
                </view>
                <view class="it2" @click="xhmodelOpen">
                    <text class="t1" style="color: red">{{ YiJiannum }}</text>
                    <text class="t2">已拣</text>
                </view>
                <view class="it2">
                    <text class="t1">{{ YingJianum - YiJiannum }}</text>
                    <text class="t2">待拣</text>
                </view>
            </view>
        </view>
        <!-- 列表内容-->
        <view
            class="shlb cgsjrklb jscklb"
            :style="{ 'margin-top': (!ckfsVal ? heights.top : heights.top + 36) + 'px', height: (!ckfsVal ? heights.body : heights.body - 36) + 'px' }"
        >
            <view class="item" v-for="(item, index) in dataList" :key="index">
                <view class="it" style="border: none">
                    <text class="txt titstr">{{ item.specifications }}</text>
                    <view class="cssj_it" style="background: #fff" v-if="ckfsVal == '按产品拣货'">
                        <view class="tlinb">
                            <view class="txt txtflexnum">
                                <view style="display: flex; flex-direction: row; width: 95%">
                                    <text>{{ item.materialNumber }}</text>
                                    <view class="mxcwdiv" @click="cwtkfn(item.materialSubStocks)">
                                        {{ item.materialSubStocks.length > 0 ? '(' : '' }}
                                        <view @click="cwtkfn(item.materialSubStocks)" class="cwhitzs">
                                            {{ item.materialSubStocks && item.materialSubStocks.length > 0 ? item.materialSubStocks.join(',') : '' }}
                                        </view>
                                        {{ item.materialSubStocks.length > 0 ? ')' : '' }}
                                    </view>
                                </view>
                                <view>
                                    <text>{{ item.accruedQty - item.realityQty }}</text>
                                </view>
                            </view>
                        </view>
                        <view class="txtNum">
                            <view class="txt txtflexnum" style="width: 100%; margin-top: 3px">
                                <view class="tinput" style="flex: 1" >
                                    <text>已拣数量</text>
                                    <text class="ckjhTxt rednum" style="height: 19px">{{ item.qty }}</text>
                                </view>
                                <view class="tinput cktinput_jh" :class="{ disInput: item.itxlhlist.length > 0 }">
                                    <input
                                        v-model="item.boxitNo"
                                        type="text"
                                        @focus="inputfocus($event, 'boxitNo', index, item.materialNumber)"
                                        style="font-size: 10px"
                                        @blur="inputblur($event, '')"
                                        @confirm="inputConfirm($event, 'boxitNo', index, item.materialNumber)"
                                        placeholder="箱信息,可输可扫检索"
                                        :disabled="item.itxlhlist.length > 0"
                                        :focus="focusInput == 'boxitNo' + index"
                                    />
                                    <image src="../../static/img/smico.png" class="searchico" @click="scanImg('boxitNo', index, item.materialNumber)"></image>
                                </view>
                            </view>
                        </view>
                    </view>
                    <view class="cssj_it" style="background: #fff" v-if="ckfsVal == '按箱拣货' || !ckfsVal">
                        <view class="tlinb">
                            <view class="txt txtflexnum">
                                <view style="display: flex; flex-direction: row; overflow: hidden; width: 100%">
                                    <text style="white-space: nowrap">{{ item.materialNumber }}</text>
                                    <view class="mxcwdiv">
                                        {{ item.materialSubStocks.length > 0 ? '(' : '' }}
                                        <view @click="cwtkfn(item.materialSubStocks)" class="cwhitzs">
                                            {{ item.materialSubStocks && item.materialSubStocks.length > 0 ? item.materialSubStocks.join(',') : '' }}
                                        </view>
                                        {{ item.materialSubStocks.length > 0 ? ')' : '' }}
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="txtNum">
                            <view>
                                <!--应拣数量 -->
                                <text>{{ item.accruedQty - item.realityQty }}</text>
                            </view>
                            <view class="txt" @click="handleDqYJnum(item,index)">
								<!-- 这里生产模式要修改成-贸易公司ORICO_HD -->
                                <view class="tinput" style="flex: 1" >
                                    <text>已拣数量:</text>
                                    <!-- 自定义数量 -->
                                    <text :style="selectCKName==='贸易公司ORICO_HD'  && item.qty? 'color:#3e67fd;padding-left: 5px' :'color: red; padding-left: 5px'">{{ item.qty }}</text>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <zero-loading v-if="listloading" type="circle" style="top: 60%"></zero-loading>
        </view>
		
        <!-- 已上架箱号-->
        <u-modal :show="xhlistshow" title="已拣箱信息" @confirm="xhlistshow = false">
            <view style="display: flex; flex-direction: column; overflow-y: auto; max-height: 60vh; overflow-y: auto">
                <view v-for="(item, index) in boxstrList">{{ item }}</view>
            </view>
        </u-modal>
        <!-- 底部按钮固定-->
        <view class="footbts">
            <view class="bt bt1" @click="qktkshow = true">清空出库数量</view>
            <view class="bt bt2" @click="wcNxetFn">完成/下一单</view>
        </view>
        <!--清空二次确认弹框-->
        <u-modal :show="qktkshow" :title="qktkTitle" :content="qktkContent" @confirm="qktkconfirm" :showCancelButton="true" @cancel="qktkshow = false"></u-modal>
        <!--设置 修改当前箱子的数量-->
        <u-modal :show="boxNumshow" title="设置" @confirm="boxNumconfirm" :showCancelButton="true" @cancel="boxNumshow = false">
            <view class="tkvi">
                <view style="padding-left: 3px">
                    箱库存
                    <text style="margin-left: 10px">{{ tkboxNum }}</text>
                </view>
                <u-input v-model="mxTkNum" class="tkinput" placeholder="拣货数量" type="number" style="border: 1px solid #d0d7de"></u-input>
                <text style="font-size: 10px; color: red">{{ tkstr }}</text>
            </view>
        </u-modal>
        <!-- 仓位弹框-->
        <u-modal :show="cwtkshow" title="所在仓位" @confirm="cwtkshow = false">
            <view class="boxtkct" style="max-height:300rpx; overflow-y: auto;">
                <view v-for="(item, index) in materialSubStocks" class="c_item">{{ item }}</view>
            </view>
        </u-modal>
        <!-- 旧的序列号箱信息弹框-->
        <u-modal :show="oldxlhBoxshow"  :showCancelButton="true" title="输入箱号" @confirm="oldxlhBoxcomfirm" @cancel="oldxlhBoxCancel">
            <view class="tkvi">
                <view class="tinput cktinput_jh oldxlhboxct">
                    <input
                        v-model="oldxlhboxVal"
                        type="text"
                        @focus="inputfocus($event, 'oldxlhbox')"
                        style="font-size: 26rpx"
                        @blur="inputblur($event, '')"
                        @confirm="inputConfirm($event, 'oldxlhbox')"
                        :focus="focusInput == 'oldxlhbox'"
                        placeholder="箱信息,可输可扫检索"
                    />
                    <image src="../../static/img/smico.png" class="searchico" @click="scanImg('oldxlhbox')"></image>
                </view>
                <view style="margin-top: 20rpx">
                    <u-checkbox-group class="gxcheckbox" v-model="oldxlhboxCheck" placement="column">
                        <u-checkbox
                            :customStyle="{ marginBottom: '8px' }"
                            v-for="(item, index) in checkboxList"
                            :key="index"
                            :label="item.name"
                            :name="item.name"
                            class="checkboxlabel"
                        ></u-checkbox>
                    </u-checkbox-group>
                </view>
            </view>
        </u-modal>
	
		<u-popup :show="isLKGZ" mode="center"  :round="14">
		    <view style="width: 610rpx;padding: 20rpx;position: relative;">
				<view style="display: flex; justify-content: space-between;align-items: center; padding-bottom: 10rpx;">
					<view style="font-weight: 900;">外箱规格填写(CM)</view>
					<u-icon name="close" size="14" @click="handleClose"></u-icon>
				</view>
				<view class="content">
				<scroll-view scroll-y="true" style="height: 300rpx;">
					<view v-for="(item,index) in wxList[wxListIndex]" :key="index">
						<view style="padding-bottom: 8rpx;display: flex;justify-content: space-between;align-items: center;">
							<view style="display: flex;align-items: center;">
								<text>{{item.boxBillNo}} : </text>
								<image src="../../static/img/copy.png" style="width: 40rpx;height:40rpx" v-if="index===0 ? false :true" @click="handleCopy(item,index)"></image>
							</view>
							<view style="display: flex;align-items: center;" v-if="index===0 ? false :true">
								<image src="../../static/img/deletico.png" style="width: 34rpx;height:34rpx;margin-top: 8rpx;"  @click="handleDel(item,index)">
							</view>
						</view>
						<view style="display: flex; justify-content: space-between;">
							<input type="text" style="border: 1px solid #d0d7de;width: 140rpx;font-size: 14px;border-radius: 8rpx;" placeholder-style="font-size:12px;color:rgba(203, 203, 203, 1);" v-model ="item.boxLength" placeholder="长" @input="handleWXInput(item,index,'boxLength')" :clearable="true" fontSize="14"></input>
							<input type="text" style="border: 1px solid #d0d7de;width: 140rpx;font-size: 14px;border-radius: 8rpx;" placeholder-style="font-size:12px;color:rgba(203, 203, 203, 1);" v-model ="item.boxWide" placeholder="宽" @input="handleWXInput(item,index,'boxWide')" clearable fontSize="14"></input>
							<input type="text" style="border: 1px solid #d0d7de;width: 140rpx;font-size: 14px;border-radius: 8rpx;" placeholder-style="font-size:12px;color:rgba(203, 203, 203, 1);" v-model ="item.boxHigh" placeholder="高" @input="handleWXInput(item,index,'boxHigh')" clearable fontSize="14"></input>
							<input type="text" style="border: 1px solid #d0d7de;width: 140rpx;font-size: 14px;border-radius: 8rpx;" placeholder-style="font-size:12px;color:rgba(203, 203, 203, 1);" v-model ="item.boxWeight" placeholder="重量/KG" @input="handleWXInput(item,index,'boxWeight')" clearable fontSize="14"></input>				
						</view>
					</view>
				</scroll-view>
				</view>
				
				<view style="display: flex; justify-content: flex-end;" @click="">
						<view class="wxBtn" @click="handleWxClick">
							确认
						</view>
				</view>
		    </view>
		</u-popup>
		<u-modal :show="isXsHD"  :content="xsHD" @confirm="xsHDconfirm" :showCancelButton="true" @cancel="isXsHD = false"></u-modal>		
	</view>
</template>

<script>
export default {
    data() {
        return {
			xsHD:"箱规格信息确认输入无误?出库完成之后PDA端不可再修改",
			ckType:0,
			isXsHD:false,
			wxListIndex:0,
			wxList:[],//外箱数据
            oldxlhboxId: null,
            dqoldboxXlh: '', //当前扫描老序列号箱号
            oldxlhdyggxh: '', // 扫描当前序列号对应的规格型号
            isOldOps: false, //是否是老ops条码
            isOldboxInfo: {
                boxName: '',
                boxId: '',
                boxsubStock: '', // 箱子的仓位
                details: []
            },
            getxlhresData: {}, // 缓存的扫描序列号请求的接口数据
            oldxlhboxCheck: [], //默认历史序列号选中
            checkboxList: [
                {
                    name: '默认历史序列号都属于该箱'
                }
            ],
            oldxlhboxVal: '', // 旧的序列号箱信息值
            oldxlhBoxshow: false, //旧的序列号箱信息弹框
            cwtkshow: false, // 仓位弹框
            materialSubStocks: [], //仓位弹框显示内容
            cklisttotal: 0, //当前出库总数
            loadingFlag: 0, //分頁提示
            pageNo: 1,
            pagingSet: true, // 是否开启出库单下拉分页
            heights: {
                top: 0,
                body: 0
            },
            listloading: false,
            xhlistshow: false,
            focusInput: '', //自动聚焦
            fid: '', // 出库单号id
            focusTag: '', //  判斷聚焦
            warehouseName: '', //仓库名称
            warehouseCode: '', //仓库编码+_$組織erpcod
			ckcode:'',//仓库编码
            ckOrderVal: '', // 出库单号输入值
            ckSelectlist: [], // 出库单模糊搜索下拉数据
            ckfsVal: '', // 出库方式输入值
            warehouseList: [], //仓库列表数据
            ckfsSelectlist: [
                {
                    id: 1,
                    name: '按箱拣货'
                },
                {
                    id: 2,
                    name: '按产品拣货'
                }
            ], // 出库方式模糊搜索下拉数据
            xhNo: '', //箱号
            boxstrList: [], // 缓存的箱号信息（多个）
            boxIds: [], // 箱id集合
            boxId: '', // 箱号id
            xlhVal: '', // 序列号
			twoData:[],
            xlhstrList: [], // 缓存的序列号信息（多个）
            dqYJnum: null, // 当前已拣数量
            filterable: true,
            dataList: [], // 列表数据
            YingJianum: 0, // 统计--应拣数量 这个是扫描订单号带出来的
            YiJiannum: 0, // 统计--已拣货数  统计--待拣货数 = 应拣-已拣
            qktkshow: false, //清空二次确认弹框
            boxNumshow: false, // 箱子数量调整弹框
            mxTkNum: 0, // 当前弹框输入值
            qktkTitle: '确定清空已出库数量?',
            qktkContent: '清空后页面数据将不保存',
            itIndx: null, //当前光标对应的是那个明细数据
            timer: null,
            tkboxNum: 0, // 弹框箱库存
            tkstr: '', //弹框提示语
            itdqboxId: '', //当前输入箱信息获取的明细boxid
            itdqsubStockId: '', //当前输入箱信息获取的明细仓位code
            dqboxNO: '', //用来是否保存当前输入箱号的值
            dqboxXlh: '', //用来是否保存当前输入xlh的值
            itboxTag: false, // 判断是否明细扫描过箱号，如果扫描过出库单号不能编辑
            APPdevice: uni.getStorageSync('devicePixelRatio'), // 缓存设备的像素比用来区分普通安卓normalAnroid还是pda
            requestStatus: false, // 请求状态识别变量
            wlId: null, //当前物料明细的物料code
			isLKGZ:false,//控制长宽高重弹窗
			materialNumberIndex:0,
			selectCKName:'',
            scanTracker: {
                lastScanTime: 0,
                lastScanCode: null
            } // 源头处理扫码段时间内重复扫
        };
    },
    watch: {
        xhNo(n) {
            if (!n) {
                this.dqboxNO = '';
            }
        },
        xlhVal(n) {
            if (!n) {
                this.dqboxXlh = '';
            }
        },
        ckOrderVal(n, o) {
            if (!n) {
                this.qktkconfirm();
                this.dataList = [];
                this.YiJiannum = 0;
                this.YingJianum = 0;
            }
            //根据出库单号检索
            this.pageNo = 1;
            this.ckSelectlist = [];
            this.getCKselectlist(n);
        }
    },
    onReady() {
         this.heights = this.$util.setlistHeight('.sh_gdInfo', '.footbts');
    },
    onLoad() {
        // this.getCKselectlist('');
        //获取广播扫码监听
        this.$broadcastScan.init(this.getScancode);
        this.$broadcastScan.start();
        this.getStock();
        this.stopScanCode();
        this.startScanCode();
    },
    onHide() {
        this.$broadcastScan.stop();
        this.stopScanCode();
    },
    onShow() {
        this.$broadcastScan.start();
        this.startScanCode();
    },
    onBackPress(e) {
        this.$util.appgoBack(e, 'index');
        return true;
    },
    methods: {
        // 开启广播
        startScanCode() {
            uni.$on('xwscan', (res) => {
                const now = Date.now();
                const timeSinceLastScan = now - this.scanTracker.lastScanTime;
                // 如果扫描的箱码和上次相同，并且时间间隔小于500ms，则不作处理
                if (res.code === this.scanTracker.lastScanCode && timeSinceLastScan < 4000) {
                    return;
                } else {
                    // 更新扫描跟踪信息
                    this.scanTracker.lastScanTime = now;
                    this.scanTracker.lastScanCode = res.code;
                    this.getScancode(res.code);
                }
            });
        },
        // 关闭广播
        stopScanCode() {
            uni.$off('xwscan');
        },
        //获取仓库数据
        getStock() {
            this.$api.get('/SysConfig/GetUcStock').then((res) => {
                if (res.status == 200) {
                    this.warehouseList = res.data;
                }
            });
        },
		xsHDconfirm() {
			this.wcData()
			this.isXsHD=false;
		},
		//验证
		numberDecimalSeparatorRexg(value) {
			 if (!value) {
			        return;
			    }
			
			    // 清除"数字"和"."以外的字符，只能输入数字和小数点
			    value = value.replace(/[^\d.]/g, "");
			    // 不能连续输入两个及以上小数点
			    value = value.replace(/\.{2,}/g, ".");
			    // 只保留第一个".", 清除多余的"."
			    value = value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
			
			    // 限制小数点后最多 5 位
			    const parts = value.split(".");
			    if (parts.length > 1 && parts[1].length > 5) {
			        parts[1] = parts[1].slice(0, 5);
			        value = parts.join(".");
			    }
			    return value;
		},
		//监听外箱input
		handleWXInput(item,index,type){
			let value = this.numberDecimalSeparatorRexg(item[type])
			this.$nextTick(() => {
			      this.wxList[this.wxListIndex][index][type] = value;
			})
			//输入的是第一行,其他行的数据直接复制第1行的数据
			if(index===0) {
				this.$nextTick(() => {
						this.wxList[this.wxListIndex].forEach(item=>{
							if(type==='boxLength'){
								item.boxLength =this.wxList[this.wxListIndex][0].boxLength
							}else if(type==='boxHigh'){
								item.boxHigh =this.wxList[this.wxListIndex][0].boxHigh
							}else if(type==='boxWide') {
								item.boxWide =this.wxList[this.wxListIndex][0].boxWide
							}else if(type==='boxWeight') {
								item.boxWeight =this.wxList[this.wxListIndex][0].boxWeight
							}
							
						})
				})
				
			}
		},
		//复制数据
		handleCopy(item,index){
			this.$nextTick(() => {
				this.wxList[this.wxListIndex][index].boxLength =this.wxList[this.wxListIndex][index-1].boxLength
				this.wxList[this.wxListIndex][index].boxHigh =this.wxList[this.wxListIndex][index-1].boxHigh
				this.wxList[this.wxListIndex][index].boxWide =this.wxList[this.wxListIndex][index-1].boxWide
				this.wxList[this.wxListIndex][index].boxWeight =this.wxList[this.wxListIndex][index-1].boxWeight
			})
		},
		//关闭外箱弹窗
		handleClose(){
			this.wxList[this.wxListIndex].forEach((item)=>{
				item.boxLength =""
				item.boxHigh =""
				item.boxWide =""
				item.boxWeight =""
			})
			// this.wxList=[]
			this.isLKGZ = false
		},
		//将外箱数据拷贝到需要提交到后台的数组中
		handleWxCopyBoxIds() {
			let wxListClone = JSON.stringify(this.wxList[[this.wxListIndex]])
			let itemArray = JSON.parse(wxListClone)
			this.boxIds = this.boxIds.map(item => {
			    const sourceItem = itemArray.find(source => source.boxId === item.boxId && source.materialNumber===item.materialNumber && source.boxBillNo===item.boxBillNo);
			    if (sourceItem) {
			        return {...item,...sourceItem };
			    } else {
			        return item;
			    }
			});
			this.boxIds.forEach((item)=>{
				item.boxLength =item.boxLength ? Number(item.boxLength) :'';
				item.boxHigh = item.boxHigh ? Number(item.boxHigh) :'';
				item.boxWide =item.boxWide? Number(item.boxWide) :'';
				item.boxWeight =item.boxWeight? Number(item.boxWeight):'';
			})
		},
		//确认
		handleWxClick() {
			this.handleWxCopyBoxIds()
			this.isLKGZ = false;
		},
		
		//清空当前行的数据
		handleDel(item,index) {
			this.wxList[this.wxListIndex][index].boxLength =""
			this.wxList[this.wxListIndex][index].boxHigh =""
			this.wxList[this.wxListIndex][index].boxWide =""
			this.wxList[this.wxListIndex][index].boxWeight =""
			this.handleWxCopyBoxIds()
			
		},
		//外层列表item点击
		handleDqYJnum(item,index) {
	
			if(this.selectCKName!=='贸易公司ORICO_HD') {
				return 
			}
			if(!item.qty) {
				return 
			}
			if(!this.boxIds.length) {
				return;
			}
			this.wxList=[]
			let groupedData ={}
			this.boxIds.forEach(item => {
			    if (!groupedData[item.materialNumber]) {
			        groupedData[item.materialNumber] = [item];
			    } else {
			        groupedData[item.materialNumber].push(item);
			    }
			});
			//根据物料进行了分组[[],[]]
			const result = Object.values(groupedData);
			let materialNumberIndex=0;
			let length = result.length 
			for(let i = 0 ;i<length;i++)  {
				let it = result[i]
				let itLength = it.length 
				for(let j = 0 ;j<itLength;j++)  {
					if( it[j].materialNumber === item.materialNumber){
						this.wxListIndex= i
					}
				}
			}
			this.wxList = result
			this.isLKGZ = true
		},
        //仓库change事件
        ckchange(e) {
			this.ckcode = e.code
            this.warehouseName = e.name;
			this.selectCKName = e.name;
            this.warehouseCode = e.code+`_$${e.erpOrgCode}`;
            if (this.warehouseName) {
                this.focusInput = 'orderinput';
            }
			this.ckSelectlist=[]
            this.getCKselectlist(this.ckOrderVal);
        },
        // 输入箱号确认 旧的序列号
        oldxlhBoxcomfirm() {
            if (this.oldxlhboxId) {
                this.oldxlhBoxshow = false;
                this.oldxlhboxId = null;
                this.setxlhdata(this.getxlhresData);
            } else {
                uni.showToast({
                    title: '请先获取箱，在确认！',
                    icon: 'none',
                    duration: 2500
                });
            }
        },
        // 输入箱号关闭 旧的序列号
        oldxlhBoxCancel() {
            this.oldxlhBoxshow = false;
            this.oldxlhboxId = null;
            this.oldxlhboxCheck = [];
            this.setSMinputoldxlhbox();
            this.setSMinputxlh();
        },
        // 一键清除出库单号
        clearnFn(val) {
            if (val == 'ckdhselect') {
                // this.warehouseName = '';
                // this.warehouseCode = '';
				this.ckfsVal=''
				this.$refs.ckfsWselect.inputData=''
            }
        },
        // 打开仓位弹框
        cwtkfn(list) {
            if (!list || (list && list.length < 2)) return;
            this.cwtkshow = true;
            this.materialSubStocks = list;
        },
        // 出库订单号查询分页
        onBottomPage(val) {
            this.pageNo = val;
            this.loadingFlag = 1;
            this.getCKselectlist(this.ckOrderVal);
        },
        // 打开查看箱号
        xhmodelOpen() {
            if (this.boxstrList.length > 0) {
                this.xhlistshow = true;
            }
        },
        // 设置明细箱拣货数量弹框确认
        boxNumconfirm() {
            this.tkstr = '';
            //首先要判断输入框是否数值
            if (!this.mxTkNum) {
                this.tkstr = '请先输入在确认！';
                return;
            }
            // 当前物料的应拣数量
            let itdqsjCKum = this.dataList[this.itIndx].accruedQty - this.dataList[this.itIndx].realityQty;
            if (parseInt(this.mxTkNum) > itdqsjCKum || parseInt(this.mxTkNum) > parseInt(this.tkboxNum)) {
                this.tkstr = '输入的值不能大于可出库和实际箱库存的值！';
                return;
            }
            let mxdqyjNUM = this.$util.sumObjectArrayValues(this.dataList, 'qty') + parseInt(this.mxTkNum);

            // 当前输入的拣货数量的判断应该是 当前弹框的拣货数量+当前已拣数量>当前应收数量  如果超过就提示
            let dqsetyjNum = this.dataList[this.itIndx].qty + parseInt(this.mxTkNum);
            if (mxdqyjNUM > this.YingJianum || dqsetyjNum > itdqsjCKum) {
                this.tkstr = '输入的值已经超过订单应拣数量！';
                return;
            }

            //如果都满足需求缓存当前箱信息,
            if (
                !this.dataList[this.itIndx].boxTjDatalist ||
                (this.dataList[this.itIndx].itboxIdlist && !this.dataList[this.itIndx].itboxIdlist.some((obj) => obj === this.itdqboxId))
            ) {
                this.dataList[this.itIndx].boxTjDatalist.push({
                    materialNumber: this.dataList[this.itIndx].materialNumber,
                    qty: parseInt(this.mxTkNum),
                    boxId: this.itdqboxId,
                    subStockCode: this.itdqsubStockcode
                });
                // 缓存当前明细行的箱id
                this.dataList[this.itIndx].itboxIdlist.push(this.itdqboxId);
            } else {
                this.dataList[this.itIndx].boxTjDatalist.forEach((it) => {
                    if (it.boxId == this.itdqboxId) {
                        //如果扫描的箱子是扫过的箱子重新计算这个已拣数量，用以前总数已拣-以前的已拣+当前的已设置的已拣数量
                        it.qty = parseInt(this.mxTkNum);
                    }
                });
            }
            this.dqYJnum = parseInt(this.mxTkNum);
            // 计算当前明细行的已拣数量累计的
            this.dataList[this.itIndx].qty = this.$util.sumObjectArrayValues(this.dataList[this.itIndx].boxTjDatalist, 'qty');
            // 统计下总数的已拣
            this.YiJiannum = this.$util.sumObjectArrayValues(this.dataList, 'qty');
            //关闭弹框
            this.boxNumshow = false;
        },
        wcData() {
			if (!this.ckfsVal) {
			    uni.showToast({
			        title: '请先输入必填值',
			        icon: 'none',
			        duration: 2000
			    });
			    return;
			}
			if (this.ckfsVal == '按箱拣货' && (!this.fid || this.boxstrList.length == 0 || !this.YiJiannum)) {
			    uni.showToast({
			        title: '请先输入必填值',
			        icon: 'none',
			        duration: 2000
			    });
			    return;
			}
			if (this.ckfsVal == '按产品拣货' && !this.YiJiannum) {
			    uni.showToast({
			        title: '请先输入必填值',
			        icon: 'none',
			        duration: 2000
			    });
			   return;
			}
			let formData = {};
			formData.taskId = this.fid;
			formData.method = this.ckfsVal == '按箱拣货' ? 1 : 2;
			formData.details = [];
			if (this.ckfsVal == '按箱拣货') {
			    this.boxIds.forEach((it) => {
			        // 过滤为0的数据
			        if (it.qty > 0) {
			            formData.details.push({
			                boxId: it.boxId,
			                materialNumber: it.materialNumber,
			                boxId: it.boxId,
			                serialNumbers: [],
			                qty: it.qty,
							boxLength:it.boxLength,
							boxWide:it.boxWide,
							boxHigh:it.boxHigh,
							boxWeight:it.boxWeight,
			            });
			        }
			    });
			}
			if (this.ckfsVal == '按产品拣货') {
			    let thedetails = [];
			    const boxdetails = []; // 只扫描过箱子的明细数据
			    const xlhdetails = []; //只扫码序列号的明细数据
			    this.dataList.forEach((it) => {
			        if (it.boxTjDatalist && it.boxTjDatalist.length > 0) {
			            it.boxTjDatalist.forEach((k) => {
			                boxdetails.push(k);
			            });
			        }
			        if (it.xljTjDatalist && it.xljTjDatalist.length > 0) {
			            it.xljTjDatalist.forEach((k) => {
			                xlhdetails.push(k);
			            });
			        }
			    });
			    // 处理只扫码序列号的明细数据合并同一个箱子的同一个物料的序列号结合
			    const mergedArray = {};
			    if (xlhdetails && xlhdetails.length > 0) {
			        xlhdetails.forEach((item) => {
			            const key = item.materialNumber + '_' + item.boxId;
			            if (!mergedArray[key]) {
			                mergedArray[key] = {
			                    materialNumber: item.materialNumber,
			                    boxId: item.boxId,
			                    serialNumbers: [],
								twoSerialNumbers:[],
			                    qty: 0
			                };
			            }
			            mergedArray[key].serialNumbers.push(item.serialNumbers);
						mergedArray[key].twoSerialNumbers.push(item.twoSerialNumbers);
			            mergedArray[key].qty += item.qty;
			        });
			        const result = Object.values(mergedArray);
			        // 合并兩個不要不同的類型數據
			        thedetails = boxdetails.concat(result);
			    } else {
			        thedetails = boxdetails;
			    }
			    // 过滤为0的数
			    formData.details = [];
			    formData.details = thedetails.filter((it) => {
					//去掉空值
					it.twoSerialNumbers  = it?.twoSerialNumbers?.filter(Boolean)
			        return it.qty && it.qty > 0;
			    });
			}
			// 节流
			if (this.requestStatus) {
			    return false;
			}
			this.requestStatus = true;
			
			this.$api.post('/OutStock/Save', formData).then((res) => {
			    if (res.status == 200) {
			        uni.showToast({
			            title: '成功',
			            icon: 'none',
			            duration: 1500
			        });
			        setTimeout(() => {
			            uni.navigateTo({
			                url: '/pages/outbound/index'
			            });
			        }, 200);
			        // this.$router.go(0)
			    }
			});
			setTimeout(() => {
			    this.requestStatus = false;
			}, 1500);
		},
		// 完成下一单
        wcNxetFn() {
			if(this.selectCKName==='贸易公司ORICO_HD' && this.ckType===1){
				this.isXsHD = true;
				return false;
			}
			this.wcData()
            
        },
        // 清空出库数量
        qktkconfirm() {
            if (this.ckfsVal == '按箱拣货') {
                this.xhNo = '';
                this.boxstrList = [];
                this.boxIds = [];
                this.setdatalistCZ();
                this.focusInput = 'box';
                this.dqboxNO = '';
            }
            if (this.ckfsVal == '按产品拣货') {
                this.xlhVal = '';
                this.xlhstrList = [];
                this.boxIds = [];
                this.setdatalistCZ();
                this.focusInput = 'xlh';
                this.dqboxXlh = '';
            }
            this.itboxTag = false;
            this.YiJiannum = 0;
            this.dqYJnum = null;
            this.qktkshow = false;
			this.twoData=[]
            //3.29
            this.oldxlhboxCheck = [];
            this.isOldOps = false;
            this.oldxlhboxId = '';
            (this.isOldboxInfo = {
                boxName: '',
                boxId: '',
                boxsubStock: '',
                details: []
            }),
                (this.getxlhresData = {});
            this.oldxlhboxCheck = [];
            this.oldxlhboxVal = '';
            this.oldxlhBoxshow = false;
        },
        // datalist数据重置
        setdatalistCZ() {
            this.dataList.map((obj) => {
                (obj.boxTjDatalist = []), // 如果是box缓存提交的信息
                    (obj.xljTjDatalist = []), //如果是序列号缓存提交的信息
                    (obj.itxlhlist = []), // 序列号集合
                    (obj.itboxIdlist = []), //箱id集合
                    (obj.itboxInfo = {}), // 当前序列号匹配的箱信息
                    (obj.boxlist = []), // 明细扫箱集合信息{数量，箱号，仓位}
                    (obj.qty = 0), // 初始默认为0
                    (obj.theyingjianNum = obj.accruedQty - obj.realityQty);
                obj.boxitNo = '';
                return obj;
            });
        },
        // 扫描框数据重置，光标聚焦
        setSMinputbox() {
            this.focusInput = '';
            setTimeout(() => {
                this.xhNo = '';
                this.focusInput = 'box';
                this.dqYJnum = null;
            }, 200);
        },
        //扫描老序列號扫箱框数据重置，光标聚焦
        setSMinputoldxlhbox() {
            this.focusInput = '';
            setTimeout(() => {
                this.oldxlhboxVal = '';
                this.focusInput = 'oldxlhbox';
                this.dqoldboxXlh = '';
            }, 200);
        },
        // 老序列号输入箱号处理
        getboxinfobyOldxlh() {
            clearTimeout(this.timer);
            this.timer = setTimeout(() => {
                if (!this.oldxlhboxVal) {
                    this.setSMinputoldxlhbox();
                    uni.showToast({
                        title: '请扫描箱号！',
                        icon: 'none',
                        duration: 2000
                    });
                    return;
                }
                this.focusInput = '';
                this.oldxlhboxId = '';
                this.$api.get('/Inventory/GetBoxInventoryDetails/' + this.oldxlhboxVal).then((res) => {
                    if (res.status == 200) {
                        //这里要判断当前扫描的序列号的规格是否存在当前箱子
                        let llhtag = res.data.details.find((it) => it.specifications == this.getxlhresData.data.specifications);
                        if (!llhtag) {
                            this.setSMinputoldxlhbox();
                            uni.showToast({
                                title: '箱内不存在该产品',
                                icon: 'none',
                                duration: 2500
                            });
                            return;
                        }
                        // 如果出库单带出的仓库信息和箱号的不匹配就没有后续操作
                        if (this.ckcode !== res.data.stockCode) {
                            this.setSMinputoldxlhbox();
                            uni.showToast({
                                title: '箱子仓库和出库单号仓库不一致！',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        let boxwlIds = res.data.details.filter((item) => item.qty > 0).map((item) => item.materialNumber);
                        let datawlds = this.dataList.map((it) => {
                            return it.materialNumber;
                        });
                        // 判断箱子物料是否完全包含在明细信息里面的
                        if (!this.$util.arrayContainsArray(datawlds, boxwlIds)) {
                            this.setSMinputoldxlhbox();
                            uni.showToast({
                                title: '箱内不存在该产品',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        // 判断这个序列对应的规格在在箱子内是否还有库存
                        let ggxhqtytag = false;
                        if (res.data.details && res.data.details.length > 0) {
                            res.data.details.forEach((it) => {
                                if (it.specifications == this.oldxlhdyggxh) {
                                    ggxhqtytag = it.qty > 0 ? false : true;
                                }
                            });
                        }
                        if (ggxhqtytag) {
                            this.setSMinputoldxlhbox();
                            uni.showToast({
                                title: '箱内产品库存不足, 箱扫描失败',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        //保留当前输入的数据
                        this.dqoldboxXlh = res.data.boxBillNo;
                        this.oldxlhboxVal = res.data.boxBillNo;
                        this.focusInput = 'oldxlhbox';
                        this.isOldboxInfo = {
                            boxName: res.data.boxBillNo,
                            boxId: res.data.boxId,
                            boxsubStock: res.data.subStockCode,
                            details: res.data.details
                        };
                        this.oldxlhboxId = res.data.boxId;
                        uni.showToast({
                            title: '获取成功',
                            icon: 'none',
                            duration: 2000
                        });
                    } else {
                        this.setSMinputoldxlhbox();
                    }
                });
            }, 1000);
        },
        // 根据箱号查相关信息
        getboxinfo() {
            clearTimeout(this.timer);
            this.timer = setTimeout(() => {
                if (!this.fid) {
                    this.setSMinputbox();
                    uni.showToast({
                        title: '请先选择出库单号',
                        icon: 'none',
                        duration: 2000
                    });
                    return;
                }
                if (!this.xhNo) {
                    this.setSMinputbox();
                    uni.showToast({
                        title: '请扫描需要上架的箱号',
                        icon: 'none',
                        duration: 2000
                    });
                    return;
                }
                if (this.boxstrList.includes(this.xhNo)) {
                    this.setSMinputbox();
                    uni.showToast({
                        title: '该箱号已扫描',
                        icon: 'none',
                        duration: 2000
                    });
                    return;
                }
                this.focusInput = '';
                //采购订单物料明细和箱物料明细-对比接口，
                this.$api.get('/Inventory/GetBoxInventoryDetails/' + this.xhNo).then((res) => {
                    if (res.status == 200 && res.data.details && res.data.details.length > 0) {
                        // 如果出库单带出的仓库信息和箱号的不匹配就没有后续操作
                        if (this.ckcode !== res.data.stockCode) {
                            this.setSMinputbox();
                            uni.showToast({
                                title: '箱子仓库和出库单号仓库不一致！',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        let boxwlIds = res.data.details.filter((item) => item.qty > 0).map((item) => item.materialNumber);
                        let datawlds = this.dataList.map((it) => {
                            return it.materialNumber;
                        });
                        // 判断箱子物料是否完全包含在明细信息里面的
                        if (!this.$util.arrayContainsArray(datawlds, boxwlIds)) {
                            this.setSMinputbox();
                            uni.showToast({
                                title: '箱内产品和出库单不一致',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        var yjtag = false;
                        var boxlists = [];
                        res.data.details.forEach((it) => {
                            this.dataList.forEach((k) => {
                                if (it.materialNumber == k.materialNumber) {
                                    //缓存箱id
                                    if (this.ckfsVal == '按箱拣货') {
                                        boxlists.push({
                                            boxId: res.data.boxId,
                                            materialNumber: it.materialNumber,
                                            subStockCode: it.subStockCode,
                                            qty: it.qty,
											boxBillNo:res.data.boxBillNo,
											boxLength:'',
											boxWide:'',
											boxHigh:'',
											boxWeight:'',
                                        });
                                    }
                                    let num1 = 0;
                                    num1 = k.qty + it.qty;
                                    if (num1 > k.accruedQty - k.realityQty) {
                                        yjtag = true;
                                    }
                                }
                            });
                        });

                        if (yjtag) {
                            this.setSMinputbox();
                            uni.showToast({
                                title: '箱内产品数量和出库订单不一致',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }

                        var bjtotal = this.YiJiannum + res.data.totalQty;
                        if (bjtotal > this.YingJianum) {
                            this.setSMinputbox();
                            uni.showToast({
                                title: '箱内产品数量超过出库订单待拣数量',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        //缓存箱id
                        if (this.ckfsVal == '按箱拣货') {
                            this.boxIds = this.boxIds.concat(boxlists);
                        }
                        // top的已拣数量
                        this.dqYJnum = res.data.totalQty;
                        // 已拣数量
                        this.YiJiannum = this.YiJiannum + res.data.totalQty;
                        // 应拣数量
                        this.totalSet();
                        // 每次扫箱对应的明细数据已拣数量要累计相加
                        res.data.details.forEach((it) => {
                            this.dataList.forEach((k) => {
                                if (it.materialNumber == k.materialNumber) {
                                    k.qty = k.qty + it.qty;
                                }
                            });
                        });
                        // 如果查询的箱号正常返回数据，就缓存改箱号信息
                        this.boxstrList.push(res.data.boxBillNo);
                        //清空当前框数据 自动聚焦箱号
                        //保留当前输入的数据
                        this.dqboxNO = res.data.boxBillNo;
                        this.xhNo = res.data.boxBillNo;
                        this.focusInput = 'box';
                        uni.showToast({
                            title: '获取成功',
                            icon: 'none',
                            duration: 2000
                        });
                    } else {
                        this.setSMinputbox();
                    }
                });
            }, 1000);
        },
        // 统计栏目的计算
        totalSet() {
            if (this.dataList && this.dataList.length > 0) {
                // 应拣数量
                this.yingjianSum = 0;
                this.YingJianum = this.dataList.reduce((accumulator, obj) => {
                    return accumulator + obj.theyingjianNum;
                }, 0);
            }
        },
        // 区分不同的扫描数据、输入数据做处理显示 box
        setSMstr(str) {
            let lth = str.length - this.dqboxNO.length;
            if (lth > 1) {
                // 扫描的值
                this.xhNo = str.substring(this.dqboxNO.length);
            } else {
                this.dqboxNO = str;
                this.xhNo = str;
            }
            console.log('扫描设置', this.dqboxNO, this.xhNo);
        },
        // 区分不同的扫描数据、输入数据做处理显示 xlh
        setSMxlhstr(str) {
            let lth = str.length - this.dqboxXlh.length;
            if (lth > 1) {
                // 扫描的值
                this.xlhVal = str.substring(this.dqboxXlh.length);
            } else {
                this.dqboxXlh = str;
                this.xlhVal = str;
            }
        },
        // 区分不同的扫描数据、输入数据做处理显示 旧的序列号
        setSMoldxljboxstr(str) {
            let lth = (str ? str.length : 0) - (this.dqoldboxXlh ? this.dqoldboxXlh.length : 0);
            if (lth > 1) {
                // 扫描的值
                this.oldxlhboxVal = str.substring(this.dqoldboxXlh.length);
            } else {
                this.dqoldboxXlh = str;
                this.oldxlhboxVal = str;
            }
        },
        // 输入确认
        inputConfirm(val, type, index, wlcode) {
            if (val) {
                if (type == 'box') {
                    this.setSMstr(val.target.value);
                    this.getboxinfo();
                }
                if (type == 'oldxlhbox') {
                    this.setSMoldxljboxstr(val.target.value);
                    this.getboxinfobyOldxlh();
                }
                if (type == 'xlh') {
                    this.setSMxlhstr(val.target.value);
                    this.getXlhInfo();
                }
                // 扫描明细的箱信息
                if (type == 'boxitNo') {
                    this.itIndx = index;
                    // 调取箱信息，如果箱子存在就打开数量的弹框
                    this.getItBoxInfo(val.target.value, index, wlcode);
                }
            }
        },
        // 扫描框数据重置，光标聚焦
        setItBox(index) {
            this.focusInput = '';
            setTimeout(() => {
                this.itIndx = index;
                this.focusInput = 'boxitNo' + index;
                this.dataList[index].boxitNo = null;
            }, 200);
        },
        // 获取明细箱信息
        getItBoxInfo(val, index, wlcode) {
            if (!val) {
                uni.showToast({
                    title: '该扫描或输入箱号',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            let exists = this.dataList[index].boxlist.some((obj) => obj.boxName === val);
            if (exists) {
                uni.showToast({
                    title: '该箱号已扫描',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            this.$api.get('/Inventory/GetBoxInventoryDetails/' + val).then((res) => {
                if (res.status == 200) {
                    // 判断当前的明细的箱子是否鱼当前订单仓库是匹配
                    if (this.ckcode !== res.data.stockCode) {
                        this.setItBox(index);
                        uni.showToast({
                            title: '该箱号的仓库与当前订单仓库不匹配，请重新设置',
                            icon: 'none',
                            duration: 1500
                        });
                        return;
                    }
                    if (res.data.details && res.data.details.length > 0) {
                        // 判断当前物料是否在改箱子内
                        let matchingObj = res.data.details.find((obj) => obj.materialNumber === wlcode);
                        if (matchingObj) {
                            // 获取匹配对象的另一个属性值
                            this.tkboxNum = matchingObj.qty;
                            this.boxNumshow = true;
                            this.tkstr = null;
                            this.mxTkNum = null;
                            this.dataList[index].boxlist.push(val);
                            this.itdqboxId = res.data.boxId;
                            this.itdqsubStockcode = res.data.subStockCode;
                            this.itboxTag = true;
                            uni.showToast({
                                title: '获取成功',
                                icon: 'none',
                                duration: 2000
                            });
                        } else {
                            this.setItBox(index);
                            uni.showToast({
                                title: '该箱子没有对应的物料信息',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                    } else {
                        this.setItBox(index);
                        uni.showToast({
                            title: '该箱子没有物料信息',
                            icon: 'none',
                            duration: 2000
                        });
                        return;
                    }
                } else {
                    this.setItBox(index);
                }
            });
        },
        // 扫描框数据重置，光标聚焦
        setSMinputxlh() {
            this.focusInput = '';
            setTimeout(() => {
                this.xlhVal = '';
                this.focusInput = 'xlh';
                this.dqYJnum = null;
            }, 200);
        },
        // 扫描序列号数据处理
        setxlhdata(res) {
            let thindx = this.dataList.findIndex((it) => it.materialNumber == res.data.materialNumber);
		
            // 如果这个序列存在明细信息就缓存
            if (!this.dataList[thindx].itxlhlist && this.dataList[thindx].itxlhlist.length == 0) {
                this.dqYJnum = 0;
                this.dataList[thindx].boxTjDatalist = [];
                this.dataList[thindx].itboxIdlist = [];
            }
            this.dataList[thindx].xljTjDatalist.push({
                materialNumber: res.data.materialNumber,
                qty: 1,
                boxId: this.isOldOps && this.isOldboxInfo.boxsubStock ? this.isOldboxInfo.boxId : res.data.boxId,
                subStockCode: this.isOldOps && this.isOldboxInfo.boxsubStock ? this.isOldboxInfo.boxsubStock : res.data.subStockCode,
                serialNumbers: res.data.serialNumber,
				twoSerialNumbers:res.data.twoSerialNumber
            });
            this.dataList[thindx].itxlhlist.push(this.xlhVal);
            this.dataList[thindx].boxitNo = this.isOldOps && this.isOldboxInfo.boxsubStock ? this.isOldboxInfo.boxName : res.data.boxBillNo;
            // top已拣数量
            this.dqYJnum = 1;
            //更新明细已拣数量
            this.dataList[thindx].qty = this.dataList[thindx].itxlhlist.length;
            // 统计已拣数量
            this.YiJiannum = this.$util.sumObjectArrayValues(this.dataList, 'qty');
            // 扫描缓存
            this.dqboxXlh = res.data.serialNumber;
            this.xlhVal = res.data.serialNumber;
            this.focusInput = 'xlh';
            // 如果查询的序列号正常返回数据，就缓存序列号信息
            this.xlhstrList.push(res.data.serialNumber);
			if(res.data.isTwo==2) {
				this.twoData.push(res.data.twoSerialNumber)
			}
			
            // 如果是老的序列号就缓存当前的箱信息
            this.dataList[thindx].itboxInfo = this.isOldboxInfo;
            uni.showToast({
                title: '获取成功',
                icon: 'none',
                duration: 2000
            });
        },
        // 根据序列号获取对应的规格型号
        getXlhInfo() {
            if (!this.xlhVal) {
                this.setSMinputxlh();
                uni.showToast({
                    title: '该扫描或输入序列号',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            if (this.xlhstrList.includes(this.xlhVal) || this.twoData.includes(this.xlhVal)) {
                this.setSMinputxlh();
                uni.showToast({
                    title: '该序列号已经扫描过了',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            this.focusInput = '';
            this.$api
                .get('/SysConfig/GetMaterial', {
                    serialNumber: this.xlhVal,
                    IsOps: true,
                    serialStatus: 3
                })
                .then((res) => {
                    if (res.status == 200) {
                        if (!res.data.isBoxInventory) {
                            this.setSMinputxlh();
                            uni.showToast({
                                title: '序列号未上架入库',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        if (this.ckcode !== res.data.stockCode && res.data.boxId) {
                            this.setSMinputoldxlhbox();
                            uni.showToast({
                                title: '箱子仓库和出库单号仓库不一致！',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }
                        if (!res.data.serialNumber) {
                            this.setSMinputxlh();
                            uni.showToast({
                                title: '请扫描或输入正确的序列号',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        }

                        let thindx = this.dataList.findIndex((it) => it.materialNumber == res.data.materialNumber);
                        if (thindx == -1) {
                            this.setSMinputxlh();
                            uni.showToast({
                                title: '序列号和出库单产品不一致',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        } else if (!res.data.serialNumber) {
                            this.setSMinputxlh();
                            uni.showToast({
                                title: '请扫描序列号',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        } else if (!res.data.subStockCode && !res.data.isOldOps) {
                            this.setSMinputxlh();
                            uni.showToast({
                                title: '该序列号没有对应仓位，不能出库',
                                icon: 'none',
                                duration: 2000
                            });
                            return;
                        } else {
                            let n = this.dataList[thindx].itxlhlist.length + 1;
                            if (n > this.dataList[thindx].accruedQty - this.dataList[thindx].realityQty) {
                                this.setSMinputxlh();
                                uni.showToast({
                                    title: '序列号累计的产品数量超过出库订单物料数据',
                                    icon: 'none',
                                    duration: 2000
                                });
                                return;
                            }
                            let yn = this.dataList[thindx].itxlhlist.length + 1;
                            if (yn > this.YingJianum) {
                                this.setSMinputxlh();
                                uni.showToast({
                                    title: '序列号累计的产品数量超过出库订单数量',
                                    icon: 'none',
                                    duration: 2000
                                });
                                return;
                            }

                            // 是否是老ops条码
                            this.isOldOps = res.data.isOldOps;
                            this.oldxlhdyggxh = res.data.specifications;
                            if (res.data.isOldOps) {
                                this.getxlhresData = res;
                            
                                this.oldxlhboxVal = '';
                                this.focusInput = 'oldxlhbox';
                                // 判断扫描的序列号在对应明细存在的箱信息里面库存是否充足
                                /**
                                 * 1. 如果是新的序列号逻辑不变
                                 * 2. 如果是老的序列号，如果勾选了默认箱，判断物料对应的明细物料是否重来没有拣货过，拣货数量加一，然后箱信息默认
                                 * 3. 如果是老的序列号，如果勾选了默认箱，如果是已经拣货过的明细物料，要判断箱子里面的可拣货数量是否有超过，有就提示
                                 * 4. 如果是老的序列号，如果没有勾选默认箱，就取当前用户输入的箱信息做数据处理
                                 **/
                                if (this.oldxlhboxCheck.length > 0) {
                                    // 判断物料明细行是否有扫描过
                                    let isoldinfoindex = this.isOldboxInfo.details.findIndex((it) => it.materialNumber == res.data.materialNumber);
                                    if (isoldinfoindex == -1) {
                                        this.setSMinputxlh();
                                        uni.showToast({
                                            title: '箱内不存在该产品',
                                            icon: 'none',
                                            duration: 2000
                                        });
                                        return;
                                    }
                                    //扫描老的序列号判断是否超过当前默认箱的历库存
                                    this.isOldboxInfo.details[isoldinfoindex].qty = this.isOldboxInfo.details[isoldinfoindex].qty - 1;
                                    if (this.isOldboxInfo.details[isoldinfoindex].qty <= 0) {
                                        this.setSMinputxlh();
                                        uni.showToast({
                                            title: '箱内产品库存不足',
                                            icon: 'none',
                                            duration: 2000
                                        });
                                        return;
                                    }
                                    this.oldxlhBoxshow = false;
                                    this.setxlhdata(res);
                                } else {
                                    if (res.data.boxId == 0) {
                                        this.oldxlhBoxshow = true;
                                    } else {
                                        this.setxlhdata(res);
                                    }
                                }
                            } else {
                                this.setxlhdata(res);
                            }
                            console.log('明细数据', this.dataList);
                        }
                    } else {
                        this.setSMinputxlh();
                    }
                });
        },
        // 普通安卓设备碘酒扫描图标扫描
        scanImg(type, index, wlcode) {
            if (this.APPdevice == 'normalAnroid') {
                this.$util.doScanQrCode().then((res) => {
                    this.focusInput = type;
                    this.focusTag = type;
                    this.getScancode(res.result, index);
                });
            }
        },
        // 获取扫描的值
        getScancode(code, index, wlcode) {
            if (this.focusTag == 'box') {
                // 有些PDA会自带换行符，trim函数处理下
                this.xhNo = '';
                this.xhNo = code.trim();
                this.getboxinfo();
                this.focusInput = 'box';
            }
            if (this.focusTag == 'oldxlhbox') {
                this.oldxlhboxVal = '';
                this.oldxlhboxVal = code.trim();
                this.getboxinfobyOldxlh();
                this.focusInput = 'oldxlhbox';
            }
            if (this.focusTag == 'xlh') {
                // 有些PDA会自带换行符，trim函数处理下
                this.xlhVal = '';
                this.xlhVal = code.trim();
                this.getXlhInfo();
                this.focusInput = 'xlh';
            }
            if (this.focusTag == 'boxitNo') {
                // this.itIndx = index
                // 调取箱信息，如果箱子存在就打开数量的弹框
                this.dataList[this.itIndx].boxitNo = '';
                this.dataList[this.itIndx].boxitNo = code.trim();
                this.getItBoxInfo(code.trim(), this.itIndx, this.wlId);
                this.focusInput = 'boxitNo' + this.itIndx;
            }
        },
        // 輸入失去焦點
        inputblur(val, type) {
            this.focusTag = type;
            // console.log('輸入失去焦點', val, type)
        },
        // 计算按照产品上架 top的意见数量和对应明细的已拣数量
        planNum() {
            // 1.计算top的数量的总和，如果光标在明细的箱号输入框
            this.dqYJnum = this.dataList.reduce((prev, curr) => {
                if ((curr.realityQty != null || curr.realityQty != '' || curr.realityQty != undefined) && !curr.itxlhlist) {
                    return prev + curr.realityQty;
                } else {
                    // 如果值为空或无效，可以选择跳过该值，也可以将其视为0
                    // 这里我们选择视为0
                    return prev;
                }
            }, 0);
            /*
				 2. 如果在明细的箱号输入框存在箱号，打开数量的弹框，填入数量，点击确定，对应的已拣数量累计加这个数量，同事更新top的
				 已拣数量(统计的是没有扫描过序列号的明细数量总和），统计栏已拣是统计所有的明细已拣数量总和
				*/

            // 3.按产品出库时 ，如果输入光标在明细箱号输入框上面的统计栏目已拣数量是所有明细框的已检数量总和
            this.YiJiannum = this.$util.sumObjectArrayValues(this.dataList, 'qty');
        },
        // 输入聚焦
        inputfocus(val, type, index, wlId) {
            this.focusTag = type;
            if (type == 'box') {
                // this.xhNo =""
            }
            if (type == 'boxitNo') {
                // top的已拣数量为所有没有扫过徐磊好的明细数量的数量综合
                this.itIndx = index;
                this.wlId = wlId;
                this.YiJiannum = this.$util.sumObjectArrayValues(this.dataList, 'qty');
            }
            // console.log('输入聚焦', val, type)
        },
        //根据出库单号获取对应的下拉数据
        getCKselectlist(val) {
            // if (!val) return
            clearTimeout(this.timer);
            this.pagingSet = false;
            if (this.ckSelectlist.length >= this.cklisttotal && this.pageNo >= 2) {
                this.loadingFlag = 2;
                return;
            }
            this.timer = setTimeout(() => {
                this.$api
                    .post('/OutStockTask/GetOutStockTaskNosByNo', {
                        billNo: val,
                        pageSize: 10,
                        pageNo: this.pageNo,
                        stockCode: this.warehouseCode
                    })
                    .then((res) => {
                        if (res.status == 200) {
                            this.cklisttotal = res.totalCount;
                            let newarr = res.data.map((item) => {
                                return {
                                    billNo: item
                                };
                            });
                            this.ckSelectlist = this.ckSelectlist.concat(newarr);
                            this.pagingSet = true;
                            this.loadingFlag = 1;
                        } else {
                            this.pagingSet = true;
                            this.cklisttotal = res.totalCount;
                        }
                    });
            }, 1000);
        },
        // 出库单号下拉选择监听
        ckSelectchange(e) {
            // 根据选择的出库单号查出对应的明细信息
            // 调取一个数据校验接口
            if (e.billNo) {
                this.listloading = true;
                this.$api
                    .get('/OutStockTask/GetOutStockTaskByNo', {
                        billNo: e.billNo
                    })
                    .then((res) => {
                        if (res.status == 200) {
                            if (res.data.details && res.data.details.length > 0) {
                                this.ckcode = res.data.stockCode;
                                this.warehouseName = res.data.stockName;
								this.ckType=res.data.type;
                                this.dataList = res.data.details.map((item) => {
                                    return {
                                        ...item,
                                        boxTjDatalist: [], // 如果是box缓存提交的信息
                                        xljTjDatalist: [], //如果是序列号缓存提交的信息
                                        itxlhlist: [], // 序列号集合
                                        itboxIdlist: [], //箱id集合
                                        itboxInfo: {}, // 当前序列号匹配的箱信息
                                        boxlist: [], // 明细扫箱集合信息{数量，箱号，仓位}
                                        qty: 0, // 初始默认为0
                                        theyingjianNum: item.accruedQty - item.realityQty < 0 ? 0 : item.accruedQty - item.realityQty
                                    };
                                });
                                this.fid = res.data.id;
                                this.totalSet();
                            }
                        }
                        this.listloading = false;
                    });
            }
        },
        // 出库方式切换
        ckfsSelectchange(e) {
            this.dqYJnum = null;
            this.YiJiannum = 0;
            this.xhNo = null;
            this.xlhVal = null;
            this.focusInput = '';
            this.boxIds = [];
            this.dataList = this.dataList.map((item) => {
                return {
                    ...item,
                    boxTjDatalist: [], // 如果是box缓存提交的信息
                    xljTjDatalist: [], //如果是序列号缓存提交的信息
                    itxlhlist: [], // 序列号集合
                    itboxIdlist: [], //箱id集合
                    itboxInfo: {}, // 当前序列号匹配的箱信息
                    boxlist: [], // 明细扫箱集合信息{数量，箱号，仓位}
                    boxitNo: '',
                    qty: 0 // 初始默认为0
                };
            });

            if (e.name == '按箱拣货') {
                setTimeout(() => {
                    this.focusInput = 'box';
                }, 200);
            }
            if (e.name == '按产品拣货') {
                setTimeout(() => {
                    this.focusInput = 'xlh';
                }, 200);
            }
            // this.heights.top = this.heights.top + 36
            // this.heights.body = this.heights.body - 36
            this.$forceUpdate();
        },
        //根据选择的出库单号查出对应的明细信息
        getCKorderlist() {
            //这个地方是多个全部明细带出
            this.dataList = [];
            // this.dataList.push(e)
            this.dataList = [
                {
                    specifications: '规格型号',
                    materialNumber: '物料编码',
                    num: 100,
                    yjnum: '110' // 已拣数量
                }
            ];
        },
        // 返回
        goback() {
            uni.navigateTo({
                url: '/pages/index'
            });
        }
    }
};
</script>

<style lang="scss">
@import '@/static/public.scss';

.mianheade2 {
    .pagetitle {
        margin-left: 30%;
    }
}
.wxBtn {
	
	background-color: #3e67fd;
	padding: 14rpx;
	width: 140rpx; 
	height:30rpx;
	border-radius: 16rpx;
	color:#fff;
	display: flex; 
	justify-content: center; 
	align-items: center;
	font-size:14px;
	margin-top: 20rpx;
}
</style>
