xwt
2025-09-30 e9330bc1e2449b5763097dff4cb896746fda8d4d
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
<template>
    <view class="container">
        <!-- 头部 -->
        <view class="header">
            <view class="title">来料检验项目明细</view>
            <view class="order-number">当前检验单号: {{formData.releaseNo}}</view>
        </view>
 
        <!-- 标签栏 -->
        <scroll-view class="tabs" scroll-x="true" :show-scrollbar="false">
            <view class="tabs-container">
                <view v-for="(tab, index) in tabs" :key="index" class="tab" :class="{active: currentTab === index}"
                    @tap="switchTab(index,tab.id)">
                    {{ tab.fcheckItem }}
                </view>
            </view>
        </scroll-view>
        <view class="tab-content">
            <!-- 基本信息 -->
            <view class="section">
                <view class="section-header">基本信息</view>
                <view class="section-body">
                    <view class="info-grid">
                        <view class="info-item">
                            <view class="info-label">项目名称</view>
                            <view class="info-value">{{ formData.fcheckItem }}</view>
                        </view>
                        <view v-if="parseHoleCount(formData.fcheckItem)" class="info-item">
                            <view class="info-label">穴数</view>
                            <view class="info-value hole-count">
                                {{ parseHoleCount(formData.fcheckItem) }}穴
                                <span v-if="formData.dnum" class="blocked-holes-info">(已堵{{ formData.dnum }}穴)</span>
                            </view>
                        </view>
                        <view class="info-item">
                            <view class="info-label">检验工具</view>
                            <view class="info-value">{{ formData.fcheckTool }}</view>
                        </view>
                        <view class="info-item">
                            <view class="info-label">检验数量</view>
                            <view class="info-value">{{ formData.checkQyt }}</view>
                        </view>
                        <view class="info-item">
                            <view class="info-label">检验标准</view>
                            <view class="info-value">{{ formData.sampleSizeNo }}</view>
                        </view>
                        <view class="info-item">
                            <view class="info-label">检验水平</view>
                            <view class="info-value">{{ formData.fcheckLevel }}</view>
                        </view>
                        <view class="info-item">
                            <view class="info-label">接收水平</view>
                            <view class="info-value">{{ formData.facLevel }}</view>
                        </view>
                        <view v-if="formData.fdownAllow!=null" class="info-item">
                            <view class="info-label">下限</view>
                            <view class="info-value">{{ formData.fdownAllow }}</view>
                        </view>
                        <view v-if="formData.fstand!=null" class="info-item">
                            <view class="info-label">标准值</view>
                            <view class="info-value">{{ formData.fstand }}</view>
                        </view>
                        <view v-if="formData.fupAllow!=null" class="info-item">
                            <view class="info-label">上限</view>
                            <view class="info-value">{{ formData.fupAllow }}</view>
                        </view>
                    </view>
                </view>
            </view>
 
            <!-- 规格要求 -->
            <view class="section">
                <view class="section-header">规格要求</view>
                <view class="section-body">
                    <text class="spec-text">{{ formData.fspecRequ }}</text>
                </view>
            </view>
            <!-- 规格要求 -->
            <view class="section">
                <view class="section-header">检验描述</view>
                <view class="section-body">
                    <text class="spec-text">{{ formData.fcheckItemDesc }}</text>
                </view>
            </view>
            <!-- 检验结果 -->
            <view class="section">
                <view class="section-header">检验结果</view>
                <view class="section-body">
                    <view class="info-grid">
                        <view class="info-item">
                            <view class="info-label">AC数</view>
                            <view class="info-value">{{formData.facQty}}</view>
                        </view>
                        <view class="info-item">
                            <view class="info-label">RE数</view>
                            <view class="info-value">{{formData.freQty}}</view>
                        </view>
                        <view class="info-item">
                            <view class="info-label">不合格数</view>
                            <view class="info-value">{{formData.fngQty}}</view>
                        </view>
                    </view>
 
                    <view v-if="formData.result!=null" class="result-preview">
                        <view class="info-label">预览结果</view>
                        <view class="info-value">{{formData.result}}</view>
                    </view>
 
                    <view v-if="formData.funit!=null" class="result-ng">
                        <view class="info-label">不良描述</view>
                        <view class="info-value danger">{{formData.funit}}</view>
                    </view>
                    <view class="result-ng">
                        <view class="info-label">备注</view>
                        <view class="info-value danger">{{formData.meom}}</view>
                    </view>
                </view>
            </view>
 
            <!-- 结果录入 -->
            <view class="section">
                <view class="section-header">检验结果录入</view>
                <view class="section-body">
                    <view class="input-group" v-if="tableData.length >= formData.checkQyt && formData.fstand == null">
                        <view class="input-wrapper">
                            <input v-model="batchInput" type="text" class="result-input"
                                placeholder="格式:OK-3 或 NG-3(请勿修改结果为数字的值)" placeholder-class="placeholder"
                                @input="validateBatchInput" @blur="validateBatchInput" />
                            <button :disabled="!isBatchInputValid" :class="{ 'btn-disabled': !isBatchInputValid }"
                                style="margin: 0px;background-color: #3498db;color:#ffffff ;" class="btn primary-btn"
                                @tap="batchUpdateResults">批量修改</button>
                        </view>
                        <view v-if="batchInputError" class="error-message">{{ batchInputError }}</view>
                    </view>
                     <!-- 有穴数时的输入样式 -->
                     <view v-if="parseHoleCount(formData.fcheckItem)" class="input-group input-with-holes">
                         <view class="input-wrapper">
                             <button class="btn upload-btn" @tap="chooseImage">
                                 <uni-icons type="upload" size="16" color="#fff"></uni-icons>
                                 上传/查看图片
                             </button>
                             <button v-if="this.current" class="btn upload-btn" @tap="upRemarks">
                                 <uni-icons type="compose" size="16" color="#fff"></uni-icons>
                                 不良描述
                             </button>
                             <button v-if="this.current" class="btn upload-btn" @tap="upMeom">
                                 <uni-icons type="compose" size="16" color="#fff"></uni-icons>
                                 备注
                             </button>
                         </view>
                         <view class="input-wrapper" style="margin-top: 15px;">
                             <input v-if="(tableData.length < formData.checkQyt) && formData.fupAllow && formData.fdownAllow"
                                 ref="numberInput"
                                 :focus="isFocus"
                                 @input="onNumberInput"
                                 @confirm="onEnterSave"
                                 @blur="isFocus = false"
                                 v-model="formData.fcheckResu"
                                 type="text"
                                 class="result-input"
                                 placeholder="请输入检验结果..."
                                 placeholder-class="placeholder" />
                             <input v-else-if="(tableData.length < formData.checkQyt)"
                                 ref="textInput"
                                 :focus="isFocus"
                                 @input="search($event)"
                                 @confirm="onEnterSave"
                                 @blur="isFocus = false"
                                 v-model="inputTxt"
                                 type="text"
                                 class="result-input"
                                 placeholder="请输入检验结果..."
                                 placeholder-class="placeholder" />
                             <button v-if="(tableData.length < formData.checkQyt)"
                                 style="margin: 0px;background-color: #3498db;color:#ffffff ;" class="btn primary-btn"
                                 @tap="saveResult">保存结果</button>
                         </view>
                     </view>
 
                     <!-- 无穴数时的输入样式 -->
                     <view v-else class="input-group input-without-holes">
                         <view class="input-wrapper">
                             <button class="btn upload-btn" @tap="chooseImage">
                                 <uni-icons type="upload" size="16" color="#fff"></uni-icons>
                                 上传/查看图片
                             </button>
                             <button v-if="this.current" class="btn upload-btn" @tap="upRemarks">
                                 <uni-icons type="compose" size="16" color="#fff"></uni-icons>
                                 不良描述
                             </button>
                             <button v-if="this.current" class="btn upload-btn" @tap="upMeom">
                                 <uni-icons type="compose" size="16" color="#fff"></uni-icons>
                                 备注
                             </button>
                             <input v-if="(tableData.length < formData.checkQyt) && formData.fupAllow && formData.fdownAllow"
                                 ref="numberInput"
                                 :focus="isFocus"
                                 @input="onNumberInput"
                                 @confirm="onEnterSave"
                                 @blur="isFocus = false"
                                 v-model="formData.fcheckResu"
                                 type="text"
                                 class="result-input"
                                 placeholder="请输入检验结果..."
                                 placeholder-class="placeholder" />
                             <input v-else-if="(tableData.length < formData.checkQyt)"
                                 ref="textInput"
                                 :focus="isFocus"
                                 @input="search($event)"
                                 @confirm="onEnterSave"
                                 @blur="isFocus = false"
                                 v-model="inputTxt"
                                 type="text"
                                 class="result-input"
                                 placeholder="请输入检验结果..."
                                 placeholder-class="placeholder" />
                             <button v-if="(tableData.length < formData.checkQyt)"
                                 style="margin: 0px;background-color: #3498db;color:#ffffff ;" class="btn primary-btn"
                                 @tap="saveResult">保存结果</button>
                         </view>
                     </view>
 
                </view>
            </view>
 
            <!-- 结果表格 -->
            <view v-if="parseHoleCount(formData.fcheckItem) || (tableData.length>0 && !parseHoleCount(formData.fcheckItem))" class="table-container">
                <!-- 有穴数时的表格头部 -->
                <view v-if="parseHoleCount(formData.fcheckItem)" class="table-header">
                    <view class="th">编号</view>
                    <view class="th">穴号</view>
                    <view class="th">记录值</view>
                    <view class="th">检验结果<i style="color: rgb(0 212 68);"
                            v-if="!(tableData.length < formData.checkQyt)">(输入已完成)</i></view>
                    <view class="th" v-if="current">操作</view>
                </view>
                
                <!-- 无穴数时的表格头部 -->
                <view v-else class="table-header">
                    <view class="th">编号</view>
                    <view class="th">检验结果<i style="color: rgb(0 212 68);"
                            v-if="!(tableData.length < formData.checkQyt)">(输入已完成)</i></view>
                    <view class="th" v-if="current">操作</view>
                </view>
 
                <!-- 有穴数时的表格行 -->
                <template v-if="parseHoleCount(formData.fcheckItem)">
                    <view v-for="(item, index) in completeHoleList" :key="index" class="table-row">
                        <view class="td">{{ index + 1 }}</view>
                        <view class="td">{{ item.holeNumber }}穴</view>
                        <view class="td">{{ item.recordValue }}</view>
                        <view class="td">
                            <view :class="['result-badge', getResultBadgeClass(item.resultStatus)]">
                                {{ item.resultStatus }}
                            </view>
                        </view>
                        <view class="td" v-if="current">
                            <button v-if="!item.isDefault && isNumber && !item.isBlocked" class="btn danger-btn" @tap="toDetail(item)">
                                修改
                            </button>
                            <span v-if="item.isBlocked" class="blocked-text">已堵穴</span>
                        </view>
                    </view>
                </template>
                
                <!-- 无穴数时的表格行 -->
                <template v-else>
                    <view v-for="(item, index) in tableData" :key="index" class="table-row">
                        <view class="td">{{ index + 1 }}</view>
                        <view class="td">
                            <view :class="['result-badge', item.fcheckResu]">
                                {{ item.fcheckResu }}
                            </view>
                        </view>
                        <view class="td" v-if="current">
                            <button v-if="!isNumber" class="btn danger-btn" @tap="toggleResult(item)">
                                {{ editResult(item.fcheckResu) }}
                            </button>
                            <button v-if="isNumber" class="btn danger-btn" @tap="toDetail(item)">
                                修改
                            </button>
                        </view>
                    </view>
                </template>
            </view>
            <view v-if="remarksPopup" class="overlay">
                <view class="popup">
                    <h3>修改不合格描述</h3>
                    <form>
                        <view class="form-group">
                            <label class="form-label">不合格描述:</label>
                            <input class="form-input" type="text" v-model="remarks" />
                        </view>
                        <button class="updateBut" type="warn" @click="editRemarks">修改</button>
                        <button @click="remarksPopup = !remarksPopup">取消</button>
                    </form>
                </view>
            </view>
            <view v-if="meomPopup" class="overlay">
                <view class="popup">
                    <h3>修改备注</h3>
                    <form>
                        <view class="form-group">
                            <label class="form-label">备注:</label>
                            <input class="form-input" type="text" v-model="meom" />
                        </view>
                        <button class="updateBut" type="warn" @click="editMeom">修改</button>
                        <button @click="meomPopup = !meomPopup">取消</button>
                    </form>
                </view>
            </view>
            <view v-if="showMeom" class="overlay">
                <view class="popup">
                    <h3>修改检验结果</h3>
                    <form :modelValue="editData">
                        <view class="form-group">
                            <label class="form-label">检验结果:</label>
                            <input class="form-input" type="text" v-model="editData.fcheckResu" />
                        </view>
                        <button type="warn" @click="eidt">修改</button>
                        <button @click="showMeom = !showMeom">取消</button>
                    </form>
                </view>
            </view>
 
        </view>
    </view>
</template>
 
<script>
    import {
        compile
    } from "vue";
 
    export default {
        data() {
            return {
                formData: {},
                tableData: {},
                mainId: '',
                isNumber: false,
                currentTab: 0,
                tabs: [],
                inputResult: '',
                remarksPopup: false,
                showPopup: false,
                editData: {},
                inputTxt: '',
                formID: '',
                releaseNo: '',
                current: false,
                batchInput: '',
                batchInputError: '',
                isBatchInputValid: false,
                funit:'',
                meomPopup: false,
                showMeom:false,
                meom: '',
                isFocus: false, // 新增,控制输入框聚焦
            }
        },
        computed: {
            // 生成完整的穴位列表(根据检验数量生成,穴号循环显示)
            completeHoleList() {
                const holeCount = this.parseHoleCount(this.formData.fcheckItem);
                if (!holeCount) return this.tableData;
                
                // 获取原始检验数量(堵穴前的数量)
                const originalCheckQyt = this.getOriginalCheckQyt();
                const completeList = [];
                
                // 解析堵穴信息
                const blockedHoles = this.getBlockedHolesList();
                
                // 根据原始检验数量生成记录,穴号循环显示
                for (let i = 1; i <= originalCheckQyt; i++) {
                    // 计算当前记录的穴号(循环显示)
                    const holeNumber = ((i - 1) % holeCount) + 1;
                    
                    // 检查当前穴号是否被堵穴
                    const isBlocked = blockedHoles.includes(holeNumber);
                    
                    // 查找是否已有该穴号的记录
                    // 由于堵穴后检验数量减少,需要按实际检验数量来匹配
                    const actualCheckQyt = this.formData.checkQyt || 0;
                    let existingRecord = null;
                    
                    // 按顺序匹配记录,但只匹配未堵穴的穴
                    if (!isBlocked && this.tableData.length > 0) {
                        // 计算当前穴号在未堵穴中的序号
                        let unblockedIndex = 0;
                        for (let j = 1; j <= holeNumber; j++) {
                            if (!blockedHoles.includes(j)) {
                                if (j === holeNumber) {
                                    // 找到当前穴号在未堵穴中的位置
                                    existingRecord = this.tableData[unblockedIndex];
                                    break;
                                }
                                unblockedIndex++;
                            }
                        }
                    }
                    
                    console.log(`穴号${holeNumber} ${isBlocked ? '(已堵穴)' : '(可填写)'}: ${existingRecord ? '找到记录' : '未找到记录'}`);
                    
                    if (existingRecord) {
                        // 如果已有记录,使用现有数据
                        completeList.push({
                            ...existingRecord,
                            holeNumber: holeNumber,
                            recordValue: isBlocked ? 'N/A' : (existingRecord.fcheckResu || 'N/A'),
                            resultStatus: isBlocked ? '已堵穴' : (this.getResultStatus(existingRecord.fcheckResu) || '未填写'),
                            isBlocked: isBlocked
                        });
                    } else {
                        // 如果没有记录,创建默认记录
                        completeList.push({
                            id: null,
                            holeNumber: holeNumber,
                            recordValue: isBlocked ? 'N/A' : 'N/A',
                            resultStatus: isBlocked ? '已堵穴' : '待填写',
                            fcheckResu: null,
                            isDefault: true, // 标记为默认记录
                            isBlocked: isBlocked
                        });
                    }
                }
                
                // 排序:未堵穴的在前,已堵穴的在后,然后按穴号排序
                return completeList.sort((a, b) => {
                    // 首先按是否堵穴排序:未堵穴的在前,已堵穴的在后
                    if (a.isBlocked !== b.isBlocked) {
                        return a.isBlocked ? 1 : -1;
                    }
                    // 然后按穴号排序
                    if (a.holeNumber !== b.holeNumber) {
                        return a.holeNumber - b.holeNumber;
                    }
                    // 穴号相同时,按原始顺序排序
                    return 0;
                });
            }
        },
        methods: {
            // 解析检验项目名称中的穴数
            parseHoleCount(checkItemName) {
                if (!checkItemName) return null;
                
                // 匹配格式:尺寸检查(5穴)或 尺寸检查(5穴)
                const match = checkItemName.match(/[((](\d+)穴[))]/);
                return match ? parseInt(match[1]) : null;
            },
            
            // 获取堵穴列表
            getBlockedHolesList() {
                if (!this.formData.dnum) return [];
                
                // 解析堵穴字符串,支持 "1,2,3" 或 "1,2,3" 格式
                return this.formData.dnum
                    .split(/[,,]/)
                    .map(s => parseInt(s.trim()))
                    .filter(n => !isNaN(n));
            },
            
            // 获取原始检验数量(堵穴前的数量)
            getOriginalCheckQyt() {
                const holeCount = this.parseHoleCount(this.formData.fcheckItem);
                if (!holeCount || !this.formData.dnum) {
                    return this.formData.checkQyt || 0;
                }
                
                const blockedHoles = this.getBlockedHolesList();
                const blockedRatio = blockedHoles.length / holeCount;
                const currentCheckQyt = this.formData.checkQyt || 0;
                
                // 计算原始检验数量:当前数量 / (1 - 堵穴比例)
                const originalCheckQyt = Math.round(currentCheckQyt / (1 - blockedRatio));
                
                return originalCheckQyt;
            },
            
            // 根据记录值判断检验结果状态
            getResultStatus(recordValue) {
                if (!recordValue) return '';
                
                // 如果有上下限,根据数值判断
                if (this.formData.fupAllow && this.formData.fdownAllow) {
                    const numValue = parseFloat(recordValue);
                    if (isNaN(numValue)) return recordValue;
                    
                    if (numValue >= parseFloat(this.formData.fdownAllow) && 
                        numValue <= parseFloat(this.formData.fupAllow)) {
                        return 'OK';
                    } else {
                        return 'NG';
                    }
                }
                
                // 无上下限时,直接返回记录值
                return recordValue;
            },
            
            // 获取检验结果徽章的样式类
            getResultBadgeClass(resultStatus) {
                switch(resultStatus) {
                    case 'OK':
                        return 'OK';
                    case 'NG':
                        return 'NG';
                    case '未填写':
                        return 'pending';
                    case '待填写':
                        return 'pending';
                    case '已堵穴':
                        return 'blocked';
                    case 'N/A':
                        return 'blocked';
                    default:
                        return 'default';
                }
            },
            
            // 添加新记录(用于未填写的穴位)
            addNewRecord(item) {
                // 这里可以触发填写逻辑,比如弹出输入框或跳转到填写页面
                // 暂时先显示提示
                this.$showMessage(`请填写第${item.holeNumber}穴的检验结果`);
            },
            
            
            
            // 处理回车键保存事件
            onEnterSave() {
                // 检查是否已经达到检验数量上限
                if (this.tableData.length >= this.formData.checkQyt) {
                    this.$showMessage("已达到检验数量上限");
                    return;
                }
                
                // 直接保存结果
                this.saveResult();
            },
            
            switchTab(index, mainIds) {
                this.currentTab = index
                this.mainId = mainIds;
                this.refreshResult();
 
            },
            validateBatchInput() {
                const input = this.batchInput.trim();
                if (!input) {
                    this.batchInputError = '';
                    this.isBatchInputValid = false;
                    return;
                }
 
                // 验证格式:OK-数字 或 NG-数字
                const match = input.match(/^(OK|NG)-(\d+)$/);
                if (!match) {
                    this.batchInputError = '格式错误,请输入:OK-数字 或 NG-数字';
                    this.isBatchInputValid = false;
                    return;
                }
 
                const count = parseInt(match[2]);
                if (count <= 0 || count > this.tableData.length) {
                    this.batchInputError = `数量必须在 1-${this.tableData.length} 之间`;
                    this.isBatchInputValid = false;
                    return;
                }
 
 
                this.batchInputError = '';
                this.isBatchInputValid = true;
            },
 
            // 批量更新检验结果
            batchUpdateResults() {
                if (!this.isBatchInputValid) return;
 
                const [status, countStr] = this.batchInput.split('-');
                const count = parseInt(countStr);
 
                if (this.tableData.length > 0) {
                    const firstItem = this.tableData[0];
                    const isNumber = /^-?\d+(\.\d+)?$/.test(firstItem.fcheckResu);
                    if (isNumber) {
                        this.$showMessage("不能批量修改数字类型的结果");
                        return;
                    }
                }
                let updatedCount = 0;
                const requests = [];
                for (let i = 0; i < count; i++) {
                    const item = this.tableData[i];
                    const fstand = status === 'OK' ? '√' : '×';
                    const fcheckResu = status;
 
                    requests.push(this.$post({
                        url: "/LLJ/UpdateQSItemDetail",
                        data: {
                            id: item.id,
                            mainId: this.formData.id,
                            releaseNo: this.formData.releaseNo,
                            fstand: fstand,
                            fcheckResu: fcheckResu,
                            updateBy: this.$loginInfo.account,
                        }
                    }));
                }
 
                Promise.all(requests)
                    .then(() => {
                        this.$showMessage(`成功将前${count}个结果修改为${status}`);
                        this.batchInput = '';
                        this.batchInputError = '';
                        this.isBatchInputValid = false;
                        this.refreshResult(); // 刷新结果
                    })
                    .catch(error => {
                        this.$showMessage(`批量修改失败: ${error.message}`);
                    });
            },
            //检测输入框的输入,并给变量赋值
            search(event) {
                this.formData.fcheckResu = event.detail.value;
                this.inputTxt = event.detail.value;
            },
            onNumberInput(e) {
                // 只允许输入数字和小数点
                let val = e.detail.value.replace(/[^\d.]/g, '');
                // 只允许一个小数点
                val = val.replace(/\.{2,}/g, '.');
                val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
                this.formData.fcheckResu = val;
            },
            toggleResult(item) {
                let fstand = "√";
                let fcheckResu = "OK";
 
                if (item.fcheckResu == 'OK') {
                    fstand = "×";
                    fcheckResu = "NG";
                }
 
                this.$post({
                    url: "/LLJ/UpdateQSItemDetail",
                    data: {
                        id: item.id,
                        mainId: this.formData.id,
                        releaseNo: this.formData.releaseNo,
                        fstand: fstand,
                        fcheckResu: fcheckResu,
                        updateBy: this.$loginInfo.account,
                    }
                }).then(res => {
                    this.$showMessage("修改成功");
                    this.refreshResult(); //刷新页面
                })
            },
            chooseImage() {
                uni.navigateTo({
                    url: 'ImageItem?id=' + this.formData.id
                });
            },
            upRemarks() {
                this.remarksPopup = true;
            },
            saveResult() {
                let count = this.formData.checkQyt;
                let fstand = "√";
 
                console.log('保存结果:', this.formData.fcheckResu);
                console.log('当前tableData长度:', this.tableData.length);
                console.log('检验数量:', this.formData.checkQyt);
 
                //有最大值和最小值就根据是否符合标准值更新判定结果,没有最大值和最小值就根据是否通过检验判定结果
                if (this.formData.fupAllow && this.formData.fdownAllow) {
 
                    if (!this.formData.fcheckResu) {
                        this.$showMessage("请输入正确的检验值");
                        return;
                    }
 
                    if (isNaN(parseFloat(this.formData.fcheckResu))) {
                        this.$showMessage("请输入正确的检验值");
                        return;
                    }
                    
                    if (!/^-?\d+(\.\d+)?$/.test(this.formData.fcheckResu)) {
                        this.$showMessage("请输入正确的数值!");
                        return;
                    }
                    if (parseFloat(this.formData.fcheckResu) >= parseFloat(this.formData.fdownAllow) && parseFloat(this
                            .formData
                            .fcheckResu) <= parseFloat(this.formData.fupAllow)) {
                        fstand = "√"
                    } else {
                        fstand = "×";
                    }
                    count = 1;
                } else {
 
                    if (!this.formData.fcheckResu) {
                        this.formData.fcheckResu = 1
                    }
 
                    if (this.formData.fcheckResu == 0 || this.formData.fcheckResu == 1) {
                        this.formData.isPass = this.formData.fcheckResu
                    } else {
                        this.$showMessage("无标准值时,检验结果只能为0或1!");
                        return;
                    }
                    count = count - this.tableData.length;
                }
 
                console.log('准备保存:', {
                    fstand: fstand,
                    fcheckResu: this.formData.fcheckResu,
                    count: count
                });
 
                this.formData.updater = this.$loginInfo.account;
 
                this.$post({
                    url: "/LLJ/SetQSItemDetail",
                    data: {
                        mainId: this.formData.id,
                        releaseNo: this.formData.releaseNo,
                        fstand: fstand,
                        fcheckResu: this.formData.fcheckResu,
                        LastupdateBy: this.$loginInfo.account,
                        count: count
                    }
                }).then(res => {
                    console.log('保存成功,刷新数据');
                    this.formData.fcheckResu = null;
                    this.$showMessage("保存成功");
                    this.refreshResult();
                    this.inputTxt = '';
                    // 使用 isFocus 控制聚焦,兼容多端
                    this.isFocus = false;
                    this.$nextTick(() => {
                        this.isFocus = true;
                    });
                })
 
            },
            
            goBack() {
                uni.navigateBack()
            },
            //获取检验单详情
            refreshResult() {
                this.$post({
                    url: "/LLJ/getXjDetail02ById",
                    data: {
                        id: this.mainId
                    }
                }).then(res => {
                    this.formData = res.data.tbBillList.itemXj01;
 
                    this.tableData = res.data.tbBillList.itemXj02s;
 
                    if (this.formData.imageData) {
                        this.isShowImg = true;
                        this.base64Image = 'data:image/jpeg;base64,' + this.formData.imageData;
                    }
 
                    //fupAllow  fdownAllow  standardValue
                    if (this.formData.fupAllow && this.formData.fdownAllow && this.formData.fstand) {
                        this.isNumber = true;
                    } else {
                        this.isNumber = false;
                    }
                    
                })
            },
            editResult(fcheckResu) {
                // 统一显示"改为不合格"
                return "改为不合格";
            },
            toDetail(item) {
                this.showPopup = !this.showPopup;
                this.showMeom = !this.showMeom;
                this.editData = item;
                
            },
            upMeom() {
                this.meomPopup = true;
                
            },
            editMeom() {
                // 保存备注信息
                if (this.meom) {
                    this.$post({
                        url: "/LLJ/saveRemarksPid",
                        data: {
                            pid: this.formData.id,
                            meom: this.meom,
                            
                        }
                    }).then(res => {
                        if (res.data.tbBillList > 0) {
                            this.formData.meom = this.meom;
                            this.meomPopup = !this.meomPopup;
                            this.$showMessage("保存成功");
                        }
                    })
                } else {
                    this.$post({
                        url: "/LLJ/saveRemarksPid",
                        data: {
                            pid: this.formData.id,
                            meom: ''
                        }
                    }).then(res => {
                        if (res.data.tbBillList > 0) {
                            this.formData.meom = this.meom;
                            this.meomPopup = !this.meomPopup;
                            this.$showMessage("保存成功");
                        }
                    })
                }
            },
            editRemarks() {
                if (this.remarks) {
                    
                    this.$post({
                        url: "/LLJ/saveRemarksPid",
                        data: {
                            pid: this.formData.id,
                            remarks: this.remarks
                        }
                    }).then(res => {
                        if (res.data.tbBillList > 0) {
                            this.formData.remarks = this.remarks;
                            this.remarksPopup = !this.remarksPopup;
                            this.$showMessage("保存成功");
                        }
                    })
                } else {
                    this.$post({
                        url: "/LLJ/saveRemarksPid",
                        data: {
                            pid: this.formData.id,
                            remarks: ''
                        }
                    }).then(res => {
                        if (res.data.tbBillList > 0) {
                            this.formData.remarks = this.remarks;
                            this.remarksPopup = !this.remarksPopup;
                            this.$showMessage("保存成功");
                        }
                    })
                }
            },
            eidt() {
 
                if (!this.editData.fcheckResu) {
                    this.$showMessage("请输入检验结果");
                }
 
                if (this.formData.fcheckResu == this.editData.fcheckResu) {
                    this.$showMessage("修改成功");
                    return;
                }
 
                let fstand = "√";
 
                if (this.formData.fupAllow && this.formData.fdownAllow) {
 
                    if (!this.editData.fcheckResu) {
                        this.$showMessage("请输入检验值");
                        return;
                    }
 
                    if (parseFloat(this.editData.fcheckResu) >= parseFloat(this.formData.fdownAllow) && parseFloat(this
                            .editData
                            .fcheckResu) <= parseFloat(this.formData.fupAllow)) {
                        this.editData.isPass = 1
                    } else {
                        this.editData.isPass = 0
                        fstand = "×";
                    }
                } else {
 
                    if (!this.editData.fcheckResu) {
                        this.editData.fcheckResu = 1
                    }
 
                    if (this.editData.fcheckResu == 0 || this.editData.fcheckResu == 1) {
                        if (this.editData.fcheckResu == 0) {
                            fstand = "×";
                        }
                    } else {
                        this.$showMessage("无标准值时,检验结果只能为0或1!");
                        return;
                    }
                }
 
                this.editData.updater = this.$loginInfo.account;
 
                this.$post({
                    url: "/LLJ/UpdateQSItemDetail",
                    data: {
                        id: this.editData.id,
                        mainId: this.formData.id,
                        releaseNo: this.formData.releaseNo,
                        fstand: fstand,
                        fcheckResu: this.editData.fcheckResu,
                        updateBy: this.$loginInfo.account,
                    }
                }).then(res => {
                    this.showPopup = !this.showPopup;
                    this.$showMessage("修改成功");
                    this.refreshResult(); //刷新页面
                })
            },
        },
        onLoad(options) {
            //options中包含了url附带的参数
            let params = options;
            this.mainId = params["mainId"];
            this.refreshResult();
            this.formID = params["formID"];
            this.releaseNo = params["releaseNo"];
            this.currentTab = parseInt(params["index"]);
            this.current = params["current"] === 'true' ? true : false;
            this.$post({
                url: "/LLJ/getJYItem",
                data: {
                    id: this.formID,
                    releaseNo: this.releaseNo,
                    
                }
            }).then(res1 => {
                let tableData = res1.data.tbBillList
                //当已检验个数都不为空时按照检测结构排序
                tableData.sort((a, b) => {
                    if (a.result === '未完成' && b.result === '合格') {
                        return -1;
                    } else if (a.result === '合格' && b.result === '未完成') {
                        return 1;
                    } else {
                        return 0;
                    }
                });
                this.tabs = tableData;
                // if (this.tableData.length === 0) {
                //     this.isShowTable = true;
                // }
                this.tableData.forEach((item, index) => {
                    this.set(item, 'current', this.current);
                });
                console.log(this.tableData);
 
 
            })
            this.$nextTick(() => {
                this.validateBatchInput();
            });
        }
    }
</script>
 
<style lang="scss">
    $primary-color: #409EFF;
    $success-color: #67C23A;
    $danger-color: #F56C6C;
    $border-color: #DCDFE6;
    $bg-color: #f5f7fa;
 
    .container {
        padding: 20px;
        background-color: #fff;
    }
 
    .header {
        padding: 20px;
        border-bottom: 1px solid $border-color;
        background: linear-gradient(90deg, #f0f7ff, #e1f0ff);
 
        .title {
            font-size: 24px;
            color: #333;
            margin-bottom: 10px;
        }
 
        .order-number {
            color: #666;
            font-size: 14px;
        }
    }
 
    .tabs {
        background-color: $bg-color;
        border-bottom: 1px solid $border-color;
        width: 100%;
        white-space: nowrap;
 
        .tabs-container {
            display: flex;
            min-width: 100%;
        }
 
        .tab {
            flex: none;
            min-width: 120px;
            text-align: center;
            padding: 12px 16px;
            border-right: 1px solid $border-color;
            color: #666;
            transition: all 0.3s;
            white-space: nowrap;
 
            &:last-child {
                border-right: none;
            }
 
            &.active {
                background-color: #fff;
                color: $primary-color;
                font-weight: bold;
                position: relative;
 
                &::after {
                    content: '';
                    position: absolute;
                    bottom: 0;
                    left: 0;
                    right: 0;
                    height: 2px;
                    background-color: $primary-color;
                }
            }
        }
    }
 
    .section {
        margin: 20px 0;
        border: 1px solid $border-color;
        border-radius: 4px;
 
        &-header {
            padding: 12px 16px;
            background-color: $bg-color;
            border-bottom: 1px solid $border-color;
            font-weight: bold;
        }
 
        &-body {
            padding: 16px;
        }
    }
 
    .info-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
 
        .info-item {
            margin-bottom: 12px;
 
            .info-label {
                color: #909399;
                font-size: 14px;
                margin-bottom: 4px;
            }
 
            .info-value {
                color: #333;
                font-weight: 500;
            }
        }
    }
 
    .input-group {
        margin: 16px 0;
 
        .input-wrapper {
            display: flex;
            gap: 12px;
 
            .result-input {
                flex: 1;
                height: 45px;
                padding: 0 12px;
                border: 1px solid $border-color;
                border-radius: 4px;
                font-size: 14px;
            }
 
            .upload-btn {
                background-color: #909399;
                color: #fff;
                padding: 0 10px;
                margin: 0;
                //height: 40rpx;
            }
        }
    }
 
    .table-container {
        border: 1px solid $border-color;
        border-radius: 4px;
        margin-top: 20px;
 
        .table-header {
            display: flex;
            background-color: $bg-color;
            border-bottom: 1px solid $border-color;
 
            .th {
                flex: 1;
                padding: 12px;
                font-weight: bold;
                text-align: center;
            }
        }
 
        .table-row {
            display: flex;
            border-bottom: 1px solid $border-color;
            padding: 12px;
 
            &:last-child {
                border-bottom: none;
            }
 
            .td {
                flex: 1;
                display: flex;
                align-items: center;
                justify-content: center;
                text-align: center;
            }
        }
    }
 
    .result-badge {
        display: inline-block;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 12px;
        font-weight: bold;
 
        &.OK {
            background-color: rgba($success-color, 0.1);
            color: $success-color;
        }
 
        &.NG {
            background-color: rgba($danger-color, 0.1);
            color: $danger-color;
        }
        
        &.pending {
            background-color: rgba(#f39c12, 0.1);
            color: #f39c12;
        }
        
        &.default {
            background-color: rgba(#909399, 0.1);
            color: #909399;
        }
        
        &.blocked {
            background-color: rgba(#e74c3c, 0.1);
            color: #e74c3c;
            font-weight: bold;
        }
    }
 
    .action-buttons {
        margin-top: 20px;
        display: flex;
        justify-content: flex-end;
        gap: 12px;
 
        .btn {
            padding: 8px 20px;
            border-radius: 4px;
 
            &.primary-btn {
                background-color: $primary-color;
                color: #fff;
 
            }
 
            &.cancel-btn {
                background-color: #909399;
                color: #fff;
            }
        }
    }
 
    .danger {
        color: $danger-color;
    }
 
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        display: flex;
        justify-content: center;
        align-items: center;
    }
 
    .popup {
        background-color: #fff;
        padding: 20px;
        border: 1px solid #ccc;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        width: 68vw;
        /* 设置宽度为视口宽度的80% */
        height: 25vh;
        /* 设置高度为视口高度的80% */
    }
 
    .updateBut {
        background-color: #3498db;
        color: white;
    }
 
     /* 有穴数时的输入样式 */
     .input-with-holes {
         .input-wrapper {
             display: flex;
             flex-direction: row;
             gap: 12px;
             align-items: center;
             flex-wrap: wrap;
             
             &:last-child {
                 margin-top: 15px;
                 flex-direction: row;
                 align-items: center;
             }
         }
         
         .result-input {
             flex: 1;
             height: 45px;
             padding: 0 12px;
             border: 1px solid $border-color;
             border-radius: 4px;
             font-size: 14px;
         }
     }
 
     /* 无穴数时的输入样式 */
     .input-without-holes {
         .input-wrapper {
             display: flex;
             flex-direction: row;
             gap: 12px;
             align-items: center;
         }
         
         .result-input {
             flex: 1;
             height: 45px;
             padding: 0 12px;
             border: 1px solid $border-color;
             border-radius: 4px;
             font-size: 14px;
         }
     }
 
    .error-message {
        color: $danger-color;
        font-size: 12px;
        margin-top: 4px;
    }
 
    .input-group:first-child {
        .result-input {
            border-color: $primary-color;
            box-shadow: 0 0 0 2px rgba($primary-color, 0.2);
        }
    }
 
    .btn-disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }
 
    .hole-count {
        color: #409EFF;
        font-weight: bold;
        background-color: rgba(64, 158, 255, 0.1);
        padding: 2px 8px;
        border-radius: 4px;
        display: inline-block;
    }
    
    .blocked-holes-info {
        color: #e74c3c;
        font-weight: bold;
        margin-left: 8px;
    }
    
    .blocked-text {
        color: #e74c3c;
        font-weight: bold;
        font-size: 12px;
    }
</style>