<template>
	<view>
		<view class="sticky-box">
			<view class="button-group">
				<button type="default" @click="reset">取消</button>
				<button type="default" @click="navigateToCreate">新增</button>
				<button type="default" @click="navigateToSummary">统计</button>
				<button type="default" @click="navigateToSearch">查询</button>
				<button type="default" @click="navigateToStage">暂存</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">

				<view class="table-header">
					<view class="table-cell">操作</view>
					<view class="table-cell">扫描状态</view>
					<view class="table-cellwl">仓库</view>
					<view class="table-cell">仓位</view>
					<view class="table-cellwl">物料编码</view>
					<view class="table-cell1">装箱单号</view>
					<view class="table-cell">数量</view>
				</view>
				<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" :disabled="item['FAccountNum'] !== 0" size="mini"
							@click="edit(item,index)">编辑</button>
					</view>
					<view class="table-cell">{{ item.smzt? '已扫描' : '未扫描' }}</view>
					<view class="table-cellwl">{{ item["FStockId.FName"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ 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["FEnchaseNo"] }}</view>
					<view class="table-cell" :style="getStyle(item.smzt)">{{ item["FCheckNum"] }}</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>仓位：{{ Location }}</view>
				</view>
			</view>
		</view>
	</view>
</template>


<script>
	import {
		getInfoByBarcode,
		getStockInfo,
		getInventoryList	} from '../../api/production_replenishment';
	import modal from '../../plugins/modal';
	// import {
	// 	audioUrls,
	// 	playVoice
	// } from '../../utils/audio';
	import {
		playVoice,
		audioUrls,
		playSequentially
	} from '../../utils/audio2';
	import submitHelper from '@/utils/checkSubmitHelper.js'; // 确保路径正确
	import {
		executeSql
	} from '../../utils/database';
	import {
		createInventoryQueryRequest
	} from '@/utils/newparams.js';
	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
			},
			showInventoryQty() {
				return this.formId !== 'SP_PickMtrl' && uni.getStorageSync("fbillType") !== "B";
			},
			showWorkCenter() {
				return this.formId !== 'PUR_MRB' && this.formId !== 'STK_MisDelivery' && this.formId !==
					'STK_OEMInStockRETURN' && this.formId !== 'SAL_OUTSTOCK';

			},
			showRemark() {
				return this.formId !== 'PUR_MRB';
			},
			showApplicant() { //显示申请人
				return this.formId == 'LT_PRD_PMCWorkBench';
			},
			showMaterialReceiver() { //显示领料人
				return this.formId == 'STK_MisDelivery' || this.formId == 'SP_PickMtrl';
			}
		},
		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 {
				formId: '',
				fbillType: '',
				isFocus: true,
				indexList: [],
				clientHeight: '',
				searchValue: '',
				scrollItem: '', // 滚动到的指定元素
				color: '',
				Location: '', //正操作仓位
				uniqueFStockLocId: [],
				balance: 0,
				isStage: false,
				stageIds: [],
				stageLists: [],
				tableName: "common_bill",

			};
		},
		//获取上一页传过来的参数
		onLoad(option) {
			this.formId = uni.getStorageSync("formId")
			this.fbillType = uni.getStorageSync("fbillType")
			// this.fbillType = option.FBillType;
			// console.log(this.formId)
			// console.log(this.fbillType)
			uni.setNavigationBarTitle({
				title: uni.getStorageSync("moudleName")
			});
			uni.$on('item', (data) => {
				console.log(data)
				this.indexList.forEach(item => {
					if (item.FEnchaseNo === data.FEnchaseNo) {
						item.FCheckNum = data.FCheckNum; // 将FCheckNum赋值为目标对象的FCheckNum
					}
				});
				console.log(this.indexList)

				this.$nextTick(() => {
					this.searchValue = ''
					this.isFocus = true
				})
			})
			uni.$on('search', (data) => {
				console.log(data)
				if (data[0]["FEntity.FEntryID"] == 0) {
					this.indexList = []
				} else {
					this.indexList = data
				}
				this.indexList.forEach(item => {
					// item.smzt = 0; // 增加属性 smzt，并设置初始值为0
					this.$set(item, 'smzt', 0);
					this.$set(item, 'FIsCheck', "B");
					this.$set(item, 'FCheckTag', "C"); //默认盘亏
				})
				console.log("初始化后列表", data)
				this.$nextTick(() => {
					this.searchValue = ''
					this.isFocus = true;
				})
			})
			uni.$on('summary', (data) => {
				console.log(data)
				this.indexList = data
				this.searchValue = ''
				if (this.indexList.length == 0) {
					this.Location = ""
				}
				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.searchValue = ''
				this.isFocus = true;
				this.isStage = true
			})

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

		},
		methods: {
			getActualWorkQuantity(item) {
				if (this.formId === 'LT_PRD_PMCWorkBench' || (this.formId === 'SP_PickMtrl' && uni.getStorageSync(
						"fbillType") !== "B")) {
					return item["FActualQty"];
				} else if (this.formId === 'SP_PickMtrl' && uni.getStorageSync("fbillType") == "B") {
					return item["FSumActualQty"];
				} else if (this.formId === 'STK_MisDelivery') {
					return item["FQty"];
				} else if (this.formId === 'PUR_MRB') {
					return item["FRMREALQTY"];
				} else if (this.formId === 'SAL_OUTSTOCK') {
					return item["FRealQty"];
				} else {
					return item["FQty"];
				}
			},
			getInventoryQty(item) {
				switch (this.formId) {
					case 'SAL_OUTSTOCK':
						return item["FInventoryQty.LT"];
					default:
						return item["FInventoryQty"];
				}
			},
			getFabricOrderNo(item) {
				switch (this.formId) {
					case 'PUR_MRB':
					case 'LT_PRD_PMCWorkBench':
					case 'STK_OEMInStockRETURN':
						return item["FFabricOrderNo"];
					case 'SAL_OUTSTOCK':
						return item["FFABRICORDERNO_LT"];
					default:
						return item["FFabricOrderNo.LT"];
				}
			},
			getMaterial(item) {
				if (this.formId === 'SP_PickMtrl' && uni.getStorageSync("fbillType") == "B") {
					return item["FSumMaterialId.fnumber"];

				} else {
					return item["FMaterialId.fnumber"];
				}
			},
			getFENCHASENUM(item) {
				if (this.formId === 'SP_PickMtrl' && uni.getStorageSync("fbillType") == "B") {
					return item["FSumEnchaseNum.LT"];

				} else {
					return item["FENCHASENUM.LT"];
				}
			},
			getFAuxPropId(item) {
				if (this.formId === 'SP_PickMtrl' && uni.getStorageSync("fbillType") == "B") {
					return item["FSumAuxPropId.FF101501.FNumber"];

				} else {
					return item["FAuxPropId.FF101501.FDATAVALUE"];
				}
			},
			getFlot(item) {
				if (this.formId === 'SP_PickMtrl' && uni.getStorageSync("fbillType") == "B") {
					return item["FSumLot.FNumber"];

				} else {
					return item["Flot.FNumber"];
				}
			},
			getPosition(item) {
				if (this.formId === 'SP_PickMtrl' && uni.getStorageSync("fbillType") == "B") {
					return item["FSumStockLocId.FF102029.fname"];

				} else {
					return item["FStockLocId.FF102029.fname"];
				}
			},
			getBoxNo(item) {
				if (this.formId === 'STK_OEMInStockRETURN') {
					return item["FBoxNo"];
				} else if (this.formId === 'SAL_OUTSTOCK') {
					return item["FBoxNumber"];
				} else if (this.formId === 'SP_PickMtrl' && uni.getStorageSync("fbillType") == "B") {
					return item["FSumBoxNo.LT"];
				} else {
					return item["FBOXNO.LT"];
				}
			},
			getWorkCenterName(item) {
				switch (this.formId) {
					case 'LT_PRD_PMCWorkBench':
						return item["FWorkCenterId.LT.fname"];
					case 'STK_MisDelivery':
					case 'SP_PickMtrl':
						return item["FWorkCenterId.fname"];
					default:
						return '';
				}
			},
			getApplicantName(item) {
				switch (this.formId) {
					case 'LT_PRD_PMCWorkBench':
						return item["FApplicantId.fname"];
					case 'STK_MisDelivery':
						return item["FPickingPeople.LT.fname"];
					case 'SP_PickMtrl':
						return item["FPickerId.fname"];
					default:
						return ''; // 默认返回值，可以根据需求调整
				}
			},
			getStockClerk(item) {
				switch (this.formId) {
					case 'SAL_OUTSTOCK':
						return item["FStockerEId_LT.FName"];
					default:
						return item["FSTOCKERID.fname"]; // 默认返回值，可以根据需求调整
				}
			},
			getRemark(item) {
				switch (this.formId) {
					case 'STK_OEMInStockRETURN':
						return item["FNoteEntry"];
						// case 'STK_MisDelivery':
						// 	return item["FPickingPeople.LT.fname"];
						// case 'SP_PickMtrl':
						// 	return item["FPickerId.fname"];
					default:
						return item["FEntrtyMemo"]; // 默认返回值，可以根据需求调整
				}
			},
			async updateIndexList(data1) {
				try {
					// 存储所有的异步操作 promise
					let promises = [];
					// 遍历 uniqueFStockLocId 数组
					for (let fname of this.uniqueFStockLocId) {
						const requestData = createInventoryQueryRequest(fname)

						// 发起异步请求，并将 promise 存储在数组中
						let promise = getInventoryList(JSON.stringify(requestData)).then(res => {
							let objs = data1.filter(item => item['FStockLocId.FF102029.fname'] === fname ||
								item['FSumStockLocId.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.searchValue = ""
						self.balance = 0
						this.isFocus = true
						playVoice(audioUrls.warningSuccessUrl)
					} else {
						// 用户点击取消，不执行任何操作
					}
				})
			},
			edit(item, index) {
				uni.navigateTo({
					url: '/pages/check/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) {
					playVoice(audioUrls.failVoiceUrl)
					uni.showToast({
						title: '源单已选择',
						duration: 2000,
						icon: "error"
					});
					return;
				}
				uni.navigateTo({
					// url: '/pages/production-replenishment/search', //这是你的当前页面地址
					url: `/pages/check/search?FormId=${this.formId}&FBillType=${this.fbillType}`
				});

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

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

			},
			navigateToCreate() {
				if (this.indexList.length > 0) {
					playVoice(audioUrls.failVoiceUrl)
					uni.showToast({
						title: '源单已选择',
						duration: 2000,
						icon: "error"
					});
					return;
				}
				if (uni.getStorageSync("moudleName") == "仓位盘点") {
					uni.navigateTo({
						url: '/pages/check/create', //这是你的当前页面地址
					});
				} else {
					uni.navigateTo({
						url: '/pages/check/create2', //这是你的当前页面地址
					});
				}

			},
			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) {
				const FormId = uni.getStorageSync('formId')
				const fbillType = uni.getStorageSync('fbillType')
				try {
					await submitHelper.submit(FormId, FID, this.indexList, fbillType);
					this.indexList = this.indexList.filter(item => item.FID !== FID);
					console.log(this.indexList)
					this.Location = ''
					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)
					}
					this.balance = 0
				} 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)
					})
			},
			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, FStockLocIdkey) {
				this.Location = this.indexList[nowindex][FStockLocIdkey]
				this.indexList[nowindex].smzt = 1 //修改数据状态
				this.indexList[nowindex].FCheckNum = this.indexList[nowindex].FAccountNum //修改数据状态
				if (this.indexList[nowindex].FCheckTag == "C") {
					this.indexList[nowindex].FCheckTag = "A" //修改数据状态
				}
				console.log(this.indexList.filter(obj => obj.smzt === 1).length)
				this.$forceUpdate()
				const audioUrlsArr = [];
				// console.log(this.getActualWorkQuantity(this.indexList[nowindex]))
				// //是否全发
				// if (this.getActualWorkQuantity(this.indexList[nowindex]) == this.indexList[nowindex][
				// 		"FInventoryQty"
				// 	]) { //全发播放声音
				// 	console.log("播放声音")
				// 	audioUrlsArr.push(audioUrls.successVoiceUrl);
				// } else { //不全发播放声音
				// 	audioUrlsArr.push(audioUrls.success2VoiceUrl);
				// }
				audioUrlsArr.push(audioUrls.success2VoiceUrl);
				// playSequentially(audioUrlsArr);
				if (this.indexList.filter(item =>
						item[FStockLocIdkey] == this.Location && item[
							'smzt'] != 1
					).length == 0) { //该仓位扫描完
					// playVoice(audioUrls.allSuccessVoiceUrl)
					audioUrlsArr.push(audioUrls.storeSuccessUrl);
				}
				if (this.areAllDetailsScanned(nowindex)) { //校验单号是否全扫完
					audioUrlsArr.push(audioUrls.allSuccessVoiceUrl)
					// playVoice(audioUrls.allSuccessVoiceUrl)
					this.showModalAndHandleSubmit(nowindex)
				} else { //单号未全扫完
					// this.handlePositionScanCompletion()
					this.$nextTick(() => {
						this.searchValue = ''
						this.isFocus = true;
						this.scrollToItem("scrollItem-" + nowindex)
					})
				}
				playSequentially(audioUrlsArr);

			},
			scan() {
				if (this.indexList.length === 0) {
					modal.msgError("请先提取盘点单")
					playVoice(audioUrls.failVoiceUrl)
					this.searchValue = ''
					this.focusPoint()
					return;
				}
				let vm = this
				//校验是否输入条码
				if (this.searchValueIsEmpty(this.searchValue)) {
					playVoice(audioUrls.failVoiceUrl)
					this.showToast()
					this.focusPoint()
					return
				}
				let FENCHASENUMkey = "FEnchaseNo"; // 默认字段名
				let FStockLocIdkey = "FStockLocId.FF102029.fname"; // 默认字段名
				// 校验条码是否存在
				console.log(this.searchValue)
				if (this.checkBarcodeInArray(this.searchValue, this.indexList, FENCHASENUMkey)) { //不存在
					playVoice(audioUrls.failVoiceUrl)
					console.log(this.searchValue)
					let searchValue = this.searchValue
					uni.showModal({
						title: "提示",
						content: "装箱单号不存在，是否新增？",
						showCancel: true,
						success: function(res) {
							if (res.confirm) {
								this.getNewItem(searchValue)
							} else {}
						}.bind(this)
					})

					// this.$nextTick(() => {
					// 	console.log("sdafsfsfsdf")
					// 	this.searchValue = ''
					// 	this.isFocus = true
					// })
					// 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][FENCHASENUMkey] === this.searchValue) {
						nowlocation = this.indexList[i][FStockLocIdkey] //当前仓位
						nowindex = i //当前索引
						this.balance = this.indexList[i]["quantity"] - this.indexList[i]["rowCount"]
						break;
					}
				}
				//不是首次扫描
				if (this.indexListLength != 0) { //已有操作，计算上次操作的仓位未扫描数
					let UnscannedNumber = this.indexList.filter(item =>
						item[FStockLocIdkey] == this.Location && item['smzt'] != 1
					).length
					if (nowlocation != this.Location && UnscannedNumber != 0) { //仓位不一致
						playVoice(audioUrls.warningSuccessUrl)
						uni.showModal({
							title: "提示",
							content: "是否切换仓位",
							showCancel: true,
							success: function(res) {
								if (res.confirm) {
									vm.handleScanSuccess(nowindex, FStockLocIdkey)
								} else {
									// 执行取消后的操作
									vm.$nextTick(() => {
										vm.searchValue = ''
										vm.isFocus = true;
									})
								}
							}
						})
						return
					} else { //仓位一致或原仓位已扫完，正常扫描，无切换
						this.handleScanSuccess(nowindex, FStockLocIdkey)

					}
				} else { //首次扫描
					this.handleScanSuccess(nowindex, FStockLocIdkey)
				}
			},
			async getNewItem(searchValue) {
				// this.$modal.loading('新增行，请耐心等待1...');
				const data = {
					"parameters": [{
						"FormId": "LT_BD_MtlLotCodeMap",
						"FieldKeys": "FMaterialId,FMaterialId.fnumber,FLot.FNumber,FLot,FEntity_FSEQ,FBoxNo_LT",
						"FilterString": [{
							"Left": "",
							"FieldName": "FNumber",
							"Compare": "67",
							// "Value": "T23091000852",
							"Value": searchValue,
							"Right": "",
							"Logic": 0
						}],
						"OrderString": "FEntity_FSEQ DESC",
					}]
				}

				const firstResponse = await getInfoByBarcode(JSON.stringify(data))
				console.log(firstResponse)
				if (firstResponse.length === 0) { //未生成条形码
					console.log("dafafadf")
					console.log(searchValue)
					// 转换后的数据结构
					const transformedData = {
						"FID": this.indexList[0]["FID"],
						"FEntity.FEntryID": 0,
						"FBillNo": this.indexList[0]["FBillNo"],
						"FStockId.fnumber": "",
						"FStockId.FName": "",
						"FStockLocId.FF102029.fname": "",
						"FMaterialId.fnumber": "面料盘盈",
						"FEnchaseNo": searchValue,
						"FBoxNo": '',
						"FIsCheck": "B",
						"FCheckTag": "B",
						"FCheckNum": 0,
						"FAccountNum": 0,
						"FLot.FNumber": '',
						"FAuxPropId.FF101501.FDATAVALUE": '',
						"smzt":1
					};
					this.indexList.push(transformedData);
					console.log(secondResponse)
					console.log(this.indexList)
					this.$modal.closeLoading()

					uni.showToast({
						title: '新增成功',
						icon: 'none',
						duration: 3000
					})

					this.$nextTick(() => {
						this.searchValue = ''
						this.isFocus = true;
						this.scrollToItem("scrollItem-" + nowindex)
					})
					playVoice(audioUrls.successVoiceUrl)
					// this.createDetail(transformedData)
					// console.log(this.$modal)

					return; // 停止保存操作
				}
				// if (firstResponse[0]["FMaterialId.fnumber"] != (this.item["FMaterialId.fnumber"]||this.item["FSumMaterialId.fnumber"])) {
				// 	console.log("dafafadf")
				// 	uni.showToast({
				// 		title: '编码与原物料编码不一致，请重新替换装箱单号',
				// 		duration: 3000,
				// 		icon: 'none'
				// 	});
				// 	playVoice(audioUrls.failVoiceUrl)
				// 	return; // 停止保存操作
				// }
				const data2 = {
					"parameters": [{
						"FormId": "STK_Inventory",
						"FieldKeys": "FMaterialId.FNumber,FAuxPropId.FF101501.FDATAVALUE,FBaseQty,FStockLocId.FF102029.fnumber,FStockId.fnumber,FStockId.FName,FLot.FNumber",
						"FilterString": [{
								"Left": "",
								"FieldName": "FMaterialId.FNumber",
								"Compare": "67",
								// "Value": "CAW04044-1611088-1",
								"Value": firstResponse[0]["FMaterialId.fnumber"],
								"Right": "",
								"Logic": 0
							},
							{
								"Left": "",
								"FieldName": "FLot.FNumber",
								"Compare": "67",
								// "Value": "智能工厂-智能1220/20230821&T23091000852&无&23122000002",
								"Value": firstResponse[0]["FLot.FNumber"],
								"Right": "",
								"Logic": 0
							},
							{
								"Left": "",
								"FieldName": "FBaseQty",
								"Compare": "21",
								"Value": "0",
								"Right": "",
								"Logic": 0
							}
						],
						"OrderString": "",
					}]
				}
				const secondResponse = await getStockInfo(JSON.stringify(data2))
				if (secondResponse.length > 1) {
					this.handleError("即时库存存在多个仓位，不允许选择！")
					this.$modal.closeLoading()
					this.item['NewFENCHASENUM.LT'] = ""
					return
				}
				if (secondResponse.length == 0) {
					const transformedData = {
						"FID": this.indexList[0]["FID"],
						"FEntity.FEntryID": 0,
						"FBillNo": this.indexList[0]["FBillNo"],
						"FStockId.fnumber": "",
						"FStockId.FName": "",
						"FStockLocId.FF102029.fname": "",
						"FMaterialId.fnumber": firstResponse[0]["FMaterialId.fnumber"],
						"FEnchaseNo": searchValue,
						"FBoxNo": firstResponse[0]["FBoxNo.LT"],
						"FIsCheck": "B",
						"FCheckTag": "B",
						"FCheckNum": 0,
						"FAccountNum": 0,
						"FLot.FNumber": firstResponse[0]["FLot.FNumber"],
						"FAuxPropId.FF101501.FDATAVALUE": '',
						"smzt":1
					};
					// this.createDetail(transformedData)
					this.indexList.push(transformedData);
					console.log(secondResponse)
					console.log(this.indexList)
					this.$modal.closeLoading()

					uni.showToast({
						title: '新增成功',
						icon: 'none',
						duration: 3000
					})

					this.$nextTick(() => {
						this.searchValue = ''
						this.isFocus = true;
						this.scrollToItem("scrollItem-" + nowindex)
					})
					playVoice(audioUrls.successVoiceUrl)
					return
				}
				// 转换后的数据结构
				const transformedData = {
					"FID": this.indexList[0]["FID"],
					"FEntity.FEntryID": 0,
					"FBillNo": "PD24123000001",
					"FStockId.fnumber": secondResponse[0]["FStockId.fnumber"],
					"FStockId.FName": secondResponse[0]["FStockId.FName"],
					"FStockLocId.FF102029.fname": secondResponse[0]["FStockLocId.FF102029.fnumber"],
					"FMaterialId.fnumber": secondResponse[0]["FMaterialId.FNumber"],
					"FEnchaseNo": searchValue,
					"FBoxNo": firstResponse[0]["FBoxNo.LT"],
					"FIsCheck": "B",
					"FCheckTag": "B",
					"FCheckNum": secondResponse[0]["FBaseQty"],
					"FAccountNum": secondResponse[0]["FBaseQty"],
					"FLot.FNumber": secondResponse[0]["FLot.FNumber"],
					"FAuxPropId.FF101501.FDATAVALUE": secondResponse[0]["FAuxPropId.FF101501.FDATAVALUE"],
					"smzt":1
				};
				// this.createDetail(transformedData)
				this.indexList.push(transformedData);
				console.log(secondResponse)
				console.log(this.indexList)
				this.$modal.closeLoading()
				uni.showToast({
					title: '新增成功',
					icon: 'none',
					duration: 3000
				})
				this.$nextTick(() => {
					this.searchValue = ''
					this.isFocus = true;
					this.scrollToItem("scrollItem-" + nowindex)
				})
				playVoice(audioUrls.successVoiceUrl)

			},
			createDetail(transformedData) {
				this.indexList.push(transformedData);
				console.log(secondResponse)
				console.log(this.indexList)
				this.$modal.closeLoading()

				uni.showToast({
					title: '新增成功',
					icon: 'none',
					duration: 3000
				})

				this.$nextTick(() => {
					this.searchValue = ''
					this.isFocus = true;
					this.scrollToItem("scrollItem-" + nowindex)
				})
				playVoice(audioUrls.successVoiceUrl)


			},
			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>