spring
16 小时以前 b83e8417c341636a6da3a8eb7db7c151ef3c00cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<template>
  <view>
    <wd-row>
      <wd-col :span="21">
        <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">
          <wd-icon name="scan" size="24px" color="#0D867F"></wd-icon>
        </view>
      </wd-col>
    </wd-row>
    <wd-tabs v-model="tab" auto-line-width slidable="always" :map-num="patrolList.length">
      <wd-tab
        v-for="(item, index) in patrolList"
        :key="index"
        :title="`${item.deviceModel}(待检查${item.pendingNum}条)`"
        class="tab_bg"
      >
        <ProductList
          :key="searchKey"
          :api="RoutingInspectionApi.getInspectListByPatrol"
          :ProList="{ ...item, teamName: searchKeyword }"
        />
      </wd-tab>
    </wd-tabs>
    <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 { 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 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) => {
  // 可以在这里更新特定巡检设备的待检查数量
  // 例如:patrolList.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 = () => {
  console.log("index.vue - 点击扫码按钮(全局扫码模式,无需手动触发)");
  // 全局扫码模式下,硬件扫码会自动触发,无需手动调用
  uni.showToast({
    title: "请使用扫码枪扫描",
    icon: "none",
  });
};
 
// 获取巡检设备列表
const loadPatrolList = async () => {
  try {
    const { data } = await RoutingInspectionApi.getDeviceInspectListByPatrol({});
    if (data) {
      patrolList.value = data;
    }
  } catch (error) {
    toast.error("获取巡检设备列表失败");
  }
};
 
onMounted(() => {
  // 页面加载时获取巡检设备列表
  loadPatrolList();
  // 启用全局监听器
  enableListener();
  console.log("index.vue - onMounted");
});
 
onShow(() => {
  console.log("========== index.vue - onShow 触发 ==========");
  // 页面显示时重新启用监听器(确保监听器有效)
  enableListener();
  // 加载缓存(更新UI显示)
  loadFromCache();
 
  // 检查是否需要刷新列表(只有提交成功后才刷新)
  const needRefresh = uni.getStorageSync("needRefreshInspectionList");
  if (needRefresh) {
    console.log("检测到需要刷新列表,开始刷新...");
    // 重新加载巡检设备列表(刷新待检查数量)
    loadPatrolList();
    // 强制刷新 ProductList 组件
    searchKey.value++;
    // 清除刷新标记
    uni.removeStorageSync("needRefreshInspectionList");
  }
});
</script>
 
<style lang="scss" scoped>
::v-deep .wd-search__block {
  border-radius: unset;
}
.scan_box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 6px;
  background: #fff;
}
::v-deep .wd-tabs__line {
  background: #0d867f;
}
::v-deep .wd-tabs__nav {
  border-bottom: 1px #dddddd solid;
}
.tab_bg {
  background: #f3f9f8;
}
 
.icon_box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: #e7f4ec99;
  border-radius: 50%;
}
 
.statistics_box {
  margin: 15px;
}
</style>