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/repair/maintain.vue | 267 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 267 insertions(+), 0 deletions(-) diff --git a/src/pages/equipmentManagement/repair/maintain.vue b/src/pages/equipmentManagement/repair/maintain.vue new file mode 100644 index 0000000..64d08cb --- /dev/null +++ b/src/pages/equipmentManagement/repair/maintain.vue @@ -0,0 +1,267 @@ +<template> + <view class="repair-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.maintenanceName" + label="缁翠慨浜�" + placeholder="璇疯緭鍏ョ淮淇汉" + :rules="formRules.maintenanceName" + required + clearable + /> + <van-field + v-model="form.maintenanceResult" + label="缁翠慨缁撴灉" + type="textarea" + rows="3" + placeholder="璇疯緭鍏ョ淮淇粨鏋�" + :rules="formRules.maintenanceResult" + required + clearable + maxlength="200" + show-word-limit + /> + <van-field + v-model="form.maintenanceTime" + label="缁翠慨鏃ユ湡" + placeholder="璇烽�夋嫨缁翠慨鏃ユ湡" + :rules="formRules.maintenanceTime" + required + readonly + @click="showDatePicker" + 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> + </view> +</template> + +<script setup> +import { ref, onMounted } from 'vue'; +import { onShow } from '@dcloudio/uni-app'; +import PageHeader from '@/components/PageHeader.vue'; +import { addMaintain } from '@/api/equipmentManagement/repair'; +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 currentDate = ref([new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()]); + +// 琛ㄥ崟楠岃瘉瑙勫垯 +const formRules = { + maintenanceName: [{ required: true, trigger: "blur", message: "璇疯緭鍏ョ淮淇汉" }], + maintenanceResult: [{ required: true, trigger: "blur", message: "璇疯緭鍏ョ淮淇粨鏋�" }], + maintenanceTime: [{ required: true, trigger: "change", message: "璇烽�夋嫨缁翠慨鏃ユ湡" }], +}; + +// 浣跨敤 ref 澹版槑琛ㄥ崟鏁版嵁 +const form = ref({ + maintenanceName: userStore.nickName || '', // 榛樿浣跨敤褰撳墠鐢ㄦ埛鏄电О + maintenanceResult: undefined, // 缁翠慨缁撴灉 + maintenanceTime: dayjs().format("YYYY-MM-DD"), // 缁翠慨鏃ユ湡锛堝彧鏄剧ず鏃ユ湡锛� +}); + +// 娓呴櫎琛ㄥ崟鏍¢獙鐘舵�� +const clearValidate = () => { + // Vant4涓笉闇�瑕佹墜鍔ㄦ竻闄ら獙璇佺姸鎬侊紝閲嶇疆琛ㄥ崟鏃朵細鑷姩娓呴櫎 + // formRef.value?.clearValidate(); // 鍒犻櫎杩欒 +}; + +// 閲嶇疆琛ㄥ崟鏁版嵁鍜屾牎楠岀姸鎬� +const resetForm = () => { + form.value = { + maintenanceName: userStore.nickName || '', + maintenanceResult: undefined, + maintenanceTime: dayjs().format("YYYY-MM-DD"), + }; +}; + +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; + } + + // 鍑嗗鎻愪氦鏁版嵁锛宮aintenanceTime 鍔犱笂褰撳墠鏃跺垎绉� + const submitData = { ...form.value }; + if (submitData.maintenanceTime && !submitData.maintenanceTime.includes(':')) { + // 濡傛灉 maintenanceTime 鍙寘鍚棩鏈燂紝娣诲姞褰撳墠鏃跺垎绉� + submitData.maintenanceTime = submitData.maintenanceTime + ' ' + dayjs().format('HH:mm:ss'); + } + + const { code } = await addMaintain({ 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.maintenanceTime = selectedValues.join('-'); + currentDate.value = selectedValues; + showDate.value = false; +}; + +// 鍒濆鍖栬〃鍗曟暟鎹� +const initForm = () => { + // 璁剧疆缁翠慨浜轰负褰撳墠鐢ㄦ埛鏄电О + form.value.maintenanceName = userStore.nickName || ''; + // 璁剧疆褰撳墠鏃ユ湡锛堝彧鍖呭惈骞存湀鏃ワ級 + form.value.maintenanceTime = 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"> +.repair-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