安琪酵母(西藏)益生菌信息采集中心智能实验室
longyvfengyun
2023-09-06 093388d51f56e95d155f204971d49fe303b76408
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
import {searchDoorHistoryApi} from "@/views/accessControl/js/api";
import {ref} from "vue";
import door from "@/assets/js/const/door";
import getLabelByKey from "@/assets/js/tools/getLabelByKey";
import exportExcelUtil from "@/assets/js/tools/exportExcelUtil";
import { ElMessage } from 'element-plus';
 
const doorInfoHistoryModule =  (id)=>{
  const doorId = ref(id);
  const headers = {carcameraName:"门禁名称", recordTime: "开门时间", state: "状态变换"};
  const lockStatusList = door.lockStatus;
  const doorHistoryData = ref([]);
  const page = ref({
    pageCurr: 1,
    pageSize: 10,
    total: 0
  });
 
  /**
   * 查询门禁开门历史记录
   * @return {Promise<void>}
   */
  const searchDoorHistory = async (isExportFile, isAll)=>{
    const pageValue = page.value;
    // 判断是否导出全部 === 不能删除,防止isExPortFile={}
    isExportFile = isExportFile === true;
    isAll = isAll === true;
    try{
      const curr = isExportFile && isAll?1:pageValue.pageCurr;
      const size = isExportFile && isAll?pageValue.total:pageValue.pageSize;
      const res = await searchDoorHistoryApi(doorId.value, curr, size);
      let list = [];
      let pageCurr = 1;
      let total = 0;
      let rs = res.data;
      if(rs.code === 1 && rs.data) {
        let data2 = rs.data2;
        list = data2.list.map(item=>{
          let lastState = getLabelByKey(item.lastStatus, lockStatusList, "未知");
          let state = getLabelByKey(item.status, lockStatusList, "未知");
          item.carcameraName = item.cameraInf.carcameraName;
          item.state = "从"+lastState+"变更为"+state;
          return item;
        });
        pageCurr = data2.pageNum;
        total = data2.total;
      }else {
        pageCurr = 0;
        total = 0;
      }
      if(isExportFile) {
        exportExcelUtil(
          headers,
          list,
          "门禁历史记录-"+new Date().format("yyyy-MM-dd hh:mm:ss")
        );
      }else {
        page.value.pageCurr = pageCurr;
        page.value.total = total;
        doorHistoryData.value = list;
      }
    }catch (e) {
      page.value.pageCurr = 0;
      page.value.total = 0;
    }
  }
 
  const exportFile = (isAll)=>{
    isAll = isAll === true;
    if(page.value.total === 0) {
      ElMessage({
        message: '暂无数据,无法导出',
        type: 'warning',
      })
      return;
    }
    searchDoorHistory(true, isAll);
  }
 
  return {
    doorId,
    page,
    doorHistoryData,
    searchDoorHistory,
    exportFile
  }
}
 
export default doorInfoHistoryModule;