<template>
	<gui-page :custom-header="true" :header-class="['gui-theme-background-color']">
		<template #gHeader>
			<view style="height:44px;" class="gui-flex gui-nowrap gui-rows gui-align-items-center">
				<!-- 使用组件实现返回按钮及返回首页按钮 -->
				<text style="font-size:44rpx;" class="gui-header-leader-btns gui-color-white font-icons"
					@tap="goBack">&#xe6c5;</text>
				<!-- 导航文本此处也可以是其他自定义内容 -->
				<text
					class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text">工单执行</text>
				<!-- 此处加一个右侧展位元素与左侧同宽，实现标题居中 -->
				<!-- 实际宽度请根据自己情况设置 -->
				<view style="width:40px;" />
				<!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
			</view>
		</template>
		<template #gBody>
			<view class="oqc-checkout">
				<view class="scan">
					<view class="scan-title">
						<span>{{ params.erpWorkOrderNo }}</span>
						<span>{{ params.processName }}</span>
					</view>
				</view>
				<view class="scan">
					<view class="scan-title">
						<span>检验状态</span>
						<span>{{ computedIPQCState(btnState) }}</span>
					</view>
				</view>
				<view class="scan">
					<view class="scan-card">
						<span>执行人</span>
						<uni-easyinput ref="userInput" v-model="params.userName" :input-border="false" type="text"
							placeholder="请扫描工号" @confirm="confirmUser" @focus="handleInputFocus('userInput')"
							@clear="handleClear('userInput')" />
						<text class="font-icons" @click="handleScanUser">&#xe6b7;</text>
					</view>
				</view>
				<view v-if="params.equipmentInspection * 1 === 1" class="scan">
					<view v-if="params.equipmentInspection * 1 === 0 && !params.userName" class="scan-card">
						<span>设备</span>
						<uni-easyinput v-model="params.equipmentName" :input-border="false" disabled type="text"
							placeholder="请扫描设备码" />
					</view>
					<view v-if="params.equipmentInspection * 1 === 1 || params.userName" class="scan-card">
						<span>设备</span>
						<uni-easyinput ref="equipmentInput" v-model="params.equipmentName" :input-border="false"
							type="text" placeholder="请扫描设备码" @confirm="confirmEquipmentName"
							@focus="handleInputFocus('equipmentInput')" @clear="handleClear('equipmentInput')" />
						<text class="font-icons" @click="handleScanDevice">&#xe6b7;</text>
					</view>
				</view>
				<view v-if="params.verifyMoldFixture * 1 === 1" class="scan">
					<view v-if="params.verifyMoldFixture * 1 === 0 && !params.equipmentName" class="scan-card">
						<span>模具</span>
						<uni-easyinput v-model="params.toolingName" :input-border="false" disabled type="text"
							placeholder="请扫描模具码" />
					</view>
					<view v-if="params.verifyMoldFixture * 1 === 1 || params.equipmentName" class="scan-card">
						<span>模具</span>
						<uni-easyinput ref="toolingInput" v-model="params.toolingName" :input-border="false" type="text"
							placeholder="请扫描模具码" @confirm="confirmToolingName" @focus="handleInputFocus('toolingInput')"
							@clear="handleClear('toolingInput')" />
						<text class="font-icons" @click="handleScanTooling">&#xe6b7;</text>
					</view>
				</view>
				<!-- <view class="scan" v-if="params.verifyMoldFixture === '0'">
					<view class="scan-card">
						<span>物料清单</span>
						<uni-easyinput :inputBorder="false" disabled  type="text"
							v-model="params.scanMaterialNumber" placeholder="请扫描物料条码/轴号"></uni-easyinput>
					</view>
				</view> -->
				<view class="scan">
					<!-- toolState: 当前是否已绑定模具 -->
					<!-- verifyMoldFixture: 是否需要绑定摸具 -->
					<view v-if="params.toolState * 1 === 0" class="scan-card">
						<span>物料清单</span>
						<uni-easyinput v-model="params.scanMaterialNumber" :input-border="false" disabled type="text"
							placeholder="请扫描物料条码/轴号" />
					</view>
					<view v-if="params.toolState * 1 === 1" class="scan-card">
						<span>物料清单</span>
						<uni-easyinput ref="materialInput" v-model="params.scanMaterialNumber" :input-border="false"
							type="text" placeholder="请扫描物料条码/轴号" @confirm="confirmMaterial"
							@focus="handleInputFocus('materialInput')" @clear="handleClear('materialInput')" />
						<text class="font-icons" @click="handleScanMaterialOrAxisNumber">&#xe6b7;</text>
					</view>
				</view>

				<uni-collapse accordion style="margin-bottom: 100px;">
					<uni-collapse-item v-for="(item, key) in params.materialList" :key="key">
						<template #title>
							<view class="collapse">
								<text
									v-if="params.materialList[key].complete && computedResidualArea(params.materialList[key].batchNumberDetails) > 0"
									class="font-icons" style="color: rgba(109, 205, 50, 1);">&#xe6ba;</text>
								<text v-else class="font-icons" style="color: orange;">&#xe6d1;</text>
								<view class="collapse-title">
									<view class="title-text-layout">{{ computedCollapseTitle(item) }}</view>
									<view v-if="params.materialList[key].complete"
										style="display: grid;grid-template-columns: 2fr 5fr 3fr;">
										<view class="title-text-layout">
											轴({{ computedRollNo(params.materialList[key].rollNo) }})</view>
										<view class="title-text-layout">
											规格({{ params.materialList[key].materialModels }})</view>
										<view class="title-text-layout"
											style="text-align: right;color: orange;font-weight: bold;">
											{{ computedResidualArea(params.materialList[key].batchNumberDetails) }}
										</view>
									</view>
								</view>
							</view>
						</template>
						<view class="content">
							<view v-for="(Citem, Ckey) in params.materialList[key].batchNumberDetails" :key="Ckey"
								class="body-card" @click="handleChangeRow(Citem)">
								<view class="body-card-row">
									<span>批号</span>
									<span>{{ Citem.batchNum }}</span>
								</view>
								<view class="body-card-row">
									<span>余量</span>
									<span>{{ Citem.residueNumber }}㎡</span>
								</view>
							</view>
						</view>
					</uni-collapse-item>
				</uni-collapse>

				<view class="operationBtn">
					<button v-if="(btnState * 1 === 1) && (params.finishedProcess * 1 === 1)" type="primary"
						style="width: calc(100% - 8px);margin: 0 4px;" :disabled="params.printLabel * 1 === 0" @click="handleShowDayModal">打印</button>
					<button v-else-if="(btnState * 1 === 1) && (params.finishedProcess * 1 !== 1)" type="primary"
						style="width: calc(100% - 8px);margin: 0 4px;" :disabled="params.printLabel * 1 === 0" @click="handleValidataPrint('')">打印</button>
					<button v-else-if="btnState === -1" type="primary" style="width: calc(100% - 8px);margin: 0 4px;"
						@click="handleSubmission">送检</button>
					<button type="primary" style="width: calc(100% - 8px);margin: 0 4px;background-color: #07c160;"
						@click="handleNavigate">生产结束</button>
				</view>
			</view>
			<!-- 选择班别 -->
			<uni-popup ref="dayModal" background-color="#fff">
				<view class="popup-process-content">
					<view class="list-title" style="margin-bottom: 8px;">
						<span class="font-icons"
							style="font-size: 20px;color: #00a0e9;width: 40px;text-align: center;">&#xe6a3;</span>
						<span>班别列表</span>
					</view>
					<view class="grid-box">
						<view v-for="(item, key) in dictDataList" :key="key" class="box" @click="handleClickDay(item)">
							<text>{{ item.label }}</text>
						</view>
					</view>
				</view>
			</uni-popup>
			<!-- 打印前，用户需要输入生产数量 -->
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="inputClose" mode="input" title="标签生产数量" :value="qty" placeholder="请输入内容"
					@confirm="handleSetNum" />
			</uni-popup>
			<!-- 提示窗示例 -->
			<uni-popup ref="popup" type="dialog">
				<uni-popup-dialog type="warn" cancel-text="取消" confirm-text="确认" title="提示"
					@confirm="handleReportingWork" @close="popup.close()">
					<!-- eslint-disable-next-line -->
					<template #default="custom">
						<view class="form" style="width: 100%;margin: 0;">
							<view class="form-item">
								<div class="title">物料批次</div>
								<div class="content">
									<uni-easyinput v-model="rowEvent.materialCode" disabled type="digit"
										placeholder="请输入" />
								</div>
							</view>
							<view class="form-item">
								<div class="title">轴号</div>
								<div class="content">
									<uni-easyinput v-model="rowEvent.rollNo" disabled type="text" />
								</div>
							</view>
							<view class="form-item">
								<div class="title">剩余长度</div>
								<div class="content">
									<uni-easyinput v-model="rowEvent.residueLength" placeholder="请输入长度" type="digit" />
								</div>
							</view>
							<view class="form-item">
								<div class="title">核准数量（㎡）</div>
								<div class="content" style="margin: 0;">
									<input v-model="rowEvent.calculate" disabled>
								</div>
							</view>
							<view style="margin: 0 0 12px 0;display: flex;align-items: center;">
								<checkbox-group @change="handlePrintLabelChecked">
									<checkbox value="printLabel" :checked="isPrintLabel" color="#007aff"
										style="transform:scale(0.7)" />
									打标签
								</checkbox-group>
							</view>
						</view>
					</template>
				</uni-popup-dialog>
			</uni-popup>
			<uni-popup ref="errorTip" type="dialog">
				<uni-popup-dialog type="error" cancel-text="关闭" confirm-text="确认" title="提示" :content="errorTipMessage"
					@confirm="handleCloseErrorTipsModal" @close="handleCloseErrorTipsModal" />
			</uni-popup>
		</template>
	</gui-page>
</template>
<script>
	import {
		add
	} from '@/unit/Math.js'
	import {
		computed,
		defineComponent,
		ref,
		onMounted,
		onBeforeMount,
		watch
	} from 'vue'
	import tsc from '@/unit/CHITEN_SDK_APP/tsc.js'
	export default defineComponent({
		onLoad() {
			// // #ifdef APP-PLUS
			// plus.screen.lockOrientation('default');
			// // #endif
		},
		onUnload() {
			// // #ifdef APP-PLUS
			// plus.screen.lockOrientation('portrait-primary');
			// // #endif
		},
		onResize() {
			if ([90, -90].includes(plus.navigator.getOrientation())) {
				this.isLandscapeScreen = true
			} else {
				this.isLandscapeScreen = false
			}
		},
		setup(options) {
			const popup = ref()
			const btnState = ref(0)
			const modalForm = ref()
			const dayModal = ref()
			const dictDataList = ref([])
			const isLandscapeScreen = ref(false)
			// 是否打标签
			const isPrintLabel = ref(false)
			const parentRow = uni.getStorageSync('HotPressInfo') ?? {}
			// 绑定的检查人信息
			const params = ref({
				userState: '0', // 执行人
				deviceState: '0', // 设备
				toolState: '0', // 模具
				processName: '',
				routingListId: '',
				materialCount: 0,
				finishedProcess: '', // 打印是否需要选择班别, 为1则表示需要选择班别
				userName: '', // 执行人
				equipmentName: '', // 设备
				toolingName: '', // 模具
				materialNo: '', // 物料编码
				scanMaterialNumber: '', // 物料/轴号
				upperMaterialId: '', // 物料主表Id
				materialList: [], // 用料清单
				equipmentInspection: '',
				verifyMoldFixture: '',
				// 是否打印标签:为0不打印，打印按钮置灰
				printLabel: 0
			})
			const rowEvent = ref({
				width: 0, // 宽度
				residueLength: 0, //剩余长度
				materialCode: '',
				batchNum: '',
				rollNo: '',
				calculate: '',
				labelMasterId: ''
			})
			// 0：物料，1：轴号
			const nextScanState = ref('batchNum')
			// 生产数量
			const qty = ref(0)
			const inputDialog = ref()
			// 班别列表选择的班别
			const className = ref()
			// 当前执行物料清单索引
			const nextCodeIndex = ref(0)
			const bluetooth = ref()
			const blueConfig = ref({
				loopBuffer: 0,
				currentTime: 1,
				lastData: 0,
				onBufferSize: 20,
				printerNum: 1,
				currentPrint: 1,
				isLabelSend: false
			})

			const userInput = ref()
			const equipmentInput = ref()
			const toolingInput = ref()
			const materialInput = ref()
			const emptyDocument = ref()
			const errorState = ref(0)
			const errorTip = ref('')
			const errorTipMessage = ref('')

			// 手风琴表头
			const computedCollapseTitle = computed(() => {
				return item => {
					if (![NaN, null, undefined, ''].includes(item.materialCode)) {
						return item?.materialCode + '（' + item?.materialName + '）'
					}
					return ''
				}
			})

			const computedResidualArea = computed(() => {
				return item => {
					if (item?.length > 0) {
						let num = 0
						for (let i = 0; i < item.length; i++) {
							num = add(item[i].residueNumber, num)
						}
						return num
					} else {
						return 0
					}
				}
			})

			// rollNo
			const computedRollNo = computed(() => {
				return item => {
					if (![NaN, null, undefined, ''].includes(item)) {
						return item.trim()?.slice(0, 3)
					}
					return ''
				}
			})

			const computedIPQCState = computed(() => {
				return item => {
					if (![NaN, null, undefined, ''].includes(item)) {
						switch (item) {
							case -1:
								return '待送检'
							case 0:
								return '工单冻结不可送检'
							case 1:
								return '可下料打标签'
							case 2:
								return '已送检未审核'
						}
					}
					return ''
				}
			})

			// 根据剩余长度计算剩余数量
			watch([() => rowEvent.value.residueLength], (oldVal, newVal) => {
				rowEvent.value.calculate = Math.ceil((oldVal[0] * 1) * (rowEvent.value.width * 0.001)).toFixed(5);
			})

			const search = async function() {
				await uni.$reqGet('getProcessParam', {
						id: params.value?.id
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							Object.assign(params.value, data)
						} else {
							uni.showToast({
								title: msg,
								icon: 'none',
								duration: 2000
							})
						}
					})
				await uni.$reqGet('getUpperMaterialFlatKnife', {
						hotPressId: params.value?.id
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							data?.materialList.forEach(item => {
								item.complete = true
							})
							nextCodeIndex.value = data?.materialList?.length
							if (params.value.verifyMoldFixture * 1 === 0 || data?.toolingName) {
								params
									.value.toolState = '1'
							}
							Object.assign(params.value, data)
							if (params.value.materialCount > 0) {
								const forCount = params.value.materialCount - data
									.materialList?.length
								for (let i = 0; i < forCount; i++) {
									params.value.materialList.push({
										batchNum: '',
										materialName: '',
										rollNo: '',
										complete: false
									})
								}
							}
						} else {
							uni.showToast({
								title: msg,
								icon: 'none',
								duration: 2000
							})
						}
					})
			}

			// 校验显示打印按钮还是送检按钮
			const initChecked = async function() {
				const month = new Date().getMonth() + 1
				const day = new Date().getDate()
				await uni.$reqPost('getCheckedIPQCPass', {
						ipqcDate: new Date().getFullYear() + '' + (
							month < 10 ? ('0' +
								month) :
							month) + '' + (day < 10 ? ('0' + day) : day),
						mesHotPressId: params.value?.id,
						productionCode: '1605796881528524802'
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							btnState.value = data
						} else {
							uni.showToast({
								title: msg,
								icon: 'none',
								duration: 2000
							})
						}
					})
			}

			onBeforeMount(() => {
				Object.assign(params.value, JSON.parse(parentRow))
				// #ifdef APP-PLUS
				const bluetoothConfig = uni.getStorageSync('bluetoothConfig')
				if ([null, '', undefined].includes(bluetoothConfig)) {
					bluetooth.value = {
						'isOpenBle': false,
						'deviceId': '',
						'serviceId': '',
						'writeId': '',
						'notifyId': ''
					}
					setTimeout(() => {
						// #ifdef APP-PLUS
						plus.device.beep(2)
						// #endif
						errorTipMessage.value = '蓝牙打印机未连接'
						errorState.value = -1
						errorTip.value.open()
					}, 800)
				} else {
					bluetooth.value = JSON.parse(bluetoothConfig)
				}
				// #endif
				// 获取班别字典数据
				uni.$reqGet('getDictDataPage', {
						dictType: 'class_flag',
						pageNo: 1,
						pageSize: 100
					})
					.then(({
						code,
						data,
						msg
					}) => {
						dictDataList.value = data?.list ?? []
					})
			})

			onMounted(async () => {
				await search()
				await initChecked()
				if (params.value.userName && params.value.equipmentName && params.value.toolingName) {
					materialInput.value.onBlur()
					materialInput.value.onFocus()
				} else if (params.value.userName && params.value.equipmentName) {
					toolingInput.value.onBlur()
					toolingInput.value.onFocus()
				} else if (params.value.userName) {
					equipmentInput.value.onBlur()
					equipmentInput.value.onFocus()
				} else {
					userInput.value.onBlur()
					userInput.value.onFocus()
				}
			})

			const goBack = function() {
				uni.$goBack('/pages/workbranch/production/processExecution/processDetails')
			}

			const handleScanUser = function() {
				// #ifdef APP-PLUS
				const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_code === 1000) {
							// 执行人
							uni.$reqPost('scanUser', {
									hotPressId: params.value?.id,
									qrCode: ret.resp_result
								})
								.then(({
									code,
									data,
									msg
								}) => {
									if (code === 0) {
										if (data?.result * 1 === 0) {
											params.value.userName = ''
											// #ifdef APP-PLUS
											plus.device.beep(2)
											// #endif
											errorTipMessage.value = data.message
											errorTip.value.open()
											errorState.value = 0
											return
										}

										params.value.userName = data?.echoData
										params.value.userState = data?.result
										equipmentInput.value.onBlur()
										equipmentInput.value.onFocus()
									} else {
										// #ifdef APP-PLUS
										plus.device.beep(2)
										// #endif
										errorTipMessage.value = msg
										errorTip.value.open()
										errorState.value = 0
									}
								})
						}
					})
				// #endif
			}

			// 绑定执行人
			const confirmUser = function(e) {
				// 执行人
				uni.$reqPost('scanUser', {
						hotPressId: params.value?.id,
						qrCode: e
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							if (data?.result * 1 === 0) {
								params.value.userName = ''
								// #ifdef APP-PLUS
								plus.device.beep(2)
								// #endif
								errorTipMessage.value = data.message
								errorTip.value.open()
								errorState.value = 0
								return
							}
							params.value.userName = data?.echoData
							params.value.userState = data?.result
							equipmentInput.value.onBlur()
							equipmentInput.value.onFocus()
						} else {
							// #ifdef APP-PLUS
							plus.device.beep(2)
							// #endif
							errorTipMessage.value = msg
							errorTip.value.open()
							errorState.value = 0
						}
					})
			}

			const handleScanDevice = function() {
				// #ifdef APP-PLUS
				const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_code === 1000) {
							// 扫描设备
							uni.$reqPost('scanDevice', {
									hotPressId: params.value?.id,
									qrCode: ret.resp_result
								})
								.then(({
									code,
									data,
									msg
								}) => {
									if (code === 0) {
										if (data?.result * 1 === 0) {
											params.value.equipmentName = ''
											// #ifdef APP-PLUS
											plus.device.beep(2)
											// #endif
											errorTipMessage.value = data.message
											errorTip.value.open()
											errorState.value = 1
											return
										}
										params.value.equipmentName = data?.echoData
										params.value.deviceState = data?.result
										toolingInput.value.onBlur()
										toolingInput.value.onFocus()
									} else {
										// #ifdef APP-PLUS
										plus.device.beep(2)
										// #endif
										errorTipMessage.value = msg
										errorTip.value.open()
										errorState.value = 1
									}
								})
						}
					})
				// #endif
			}

			const confirmEquipmentName = function(e) {
				// 扫描设备
				uni.$reqPost('scanDevice', {
						hotPressId: params.value?.id,
						qrCode: e
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							if (data?.result * 1 === 0) {
								params.value.equipmentName = ''
								// #ifdef APP-PLUS
								plus.device.beep(2)
								// #endif
								errorTipMessage.value = data.message
								errorTip.value.open()
								errorState.value = 1
								return
							}
							params.value.equipmentName = data?.echoData
							params.value.deviceState = data?.result
							toolingInput.value.onBlur()
							toolingInput.value.onFocus()
						} else {
							// #ifdef APP-PLUS
							plus.device.beep(2)
							// #endif
							errorTipMessage.value = msg
							errorTip.value.open()
							errorState.value = 1
						}
					})
			}

			const handleScanTooling = function() {
				// #ifdef APP-PLUS
				const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_code === 1000) {
							// 扫描模具
							uni.$reqPost('scanTooling', {
									hotPressId: params.value?.id,
									qrCode: ret.resp_result
								})
								.then(({
									code,
									data,
									msg
								}) => {
									if (code === 0) {
										if (data?.result * 1 === 0) {
											params.value.toolingName = ''
											// #ifdef APP-PLUS
											plus.device.beep(2)
											// #endif
											errorTipMessage.value = data.message
											errorTip.value.open()
											errorState.value = 2
											return
										}
										params.value.toolingName = data?.echoData
										params.value.toolState = data?.result
										materialInput.value.onBlur()
										materialInput.value.onFocus()
									} else {
										// #ifdef APP-PLUS
										plus.device.beep(2)
										// #endif
										errorTipMessage.value = msg
										errorTip.value.open()
										errorState.value = 2
									}
								})
						}
					})
				// #endif
			}

			const confirmToolingName = function(e) {
				// 扫描模具
				uni.$reqPost('scanTooling', {
						hotPressId: params.value?.id,
						qrCode: e
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							if (data?.result * 1 === 0) {
								params.value.toolingName = ''
								// #ifdef APP-PLUS
								plus.device.beep(2)
								// #endif
								errorTipMessage.value = data.message
								errorTip.value.open()
								errorState.value = 2
								return
							}
							params.value.toolingName = data?.echoData
							params.value.toolState = data?.result
							materialInput.value.onBlur()
							materialInput.value.onFocus()
						} else {
							// #ifdef APP-PLUS
							plus.device.beep(2)
							// #endif
							errorTipMessage.value = msg
							errorTip.value.open()
							errorState.value = 2
						}
					})
			}

			const handleScanMaterialOrAxisNumber = function() {
				// #ifdef APP-PLUS
				const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
				mpaasScanModule.mpaasScan({
						// 扫码识别类型，参数可多选，qrCode、barCode，不设置，默认识别所有
						'scanType': ['qrCode', 'barCode'],
						// 是否隐藏相册，默认false不隐藏
						'hideAlbum': false
					},
					(ret) => {
						if (ret.resp_code === 1000) {
							if (nextScanState.value !== 'roll') {
								// 扫描物料
								uni.$reqPost('scanMaterialInfo', {
										hotPressId: params.value?.id,
										qrCode: ret.resp_result
									})
									.then(({
										code,
										data,
										msg
									}) => {
										if (code === 0) {
											// errorTipMessage.value = data?.message;
											// errorTip.value.open();

											if (data?.result * 1 === 1) {
												params.value.scanMaterialNumber = ret.resp_result
												params.value.materialNo = ret.resp_result
												// 存在两种情况，1：物料与轴号对应，2：只需扫物料
												// next等于2表示需要扫轴
												if (data?.next * 1 === 2) {
													nextScanState.value = 'roll'
												} else {
													nextScanState.value = 'batchNum'
													search()
												}
											} else {
												// #ifdef APP-PLUS
												plus.device.beep(2)
												// #endif
												errorTipMessage.value = data.message
												errorTip.value.open()
												errorState.value = 3
											}
										} else {
											// #ifdef APP-PLUS
											plus.device.beep(2)
											// #endif
											errorTipMessage.value = msg
											errorTip.value.open()
											errorState.value = 3
										}
									})
							} else {
								// 扫描轴号
								uni.$reqPost('scaRoll', {
										hotPressId: params.value?.id,
										materialQrCode: params.value.materialNo,
										rollQrCode: ret.resp_result
									})
									.then(({
										code,
										data,
										msg
									}) => {
										if (code === 0) {
											// errorTipMessage.value = data?.message;
											// errorTip.value.open();

											if (data?.result * 1 === 1) {
												if (data?.next * 1 === 1) {
													nextScanState.value = 'batchNum'
												}
												search()
											} else {
												// #ifdef APP-PLUS
												plus.device.beep(2)
												// #endif
												errorTipMessage.value = data.message
												errorTip.value.open()
												errorState.value = 3
											}
										} else {
											// #ifdef APP-PLUS
											plus.device.beep(2)
											// #endif
											errorTipMessage.value = msg
											errorTip.value.open()
											errorState.value = 3
										}
									})
							}
						}
					})
				// #endif
			}

			// 绑定物料/轴号
			const confirmMaterial = function(e) {
				if (nextScanState.value !== 'roll') {
					// 扫描物料
					uni.$reqPost('scanMaterialInfo', {
							hotPressId: params.value?.id,
							qrCode: e
						})
						.then(({
							code,
							data,
							msg
						}) => {
							if (code === 0) {
								// errorTipMessage.value = data?.message;
								// errorTip.value.open();

								if (data?.result * 1 === 1) {
									params.value.materialNo = e
									errorState.value = 3
									setInputFocus()
									// 存在两种情况，1：物料与轴号对应，2：只需扫物料
									// next等于2表示需要扫轴
									if (data?.next * 1 === 2) {
										nextScanState.value = 'roll'
									} else {
										nextScanState.value = 'batchNum'
										search()
									}
								} else {
									// #ifdef APP-PLUS
									plus.device.beep(2)
									// #endif
									errorTipMessage.value = data.message
									errorTip.value.open()
									errorState.value = 3
								}
							} else {
								// #ifdef APP-PLUS
								plus.device.beep(2)
								// #endif
								errorTipMessage.value = msg
								errorTip.value.open()
								errorState.value = 3
							}
						})
				} else {
					// 扫描轴号
					uni.$reqPost('scaRoll', {
							hotPressId: params.value?.id,
							materialQrCode: params.value.materialNo,
							rollQrCode: e
						})
						.then(({
							code,
							data,
							msg
						}) => {
							if (code === 0) {
								// errorTipMessage.value = data?.message;
								// errorTip.value.open();

								if (data?.result * 1 === 1) {
									errorState.value = 3
									setInputFocus()
									if (data?.next * 1 === 1) {
										nextScanState.value = 'batchNum'
									}
									search()
								} else {
									// #ifdef APP-PLUS
									plus.device.beep(2)
									// #endif
									errorTipMessage.value = data.message
									errorTip.value.open()
									errorState.value = 3
								}
							} else {
								// #ifdef APP-PLUS
								plus.device.beep(2)
								// #endif
								errorTipMessage.value = msg
								errorTip.value.open()
								errorState.value = 3
							}
						})
				}
			}

			// 送检
			const handleSubmission = function() {
				const month = new Date().getMonth() + 1
				const day = new Date().getDate()
				uni.$reqPost('createIPQCFormHotPress', {
						ipqcDate: new Date().getFullYear() + '' + (
							month < 10 ? ('0' +
								month) :
							month) + '' + (day < 10 ? ('0' + day) : day),
						mesHotPressId: params.value?.id,
						productionCode: '1605796881528524802'
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							uni.showToast({
								title: '送检成功',
								icon: 'none',
								duration: 2000
							})
							initChecked()
						} else {
							// #ifdef APP-PLUS
							plus.device.beep(2)
							// #endif
							errorTipMessage.value = msg
							errorTip.value.open()
							errorState.value = -1
						}
					})
			}

			const handleChangeRow = function(row) {
				Object.assign(rowEvent.value, {
					materialCode: row.materialCode,
					batchNum: row.batchNum,
					rollNo: row.rollNo,
					labelMasterId: row.labelMasterId ?? '',
					width: row.width ?? 0,
					residueLength: Math.ceil(((row.residueNumber * 1) / ((row.width * 1) * 0.001))).toFixed(5) ?? 0,
					// calculate: row.residueNumber ?? ''
				})
				popup.value.open()
			}

			const handleReportingWork = function() {
				let list = []
				// 卸料
				uni.$reqPost('ReportingWorkDischarge', {
						hotPressId: params.value?.id,
						batchNum: rowEvent.value.batchNum,
						materialCode: rowEvent.value.materialCode,
						calculate: Number(rowEvent.value.calculate)
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							// // #ifdef APP-PLUS
							// const Activity = plus.android.runtimeMainActivity();
							// const Intent = plus.android.importClass("android.content.Intent");
							// const Uri = plus.android.importClass("android.net.Uri");
							// const browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
							// 	`${uni.$baseUrl}/jmreport/view/821903765761437696?id=${data}`
							// ))
							// Activity.startActivity(browserIntent);
							// // #endif

							// // #ifdef H5
							// const dom = document.createElement('a');
							// dom.setAttribute("href",
							// 	`${uni.$baseUrl}/jmreport/view/821903765761437696?id=${data}`
							// );
							// dom.setAttribute("target", "_blank");
							// dom.click();
							// // #endif
							search()
							if (!isPrintLabel.value) {
								uni.showToast({
									title: '卸料成功',
									duration: 2000,
									icon: 'none'
								})
								return
							}
							uni.request({
								url: uni.$baseUrl + '/report/print/slittingPrintData',
								data: {
									id: rowEvent.value.labelMasterId
								}
							}).then(async ({
								data
							}) => {
								if (data.data?.length > 0) {
									uni.showToast({
										title: '标签打印中，请勿进行操作',
										duration: 10000,
										icon: 'none'
									})
									list = data.data
									if (list.length > 0) {
										blueConfig.value.currentPrint = 1
										blueConfig.value.printNum = list.length

										const timer = setInterval(async () => {
											const currentPrint = blueConfig.value
												.currentPrint - 1
											if (blueConfig.value.isLabelSend ===
												false &&
												currentPrint <
												blueConfig.value.printNum) {
												const paramsObj = {
													materialName: list[
															currentPrint]
														.materialName ?? '',
													materialNo: list[
															currentPrint]
														.materialNo ??
														'',
													supplierName: list[
															currentPrint]
														.supplierName ??
														'',
													size: list[currentPrint]
														.size ??
														'',
													createTime: list[
															currentPrint]
														.createTime ??
														'',
													materialLots: list[
															currentPrint]
														.materialLots ??
														'',
													wmsStockLocationName: list[
															currentPrint]
														.wmsStockLocationName ??
														'',
													validityDate: list[
															currentPrint]
														.validityDate ??
														'',
													inspectTime: list[
															currentPrint]
														.inspectTime ??
														'',
													storageEnvironment: list[
															currentPrint]
														.storageEnvironment ??
														'',
													slittingOrderNo: list[
															currentPrint]
														.slittingOrderNo ??
														'',
													produceDate: list[
															currentPrint]
														.produceDate ??
														'',
													batchNumber: list[
															currentPrint]
														.batchNumber ??
														'',
													qty: list[currentPrint]
														.qty ??
														''
												}
												await cuttingLabelTest(paramsObj)
											}
											if (currentPrint === blueConfig.value
												.printNum) {
												await clearInterval(timer)
											}
										}, 3000)
									}
								} else {
									uni.showToast({
										title: '打印数据错误',
										icon: 'none',
										duration: 2000
									})
								}
							})
						} else {
							// #ifdef APP-PLUS
							plus.device.beep(2)
							// #endif
							errorTipMessage.value = msg
							errorTip.value.open()
							errorState.value = -1
						}
					})
			}

			const handleNavigate = function() {
				uni.navigateTo({
					url: '/pages/workbranch/production/processExecution/takePhoto'
				})
			}

			const handleShowDayModal = function() {
				if (dayModal.value?.showPopup === false) {
					dayModal.value.open('bottom')
				}
			}

			// 班别列表选择事件
			const handleClickDay = function(ret) {
				className.value = ret.value
				handleValidataPrint()
				dayModal.value.close()
			}

			// 分切打印测试
			const cuttingLabelTest = async function(ret) {
				var command = tsc.dlabelPrinter.createNew()
				command.setBackFeed(6)
				// (640 * 320)dots
				command.setSize(80, 40)
				command.setCls()
				command.setGap(8)
				command.setBox(0, 0, 635, 315, 1)
				command.setBar(0, 40, 640, 2)
				command.setBar(0, 80, 640, 2)
				command.setBar(0, 120, 640, 2)
				command.setBar(0, 160, 640, 2)
				command.setBar(0, 200, 366, 2)
				command.setBar(0, 240, 366, 2)
				command.setBar(0, 280, 640, 2)
				// 1
				command.setBar(115, 0, 2, 40)
				command.setBar(115, 40, 2, 40)
				command.setBar(115, 80, 2, 40)
				command.setBar(115, 120, 2, 40)
				command.setBar(115, 160, 2, 40)
				command.setBar(115, 200, 2, 40)
				command.setBar(115, 240, 2, 40)
				command.setBar(115, 280, 2, 40)
				// 2
				command.setBar(360, 40, 2, 40)
				command.setBar(360, 80, 2, 40)
				command.setBar(360, 120, 2, 40)
				command.setBar(360, 160, 2, 40)
				command.setBar(360, 200, 2, 40)
				command.setBar(360, 240, 2, 40)
				command.setBar(360, 280, 2, 40)
				// 3
				command.setBar(475, 40, 2, 40)
				command.setBar(475, 80, 2, 40)
				command.setBar(475, 120, 2, 40)
				command.setBar(475, 280, 2, 40)

				command.setText(10, 6, 'TSS24.BF2', 0, 1, 1, '物料名称')
				command.setText(126, 6, 'TSS24.BF2', 0, 1, 1, ret.materialName)
				// row2
				command.setText(10, 46, 'TSS24.BF2', 0, 1, 1, '物料编码')
				command.setText(126, 46, 'TSS24.BF2', 0, 1, 1, ret.materialNo)
				command.setText(366, 46, 'TSS24.BF2', 0, 1, 1, '供应商')
				command.setText(481, 46, 'TSS24.BF2', 0, 1, 1, ret.supplierName)
				// row3
				command.setText(10, 86, 'TSS24.BF2', 0, 1, 1, '物料规格')
				command.setText(126, 86, 'TSS24.BF2', 0, 1, 1, ret.size)
				command.setText(366, 86, 'TSS24.BF2', 0, 1, 1, '分切日期')
				command.setText(481, 86, 'TSS24.BF2', 0, 1, 1, ret.createTime)
				// row4
				command.setText(10, 126, 'TSS24.BF2', 0, 1, 1, 'Lot no.')
				command.setText(126, 126, '1', 0, 1, 1, ret.materialLots)
				command.setText(366, 126, 'TSS24.BF2', 0, 1, 1, '储位')
				command.setText(481, 126, 'TSS24.BF2', 0, 1, 1, ret.wmsStockLocationName)
				// row5
				command.setText(10, 166, 'TSS24.BF2', 0, 1, 1, '有效期')
				command.setText(126, 166, 'TSS24.BF2', 0, 1, 1, ret.validityDate)
				// row6
				command.setText(10, 206, 'TSS24.BF2', 0, 1, 1, '检测日期')
				command.setText(126, 206, 'TSS24.BF2', 0, 1, 1, ret.inspectTime)
				// row7
				command.setText(10, 246, 'TSS24.BF2', 0, 1, 1, '存储条件')
				const strList = ret.storageEnvironment?.split(' ')
				const strText = strList[0] + ' ' + strList[1]
				command.setText(126, 246, 'TSS24.BF2', 0, 1, 1, strText)
				// row8
				command.setText(10, 286, 'TSS24.BF2', 0, 1, 1, '分切单号')
				command.setText(126, 286, 'TSS24.BF2', 0, 1, 1, ret.slittingOrderNo)
				command.setText(366, 286, 'TSS24.BF2', 0, 1, 1, '生产日期')
				command.setText(481, 286, 'TSS24.BF2', 0, 1, 1, ret.produceDate)

				command.setText(480, 216, '2', 0, 1, 1, ret.qty)
				command.setQrcode(366, 166, 'L', 4, 'A', ret.batchNumber)
				command.setPagePrint()
				prepareSend(command.getData())
			}

			const Send = function(buff) {
				var currentTime = blueConfig.value.currentTime
				var loopBuffer = blueConfig.value.loopBuffer
				var lastData = blueConfig.value.lastData
				var onBufferSize = blueConfig.value.onBufferSize
				var printNum = blueConfig.value.printerNum
				var currentPrint = blueConfig.value.currentPrint
				var buf
				var dataView
				if (currentTime < loopBuffer) {
					buf = new ArrayBuffer(onBufferSize)
					dataView = new DataView(buf)
					for (let i = 0; i < onBufferSize; ++i) {
						dataView.setUint8(i, buff[(currentTime - 1) * onBufferSize + i])
					}
				} else {
					buf = new ArrayBuffer(lastData)
					dataView = new DataView(buf)
					for (let i = 0; i < lastData; ++i) {
						dataView.setUint8(i, buff[(currentTime - 1) * onBufferSize + i])
					}
				}
				plus.bluetooth.writeBLECharacteristicValue({
					deviceId: bluetooth.value.deviceId,
					serviceId: bluetooth.value.serviceId,
					characteristicId: bluetooth.value.writeId,
					value: buf,
					success: function(res) {
						if (currentPrint <= printNum) {
							wx.showToast({
								title: '数据打印中',
								icon: 'loading'
							})
						}
						// 将complete中处理数据的代码挪过来，增加30ms延迟, 解决蓝牙打印数据传输10007问题
						setTimeout(() => {
							currentTime += 1
							if (currentTime <= loopBuffer) {
								blueConfig.value.isLabelSend = true
								blueConfig.value.currentTime = currentTime
								Send(buff)
							}
							// end
							if (currentTime === loopBuffer) {
								blueConfig.value.currentPrint += 1
								blueConfig.value.isLabelSend = false
							}
						}, 10)
					},
					fail: function(e) {
						wx.showToast({
							title: '打印第' + currentPrint + '张失败' + 'error: code ' + e
								?.code + ', message ' + e?.message,
							icon: 'none',
							duration: 4000
						})
					},
					complete: function() {}
				})
			}

			const prepareSend = function(buff) {
				var time = blueConfig.value.onBufferSize
				var loopBuffer = parseInt(buff.length / time)
				var lastData = parseInt(buff.length % time)
				blueConfig.value.loopBuffer = loopBuffer + 1
				blueConfig.value.lastData = lastData
				blueConfig.value.currentTime = 1
				Send(buff)
			}

			const labelTest = function(ret) {
				var command = tsc.dlabelPrinter.createNew()
				command.setBackFeed(6)
				// (480 * 200)dots
				command.setSize(60, 25)
				command.setCls()
				command.setGap(6)
				command.setBox(0, 0, 475, 200, 1)
				// 1
				command.setBar(108, 0, 2, 40)
				command.setBar(108, 40, 2, 40)
				command.setBar(108, 80, 2, 40)
				command.setBar(108, 120, 2, 40)
				command.setBar(108, 160, 2, 40)
				command.setBar(108, 200, 2, 40)
				// 竖
				command.setBar(210, 80, 2, 40)
				command.setBar(210, 120, 2, 40)
				command.setBar(210, 160, 2, 40)
				command.setBar(210, 200, 2, 40)
				// 横
				command.setBar(0, 40, 480, 2)
				command.setBar(0, 80, 320, 2)
				command.setBar(0, 120, 210, 2)
				command.setBar(0, 160, 210, 2)
				// 横
				command.setBar(320, 80, 480, 2)
				command.setBar(320, 120, 480, 2)
				command.setBar(320, 160, 480, 2)
				// 竖
				command.setBar(322, 40, 2, 40)
				command.setBar(322, 80, 2, 40)
				command.setBar(322, 120, 2, 40)
				command.setBar(322, 160, 2, 40)
				// 竖
				command.setBar(378, 40, 2, 40)
				command.setBar(378, 80, 2, 40)
				command.setBar(378, 120, 2, 40)
				command.setBar(378, 160, 2, 40)

				// row1
				command.setText(4, 8, 'TSS24.BF2', 0, 1, 1, '料号')
				command.setText(112, 10, '2', 0, 1, 1, ret.materialName)
				// row2
				command.setText(4, 48, 'TSS24.BF2', 0, 1, 1, '工令单')
				command.setText(112, 50, '2', 0, 1, 1, ret.wordOrderNo)
				command.setText(328, 48, 'TSS24.BF2', 0, 1, 1, '数量')
				command.setText(384, 50, '2', 0, 1, 1, ret.qty)
				// row3
				command.setText(4, 88, 'TSS24.BF2', 0, 1, 1, '生产日期')
				command.setText(110, 90, '1', 0, 1, 1, ret.dateOfManufacture)
				command.setText(328, 88, 'TSS24.BF2', 0, 1, 1, '库位')
				command.setText(384, 90, '1', 0, 1, 1, ret.storageLocation)
				// row4
				command.setText(4, 128, 'TSS24.BF2', 0, 1, 1, '供应商')
				command.setText(112, 130, '3', 0, 1, 1, ret.vendor)
				command.setText(328, 128, 'TSS24.BF2', 0, 1, 1, '后制')
				command.setText(384, 130, '1', 0, 1, 1, ret.postProduction)
				// row5
				command.setText(4, 168, 'TSS24.BF2', 0, 1, 1, '包装')
				command.setText(112, 170, '1', 0, 1, 1, ret.packaging)
				command.setText(328, 168, 'TSS24.BF2', 0, 1, 1, 'QC')
				command.setText(384, 170, '1', 0, 1, 1, ret.qc)

				command.setQrcode(214, 88, 'L', 5, 'A', ret.qrCode)
				command.setPagePrint()
				prepareSend(command.getData())
			}

			const handleLabelPrint = function() {
				let list = []
				const submitParams = {
					hotPressId: params.value?.id
				}
				if (![null, NaN, undefined, ''].includes(className.value)) {
					submitParams.classFlag = className.value
				}
				if (![null, NaN, undefined, ''].includes(qty.value)) {
					submitParams.qty = qty.value
				}
				// 打印确认
				uni.$reqPost('printConfirm', submitParams)
					.then(async ({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							uni.showToast({
								title: data?.message,
								icon: 'none',
								duration: 2000
							})
							if (data?.result * 1 === 1) {
								uni.request({
									method: 'GET',
									url: uni.$baseUrl + '/report/print/getPrintDataFeol',
									data: {
										hotPressId: params.value?.id
									}
								}).then(async ({
									data: {
										code,
										data,
										msg
									}
								}) => {
									if (code === 0) {
										uni.showToast({
											title: '标签打印中，请勿操作',
											duration: 10000,
											icon: 'none'
										})
										list = data
										if (list.length > 0) {
											blueConfig.value.currentPrint = 1
											blueConfig.value.printNum = list.length

											const timer = setInterval(async () => {
												const currentPrint = blueConfig
													.value.currentPrint - 1
												if (blueConfig.value
													.isLabelSend === false &&
													currentPrint <
													blueConfig.value.printNum
												) {
													const paramsObj = {
														pn: list[
																currentPrint
															]
															.pn ?? '',
														wordOrderNo: list[
																currentPrint
															]
															.wordOrderNo ??
															'',
														qty: list[
																currentPrint
															]
															.qty ??
															'',
														dateOfManufacture: list[
																currentPrint
															]
															.dateOfManufacture ??
															'',
														storageLocation: list[
																currentPrint
															]
															.storageLocation ??
															'',
														postProduction: list[
																currentPrint
															]
															.postProduction ??
															'',
														vendor: list[
																currentPrint
															]
															.vendor ??
															'',
														packaging: list[
																currentPrint
															]
															.packaging ??
															'',
														qc: list[
																currentPrint
															]
															.qc ??
															'',
														qrCode: list[
																currentPrint
															]
															.qrCode ??
															''
													}
													await labelTest(paramsObj)
												}
												if (currentPrint === blueConfig
													.value.printNum) {
													await clearInterval(timer)
												}
											}, 3000)
										}
									} else {
										// #ifdef APP-PLUS
										plus.device.beep(2)
										// #endif
										errorTipMessage.value = msg
										errorTip.value.open()
										errorState.value = -1
									}
								})
							}
							await search()
						} else {
							// #ifdef APP-PLUS
							plus.device.beep(2)
							// #endif
							errorTipMessage.value = msg
							errorTip.value.open()
							errorState.value = -1
						}
					})
			}

			const handleValidataPrint = function(dictValue) {
				console.log(dictValue)
				uni.$reqGet('getHotProcessProductionNum', {
						id: params.value?.id
					})
					.then(({
						code,
						data,
						msg
					}) => {
						if (code === 0) {
							qty.value = data?.numberOfPieces ?? 0
							inputDialog.value.open()
						}
					})
			}

			const setInputFocus = function() {
				if (errorState.value === 0) {
					params.value.userName = ''
					userInput.value.onBlur()
					userInput.value.onFocus()
				} else if (errorState.value === 1) {
					params.value.equipmentName = ''
					equipmentInput.value.onBlur()
					equipmentInput.value.onFocus()
				} else if (errorState.value === 2) {
					params.value.toolingName = ''
					toolingInput.value.onBlur()
					toolingInput.value.onFocus()
				} else if (errorState.value === 3) {
					params.value.scanMaterialNumber = ''
					materialInput.value.onBlur()
					materialInput.value.onFocus()
				}
			}

			// 关闭错误信息弹窗
			const handleCloseErrorTipsModal = async function() {
				errorTip.value.close()
				await setInputFocus()
			}

			const handleInputFocus = function(text) {
				setTimeout(() => {
					uni.hideKeyboard()
				}, 100)
				emptyDocument.value ? emptyDocument.value.$el.className = 'uni-easyinput' : false
				if (text === 'userInput') {
					userInput.value.$el.className = 'uni-easyinput light-focus'
					emptyDocument.value = userInput.value
				}
				if (text === 'equipmentInput') {
					equipmentInput.value.$el.className = 'uni-easyinput light-focus'
					emptyDocument.value = equipmentInput.value
				}
				if (text === 'toolingInput') {
					toolingInput.value.$el.className = 'uni-easyinput light-focus'
					emptyDocument.value = toolingInput.value
				}
				if (text === 'materialInput') {
					materialInput.value.$el.className = 'uni-easyinput light-focus'
					emptyDocument.value = materialInput.value
				}
			}

			const handleClear = function(text) {
				if (text === 'userInput') {
					userInput.value.onBlur()
					userInput.value.onFocus()
				}
				if (text === 'equipmentInput') {
					equipmentInput.value.onBlur()
					equipmentInput.value.onFocus()
				}
				if (text === 'toolingInput') {
					toolingInput.value.onBlur()
					toolingInput.value.onFocus()
				}
				if (text === 'materialInput') {
					materialInput.value.onBlur()
					materialInput.value.onFocus()
				}
			}

			// 设置标签生产数量
			const handleSetNum = function(ret) {
				if (![NaN, undefined, null, ''].includes(Number(ret))) {
					qty.value = ret
				} else {
					// #ifdef APP-PLUS
					plus.device.beep(2)
					// #endif
					errorTipMessage.value = '数量不正确!'
					errorTip.value.open()
					errorState.value = 3
					return
				}
				handleLabelPrint()
			}

			// 是否打标签单选框触发事件
			const handlePrintLabelChecked = function(e) {
				const checked = e.detail.value
				if (checked?.length > 0) {
					isPrintLabel.value = true
				} else {
					isPrintLabel.value = false
				}
			}

			return {
				popup,
				goBack,
				dayModal,
				modalForm,
				errorState,
				errorTip,
				errorTipMessage,
				userInput,
				equipmentInput,
				toolingInput,
				materialInput,
				isPrintLabel,
				qty,
				rowEvent,
				btnState,
				isLandscapeScreen,
				params,
				inputDialog,
				dictDataList,
				handleInputFocus,
				handleClear,
				computedResidualArea,
				computedRollNo,
				computedIPQCState,
				computedCollapseTitle,
				handleSubmission,
				handleShowDayModal,
				handleValidataPrint,
				handleScanUser,
				handleScanDevice,
				handleScanTooling,
				handleReportingWork,
				handleSetNum,
				confirmUser,
				confirmEquipmentName,
				confirmToolingName,
				confirmMaterial,
				handleScanMaterialOrAxisNumber,
				handleCloseErrorTipsModal,
				handleChangeRow,
				handleNavigate,
				handleClickDay,
				handlePrintLabelChecked
			}
		}
	})
</script>

<style lang="scss" scoped>
	.gui-header-leader-btns {
		color: black;
		font-size: 24px !important;
		margin-left: 24rpx;
	}

	.gui-sbody {
		background-color: rgba(234, 239, 242, 1);
	}

	.gui-relative {
		overflow: visible;
		height: 100vh;

		.oqc-checkout {
			width: 100vw;
			height: calc(100vh - 75px);
			position: absolute;
			top: 95px;
			overflow-y: scroll;
		}
	}

	.popup-content {
		width: 100vw;
		height: 55vh;
		overflow-y: scroll;
	}

	.card-list-flexbox-popup {
		width: 100vw;
		display: flex;
		flex-direction: row;
		align-items: center;
		flex-wrap: wrap;

		.card-list-item,
		.card-list-item-input {
			width: 100vw;
			height: 100%;
			min-height: 40px;
			display: flex;
			flex-direction: row;
			align-items: center;
			background-color: #fff;

			uni-text {
				font-size: 14px;
				height: 50rpx;
				text-align: left;
				padding: 0 12px;
				display: flex;
				flex-direction: row;
				align-items: center;
			}

			uni-image {
				width: calc(100vw / 2 - 4px);
				height: calc(100vw / 3.2 - 2px);
				pointer-events: none;
			}

			uni-image::after {
				content: "×";
				width: 22px;
				height: 22px;
				position: absolute;
				top: 5px;
				right: 5px;
				display: flex;
				justify-content: center;
				align-items: center;
				color: rgba(255, 255, 255, 0.9);
				background-color: rgba(0, 0, 0, 0.5);
				border-radius: 50%;
				font-size: 24px;
				/*给伪元素开启鼠标事件，将事件冒泡到父元素的点击事件中*/
				pointer-events: auto;
			}

			.text-1 {
				flex: 1;
				height: 40px;
				justify-content: flex-start;
			}

			.text-2 {
				flex: 3;
				height: 40px;
				justify-content: flex-end;
				margin-right: 4px;
				padding: 2px 6px;
			}

			.text-3 {
				width: calc(100% - 15%);
				min-height: 35px;
				justify-content: flex-end;
				padding: 2px 6px;
			}

			.text-3::before {}

			.btn-mg {
				margin: 0 5px;
			}
		}

		.card-list-item {
			justify-content: center;
		}

		.card-list-item-input {
			margin: 10px 0 10px 2%;
			display: flex;
			flex-direction: column;

			uni-view {
				width: 100%;
				height: 100%;
				display: flex;

				uni-textarea {
					flex: 8;
				}

				uni-view {
					flex: 1;
				}

				.operation-icon,
				.operation-icon-2 {
					height: auto;

					uni-text {
						width: 22px;
						height: 100%;
						padding: 0 !important;
						text-align: center;
						display: flex;
						justify-content: center;
						align-items: center;
						border-top-right-radius: 4px;
						border-bottom-right-radius: 4px;
						color: white;
						background-color: #80b7ff;
					}
				}

				.operation-icon-2 {
					uni-text {
						background-color: #ff5962;
					}
				}

			}
		}

		.grid-image {
			/* 设置容器布局为grid布局 */
			display: grid;
			/* 指定每一行的宽度 每个宽度中间用空格隔开 */
			grid-template-rows: repeat(auto-fill, 1fr);
			/* 指定每一列的宽度 每个宽度中间用空格隔开 */
			grid-template-columns: repeat(2, 1fr);
			padding: 0 4px;
		}

		.card-list-item:nth-of-type(1) {

			.text-1 {
				flex: 9;
				font-weight: bold;
				color: black !important;
			}

			.text-1::before {
				content: "";
				width: 4px;
				height: 20px;
				border-radius: 4px;
				margin-right: 4px;
				background-color: skyblue;
			}

			.text-2 {
				flex: 4;
				display: flex;
				flex-direction: row;
				justify-content: flex-end;
				align-items: center;
				color: limegreen !important;
			}
		}

	}

	.table-title {
		height: 40px;
		line-height: 40px;
		margin: 0 0 -3px 0;
		padding: 0 12px;
		font-size: 16px;
		font-weight: bold;
		background-color: white;
	}

	.uni-list-cell {
		width: 100vw;
		height: 35px;
		margin: 4px 0;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		border-bottom: 2px solid #eaeff2;
		background-color: #fff;

		view {
			font-size: 14px;
			height: 50rpx;
			text-align: left;
			padding: 0 8px;
			display: flex;
			flex-direction: row;
			align-items: center;
		}

		.uni-list-cell-left {
			flex: 1;
			height: 35px;
			justify-content: flex-start;
		}

		.uni-list-cell-db {
			flex: 3;
			height: 35px;
			justify-content: flex-end;
			margin-right: 4px;
			padding: 2px 6px;

			uni-picker {
				width: 100%;
				display: flex;
				flex-direction: row;
				justify-content: center;
			}
		}
	}

	.modal-btns {
		height: 100rpx;
		line-height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.line {
		margin-top: 10rpx;
		height: 80rpx;
		width: 1rpx;
		background-color: #dcdcdc;
	}

	.card-list {
		display: grid;
		grid-template-rows: 1fr;
		grid-template-columns: 1fr 1fr;
		background-color: white;

		.card {
			display: grid;
			grid-template-rows: 1fr;
			grid-template-columns: 2fr 5fr;
			height: 45px;

			span {
				font-size: 14px;
				font-weight: bold;
				text-align: center;
				line-height: 45px;
			}

			uni-input {
				height: 45px;
				display: flex;
				align-items: center;
			}
		}
	}

	.font-icons {
		width: 30px;
		font-size: 20px;
		text-align: right;
	}

	.scan {
		height: 45px;
		width: calc(100% - 48px);
		margin: 0 12px 12px 12px;
		padding: 0 12px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-radius: 6px;
		background-color: white;

		.scan-title {
			width: 100%;
			display: grid;
			grid-template-rows: 1fr;
			grid-template-columns: 1fr 1fr;
			align-items: center;

			span {
				font-size: 14px;
				font-weight: bold;
			}

			span:nth-of-type(2) {
				text-align: right;
			}
		}

		.scan-card {
			width: 100%;
			display: grid;
			grid-template-rows: 1fr;
			grid-template-columns: 2fr 6fr 1fr;
			align-items: center;

			span {
				font-size: 14px;
				font-weight: bold;
			}

			input {
				height: 35px;
				line-height: 35px;
			}

			text {
				width: 100%;
				text-align: right;
			}
		}
	}

	.body-card {
		width: calc(100% - 48px);
		margin: 0 12px 12px 12px;
		padding: 0 12px;
		display: grid;
		grid-template-columns: 1fr;
		grid-template-rows: 1fr 1fr;
		border-radius: 6px;
		background-color: white;

		.body-card-row {
			height: 35px;
			line-height: 35px;
			display: flex;
			justify-content: space-between;
		}
	}

	.collapse {
		width: 100%;
		display: flex;
		align-items: center;

		.collapse-title {
			height: 90px;
			width: 80%;
			padding: 0 12px;
			display: grid;
			grid-template-columns: 1fr;
			grid-template-rows: 1fr 1fr;

			uni-text {
				display: inline-block;
				height: 45px;
				line-height: 45px;
				font-size: 14px;
			}
		}
	}

	.example-body {
		flex-direction: column;
		flex: 1;
	}


	.form {
		font-size: 14px;
		margin: 0 12px 80px 12px;
		padding: 4px 8px;
		border-radius: 4px;
		background-color: white;

		.form-title {
			height: 32px;
			line-height: 32px;
			text-align: center;
			font-size: 16px;
			font-weight: bold;
			border-bottom: 2px dashed #edeeee;
		}

		.form-item {
			.title {
				height: 32px;
				line-height: 32px;
				text-align: left;
				font-weight: bold;
				color: #333;
			}

			.content {
				height: 42px;
				line-height: 42px;
				margin: 0 0 6px 0;
			}
		}
	}

	.title-text-layout {
		height: 45px;
		line-height: 45px;
		font-size: 14px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		-o-text-overflow: ellipsis;
	}

	.popup-process-content {
		width: 100vw;
		height: 85vh;
		overflow-y: scroll;

		.list-title {
			// position: fixed;
			// top: 0;
			// left: 0;
			// z-index: 99999;
			display: flex;
			align-items: center;
			height: 45px;
			line-height: 45px;
			font-size: 16px;
			font-weight: bold;
			border-top-left-radius: 16px;
			border-top-right-radius: 16px;
			border-bottom: 2px solid #d4d4d4;

			.block {
				width: 6px;
				height: 60%;
				margin: 0 4px;
				background-color: rgb(0, 160, 233);
			}
		}

		.grid-box {
			display: grid;
			grid-template-columns: 1fr 1fr 1fr 1fr;
			
			.box {
				position: relative;
				height: 40px;
				padding: 10px 6px;
				border: 1px solid rgb(250, 250, 251);
				box-sizing: border-box;
				margin: 12px;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 14px;
				font-weight: bold;
				border-radius: 4px;
				color: white;
				box-shadow: 0 3px 6px 0 rgba(121, 118, 118, 0.34);
				background-color: rgb(0, 160, 233);
			}
			
			.box::before {
				content: '';
				position: absolute;
				top: 20px;
				left: 0;
				bottom: 0;
				transform: translate(-50%, -50%);
				width: 12px;
				height: 12px;
				border-radius: 50%;
				z-index: 1;
				background-color: #ffffff;
			}
		}
	}

	.light-focus {
		border: 1px solid #008aff;
		border-radius: 6px !important;

		::v-deep .uni-easyinput__content {
			border-radius: 6px !important;
		}
	}

	.light-focus::before {
		position: absolute;
		left: -10px;
		top: -10px;
		content: "✏️";
		width: 20px;
		height: 20px;
		color: red;
		font-weight: bold;
		font-size: 18px;
	}

	.operationBtn {
		position: fixed;
		display: grid;
		grid-template-rows: 1fr;
		grid-template-columns: 1fr 1fr;
		width: 100%;
		bottom: 0;
		padding: 12px 0;
	}
</style>