From c58665039ce8b7c895ed4f1000ff4cf525a92085 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 27 八月 2025 16:28:21 +0800
Subject: [PATCH] 1.设备保养开发联调

---
 src/pages/equipmentManagement/upkeep/maintain.vue |  298 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 298 insertions(+), 0 deletions(-)

diff --git a/src/pages/equipmentManagement/upkeep/maintain.vue b/src/pages/equipmentManagement/upkeep/maintain.vue
new file mode 100644
index 0000000..c70ec14
--- /dev/null
+++ b/src/pages/equipmentManagement/upkeep/maintain.vue
@@ -0,0 +1,298 @@
+<template>
+	<view class="upkeep-maintain">
+		<!-- 浣跨敤閫氱敤椤甸潰澶撮儴缁勪欢 -->
+		<PageHeader title="鏂板淇濆吇" @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">
+			<!-- 鍩烘湰淇℃伅 -->
+			<van-cell-group title="淇濆吇淇℃伅" inset>
+				<van-field
+					v-model="form.maintenanceActuallyName"
+					label="瀹為檯淇濆吇浜�"
+					placeholder="璇疯緭鍏ュ疄闄呬繚鍏讳汉"
+					:rules="formRules.maintenanceActuallyName"
+					required
+					clearable
+				/>
+				<van-field
+					v-model="form.maintenanceActuallyTime"
+					label="瀹為檯淇濆吇鏃ユ湡"
+					placeholder="璇烽�夋嫨瀹為檯淇濆吇鏃ユ湡"
+					:rules="formRules.maintenanceActuallyTime"
+					required
+					readonly
+					@click="showDatePicker"
+					clearable
+				/>
+				<van-field
+					v-model="maintenanceResultText"
+					label="淇濆吇缁撴灉"
+					placeholder="璇烽�夋嫨淇濆吇缁撴灉"
+					:rules="formRules.maintenanceResult"
+					required
+					readonly
+					@click="showResultPicker"
+					clearable
+				/>
+			</van-cell-group>
+			
+			<!-- 鎻愪氦鎸夐挳 -->
+			<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>
+			</view>
+		</van-form>
+
+		<!-- 鏃ユ湡閫夋嫨鍣� -->
+		<van-popup v-model:show="showDate" position="bottom">
+			<van-date-picker
+				v-model="currentDate"
+				title="閫夋嫨鏃ユ湡"
+				@confirm="onDateConfirm"
+				@cancel="showDate = false"
+			/>
+		</van-popup>
+
+		<!-- 淇濆吇缁撴灉閫夋嫨鍣� -->
+		<van-popup v-model:show="showResult" position="bottom">
+			<van-picker
+				:model-value="resultPickerValue"
+				:columns="resultColumns"
+				@confirm="onResultConfirm"
+				@cancel="showResult = false"
+			/>
+		</van-popup>
+	</view>
+</template>
+
+<script setup>
+import { ref, onMounted } from 'vue';
+import { onShow } from '@dcloudio/uni-app';
+import PageHeader from '@/components/PageHeader.vue';
+import { addMaintenance } from '@/api/equipmentManagement/upkeep';
+import useUserStore from "@/store/modules/user";
+import dayjs from "dayjs";
+import { showToast } from 'vant';
+
+defineOptions({
+	name: "璁惧淇濆吇琛ㄥ崟",
+});
+
+const userStore = useUserStore();
+
+// 琛ㄥ崟寮曠敤
+const formRef = ref(null);
+const loading = ref(false);
+const showDate = ref(false);
+const showResult = ref(false);
+const currentDate = ref([new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()]);
+const resultPickerValue = ref([]);
+const maintenanceResultText = ref('');
+
+// 淇濆吇缁撴灉閫夐」
+const resultColumns = [
+	{ text: '瀹屽ソ', value: 1 },
+	{ text: '缁翠慨', value: 0 }
+];
+
+// 琛ㄥ崟楠岃瘉瑙勫垯
+const formRules = {
+	maintenanceActuallyName: [{ required: true, trigger: "blur", message: "璇疯緭鍏ュ疄闄呬繚鍏讳汉" }],
+	maintenanceActuallyTime: [{ required: true, trigger: "change", message: "璇烽�夋嫨瀹為檯淇濆吇鏃ユ湡" }],
+	maintenanceResult: [{ required: true, trigger: "change", message: "璇烽�夋嫨淇濆吇缁撴灉" }],
+};
+
+// 浣跨敤 ref 澹版槑琛ㄥ崟鏁版嵁
+const form = ref({
+	maintenanceActuallyName: userStore.nickName || '', // 榛樿浣跨敤褰撳墠鐢ㄦ埛鏄电О
+	maintenanceResult: undefined, // 淇濆吇缁撴灉
+	maintenanceActuallyTime: dayjs().format("YYYY-MM-DD"), // 瀹為檯淇濆吇鏃ユ湡锛堝彧鏄剧ず鏃ユ湡锛�
+});
+
+// 娓呴櫎琛ㄥ崟鏍¢獙鐘舵��
+const clearValidate = () => {
+	// Vant4涓笉闇�瑕佹墜鍔ㄦ竻闄ら獙璇佺姸鎬侊紝閲嶇疆琛ㄥ崟鏃朵細鑷姩娓呴櫎
+	// formRef.value?.clearValidate(); // 鍒犻櫎杩欒
+};
+
+// 閲嶇疆琛ㄥ崟鏁版嵁鍜屾牎楠岀姸鎬�
+const resetForm = () => {
+	form.value = {
+		maintenanceActuallyName: userStore.nickName || '',
+		maintenanceResult: undefined,
+		maintenanceActuallyTime: dayjs().format("YYYY-MM-DD"),
+	};
+	maintenanceResultText.value = '';
+};
+
+const resetFormAndValidate = () => {
+	resetForm();
+	// clearValidate(); // 鍒犻櫎杩欒锛孷ant4浼氳嚜鍔ㄥ鐞�
+};
+
+// 鎻愪氦琛ㄥ崟
+const sendForm = async () => {
+	try {
+		// 浣跨敤Vant4鐨勬纭獙璇佹柟寮�
+		formRef.value?.validate().then(() => {
+			// 楠岃瘉閫氳繃
+			submitFormData();
+		}).catch((errors) => {
+			// 楠岃瘉澶辫触
+			showToast('璇峰~鍐欏畬鏁翠俊鎭�');
+		});
+	} catch (e) {
+		showToast('琛ㄥ崟楠岃瘉澶辫触');
+	}
+};
+
+// 鎻愪氦琛ㄥ崟鏁版嵁
+const submitFormData = async () => {
+	try {
+		loading.value = true;
+		const id = getPageId();
+		
+		if (!id) {
+			showToast('鍙傛暟閿欒');
+			loading.value = false;
+			return;
+		}
+		
+		// 鍑嗗鎻愪氦鏁版嵁锛宮aintenanceActuallyTime 鍔犱笂褰撳墠鏃跺垎绉�
+		const submitData = { ...form.value };
+		if (submitData.maintenanceActuallyTime && !submitData.maintenanceActuallyTime.includes(':')) {
+			// 濡傛灉 maintenanceActuallyTime 鍙寘鍚棩鏈燂紝娣诲姞褰撳墠鏃跺垎绉�
+			submitData.maintenanceActuallyTime = submitData.maintenanceActuallyTime + ' ' + dayjs().format('HH:mm:ss');
+		}
+		
+		const { code } = await addMaintenance({ id: id, ...submitData });
+		
+		if (code == 200) {
+			showToast('鏂板淇濆吇鎴愬姛');
+			resetFormAndValidate();
+			setTimeout(() => {
+				uni.navigateBack();
+			}, 1500);
+		} else {
+			loading.value = false;
+		}
+	} catch (e) {
+		loading.value = false;
+		showToast('鎿嶄綔澶辫触');
+	}
+};
+
+// 杩斿洖涓婁竴椤�
+const goBack = () => {
+	uni.navigateBack();
+};
+
+// 鑾峰彇椤甸潰ID
+const getPageId = () => {
+	const pages = getCurrentPages();
+	const currentPage = pages[pages.length - 1];
+	const options = currentPage.options;
+	return options.id;
+};
+
+// 鏄剧ず鏃ユ湡閫夋嫨鍣�
+const showDatePicker = () => {
+	showDate.value = true;
+};
+
+// 纭鏃ユ湡閫夋嫨
+const onDateConfirm = ({ selectedValues }) => {
+	// 鍙繚瀛樺勾鏈堟棩锛屼笉鍖呭惈鏃跺垎绉�
+	form.value.maintenanceActuallyTime = selectedValues.join('-');
+	currentDate.value = selectedValues;
+	showDate.value = false;
+};
+
+// 鏄剧ず淇濆吇缁撴灉閫夋嫨鍣�
+const showResultPicker = () => {
+	showResult.value = true;
+};
+
+// 纭淇濆吇缁撴灉閫夋嫨
+const onResultConfirm = ({ selectedValues, selectedOptions }) => {
+	form.value.maintenanceResult = selectedOptions[0].value;
+	maintenanceResultText.value = selectedOptions[0].text;
+	resultPickerValue.value = selectedValues;
+	showResult.value = false;
+};
+
+// 鍒濆鍖栬〃鍗曟暟鎹�
+const initForm = () => {
+	// 璁剧疆淇濆吇浜轰负褰撳墠鐢ㄦ埛鏄电О
+	form.value.maintenanceActuallyName = userStore.nickName || '';
+	// 璁剧疆褰撳墠鏃ユ湡锛堝彧鍖呭惈骞存湀鏃ワ級
+	form.value.maintenanceActuallyTime = dayjs().format('YYYY-MM-DD');
+	currentDate.value = [new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()];
+};
+
+onShow(() => {
+	// 椤甸潰鏄剧ず鏃跺垵濮嬪寲琛ㄥ崟
+	initForm();
+});
+
+onMounted(() => {
+	// 椤甸潰鍔犺浇鏃跺垵濮嬪寲琛ㄥ崟
+	initForm();
+});
+</script>
+
+<style scoped lang="scss">
+.upkeep-maintain {
+	min-height: 100vh;
+	background: #f8f9fa;
+	padding-bottom: 5rem;
+}
+
+.footer-btns {
+	position: fixed;
+	left: 0;
+	right: 0;
+	bottom: 0;
+	background: #fff;
+	display: flex;
+	justify-content: space-around;
+	align-items: center;
+	padding: 0.75rem 0;
+	box-shadow: 0 -0.125rem 0.5rem rgba(0,0,0,0.05);
+	z-index: 1000;
+}
+
+.cancel-btn {
+	font-weight: 400;
+	font-size: 1rem;
+	color: #FFFFFF;
+	width: 6.375rem;
+	background: #C7C9CC;
+	box-shadow: 0 0.25rem 0.625rem 0 rgba(3,88,185,0.2);
+	border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
+}
+
+.save-btn {
+	font-weight: 400;
+	font-size: 1rem;
+	color: #FFFFFF;
+	width: 14rem;
+	background: linear-gradient( 140deg, #00BAFF 0%, #006CFB 100%);
+	box-shadow: 0 0.25rem 0.625rem 0 rgba(3,88,185,0.2);
+	border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
+}
+
+// 鍝嶅簲寮忚皟鏁�
+@media (max-width: 768px) {
+	.submit-section {
+		padding: 12px;
+	}
+}
+
+.tip-text { 
+	padding: 4px 16px 0 16px; 
+	font-size: 12px; 
+	color: #888; 
+}
+</style>
\ No newline at end of file

--
Gitblit v1.9.3