From 8cc901ed214f3885b34a07d0520fbcfd50063439 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 19 十一月 2025 14:30:39 +0800
Subject: [PATCH] fix: 完成绞线自检,生产确认等功能新增

---
 src/pages/production/index.vue |   89 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/src/pages/production/index.vue b/src/pages/production/index.vue
index a55a50a..73d3f94 100644
--- a/src/pages/production/index.vue
+++ b/src/pages/production/index.vue
@@ -2,10 +2,17 @@
   <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">
+        <view class="scan_box" @click="openScan">
           <wd-icon name="scan" size="24px" color="#0D867F"></wd-icon>
         </view>
       </wd-col>
@@ -14,20 +21,26 @@
       <wd-tab :title="`寰呯敓浜�(${total.wait})`" class="tab_bg">
         <ProductList
           ref="waitRef"
+          :key="`wait-${searchKey}`"
           :api="ManageApi.getProductList"
           state="寰呭畬鎴�"
+          :search="searchKeyword"
           @ok="changeWait"
         />
       </wd-tab>
       <wd-tab :title="`宸茬敓浜�(${total.already})`" class="tab_bg">
         <ProductList
           ref="alreadyRef"
+          :key="`already-${searchKey}`"
           :api="ManageApi.getProductList"
           state="宸插畬鎴�"
+          :search="searchKeyword"
           @ok="changeAlready"
         />
       </wd-tab>
     </wd-tabs>
+    <Scan ref="scanRef" emitName="scan" />
+    <wd-toast />
   </view>
 </template>
 
@@ -35,10 +48,21 @@
 import ManageApi from "@/api/product/manage";
 import { ref } from "vue";
 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";
+
+const scanRef = ref();
+const userStore = useUserStore();
+const userInfo: any = computed(() => userStore.userInfo);
+const toast = useToast();
 
 const waitRef = ref();
 const alreadyRef = ref();
 const tab = ref<number>(0);
+const searchKeyword = ref("");
+const searchKey = ref(0);
 const total = reactive({
   wait: 0,
   already: 0,
@@ -51,6 +75,67 @@
 const changeAlready = (num: number) => {
   total.already = num;
 };
+
+// 鑾峰彇缁熻鏁版嵁
+const getStatistics = async () => {
+  try {
+    const params: any = {};
+    if (searchKeyword.value) {
+      params.search = searchKeyword.value;
+    }
+    const { code, data } = await ManageApi.getProductStatistics(params);
+    if (code === 200 && data) {
+      total.wait = data["寰呭畬鎴�"] || 0;
+      total.already = data["宸插畬鎴�"] || 0;
+    }
+  } catch (error) {
+    console.error("鑾峰彇缁熻鏁版嵁澶辫触:", error);
+  }
+};
+
+const handleSearch = () => {
+  searchKey.value++;
+  // 鎼滅储鏃舵洿鏂扮粺璁℃暟鎹�
+  getStatistics();
+};
+
+const handleClear = () => {
+  searchKeyword.value = "";
+  handleSearch();
+};
+
+const openScan = () => {
+  scanRef.value.triggerScan();
+};
+
+const getScanCode = async () => {
+  console.log("鐢熶骇绠$悊鎵爜鍥炶皟");
+  const { code } = await reportApi.sendWorkTime({
+    userName: userInfo.value.userName,
+  });
+  if (code == 200) {
+    toast.success("鎵爜鎴愬姛");
+  }
+};
+
+// 纭繚鍏堢Щ闄ゅ啀娣诲姞鐩戝惉
+const setupScanListener = () => {
+  uni.$off("scan", getScanCode); // 鍏堢Щ闄ゆ棫鐨�
+  uni.$on("scan", getScanCode); // 鍐嶆坊鍔犳柊鐨�
+};
+
+onMounted(() => {
+  // 寮�鍚箍鎾洃鍚簨浠�
+  setupScanListener();
+  // 鑾峰彇缁熻鏁版嵁
+  getStatistics();
+  console.log("鏄剧ず1");
+});
+onUnmounted(() => {
+  // 寮�鍚箍鎾洃鍚簨浠�
+  uni.$off("scan", getScanCode);
+  console.log("绂诲紑1");
+});
 </script>
 
 <style lang="scss" scoped>

--
Gitblit v1.9.3