From 025e46e11cb2962fd7692adfa401333758cc779b Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 02 九月 2025 14:00:34 +0800 Subject: [PATCH] 修改组件 --- src/pages/equipmentManagement/upkeep/add.vue | 157 +++++++++++++++++++++++----------------------------- 1 files changed, 69 insertions(+), 88 deletions(-) diff --git a/src/pages/equipmentManagement/upkeep/add.vue b/src/pages/equipmentManagement/upkeep/add.vue index c9fe45f..c0e7e34 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(); }; // 鎵弿浜岀淮鐮佸姛鑳� @@ -233,7 +209,7 @@ 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 +224,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 +241,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 +268,8 @@ const sendForm = async () => { try { // 鎵嬪姩楠岃瘉琛ㄥ崟 - await formRef.value?.validate(); + const valid = await formRef.value.validate(); + if (!valid) return; loading.value = true; const id = getPageId(); @@ -350,6 +330,7 @@ </script> <style scoped lang="scss"> +@import '@/static/scss/form-common.scss'; .upkeep-add { min-height: 100vh; background: #f8f9fa; -- Gitblit v1.9.3