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/index.vue |  107 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 61 insertions(+), 46 deletions(-)

diff --git a/src/pages/routingInspection/index.vue b/src/pages/routingInspection/index.vue
index 7979244..ddad4be 100644
--- a/src/pages/routingInspection/index.vue
+++ b/src/pages/routingInspection/index.vue
@@ -2,7 +2,14 @@
   <view>
     <wd-row>
       <wd-col :span="21">
-        <wd-search placeholder-left hide-cancel></wd-search>
+        <wd-search
+          v-model="searchKeyword"
+          placeholder="璇疯緭鍏ョ彮缁勫悕绉�"
+          placeholder-left
+          hide-cancel
+          @search="handleSearch"
+          @clear="handleClear"
+        ></wd-search>
       </wd-col>
       <wd-col :span="3">
         <view class="scan_box" @click="openScan">
@@ -17,64 +24,64 @@
         :title="`${item.deviceModel}锛堝緟妫�鏌�${item.pendingNum}鏉★級`"
         class="tab_bg"
       >
-        <ProductList :api="RoutingInspectionApi.getInspectListByPatrol" :ProList="item" />
+        <ProductList
+          :key="searchKey"
+          :api="RoutingInspectionApi.getInspectListByPatrol"
+          :ProList="{ ...item, teamName: searchKeyword }"
+        />
       </wd-tab>
     </wd-tabs>
-    <Scan ref="scanRef" emitName="scan" />
     <wd-toast />
   </view>
 </template>
 
 <script lang="ts" setup>
 import { ref, reactive, computed, onMounted, onUnmounted } from "vue";
+import { onShow, onHide } from "@dcloudio/uni-app";
 import ProductList from "./list/index.vue";
-import Scan from "@/components/scan/index.vue";
 import { useUserStore } from "@/store/modules/user";
 import reportApi from "@/api/work/report";
 import { useToast } from "wot-design-uni";
 import RoutingInspectionApi from "@/api/routingInspection/routingInspection";
+import { useScanCode } from "@/composables/useScanCode";
 
-const scanRef = ref();
 const userStore = useUserStore();
 const userInfo: any = computed(() => userStore.userInfo);
 const toast = useToast();
 const tab = ref<number>(0);
 const patrolList = ref<any[]>([]); // 宸℃璁惧鍒楄〃鏁版嵁
+const searchKeyword = ref<string>(""); // 鎼滅储鍏抽敭璇嶏紙鐝粍鍚嶇О锛�
+const searchKey = ref<number>(0); // 鐢ㄤ簬寮哄埗鍒锋柊鍒楄〃
+
+// 浣跨敤鎵爜绠$悊 composable锛堝叏灞�鐩戝惉鍣紝涓嶉殢椤甸潰鍒囨崲鍏抽棴锛�
+const { deviceUid, deviceModel, hasScanned, displayText, loadFromCache, enableListener } =
+  useScanCode("scanIndex");
 
 const handlePatrolData = (index: number, count: number) => {
   // 鍙互鍦ㄨ繖閲屾洿鏂扮壒瀹氬贰妫�璁惧鐨勫緟妫�鏌ユ暟閲�
   // 渚嬪锛歱atrolList.value[index].pendingNum = count;
 };
 
+// 澶勭悊鎼滅储
+const handleSearch = (value: string) => {
+  console.log("鎼滅储鐝粍:", value);
+  searchKey.value++; // 鏇存柊 key 寮哄埗鍒锋柊鍒楄〃
+};
+
+// 澶勭悊娓呯┖鎼滅储
+const handleClear = () => {
+  console.log("娓呯┖鎼滅储");
+  searchKeyword.value = "";
+  searchKey.value++; // 鏇存柊 key 寮哄埗鍒锋柊鍒楄〃
+};
+
 const openScan = () => {
-  scanRef.value.triggerScan();
-};
-
-const getScanCode = async () => {
-  const { code } = await reportApi.sendWorkTime({
-    userName: userInfo.value.userName,
+  console.log("index.vue - 鐐瑰嚮鎵爜鎸夐挳锛堝叏灞�鎵爜妯″紡锛屾棤闇�鎵嬪姩瑙﹀彂锛�");
+  // 鍏ㄥ眬鎵爜妯″紡涓嬶紝纭欢鎵爜浼氳嚜鍔ㄨЕ鍙戯紝鏃犻渶鎵嬪姩璋冪敤
+  uni.showToast({
+    title: "璇蜂娇鐢ㄦ壂鐮佹灙鎵弿",
+    icon: "none",
   });
-  if (code == 200) {
-    toast.success("鎵爜鎴愬姛");
-  }
-};
-
-// 鑾峰彇鐗瑰畾宸℃璁惧鐨勬暟鎹�
-const getPatrolData = (item: any) => {
-  return async (params: any) => {
-    // 杩欓噷鍙互鏍规嵁item涓殑淇℃伅璋冪敤鐩稿簲鐨勬帴鍙h幏鍙栬鎯�
-    // 杩斿洖鐨勬暟鎹牸寮忛渶瑕佷笌ProductList缁勪欢鏈熸湜鐨勬牸寮忎竴鑷�
-    return {
-      code: 200,
-      data: {
-        type: "宸℃",
-        data: {
-          total: 0,
-          records: [],
-        },
-      },
-    };
-  };
 };
 
 // 鑾峰彇宸℃璁惧鍒楄〃
@@ -89,24 +96,32 @@
   }
 };
 
-// 纭繚鍏堢Щ闄ゅ啀娣诲姞鐩戝惉
-const setupScanListener = () => {
-  uni.$off("scan", getScanCode); // 鍏堢Щ闄ゆ棫鐨�
-  uni.$on("scan", getScanCode); // 鍐嶆坊鍔犳柊鐨�
-};
-
 onMounted(() => {
-  // 寮�鍚箍鎾洃鍚簨浠�
-  setupScanListener();
-  console.log("鏄剧ず1");
   // 椤甸潰鍔犺浇鏃惰幏鍙栧贰妫�璁惧鍒楄〃
   loadPatrolList();
+  // 鍚敤鍏ㄥ眬鐩戝惉鍣�
+  enableListener();
+  console.log("index.vue - onMounted");
 });
 
-onUnmounted(() => {
-  // 寮�鍚箍鎾洃鍚簨浠�
-  uni.$off("scan", getScanCode);
-  console.log("绂诲紑1");
+onShow(() => {
+  console.log("========== index.vue - onShow 瑙﹀彂 ==========");
+  // 椤甸潰鏄剧ず鏃堕噸鏂板惎鐢ㄧ洃鍚櫒锛堢‘淇濈洃鍚櫒鏈夋晥锛�
+  enableListener();
+  // 鍔犺浇缂撳瓨锛堟洿鏂癠I鏄剧ず锛�
+  loadFromCache();
+
+  // 妫�鏌ユ槸鍚﹂渶瑕佸埛鏂板垪琛紙鍙湁鎻愪氦鎴愬姛鍚庢墠鍒锋柊锛�
+  const needRefresh = uni.getStorageSync("needRefreshInspectionList");
+  if (needRefresh) {
+    console.log("妫�娴嬪埌闇�瑕佸埛鏂板垪琛紝寮�濮嬪埛鏂�...");
+    // 閲嶆柊鍔犺浇宸℃璁惧鍒楄〃锛堝埛鏂板緟妫�鏌ユ暟閲忥級
+    loadPatrolList();
+    // 寮哄埗鍒锋柊 ProductList 缁勪欢
+    searchKey.value++;
+    // 娓呴櫎鍒锋柊鏍囪
+    uni.removeStorageSync("needRefreshInspectionList");
+  }
 });
 </script>
 
@@ -146,4 +161,4 @@
 .statistics_box {
   margin: 15px;
 }
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.3