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 |  240 ++++++++++++++++++++++++++---------------------------------
 1 files changed, 105 insertions(+), 135 deletions(-)

diff --git a/src/pages/equipmentManagement/upkeep/add.vue b/src/pages/equipmentManagement/upkeep/add.vue
index fc6c5f7..8dedb1b 100644
--- a/src/pages/equipmentManagement/upkeep/add.vue
+++ b/src/pages/equipmentManagement/upkeep/add.vue
@@ -1,78 +1,84 @@
 <template>
 	<view class="upkeep-add">
 		<!-- 浣跨敤閫氱敤椤甸潰澶撮儴缁勪欢 -->
-		<PageHeader title="鏂板淇濆吇" @back="goBack" />
+		<PageHeader :title="operationType === 'edit' ? '缂栬緫淇濆吇璁″垝' : '鏂板淇濆吇璁″垝'" @back="goBack" />
 		
 		<!-- 琛ㄥ崟鍐呭 -->
-		<u-form @submit="sendForm" ref="formRef" label-width="110" input-align="right" error-message-align="right">
+		<u-form ref="formRef" :model="form" :rules="formRules" label-width="110px">
 			<!-- 鍩烘湰淇℃伅 -->
-			<u-cell-group title="鍩烘湰淇℃伅">
-				<u-form-item label="璁惧鍚嶇О" prop="deviceName" required border-bottom>
-					<u-input
-						v-model="deviceNameText"
-						placeholder="璇烽�夋嫨璁惧鍚嶇О"
-						readonly
-						@click="showDevicePicker"
-						clearable
-					>
-						<template #suffix>
-							<u-icon name="scan" @click.stop="startScan" class="scan-icon" />
-						</template>
-					</u-input>
-				</u-form-item>
-				<u-form-item label="瑙勬牸鍨嬪彿" border-bottom>
-					<u-input
-						v-model="form.deviceModel"
-						placeholder="璇疯緭鍏ヨ鏍煎瀷鍙�"
-						readonly
-						clearable
-					/>
-				</u-form-item>
-				<u-form-item label="淇濆吇鏃ユ湡" prop="upkeepDate" required border-bottom>
-					<u-input
-						v-model="form.upkeepDate"
-						placeholder="璇烽�夋嫨淇濆吇鏃ユ湡"
-						readonly
-						@click="showDatePicker"
-						clearable
-					/>
-				</u-form-item>
-			</u-cell-group>
+			<u-form-item label="璁惧鍚嶇О" prop="deviceNameText" required border-bottom>
+				<u-input
+					v-model="form.deviceNameText"
+					placeholder="璇烽�夋嫨璁惧鍚嶇О"
+					readonly
+					@click="showDevicePicker"
+					clearable
+				/>
+				<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"
+					placeholder="璇疯緭鍏ヨ鏍煎瀷鍙�"
+					readonly
+					clearable
+				/>
+			</u-form-item>
+			
+			<u-form-item label="璁″垝淇濆吇鏃ユ湡" prop="maintenancePlanTime" required border-bottom>
+				<u-input
+					v-model="form.maintenancePlanTime"
+					placeholder="璇烽�夋嫨璁″垝淇濆吇鏃ユ湡"
+					readonly
+					@click="showDatePicker"
+					clearable
+				/>
+				<template #right>
+					<u-icon name="arrow-right" @click="showDatePicker" />
+				</template>
+			</u-form-item>
 			
 			<!-- 鎻愪氦鎸夐挳 -->
 			<view class="footer-btns">
 				<u-button class="cancel-btn" @click="goBack">鍙栨秷</u-button>
-				<u-button class="save-btn" type="primary" @click="sendForm" :loading="loading">淇濆瓨</u-button>
+				<u-button class="save-btn" @click="sendForm" :loading="loading">淇濆瓨</u-button>
 			</view>
 		</u-form>
 
 		<!-- 璁惧閫夋嫨鍣� -->
-		<u-popup v-model="showDevice" mode="bottom">
-			<u-picker
-				v-model="devicePickerValue"
-				:columns="deviceColumns"
-				@confirm="onDeviceConfirm"
-				@cancel="showDevice = false"
-			/>
-		</u-popup>
-
-		<!-- 鏃ユ湡閫夋嫨鍣� -->
-		<u-popup v-model="showDate" mode="bottom">
-			<u-datetime-picker
-				v-model="currentDate"
-				title="閫夋嫨鏃ユ湡"
-				@confirm="onDateConfirm"
-				@cancel="showDate = false"
-			/>
-		</u-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>
 
 <script setup>
-// 鏇挎崲 Vant 鐨� toast
-// import { showToast } from 'vant';
+import { ref, computed, onMounted, onUnmounted } from 'vue';
+import { onShow } from '@dcloudio/uni-app';
+import PageHeader from '@/components/PageHeader.vue';
+import { getDeviceLedger } from '@/api/equipmentManagement/ledger';
+import { addUpkeep, editUpkeep, getUpkeepById } from '@/api/equipmentManagement/upkeep';
+import dayjs from "dayjs";
+import { formatDateToYMD } from '@/utils/ruoyi';
 
-// 鏇挎崲 toast 鏂规硶
+defineOptions({
+	name: "璁惧淇濆吇璁″垝琛ㄥ崟",
+});
 const showToast = (message) => {
   uni.showToast({
     title: message,
@@ -80,30 +86,26 @@
   })
 }
 
-import { ref, computed, onMounted, onUnmounted } from 'vue';
-import { onShow } from '@dcloudio/uni-app';
-import PageHeader from '@/components/PageHeader.vue';
-import { getDeviceLedger } from '@/api/equipmentManagement/ledger';
-import { addUpkeep, editUpkeep, getUpkeepById } from '@/api/equipmentManagement/upkeep';
-import dayjs from "dayjs";
-import { showToast } from 'vant';
-
-defineOptions({
-	name: "璁惧淇濆吇璁″垝琛ㄥ崟",
-});
-
 // 琛ㄥ崟寮曠敤
 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);
@@ -122,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 {
@@ -137,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;
 	}
 };
 
@@ -162,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) {
@@ -172,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();
 };
 
 // 鎵弿浜岀淮鐮佸姛鑳�
@@ -222,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 {
@@ -259,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);
 };
 
 // 鏄剧ず鏃ユ湡閫夋嫨鍣�
@@ -272,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;
 };
 
@@ -300,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();
@@ -332,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();
@@ -353,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