From 6e763136fdf4469143ebbae0b717eb8e9b0ca954 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 03 十一月 2025 17:32:35 +0800
Subject: [PATCH] fix: 完成巡查
---
 src/pages/routingInspection/detail/indexLS.vue |  199 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 149 insertions(+), 50 deletions(-)
diff --git a/src/pages/routingInspection/detail/indexLS.vue b/src/pages/routingInspection/detail/indexLS.vue
index f0f4a6b..31b72e3 100644
--- a/src/pages/routingInspection/detail/indexLS.vue
+++ b/src/pages/routingInspection/detail/indexLS.vue
@@ -34,6 +34,9 @@
         淇濆瓨
       </wd-button>
       <view class="placeholder"></view>
+      <view class="scan-info">
+        <text class="scan-device-text">褰撳墠鎵爜鏈哄彴: {{ scannedDeviceModel || "鏈壂鐮�" }}</text>
+      </view>
       <view class="scan-wrapper" @click="openScan">
         <wd-icon name="scan" size="24px" color="#0D867F"></wd-icon>
       </view>
@@ -126,17 +129,18 @@
 
         <wd-form-item label="澶栬" prop="appearance" required>
           <template v-if="isEdit">
-            <wd-checkbox-group
-              v-model="formData.appearance"
-              inline
-              v-for="(opt, idx) in appearanceOptions"
-              :key="idx"
-              style="text-align: justify"
-            >
-              <wd-checkbox :modelValue="opt.value" style="width: 100px">
+            <view style="display: flex; flex-wrap: wrap; gap: 10px">
+              <wd-checkbox
+                v-for="(opt, idx) in appearanceOptions"
+                :key="idx"
+                :value="opt.value"
+                :modelValue="formData.appearance?.includes(opt.value) || false"
+                @click="handleAppearanceClick(opt.value)"
+                style="width: 100px"
+              >
                 {{ opt.label }}
               </wd-checkbox>
-            </wd-checkbox-group>
+            </view>
           </template>
           <template v-else>
             {{ formatProductAppearance(formData.appearance) }}
@@ -293,18 +297,18 @@
         <img :src="previewImageUrl" alt="棰勮鍥剧墖" style="width: 100%; height: auto" />
       </div>
     </wd-popup>
-    <Scan ref="scanRef" emitName="scan" />
     <wd-toast />
   </view>
 </template>
 
 <script setup lang="ts">
-import { ref, reactive } from "vue";
-import { onLoad } from "@dcloudio/uni-app";
+import { ref, reactive, computed, onUnmounted } from "vue";
+import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
 import RoutingInspectionApi from "@/api/routingInspection/routingInspection";
-import Scan from "@/components/scan/index.vue";
 import { useToast } from "wot-design-uni";
 import AttachmentUpload from "../upload.vue";
+import { useUserStore } from "@/store/modules/user";
+import { useScanCode } from "@/composables/useScanCode";
 
 // 鏍稿績鐘舵��
 const paramsId = ref("");
@@ -314,17 +318,27 @@
 const previewImageUrl = ref("");
 const isEdit = ref(false);
 const tempFiles = ref<any[]>([]);
-const deviceUid = ref("");
-const scanRef = ref();
 const toast = useToast();
 const attachmentRef = ref<any>(null);
+
+// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛淇℃伅
+const userStore = useUserStore();
+const userInfo: any = computed(() => userStore.userInfo);
+
+// 浣跨敤鎵爜绠$悊 composable锛堝叏灞�鐩戝惉鍣紝涓嶉殢椤甸潰鍒囨崲鍏抽棴锛�
+const {
+  deviceUid,
+  deviceModel: scannedDeviceModel,
+  loadFromCache,
+  enableListener,
+} = useScanCode("scanLS");
 
 // 琛ㄥ崟鏁版嵁
 const formData = reactive({
   dia: "",
   maxDia: "",
   minDia: "",
-  appearance: [],
+  appearance: [] as string[],
   windingTightness: "",
   arrangementNeatness: "",
   aluminumWireDistance: "",
@@ -360,11 +374,11 @@
     case 1:
       return "danger";
     case 2:
-      return "info";
+      return "primary";
     case 3:
       return "success";
     default:
-      return "info";
+      return "default";
   }
 };
 
@@ -385,7 +399,45 @@
 
 // 鏍煎紡鍖栧伐鍏�
 const formatProductAppearance = (productAppearance: string[]) => {
-  return !productAppearance.length ? "-" : productAppearance.join("銆�");
+  if (!productAppearance || !Array.isArray(productAppearance) || !productAppearance.length) {
+    return "-";
+  }
+  return productAppearance.join("銆�");
+};
+
+// 澶勭悊澶栬閫夋嫨鐨勪簰鏂ラ�昏緫
+const handleAppearanceClick = (value: string) => {
+  // 纭繚 appearance 鏄暟缁�
+  if (!Array.isArray(formData.appearance)) {
+    formData.appearance = [];
+  }
+
+  const currentValues = [...formData.appearance];
+  const isCurrentlyChecked = currentValues.includes(value);
+
+  let newSelection: string[] = [];
+
+  if (value === "鏃犲瑙傞棶棰�") {
+    if (isCurrentlyChecked) {
+      // 鍙栨秷閫変腑"鏃犲瑙傞棶棰�"
+      newSelection = [];
+    } else {
+      // 閫変腑"鏃犲瑙傞棶棰�"锛屾竻绌哄叾浠栭�夐」
+      newSelection = ["鏃犲瑙傞棶棰�"];
+    }
+  } else {
+    // 鐐瑰嚮鍏朵粬閫夐」
+    if (isCurrentlyChecked) {
+      // 鍙栨秷閫変腑璇ラ�夐」
+      newSelection = currentValues.filter((v) => v !== value);
+    } else {
+      // 閫変腑璇ラ�夐」锛岀Щ闄�"鏃犲瑙傞棶棰�"
+      const filteredValues = currentValues.filter((v) => v !== "鏃犲瑙傞棶棰�");
+      newSelection = [...filteredValues, value];
+    }
+  }
+
+  formData.appearance = newSelection;
 };
 
 const formatValue = (value: any, unit?: string) => {
@@ -409,7 +461,12 @@
   formData.dia = inspectionResult.dia || "";
   formData.maxDia = inspectionResult.maxDia || "";
   formData.minDia = inspectionResult.minDia || "";
-  formData.appearance = inspectionResult.appearance || [];
+  // 纭繚 appearance 鏄暟缁�
+  formData.appearance = Array.isArray(inspectionResult.appearance)
+    ? inspectionResult.appearance
+    : inspectionResult.appearance
+      ? [inspectionResult.appearance]
+      : [];
   formData.windingTightness = inspectionResult.windingTightness || "";
   formData.arrangementNeatness = inspectionResult.arrangementNeatness || "";
   formData.aluminumWireDistance = inspectionResult.aluminumWireDistance || "";
@@ -423,6 +480,13 @@
   try {
     const response = await RoutingInspectionApi.getDrawInspectInfoById({ id });
     detailData.value = response.data;
+
+    // 濡傛灉宸℃鍛樹负绌猴紝榛樿璁剧疆涓哄綋鍓嶇櫥褰曠敤鎴�
+    if (!detailData.value.processInspectionUserName) {
+      detailData.value.processInspectionUserName =
+        userInfo.value?.nickName || userInfo.value?.userName || "";
+    }
+
     tempFiles.value = [];
     initFormData();
   } catch (error) {
@@ -464,7 +528,16 @@
     return uni.showToast({ title: "鎴愬搧妯″悗鎺ュご鎯呭喌涓哄繀濉」", icon: "none" });
   if (!formData.conclusion) return uni.showToast({ title: "缁撹涓哄繀濉」", icon: "none" });
   if (!formData.isFully) return uni.showToast({ title: "閾濇潌鏍峰搧鏄惁榻愬叏涓哄繀濉」", icon: "none" });
-  if (!deviceUid.value) return uni.showToast({ title: "璇锋壂鎻忎簩缁寸爜", icon: "none" });
+
+  // 楠岃瘉鎵爜鏁版嵁锛堜粠缂撳瓨鎴栨柊鎵爜鑾峰彇锛�
+  console.log("淇濆瓨鍓嶆鏌� deviceUid:", deviceUid.value);
+  if (!deviceUid.value) {
+    return uni.showToast({
+      title: "璇峰厛鎵弿璁惧浜岀淮鐮�",
+      icon: "none",
+      duration: 2000,
+    });
+  }
   const { newFiles } = attachmentRef.value.getSubmitFiles();
   console.log("newFiles", newFiles);
   const allFileIds = [...newFiles];
@@ -488,9 +561,20 @@
       processInspectionAttachmentList: allFileIds,
     });
     if (res.code === 200) {
-      uni.showToast({ title: "淇濆瓨鎴愬姛", icon: "success" });
-      isEdit.value = false;
-      getDetailData(paramsId.value, paramsType.value);
+      // 璁剧疆鍒锋柊鏍囪锛屽憡璇夊垪琛ㄩ〉闇�瑕佸埛鏂�
+      uni.setStorageSync("needRefreshInspectionList", true);
+
+      uni.showToast({
+        title: "淇濆瓨鎴愬姛",
+        icon: "success",
+        duration: 1500,
+      });
+      // 寤惰繜杩斿洖鍒楄〃椤碉紝璁╃敤鎴风湅鍒版垚鍔熸彁绀�
+      setTimeout(() => {
+        uni.navigateBack({
+          delta: 1,
+        });
+      }, 1500);
     } else {
       uni.showModal({ title: res.msg || "淇濆瓨澶辫触", icon: "error" });
     }
@@ -505,33 +589,36 @@
 };
 
 const openScan = () => {
-  scanRef.value.triggerScan();
+  console.log("indexLS - 鐐瑰嚮鎵爜鎸夐挳锛堝叏灞�鎵爜妯″紡锛屾棤闇�鎵嬪姩瑙﹀彂锛�");
+  // 鍏ㄥ眬鎵爜妯″紡涓嬶紝纭欢鎵爜浼氳嚜鍔ㄨЕ鍙戯紝鏃犻渶鎵嬪姩璋冪敤
+  uni.showToast({
+    title: "璇蜂娇鐢ㄦ壂鐮佹灙鎵弿",
+    icon: "none",
+  });
 };
-const getScanCode = (params: any) => {
-  let codeObj = {};
-  try {
-    codeObj = JSON.parse(params.code);
-  } catch (err) {
-    toast.error("鎵爜鏁版嵁寮傚父");
-    return; // 瑙f瀽澶辫触鐩存帴杩斿洖锛岄伩鍏嶅悗缁敊璇�
+
+// 椤甸潰鏄剧ず鏃剁殑澶勭悊
+onShow(() => {
+  console.log("========== indexLS - onShow 瑙﹀彂 ==========");
+  // 閲嶆柊鍚敤鐩戝惉鍣紙纭繚鐩戝惉鍣ㄦ湁鏁堬級
+  enableListener();
+  // 鍔犺浇缂撳瓨锛堟洿鏂癠I鏄剧ず锛�
+  const cachedData = loadFromCache();
+
+  // 濡傛灉娌℃湁缂撳瓨鏁版嵁锛屾彁绀虹敤鎴烽渶瑕佹壂鐮�
+  if (!cachedData || !cachedData.uid) {
+    console.log("鈿狅笍 鏈娴嬪埌鎵爜缂撳瓨锛岀敤鎴烽渶瑕佹壂鎻忚澶囦簩缁寸爜");
+    // 鍦ㄧ紪杈戞ā寮忎笅鎵嶆彁绀�
+    if (isEdit.value) {
+      setTimeout(() => {
+        uni.showToast({
+          title: "璇锋壂鎻忚澶囦簩缁寸爜鍚庡啀淇濆瓨",
+          icon: "none",
+          duration: 2000,
+        });
+      }, 500);
+    }
   }
-  deviceUid.value = codeObj?.uid;
-  toast.success("鎵爜鎴愬姛");
-};
-// 纭繚鍏堢Щ闄ゅ啀娣诲姞鐩戝惉
-const setupScanListener = () => {
-  uni.$off("scan", getScanCode); // 鍏堢Щ闄ゆ棫鐨�
-  uni.$on("scan", getScanCode); // 鍐嶆坊鍔犳柊鐨�
-};
-onUnmounted(() => {
-  // 寮�鍚箍鎾洃鍚簨浠�
-  uni.$off("scan", getScanCode);
-  console.log("绂诲紑1");
-});
-onMounted(() => {
-  // 寮�鍚箍鎾洃鍚簨浠�
-  setupScanListener();
-  console.log("鏄剧ず1");
 });
 </script>
 
@@ -559,6 +646,18 @@
 
 .placeholder {
   flex: 1;
+}
+
+.scan-info {
+  display: flex;
+  align-items: center;
+  margin-right: 10px;
+
+  .scan-device-text {
+    font-size: 14px;
+    color: #0d867f;
+    font-weight: 500;
+  }
 }
 
 .scan-wrapper {
@@ -681,4 +780,4 @@
   align-items: flex-start; // 鍨傜洿鏂瑰悜椤堕儴瀵归綈锛堜笂绉诲叧閿級
   gap: 20rpx; // 閫夐」涔嬮棿鐨勯棿璺�
 }
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.9.3