From aa0867a85101e396157f62f6a41497025b10ff1b Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期五, 15 五月 2026 15:13:35 +0800
Subject: [PATCH] 维修图片上传功能,维修和保养的维修项目字段更换
---
src/pages/equipmentManagement/upkeep/index.vue | 2
src/pages/equipmentManagement/upkeep/add.vue | 778 +++++++++++++++++++++++++-----------------------
src/pages/equipmentManagement/repair/index.vue | 6
src/pages/equipmentManagement/repair/add.vue | 153 ++++++++-
4 files changed, 536 insertions(+), 403 deletions(-)
diff --git a/src/pages/equipmentManagement/repair/add.vue b/src/pages/equipmentManagement/repair/add.vue
index e931494..b92ec4a 100644
--- a/src/pages/equipmentManagement/repair/add.vue
+++ b/src/pages/equipmentManagement/repair/add.vue
@@ -77,9 +77,9 @@
clearable />
</u-form-item>
<u-form-item label="缁翠慨椤圭洰"
- prop="maintenanceProject"
+ prop="machineryCategory"
border-bottom>
- <u-input v-model="form.maintenanceProject"
+ <u-input v-model="form.machineryCategory"
placeholder="璇疯緭鍏ョ淮淇」鐩�"
clearable />
</u-form-item>
@@ -93,6 +93,17 @@
clearable
count
maxlength="200" />
+ </u-form-item>
+ <u-form-item label="鍥剧墖闄勪欢"
+ prop="storageBlobDTOs"
+ border-bottom>
+ <u-upload :fileList="fileList"
+ @afterRead="afterRead"
+ @delete="deleteFile"
+ name="file"
+ multiple
+ :maxCount="9"
+ accept="image"></u-upload>
</u-form-item>
</u-cell-group>
<!-- 鎻愪氦鎸夐挳 -->
@@ -122,7 +133,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted } from "vue";
- import { onShow } from "@dcloudio/uni-app";
+ import { onShow, onLoad } from "@dcloudio/uni-app";
import PageHeader from "@/components/PageHeader.vue";
import { getDeviceLedger } from "@/api/equipmentManagement/ledger";
import {
@@ -132,6 +143,8 @@
} from "@/api/equipmentManagement/repair";
import dayjs from "dayjs";
import { formatDateToYMD } from "@/utils/ruoyi";
+ import { getToken } from "@/utils/auth";
+ import config from "@/config";
const showToast = message => {
uni.showToast({
title: message,
@@ -146,10 +159,18 @@
// 琛ㄥ崟寮曠敤
const formRef = ref(null);
const operationType = ref("add");
+ const repairId = ref("");
const loading = ref(false);
const showDevice = ref(false);
const showDate = ref(false);
const pickerDateValue = ref(Date.now());
+
+ onLoad(options => {
+ if (options.id) {
+ repairId.value = options.id;
+ }
+ getPageParams();
+ });
// 璁惧閫夐」
const deviceOptions = ref([]);
@@ -184,9 +205,12 @@
repairTime: dayjs().format("YYYY-MM-DD"), // 鎶ヤ慨鏃ユ湡
repairName: undefined, // 鎶ヤ慨浜�
maintenanceName: undefined, // 缁翠慨浜�
- maintenanceProject: undefined, // 缁翠慨椤圭洰
+ machineryCategory: undefined, // 缁翠慨椤圭洰
remark: undefined, // 鏁呴殰鐜拌薄
+ storageBlobDTOs: [], // 鍥剧墖闄勪欢
});
+
+ const fileList = ref([]);
// 鎶ヤ慨鐘舵�侀�夐」
const repairStatusOptions = ref([
@@ -238,8 +262,18 @@
form.value.repairTime = dayjs(data.repairTime).format("YYYY-MM-DD");
form.value.repairName = data.repairName;
form.value.maintenanceName = data.maintenanceName;
- form.value.maintenanceProject = data.maintenanceProject;
+ form.value.machineryCategory = data.machineryCategory;
form.value.remark = data.remark;
+ form.value.storageBlobDTOs = data.storageBlobVOs || [];
+ // 璁剧疆鍥剧墖鍒楄〃鏄剧ず
+ if (data.storageBlobVOs && data.storageBlobVOs.length > 0) {
+ fileList.value = data.storageBlobVOs.map(item => ({
+ url: item.url,
+ name: item.name,
+ status: "success",
+ message: "",
+ }));
+ }
repairStatusText.value =
repairStatusOptions.value.find(item => item.value == data.status)
?.name || "";
@@ -345,15 +379,101 @@
showDate.value = false;
};
+ // 鍥剧墖涓婁紶鍚庣殑澶勭悊
+ const afterRead = async event => {
+ // 褰撹缃� mutiple 涓� true 鏃�, file 涓烘暟缁勬牸寮忥紝鍚﹀垯涓哄璞℃牸寮�
+ let lists = [].concat(event.file);
+ let fileListLen = fileList.value.length;
+ lists.map(item => {
+ fileList.value.push({
+ ...item,
+ status: "uploading",
+ message: "涓婁紶涓�",
+ });
+ });
+ for (let i = 0; i < lists.length; i++) {
+ try {
+ const result = await uploadFilePromise(lists[i].url);
+ let item = fileList.value[fileListLen];
+ fileList.value.splice(
+ fileListLen,
+ 1,
+ Object.assign(item, {
+ status: "success",
+ message: "",
+ url: result.url,
+ name: result.name,
+ })
+ );
+ // 鍚屾鍒拌〃鍗曟暟鎹�
+ form.value.storageBlobDTOs.push(result);
+ fileListLen++;
+ } catch (e) {
+ let item = fileList.value[fileListLen];
+ fileList.value.splice(
+ fileListLen,
+ 1,
+ Object.assign(item, {
+ status: "failed",
+ message: "涓婁紶澶辫触",
+ })
+ );
+ showToast(typeof e === "string" ? e : "涓婁紶澶辫触");
+ }
+ }
+ };
+
+ const uploadFilePromise = url => {
+ return new Promise((resolve, reject) => {
+ uni.uploadFile({
+ url: config.baseUrl + "/common/upload",
+ filePath: url,
+ name: "files",
+ header: {
+ Authorization: "Bearer " + getToken(),
+ },
+ success: res => {
+ try {
+ const data = JSON.parse(res.data);
+ if (data.code === 200) {
+ // 濡傛灉杩斿洖鐨勬槸鏁扮粍锛屽彇绗竴涓厓绱狅紝閬垮厤宓屽鏁扮粍
+ const resultData = Array.isArray(data.data)
+ ? data.data[0]
+ : data.data;
+
+ // 濡傛灉 url 涓虹┖涓� previewURL 瀛樺湪锛屽垯澶勭悊 previewURL 璧嬪�肩粰 url
+ if (!resultData.url && resultData.previewURL) {
+ resultData.url = resultData.previewURL;
+ }
+ resultData.name = resultData.originalFilename;
+
+ resolve(resultData);
+ } else {
+ reject(data.msg || "涓婁紶澶辫触");
+ }
+ } catch (e) {
+ reject("瑙f瀽鍝嶅簲澶辫触");
+ }
+ },
+ fail: err => {
+ reject(err);
+ },
+ });
+ });
+ };
+
+ const deleteFile = event => {
+ fileList.value.splice(event.index, 1);
+ form.value.storageBlobDTOs.splice(event.index, 1);
+ };
+
onShow(() => {
- // 椤甸潰鏄剧ず鏃惰幏鍙栧弬鏁�
- getPageParams();
+ // 椤甸潰鏄剧ず鏃堕�昏緫
});
onMounted(() => {
- // 椤甸潰鍔犺浇鏃惰幏鍙栬澶囧垪琛ㄥ拰鍙傛暟
+ // 椤甸潰鍔犺浇鏃惰幏鍙栬澶囧垪琛�
loadDeviceName();
- getPageParams();
});
// 缁勪欢鍗歌浇鏃舵竻鐞嗗畾鏃跺櫒
@@ -393,7 +513,6 @@
// 鍑嗗鎻愪氦鏁版嵁
const submitData = { ...form.value };
-
const { code } = id
? await editRepair({ id: id, ...submitData })
: await addRepair(submitData);
@@ -414,21 +533,15 @@
// 杩斿洖涓婁竴椤�
const goBack = () => {
- uni.removeStorageSync("repairId");
uni.navigateBack();
};
// 鑾峰彇椤甸潰鍙傛暟
const getPageParams = () => {
- // 浣跨敤uni.getStorageSync鑾峰彇id
- const id = uni.getStorageSync("repairId");
-
// 鏍规嵁鏄惁鏈塱d鍙傛暟鏉ュ垽鏂槸鏂板杩樻槸缂栬緫
- if (id) {
+ if (repairId.value) {
// 缂栬緫妯″紡锛岃幏鍙栬鎯�
- loadForm(id);
- // 鍙�夛細鑾峰彇鍚庢竻闄ゅ瓨鍌ㄧ殑id锛岄伩鍏嶅奖鍝嶅悗缁搷浣�
- uni.removeStorageSync("repairId");
+ loadForm(repairId.value);
} else {
// 鏂板妯″紡
loadForm();
@@ -437,9 +550,7 @@
// 鑾峰彇椤甸潰ID
const getPageId = () => {
- // 浣跨敤uni.getStorageSync鑾峰彇id
- const id = uni.getStorageSync("repairId");
- return id;
+ return repairId.value;
};
</script>
diff --git a/src/pages/equipmentManagement/repair/index.vue b/src/pages/equipmentManagement/repair/index.vue
index 5543e43..8c41ab1 100644
--- a/src/pages/equipmentManagement/repair/index.vue
+++ b/src/pages/equipmentManagement/repair/index.vue
@@ -63,7 +63,7 @@
</view>
<view class="detail-row">
<text class="detail-label">缁翠慨椤圭洰</text>
- <text class="detail-value">{{ item.maintenanceProject || '-' }}</text>
+ <text class="detail-value">{{ item.machineryCategory || '-' }}</text>
</view>
<view class="detail-row">
<text class="detail-label">鏁呴殰鐜拌薄</text>
@@ -212,9 +212,9 @@
const edit = id => {
if (!id) return;
// 浣跨敤uni.setStorageSync瀛樺偍id
- uni.setStorageSync("repairId", id);
+ // uni.setStorageSync("repairId", id);
uni.navigateTo({
- url: "/pages/equipmentManagement/repair/add",
+ url: "/pages/equipmentManagement/repair/add?id=" + id,
});
};
diff --git a/src/pages/equipmentManagement/upkeep/add.vue b/src/pages/equipmentManagement/upkeep/add.vue
index 2b5d3da..5173510 100644
--- a/src/pages/equipmentManagement/upkeep/add.vue
+++ b/src/pages/equipmentManagement/upkeep/add.vue
@@ -1,413 +1,435 @@
<template>
- <view class="upkeep-add">
- <!-- 浣跨敤閫氱敤椤甸潰澶撮儴缁勪欢 -->
- <PageHeader :title="operationType === 'edit' ? '缂栬緫淇濆吇璁″垝' : '鏂板淇濆吇璁″垝'" @back="goBack" />
-
- <!-- 琛ㄥ崟鍐呭 -->
- <u-form ref="formRef" :model="form" :rules="formRules" label-width="110px">
- <!-- 鍩烘湰淇℃伅 -->
- <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>
-
- <u-form-item label="淇濆吇浜�" prop="maintenancePerson" border-bottom>
- <u-input
- v-model="form.maintenancePerson"
- placeholder="璇疯緭鍏ヤ繚鍏讳汉"
- clearable
- />
- </u-form-item>
-
- <u-form-item label="淇濆吇椤圭洰" prop="maintenanceProject" border-bottom>
- <u-input
- v-model="form.maintenanceProject"
- placeholder="璇疯緭鍏ヤ繚鍏婚」鐩�"
- clearable
- />
- </u-form-item>
-
- <!-- 鎻愪氦鎸夐挳 -->
- <view class="footer-btns">
- <u-button class="cancel-btn" @click="goBack">鍙栨秷</u-button>
- <u-button class="save-btn" @click="sendForm" :loading="loading">淇濆瓨</u-button>
- </view>
- </u-form>
-
- <!-- 璁惧閫夋嫨鍣� -->
- <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>
+ <view class="upkeep-add">
+ <!-- 浣跨敤閫氱敤椤甸潰澶撮儴缁勪欢 -->
+ <PageHeader :title="operationType === 'edit' ? '缂栬緫淇濆吇璁″垝' : '鏂板淇濆吇璁″垝'"
+ @back="goBack" />
+ <!-- 琛ㄥ崟鍐呭 -->
+ <u-form ref="formRef"
+ :model="form"
+ :rules="formRules"
+ label-width="110px">
+ <!-- 鍩烘湰淇℃伅 -->
+ <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>
+ <u-form-item label="淇濆吇浜�"
+ prop="maintenancePerson"
+ border-bottom>
+ <u-input v-model="form.maintenancePerson"
+ placeholder="璇疯緭鍏ヤ繚鍏讳汉"
+ clearable />
+ </u-form-item>
+ <u-form-item label="淇濆吇椤圭洰"
+ prop="machineryCategory"
+ border-bottom>
+ <u-input v-model="form.machineryCategory"
+ placeholder="璇疯緭鍏ヤ繚鍏婚」鐩�"
+ clearable />
+ </u-form-item>
+ <!-- 鎻愪氦鎸夐挳 -->
+ <view class="footer-btns">
+ <u-button class="cancel-btn"
+ @click="goBack">鍙栨秷</u-button>
+ <u-button class="save-btn"
+ @click="sendForm"
+ :loading="loading">淇濆瓨</u-button>
+ </view>
+ </u-form>
+ <!-- 璁惧閫夋嫨鍣� -->
+ <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>
-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';
+ 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";
-defineOptions({
- name: "璁惧淇濆吇璁″垝琛ㄥ崟",
-});
-const showToast = (message) => {
- uni.showToast({
- title: message,
- icon: 'none'
- })
-}
+ 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 showDate = ref(false);
-const pickerDateValue = ref(Date.now());
-const currentDate = ref([new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()]);
+ // 琛ㄥ崟寮曠敤
+ const formRef = ref(null);
+ const operationType = ref("add");
+ const loading = ref(false);
+ const showDevice = ref(false);
+ 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 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);
-const scanTimer = ref(null);
+ // 鎵爜鐩稿叧鐘舵��
+ const isScanning = ref(false);
+ const scanTimer = ref(null);
-// 琛ㄥ崟楠岃瘉瑙勫垯
-const formRules = {
- deviceLedgerId: [{ required: true, trigger: "change", message: "璇烽�夋嫨璁惧鍚嶇О" }],
- maintenancePlanTime: [{ required: true, trigger: "change", message: "璇烽�夋嫨璁″垝淇濆吇鏃ユ湡" }],
-};
+ // 琛ㄥ崟楠岃瘉瑙勫垯
+ const formRules = {
+ deviceLedgerId: [
+ { required: true, trigger: "change", message: "璇烽�夋嫨璁惧鍚嶇О" },
+ ],
+ maintenancePlanTime: [
+ { required: true, trigger: "change", message: "璇烽�夋嫨璁″垝淇濆吇鏃ユ湡" },
+ ],
+ };
-// 浣跨敤 ref 澹版槑琛ㄥ崟鏁版嵁
-const form = ref({
- deviceLedgerId: undefined, // 璁惧ID
- deviceModel: undefined, // 瑙勬牸鍨嬪彿
- maintenancePlanTime: dayjs().format("YYYY-MM-DD"), // 璁″垝淇濆吇鏃ユ湡
- maintenancePerson: undefined, // 淇濆吇浜�
- maintenanceProject: undefined, // 淇濆吇椤圭洰
-});
+ // 浣跨敤 ref 澹版槑琛ㄥ崟鏁版嵁
+ const form = ref({
+ deviceLedgerId: undefined, // 璁惧ID
+ deviceModel: undefined, // 瑙勬牸鍨嬪彿
+ maintenancePlanTime: dayjs().format("YYYY-MM-DD"), // 璁″垝淇濆吇鏃ユ湡
+ maintenancePerson: undefined, // 淇濆吇浜�
+ machineryCategory: undefined, // 淇濆吇椤圭洰
+ });
-// 鍔犺浇璁惧鍒楄〃
-const loadDeviceName = async () => {
- try {
- const { data } = await getDeviceLedger();
- deviceOptions.value = data || [];
- } catch (e) {
- showToast('鑾峰彇璁惧鍒楄〃澶辫触');
- }
-};
+ // 鍔犺浇璁惧鍒楄〃
+ const loadDeviceName = async () => {
+ try {
+ const { data } = await getDeviceLedger();
+ deviceOptions.value = data || [];
+ } catch (e) {
+ showToast("鑾峰彇璁惧鍒楄〃澶辫触");
+ }
+ };
-// 鍔犺浇琛ㄥ崟鏁版嵁锛堢紪杈戞ā寮忥級
-const loadForm = async (id) => {
- if (id) {
- operationType.value = 'edit';
- try {
- const { code, data } = await getUpkeepById(id);
- if (code == 200) {
- form.value.deviceLedgerId = data.deviceLedgerId;
- form.value.deviceModel = data.deviceModel;
- form.value.maintenancePlanTime = dayjs(data.maintenancePlanTime).format("YYYY-MM-DD");
- form.value.maintenancePerson = data.maintenancePerson;
- form.value.maintenanceProject = data.maintenanceProject;
- // 璁剧疆璁惧鍚嶇О鏄剧ず
- const device = deviceOptions.value.find(item => item.id === data.deviceLedgerId);
- if (device) {
- form.value.deviceNameText = device.deviceName;
- }
- }
- } catch (e) {
- showToast('鑾峰彇璇︽儏澶辫触');
- }
- } else {
- // 鏂板妯″紡
- operationType.value = 'add';
- }
-};
+ // 鍔犺浇琛ㄥ崟鏁版嵁锛堢紪杈戞ā寮忥級
+ const loadForm = async id => {
+ if (id) {
+ operationType.value = "edit";
+ try {
+ const { code, data } = await getUpkeepById(id);
+ if (code == 200) {
+ form.value.deviceLedgerId = data.deviceLedgerId;
+ form.value.deviceModel = data.deviceModel;
+ form.value.maintenancePlanTime = dayjs(data.maintenancePlanTime).format(
+ "YYYY-MM-DD"
+ );
+ form.value.maintenancePerson = data.maintenancePerson;
+ form.value.machineryCategory = data.machineryCategory;
+ // 璁剧疆璁惧鍚嶇О鏄剧ず
+ const device = deviceOptions.value.find(
+ item => item.id === data.deviceLedgerId
+ );
+ if (device) {
+ form.value.deviceNameText = device.deviceName;
+ }
+ }
+ } catch (e) {
+ showToast("鑾峰彇璇︽儏澶辫触");
+ }
+ } else {
+ // 鏂板妯″紡
+ operationType.value = "add";
+ }
+ };
-// 鎵弿浜岀淮鐮佸姛鑳�
-const startScan = () => {
- if (isScanning.value) {
- showToast('姝e湪鎵弿涓紝璇风◢鍊�...');
- return;
- }
-
- // 璋冪敤uni-app鐨勬壂鐮丄PI
- uni.scanCode({
- scanType: ['qrCode', 'barCode'],
- success: (res) => {
- handleScanResult(res.result);
- },
- fail: (err) => {
- console.error('鎵爜澶辫触:', err);
- showToast('鎵爜澶辫触锛岃閲嶈瘯');
- }
- });
-};
+ // 鎵弿浜岀淮鐮佸姛鑳�
+ const startScan = () => {
+ if (isScanning.value) {
+ showToast("姝e湪鎵弿涓紝璇风◢鍊�...");
+ return;
+ }
-// 澶勭悊鎵爜缁撴灉
-const handleScanResult = (scanResult) => {
- if (!scanResult) {
- showToast('鎵爜缁撴灉涓虹┖');
- return;
- }
-
- isScanning.value = true;
- showToast('鎵爜鎴愬姛');
-
- // 3绉掑悗澶勭悊鎵爜缁撴灉
- scanTimer.value = setTimeout(() => {
- processScanResult(scanResult);
- isScanning.value = false;
- }, 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 deviceId = getDeviceIdByRegExp(scanResult);
- const matchedDevice = deviceOptions.value.find(item => item.id == deviceId);
-
- if (matchedDevice) {
- // 鎵惧埌鍖归厤鐨勮澶囷紝鑷姩濉厖
- form.value.deviceLedgerId = matchedDevice.id;
- form.value.deviceNameText = matchedDevice.deviceName;
- form.value.deviceModel = matchedDevice.deviceModel;
- showToast('璁惧淇℃伅宸茶嚜鍔ㄥ~鍏�');
- } else {
- // 鏈壘鍒板尮閰嶇殑璁惧
- showToast('鏈壘鍒板尮閰嶇殑璁惧锛岃鎵嬪姩閫夋嫨');
- }
-};
+ // 璋冪敤uni-app鐨勬壂鐮丄PI
+ uni.scanCode({
+ scanType: ["qrCode", "barCode"],
+ success: res => {
+ handleScanResult(res.result);
+ },
+ fail: err => {
+ console.error("鎵爜澶辫触:", err);
+ showToast("鎵爜澶辫触锛岃閲嶈瘯");
+ },
+ });
+ };
-// 鏄剧ず璁惧閫夋嫨鍣�
-const showDevicePicker = () => {
- showDevice.value = true;
-};
+ // 澶勭悊鎵爜缁撴灉
+ const handleScanResult = scanResult => {
+ if (!scanResult) {
+ showToast("鎵爜缁撴灉涓虹┖");
+ return;
+ }
-// 纭璁惧閫夋嫨
-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;
-};
+ isScanning.value = true;
+ showToast("鎵爜鎴愬姛");
-// 鏄剧ず鏃ユ湡閫夋嫨鍣�
-const showDatePicker = () => {
- showDate.value = true;
-};
+ // 3绉掑悗澶勭悊鎵爜缁撴灉
+ scanTimer.value = setTimeout(() => {
+ processScanResult(scanResult);
+ isScanning.value = false;
+ }, 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 deviceId = getDeviceIdByRegExp(scanResult);
+ const matchedDevice = deviceOptions.value.find(item => item.id == deviceId);
-// 纭鏃ユ湡閫夋嫨
-const onDateConfirm = (e) => {
- form.value.maintenancePlanTime = formatDateToYMD(e.value);
- showDate.value = false;
-};
+ if (matchedDevice) {
+ // 鎵惧埌鍖归厤鐨勮澶囷紝鑷姩濉厖
+ form.value.deviceLedgerId = matchedDevice.id;
+ form.value.deviceNameText = matchedDevice.deviceName;
+ form.value.deviceModel = matchedDevice.deviceModel;
+ showToast("璁惧淇℃伅宸茶嚜鍔ㄥ~鍏�");
+ } else {
+ // 鏈壘鍒板尮閰嶇殑璁惧
+ showToast("鏈壘鍒板尮閰嶇殑璁惧锛岃鎵嬪姩閫夋嫨");
+ }
+ };
-onShow(() => {
- // 椤甸潰鏄剧ず鏃惰幏鍙栧弬鏁�
- getPageParams();
-});
+ // 鏄剧ず璁惧閫夋嫨鍣�
+ const showDevicePicker = () => {
+ showDevice.value = true;
+ };
-onMounted(() => {
- // 椤甸潰鍔犺浇鏃惰幏鍙栬澶囧垪琛ㄥ拰鍙傛暟
- loadDeviceName();
- getPageParams();
-});
+ // 纭璁惧閫夋嫨
+ 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;
+ };
-// 缁勪欢鍗歌浇鏃舵竻鐞嗗畾鏃跺櫒
-onUnmounted(() => {
- if (scanTimer.value) {
- clearTimeout(scanTimer.value);
- }
-});
+ // 鏄剧ず鏃ユ湡閫夋嫨鍣�
+ const showDatePicker = () => {
+ showDate.value = true;
+ };
-// 鎻愪氦琛ㄥ崟
-const sendForm = async () => {
- try {
- // 鎵嬪姩楠岃瘉琛ㄥ崟
- const valid = await formRef.value.validate();
- if (!valid) return;
-
- loading.value = true;
- const id = getPageId();
-
- // 鍑嗗鎻愪氦鏁版嵁
- const submitData = { ...form.value };
- // 纭繚鏃ユ湡鏍煎紡姝g‘
- if (submitData.maintenancePlanTime && !submitData.maintenancePlanTime.includes(':')) {
- submitData.maintenancePlanTime = submitData.maintenancePlanTime + ' 00:00:00';
- }
-
- const { code } = id
- ? await editUpkeep({ id: id, ...submitData })
- : await addUpkeep(submitData);
-
- if (code == 200) {
- showToast(`${id ? "缂栬緫" : "鏂板"}璁″垝鎴愬姛`);
- setTimeout(() => {
- uni.navigateBack();
- }, 1500);
- } else {
- loading.value = false;
- }
- } catch (e) {
- loading.value = false;
- showToast('琛ㄥ崟楠岃瘉澶辫触');
- }
-};
+ // 纭鏃ユ湡閫夋嫨
+ const onDateConfirm = e => {
+ form.value.maintenancePlanTime = formatDateToYMD(e.value);
+ showDate.value = false;
+ };
-// 杩斿洖涓婁竴椤�
-const goBack = () => {
- // 娓呴櫎瀛樺偍鐨刬d
- uni.removeStorageSync('repairId');
- uni.navigateBack();
-};
+ onShow(() => {
+ // 椤甸潰鏄剧ず鏃惰幏鍙栧弬鏁�
+ getPageParams();
+ });
-// 鑾峰彇椤甸潰鍙傛暟
-const getPageParams = () => {
- // 浠庢湰鍦板瓨鍌ㄨ幏鍙杋d
- const id = uni.getStorageSync('repairId');
-
- // 鏍规嵁鏄惁鏈塱d鍙傛暟鏉ュ垽鏂槸鏂板杩樻槸缂栬緫
- if (id) {
- // 缂栬緫妯″紡锛岃幏鍙栬鎯�
- loadForm(id);
- } else {
- // 鏂板妯″紡
- loadForm();
- }
-};
+ onMounted(() => {
+ // 椤甸潰鍔犺浇鏃惰幏鍙栬澶囧垪琛ㄥ拰鍙傛暟
+ loadDeviceName();
+ getPageParams();
+ });
-// 鑾峰彇椤甸潰ID
-const getPageId = () => {
- // 浠庢湰鍦板瓨鍌ㄨ幏鍙杋d
- return uni.getStorageSync('repairId');
-};
+ // 缁勪欢鍗歌浇鏃舵竻鐞嗗畾鏃跺櫒
+ onUnmounted(() => {
+ if (scanTimer.value) {
+ clearTimeout(scanTimer.value);
+ }
+ });
+
+ // 鎻愪氦琛ㄥ崟
+ const sendForm = async () => {
+ try {
+ // 鎵嬪姩楠岃瘉琛ㄥ崟
+ const valid = await formRef.value.validate();
+ if (!valid) return;
+
+ loading.value = true;
+ const id = getPageId();
+
+ // 鍑嗗鎻愪氦鏁版嵁
+ const submitData = { ...form.value };
+ // 纭繚鏃ユ湡鏍煎紡姝g‘
+ if (
+ submitData.maintenancePlanTime &&
+ !submitData.maintenancePlanTime.includes(":")
+ ) {
+ submitData.maintenancePlanTime =
+ submitData.maintenancePlanTime + " 00:00:00";
+ }
+
+ const { code } = id
+ ? await editUpkeep({ id: id, ...submitData })
+ : await addUpkeep(submitData);
+
+ if (code == 200) {
+ showToast(`${id ? "缂栬緫" : "鏂板"}璁″垝鎴愬姛`);
+ setTimeout(() => {
+ uni.navigateBack();
+ }, 1500);
+ } else {
+ loading.value = false;
+ }
+ } catch (e) {
+ loading.value = false;
+ showToast("琛ㄥ崟楠岃瘉澶辫触");
+ }
+ };
+
+ // 杩斿洖涓婁竴椤�
+ const goBack = () => {
+ // 娓呴櫎瀛樺偍鐨刬d
+ uni.removeStorageSync("repairId");
+ uni.navigateBack();
+ };
+
+ // 鑾峰彇椤甸潰鍙傛暟
+ const getPageParams = () => {
+ // 浠庢湰鍦板瓨鍌ㄨ幏鍙杋d
+ const id = uni.getStorageSync("repairId");
+
+ // 鏍规嵁鏄惁鏈塱d鍙傛暟鏉ュ垽鏂槸鏂板杩樻槸缂栬緫
+ if (id) {
+ // 缂栬緫妯″紡锛岃幏鍙栬鎯�
+ loadForm(id);
+ } else {
+ // 鏂板妯″紡
+ loadForm();
+ }
+ };
+
+ // 鑾峰彇椤甸潰ID
+ const getPageId = () => {
+ // 浠庢湰鍦板瓨鍌ㄨ幏鍙杋d
+ return uni.getStorageSync("repairId");
+ };
</script>
<style scoped lang="scss">
-@import '@/static/scss/form-common.scss';
-.upkeep-add {
- min-height: 100vh;
- background: #f8f9fa;
- padding-bottom: 5rem;
-}
+ @import "@/static/scss/form-common.scss";
+ .upkeep-add {
+ 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;
-}
+ .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;
-}
+ .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;
-}
+ .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;
- }
-}
+ // 鍝嶅簲寮忚皟鏁�
+ @media (max-width: 768px) {
+ .submit-section {
+ padding: 12px;
+ }
+ }
-.tip-text {
- padding: 4px 16px 0 16px;
- font-size: 12px;
- color: #888;
-}
+ .tip-text {
+ padding: 4px 16px 0 16px;
+ font-size: 12px;
+ color: #888;
+ }
-.scan-icon {
- color: #1989fa;
- font-size: 18px;
- margin-left: 8px;
- cursor: pointer;
-}
+ .scan-icon {
+ color: #1989fa;
+ font-size: 18px;
+ margin-left: 8px;
+ cursor: pointer;
+ }
</style>
\ No newline at end of file
diff --git a/src/pages/equipmentManagement/upkeep/index.vue b/src/pages/equipmentManagement/upkeep/index.vue
index 8646554..a9ecd0c 100644
--- a/src/pages/equipmentManagement/upkeep/index.vue
+++ b/src/pages/equipmentManagement/upkeep/index.vue
@@ -68,7 +68,7 @@
</view>
<view class="detail-row">
<text class="detail-label">淇濆吇椤圭洰</text>
- <text class="detail-value">{{ item.maintenanceProject || '-' }}</text>
+ <text class="detail-value">{{ item.machineryCategory || '-' }}</text>
</view>
<view class="detail-row">
<text class="detail-label">瀹為檯淇濆吇浜�</text>
--
Gitblit v1.9.3