| | |
| | | placeholder="请选择设备名称" |
| | | @click="showDevicePicker" |
| | | clearable |
| | | readonly="" |
| | | /> |
| | | <template #right> |
| | | <u-icon name="scan" @click="startScan" class="scan-icon" /> |
| | |
| | | if (code == 200) { |
| | | form.value.deviceLedgerId = data.deviceLedgerId; |
| | | form.value.deviceModel = data.deviceModel; |
| | | form.value.repairTime = data.repairTime; |
| | | form.value.repairTime = dayjs(data.repairTime).format("YYYY-MM-DD"); |
| | | form.value.repairName = data.repairName; |
| | | form.value.remark = data.remark; |
| | | // 设置设备名称显示 |
| | |
| | | // 新增模式 |
| | | operationType.value = 'add'; |
| | | } |
| | | }; |
| | | |
| | | // 清除表单校验状态 |
| | | const clearValidate = () => { |
| | | formRef.value?.clearValidate(); |
| | | }; |
| | | |
| | | // 重置表单数据和校验状态 |
| | | const resetForm = () => { |
| | | form.value = { |
| | | deviceLedgerId: undefined, |
| | | deviceModel: undefined, |
| | | repairTime: dayjs().format("YYYY-MM-DD"), |
| | | repairName: undefined, |
| | | remark: undefined, |
| | | }; |
| | | deviceNameText.value = ''; |
| | | }; |
| | | |
| | | // 扫描二维码功能 |
| | |
| | | } |
| | | |
| | | isScanning.value = true; |
| | | showToast('扫码成功,3秒后自动填充设备信息'); |
| | | showToast('扫码成功'); |
| | | |
| | | // 3秒后处理扫码结果 |
| | | scanTimer.value = setTimeout(() => { |
| | | processScanResult(scanResult); |
| | | isScanning.value = false; |
| | | }, 3000); |
| | | }, 100); |
| | | }; |
| | | function getDeviceIdByRegExp(url) { |
| | | // 匹配deviceId=后面的数字 |
| | | const reg = /deviceId=(\d+)/; |
| | | const match = url.match(reg); |
| | | // 如果匹配到结果,返回数字类型,否则返回null |
| | | return match ? Number(match[1]) : null; |
| | | } |
| | | |
| | | // 处理扫码结果并匹配设备 |
| | | const processScanResult = (scanResult) => { |
| | | // 在设备列表中查找匹配的设备 |
| | | // 假设二维码内容是设备名称或设备编号 |
| | | const matchedDevice = deviceOptions.value.find(device => |
| | | device.deviceName === scanResult || |
| | | device.deviceCode === scanResult || |
| | | device.id.toString() === scanResult |
| | | ); |
| | | const deviceId = getDeviceIdByRegExp(scanResult); |
| | | const matchedDevice = deviceOptions.value.find(item => item.id == deviceId); |
| | | |
| | | if (matchedDevice) { |
| | | // 找到匹配的设备,自动填充 |
| | |
| | | // 确认日期选择 |
| | | const onDateConfirm = (e) => { |
| | | form.value.repairTime = formatDateToYMD(e.value); |
| | | pickerDateValue.value = dayjs(e.value).format("YYYY-MM-DD"); |
| | | showDate.value = false; |
| | | }; |
| | | |
| | |
| | | |
| | | // 返回上一页 |
| | | const goBack = () => { |
| | | uni.removeStorageSync('repairId'); |
| | | uni.navigateBack(); |
| | | }; |
| | | |
| | | // 获取页面参数 |
| | | const getPageParams = () => { |
| | | const pages = getCurrentPages(); |
| | | const currentPage = pages[pages.length - 1]; |
| | | const options = currentPage.options; |
| | | // 使用uni.getStorageSync获取id |
| | | const id = uni.getStorageSync('repairId'); |
| | | |
| | | // 根据是否有id参数来判断是新增还是编辑 |
| | | if (options.id) { |
| | | if (id) { |
| | | // 编辑模式,获取详情 |
| | | loadForm(options.id); |
| | | loadForm(id); |
| | | // 可选:获取后清除存储的id,避免影响后续操作 |
| | | // uni.removeStorageSync('repairId'); |
| | | } else { |
| | | // 新增模式 |
| | | loadForm(); |
| | |
| | | |
| | | // 获取页面ID |
| | | const getPageId = () => { |
| | | const pages = getCurrentPages(); |
| | | const currentPage = pages[pages.length - 1]; |
| | | const options = currentPage.options; |
| | | return options.id; |
| | | // 使用uni.getStorageSync获取id |
| | | const id = uni.getStorageSync('repairId'); |
| | | return id; |
| | | }; |
| | | </script> |
| | | |