<template>
	<view class="container">
		<view class="form-panel">
			<uni-section title="部件出库" type="line">
				<uni-forms ref="baseForm" :modelValue="baseFormData" labelWidth="100px">
					<uni-forms-item label="所属区域" required name="owningRegion"
						:rules="[{ required: true, errorMessage: '请输入所属区域' }]">
						<selectOperation v-model="baseFormData.owningRegion" placeholder="请选择所属区域" :disabled="readOnly">
						</selectOperation>
					</uni-forms-item>
					<uni-forms-item label="选择部件" required name="componentType"
						:rules="[{ required: true, errorMessage: '请选择部件' }]">
						<selectComponentType v-model="baseFormData.componentType" placeholder="请选择部件"
							:disabled="readOnly" @change="changeType"></selectComponentType>
					</uni-forms-item>
					<uni-section v-if="baseFormData.componentType == '262711452730000'" title="出库电池列表" type="line">
						<template v-slot:right>
							<uni-icons type="scan" size="20" @click="onBatteryScanClick" v-if="!readOnly"></uni-icons>
						</template>
						<uni-swipe-action>
							<uni-swipe-action-item v-for="(item,index) in listBatteryData" :key="index"
								:right-options="listBatteryOptions" :disabled="readOnly">
								<div class="content-box">
									<label>{{item.batteryCode}}</label>
									<div v-show="!readOnly" @click="delData(index)">
										<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
											color="rgb(121 116 116)" size="20" />
									</div>
								</div>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</uni-section>
					<uni-section v-if="baseFormData.componentType == '262711452730001'" title="出库头盔列表" type="line">
						<template v-slot:right>
							<uni-icons type="scan" size="20" @click="onHelmetScanClick" v-if="!readOnly"></uni-icons>
						</template>
						<uni-swipe-action>
							<uni-swipe-action-item v-for="(item,index) in listHelmetData" :key="index"
								:right-options="listHelmetOptions" :disabled="readOnly">
								<div class="content-box">
									<label>{{item.helmetCode}}</label>
									<div v-show="!readOnly" @click="delData(index)">
										<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
											color="rgb(121 116 116)" size="20" />
									</div>
								</div>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</uni-section>
					<uni-section v-if="baseFormData.componentType == '262711452730008'" title="出库中控列表" type="line">
						<template v-slot:right>
							<uni-icons type="scan" size="20" @click="onEcuScanClick" v-if="!readOnly"></uni-icons>
						</template>
						<uni-swipe-action>
							<uni-swipe-action-item v-for="(item,index) in listEcuData" :key="index"
								:right-options="listEcuOptions" :disabled="readOnly">
								<div class="content-box">
									<label>{{item.ecuSn}}</label>
									<div v-show="!readOnly" @click="delData(index)">
										<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
											color="rgb(121 116 116)" size="20" />
									</div>
								</div>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</uni-section>
					<uni-forms-item label="出库数量" required name="outQuantity"
						:rules="[{ required: true, errorMessage: '请输入出库数量' }]">
						<uni-number-box :background="(readOnly||disabledOutNum)?'#d8d9d0':'#ffffff'"
							v-model="baseFormData.outQuantity" placeholder="请输入出库数量"
							:disabled="readOnly || disabledOutNum" />
					</uni-forms-item>
					<uni-section v-if="baseFormData.componentType == '262711452730000'& openType=='1'" title="归还电池列表"
						type="line">
						<template v-slot:right>
							<uni-icons type="scan" size="20" @click="onInBatteryScanClick"
								v-if="readOnly1&baseFormData.state!='2'"></uni-icons>
						</template>
						<uni-swipe-action>
							<uni-swipe-action-item v-for="(item,index) in listInBatteryData" :key="index"
								:right-options="listInBatteryOptions" :disabled="readOnly1">
								<div class="content-box">
									<label>{{item.batteryCode}}</label>
									<div v-show="readOnly1&baseFormData.state!='2'" @click="delInData(index)">
										<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
											color="rgb(121 116 116)" size="20" />
									</div>
								</div>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</uni-section>
					<uni-section v-if="baseFormData.componentType == '262711452730001'& openType=='1'" title="归还头盔列表"
						type="line">
						<template v-slot:right>
							<uni-icons type="scan" size="20" @click="onInHelmetScanClick"
								v-if="readOnly1&baseFormData.state!='2'"></uni-icons>
						</template>
						<uni-swipe-action>
							<uni-swipe-action-item v-for="(item,index) in listInHelmetData" :key="index"
								:right-options="listInHelmetOptions" :disabled="readOnly1">
								<div class="content-box">
									<label>{{item.helmetCode}}</label>
									<div v-show="readOnly1&baseFormData.state!='2'" @click="delInData(index)">
										<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
											color="rgb(121 116 116)" size="20" />
									</div>
								</div>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</uni-section>
					<uni-section v-if="baseFormData.componentType == '262711452730008'& openType=='1'" title="归还中控列表"
						type="line">
						<template v-slot:right>
							<uni-icons type="scan" size="20" @click="onInEcuScanClick"
								v-if="readOnly1&baseFormData.state!='2'"></uni-icons>
						</template>
						<uni-swipe-action>
							<uni-swipe-action-item v-for="(item,index) in listInEcuData" :key="index"
								:right-options="listInEcuOptions" :disabled="readOnly1">
								<div class="content-box">
									<label>{{item.ecuSn}}</label>
									<div v-show="readOnly1&baseFormData.state!='2'" @click="delInData(index)">
										<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
											color="rgb(121 116 116)" size="20" />
									</div>
								</div>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</uni-section>
					<uni-forms-item label="归还数量" name="enterQuantity" v-if="openType=='1'"
						:rules="[{ required: true, errorMessage: '请输入归还数量' }]">
						<uni-number-box :background="(readOnly1||disabledEnterNum)?'#d8d9d0':'#ffffff'"
							v-model="baseFormData.enterQuantity" placeholder="请输入归还数量"
							:disabled="readOnly1 || disabledEnterNum" />
					</uni-forms-item>
					<uni-forms-item label="原部件处理方案" required name="oldComponentHandleOption"
						:rules="[{ required: true, errorMessage: '请选择原部件处理方案' }]">
						<uni-data-select v-model="baseFormData.oldComponentHandleOption"
							:localdata="componentHandleOptionRange" @change="componentHandleOptionChange"
							placeholder="请选择原部件处理方案" :disabled="readOnly"></uni-data-select>
					</uni-forms-item>
				</uni-forms>
			</uni-section>
		</view>
	</view>
	<view class="nav-panel" v-if="baseFormData.state == '0' || (baseFormData.state == '1' && 
		(baseFormData.componentType == '262711452730000' || 
		baseFormData.componentType == '262711452730001' ||
		baseFormData.componentType == '262711452730008'))">
		<c-uni-goods-nav :fill="true" :options="navOptions" @click="navOptionsClick" :buttonGroup="navButtonGroup"
			@buttonClick="navButtonClick" />
	</view>
</template>
<script setup>
	import {
		onMounted,
		ref,
		reactive
	} from 'vue';
	import * as api from '@/utils/api.js';
	import {
		showModelMessage,
		isNullOrEmpty,
		dataFormat
	} from '@/utils/tools.js';
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	import {
		useScanCodeStore
	} from '@/stores/scancode.js';
	const scancode = useScanCodeStore();

	const baseForm = ref(null);
	const readOnly = ref(false);
	const readOnly1 = ref(false);
	const userInfo = ref(null);
	const disabledOutNum = ref(false);
	const disabledEnterNum = ref(false);
	const componentOutRecordId = ref("");
	const openType = ref("0");
	const state = ref("0");
	// 基础表单数据
	const baseFormData = ref({
		"componentOutRecordId": "",
		"owningRegion": "",
		"componentType": "",
		"outQuantity": 0,
		"oldComponentHandleOption": "",
		"state": "0",
		"enterQuantity": 0,
		"stockInType": "0"
	});

	let navOptions = reactive([{
		icon: 'download',
		text: '暂存',
		disable: false
	}, {
		icon: 'closeempty',
		text: '取消',
		disable: false
	}]);

	let navButtonGroup = reactive([{
		text: '出库',
		backgroundColor: '#0078D4',
		color: '#fff',
		disable: false
	}]);

	const componentHandleOptionRange = [{
			value: "报废",
			text: "报废"
		},
		{
			value: "返修",
			text: "返修"
		}
	]

	const listBatteryData = ref([]);
	const listHelmetData = ref([]);
	const listEcuData = ref([]);

	const componentHandleOptionChange = (value) => {
		baseFormData.value.oldComponentHandleOption = value;
	};

	// 在组件挂载完成后加载数据
	onMounted(() => {
		if (!isNullOrEmpty(componentOutRecordId.value)) {
			loadData();
		}
	});
	onLoad((options) => {
		scancode.clearCode();
		baseFormData.value.enterQuantity = 0;
		baseFormData.value.outQuantity = 0;
		if (options.componentOutRecordId) {
			componentOutRecordId.value = options.componentOutRecordId;
		}
		if (options.state) {
			state.value = options.state;
			if (options.state == '1') {
				openType.value = '1';
				navButtonGroup[0].text = '归还'
				readOnly.value = true;
				readOnly1.value = true;
			} else if (options.state == '2') {
				openType.value = '1';
				readOnly.value = true;
				readOnly1.value = true;
			} else if (options.state == '0') {
				readOnly.value = false;
			} else {
				readOnly.value = true;
			}
		}
		userInfo.value = uni.getStorageSync('userInfo');
	});

	onShow(() => {
		if (!isNullOrEmpty(scancode.code)) {
			const arr = scancode.code;
			for (let i = 0; i < arr.length; i++) {
				if (scancode.type == 'outBattery') {
					listBatteryData.value = [];
					const oneBattery = {
						"componentOutRecordId": componentOutRecordId.value,
						"batteryCode": arr[i]
					}
					listBatteryData.value.push(oneBattery)
					baseFormData.value.outQuantity = listBatteryData.value.length
				} else if (scancode.type == 'outHelmet') {
					listHelmetData.value = [];
					const oneHelmet = {
						"componentOutRecordId": componentOutRecordId.value,
						"helmetCode": arr[i]
					}
					listHelmetData.value.push(oneHelmet)
					baseFormData.value.outQuantity = listHelmetData.value.length
				} else if (scancode.type == 'inBattery') {
					listInBatteryData.value = [];
					const oneBattery = {
						"componentOutRecordId": componentOutRecordId.value,
						"batteryCode": arr[i]
					}
					listInBatteryData.value.push(oneBattery)
					baseFormData.value.enterQuantity = listInBatteryData.value.length
				} else if (scancode.type == 'inHelmet') {
					listInHelmetData.value = [];
					const oneHelmet = {
						"componentOutRecordId": componentOutRecordId.value,
						"helmetCode": arr[i]
					}
					listInHelmetData.value.push(oneHelmet)
					baseFormData.value.enterQuantity = listInHelmetData.value.length
				} else if (scancode.type == 'inEcu') {
					listInEcuData.value = [];
					const arrCode = arr[i].split(" ");
					const imei = arrCode[0].replace("IMEI:", "");
					const sn = arrCode[1].replace("SN:", "");
					const oneEcu = {
						"componentOutRecordId": componentOutRecordId.value,
						"ecuCode": imei,
						"ecuSn": sn
					}
					listInEcuData.value.push(oneEcu)
					baseFormData.value.enterQuantity = listInEcuData.value.length
				} else if (scancode.type == 'outEcu') {
					listEcuData.value = [];
					const arrCode = arr[i].split(" ");
					const imei = arrCode[0].replace("IMEI:", "");
					const sn = arrCode[1].replace("SN:", "");
					const oneEcu = {
						"componentOutRecordId": componentOutRecordId.value,
						"ecuCode": imei,
						"ecuSn": sn
					}
					listEcuData.value.push(oneEcu)
					baseFormData.value.outQuantity = listEcuData.value.length
				} else break;
			}
		}
	});

	function changeType(value) {
		if (",262711452730000,262711452730001,262711452730008,".indexOf("," + value + ",") > -1) {
			disabledEnterNum.value = true;
			disabledOutNum.value = true;
			scancode.clearCode();
			listBatteryData.value = [];
			listHelmetData.value = [];
			listEcuData.value = [];
		} else {
			disabledEnterNum.value = false;
			disabledOutNum.value = false;
		}
		baseFormData.value.enterQuantity = 0;
		baseFormData.value.outQuantity = 0;
	}

	const loadData = () => {
		api.callOperateApi("ebikeComponent/getComponentOutRecordInfo?componentOutRecordId=" + componentOutRecordId
			.value, {}, "get").then((
			res) => {
			if (res.code === 200) {
				baseFormData.value = res.data;
				if (baseFormData.value.componentType == '262711452730000') {
					listBatteryData.valueres.data.ebikeBatteryOutRecords ? [...res.data
						.ebikeBatteryOutRecords
					] : [];
					baseFormData.value.outQuantity = listBatteryData.value.length;
					listInBatteryData.valueres.data.ebikeBatteryEnterRecords ? [...res.data
						.ebikeBatteryEnterRecords
					] : [];
					baseFormData.value.enterQuantity = listInBatteryData.value.length;
				} else if (baseFormData.value.componentType == '262711452730001') {
					listHelmetData.valueres.data.ebikeHelmetOutRecords ? [...res.data.ebikeHelmetOutRecords] :
						[];
					baseFormData.value.outQuantity = listHelmetData.value.length;
					listInHelmetData.valueres.data.ebikeHelmetEnterRecords ? [...res.data
						.ebikeHelmetEnterRecords
					] : [];
					baseFormData.value.enterQuantity = listInHelmetData.value.length;
				} else if (baseFormData.value.componentType == '262711452730008') {
					listEcuData.value = res.data.ebikeEcuOutRecords ? [...res.data.ebikeEcuOutRecords] : [];
					baseFormData.value.outQuantity = listEcuData.value.length;
					listInEcuData.value = res.data.ebikeEcuEnterRecords ? [...res.data.ebikeEcuEnterRecords] :
						[];
					baseFormData.value.enterQuantity = listInEcuData.value.length;
				}
			}
		})
	};

	const getBatteryList = (componentOutRecordId, pageNo = 1, pageSize = 100) => {
		// 组装参数
		const params = {
			"componentOutRecordId": componentOutRecordId,
			"pageParam": {
				"pageNum": pageNo,
				"pageSize": pageSize
			}
		}
		api.callOperateApi("ebikeBatteryOutRecords/list", params).then((res) => {
			if (res.code === 200) {
				listBatteryData.value.push(...res.data.records);
				baseFormData.value.outQuantity = listBatteryData.value.length;
				if (res.data.totalRow > pageNo * pageSize) {
					pageNo += 1;
					getBatteryList(componentOutRecordId, pageNo, pageSize);
				}
			}
		});
	}

	const getHelmetList = (componentOutRecordId, pageNo = 1, pageSize = 100) => {
		// 组装参数
		const params = {
			"componentOutRecordId": componentOutRecordId,
			"pageParam": {
				"pageNum": pageNo,
				"pageSize": pageSize
			}
		}
		api.callOperateApi("ebikeHelmetOutRecords/list", params).then((res) => {
			if (res.code === 200) {
				listHelmetData.value.push(...res.data.records);
				baseFormData.value.outQuantity = listHelmetData.value.length;
				if (res.data.totalRow > pageNo * pageSize) {
					pageNo += 1;
					getHelmetList(componentOutRecordId, pageNo, pageSize);
				}
			}
		});
	}

	const getEcuList = (componentOutRecordId, pageNo = 1, pageSize = 100) => {
		// 组装参数
		const params = {
			"componentOutRecordId": componentOutRecordId,
			"pageParam": {
				"pageNum": pageNo,
				"pageSize": pageSize
			}
		}
		api.callOperateApi("ebikeComponent/ecuOutList", params).then((res) => {
			if (res.code === 200) {
				listEcuData.value.push(...res.data.records);
				baseFormData.value.outQuantity = listEcuData.value.length;
				if (res.data.totalRow > pageNo * pageSize) {
					pageNo += 1;
					getEcuList(componentOutRecordId, pageNo, pageSize);
				}
			}
		});
	}

	const listInBatteryData = ref([]);
	const listInHelmetData = ref([]);
	const listInEcuData = ref([]);
	const getInBatteryList = (componentOutRecordId, pageNo = 1, pageSize = 100) => {
		// 组装参数
		const params = {
			"componentEnterRecordId": componentOutRecordId,
			"pageParam": {
				"pageNum": pageNo,
				"pageSize": pageSize
			}
		}
		api.callOperateApi("ebikeBatteryEnterRecords/list", params).then((res) => {
			if (res.code === 200) {
				listInBatteryData.value.push(...res.data.records);
				baseFormData.value.enterQuantity = listInBatteryData.value.length;
				if (res.data.totalRow > pageNo * pageSize) {
					pageNo += 1;
					getInBatteryList(componentOutRecordId, pageNo, pageSize);
				}
			}
		});
	}

	const getInHelmetList = (componentOutRecordId, pageNo = 1, pageSize = 100) => {
		// 组装参数
		const params = {
			"componentEnterRecordId": componentOutRecordId,
			"pageParam": {
				"pageNum": pageNo,
				"pageSize": pageSize
			}
		}
		api.callOperateApi("ebikeHelmetEnterRecords/list", params).then((res) => {
			if (res.code === 200) {
				listInHelmetData.value.push(...res.data.records);
				baseFormData.value.enterQuantity = listInHelmetData.value.length;
				if (res.data.totalRow > pageNo * pageSize) {
					pageNo += 1;
					getInHelmetList(componentOutRecordId, pageNo, pageSize);
				}
			}
		});
	}

	const getInEcuList = (componentOutRecordId, pageNo = 1, pageSize = 100) => {
		// 组装参数
		const params = {
			"componentEnterRecordId": componentOutRecordId,
			"pageParam": {
				"pageNum": pageNo,
				"pageSize": pageSize
			}
		}
		api.callOperateApi("ebikeComponent/list", params).then((res) => {
			if (res.code === 200) {
				listInEcuData.value.push(...res.data.records);
				baseFormData.value.enterQuantity = listInEcuData.value.length;
				if (res.data.totalRow > pageNo * pageSize) {
					pageNo += 1;
					getInEcuList(componentOutRecordId, pageNo, pageSize);
				}
			}
		});
	}


	const navOptionsClick = (e) => {
		const index = e.index;
		if (index == 0) {
			handleSubmit('0');
		} else if (index == 1) {
			handleSubmit('-1');
		}
	}

	const navButtonClick = (e) => {
		const index = e.index;
		//navButtonGroup[index].disable = true;
		if (index == 0) {
			if (baseForm.value) { // 确保表单元素已挂载
				baseForm.value.validate().then((res) => {
					if (baseFormData.value.state == "1") {
						if (baseFormData.value.componentType == '262711452730000') {
							if (listInBatteryData.value.length == 0) {
								showModelMessage("归还电池列表不能为空！");
								return false;
							}
						}
						if (baseFormData.value.componentType == '262711452730001') {
							if (listInHelmetData.value.length == 0) {
								showModelMessage("归还头盔列表不能为空！");
								return false;
							}
						}
						if (baseFormData.value.componentType == '262711452730008') {
							if (listInEcuData.value.length == 0) {
								showModelMessage("归还中控列表不能为空！");
								return false;
							}
						}
						handleSubmit('2');
					} else {
						if (baseFormData.value.componentType == '262711452730000') {
							if (listBatteryData.value.length == 0) {
								showModelMessage("出库电池列表不能为空！");
								return false;
							}
						}
						if (baseFormData.value.componentType == '262711452730001') {
							if (listHelmetData.value.length == 0) {
								showModelMessage("出库头盔列表不能为空！");
								return false;
							}
						}
						if (baseFormData.value.componentType == '262711452730008') {
							if (listEcuData.value.length == 0) {
								showModelMessage("出库中控列表不能为空！");
								return false;
							}
						}
						handleSubmit('1');
					}
				}).catch((err) => {
					//console.log('err', err);
				});
			} else {
				//console.error('Form element is not available'); // 调试信息，以防万一
			}
		}
	}

	const handleSubmit = (state) => {
		const params = baseFormData.value;
		let sucessMsg = "保存成功";
		let errorMsg = "保存失败";
		baseFormData.value.stockInType = '0';
		if (componentOutRecordId.value) {
			baseFormData.value.componentOutRecordId = componentOutRecordId.value
		}
		if (state == '-1') {
			sucessMsg = "取消成功";
			errorMsg = "取消失败";
			if (componentOutRecordId.value) {
				api.callOperateApi("ebikeComponent/cancelOutDevicePart?componentOutRecordId=" +
					componentOutRecordId.value, {}, "get").then((res) => {
					if (res.code == '200') {
						uni.showToast({
							title: sucessMsg,
							icon: 'success',
							duration: 2000
						});
						setTimeout(function() {
							uni.navigateBack(1);
						}, 2000)
					} else {
						uni.showToast({
							title: res.message,
							icon: 'error',
							duration: 2000
						});
					};
				});
				return;
			}
		} else if (state == '1') {
			sucessMsg = "出库成功";
			errorMsg = "出库失败";
			baseFormData.value.stockInType = '1';
			if (params.componentType == '262711452730000') {
				params['ebikeBatteryOutRecords'] = listBatteryData.value;
			} else if (params.componentType == '262711452730001') {
				params['ebikeHelmetOutRecords'] = listHelmetData.value;
			} else if (params.componentType == '262711452730008') {
				params['ebikeEcuOutRecords'] = listEcuData.value;
			}
			api.callOperateApi("ebikeComponent/ComponentInventoryOutbound", params).then((res) => {
				if (res.code == '200') {

					uni.showToast({
						title: sucessMsg,
						icon: 'success',
						duration: 2000
					});
					if (state == '1' || state == '-1') {
						setTimeout(function() {
							uni.navigateBack(1);
						}, 2000)
					} else {
						componentOutRecordId.value = res.data;
					}
				} else {
					uni.showToast({
						title: res.message,
						icon: 'error',
						duration: 2000
					});
				};
			});
			return;
		} else if (state == '2') {
			sucessMsg = "归还成功";
			errorMsg = "归还失败";
			baseFormData.value.stockInType = '1';
			if (params.componentType == '262711452730000') {
				params['ebikeBatteryEnterRecords'] = listInBatteryData.value;
			} else if (params.componentType == '262711452730001') {
				params['ebikeHelmetEnterRecords'] = listInHelmetData.value;
			} else if (params.componentType == '262711452730008') {
				params['ebikeEcuEnterRecords'] = listInEcuData.value;
			}
			api.callOperateApi("ebikeComponent/componentInventoryEnterbound", params).then((res) => {
				if (res.code == '200') {
					uni.showToast({
						title: sucessMsg,
						icon: 'success',
						duration: 2000
					});
					setTimeout(function() {
						uni.navigateBack(1);
					}, 2000)
				} else {
					uni.showToast({
						title: errorMsg,
						icon: 'error',
						duration: 2000
					});
				};
			});
			return;
		}
		if (baseFormData.value.state == '0') {
			if (params.componentType == '262711452730000') {
				params['ebikeBatteryOutRecords'] = listBatteryData.value;
			} else if (params.componentType == '262711452730001') {
				params['ebikeHelmetOutRecords'] = listHelmetData.value;
			} else if (params.componentType == '262711452730008') {
				params['ebikeEcuOutRecords'] = listEcuData.value;
			}
			api.callOperateApi("ebikeComponent/ComponentInventoryOutbound", params).then((res) => {
				if (res.code == '200') {

					uni.showToast({
						title: sucessMsg,
						icon: 'success',
						duration: 2000
					});
					componentOutRecordId.value = res.data;
				} else {
					uni.showToast({
						title: res.message,
						icon: 'error',
						duration: 2000
					});
				};
			});
		} else if (baseFormData.value.state == '1') {
			if (params.componentType == '262711452730000') {
				params['ebikeBatteryEnterRecords'] = listInBatteryData.value;
			} else if (params.componentType == '262711452730001') {
				params['ebikeHelmetEnterRecords'] = listInHelmetData.value;
			} else if (params.componentType == '262711452730008') {
				params['ebikeEcuEnterRecords'] = listInEcuData.value;
			}
			api.callOperateApi("ebikeComponent/componentInventoryEnterbound", params).then((res) => {
				if (res.code == '200') {
					uni.showToast({
						title: sucessMsg,
						icon: 'success',
						duration: 2000
					});
				} else {
					uni.showToast({
						title: errorMsg,
						icon: 'error',
						duration: 2000
					});
				};
			});
		}
	};

	const listBatteryOptions = reactive([{
		text: '删除',
		style: {
			backgroundColor: '#007aff'
		}
	}]);

	const listHelmetOptions = reactive([{
		text: '删除',
		style: {
			backgroundColor: '#007aff'
		}
	}]);
	const listEcuOptions = reactive([{
		text: '删除',
		style: {
			backgroundColor: '#007aff'
		}
	}]);

	function delData(index) {
		switch (baseFormData.value.componentType) {
			case "262711452730000":
				listBatteryData.value.splice(index, 1);
				break;
			case "262711452730001":
				listHelmetData.value.splice(index, 1);
				break;
			case "262711452730008":
				listEcuData.value.splice(index, 1);
				break;
		}
		scancode.delDataByIndex(index);
		baseFormData.value.outQuantity = baseFormData.value.outQuantity - 1;
	}

	const onBatteryScanClick = (e) => {
		uni.navigateTo({
			url: `/pages/common/batchscancode?type=outBattery`, //
		});
	}

	const onHelmetScanClick = (e) => {
		uni.navigateTo({
			url: `/pages/common/batchscancode?type=outHelmet`, //
		});
	}

	const onEcuScanClick = (e) => {
		uni.navigateTo({
			url: `/pages/common/batchscancode?type=outEcu`, //
		});
	}

	const listInBatteryOptions = ref([{
		text: '删除',
		style: {
			backgroundColor: '#007aff'
		}
	}]);

	const listInHelmetOptions = ref([{
		text: '删除',
		style: {
			backgroundColor: '#007aff'
		}
	}]);

	const listInEcuOptions = ref([{
		text: '删除',
		style: {
			backgroundColor: '#007aff'
		}
	}]);

	function delInData(index) {
		switch (baseFormData.value.componentType) {
			case "262711452730000":
				listInBatteryData.value.splice(index, 1);
				break;
			case "262711452730001":
				listInHelmetData.value.splice(index, 1);
				break;
			case "262711452730008":
				listInEcuData.value.splice(index, 1);
				break;
		}
		scancode.delDataByIndex(index);
		baseFormData.value.enterQuantity = baseFormData.value.enterQuantity - 1;
	}

	const onInBatteryScanClick = (e) => {
		uni.navigateTo({
			url: `/pages/common/batchscancode?type=inBattery&scanType=bjgh`, //
		});
	}

	const onInHelmetScanClick = (e) => {
		uni.navigateTo({
			url: `/pages/common/batchscancode?type=inHelmet&scanType=bjgh`, //
		});
	}

	const onInEcuScanClick = (e) => {
		uni.navigateTo({
			url: `/pages/common/batchscancode?type=inEcu&scanType=bjgh`, //
		});
	}
</script>

<style lang="scss">
	.container {
		padding: 15px;
		background-color: #fff;
	}

	.form-panel {
		padding-bottom: 55px;
	}

	.nav-panel {
		position: fixed;
		bottom: 0rpx;
		width: 100%;
		padding-bottom: 10px;
		z-index: 999;
		background-color: #fff;
	}

	.content-box {
		display: flex;
		line-height: 50px;
		border-bottom: 1px solid #f4f4f4;
	}

	.content-box label {
		flex: 1
	}

	.uni-section {
		margin: 20px 0px;
	}

	.uni-section-header {
		border-top: 1px solid #f4f4f4;
		border-bottom: 1px solid #f4f4f4;
	}
</style>