<template>
|
<view>
|
<wd-row>
|
<wd-col :span="21">
|
<wd-search placeholder-left hide-cancel></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>
|
<wd-tab
|
v-for="(item, index) in patrolList"
|
:key="index"
|
:title="`${item.deviceModel}(待检查${item.pendingNum}条)`"
|
class="tab_bg"
|
>
|
<ProductList
|
:api="RoutingInspectionApi.getInspectListByPatrol"
|
:ProList="item"
|
/>
|
</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 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";
|
|
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 handlePatrolData = (index: number, count: number) => {
|
// 可以在这里更新特定巡检设备的待检查数量
|
// 例如:patrolList.value[index].pendingNum = count;
|
};
|
|
const openScan = () => {
|
scanRef.value.triggerScan();
|
};
|
|
const getScanCode = async () => {
|
const { code } = await reportApi.sendWorkTime({
|
userName: userInfo.value.userName,
|
});
|
if (code == 200) {
|
toast.success("扫码成功");
|
}
|
};
|
|
// 获取特定巡检设备的数据
|
const getPatrolData = (item: any) => {
|
return async (params: any) => {
|
// 这里可以根据item中的信息调用相应的接口获取详情
|
// 返回的数据格式需要与ProductList组件期望的格式一致
|
return {
|
code: 200,
|
data: {
|
type: "巡检",
|
data: {
|
total: 0,
|
records: []
|
}
|
}
|
};
|
};
|
};
|
|
// 获取巡检设备列表
|
const loadPatrolList = async () => {
|
try {
|
const { data } = await RoutingInspectionApi.getDeviceInspectListByPatrol({});
|
if (data) {
|
patrolList.value = data;
|
}
|
} catch (error) {
|
toast.error("获取巡检设备列表失败");
|
}
|
};
|
|
// 确保先移除再添加监听
|
const setupScanListener = () => {
|
uni.$off("scan", getScanCode); // 先移除旧的
|
uni.$on("scan", getScanCode); // 再添加新的
|
};
|
|
onMounted(() => {
|
// 开启广播监听事件
|
setupScanListener();
|
console.log("显示1");
|
// 页面加载时获取巡检设备列表
|
loadPatrolList();
|
});
|
|
onUnmounted(() => {
|
// 开启广播监听事件
|
uni.$off("scan", getScanCode);
|
console.log("离开1");
|
});
|
</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>
|