zhangwencui
2 天以前 cef1acd01505b160f8cf9d5d01fb03f4feb47438
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
<template>
  <view class="notice-page">
    <PageHeader title="运行管理"
                @back="goBack" />
    <!-- 通知公告板 -->
    <view class="notice-board">
      <!-- 统一通知区域 -->
      <view class="notice-section">
        <view class="section-header">
          <h3>设备运行记录</h3>
        </view>
        <view class="notice-cards">
          <!-- 放假通知 -->
          <view v-for="notice in holidayNotices"
                :key="'holiday-' + notice.id"
                class="notice-card holiday-card"
                :class="{ 'urgent': isOverdue(notice) }">
            <view class="card-header">
              <view class="card-title">
                <view class="holiday-icon">
                  <up-icon name="calendar"
                           size="18"
                           color="#67c23a" />
                </view>
                <text>设备名称:{{ notice.deviceName }}</text>
              </view>
              <view class="card-actions warning"
                    v-if="isOverdue(notice)">
                <up-icon name="info-circle"
                         size="16"
                         color="#fff" />
                <text>{{ '超时未启动' }}</text>
              </view>
              <view v-else
                    class="card-actions"
                    :class="getTagType(notice.status)">
                <up-icon :name="getIconName(notice.status)"
                         size="16"
                         color="#fff" />
                <text>{{ notice.status || '未知' }}</text>
              </view>
            </view>
            <view class="card-content">
              <text>规格型号:{{ notice.deviceModel || "-" }}</text>
            </view>
            <view class="card-content">
              <text>计划运行时间:{{ notice.planRuntimeTime || "-" }}</text>
            </view>
            <view class="card-content">
              <text>开始运行时间:{{ notice.startRuntimeTime || "-" }}</text>
            </view>
            <view class="card-content">
              <text>结束运行时间:{{ notice.endRuntimeTime || "-" }}</text>
            </view>
            <view class="card-content">
              <text>运行时长:{{ notice.runtimeDuration || "-" }}</text>
            </view>
            <up-button text
                       v-if="isOverdue(notice)"
                       type="warning"
                       size="small"
                       @click="handleEdit(notice, '启动运行')"
                       :disabled="isNoticeExpired(notice)">
              <up-icon name="play-circle"
                       size="16"
                       style="margin-right: 10rpx;"
                       color="#fff" />
              立即启动
            </up-button>
            <up-button text
                       v-else-if="notice.status"
                       :type="getTagType2(notice.status)"
                       size="small"
                       @click="handleEdit(notice, notice.status === '运行中' ? '停止运行' : '启动运行')"
                       :disabled="isNoticeExpired(notice)">
              <up-icon :name="getIconName2(notice.status)"
                       size="16"
                       color="#fff" />
              {{ notice.status === '运行中' ? '停止运行' : '立即启动' }}
            </up-button>
          </view>
        </view>
      </view>
      <!-- 空状态 -->
      <view class="empty-state"
            v-if="holidayNotices.length === 0 && maintenanceNotices.length === 0">
        <text>暂无通知公告</text>
      </view>
    </view>
  </view>
</template>
 
<script setup>
  import { onMounted, ref } from "vue";
  import PageHeader from "@/components/PageHeader.vue";
  import {
    getLedgerPage,
    editLedger,
  } from "@/api/equipmentManagement/runManagement.js";
 
  // 获取标签类型
  const getTagType = status => {
    switch (status) {
      case "运行中":
        return "success";
      case "停止运行":
        return "error";
      default:
        return "info";
    }
  };
  const getTagType2 = status => {
    switch (status) {
      case "停止运行":
        return "success";
      case "运行中":
        return "error";
      default:
        return "info";
    }
  };
  // 获取图标名称
  const getIconName = status => {
    switch (status) {
      case "运行中":
        return "play-circle";
      case "停止运行":
        return "pause-circle";
      default:
        return "question-circle";
    }
  };
  // 获取图标名称2
  const getIconName2 = status => {
    switch (status) {
      case "停止运行":
        return "play-circle";
      case "运行中":
        return "pause-circle";
      default:
        return "question-circle";
    }
  };
  const goBack = () => {
    uni.navigateBack();
  };
  const isOverdue = notice => {
    if (
      notice.status == "运行中" ||
      !notice.planRuntimeTime ||
      notice.startRuntimeTime
    ) {
      return false;
    }
    const planTime = new Date(notice.planRuntimeTime).getTime();
    const currentTime = new Date().getTime();
    return currentTime > planTime;
  };
 
  const isNoticeExpired = notice => {
    if (!notice || !notice.expirationDate) {
      return false;
    }
 
    const expiration = new Date(notice.expirationDate);
 
    if (Number.isNaN(expiration.getTime())) {
      return false;
    }
 
    expiration.setHours(23, 59, 59, 999);
 
    return new Date() > expiration;
  };
 
  const handleEdit = async (device, status) => {
    try {
      const currentTime = new Date()
        .toLocaleString("zh-CN", {
          year: "numeric",
          month: "2-digit",
          day: "2-digit",
          hour: "2-digit",
          minute: "2-digit",
          second: "2-digit",
          hour12: false,
        })
        .replace(/\//g, "-");
 
      // 更新设备状态和相关时间字段
      if (status === "启动运行") {
        device.status = "运行中";
        device.startRuntimeTime = currentTime;
        device.endRuntimeTime = null; // 清空结束时间
        device.runtimeDuration = null; // 清空运行时长
      } else {
        device.status = "停止运行";
        device.endRuntimeTime = currentTime;
        // 计算运行时长
        if (device.startRuntimeTime) {
          const startTime = new Date(device.startRuntimeTime);
          const endTime = new Date(currentTime);
          const duration = endTime - startTime;
          const hours = Math.floor(duration / (1000 * 60 * 60));
          const minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60));
          device.runtimeDuration = `${hours}小时${minutes}分钟`;
        }
      }
      const params = {
        id: device.id,
        status: device.status,
        planRuntimeTime: device.planRuntimeTime,
        startRuntimeTime: device.startRuntimeTime,
        endRuntimeTime: device.endRuntimeTime,
        runtimeDuration: device.runtimeDuration,
      };
      // 调用API更新设备状态
      const response = await editLedger(params);
      if (response.code === 200) {
        showToast(`${device.deviceName} ${status}成功`);
        // 刷新列表
        await fetchHolidayNotices();
      } else {
        showToast(response.msg || "操作失败");
      }
    } catch (error) {
      console.error("更新设备状态失败:", error);
      showToast("操作失败");
    }
  };
 
  const holidayNotices = ref([]);
  const maintenanceNotices = ref([]);
 
  const fetchHolidayNotices = (append = false) => {
    getLedgerPage({}).then(res => {
      holidayNotices.value = res?.data?.records || [];
    });
  };
 
  // 生命周期
  onMounted(() => {
    fetchHolidayNotices();
  });
</script>
 
<style scoped>
  .notice-page {
    min-height: 100vh;
    background: #f5f7fa;
    padding-bottom: 16px;
    display: flex;
    flex-direction: column;
  }
 
  .search_form {
    background: #ffffff;
    padding: 12px 16px;
    margin: 8px 12px 12px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
 
  .search_title {
    font-weight: 500;
    color: #333;
    margin-right: 8px;
  }
 
  .ml10 {
    margin-left: 10px;
  }
 
  .notice-board {
    padding: 0 12px 16px;
  }
 
  .notice-section {
    margin-bottom: 16px;
  }
 
  .section-header {
    display: flex;
    align-items: center;
    margin: 4px 4px 12px;
  }
 
  .section-header h3 {
    margin: 0;
    color: #303133;
    font-size: 16px;
    font-weight: 600;
  }
 
  .section-count {
    margin-left: 10px;
    background: #409eff;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
  }
 
  .notice-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
 
  .notice-card {
    background: white;
    border-radius: 12px;
    padding: 14px 14px 10px;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.06);
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
  }
 
  .notice-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  }
 
  .holiday-card {
    border-left-color: #bec4c3;
  }
 
  .maintenance-card {
    border-left-color: #e6a23c;
  }
 
  .urgent {
    border-left-color: #f56c6c;
    background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
  }
 
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
  }
 
  .card-title {
    display: flex;
    align-items: center;
    font-size: 15px;
    font-weight: 600;
    color: #303133;
    flex: 1;
  }
 
  .holiday-icon {
    color: #67c23a;
    margin-right: 8px;
    font-size: 18px;
  }
 
  .maintenance-icon {
    color: #e6a23c;
    margin-right: 8px;
    font-size: 18px;
  }
 
  .card-actions {
    display: flex;
    gap: 8px;
    padding: 4rpx 8rpx;
    border-radius: 10rpx;
  }
 
  .card-content {
    margin-bottom: 10px;
  }
 
  .card-content text {
    color: #606266;
    line-height: 1.6;
    font-size: 13px;
  }
 
  .card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
  }
 
  .card-meta {
    display: flex;
    gap: 8px;
  }
 
  .type,
  .priority,
  .status {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
  }
 
  .type-1 {
    background: #f0f9ff;
    color: #0369a1;
  }
 
  .type-2 {
    background: #fef3c7;
    color: #d97706;
  }
 
  .priority-1 {
    background: #f0f9ff;
    color: #0369a1;
  }
 
  .priority-2 {
    background: #fef3c7;
    color: #d97706;
  }
  .success {
    background: #67c23a;
    color: #fff;
  }
  .error {
    background: #f56c6c;
    color: #fff;
  }
  .info {
    background: #a8a9aa;
    color: #fff;
  }
  .warning {
    background: #e6a23c;
    color: #fff;
  }
 
  .priority-3 {
    background: #fef2f2;
    color: #dc2626;
  }
 
  .status-0 {
    background: #f3f4f6;
    color: #6b7280;
  }
 
  .status-1 {
    background: #d1fae5;
    color: #059669;
  }
 
  .status-2 {
    background: #fef3c7;
    color: #d97706;
  }
 
  .card-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 12px;
    color: #909399;
  }
 
  .creator {
    font-weight: 500;
    margin-bottom: 2px;
  }
 
  .expiration {
    margin-top: 2px;
  }
 
  .card-remark {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 12px;
    color: #606266;
    border-left: 3px solid #409eff;
  }
 
  .empty-state {
    text-align: center;
    padding: 48px 16px;
    color: #999;
    font-size: 13px;
  }
 
  .dialog-footer {
    text-align: right;
  }
 
  /* 移动端弹窗样式 */
  .dialog-container {
    background: #ffffff;
    border-radius: 18px 18px 0 0;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
  }
 
  .dialog-header {
    padding: 16px 20px 8px 20px;
  }
 
  .dialog-title {
    font-size: 16px;
    font-weight: 600;
    color: #303133;
  }
 
  .dialog-body {
    flex: 1;
    padding: 0 16px 12px 16px;
    overflow-y: auto;
  }
 
  .dialog-footer {
    display: flex;
    padding: 12px 16px 16px 16px;
    border-top: 1px solid #f0f0f0;
  }
 
  /* 响应式设计 */
  @media (max-width: 768px) {
    .search_form {
      flex-direction: column;
      gap: 15px;
      align-items: flex-start;
    }
 
    .search_form > div {
      width: 100%;
      display: flex;
      gap: 10px;
    }
  }
</style>