wangfei
2025-03-13 5725c89e4bfe7f91e9cf2cce9c2cd1734b02ec57
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>  
    <div>  
  <div style="display: flex;width: 1770px;">
    <el-input v-model="glassId" clearable style="margin-left: 10px;margin-bottom: 10px;width: 200px;" :placeholder="$t('searchOrder.inglassID')" />
    <el-select 
            :placeholder="$t('searchOrder.taskstatus')"
             clearable
             style="width: 270px;margin-left: 10px;"  
             v-model="taskState">
               <el-option
                v-for="item in optionsa"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
          </el-select>
          <el-select 
            :placeholder="$t('film.enabletype')"
             clearable
             style="width: 270px;margin-left: 10px;"  
             v-model="taskType">
               <el-option
                v-for="item in optionsb"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
          </el-select>
            <el-date-picker v-model="timeRange" type="datetimerange" range-separator="至" :start-placeholder="$t('reportmanage.starttime')" 
             style="margin-left: 15px;" value-format = "YYYY-MM-DD hh:mm:ss"
              :end-placeholder="$t('reportmanage.endtime')">
            </el-date-picker>
          <el-button type="primary" style="margin-left: 10px;margin-bottom: 10px;" @click="sethistorical()">{{$t('reportmanage.inquire')}}</el-button>
     </div>
        <el-table ref="table" style="margin-top: 20px;height: 580px;width: 1770px;" :data="tableDatax" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
      <el-table-column prop="glassIdIn" align="center" :label="$t('searchOrder.glassID')" min-width="80" />
          <el-table-column
            align="center"
            :label="$t('film.taskstatus')"
            min-width="80"
            prop="taskState"
          >
          <template #default="scope">  
        <el-tag :type="getStatusTypeb(scope.row.taskState)">  
          {{ getStatusTextb(scope.row.taskState) }}  
        </el-tag>  
      </template> 
          </el-table-column>
          <el-table-column
            align="center"
            :label="$t('film.enabletype')"
            min-width="80"
            prop="taskType"
          >
          <template #default="scope">  
        <el-tag :type="getStatusTypea(scope.row.taskType)">  
          {{ getStatusTexta(scope.row.taskType) }}  
        </el-tag>  
      </template> 
          </el-table-column>
          <el-table-column prop="createTime" align="center" :label="$t('reportmanage.starttime')" min-width="100" />
          <el-table-column prop="updateTime" align="center" :label="$t('reportmanage.endtime')" min-width="100" />
        </el-table>
  <div style="margin-top: 20px;margin-left: 40%;">
        <el-pagination
          v-model:current-page="currentPage2"
          :page-size="pageSize"
          :size="large"
          :disabled="disabled"
          layout="prev, pager, next, jumper"
          :total="totalRecords"
          @current-change="handlePageChange2"
          style="margin-top: 10px;"
      />
    </div>
  </div>
  </template>  
<script lang="ts" setup>
import {useI18n} from 'vue-i18n'
import {useRouter} from "vue-router"
import request from "@/utils/request"
import {host, WebSocketHost} from '@/utils/constants'
import {onBeforeUnmount, onMounted, onUnmounted, reactive, ref} from "vue";
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {ElMessage, ElMessageBox} from 'element-plus'
const {t} = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
import { inject } from 'vue';
const globalDate = inject('globalDate');
const router = useRouter()
const timeRange = ref([])
const selectValuesa = reactive([]);
const tableDatax = ref([])
const currentPage2 = ref(1)
const totalRecords = ref(0)
const glassId = ref('');
const startSlot = ref('');
const targetSlot = ref('');
const taskState = ref('');
const taskType = ref('');
let getglobalDate = window.localStorage.getItem('getglobalDate')
const historical = async () => {
  try {
  let startTime = window.localStorage.getItem('startTime')
      const response = await request.post("/cacheGlass/edgStorageDeviceTaskHistory", {
        deviceId: 2,
        pageNo: 1,
        pageSize: 20,
        glassId: glassId.value,
        taskState: '',
        taskType: '',
        startTime: startTime,
        endTime: getglobalDate
    })
      if (response.code == 200) {
        ElMessage.success(response.message);
        tableDatax.value = response.data.records;
        console.log(response.data.pages);
        totalRecords.value = response.data.total/2 || 0
      } else {
        ElMessage.error(response.message);
    }
}
catch (error) {
    console.error(error);
  }
}
const handlePageChange2 = (newPage) => {
  currentPage2.value = newPage;
  console.log(currentPage2.value);
  window.localStorage.setItem('pagenumber', currentPage2.value)
  historicala(currentPage2.value);
};
const historicala = async (page) => {
  try { 
  let page = window.localStorage.getItem('pagenumber')
  let startTime = window.localStorage.getItem('startTime')
      const response = await request.post("/cacheGlass/edgStorageDeviceTaskHistory", {
        deviceId: 2,
        pageNo: page,
        pageSize: 20,
        glassId: glassId.value,
        taskState: taskState.value,
        taskType: taskType.value,
        startTime: (timeRange.value && timeRange.value[0]) || '',
        endTime: (timeRange.value && timeRange.value[1]) || '',
    })
      if (response.code == 200) {
        ElMessage.success(response.message);
        tableDatax.value = response.data.records;
        totalRecords.value = response.data.total/2 || 0
      } else {
        ElMessage.error(response.message);
    }
}
catch (error) {
    console.error(error);
  }
}
// 历史查询点击
const sethistorical = async () => {
  try { 
  let startTime = window.localStorage.getItem('startTime')
  let page = window.localStorage.getItem('pagenumber')
  console.log(page);
  const response = await request.post("/cacheGlass/edgStorageDeviceTaskHistory", {
        deviceId: 2,
        pageNo: 1,
        pageSize: 20,
        glassId: glassId.value,
        taskState: taskState.value,
        taskType: taskType.value,
        startTime: (timeRange.value && timeRange.value[0]) || '',
        endTime: (timeRange.value && timeRange.value[1]) || '',
    })
      if (response.code == 200) {
        currentPage2.value = 1;
        ElMessage.success(response.message);
        tableDatax.value = response.data.records;
        totalRecords.value = response.data.total/2 || 0
      } else {
        ElMessage.error(response.message);
    }
}
catch (error) {
    console.error(error);
  }
}
// 格式化时间戳为年月日时间字符串的函数
function formatTimestamp(timestamp) {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并补零
  const day = String(date.getDate()).padStart(2, '0'); // 补零
  const hours = String(date.getHours()).padStart(2, '0'); // 补零(如果需要显示时间)
  const minutes = String(date.getMinutes()).padStart(2, '0'); // 补零(如果需要显示时间)
  const seconds = String(date.getSeconds()).padStart(2, '0'); // 补零(如果需要显示时间)
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
// 格式化后端时间并计算一周前的时间
const defaultTime = ref<[Date, Date]>([new Date(), new Date()]);
function parseAndSetTime() {
  const backendTime = new Date(getglobalDate);
  const oneWeekAgo = new Date(backendTime.getTime() - 7 * 24 * 60 * 60 * 1000); // 减去7天
  console.log(formatTimestamp(oneWeekAgo));
  console.log(oneWeekAgo);
  timeRange.value = [formatTimestamp(oneWeekAgo), formatTimestamp(backendTime)];
  window.localStorage.setItem('startTime', formatTimestamp(oneWeekAgo))
}
function getStatusTypeb(taskState: number) {  
  switch (taskState) {  
    case 0:
      return 'primary';  
    case 1: 
      return 'success';  
  }  
}
function getStatusTextb(taskState: number) {
  switch (taskState) {
    case 0:  
      return t('searchOrder.empty');
    case 1:  
      return t('searchOrder.endtask');
  }  
}
function getStatusTypea(taskType: number) {  
  switch (taskType) {  
    case 1: 
      return 'primary';  
    case 2: 
      return 'success';  
    case 3:
      return 'warning';  
  }  
}  
function getStatusTexta(taskType: number) {
  switch (taskType) {
    case 1:  
      return t('sorter.advancetask');
    case 2:  
    return t('sorter.outputtasks');
    case 3:  
    return t('sorter.straighttasks');
  }  
}
const optionsa = [
  {
    value: 0,
    label: t('searchOrder.empty'),
  },
  {
    value: 1,
    label: t('searchOrder.endtask'),
  }
]
const optionsb = [
  {
    value: 1,
    label: t('sorter.advancetask'),
  },
  {
    value: 2,
    label: t('sorter.outputtasks'),
  },
  {
    value: 3,
    label: t('sorter.straighttasks'),
  }
]
onMounted(() => {
  parseAndSetTime();
  historical();
});
  </script>
  <style scoped>  
  </style>