From 91af6caf5a797bcc912e9a22656c97775bd4a198 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期五, 05 九月 2025 11:20:16 +0800 Subject: [PATCH] 设备保养、设备维修真机测试,bug修改 --- src/pages/equipmentManagement/upkeep/add.vue | 195 ++++++++++++++++++++++-------------------------- 1 files changed, 88 insertions(+), 107 deletions(-) diff --git a/src/pages/equipmentManagement/upkeep/add.vue b/src/pages/equipmentManagement/upkeep/add.vue index c9fe45f..8dedb1b 100644 --- a/src/pages/equipmentManagement/upkeep/add.vue +++ b/src/pages/equipmentManagement/upkeep/add.vue @@ -4,68 +4,66 @@ <PageHeader :title="operationType === 'edit' ? '缂栬緫淇濆吇璁″垝' : '鏂板淇濆吇璁″垝'" @back="goBack" /> <!-- 琛ㄥ崟鍐呭 --> - <van-form @submit="sendForm" ref="formRef" label-width="110px" input-align="right" error-message-align="right" scroll-to-error scroll-to-error-position="center"> + <u-form ref="formRef" :model="form" :rules="formRules" label-width="110px"> <!-- 鍩烘湰淇℃伅 --> - <van-cell-group title="鍩烘湰淇℃伅" inset> - <van-field - v-model="deviceNameText" - label="璁惧鍚嶇О" + <u-form-item label="璁惧鍚嶇О" prop="deviceNameText" required border-bottom> + <u-input + v-model="form.deviceNameText" placeholder="璇烽�夋嫨璁惧鍚嶇О" - :rules="formRules.deviceLedgerId" - required readonly @click="showDevicePicker" clearable - > - <template #right-icon> - <van-icon name="scan" @click.stop="startScan" class="scan-icon" /> - </template> - </van-field> - <van-field + /> + <template #right> + <u-icon name="scan" @click="startScan" class="scan-icon" /> + </template> + </u-form-item> + + <u-form-item label="瑙勬牸鍨嬪彿" prop="deviceModel" border-bottom> + <u-input v-model="form.deviceModel" - label="瑙勬牸鍨嬪彿" placeholder="璇疯緭鍏ヨ鏍煎瀷鍙�" readonly clearable /> - <van-field + </u-form-item> + + <u-form-item label="璁″垝淇濆吇鏃ユ湡" prop="maintenancePlanTime" required border-bottom> + <u-input v-model="form.maintenancePlanTime" - label="璁″垝淇濆吇鏃ユ湡" placeholder="璇烽�夋嫨璁″垝淇濆吇鏃ユ湡" - :rules="formRules.maintenancePlanTime" - required readonly @click="showDatePicker" clearable /> - </van-cell-group> + <template #right> + <u-icon name="arrow-right" @click="showDatePicker" /> + </template> + </u-form-item> <!-- 鎻愪氦鎸夐挳 --> <view class="footer-btns"> - <van-button class="cancel-btn" @click="goBack">鍙栨秷</van-button> - <van-button class="save-btn" native-type="submit" form-type="submit" :loading="loading">淇濆瓨</van-button> + <u-button class="cancel-btn" @click="goBack">鍙栨秷</u-button> + <u-button class="save-btn" @click="sendForm" :loading="loading">淇濆瓨</u-button> </view> - </van-form> + </u-form> <!-- 璁惧閫夋嫨鍣� --> - <van-popup v-model:show="showDevice" position="bottom"> - <van-picker - :model-value="devicePickerValue" - :columns="deviceColumns" - @confirm="onDeviceConfirm" - @cancel="showDevice = false" - /> - </van-popup> - - <!-- 鏃ユ湡閫夋嫨鍣� --> - <van-popup v-model:show="showDate" position="bottom"> - <van-date-picker - v-model="currentDate" - title="閫夋嫨鏃ユ湡" - @confirm="onDateConfirm" - @cancel="showDate = false" - /> - </van-popup> + <up-action-sheet + :show="showDevice" + :actions="deviceActions" + title="閫夋嫨璁惧" + @select="onDeviceConfirm" + @close="showDevice = false" + /> +<up-datetime-picker + :show="showDate" + v-model="pickerDateValue" + @confirm="onDateConfirm" + @cancel="showDate = false" + mode="date" + /> + </view> </template> @@ -76,23 +74,38 @@ import { getDeviceLedger } from '@/api/equipmentManagement/ledger'; import { addUpkeep, editUpkeep, getUpkeepById } from '@/api/equipmentManagement/upkeep'; import dayjs from "dayjs"; +import { formatDateToYMD } from '@/utils/ruoyi'; defineOptions({ name: "璁惧淇濆吇璁″垝琛ㄥ崟", }); +const showToast = (message) => { + uni.showToast({ + title: message, + icon: 'none' + }) +} // 琛ㄥ崟寮曠敤 const formRef = ref(null); const operationType = ref('add'); const loading = ref(false); const showDevice = ref(false); -const devicePickerValue = ref([]); const showDate = ref(false); +const pickerDateValue = ref(Date.now()); const currentDate = ref([new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()]); // 璁惧閫夐」 const deviceOptions = ref([]); const deviceNameText = ref(''); +// 杞崲涓� action-sheet 闇�瑕佺殑鏍煎紡 +const deviceActions = computed(() => { + return deviceOptions.value.map(item => ({ + text: item.deviceName, + value: item.id, + data: item + })); +}); // 鎵爜鐩稿叧鐘舵�� const isScanning = ref(false); @@ -111,14 +124,6 @@ maintenancePlanTime: dayjs().format("YYYY-MM-DD"), // 璁″垝淇濆吇鏃ユ湡 }); -// 璁惧閫夋嫨鍣ㄥ垪 -const deviceColumns = computed(() => { - return deviceOptions.value.map(item => ({ - text: item.deviceName, - value: item.id - })); -}); - // 鍔犺浇璁惧鍒楄〃 const loadDeviceName = async () => { try { @@ -126,15 +131,6 @@ deviceOptions.value = data || []; } catch (e) { showToast('鑾峰彇璁惧鍒楄〃澶辫触'); - } -}; - -// 璁剧疆璁惧瑙勬牸鍨嬪彿 -const setDeviceModel = (id) => { - const option = deviceOptions.value.find((item) => item.id === id); - if (option) { - form.value.deviceModel = option.deviceModel; - deviceNameText.value = option.deviceName; } }; @@ -151,7 +147,7 @@ // 璁剧疆璁惧鍚嶇О鏄剧ず const device = deviceOptions.value.find(item => item.id === data.deviceLedgerId); if (device) { - deviceNameText.value = device.deviceName; + form.value.deviceNameText = device.deviceName; } } } catch (e) { @@ -161,26 +157,6 @@ // 鏂板妯″紡 operationType.value = 'add'; } -}; - -// 娓呴櫎琛ㄥ崟鏍¢獙鐘舵�� -const clearValidate = () => { - formRef.value?.clearValidate(); -}; - -// 閲嶇疆琛ㄥ崟鏁版嵁鍜屾牎楠岀姸鎬� -const resetForm = () => { - form.value = { - deviceLedgerId: undefined, - deviceModel: undefined, - maintenancePlanTime: dayjs().format("YYYY-MM-DD"), - }; - deviceNameText.value = ''; -}; - -const resetFormAndValidate = () => { - resetForm(); - clearValidate(); }; // 鎵弿浜岀淮鐮佸姛鑳� @@ -211,29 +187,30 @@ } 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); + // 濡傛灉鍖归厤鍒扮粨鏋滐紝杩斿洖鏁板瓧绫诲瀷锛屽惁鍒欒繑鍥瀗ull + 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) { // 鎵惧埌鍖归厤鐨勮澶囷紝鑷姩濉厖 form.value.deviceLedgerId = matchedDevice.id; - deviceNameText.value = matchedDevice.deviceName; + form.value.deviceNameText = matchedDevice.deviceName; form.value.deviceModel = matchedDevice.deviceModel; showToast('璁惧淇℃伅宸茶嚜鍔ㄥ~鍏�'); } else { @@ -248,11 +225,15 @@ }; // 纭璁惧閫夋嫨 -const onDeviceConfirm = ({ selectedValues, selectedOptions }) => { - form.value.deviceLedgerId = selectedOptions[0].value; - devicePickerValue.value = selectedValues; +const onDeviceConfirm = (selected) => { + // selected 杩斿洖鐨勬槸閫変腑椤� + form.value.deviceLedgerId = selected.value; + form.value.deviceNameText = selected.name; + const selectedDevice = deviceOptions.value.find(item => item.id === selected.value); + if (selectedDevice) { + form.value.deviceModel = selectedDevice.deviceModel; + } showDevice.value = false; - setDeviceModel(selectedOptions[0].value); }; // 鏄剧ず鏃ユ湡閫夋嫨鍣� @@ -261,9 +242,8 @@ }; // 纭鏃ユ湡閫夋嫨 -const onDateConfirm = ({ selectedValues }) => { - form.value.maintenancePlanTime = selectedValues.join('-'); - currentDate.value = selectedValues; +const onDateConfirm = (e) => { + form.value.maintenancePlanTime = formatDateToYMD(e.value); showDate.value = false; }; @@ -289,7 +269,8 @@ const sendForm = async () => { try { // 鎵嬪姩楠岃瘉琛ㄥ崟 - await formRef.value?.validate(); + const valid = await formRef.value.validate(); + if (!valid) return; loading.value = true; const id = getPageId(); @@ -321,19 +302,20 @@ // 杩斿洖涓婁竴椤� const goBack = () => { + // 娓呴櫎瀛樺偍鐨刬d + uni.removeStorageSync('repairId'); uni.navigateBack(); }; // 鑾峰彇椤甸潰鍙傛暟 const getPageParams = () => { - const pages = getCurrentPages(); - const currentPage = pages[pages.length - 1]; - const options = currentPage.options; + // 浠庢湰鍦板瓨鍌ㄨ幏鍙杋d + const id = uni.getStorageSync('repairId'); // 鏍规嵁鏄惁鏈塱d鍙傛暟鏉ュ垽鏂槸鏂板杩樻槸缂栬緫 - if (options.id) { + if (id) { // 缂栬緫妯″紡锛岃幏鍙栬鎯� - loadForm(options.id); + loadForm(id); } else { // 鏂板妯″紡 loadForm(); @@ -342,14 +324,13 @@ // 鑾峰彇椤甸潰ID const getPageId = () => { - const pages = getCurrentPages(); - const currentPage = pages[pages.length - 1]; - const options = currentPage.options; - return options.id; + // 浠庢湰鍦板瓨鍌ㄨ幏鍙杋d + return uni.getStorageSync('repairId'); }; </script> <style scoped lang="scss"> +@import '@/static/scss/form-common.scss'; .upkeep-add { min-height: 100vh; background: #f8f9fa; -- Gitblit v1.9.3