Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
1053 lines (924 loc) · 39.3 KB
/
Copy pathscript.js
File metadata and controls
1053 lines (924 loc) · 39.3 KB
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
let tabs = [];
let activeTabId = null;
function normalizeUrl(url) {
if (url.startsWith('../')) {
return url.substring(3);
}
if (url.startsWith('./')) {
return url.substring(2);
}
return url;
}
function getTabId(url) {
const normalizedUrl = normalizeUrl(url);
return normalizedUrl.replace(/\//g, '-').replace(/\./g, '-');
}
function getTabTitle(url) {
const normalizedUrl = normalizeUrl(url);
const menuTitles = {
'index.html': '首页',
'dashboard.html': '首页',
'pre-process/work-order.html': '前工序生产工单',
'pre-process/plan.html': '前工序计划',
'pre-process/workshop.html': '车间维护',
'pre-process/section.html': '工段维护',
'pre-process/team.html': '班组维护',
'assembly/work-order.html': '总装生产工单',
'assembly/plan.html': '总装计划',
'assembly/barcode.html': '总装条码管理',
'assembly/scan-station.html': '扫码过站',
'assembly/record.html': '总装条码过站记录',
'assembly/workshop.html': '车间维护',
'assembly/production-line.html': '产线维护',
'assembly/workstation.html': '工站维护',
'quality/process-inspection.html': '过程检验',
'quality/oqc-inspection.html': '成品OQC检验',
'quality/defect-management.html': '不合格审批',
'quality/alarm-call.html': '安灯呼叫',
'quality/defect-record.html': '批次不良',
'equipment/equipment-check.html': '设备点检',
'equipment/equipment-patrol.html': '设备巡检',
'equipment/equipment-maintenance.html': '设备保养',
'basic-data/factory.html': '工厂管理',
'basic-data/material.html': '物料管理',
'basic-data/bom-management.html': '产品BOM',
'basic-data/equipment.html': '设备管理',
'basic-data/first-inspection.html': '首检配置',
'basic-data/patrol-inspection.html': '巡检配置',
'basic-data/sampling-inspection.html': '抽检配置',
'basic-data/equipment-check.html': '设备点检配置',
'basic-data/equipment-patrol.html': '设备巡检配置',
'basic-data/equipment-maintenance.html': '设备维保定义',
'basic-data/transport-box.html': '周转箱定义',
'system/menu-management.html': '菜单管理',
'system/role-management.html': '角色管理',
'system/dept-management.html': '部门管理',
'system/user-management.html': '用户管理',
'system/dict-management.html': '字典管理',
'system/system-config.html': '系统参数'
};
return menuTitles[normalizedUrl] || normalizedUrl.split('/').pop().replace('.html', '');
}
function getTabIcon(url) {
const normalizedUrl = normalizeUrl(url);
const icons = {
'index.html': '🏠',
'dashboard.html': '🏠',
'pre-process/work-order.html': '📋',
'pre-process/plan.html': '📅',
'pre-process/workshop.html': '🏭',
'pre-process/section.html': '📐',
'pre-process/team.html': '👥',
'assembly/work-order.html': '📋',
'assembly/plan.html': '📅',
'assembly/barcode.html': '🏷️',
'assembly/scan-station.html': '🔍',
'assembly/record.html': '📝',
'assembly/workshop.html': '🏭',
'assembly/production-line.html': '⚡',
'assembly/workstation.html': '🔧',
'quality/process-inspection.html': '🔍',
'quality/oqc-inspection.html': '✅',
'quality/defect-management.html': '❌',
'quality/alarm-call.html': '🚨',
'quality/defect-record.html': '⚠️',
'equipment/equipment-check.html': '🔧',
'equipment/equipment-patrol.html': '👀',
'equipment/equipment-maintenance.html': '🛠️',
'basic-data/factory.html': '🏭',
'basic-data/material.html': '📦',
'basic-data/bom-management.html': '📋',
'basic-data/equipment.html': '🖥️',
'basic-data/first-inspection.html': '🔍',
'basic-data/patrol-inspection.html': '👀',
'basic-data/sampling-inspection.html': '📊',
'basic-data/equipment-check.html': '⚙️',
'basic-data/equipment-patrol.html': '🚶',
'basic-data/equipment-maintenance.html': '🔧',
'basic-data/transport-box.html': '📦',
'system/menu-management.html': '📑',
'system/role-management.html': '🎭',
'system/dept-management.html': '🏢',
'system/user-management.html': '👥',
'system/dict-management.html': '📖',
'system/system-config.html': '⚙️'
};
return icons[normalizedUrl] || '📄';
}
function createTab(url) {
const normalizedUrl = normalizeUrl(url);
const tabId = getTabId(url);
const existingTab = tabs.find(t => t.id === tabId);
if (existingTab) {
switchTab(tabId);
return;
}
const title = getTabTitle(url);
const icon = getTabIcon(url);
const newTab = {
id: tabId,
url: normalizedUrl,
title: title,
icon: icon
};
tabs.push(newTab);
renderTabs();
switchTab(tabId);
}
function renderTabs() {
const tabsContainer = document.getElementById('tabs-container');
if (!tabsContainer) return;
tabsContainer.innerHTML = tabs.map(tab => `
<button class="tab-item ${tab.id === activeTabId ? 'active' : ''}" onclick="switchTab('${tab.id}')">
<span class="tab-title">
<span class="tab-icon">${tab.icon}</span>
${tab.title}
</span>
<span class="tab-close" onclick="event.stopPropagation(); closeTab('${tab.id}')">×</span>
</button>
`).join('');
}
function switchTab(tabId) {
const tab = tabs.find(t => t.id === tabId);
if (!tab) return;
activeTabId = tabId;
renderTabs();
const contentFrame = document.getElementById('content-frame');
if (contentFrame) {
contentFrame.src = tab.url;
}
const submenuLinks = document.querySelectorAll('.submenu-link');
submenuLinks.forEach(link => {
link.classList.remove('active');
const href = link.getAttribute('href');
if (href && getTabId(href) === tabId) {
link.classList.add('active');
}
});
}
function closeTab(tabId) {
if (tabs.length <= 1) {
alert('至少保留一个标签页');
return;
}
const tabIndex = tabs.findIndex(t => t.id === tabId);
if (tabIndex === -1) return;
tabs.splice(tabIndex, 1);
if (activeTabId === tabId) {
const newActiveIndex = tabIndex < tabs.length ? tabIndex : tabs.length - 1;
activeTabId = tabs[newActiveIndex].id;
}
renderTabs();
const contentFrame = document.getElementById('content-frame');
if (contentFrame && tabs.length > 0) {
const activeTab = tabs.find(t => t.id === activeTabId);
if (activeTab) {
contentFrame.src = activeTab.url;
}
}
}
function initTabs() {
tabs = [{
id: 'dashboard-html',
url: 'dashboard.html',
title: '首页',
icon: '🏠'
}];
activeTabId = tabs[0].id;
renderTabs();
}
async function loadMenu() {
const menuContainer = document.getElementById('menu-container');
if (!menuContainer) return;
try {
const response = await fetch('../components/menu.html');
const html = await response.text();
menuContainer.innerHTML = html;
initMenu();
} catch (error) {
console.error('Failed to load menu component:', error);
}
}
function initMenu() {
const menuLinks = document.querySelectorAll('.menu-link');
const submenuLinks = document.querySelectorAll('.submenu-link');
menuLinks.forEach(link => {
link.addEventListener('click', function(e) {
const parent = this.parentElement;
const hasSubmenu = parent.classList.contains('has-submenu');
const href = this.getAttribute('href');
if (hasSubmenu) {
e.preventDefault();
const submenu = parent.querySelector('.submenu');
menuLinks.forEach(l => {
const lp = l.parentElement;
if (l !== this && lp.classList.contains('has-submenu')) {
l.classList.remove('expanded');
lp.querySelector('.submenu')?.classList.remove('active');
}
});
this.classList.toggle('expanded');
submenu?.classList.toggle('active');
} else if (href && href !== '#') {
e.preventDefault();
createTab(href);
}
});
});
submenuLinks.forEach(link => {
link.addEventListener('click', function(e) {
const href = this.getAttribute('href');
if (href && href !== '#' && !href.startsWith('#')) {
e.preventDefault();
createTab(href);
}
});
});
initOrderLinks();
}
function updateCurrentTime() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
const weekDay = weekDays[now.getDay()];
const timeStr = `${year}年${month}月${day}日 ${weekDay} ${hours}:${minutes}:${seconds}`;
const timeElement = document.getElementById('current-time');
if (timeElement) {
timeElement.textContent = timeStr;
}
}
function drawProductionTrend() {
const canvas = document.getElementById('trend-canvas');
if (!canvas) return;
const container = canvas.parentElement;
const width = container.clientWidth;
const height = 250;
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, width, height);
const padding = { top: 20, right: 20, bottom: 40, left: 50 };
const chartWidth = width - padding.left - padding.right;
const chartHeight = height - padding.top - padding.bottom;
const data = [
{ label: '周一', value: 8500 },
{ label: '周二', value: 9200 },
{ label: '周三', value: 7800 },
{ label: '周四', value: 10500 },
{ label: '周五', value: 11200 },
{ label: '周六', value: 6500 },
{ label: '周日', value: 5800 }
];
const maxValue = Math.max(...data.map(d => d.value));
const minValue = Math.min(...data.map(d => d.value));
const range = maxValue - minValue || 1;
ctx.strokeStyle = '#e5e7eb';
ctx.lineWidth = 1;
for (let i = 0; i <= 4; i++) {
const y = padding.top + (chartHeight / 4) * i;
ctx.beginPath();
ctx.moveTo(padding.left, y);
ctx.lineTo(width - padding.right, y);
ctx.stroke();
const value = Math.round(maxValue - (range / 4) * i);
ctx.fillStyle = '#6b7280';
ctx.font = '12px Arial';
ctx.textAlign = 'right';
ctx.fillText(value.toString(), padding.left - 10, y + 4);
}
ctx.strokeStyle = '#10b981';
ctx.lineWidth = 3;
ctx.beginPath();
const stepX = chartWidth / (data.length - 1);
data.forEach((point, index) => {
const x = padding.left + stepX * index;
const y = padding.top + chartHeight - ((point.value - minValue) / range) * chartHeight;
if (index === 0) {
ctx.moveTo(x, y);
} else {
ctx.lineTo(x, y);
}
});
ctx.stroke();
data.forEach((point, index) => {
const x = padding.left + stepX * index;
const y = padding.top + chartHeight - ((point.value - minValue) / range) * chartHeight;
ctx.beginPath();
ctx.arc(x, y, 5, 0, Math.PI * 2);
ctx.fillStyle = '#10b981';
ctx.fill();
ctx.strokeStyle = '#fff';
ctx.lineWidth = 2;
ctx.stroke();
ctx.fillStyle = '#374151';
ctx.font = '12px Arial';
ctx.textAlign = 'center';
ctx.fillText(point.label, x, height - 15);
});
ctx.fillStyle = '#374151';
ctx.font = 'bold 14px Arial';
ctx.textAlign = 'center';
ctx.fillText('单位: 件', width / 2, height - 5);
}
document.addEventListener('DOMContentLoaded', function() {
const tabsContainer = document.getElementById('tabs-container');
if (tabsContainer) {
loadMenu();
initTabs();
}
updateCurrentTime();
setInterval(updateCurrentTime, 1000);
drawProductionTrend();
initOrderLinks();
window.addEventListener('resize', function() {
drawProductionTrend();
});
const menuLinks = document.querySelectorAll('.menu-link');
const submenuLinks = document.querySelectorAll('.submenu-link');
const pageTitle = document.getElementById('page-title');
const content = document.getElementById('content');
const addWorkOrderBtn = document.getElementById('add-work-order');
const addModal = document.getElementById('add-modal');
const closeModalBtn = document.getElementById('close-modal');
const cancelBtn = document.getElementById('cancel-btn');
const confirmBtn = document.getElementById('confirm-btn');
const planSearch = document.getElementById('plan-search');
const checkAllModal = document.querySelector('.check-all-modal');
if (addWorkOrderBtn) {
addWorkOrderBtn.addEventListener('click', function() {
addModal.classList.add('show');
});
}
if (closeModalBtn) {
closeModalBtn.addEventListener('click', function() {
addModal.classList.remove('show');
});
}
if (cancelBtn) {
cancelBtn.addEventListener('click', function() {
addModal.classList.remove('show');
});
}
if (addModal) {
addModal.addEventListener('click', function(e) {
if (e.target === addModal) {
addModal.classList.remove('show');
}
});
}
if (checkAllModal) {
checkAllModal.addEventListener('change', function() {
const checkboxes = document.querySelectorAll('#plan-list input[type="checkbox"]');
checkboxes.forEach(cb => cb.checked = checkAllModal.checked);
});
}
if (planSearch) {
planSearch.addEventListener('input', function() {
const searchText = planSearch.value.toLowerCase();
const rows = document.querySelectorAll('#plan-list tr');
rows.forEach(row => {
const text = row.textContent.toLowerCase();
row.style.display = text.includes(searchText) ? '' : 'none';
});
});
}
if (confirmBtn) {
confirmBtn.addEventListener('click', function() {
const checkedBoxes = document.querySelectorAll('#plan-list input[type="checkbox"]:checked');
if (checkedBoxes.length === 0) {
alert('请至少选择一个计划');
return;
}
const selectedPlans = [];
checkedBoxes.forEach(cb => {
const row = cb.closest('tr');
const planId = cb.dataset.planId;
const planNo = row.querySelector('td:nth-child(2)').textContent;
const qtyInput = row.querySelector('.work-order-qty');
const qty = parseInt(qtyInput.value);
const maxQty = parseInt(qtyInput.max);
if (qty > maxQty) {
alert(`计划 ${planNo} 的工单数量不能超过未排产数量 ${maxQty}`);
return;
}
selectedPlans.push({ planId, planNo, qty });
});
if (selectedPlans.length > 0) {
alert(`已选择 ${selectedPlans.length} 个计划创建工单`);
addModal.classList.remove('show');
}
});
}
const pageContents = {
'pre-process-plan': {
title: '前工序计划',
html: `
<div class="content-section active">
<h3>前工序计划管理</h3>
<div class="info-card">
<h4>功能概述</h4>
<p>前工序计划模块用于管理和跟踪前工序的生产计划安排,包括计划创建、修改、查询和执行状态监控。</p>
</div>
<div class="info-card">
<h4>主要功能</h4>
<p>• 计划编制与发布</p>
<p>• 计划调整与变更</p>
<p>• 计划执行进度跟踪</p>
<p>• 产能负荷分析</p>
</div>
</div>
`
},
'pre-process-work-order': {
title: '前工序生产工单',
html: `
<div class="content-section active">
<h3>前工序生产工单管理</h3>
<div class="info-card">
<h4>功能概述</h4>
<p>前工序生产工单模块用于管理前工序的生产任务,包括工单创建、派工、执行和完工确认。</p>
</div>
<div class="info-card">
<h4>主要功能</h4>
<p>• 工单创建与审核</p>
<p>• 工单派工与分配</p>
<p>• 工单执行跟踪</p>
<p>• 工单完工与报工</p>
</div>
</div>
`
},
'assembly-plan': {
title: '总装计划',
html: `
<div class="content-section active">
<h3>总装计划管理</h3>
<div class="info-card">
<h4>功能概述</h4>
<p>总装计划模块用于管理总装生产线的生产计划,协调各工位的生产节拍和物料供应。</p>
</div>
<div class="info-card">
<h4>主要功能</h4>
<p>• 总装计划编制</p>
<p>• 生产线平衡优化</p>
<p>• 物料齐套检查</p>
<p>• 计划执行监控</p>
</div>
</div>
`
},
'assembly-work-order': {
title: '总装生产工单',
html: `
<div class="content-section active">
<h3>总装生产工单管理</h3>
<div class="info-card">
<h4>功能概述</h4>
<p>总装生产工单模块用于管理总装车间的生产任务,支持多工位协同生产和进度追踪。</p>
</div>
<div class="info-card">
<h4>主要功能</h4>
<p>• 工单创建与下达</p>
<p>• 工位任务分配</p>
<p>• 生产进度实时监控</p>
<p>• 工单完工验收</p>
</div>
</div>
`
},
'assembly-barcode': {
title: '总装条码管理',
html: `
<div class="content-section active">
<h3>总装条码管理</h3>
<div class="info-card">
<h4>功能概述</h4>
<p>总装条码管理模块用于管理产品条码的生成、打印和绑定,实现产品全生命周期追溯。</p>
</div>
<div class="info-card">
<h4>主要功能</h4>
<p>• 条码生成与打印</p>
<p>• 条码与工单绑定</p>
<p>• 条码追溯查询</p>
<p>• 条码报废管理</p>
</div>
</div>
`
},
'assembly-record': {
title: '总装条码过站记录',
html: `
<div class="content-section active">
<h3>总装条码过站记录</h3>
<div class="info-card">
<h4>功能概述</h4>
<p>总装条码过站记录模块用于记录产品在各工位的过站信息,实现生产过程的全程追溯。</p>
</div>
<div class="info-card">
<h4>主要功能</h4>
<p>• 过站记录采集</p>
<p>• 过站时间统计</p>
<p>• 异常过站告警</p>
<p>• 过站历史查询</p>
</div>
</div>
`
}
};
});
document.addEventListener('DOMContentLoaded', function() {
const publishBtn = document.getElementById('publish-btn');
const publishModal = document.getElementById('publish-modal');
const closePublishModal = document.getElementById('close-publish-modal');
const cancelPublishBtn = document.getElementById('cancel-publish-btn');
const confirmPublishBtn = document.getElementById('confirm-publish-btn');
const startBtn = document.getElementById('start-btn');
function openModal(modal) {
if (modal) {
modal.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
}
function closeModal(modal) {
if (modal) {
modal.style.display = 'none';
document.body.style.overflow = '';
}
}
if (publishBtn) {
publishBtn.addEventListener('click', function() {
const checkedBoxes = document.querySelectorAll('table.data-table.wide-table tbody input[type="checkbox"]:checked');
if (checkedBoxes.length === 0) {
alert('请至少选择一个工单');
return;
}
openModal(publishModal);
});
}
if (closePublishModal) {
closePublishModal.addEventListener('click', function() {
closeModal(publishModal);
});
}
if (cancelPublishBtn) {
cancelPublishBtn.addEventListener('click', function() {
closeModal(publishModal);
});
}
if (confirmPublishBtn) {
confirmPublishBtn.addEventListener('click', function() {
const line = document.getElementById('publish-line').value;
const startTime = document.getElementById('publish-start-time').value;
const endTime = document.getElementById('publish-end-time').value;
if (!line || line === '') {
alert('请选择产线');
return;
}
if (!startTime || startTime === '') {
alert('请选择计划开始时间');
return;
}
if (!endTime || endTime === '') {
alert('请选择计划结束时间');
return;
}
if (new Date(startTime) >= new Date(endTime)) {
alert('计划开始时间不能大于或等于计划结束时间');
return;
}
closeModal(publishModal);
alert('工单发布成功!');
const checkedBoxes = document.querySelectorAll('table.data-table.wide-table tbody input[type="checkbox"]:checked');
checkedBoxes.forEach(cb => {
const row = cb.closest('tr');
const statusSpan = row.querySelector('.status');
if (statusSpan) {
statusSpan.textContent = '已发布';
statusSpan.className = 'status status-released';
}
});
});
}
if (publishModal) {
publishModal.addEventListener('click', function(e) {
if (e.target === publishModal) {
closeModal(publishModal);
}
});
}
if (startBtn) {
startBtn.addEventListener('click', function() {
const checkedBoxes = document.querySelectorAll('table.data-table.wide-table tbody input[type="checkbox"]:checked');
if (checkedBoxes.length === 0) {
alert('请至少选择一个工单');
return;
}
const releasedBoxes = [];
checkedBoxes.forEach(cb => {
const row = cb.closest('tr');
const statusSpan = row.querySelector('.status');
if (statusSpan && statusSpan.textContent === '已发布') {
releasedBoxes.push(cb);
}
});
if (releasedBoxes.length === 0) {
alert('请选择已发布状态的工单');
return;
}
if (confirm(`确认将选中的 ${releasedBoxes.length} 个工单开工?`)) {
releasedBoxes.forEach(cb => {
const row = cb.closest('tr');
const statusSpan = row.querySelector('.status');
if (statusSpan) {
statusSpan.textContent = '生产中';
statusSpan.className = 'status status-in-production';
}
const actualStartTime = row.querySelector('td:nth-child(17)') || row.querySelector('td:nth-child(13)');
if (actualStartTime) {
const now = new Date();
actualStartTime.textContent = now.toLocaleString('zh-CN');
}
});
alert('工单开工成功!');
}
});
}
const reportBtn = document.getElementById('report-btn');
const reportModal = document.getElementById('report-modal');
const closeReportModal = document.getElementById('close-report-modal');
const reportModalBtn = document.getElementById('report-modal-btn');
const addReportModal = document.getElementById('add-report-modal');
const closeAddReportModal = document.getElementById('close-add-report-modal');
const cancelAddReportBtn = document.getElementById('cancel-add-report-btn');
const confirmAddReportBtn = document.getElementById('confirm-add-report-btn');
function openModal(modal) {
if (modal) {
modal.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
}
function closeModal(modal) {
if (modal) {
modal.style.display = 'none';
document.body.style.overflow = '';
}
}
if (reportBtn) {
reportBtn.addEventListener('click', function() {
openModal(reportModal);
});
}
const reportRowBtns = document.querySelectorAll('.report-row-btn');
reportRowBtns.forEach(btn => {
btn.addEventListener('click', function() {
openModal(reportModal);
});
});
if (closeReportModal) {
closeReportModal.addEventListener('click', function() {
closeModal(reportModal);
});
}
if (reportModalBtn) {
reportModalBtn.addEventListener('click', function() {
closeModal(reportModal);
openModal(addReportModal);
});
}
if (closeAddReportModal) {
closeAddReportModal.addEventListener('click', function() {
closeModal(addReportModal);
});
}
if (cancelAddReportBtn) {
cancelAddReportBtn.addEventListener('click', function() {
closeModal(addReportModal);
});
}
if (confirmAddReportBtn) {
confirmAddReportBtn.addEventListener('click', function() {
const boxCode = document.getElementById('box-code').value;
const reportQty = document.getElementById('report-qty').value;
if (!boxCode || boxCode.trim() === '') {
alert('请扫描或输入流转箱编号');
return;
}
if (!reportQty || parseInt(reportQty) <= 0) {
alert('请输入有效的报工数量');
return;
}
closeModal(addReportModal);
alert('报工成功!');
});
}
if (reportModal) {
reportModal.addEventListener('click', function(e) {
if (e.target === reportModal) {
closeModal(reportModal);
}
});
}
if (addReportModal) {
addReportModal.addEventListener('click', function(e) {
if (e.target === addReportModal) {
closeModal(addReportModal);
}
});
}
// 通用新增弹窗功能
const addButtons = document.querySelectorAll('.add-btn');
const addModals = document.querySelectorAll('.add-modal');
addButtons.forEach(btn => {
btn.addEventListener('click', function() {
const modalId = this.dataset.modal;
const modal = document.getElementById(modalId);
if (modal) {
openModal(modal);
}
});
});
addModals.forEach(modal => {
const closeBtn = modal.querySelector('.btn-close');
const cancelBtn = modal.querySelector('.cancel-btn');
const confirmBtn = modal.querySelector('.confirm-btn');
if (closeBtn) {
closeBtn.addEventListener('click', function() {
closeModal(modal);
});
}
if (cancelBtn) {
cancelBtn.addEventListener('click', function() {
closeModal(modal);
});
}
if (confirmBtn) {
confirmBtn.addEventListener('click', function() {
alert('保存成功!');
closeModal(modal);
});
}
modal.addEventListener('click', function(e) {
if (e.target === modal) {
closeModal(modal);
}
});
});
// 填写报告弹窗功能
const fillReportBtns = document.querySelectorAll('.fill-report-btn');
const reportDetailModal = document.getElementById('report-detail-modal');
fillReportBtns.forEach(btn => {
btn.addEventListener('click', function() {
if (reportDetailModal) {
const sampleInputs = reportDetailModal.querySelectorAll('.sample-input');
sampleInputs.forEach(input => {
input.disabled = false;
});
reportDetailModal.querySelector('.modal-title').textContent = '填写报告';
reportDetailModal.querySelector('.report-action').innerHTML = '<button class="btn btn-primary" onclick="saveReport()">保存报告</button>';
openModal(reportDetailModal);
}
});
});
// 查看报告弹窗功能
const viewReportBtns = document.querySelectorAll('.view-report-btn');
viewReportBtns.forEach(btn => {
btn.addEventListener('click', function() {
if (reportDetailModal) {
const sampleInputs = reportDetailModal.querySelectorAll('.sample-input');
sampleInputs.forEach(input => {
input.disabled = true;
});
reportDetailModal.querySelector('.modal-title').textContent = '查看报告';
reportDetailModal.querySelector('.report-action').innerHTML = '<button class="btn btn-default" onclick="closeReportModal()">关闭</button>';
openModal(reportDetailModal);
}
});
});
});
function saveReport() {
const modal = document.getElementById('report-detail-modal');
if (modal) {
alert('报告保存成功!');
closeModal(modal);
}
}
function closeReportModal() {
const modal = document.getElementById('report-detail-modal');
if (modal) {
closeModal(modal);
}
}
const detailData = {
'DJ20260608000001': [
{ type: '13e', item: 'saf', desc: 'AGEBA WHASasFAVG SFDHFDASdadfsFW DFVEWDWFcwdxac WFEEwccwefdcWQD AEFW', result: 'Pass', time: '2022-08-25 14:05:48', workerId: 'ADMIN', worker: '系统管理员', remark: 'sacAcaa c Ac a ca v c xd' },
{ type: 'safcsad', item: 'ssfd', desc: 'sdfa', result: 'Pass', time: '2022-08-25 14:04:40', workerId: 'ADMIN', worker: '系统管理员', remark: '' },
{ type: 'scas', item: 'sf', desc: 'dsf', result: 'NG', time: '2022-08-25 14:05:01', workerId: 'ADMIN', worker: '系统管理员', remark: '' }
],
'DJ20260608000002': [
{ type: '外观检查', item: '表面状态', desc: '检查设备表面是否有划痕、锈蚀', result: 'Pass', time: '2022-08-25 14:05:48', workerId: 'ZS001', worker: '张三', remark: '状态良好' },
{ type: '功能测试', item: '运行状态', desc: '测试设备运行是否正常', result: 'NG', time: '2022-08-25 14:10:30', workerId: 'ZS001', worker: '张三', remark: '发现异常噪音' },
{ type: '安全检查', item: '安全设施', desc: '检查安全防护装置', result: 'Pass', time: '2022-08-25 14:15:00', workerId: 'ZS001', worker: '张三', remark: '' }
],
'DJ20260608000003': [
{ type: '常规检查', item: '清洁度', desc: '设备表面清洁状况', result: 'Pass', time: '2022-08-25 14:30:12', workerId: 'LS002', worker: '李四', remark: '' },
{ type: '性能测试', item: '运行参数', desc: '检查设备运行参数是否正常', result: 'Pass', time: '2022-08-25 14:35:00', workerId: 'LS002', worker: '李四', remark: '' }
],
'XJ20260608000001': [
{ type: '巡检项A', item: '设备状态', desc: '整体运行状态检查', result: 'Pass', time: '2022-08-25 09:00:00', workerId: 'ADMIN', worker: '系统管理员', remark: '' },
{ type: '巡检项B', item: '安全隐患', desc: '安全隐患排查', result: 'Pass', time: '2022-08-25 09:05:00', workerId: 'ADMIN', worker: '系统管理员', remark: '' },
{ type: '巡检项C', item: '环境检查', desc: '工作环境检查', result: 'Pass', time: '2022-08-25 09:10:00', workerId: 'ADMIN', worker: '系统管理员', remark: '' }
],
'XJ20260608000002': [
{ type: '日常巡检', item: '设备外观', desc: '检查设备外观是否完好', result: 'Pass', time: '2022-08-25 09:45:30', workerId: 'ZS001', worker: '张三', remark: '' },
{ type: '日常巡检', item: '运行状态', desc: '检查设备运行状态', result: 'Pass', time: '2022-08-25 09:50:00', workerId: 'ZS001', worker: '张三', remark: '' }
],
'XJ20260608000003': [
{ type: '专项巡检', item: '关键部件', desc: '检查关键部件磨损情况', result: 'NG', time: '2022-08-25 11:20:15', workerId: 'LS002', worker: '李四', remark: '部件有磨损,需要更换' }
],
'BY20260608000001': [
{ type: '日常保养', item: '润滑', desc: '设备润滑保养', result: 'Pass', time: '2022-08-25 09:30:00', workerId: 'ZS001', worker: '张三', remark: '已完成润滑' },
{ type: '日常保养', item: '清洁', desc: '设备清洁保养', result: 'Pass', time: '2022-08-25 09:45:00', workerId: 'ZS001', worker: '张三', remark: '' },
{ type: '日常保养', item: '紧固', desc: '紧固螺丝检查', result: 'Pass', time: '2022-08-25 10:00:00', workerId: 'ZS001', worker: '张三', remark: '' }
],
'BY20260608000002': [
{ type: '定期保养', item: '更换配件', desc: '更换磨损配件', result: 'Pass', time: '2022-08-25 10:30:00', workerId: 'LS002', worker: '李四', remark: '' },
{ type: '定期保养', item: '校准', desc: '设备校准', result: '-', time: '-', workerId: 'LS002', worker: '李四', remark: '进行中' }
],
'BY20260608000003': [
{ type: '专项保养', item: '深度清洁', desc: '设备深度清洁', result: 'Pass', time: '2022-08-25 11:45:30', workerId: 'WW003', worker: '王五', remark: '' }
]
};
function initOrderLinks() {
const orderLinks = document.querySelectorAll('.order-link');
const checkDetailModal = document.getElementById('check-detail-modal');
const patrolDetailModal = document.getElementById('patrol-detail-modal');
const maintenanceDetailModal = document.getElementById('maintenance-detail-modal');
orderLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const orderNo = this.dataset.order;
let detailModal = null;
let detailTitle = '';
if (orderNo.startsWith('DJ')) {
detailModal = checkDetailModal;
detailTitle = '点检明细';
} else if (orderNo.startsWith('XJ')) {
detailModal = patrolDetailModal;
detailTitle = '巡检明细';
} else if (orderNo.startsWith('BY')) {
detailModal = maintenanceDetailModal;
detailTitle = '保养明细';
}
if (detailModal) {