From 883ab99ab021be1adc6dc5689368f899ea436e54 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期五, 31 十月 2025 20:01:57 +0800
Subject: [PATCH] 完成

---
 src/pages/routingInspection/detail/indexJX.vue |  147 ++++++++++++-------------------------------------
 1 files changed, 36 insertions(+), 111 deletions(-)

diff --git a/src/pages/routingInspection/detail/indexJX.vue b/src/pages/routingInspection/detail/indexJX.vue
index 46fdd5f..f82336a 100644
--- a/src/pages/routingInspection/detail/indexJX.vue
+++ b/src/pages/routingInspection/detail/indexJX.vue
@@ -138,6 +138,7 @@
         style="padding-bottom: 10px"
       >
         <wd-form-item
+          prop="structureItemsGroup"
           :label="formatValue(item.structureName)"
           label-width="400rpx"
           style="color: red"
@@ -184,6 +185,7 @@
           :label="formatValue(item.twistName)"
           label-width="400rpx"
           style="color: red"
+          prop="inspectTwistGroup"
           required
         ></wd-form-item>
         <wd-form-item label="缁炲悜" prop="direction" required>
@@ -290,40 +292,15 @@
       <view style="margin: 10rpx">
         <text class="title">{{ "闄勪欢" }}</text>
       </view>
-      <view class="attachment-grid">
-        <!-- 宸蹭笂浼犻檮浠讹紙鍖呭惈鏂颁笂浼犵殑锛� -->
-        <wd-col v-for="(file, index) in allFiles" :key="file.id || index" class="attachment-item">
-          <wd-img :width="80" :height="80" :src="file.url" @click="previewImage(file.url)">
-            <template #error>
-              <view class="error-wrap">鍔犺浇澶辫触</view>
-            </template>
-            <template #loading>
-              <view class="loading-wrap">
-                <wd-loading />
-              </view>
-            </template>
-          </wd-img>
-          <!-- 缂栬緫妯″紡涓嬫樉绀哄垹闄ゆ寜閽� -->
-          <!-- <wd-icon
-            v-if="isEdit"
-            name="close-circle"
-            class="delete-icon"
-            @click.stop="deleteFile(file.id || index)"
-          ></wd-icon> -->
-        </wd-col>
-        <!-- 涓婁紶鎸夐挳锛堜粎缂栬緫妯″紡鏄剧ず锛� -->
-        <wd-col v-if="isEdit" class="attachment-item upload-btn">
-          <wd-upload
-            :multiple="true"
-            :max-count="5"
-            :before-upload="beforeUpload"
-            @success="handleUploadSuccess"
-            @fail="handleUploadFail"
-          >
-            <view class="upload-icon">+</view>
-          </wd-upload>
-        </wd-col>
-      </view>
+      <wd-col :span="24">
+        <AttachmentUpload
+          :detailData="detailData"
+          :isEdit="isEdit"
+          :deviceType="paramsType"
+          ref="attachmentRef"
+          v-if="detailDataLoaded"
+        />
+      </wd-col>
     </wd-row>
 
     <wd-popup v-model="show" custom-style="border-radius:32rpx;" @close="handleClose">
@@ -342,8 +319,9 @@
 import RoutingInspectionApi from "@/api/routingInspection/routingInspection";
 import Scan from "@/components/scan/index.vue";
 import { useToast } from "wot-design-uni";
+import AttachmentUpload from "../upload.vue";
 
-// 鏍稿績鐘舵��
+const paramsType = ref("");
 const paramsId = ref("");
 const recordData = ref<any>({ structureInfo: { files: [], structureRecordResult: {} } });
 const show = ref(false);
@@ -353,8 +331,10 @@
 const deviceUid = ref("");
 const scanRef = ref();
 const toast = useToast();
+const attachmentRef = ref<any>(null);
+const detailData = reactive<any>({});
+const detailDataLoaded = ref(false);
 
-// 琛ㄥ崟涓存椂鏁版嵁锛堢紪杈戞ā寮忕粦瀹氾級
 const formData = reactive({
   twistDiameter: "", // 缁炲埗澶栧緞
   structureFormula: "", // 鎴愬搧缁撴瀯
@@ -365,7 +345,6 @@
   sampleComplete: "", // 鏍峰搧鏄惁榻愬叏
 });
 
-// 閫夐」鏁版嵁
 const twistDirectionOptions = [
   { label: "宸﹀悜", value: "宸﹀悜" },
   { label: "鍙冲悜", value: "鍙冲悜" },
@@ -387,47 +366,40 @@
   { label: "鍚�", value: "鍚�" },
 ];
 
-// 鍚堝苟鍘熸湁闄勪欢鍜屾柊涓婁紶闄勪欢
-const allFiles = computed(() => {
-  return [...(recordData.value.structureInfo?.files || []), ...tempFiles.value];
-});
-
-// 鍒濆鍖栬〃鍗曟暟鎹紙鎺ュ彛鏁版嵁鍚屾鍒拌〃鍗曪級
 const initFormData = () => {
   const structureResult = recordData.value.structureInfo?.structureRecordResult || {};
   const inspectionResult = recordData.value.inspectionResult || {};
 
-  // 鍩虹鍙紪杈戝瓧娈�
   formData.twistDiameter = inspectionResult.twistDiameter || "";
   formData.structureFormula = structureResult.inspectStructure?.structureFormula || "";
   formData.sampleComplete = inspectionResult.sampleComplete || "";
   formData.conclusion = structureResult.conclusion || "";
-  // 淇浜у搧澶栬鍜岀粨璁虹殑鏁版嵁鏍煎紡
   formData.productAppearance = Array.isArray(structureResult.productAppearance)
     ? structureResult.productAppearance
     : structureResult.productAppearance
     ? [structureResult.productAppearance]
     : [];
 
-  // 寰幆绫诲瓧娈碉紙娣辨嫹璐濋伩鍏嶅師鏁版嵁姹℃煋锛�
   formData.structureItems = JSON.parse(
     JSON.stringify(structureResult.inspectStructure?.structureItems || [])
   );
   formData.inspectTwist = JSON.parse(JSON.stringify(structureResult.inspectTwist || []));
 
-  // 鍒濆鍖栫粸鍚戞暟鎹紙纭繚鏈夊�硷級
   formData.inspectTwist.forEach((item: any) => {
     if (!item.direction) item.direction = "";
   });
 };
 
-// 鑾峰彇璇︽儏鏁版嵁
 const getDetailData = async (id: string, deviceType: string) => {
   try {
     const response = await RoutingInspectionApi.getStrandedInspectionStructureInfoById({ id });
     recordData.value = response.data;
+    detailData.value = response.data.structureInfo;
+    console.log("detailData.value", detailData.value);
     tempFiles.value = []; // 娓呯┖涓存椂鏂囦欢
     initFormData(); // 鏁版嵁杩斿洖鍚庡垵濮嬪寲琛ㄥ崟
+    detailDataLoaded.value = true; // 鏁版嵁鍔犺浇瀹屾垚鍚庯紝娓叉煋瀛愮粍浠�
+    console.log("鐖剁粍浠�-鏁版嵁灏辩华鍚庢墦鍗�");
   } catch (error) {
     console.error("鑾峰彇璇︽儏澶辫触:", error);
     uni.showToast({ title: "鍔犺浇澶辫触", icon: "error" });
@@ -436,8 +408,14 @@
 
 // 椤甸潰鍔犺浇
 onLoad((options: any) => {
-  paramsId.value = options.id;
-  getDetailData(options.id, options.deviceType);
+  try {
+    paramsId.value = options.id;
+    paramsType.value = options.deviceType;
+    getDetailData(options.id, options.deviceType);
+  } catch (error) {
+    console.error("鑾峰彇璇︽儏澶辫触:", error);
+    uni.showToast({ title: "鍔犺浇澶辫触", icon: "error" });
+  }
 });
 
 // 缂栬緫妯″紡鍒囨崲
@@ -448,8 +426,8 @@
 // 鍙栨秷缂栬緫锛堥噸缃〃鍗曪級
 const close = () => {
   isEdit.value = false;
-  tempFiles.value = []; // 鍙栨秷鏃舵竻绌轰复鏃朵笂浼犵殑鏂囦欢
-  initFormData(); // 鎭㈠鍘熷鏁版嵁
+  tempFiles.value = [];
+  initFormData();
 };
 
 // 淇濆瓨缂栬緫锛堝惈蹇呭~椤规牎楠岋級
@@ -482,7 +460,9 @@
   }
   console.log("1111", deviceUid.value);
   if (!deviceUid.value) return uni.showToast({ title: "璇锋壂鎻忎簩缁寸爜", icon: "none" });
-  // 4. 鎻愪氦鏁版嵁鍒版帴鍙�
+  const { newFiles } = attachmentRef.value.getSubmitFiles();
+  console.log("newFiles", newFiles);
+  const allFileIds = [...newFiles];
   try {
     const res = await RoutingInspectionApi.strandedPatrolCheckInspection({
       deviceUid: deviceUid.value,
@@ -499,13 +479,13 @@
       inspectionResult: {
         sampleComplete: formData.sampleComplete,
       },
-      processInspectionAttachmentList: tempFiles.value.map((f) => f.url), // 鏂颁笂浼犵殑闄勪欢
+      processInspectionAttachmentList: allFileIds,
     });
 
     if (res.code === 200) {
       uni.showToast({ title: "淇濆瓨鎴愬姛", icon: "success" });
       isEdit.value = false;
-      getDetailData(paramsId.value, recordData.value.deviceType); // 鍒锋柊鏁版嵁
+      getDetailData(paramsId.value, paramsType.value);
     } else {
       uni.showModal({ title: res.msg || "淇濆瓨澶辫触", icon: "error" });
     }
@@ -513,61 +493,6 @@
     console.error("淇濆瓨澶辫触:", e);
     uni.showModal({ title: e.message || "淇濆瓨澶辫触", icon: "error" });
   }
-};
-
-// 闄勪欢涓婁紶鍓嶇疆鏍¢獙
-const beforeUpload = (file: any) => {
-  // 闄愬埗鍥剧墖澶у皬涓嶈秴杩�2M
-  const maxSize = 2 * 1024 * 1024;
-  if (file.size > maxSize) {
-    uni.showToast({ title: "鍥剧墖澶у皬涓嶈兘瓒呰繃2M", icon: "none" });
-    return false;
-  }
-  return true;
-};
-
-// 闄勪欢涓婁紶鎴愬姛鍥炶皟
-const handleUploadSuccess = (res: any) => {
-  // 鍋囪鎺ュ彛杩斿洖鏍煎紡: { url: 'xxx', id: 'xxx' }
-  if (Array.isArray(res)) {
-    tempFiles.value = [
-      ...tempFiles.value,
-      ...res.map((file) => ({
-        ...file,
-        id: `temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, // 鐢熸垚涓存椂ID
-      })),
-    ];
-  } else {
-    tempFiles.value.push({
-      ...res,
-      id: `temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
-    });
-  }
-};
-
-// 闄勪欢涓婁紶澶辫触鍥炶皟
-const handleUploadFail = (err: any) => {
-  uni.showToast({ title: "闄勪欢涓婁紶澶辫触", icon: "error" });
-};
-
-// 鍒犻櫎闄勪欢
-const deleteFile = (id: string | number) => {
-  // 鍒犻櫎涓存椂鏂囦欢
-  tempFiles.value = tempFiles.value.filter((file) => file.id !== id);
-
-  // 濡傛灉鏄師鏈夋枃浠讹紝闇�瑕佹爣璁板垹闄わ紙瀹為檯椤圭洰涓彲鑳介渶瑕佹帴鍙d氦浜掞級
-  if (typeof id !== "string" || !id.startsWith("temp-")) {
-    // 杩欓噷鍙互瀹炵幇鍒犻櫎鍘熸湁鏂囦欢鐨勯�昏緫
-    recordData.value.structureInfo.files = recordData.value.structureInfo.files.filter(
-      (file: any, index: number) => index !== id
-    );
-  }
-};
-
-// 鍥剧墖棰勮
-const previewImage = (url: string) => {
-  previewImageUrl.value = url;
-  show.value = true;
 };
 
 const handleClose = () => {
@@ -639,7 +564,7 @@
   } catch (err) {
     console.error("JSON瑙f瀽澶辫触锛�", err);
     toast.error("鎵爜鏁版嵁寮傚父");
-    return; // 瑙f瀽澶辫触鐩存帴杩斿洖锛岄伩鍏嶅悗缁敊璇�
+    return;
   }
   deviceUid.value = codeObj?.uid;
   toast.success("鎵爜鎴愬姛");

--
Gitblit v1.9.3