<template>
	<view>
		<view class="sticky-box">
			<view class="button-group">
				<button type="default" @click="reset">取消</button>
				<button type="default" @click="navigateToSummary">统计</button>
				<!-- <navigator url="/pages/production-replenishment/search" hover-class="navigator-hover"> -->
				<button type="default" @click="navigateToSearch">查询</button>
				<!-- </navigator> -->
				<button type="default" @click="navigateToStage">暂存</button>
				<!-- <button type="default" @click="">提交</button> -->
			</view>
			<uni-easyinput prefixIcon="search" :focus="isFocus" v-model="searchValue" @blur="isFocus = false"
				@confirm="scan" @clear="clear" placeholder="请扫描拼件单号">
			</uni-easyinput>
		</view>
		<view class="table-container" style="height: 100vh;">
			<scroll-view class="table-content" :style="{'height': clientHeight + 'px'}" scroll-x scroll-y
				:scroll-into-view="scrollItem">
				<!-- <scroll-view scroll-x="true" class="scroll-view-header"> -->
				<view class="table-header">
					<view class="table-cell">操作</view>
					<view class="table-cell">扫描状态</view>
					<view class="table-cell">仓位名称</view>
					<view class="table-cellwl">物料编码</view>
					<view class="table-cell1">箱号</view>
					<view class="table-cell1">实际作业数量</view>
					<view class="table-cell1">即时库存数量</view>
					<view class="table-cell1">装箱单号</view>
					<view class="table-cell">面料订单号</view>
					<view class="table-cell">等级</view>
					<view class="table-cellph">批号</view>
					<view class="table-cell2">工作中心</view>
					<view class="table-cell">备注</view>
					<view class="table-cell3">单据编号</view>
					<view class="table-cell">仓位原件数</view>
					<view class="table-cell">发货件数</view>
					<view class="table-cell">剩余件数</view>
					<view class="table-cell">日期</view>
					<view class="table-cell">作业申请人</view>
					<view class="table-cell">仓管员</view>
				</view>
				<!-- </scroll-view> -->
				<!-- 	<scroll-view class="table-content" :style="{'height': clientHeight + 'px'}" scroll-x scroll-y
				:scroll-into-view="scrollItem"> -->
				<view class="table-row" v-for="(item, index) in indexList" :key="index" :id="'scrollItem-' + index"
					:style="getStyle(item.smzt)">
					<view class="table-cell"><button type="default" size="mini" @click="edit(item,index)">编辑</button>
					</view>
					<view class="table-cell">{{ item.smzt? '已扫描' : '未扫描' }}</view>
					<view class="table-cell">{{ item["FStockLocId.FF102029.fname"] }}</view>
					<view class="table-cellwl" :style="getStyle(item.smzt)">{{ item["FMaterialId.fnumber"] }}</view>
					<view class="table-cell1" :style="getStyle(item.smzt)">{{ item["FBOXNO.LT"] }}</view>
					<view class="table-cell1" :style="getStyle(item.smzt)">{{ item["FActualQty"] }}</view>
					<view class="table-cell1" :style="getStyle(item.smzt)">{{ item["FInventoryQty"] }}</view>
					<view class="table-cell1" :style="getStyle(item.smzt)">{{ item["FENCHASENUM.LT"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["FFabricOrderNo.LT"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["FAuxPropId.FF101501.FDATAVALUE"] }}
					</view>
					<view class="table-cellph" :style="getStyle(item.smzt)">{{ item["Flot.FNumber"] }}</view>
					<view class="table-cell2" :style="getStyle(item.smzt)">{{ item["FEWorkCenterId.LT.fname"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["FEntrtyMemo"] }}</view>
					<view class="table-cell3" :style="getStyle(item.smzt)">{{ item["FBillNo"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["quantity"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["rowCount"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["quantity"]-item["rowCount"] }}
					</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["FDate"].substring(0, 10) }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["FApplicantId.fname"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["FSTOCKERID.fname"] }}</view>
				</view>
			</scroll-view>
		</view>

		<view style="height: 200px;touch-action: none;"></view>
		<view class="card-bottom" style="">
			<view style="margin: 0 auto;">
				<view
					style="display: flex;flex-direction: row;margin-top: 8px;font-size: 12px;margin-right: 15px;margin-bottom: 8px;">
					<view style="margin-right: 15px;">源单明细：{{ indexList.length }}</view>
					<view style="margin-right: 15px;">已扫描：{{ indexListLength }}</view>
					<view>剩余件数：{{ balance }}</view>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	import {
		audit,
		getInventoryList,
		save,
		submit
	} from '../../api/production_replenishment';
	import modal from '../../plugins/modal';
	import {
		audioUrls,
		playVoice
	} from '../../utils/audio';
	import {
		getAuditParam,
		getSaveParam,
		getSubmitParam
	} from '../../utils/params';
	import submitHelper from '@/utils/submitHelper'; // 确保路径正确
	import {
		executeSql
	} from '../../utils/database';
	export default {
		onShow() {
			const res = uni.getSystemInfo({
				success: (res => {
					console.log(res.windowHeight)
					if (res.windowHeight < 600) {
						this.clientHeight = 580
					} else {
						this.clientHeight = res.windowHeight - 150;
					}
					console.log(res.windowHeight)
					console.log(this.clientHeight)
					// console.log(getApp().globalData.navHeight)
				})
			});
			this.$nextTick(() => {
				this.searchValue = ''
				this.isFocus = true;
			})
		},
		computed: {
			//已扫描数量
			indexListLength() {
				console.log("执行了计算属性")
				console.log(this.indexList.filter(obj => obj.smzt === 1).length)
				return this.indexList.filter(obj => obj.smzt === 1).length
			},
			//剩余数量
			indexList2Length() {
				let arr1 = this.indexList.filter((item, index, self) => {
					return item.smzt == 0
				})
				console.log(arr1)
				return arr1.length
			},
			//正操作仓位未扫描数量
			indexList3Length() {
				return this.indexList.filter(item =>
					item["FStockLocId.FF102029.fname"] == this.Location && item['smzt'] != 1
				).length
			},
		},
		mounted() {
			// 页面加载完成后滚动到目标数据位置
			uni.$on('scrollIntoView', (target) => {
				this.$nextTick(() => {
					// 使用id属性定位
					uni.createSelectorQuery().select('#' + target).boundingClientRect().exec((rect) => {
						console.log(rect)
						uni.pageScrollTo({
							scrollTop: rect[0].top - 95,
							duration: 0
						});
					});
				});

			})
			this.$nextTick(() => {
				this.searchValue = ''
				this.isFocus = true;
			})


		},
		//监听
		watch: {
			Location(newValue, oldValue) {
				console.log(`Location changed from ${oldValue} to ${newValue}`)
				this.Location = newValue
				// 可以在这里执行相应的操作
			},
		},
		data() {
			return {
				isFocus: true,
				indexList: [],
				tableName: "bill",
				clientHeight: '',
				searchValue: '',
				scrollItem: '', // 滚动到的指定元素
				color: '',
				Location: '', //正操作仓位
				uniqueFStockLocId: [],
				balance: 0,
				isStage: false,
				stageIds: [],
				stageLists: []
			};
		},
		//获取上一页传过来的参数
		onLoad(option) {
			uni.$on('item', (data) => {
				console.log(data)
				let index = data["index"]
				if ("NewFENCHASENUM.LT" in data) {
					this.indexList[index]["FENCHASENUM.LT"] = data["NewFENCHASENUM.LT"]
				}
				if (this.indexList[index]["FStockLocId.FF102029.fname"] != data["FStockLocId.FF102029.fname"]) {

					const data1 = {
						"parameters": [{
							"FormId": "STK_Inventory",
							"FieldKeys": "fID",
							"FilterString": [{
									"Left": "",
									"FieldName": "FStockLocId.FF102029.FName",
									"Compare": "67",
									"Value": data["FStockLocId.FF102029.fname"],
									"Right": "",
									"Logic": 0
								},
								{
									"Left": "",
									"FieldName": "FBaseQty",
									"Compare": "21",
									"Value": "0",
									"Right": "",
									"Logic": 0
								}
							],
						}]
					}
					getInventoryList(JSON.stringify(data1)).then(res => {
						// let obj = data1.find(item => item['FStockLocId.FF102029.fname'] === fname);
						// if (obj) {
						// 	obj.quantity = res.length; // 更新数量属性
						// }
						this.indexList[index]["quantity"] = res.length
						console.log("修改了原仓位条数", res.length)
						this.indexList[index]['FStockLocId.FF102029.fname'] = data[
							"FStockLocId.FF102029.fname"]
						// 用于记录每个组合的计数
						let countMap = {};

						// 统计每个组合的行数
						this.indexList.forEach(obj => {
							// 获取当前对象的组合键
							let key = obj.FBillNo + '|' + obj['FStockLocId.FF102029.fname'];

							// 如果该组合已经存在于 countMap 中，则增加计数，否则初始化为 1
							if (countMap[key]) {
								countMap[key]++;
							} else {
								countMap[key] = 1;
							}
						});

						// 将计数值添加到每个对象中
						this.indexList.forEach(obj => {
							let key = obj.FBillNo + '|' + obj['FStockLocId.FF102029.fname'];
							obj.rowCount = countMap[key];
						});
					})


				}
				this.indexList[index]['FInventoryQty'] = data["FInventoryQty"]
				this.indexList[index]['FActualQty'] = data["FActualQty"]
				this.indexList[index]['Flot.FNumber'] = data["Flot.FNumber"]
				this.indexList[index]['FAuxPropId.FF101501.FDATAVALUE'] = data["FAuxPropId.FF101501.FDATAVALUE"]
				this.indexList[index]['smzt'] = data["smzt"]
				console.log(this.indexList[index])
				this.$nextTick(() => {
					this.searchValue = ''
					this.isFocus = true
				})
			})
			uni.$on('search', (data) => {
				console.log(data)
				this.indexList = data
				this.indexList.forEach(item => {
					// item.smzt = 0; // 增加属性 smzt，并设置初始值为0
					this.$set(item, 'smzt', 0);
				})
				// 用于记录每个组合的计数
				let countMap = {};
				// 统计每个组合的行数
				this.indexList.forEach(obj => {
					// 获取当前对象的组合键
					let key = obj.FBillNo + '|' + obj['FStockLocId.FF102029.fname'];

					// 如果该组合已经存在于 countMap 中，则增加计数，否则初始化为 1
					if (countMap[key]) {
						countMap[key]++;
					} else {
						countMap[key] = 1;
					}
				});

				// 将计数值添加到每个对象中
				this.indexList.forEach(obj => {
					let key = obj.FBillNo + '|' + obj['FStockLocId.FF102029.fname'];
					// obj.rowCount = countMap[key];
					this.$set(obj, 'rowCount', countMap[key])
				});
				// 1. 提取不同的仓位
				this.uniqueFStockLocId = [...new Set(this.indexList.map(obj => obj[
					'FStockLocId.FF102029.fname']))];
				console.log(this.uniqueFStockLocId)
				// this.processQuantity(this.uniqueFStockLocId[0])
				this.updateIndexList(this.indexList)
				this.$nextTick(() => {
					this.searchValue = ''
					this.isFocus = true;
				})
				console.log(this.stageLists)
			})
			uni.$on('summary', (data) => {
				console.log(data)
				this.indexList = data
				this.searchValue = ''
				this.isFocus = true;
			})
			uni.$on('stage', (data) => {
				console.log(data)
				// 处理每个对象
				this.stageLists = data.map(item => {
					// 解析 data 字段
					const parsedData = JSON.parse(item.data);

					// 返回处理后的对象
					return {
						...item,
						data: parsedData
					};
				});
				this.stageIds = data.map(item => item.id)
				// this.stageLists = data.map(item => item.data)
				console.log(this.stageIds)
				console.log(this.stageLists)
				// 解析字符串为数组并合并
				const combinedArray = this.stageLists
					.map(item => item.data) // 解析每个字符串
					.flat(); // 合并所有数组

				console.log(combinedArray);
				this.indexList = combinedArray
				// this.indexList = data
				this.searchValue = ''
				this.isFocus = true;
				this.isStage = true
			})

			this.$nextTick(() => {
				console.log('dddd')
				this.searchValue = ''
				this.isFocus = true;
			})
			// this.$forceUpdate()

		},
		methods: {
			async updateIndexList(data1) {
				try {
					// 存储所有的异步操作 promise
					let promises = [];

					// 遍历 uniqueFStockLocId 数组
					for (let fname of this.uniqueFStockLocId) {
						const data = {
							"parameters": [{
								"FormId": "STK_Inventory",
								"FieldKeys": "fID",
								"FilterString": [{
										"Left": "",
										"FieldName": "FStockLocId.FF102029.FName",
										"Compare": "67",
										"Value": fname,
										"Right": "",
										"Logic": 0
									},
									{
										"Left": "",
										"FieldName": "FBaseQty",
										"Compare": "21",
										"Value": "0",
										"Right": "",
										"Logic": 0
									}
								],
							}]
						};

						// 发起异步请求，并将 promise 存储在数组中
						let promise = getInventoryList(JSON.stringify(data)).then(res => {
							// let obj = data1.find(item => item['FStockLocId.FF102029.fname'] === fname);
							// if (obj) {
							// 	// obj.quantity = res.length; // 更新数量属性
							// 	this.$set(obj, 'quantity', res.length)
							// }
							let objs = data1.filter(item => item['FStockLocId.FF102029.fname'] === fname);

							objs.forEach(obj => {
								this.$set(obj, 'quantity', res.length);
							});

						});

						promises.push(promise);
					}

					// 等待所有异步操作完成
					await Promise.all(promises)
					console.log(data1)
					this.indexList = data1

					console.log('indexList updated:', this.indexList);
				} catch (error) {
					console.error('Error updating indexList:', error);
				}
			},

			scrollToItem(itemId) {
				// 设置滚动到的指定元素的 ID
				this.scrollItem = itemId;
				console.log(this.scrollItem)
			},
			//取消
			reset() {
				const self = this
				modal.confirm("是否重置?").then(res => {
					if (res) {
						self.indexList = []
						self.balance = 0
						self.searchValue = ""
						this.isFocus = true
						playVoice(audioUrls.successVoiceUrl)
					} else {
						// 用户点击取消，不执行任何操作
					}
				})
			},
			edit(item, index) {
				uni.navigateTo({
					url: '/pages/production-replenishment/show?item=' + encodeURIComponent(JSON.stringify(
							item)) +
						'&&index=' + encodeURIComponent(JSON.stringify(index))
				});
			},
			// scrollToItem(id) {
			// 	// 使用id属性定位
			// 	this.$nextTick(() => {
			// 		uni.$emit('scrollIntoView', id);
			// 	})
			// },
			showDetail(index) {
				console.log(index);
				let item = this.indexList[index.name]
				console.log(item)
				uni.navigateTo({
					url: '/pages/automatedwarehouse/listshow?Info=' + encodeURIComponent(JSON.stringify(
						item))
				});
			},
			focusPoint() {
				this.isFocus = false;
				this.$nextTick(() => {
					this.isFocus = true;
				});
			},
			clear() {
				this.focusPoint()
			},
			//跳转到查询页面
			navigateToSearch() {
				if (this.indexList.length > 0) {
					// this.isRangeSelected = false; // 显示错误提示
					playVoice(audioUrls.failVoiceUrl)
					uni.showToast({
						title: '源单已选择',
						duration: 2000,
						icon: "error"
					});
					return;
				}
				uni.navigateTo({
					url: '/pages/production-replenishment/search', //这是你的当前页面地址
				});

			},
			navigateToSummary() {
				uni.navigateTo({
					url: '/pages/production-replenishment/summary?Info=' + encodeURIComponent(JSON
						.stringify(this.indexList)) + '&&stageInfo=' + encodeURIComponent(JSON
						.stringify(this.stageLists)), //这是你的当前页面地址
				});

			},
			navigateToStage() {
				uni.navigateTo({
					url: '/pages/production-replenishment/stage?Info=' + encodeURIComponent(JSON
						.stringify(this.indexList)), //这是你的当前页面地址
				});

			},
			searchValueIsEmpty(data) {
				console.log(data)
				if (data == "" || data == undefined) {
					return true
				} else {
					return false
				}

			},
			checkBarcodeInArray(barcode, arrayOfObjects, propertyName) {
				if (arrayOfObjects.findIndex(item => item[propertyName] === barcode) < 0) { //不存在
					return true
				}
				return false

			},
			areAllDetailsScanned(nowindex) {
				if (this.indexList.filter(item =>
						item["FBillNo"] == this.indexList[nowindex].FBillNo && item[
							'smzt'] == 0
					).length == 0) {
					return true
				}
				return false

			},
			showToast() {
				uni.showToast({
					title: '请扫描条码',
					icon: 'none',
					duration: 3000
				})
			},
			handlePositionScanCompletion() { //根据仓位扫描的完成情况来处理不同的逻辑
				if (this.indexList.filter(item =>
						item["FStockLocId.FF102029.fname"] == this.Location && item[
							'smzt'] != 1
					).length == 0) { //该仓位扫描完
					playVoice(audioUrls.allSuccessVoiceUrl)

					uni.showToast({
						title: '该仓位扫描完成',
						icon: 'none',
						duration: 3000
					})

				} else { //如果改仓位未扫描完，提示音
					playVoice(audioUrls.successVoiceUrl)
					uni.showToast({
						title: '扫描成功',
						icon: 'none',
						duration: 3000
					})
				}
			},
			handleError(error) {
				playVoice(audioUrls.failVoiceUrl)
				console.error('操作失败:', error);
				modal.confirm(error.message || '操作失败').then(res => {
					if (res) {

					} else {
						// 用户点击取消，不执行任何操作
					}
				})
				// uni.showToast({
				// 	title: error.message || '操作失败',
				// 	duration: 3000,
				// 	icon: "none"
				// });

			},
			async handleSubmit(FID) {
				try {
					await submitHelper.submit(FID, this.indexList);
					this.indexList = this.indexList.filter(item => item.FID !== FID);
					console.log(this.indexList)
					if (this.isStage == true) {
						// 处理每个对象
						this.stageLists.forEach(item => {
							// 过滤掉 FID 匹配的对象
							item.data = item.data.filter(obj => obj.FID !== FID);

							// 检查 data 数组是否为空
							if (item.data.length === 0) {
								console.log("data 数组为空"); //删除暂存
								this.deleteStages(item.id)
							} else {
								console.log("data 数组不为空");
							}
						})
						console.log(this.stageLists)
					}

				} catch (error) {
					this.handleError(error)
				}
			},
			async deleteStages(id) {
				let condition = `id = (${id})`
				let sql = `delete from ${this.tableName} where ${condition}`
				executeSql(sql).then(result => {
						console.log('结果:', result);
						// this.handleDeleteSuccess()
					})
					.catch(error => {
						console.error('捕获错误:', error); // 输出: 捕获错误: 失败的结果
						// this.handleDeleteFail(error)
					})
			},
			// submit(FID) {
			// 	const savaParam = getSaveParam(FID, this.indexList)
			// 	console.log(savaParam)
			// 	let vm = this
			// 	modal.loading("提交中，请耐心等待...")
			// 	save(JSON.stringify(savaParam)).then( //保存
			// 		res => {
			// 			console.log(res)
			// 			if (res.Result.ResponseStatus.IsSuccess == true) {
			// 				const FID = res.Result.NeedReturnData[0]["FID"]
			// 				console.log(FID)
			// 				// const submitParam = vm.getSubmitParam(FID)
			// 				const submitParam = getSubmitParam(FID)
			// 				console.log(submitParam)

			// 				submit(JSON.stringify(submitParam)).then( //提交
			// 					res => {
			// 						console.log(res)

			// 						if (res.Result.ResponseStatus.IsSuccess == true) {
			// 							const Id = res.Result.ResponseStatus.SuccessEntitys[0]["Id"]
			// 							console.log(Id)
			// 							// const auditParam = vm.getAuditParam(Id)
			// 							const auditParam = getAuditParam(Id)
			// 							audit(JSON.stringify(auditParam)).then( //审核
			// 								res => {
			// 									console.log(res)
			// 									modal.closeLoading()
			// 									if (res.Result.ResponseStatus.IsSuccess == true) {
			// 										vm.indexList = vm.indexList.filter(item => item.FID !==
			// 											FID)
			// 										vm.Location = ''
			// 										vm.$nextTick(() => {
			// 											vm.searchValue = ''
			// 											vm.isFocus = true
			// 										})
			// 										uni.showModal({
			// 											title: "提示",
			// 											content: "提交成功",
			// 											showCancel: true,
			// 											success: function(res) {
			// 												if (res.confirm) {
			// 													// vm.submit(FID)											
			// 												} else {
			// 													// 执行取消后的操作
			// 												}
			// 											}
			// 										})
			// 										playVoice(audioUrls.successVoiceUrl)
			// 									} else {
			// 										uni.showToast({
			// 											title: res.Result.ResponseStatus.Errors[0]
			// 												.Message,
			// 											duration: 2000,
			// 											icon: "error"
			// 										})

			// 									}
			// 								}
			// 							).catch(error => {
			// 								// 处理失败的情况
			// 								modal.closeLoading()
			// 								console.error('audit failed:', error);
			// 								uni.showToast({
			// 									title: res.Result.ResponseStatus.Errors[0].Message,
			// 									duration: 3000,
			// 									icon: "none"
			// 								})
			// 							})
			// 						} else {
			// 							modal.closeLoading()
			// 							uni.showToast({
			// 								title: res.Result.ResponseStatus.Errors[0].Message,
			// 								duration: 3000,
			// 								icon: "error"
			// 							})

			// 						}
			// 					}
			// 				).catch(error => {
			// 					modal.closeLoading()
			// 					uni.showModal({
			// 						title: "提示",
			// 						content: error,
			// 						showCancel: true,
			// 						success: function(res) {
			// 							if (res.confirm) {
			// 								// vm.submit(FID)											
			// 							} else {
			// 								// 执行取消后的操作
			// 							}
			// 						}
			// 					})
			// 					// 处理失败的情况
			// 					console.error('Submit failed:', error);
			// 				})


			// 			} else {
			// 				modal.closeLoading()
			// 				uni.showToast({
			// 					title: res.Result.ResponseStatus.Errors[0].Message,
			// 					duration: 3000,
			// 					icon: "error"
			// 				})

			// 			}
			// 		}
			// 	).catch(error => {
			// 		// 处理失败的情况
			// 		console.error('Sava failed:', error);
			// 		modal.closeLoading()
			// 		uni.showModal({
			// 			title: "提示",
			// 			content: error,
			// 			showCancel: true,
			// 			success: function(res) {
			// 				if (res.confirm) {
			// 					// vm.submit(FID)											
			// 				} else {
			// 					// 执行取消后的操作
			// 				}
			// 			}
			// 		})

			// 	})
			// },
			showModalAndHandleSubmit(nowindex) {
				let vm = this
				console.log(nowindex)
				let bBillNo = this.indexList[nowindex]["FBillNo"]
				let FID = this.indexList[nowindex]["FID"]
				this.$nextTick(() => {
					this.searchValue = ''
					this.isFocus = true;
				})
				playVoice(audioUrls.allSuccessVoiceUrl)
				uni.showModal({
					title: "提示",
					content: "单号（" + bBillNo + "）已扫描完毕，是否提交",
					showCancel: true,
					success: function(res) {
						if (res.confirm) {
							// this.submit(FID)
							this.handleSubmit(FID)
						} else {

							// 执行取消后的操作
						}
					}.bind(this)
				})
			},
			handleScanSuccess(nowindex) {
				this.Location = this.indexList[nowindex]["FStockLocId.FF102029.fname"] //切换仓位
				this.indexList[nowindex].smzt = 1 //修改数据状态
				console.log(this.indexList.filter(obj => obj.smzt === 1).length)
				//判断仓位是否全部扫完
				let UnscannedNumber = this.indexList.filter(item =>
					item["FStockLocId.FF102029.fname"] == this.Location && item['smzt'] != 1
				).length //该仓位未扫描数量
				if (UnscannedNumber == 0) {
					playVoice(audioUrls.success2VoiceUrl)
				}
				if (this.areAllDetailsScanned(nowindex)) { //校验单号是否全扫完
					// playVoice(audioUrls.allSuccessVoiceUrl)
					this.showModalAndHandleSubmit(nowindex)
				} else { //单号未全扫完
					this.handlePositionScanCompletion()
					this.$nextTick(() => {
						this.searchValue = ''
						this.isFocus = true;
						this.scrollToItem("scrollItem-" + nowindex)
					})
				}

			},
			scan() {
				let vm = this
				//校验是否输入条码
				if (this.searchValueIsEmpty(this.searchValue)) {
					playVoice(audioUrls.failVoiceUrl)
					this.showToast()
					this.focusPoint()
					return
				}
				// 校验条码是否存在
				if (this.checkBarcodeInArray(this.searchValue, this.indexList, "FENCHASENUM.LT")) {
					uni.showModal({
						title: '提示',
						content: "条码：" + vm.searchValue + '不存在',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								this.focusPoint()
								vm.searchValue = ''
								return
							} else {
								// 执行取消后的操作
							}
						}.bind(this)
					})
					playVoice(audioUrls.failVoiceUrl)
					return
				}
				//校验条码已扫描
				if (this.indexList.findIndex(item => item["FENCHASENUM.LT"] === this.searchValue && item.smzt ==
						1) >= 0) {
					uni.showModal({
						// title: '提示',
						content: "条码：" + vm.searchValue + '已扫描',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								vm.focusPoint()
								vm.searchValue = ''
								return
							} else {
								// 执行取消后的操作
							}
						}
					})
					playVoice(audioUrls.failVoiceUrl)
					return
				}
				//条码存在未扫描
				let nowlocation = null; //该条码的仓位
				let nowindex = null; //该条码的索引
				for (let i = 0; i < this.indexList.length; i++) { //获取查询装箱单号对应仓位，并切换当前仓位
					if (this.indexList[i]["FENCHASENUM.LT"] === this.searchValue) {
						nowlocation = this.indexList[i]["FStockLocId.FF102029.fname"] //当前仓位
						nowindex = i //当前索引
						this.balance = this.indexList[i]["quantity"] - this.indexList[i]["rowCount"]
						break;
					}
				}
				//不是首次扫描
				if (this.indexListLength != 0) { //已有操作
					let UnscannedNumber = this.indexList.filter(item =>
						item["FStockLocId.FF102029.fname"] == this.Location && item['smzt'] != 1
					).length //计算上次操作的仓位未扫描数
					if (nowlocation != this.Location && UnscannedNumber != 0) { //仓位不一致并且上个仓位未全扫描
						playVoice(audioUrls.successVoiceUrl)
						uni.showModal({
							title: "提示",
							content: "是否切换仓位",
							showCancel: true,
							success: function(res) {
								if (res.confirm) {
									vm.handleScanSuccess(nowindex)
								} else {
									// 执行取消后的操作
									vm.$nextTick(() => {
										vm.searchValue = ''
										vm.isFocus = true;
									})
								}
							}
						})
						return
					} else { //仓位一致或原仓位已扫完，正常扫描，无切换
						this.handleScanSuccess(nowindex)
					}
				} else { //首次扫描
					this.handleScanSuccess(nowindex)
				}
			},
			getHeightStyle() {
				return 'height:' + this.listHeight + 'px';
			},
			getStyle(smzt) {
				return smzt ? 'background-color: Navy;color:white' : '';
				// return 'scrollItem-' + index === this.scrollItem ? 'background-color: blue;color:white' : '';
			},
		}
	};
</script>


<style lang="scss">
	.button-group {
		display: flex;
		justify-content: flex-start;
		/* 主轴上左对齐 */
		align-items: center;
		/* 垂直居中对齐 */
	}

	.button-group button {
		white-space: nowrap;
		/* 禁止换行 */
		// margin-right: 10px;
	}

	.button-item {
		flex: 1;
		text-align: center;
		padding: 10px;
		font-size: 16px;
		background-color: #eee;
	}

	/* 容器样式 */
	.table-container {
		width: 100%;
		// overflow: hidden;
		/* 添加滚动条 */
	}

	/* 表头样式 */
	.table-header {
		// background-color: #f0f0f0;
		font-weight: bold;
		display: flex;

	}

	/* 表行样式 */
	.table-row {
		display: flex;
		flex-direction: row;
		/* 水平布局 */
		// border-top: 1px solid #ccc;
	}

	/* 表内容样式 */
	.table-content {
		width: 100%;
		overflow: auto;
	}

	/* 单元格样式 */
	.table-cell1 {
		min-width: 85px;
		/* 设置最小宽度 */
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 5px;
		border: 0.5px solid #ccc;
		// text-align: center;
	}

	/* 单元格样式 */
	.table-cell2 {
		min-width: 90px;
		/* 设置最小宽度 */
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 5px;
		border: 0.5px solid #ccc;
		// text-align: center;
	}

	/* 单元格样式 */
	.table-cell3 {
		min-width: 100px;
		/* 设置最小宽度 */
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 5px;
		border: 0.5px solid #ccc;
		// text-align: center;
	}

	/* 单元格样式 */
	.table-cell4 {
		min-width: 85px;
		/* 设置最小宽度 */
		flex: 1;
		padding: 8px;
		border: 0.5px solid #ccc;
		text-align: center;
	}

	/* 单元格样式 */
	.table-cell {
		min-width: 80px;
		padding: 5px;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 0.5px solid #ccc;
		// text-align: center;
	}

	/* 单元格样式 */
	.table-cellph {
		min-width: 310px;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 0.5px solid #ccc;

	}

	/* 单元格样式 */
	.table-cellwl {
		min-width: 150px;
		/* 设置最小宽度 */
		display: flex;
		justify-content: center;
		align-items: center;
		border: 0.5px solid #ccc;
		// text-align: center;
	}

	/* 最后一个单元格去掉右边框 */
	.table-cell:last-child {
		// border-right: none;
	}


	.example {
		padding: 15px;
		background-color: #fff;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.sticky-box {
		/* #ifndef APP-PLUS-NVUE */
		// display: flex;
		position: -webkit-sticky;
		/* #endif */
		position: sticky;
		top: var(--window-top);
		z-index: 99;
		flex-direction: row;
		margin: 0px;
		// padding: 15px 0 15px 0;
		background-color: #F4F5F6;
		// border-bottom-style: solid;
		// border-bottom-color: #E2E2E2;
	}

	.button {
		border-color: #e5e5e5;
		border-style: solid;
		border-width: 1px;
		padding: 4px 8px;
		border-radius: 4px;
	}

	.card-bottom {
		touch-action: none;

		// height: 60px;
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 999;
		background-color: white;
		border-top: 1px;
		display: flex;
		flex-direction: column;
	}

	.text {
		font-size: 12px;
		color: #666;
		margin-top: 5px;
	}

	.button {
		margin-bottom: 10px;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	// .button-group {
	// 	margin-top: 15px;
	// 	display: flex;
	// 	justify-content: space-around;
	// }

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}
</style>
<style lang="scss">
	.u-page {
		padding: 0;
	}

	.u-demo-block__title {
		padding: 10px 0 2px 15px;
	}

	.swipe-action {
		&__content {
			padding: 25rpx 0;
			display: flex;
			flex-direction: column; //设置布局方向为竖直

			&__text {
				font-size: 15px;
				color: $u-main-color;
				padding-left: 30rpx;
			}
		}
	}

	.u-swipe-action-item {
		touch-action: none;
	}

	.red {
		color: red;
	}

	.label-picker-container {
		display: flex;
		align-items: center;
		/* 垂直居中对齐 */
		font-size: 12px;
		/* 设置标签的字体大小 */
	}
</style>