From 991f6f78fccb86b2718ab96969a69304daafe2b4 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期一, 03 十一月 2025 17:32:50 +0800
Subject: [PATCH] fix: 完成巡查
---
 src/pages/routingInspection/detail/indexJX.vue |  239 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 177 insertions(+), 62 deletions(-)
diff --git a/src/pages/routingInspection/detail/indexJX.vue b/src/pages/routingInspection/detail/indexJX.vue
index f82336a..27572e5 100644
--- a/src/pages/routingInspection/detail/indexJX.vue
+++ b/src/pages/routingInspection/detail/indexJX.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>
@@ -70,20 +73,20 @@
         <wd-form-item label="鐢熶骇闀垮害" prop="actuallyLength">
           {{ formatValue(recordData.fixedInfo?.actuallyLength, "m") }}
         </wd-form-item>
-        <wd-form-item label="寮犲姏璁剧疆" prop="twistTension">
-          {{ formatValue(recordData.fixedInfo?.twistTension, "N/m") }}
+        <wd-form-item label="寮犲姏璁剧疆" prop="tensionSetting">
+          {{ formatValue(recordData.fixedInfo?.tensionSetting, "N/m") }}
         </wd-form-item>
         <!-- 缁炲埗澶栧緞锛堝彲缂栬緫锛� -->
-        <wd-form-item label="缁炲埗澶栧緞" prop="twistDiameter" required>
+        <wd-form-item label="缁炲悎澶栧緞" prop="twistedOuterDiameter" required>
           <template v-if="isEdit">
             <wd-input
-              v-model="formData.twistDiameter"
-              placeholder="璇疯緭鍏ョ粸鍒跺寰勶紙mm锛�"
+              v-model="formData.twistedOuterDiameter"
+              placeholder="璇疯緭鍏ョ粸鍚堝寰勶紙mm锛�"
               type="number"
             />
           </template>
           <template v-else>
-            {{ formatValue(formData.twistDiameter, "mm") }}
+            {{ formatValue(formData.twistedOuterDiameter, "mm") }}
           </template>
         </wd-form-item>
       </wd-col>
@@ -205,7 +208,12 @@
         </wd-form-item>
         <wd-form-item label="鑺傝窛" prop="pitch" required>
           <template v-if="isEdit">
-            <wd-input v-model="item.pitch" placeholder="璇疯緭鍏ヨ妭璺濓紙mm锛�" type="number" />
+            <wd-input
+              v-model="item.pitch"
+              placeholder="璇疯緭鍏ヨ妭璺濓紙mm锛�"
+              type="number"
+              @input="updatePitchRatio(item)"
+            />
           </template>
           <template v-else>
             {{ formatValue(item.pitch, "mm") }}
@@ -225,17 +233,18 @@
       <wd-col :span="24">
         <wd-form-item label="浜у搧澶栬" prop="productAppearance" required>
           <template v-if="isEdit">
-            <wd-checkbox-group
-              v-model="formData.productAppearance"
-              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.productAppearance.includes(opt.value)"
+                @click="handleAppearanceClick(opt.value)"
+                style="width: 100px"
+              >
                 {{ opt.label }}
               </wd-checkbox>
-            </wd-checkbox-group>
+            </view>
           </template>
           <template v-else>
             {{ formatProductAppearance(formData.productAppearance) }}
@@ -308,18 +317,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, computed } 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 paramsType = ref("");
 const paramsId = ref("");
@@ -328,15 +337,25 @@
 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 detailData = reactive<any>({});
 const detailDataLoaded = ref(false);
 
+// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛淇℃伅
+const userStore = useUserStore();
+const userInfo: any = computed(() => userStore.userInfo);
+
+// 浣跨敤鎵爜绠$悊 composable锛堝叏灞�鐩戝惉鍣紝涓嶉殢椤甸潰鍒囨崲鍏抽棴锛�
+const {
+  deviceUid,
+  deviceModel: scannedDeviceModel,
+  loadFromCache,
+  enableListener,
+} = useScanCode("scanJX");
+
 const formData = reactive({
-  twistDiameter: "", // 缁炲埗澶栧緞
+  twistedOuterDiameter: "", // 缁炲埗澶栧緞
   structureFormula: "", // 鎴愬搧缁撴瀯
   structureItems: [], // 缁撴瀯鏍囧噯鍊煎拰瀹炴祴
   inspectTwist: [], // 缁炵嚎宸ヨ壓璐ㄩ噺鎺у埗
@@ -370,15 +389,19 @@
   const structureResult = recordData.value.structureInfo?.structureRecordResult || {};
   const inspectionResult = recordData.value.inspectionResult || {};
 
-  formData.twistDiameter = inspectionResult.twistDiameter || "";
+  formData.twistedOuterDiameter =
+    recordData.value.structureInfo.structureRecordResult.twistedOuterDiameter || "";
   formData.structureFormula = structureResult.inspectStructure?.structureFormula || "";
   formData.sampleComplete = inspectionResult.sampleComplete || "";
   formData.conclusion = structureResult.conclusion || "";
-  formData.productAppearance = Array.isArray(structureResult.productAppearance)
+
+  // 鍒濆鍖栦骇鍝佸瑙�
+  const appearance = Array.isArray(structureResult.productAppearance)
     ? structureResult.productAppearance
     : structureResult.productAppearance
-    ? [structureResult.productAppearance]
-    : [];
+      ? [structureResult.productAppearance]
+      : [];
+  formData.productAppearance = appearance;
 
   formData.structureItems = JSON.parse(
     JSON.stringify(structureResult.inspectStructure?.structureItems || [])
@@ -395,6 +418,13 @@
     const response = await RoutingInspectionApi.getStrandedInspectionStructureInfoById({ id });
     recordData.value = response.data;
     detailData.value = response.data.structureInfo;
+
+    // 濡傛灉璁板綍浜轰负绌猴紝榛樿璁剧疆涓哄綋鍓嶇櫥褰曠敤鎴�
+    if (recordData.value.structureInfo && !recordData.value.structureInfo.createUserName) {
+      recordData.value.structureInfo.createUserName =
+        userInfo.value?.nickName || userInfo.value?.userName || "";
+    }
+
     console.log("detailData.value", detailData.value);
     tempFiles.value = []; // 娓呯┖涓存椂鏂囦欢
     initFormData(); // 鏁版嵁杩斿洖鍚庡垵濮嬪寲琛ㄥ崟
@@ -434,7 +464,8 @@
 const saveList = async () => {
   // 1. 鍩虹瀛楁鏍¢獙
   if (!formData.structureFormula) return uni.showToast({ title: "鎴愬搧缁撴瀯涓哄繀濉」", icon: "none" });
-  if (!formData.twistDiameter) return uni.showToast({ title: "缁炲埗澶栧緞涓哄繀濉」", icon: "none" });
+  if (!formData.twistedOuterDiameter)
+    return uni.showToast({ title: "缁炲埗澶栧緞涓哄繀濉」", icon: "none" });
   if (!formData.productAppearance.length)
     return uni.showToast({ title: "浜у搧澶栬涓哄繀濉」", icon: "none" });
   if (!formData.conclusion) return uni.showToast({ title: "缁撹涓哄繀濉」", icon: "none" });
@@ -458,8 +489,15 @@
     if (!item.pitchRatio)
       return uni.showToast({ title: `${item.twistName}鑺傚緞姣斾负蹇呭~椤筦, icon: "none" });
   }
-  console.log("1111", deviceUid.value);
-  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];
@@ -468,7 +506,7 @@
       deviceUid: deviceUid.value,
       id: paramsId.value,
       result: {
-        twistDiameter: formData.twistDiameter,
+        twistedOuterDiameter: formData.twistedOuterDiameter,
         structureFormula: formData.structureFormula,
         structureItems: formData.structureItems,
         inspectTwist: formData.inspectTwist,
@@ -483,9 +521,20 @@
     });
 
     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" });
     }
@@ -507,11 +556,11 @@
     case 1:
       return "danger"; // 宸查┏鍥�
     case 2:
-      return "info"; // 寰呭鏍�
+      return "primary"; // 寰呭鏍�
     case 3:
       return "success"; // 閫氳繃
     default:
-      return "info";
+      return "default";
   }
 };
 
@@ -553,36 +602,90 @@
   });
 };
 
-const openScan = () => {
-  scanRef.value.triggerScan();
+// 璁$畻鑺傚緞姣�
+const calculatePitchRatio = (pitch: string, dia: string) => {
+  // 濡傛灉pitch鎴杁ia涓虹┖锛屽垯杩斿洖"-"
+  if (!pitch || !dia) return "-";
+
+  // 灏唒itch鍜宒ia杞崲涓烘诞鐐规暟
+  const pitchNum = parseFloat(pitch);
+  const diaNum = parseFloat(dia);
+
+  // 濡傛灉pitchNum鎴杁iaNum鏄疦aN锛屾垨鑰卍iaNum涓�0锛屽垯杩斿洖"-"
+  if (isNaN(pitchNum) || isNaN(diaNum) || diaNum === 0) return "-";
+
+  // 璁$畻pitchNum鍜宒iaNum鐨勬瘮鍊硷紝骞朵繚鐣欎袱浣嶅皬鏁�
+  return (pitchNum / diaNum).toFixed(2);
 };
-const getScanCode = (params: any) => {
-  console.log("瀹屾暣鍙傛暟锛�", params);
-  let codeObj = {};
-  try {
-    codeObj = JSON.parse(params.code);
-  } catch (err) {
-    console.error("JSON瑙f瀽澶辫触锛�", err);
-    toast.error("鎵爜鏁版嵁寮傚父");
-    return;
+
+// 鏇存柊鑺傚緞姣旓紙褰撹妭璺濆彉鍖栨椂鑷姩璁$畻锛�
+const updatePitchRatio = (item: any) => {
+  // 浣跨敤缁炲悎澶栧緞浣滀负鐩村緞鏉ヨ绠楄妭寰勬瘮
+  const dia = item.dia;
+  item.pitchRatio = calculatePitchRatio(item.pitch, dia);
+};
+
+// 澶勭悊浜у搧澶栬閫夋嫨鐨勪簰鏂ラ�昏緫
+const handleAppearanceClick = (value: string) => {
+  const currentValues = [...formData.productAppearance];
+  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];
+    }
   }
-  deviceUid.value = codeObj?.uid;
-  toast.success("鎵爜鎴愬姛");
+
+  formData.productAppearance = newSelection;
 };
-// 纭繚鍏堢Щ闄ゅ啀娣诲姞鐩戝惉
-const setupScanListener = () => {
-  uni.$off("scan", getScanCode); // 鍏堢Щ闄ゆ棫鐨�
-  uni.$on("scan", getScanCode); // 鍐嶆坊鍔犳柊鐨�
+
+const openScan = () => {
+  console.log("indexJX - 鐐瑰嚮鎵爜鎸夐挳锛堝叏灞�鎵爜妯″紡锛屾棤闇�鎵嬪姩瑙﹀彂锛�");
+  // 鍏ㄥ眬鎵爜妯″紡涓嬶紝纭欢鎵爜浼氳嚜鍔ㄨЕ鍙戯紝鏃犻渶鎵嬪姩璋冪敤
+  uni.showToast({
+    title: "璇蜂娇鐢ㄦ壂鐮佹灙鎵弿",
+    icon: "none",
+  });
 };
-onUnmounted(() => {
-  // 寮�鍚箍鎾洃鍚簨浠�
-  uni.$off("scan", getScanCode);
-  console.log("绂诲紑1");
-});
-onMounted(() => {
-  // 寮�鍚箍鎾洃鍚簨浠�
-  setupScanListener();
-  console.log("鏄剧ず1");
+
+// 椤甸潰鏄剧ず鏃剁殑澶勭悊
+onShow(() => {
+  console.log("========== indexJX - onShow 瑙﹀彂 ==========");
+  // 閲嶆柊鍚敤鐩戝惉鍣紙纭繚鐩戝惉鍣ㄦ湁鏁堬級
+  enableListener();
+  // 鍔犺浇缂撳瓨锛堟洿鏂癠I鏄剧ず锛�
+  const cachedData = loadFromCache();
+
+  // 濡傛灉娌℃湁缂撳瓨鏁版嵁锛屾彁绀虹敤鎴烽渶瑕佹壂鐮�
+  if (!cachedData || !cachedData.uid) {
+    console.log("鈿狅笍 鏈娴嬪埌鎵爜缂撳瓨锛岀敤鎴烽渶瑕佹壂鎻忚澶囦簩缁寸爜");
+    // 鍦ㄧ紪杈戞ā寮忎笅鎵嶆彁绀�
+    if (isEdit.value) {
+      setTimeout(() => {
+        uni.showToast({
+          title: "璇锋壂鎻忚澶囦簩缁寸爜鍚庡啀淇濆瓨",
+          icon: "none",
+          duration: 2000,
+        });
+      }, 500);
+    }
+  }
 });
 </script>
 
@@ -612,6 +715,18 @@
   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 {
   width: 38px;
   height: 38px;
--
Gitblit v1.9.3