From b39e0358272ba224a7659fa2ed262c00e790ff0b Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期一, 09 三月 2026 14:26:04 +0800
Subject: [PATCH] 图片地址修正

---
 src/pages/equipmentManagement/upkeep/maintain.vue |  214 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 163 insertions(+), 51 deletions(-)

diff --git a/src/pages/equipmentManagement/upkeep/maintain.vue b/src/pages/equipmentManagement/upkeep/maintain.vue
index 9edeff4..d3b8549 100644
--- a/src/pages/equipmentManagement/upkeep/maintain.vue
+++ b/src/pages/equipmentManagement/upkeep/maintain.vue
@@ -41,7 +41,7 @@
                  clearable />
       </u-form-item>
       <u-form-item label="淇濆吇鐘舵��"
-                   prop="status"
+                   prop="maintenancestatusText"
                    required
                    border-bottom>
         <u-input v-model="maintenancestatusText"
@@ -96,7 +96,7 @@
                       style="margin-right: 5px;"></u-icon>
               {{ uploading ? '涓婁紶涓�...' : '鎷嶇収' }}
             </u-button>
-            <u-button type="success"
+            <!-- <u-button type="success"
                       @click="chooseMedia('video')"
                       :loading="uploading"
                       :disabled="uploadFiles.length >= uploadConfig.limit"
@@ -107,7 +107,7 @@
                          color="#fff"
                          style="margin-right: 5px;"></uni-icons>
               {{ uploading ? '涓婁紶涓�...' : '鎷嶈棰�' }}
-            </u-button>
+            </u-button> -->
           </view>
           <!-- 涓婁紶杩涘害 -->
           <view v-if="uploading"
@@ -123,8 +123,9 @@
                   :key="index"
                   class="file-item">
               <view class="file-preview-container">
+                <!-- {{formatFileUrl(file.url)}} -->
                 <image v-if="file.type === 'image' || isImageFile(file)"
-                       :src="file.url || file.tempFilePath || file.path || file.downloadUrl"
+                       :src="formatFileUrl(file.url || file.tempFilePath || file.path || file.downloadUrl)"
                        class="file-preview"
                        mode="aspectFill" />
                 <view v-else-if="file.type === 'video'"
@@ -153,7 +154,7 @@
           </view>
           <view v-if="uploadFiles.length === 0"
                 class="empty-state">
-            <text>璇烽�夋嫨瑕佷笂浼犵殑淇濆吇鍥剧墖鎴栬棰�</text>
+            <text>璇烽�夋嫨瑕佷笂浼犵殑淇濆吇鍥剧墖</text>
           </view>
         </view>
       </u-form-item>
@@ -190,9 +191,6 @@
       <view class="spare-part-popup">
         <view class="popup-header">
           <text class="popup-title">閫夋嫨璁惧澶囦欢</text>
-          <up-button type="primary"
-                     size="small"
-                     @click="confirmSparePartSelection">纭畾</up-button>
         </view>
         <view class="spare-part-options">
           <view v-for="(item, index) in sparePartOptions"
@@ -206,6 +204,10 @@
                     color="#2c7be5" />
           </view>
         </view>
+        <up-button type="primary"
+                   size="small"
+                   :customStyle="{ borderRadius: '6px', padding: '4px 12px' }"
+                   @click="confirmSparePartSelection">纭畾</up-button>
       </view>
     </up-popup>
   </view>
@@ -338,6 +340,7 @@
 
   // 鎻愪氦琛ㄥ崟
   const sendForm = async () => {
+    console.log(form.value.sparePartsIds, "form.value.sparePartsIds");
     try {
       // 鎵嬪姩楠岃瘉琛ㄥ崟
       let isValid = true;
@@ -383,7 +386,9 @@
       const submitData = {
         ...form.value,
         imagesFile: form.value.status == "1" ? uploadFiles.value : [],
-        sparePartsIds: form.sparePartsIds ? form.sparePartsIds.join(",") : "",
+        sparePartsIds: form.value.sparePartsIds
+          ? form.value.sparePartsIds.join(",")
+          : "",
       };
       const { code } = await addMaintenance({ id: id, ...submitData });
 
@@ -416,6 +421,7 @@
     return uni.getStorageSync("repairId");
   };
 
+  const dataform = ref({});
   // 鑾峰彇璁惧淇℃伅
   const getUpkeepItemData = () => {
     try {
@@ -423,6 +429,8 @@
       if (!dataStr) {
         return null;
       }
+      dataform.value = JSON.parse(dataStr);
+      fetchSparePartOptions(dataform.value.deviceLedgerId);
       return JSON.parse(dataStr);
     } catch (e) {
       console.error("瑙f瀽璁惧鏁版嵁澶辫触:", e);
@@ -463,14 +471,17 @@
   };
 
   // 妫�鏌ュ浠舵槸鍚﹀凡閫変腑
-  const isSparePartSelected = value => {
-    return tempSelectedSpareParts.value.some(item => item.value === value);
+  const isSparePartSelected = id => {
+    return tempSelectedSpareParts.value.some(
+      item => item.id === id || item.value === id
+    );
   };
 
   // 鍒囨崲澶囦欢閫変腑鐘舵��
   const toggleSparePartSelection = item => {
+    const itemId = item.id || item.value;
     const index = tempSelectedSpareParts.value.findIndex(
-      selected => selected.value === item.value
+      selected => selected.id === itemId || selected.value === itemId
     );
     if (index > -1) {
       tempSelectedSpareParts.value.splice(index, 1);
@@ -482,16 +493,16 @@
   // 纭澶囦欢閫夋嫨
   const confirmSparePartSelection = () => {
     selectedSpareParts.value = [...tempSelectedSpareParts.value];
-    form.value.sparePartsIds = selectedSpareParts.value.map(item => item.value);
+    form.value.sparePartsIds = selectedSpareParts.value.map(item => item.id);
     showSparePart.value = false;
   };
 
   // 绉婚櫎宸查�夊浠�
   const removeSparePart = index => {
     selectedSpareParts.value.splice(index, 1);
-    form.value.sparePartsIds = selectedSpareParts.value.map(item => item.value);
+    form.value.sparePartsIds = selectedSpareParts.value.map(item => item.id);
   };
-
+  const sparePartsIds = ref([]);
   // 鍒濆鍖栬〃鍗曟暟鎹�
   const initForm = () => {
     // 鑾峰彇璁惧淇℃伅
@@ -545,18 +556,10 @@
         maintenancestatusText.value = statusMap[itemData.status] || "";
       }
       // 濉厖澶囦欢鏁版嵁
-      if (itemData.spareParts && itemData.spareParts.length > 0) {
-        selectedSpareParts.value = itemData.spareParts.map(sparePart => ({
-          id: sparePart.id || sparePart.sparePartId || sparePart.value,
-          name: sparePart.name || sparePart.sparePartName,
-          code: sparePart.code || sparePart.sparePartCode,
-          value: sparePart.id || sparePart.sparePartId || sparePart.value,
-        }));
-        // 璁剧疆澶囦欢IDs
-        form.value.sparePartsIds = selectedSpareParts.value
-          .map(item => item.value)
-          .join(",");
-      }
+
+      // 澶勭悊瀛楃涓叉牸寮忕殑澶囦欢IDs
+      sparePartsIds.value = itemData.sparePartsIds;
+
       // 濉厖闄勪欢鏁版嵁
       if (itemData.files && itemData.files.length > 0) {
         uploadFiles.value = itemData.files.map(file => ({
@@ -582,41 +585,75 @@
     }
   };
 
-  onShow(() => {
+  onShow(async () => {
+    // 鍏堣幏鍙栧浠堕�夐」锛屽啀鍒濆鍖栬〃鍗�
+    const pageId = getPageId();
+    if (pageId) {
+      await fetchSparePartOptions(pageId);
+    }
     // 椤甸潰鏄剧ず鏃跺垵濮嬪寲琛ㄥ崟
-    initForm();
-    fetchSparePartOptions(getPageId());
   });
   const sparePartOptions = ref([]);
   const fetchSparePartOptions = deviceLedgerId => {
-    getSparePartsOptions({ deviceLedgerId: deviceLedgerId }).then(res => {
-      if (res.code == 200) {
-        sparePartOptions.value = res.data || [];
-      }
+    return new Promise((resolve, reject) => {
+      getSparePartsOptions({ deviceLedgerId: deviceLedgerId })
+        .then(res => {
+          if (res.code == 200) {
+            sparePartOptions.value = res.data || [];
+            const idArray =
+              typeof sparePartsIds.value === "string"
+                ? sparePartsIds.value.split(",")
+                : sparePartsIds.value;
+
+            if (idArray.length > 0) {
+              selectedSpareParts.value = sparePartOptions.value
+                .filter(
+                  option =>
+                    idArray.includes(option.id.toString()) ||
+                    idArray.includes(option.value?.toString())
+                )
+                .map(option => ({
+                  id: option.id || option.value,
+                  name: option.name,
+                  code: option.code,
+                  value: option.id || option.value,
+                }));
+              // 璁剧疆澶囦欢IDs
+              form.value.sparePartsIds = idArray.join(",");
+            }
+            resolve(res.data);
+          } else {
+            resolve([]);
+          }
+        })
+        .catch(err => {
+          console.error("鑾峰彇澶囦欢閫夐」澶辫触:", err);
+          resolve([]);
+        });
     });
   };
 
   // 鏍煎紡鍖栨枃浠禪RL
-  const formatFileUrl = url => {
-    if (!url) return "";
+  // const formatFileUrl = url => {
+  //   if (!url) return "";
 
-    // 濡傛灉宸茬粡鏄畬鏁寸殑URL锛坔ttp鎴杊ttps寮�澶达級锛岀洿鎺ヨ繑鍥�
-    if (url.startsWith("http://") || url.startsWith("https://")) {
-      return url;
-    }
+  //   // 濡傛灉宸茬粡鏄畬鏁寸殑URL锛坔ttp鎴杊ttps寮�澶达級锛岀洿鎺ヨ繑鍥�
+  //   if (url.startsWith("http://") || url.startsWith("https://")) {
+  //     return url;
+  //   }
 
-    // 濡傛灉鏄湰鍦拌矾寰勶紙濡� D:\\ruoyi\\prod\\uploads...锛夛紝闇�瑕佽浆鎹负缃戠粶URL
-    // 浠庤矾寰勪腑鎻愬彇uploads鍚庨潰鐨勯儴鍒�
-    const uploadsIndex = url.indexOf("uploads");
-    if (uploadsIndex !== -1) {
-      const relativePath = url.substring(uploadsIndex);
-      // 浣跨敤baseUrl + /profile/ + 鐩稿璺緞
-      return `http://192.168.1.35:8888/profile/${relativePath}`;
-    }
+  //   // 濡傛灉鏄湰鍦拌矾寰勶紙濡� D:\\ruoyi\\prod\\uploads...锛夛紝闇�瑕佽浆鎹负缃戠粶URL
+  //   // 浠庤矾寰勪腑鎻愬彇uploads鍚庨潰鐨勯儴鍒�
+  //   const uploadsIndex = url.indexOf("uploads");
+  //   if (uploadsIndex !== -1) {
+  //     const relativePath = url.substring(uploadsIndex);
+  //     // 浣跨敤baseUrl + /profile/ + 鐩稿璺緞
+  //     return `http://192.168.1.35:8888/profile/${relativePath}`;
+  //   }
 
-    // 鍏朵粬鎯呭喌锛屽皾璇曠洿鎺ユ嫾鎺�
-    return `http://192.168.1.35:8888/profile/${url}`;
-  };
+  //   // 鍏朵粬鎯呭喌锛屽皾璇曠洿鎺ユ嫾鎺�
+  //   return `http://192.168.1.35:8888/profile/${url}`;
+  // };
 
   // 鏍煎紡鍖栨枃浠跺ぇ灏�
   const formatFileSize = size => {
@@ -883,6 +920,18 @@
         uploadProgress.value = res.progress;
       });
     }
+  }; // 鏍煎紡鍖栨枃浠禪RL
+  const formatFileUrl = url => {
+    if (!url) return "";
+    if (url.startsWith("http://") || url.startsWith("https://")) {
+      return url;
+    }
+    // const uploadsIndex = url.indexOf("uploads");
+    // if (uploadsIndex !== -1) {
+    //   const relativePath = url.substring(uploadsIndex);
+    //   return `${config.fileUrl}/${relativePath}`;
+    // }
+    return `${config.fileUrl}/${url}`;
   };
 
   // 涓婁紶鎴愬姛澶勭悊
@@ -1069,6 +1118,69 @@
     font-weight: 500;
   }
 
+  /* 澶囦欢閫夋嫨寮圭獥鏍峰紡 */
+  .spare-part-popup {
+    width: 100%;
+    max-height: 80vh;
+    background: #fff;
+    border-radius: 16px 16px 0 0;
+    overflow: hidden;
+  }
+
+  .popup-header {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    padding: 16px 20px;
+    border-bottom: 1px solid #f0f0f0;
+    background: #f8f9fa;
+  }
+
+  .popup-title {
+    font-size: 16px;
+    font-weight: 600;
+    color: #333;
+  }
+
+  .spare-part-options {
+    padding: 10px 0;
+    max-height: 60vh;
+    overflow-y: auto;
+  }
+
+  .spare-part-option {
+    position: relative;
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    padding: 14px 20px;
+    border-bottom: 1px solid #f0f0f0;
+    transition: all 0.2s ease;
+  }
+
+  .spare-part-option:last-child {
+    border-bottom: none;
+  }
+
+  .spare-part-option:hover {
+    background: #f8f9fa;
+  }
+
+  .spare-part-option.selected {
+    background: #e6f7ff;
+    color: #1890ff;
+  }
+
+  .spare-part-option.selected::before {
+    content: "";
+    position: absolute;
+    left: 0;
+    top: 0;
+    bottom: 0;
+    width: 4px;
+    background: #1890ff;
+  }
+
   /* 鏂囦欢涓婁紶鏍峰紡 */
   .simple-upload-area {
     width: 100%;

--
Gitblit v1.9.3