| | |
| | | </template> |
| | | </u-form-item> |
| | | |
| | | <u-form-item label="保养项目" prop="maintenanceLocation" border-bottom> |
| | | <u-input |
| | | v-model="form.maintenanceLocation" |
| | | placeholder="请输入保养项目" |
| | | clearable |
| | | /> |
| | | </u-form-item> |
| | | |
| | | <!-- 提交按钮 --> |
| | | <view class="footer-btns"> |
| | | <u-button class="cancel-btn" @click="goBack">取消</u-button> |
| | |
| | | deviceLedgerId: undefined, // 设备ID |
| | | deviceModel: undefined, // 规格型号 |
| | | maintenancePlanTime: dayjs().format("YYYY-MM-DD"), // 计划保养日期 |
| | | maintenanceLocation: undefined, // 保养项目 |
| | | }); |
| | | |
| | | // 加载设备列表 |
| | |
| | | form.value.deviceLedgerId = data.deviceLedgerId; |
| | | form.value.deviceModel = data.deviceModel; |
| | | form.value.maintenancePlanTime = dayjs(data.maintenancePlanTime).format("YYYY-MM-DD"); |
| | | form.value.maintenanceLocation = data.maintenanceLocation; |
| | | // 设置设备名称显示 |
| | | const device = deviceOptions.value.find(item => item.id === data.deviceLedgerId); |
| | | if (device) { |
| | |
| | | } |
| | | |
| | | isScanning.value = true; |
| | | showToast('扫码成功,3秒后自动填充设备信息'); |
| | | showToast('扫码成功'); |
| | | |
| | | // 3秒后处理扫码结果 |
| | | scanTimer.value = setTimeout(() => { |
| | | processScanResult(scanResult); |
| | | isScanning.value = false; |
| | | }, 3000); |
| | | }, 1000); |
| | | }; |
| | | |
| | | 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 goBack = () => { |
| | | // 清除存储的id |
| | | uni.removeStorageSync('repairId'); |
| | | uni.navigateBack(); |
| | | }; |
| | | |
| | | // 获取页面参数 |
| | | const getPageParams = () => { |
| | | const pages = getCurrentPages(); |
| | | const currentPage = pages[pages.length - 1]; |
| | | const options = currentPage.options; |
| | | // 从本地存储获取id |
| | | const id = uni.getStorageSync('repairId'); |
| | | |
| | | // 根据是否有id参数来判断是新增还是编辑 |
| | | if (options.id) { |
| | | if (id) { |
| | | // 编辑模式,获取详情 |
| | | loadForm(options.id); |
| | | loadForm(id); |
| | | } else { |
| | | // 新增模式 |
| | | loadForm(); |
| | |
| | | |
| | | // 获取页面ID |
| | | const getPageId = () => { |
| | | const pages = getCurrentPages(); |
| | | const currentPage = pages[pages.length - 1]; |
| | | const options = currentPage.options; |
| | | return options.id; |
| | | // 从本地存储获取id |
| | | return uni.getStorageSync('repairId'); |
| | | }; |
| | | </script> |
| | | |