Fixiaobai
2023-10-13 e8308ddac0ba4a1f406e8f63d7e6b6f2541cb770
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
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
<template>
  <div style="height:100%;background:#fff;">
    <div
      ref="moveBlock"
      style="position:absolute;top:0px;left:0px;height:0px;width:0px;background:#f4f6fc;text-align:center;z-index: 9999;font-size:12px;"
    ></div>
    <div class="test-item-main">
      <div class="test-item-main-left">
        <div class="layout-field">
          <div class="field-title">布局字段</div>
          <div
            v-layoutdrag="{
              belongDiv: 'groupLayOutDiv',
              setMoveBlock: setMoveBlock,
              initMoveBlock: initMoveBlock,
              getInitMoveBlock: getInitMoveBlock,
              getScrollDistance: getScrollDistance,
              findAppropriatePosition: findAppropriatePosition,
              setAppropriatePosition: setAppropriatePosition
            }"
            class="field-label"
            id="0"
            ref="groupLayOutDiv"
          >
            <i class="el-icon-menu"></i
            ><span style="margin-left:3px;">分组</span>
          </div>
        </div>
        <div class="item-field">
          <div class="field-title">检测项字段</div>
          <div class="item-field-table" ref="itemLayOutDiv">
            <div
              v-for="(item, index) in checkItems"
              :key="item.id"
              class="item-field-div"
            >
              <el-checkbox v-model="checked"></el-checkbox>
              <div
                v-layoutdrag="{
                  belongDiv: 'itemLayOutDiv',
                  setMoveBlock: setMoveBlock,
                  initMoveBlock: initMoveBlock,
                  getInitMoveBlock: getInitMoveBlock,
                  getScrollDistance: getScrollDistance,
                  findAppropriatePosition: findAppropriatePosition,
                  setAppropriatePosition: setAppropriatePosition
                }"
                class="item-field-label-div"
                :id="item.id"
              >
                {{ item.name }}
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="test-item-main-middle">
        <div class="test-item-main-middle-header">
          <el-button
            type="text"
            icon="el-icon-check"
            size="medium"
            style="color:#67c23a"
            @click="submitJson"
            >提交</el-button
          >
          <el-button
            type="text"
            icon="el-icon-view"
            size="medium"
            @click="previewLayOut"
            >预览</el-button
          ><el-button
            type="text"
            icon="el-icon-delete"
            size="medium"
            style="color:#f56c6c"
            @click="cleanLayOut"
            >清空</el-button
          >
        </div>
        <div class="test-item-main-middle-body" ref="layOutContentDiv">
          <el-row
            :gutter="5"
            v-for="(rowItem, i) in layOutItems"
            :key="rowItem.uniqueId"
          >
            <div
              :ref="'body_row_' + rowItem.uniqueId"
              :style="'min-height:' + rowItem.minHeight + 'px'"
            >
              <el-col
                :span="colItem.span"
                v-for="(colItem, k) in rowItem.cols"
                :key="colItem.uniqueId"
              >
                <div
                  style="background:#ecf5ff;"
                  :ref="'body_col_' + colItem.uniqueId"
                  :class="[colItem.isSelect ? 'selected-item' : '']"
                >
                  <div
                    v-if="colItem.type === 'item'"
                    style="position:relative;"
                  >
                    <div @click="itemClick(colItem.uniqueId, 'firstCol')">
                      <div class="col-title">
                        <div
                          v-layoutdrag="{
                            belongDiv: 'itemTitleDiv',
                            setMoveBlock: setMoveBlock,
                            initMoveBlock: initMoveBlock,
                            getInitMoveBlock: getInitMoveBlock,
                            getScrollDistance: getScrollDistance,
                            findAppropriatePosition: findAppropriatePosition,
                            setAppropriatePosition: setAppropriatePosition,
                            itemClick: itemClick,
                            uniqueId: colItem.uniqueId,
                            colType: 'firstCol'
                          }"
                          style="cursor: move;width:calc(100% - 18px)"
                          :title="colItem.label"
                          :id="colItem.uniqueId"
                        >
                          {{ colItem.label }}
                        </div>
                        <!--<div
                      style="width:18px;text-align:center;line-height:18px;background:#fff;color:#fff;border:1px solid #dcdfe6;cursor: pointer;"
                    ></div>-->
                        <div
                          style="width:18px;text-align:center;line-height:18px;background:#67c23a;color:#fff;cursor: pointer;"
                        >
                          ✓
                        </div>
                        <!--<div
                      style="width:18px;text-align:center;line-height:18px;background:#f56c6c;color:#fff;cursor: pointer;"
                    >
                      ✕
                    </div>-->
                      </div>
                      <div class="col-remark">
                        {{ colItem.remark }}
                      </div>
                      <div>
                        <el-input
                          class="item-input"
                          v-model="inputVal1"
                          placeholder="请输入内容"
                        ></el-input>
                      </div>
                    </div>
                    <el-button
                      v-show="colItem.isSelect"
                      type="danger"
                      icon="el-icon-delete"
                      circle
                      style="position:absolute;bottom: -8px;right:0px;width: 20px;height: 20px;padding:3px;z-index:999;"
                      @click.stop="delItem('0', i, k, null, null)"
                    ></el-button>
                  </div>
                  <div v-else style="position:relative;">
                    <div>
                      <div class="group-title">
                        <div
                          v-layoutdrag="{
                            belongDiv: 'groupTitleDiv',
                            setMoveBlock: setMoveBlock,
                            initMoveBlock: initMoveBlock,
                            getInitMoveBlock: getInitMoveBlock,
                            getScrollDistance: getScrollDistance,
                            findAppropriatePosition: findAppropriatePosition,
                            setAppropriatePosition: setAppropriatePosition,
                            itemClick: itemClick,
                            uniqueId: colItem.uniqueId,
                            colType: 'firstCol'
                          }"
                          style="cursor: move;line-height:30px;font-weight:bold;text-align:center;"
                          :id="colItem.uniqueId"
                        >
                          {{ colItem.label }}
                        </div>
                      </div>
                      <div class="group-item">
                        <el-row
                          :gutter="5"
                          v-for="(child, j) in colItem.children"
                          :key="child.uniqueId"
                        >
                          <div
                            :ref="'body_row_' + child.uniqueId"
                            class="test-item-row-div"
                          >
                            <el-col
                              :span="childCol.span"
                              v-for="(childCol, m) in child.cols"
                              :key="childCol.uniqueId"
                            >
                              <div style="position:relative;">
                                <div
                                  style="background:#f4f6fc;"
                                  :ref="'body_col_' + childCol.uniqueId"
                                  @click="
                                    itemClick(childCol.uniqueId, 'secondCol')
                                  "
                                  :class="[
                                    childCol.isSelect ? 'selected-item' : ''
                                  ]"
                                >
                                  <div class="col-title">
                                    <div
                                      v-layoutdrag="{
                                        belongDiv: 'groupItemTitleDiv',
                                        setMoveBlock: setMoveBlock,
                                        initMoveBlock: initMoveBlock,
                                        getInitMoveBlock: getInitMoveBlock,
                                        getScrollDistance: getScrollDistance,
                                        findAppropriatePosition: findAppropriatePosition,
                                        setAppropriatePosition: setAppropriatePosition,
                                        itemClick: itemClick,
                                        uniqueId: childCol.uniqueId,
                                        colType: 'secondCol'
                                      }"
                                      style="cursor: move;width:calc(100% - 18px)"
                                      :title="childCol.label"
                                      :id="childCol.uniqueId"
                                    >
                                      {{ childCol.label }}
                                    </div>
                                    <!--<div
                      style="width:18px;text-align:center;line-height:18px;background:#fff;color:#fff;border:1px solid #dcdfe6;cursor: pointer;"
                    ></div>-->
                                    <div
                                      style="width:18px;text-align:center;line-height:18px;background:#67c23a;color:#fff;cursor: pointer;"
                                    >
                                      ✓
                                    </div>
                                    <!--<div
                      style="width:18px;text-align:center;line-height:18px;background:#f56c6c;color:#fff;cursor: pointer;"
                    >
                      ✕
                    </div>-->
                                  </div>
                                  <div>
                                    <el-input
                                      class="item-input"
                                      v-model="inputVal"
                                      placeholder="请输入内容"
                                    ></el-input>
                                  </div>
                                </div>
                                <el-button
                                  v-show="childCol.isSelect"
                                  type="danger"
                                  icon="el-icon-delete"
                                  circle
                                  style="position:absolute;bottom: -8px;right:0px;width: 20px;height: 20px;padding:3px;z-index:999;"
                                  @click.stop="delItem('1', i, k, j, m)"
                                ></el-button>
                              </div>
                            </el-col>
                          </div>
                        </el-row>
                      </div>
                    </div>
                    <el-button
                      v-show="colItem.isSelect"
                      type="danger"
                      icon="el-icon-delete"
                      circle
                      style="position:absolute;bottom: -8px;right:0px;width: 20px;height: 20px;padding:3px;z-index:999;"
                      @click.stop="delItem('2', i, k, null, null)"
                    ></el-button>
                  </div>
                </div>
              </el-col>
            </div>
          </el-row>
        </div>
      </div>
      <div class="test-item-main-right">
        <div class="test-item-main-right-header">
          字段属性
        </div>
        <div class="test-item-main-right-body">
          <div class="test-item-main-right-body-title">
            <span>标题:</span
            ><el-input
              v-model="itemTitle"
              placeholder="请输入内容"
              @input="titleChange"
            ></el-input>
          </div>
          <div class="test-item-main-right-body-width">
            <span>宽度:</span>
            <el-input-number
              v-model="widthNum"
              controls-position="right"
              @change="widthChange"
              :min="3"
              :max="24"
            ></el-input-number>
          </div>
        </div>
      </div>
    </div>
    <previewLayout
      :currshowlist.sync="showPreviewLayout"
      :layOutJson="layOutJson"
    />
  </div>
</template>
<style lang="scss" scoped>
.test-item-main {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.test-item-main {
  display: flex;
  justify-content: space-around;
  height: 100%;
}
.test-item-main-left {
  width: 17%;
  padding-left: 10px;
  padding-top: 30px;
}
.layout-field {
  height: 80px;
}
.item-field {
  height: calc(100% - 80px);
}
.field-title {
  font-size: 13px;
  height: 30px;
  line-height: 30px;
}
.field-label {
  width: 120px;
  font-size: 12px;
  height: 29px;
  line-height: 29px;
  cursor: move;
  background: #f4f6fc;
  border: 1px solid #f4f6fc;
}
.field-label:hover {
  border: 1px dashed #409eff;
}
.item-field-table {
  height: calc(100% - 30px);
}
.item-field-div {
  display: flex;
  height: 29px;
  line-height: 29px;
  font-size: 12px;
}
.item-field-label-div {
  margin-left: 3px;
  cursor: move;
  background: #f4f6fc;
  border: 1px solid #f4f6fc;
}
.item-field-label-div:hover {
  border: 1px dashed #409eff;
}
.test-item-main-middle {
  width: 67%;
  padding-top: 24px;
  border-left: 1px solid #e0e0e0;
  border-right: 1px solid #e0e0e0;
}
.test-item-main-middle-header {
  height: 36px;
  border-bottom: 1px solid #e0e0e0;
  text-align: right;
  padding: 0px 20px;
}
.test-item-main-middle-body {
  height: calc(100% - 36px);
  padding: 0px 3px;
  overflow: auto;
}
.test-item-row-div {
  min-height: 60px;
}
.col-title {
  display: flex;
  justify-content: space-between;
  height: 18px;
  text-align: center;
}
.col-title >>> div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.test-item-main-right {
  width: 14%;
  padding-top: 24px;
}
.test-item-main-right-header {
  height: 36px;
  border-bottom: 1px solid #e0e0e0;
  text-align: center;
  line-height: 36px;
  font-size: 15px;
}
.test-item-main-right-body {
}
.test-item-main-right-body >>> span {
  width: 40px;
  font-size: 13px;
  line-height: 32px;
}
.test-item-main-right-body >>> .el-input {
  width: calc(100% - 40px);
}
.test-item-main-right-body-title {
  display: flex;
  margin-top: 10px;
}
.test-item-main-right-body-width {
  display: flex;
  margin-top: 10px;
}
.group-title {
  height: 30px;
}
.group-item {
  border: 1px dashed #ccc;
}
.col-remark {
  border-top: 1px solid #ccc;
  height: 16px;
  font-size: 12px;
  text-align: center;
}
.item-input >>> input {
  height: 28px;
}
.selected-item {
  background: yellow !important;
}
</style>
<script>
import previewLayout from '@/views/quality/testitemlayout/preview-layout.vue'
import { getElPosition } from '@/util/plugin/dragAndDropFunc.js'
export default {
  components: {
    previewLayout
  },
  data() {
    return {
      checked: false,
      checkItems: [
        {
          id: 1,
          name: '铜带绕包—绝缘屏蔽线芯标称外径(陆缆)1',
          remark: '要求范围:0.3-0.5',
          itemNo: '1'
        },
        {
          id: 2,
          name: '铜带绕包—绝缘屏蔽线芯标称外径(陆缆)2',
          remark: '要求范围:0.3-0.5',
          itemNo: '2'
        },
        {
          id: 3,
          name: '铜带绕包—绝缘屏蔽线芯标称外径(陆缆)3',
          remark: '要求范围:0.3-0.5',
          itemNo: '3'
        },
        {
          id: 4,
          name: '铜带绕包—绝缘屏蔽线芯标称外径(陆缆)4',
          remark: '要求范围:0.3-0.5',
          itemNo: '4'
        },
        {
          id: 5,
          name: '铜带绕包—绝缘屏蔽线芯标称外径(陆缆)5',
          remark: '要求范围:0.3-0.5',
          itemNo: '5'
        },
        {
          id: 6,
          name: '铜带绕包—绝缘屏蔽线芯标称外径(陆缆)6',
          remark: '要求范围:0.3-0.5',
          itemNo: '6'
        },
        { id: 7, name: '长度', remark: '要求范围:0.3-0.5', itemNo: '7' },
        { id: 8, name: '半径', remark: '要求范围:0.3-0.5', itemNo: '8' },
        { id: 9, name: '高度', remark: '要求范围:0.3-0.5', itemNo: '9' },
        { id: 10, name: '直径', remark: '要求范围:0.3-0.5', itemNo: '10' }
      ],
      hasLayOutCheckItems: [],
      layOutItems: [],
      lastRowRef: null,
      lastColRef: null,
      inputVal: '',
      inputVal1: '',
      widthNum: 3,
      itemTitle: null,
      currUniqueId: null,
      currColType: null,
      currClickItem: null,
      layOutJson: [],
      showPreviewLayout: false
    }
  },
  directives: {
    layoutdrag: {
      bind: function(el, binding, vnode) {
        el.onmousedown = (e) => {
          // 获取鼠标点击元素的文本内容
          const elContent = el.innerText
          // 获取鼠标点击元素的id,不同的belongDiv,对应的id组成不一样
          const elId = el.id
          // 是否允许拖动标识
          let permitDrag = true
          // 当前元素相对整个页面(除浏览器头部的位置)
          const eleX = getElPosition(el).left
          const eleY = getElPosition(el).top
          // 鼠标点击元素所属的table
          const belongDiv = binding.value.belongDiv
          // 所属table的滚动偏移量
          const scrollDistance = binding.value.getScrollDistance(belongDiv)
          // 鼠标相对整个页面(除浏览器头部的位置),是e.clientX、e.clientY
          // 鼠标与当前元素之间的位置差,是disX、disY
          const disX = e.clientX - (eleX - scrollDistance.scrollX)
          const disY = e.clientY - (eleY - scrollDistance.scrollY)
          // 获取可拖动模块DIV的原始位置相对于整个页面(除浏览器头部的位置)
          const moveBlock = binding.value.getInitMoveBlock()
          const moveBlockX = moveBlock.moveBlockX
          const moveBlockY = moveBlock.moveBlockY
          // 设定拖拽模块的位置,使拖拽模块的位置,定位到鼠标点击的元素位置。(拖拽模块的top、left属性,是相对于最近一个父亲定位元素的距离)
          binding.value.setMoveBlock(
            eleX - moveBlockX - scrollDistance.scrollX,
            eleY - moveBlockY - scrollDistance.scrollY,
            elContent,
            el.offsetWidth,
            el.offsetHeight,
            'move'
          )
          if (
            belongDiv === 'itemTitleDiv' ||
            belongDiv === 'groupTitleDiv' ||
            belongDiv === 'groupItemTitleDiv'
          ) {
            const uniqueId = binding.value.uniqueId
            const colType = binding.value.colType
            binding.value.itemClick(uniqueId, colType)
          }
          document.onmousemove = (e) => {
            if (permitDrag) {
              // 用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
              const event = e || window.event
 
              let left = event.clientX - disX
              let top = event.clientY - disY
              // 限制左边距
              if (left <= moveBlockX) {
                left = moveBlockX
              }
              // 限制上边距
              if (top < moveBlockY) {
                top = moveBlockY
              }
              // 限制右边距
              if (left > document.body.offsetWidth - el.offsetWidth) {
                left = document.body.offsetWidth - el.offsetWidth
              }
              // 限制下边距
              if (top > document.body.offsetHeight - el.offsetHeight) {
                top = document.body.offsetHeight - el.offsetHeight
              }
              // 鼠标移动过程中,实时改变拖拽模块的位置,实现拖动效果。(拖拽模块的top、left属性,是相对于最近一个父亲定位元素的距离)
              binding.value.setMoveBlock(
                left - moveBlockX,
                top - moveBlockY,
                elContent,
                null,
                null,
                null
              )
              // 寻找符合要求的检测项位置,即是拿当前鼠标光标的位置跟布局div中的检测项位置进行匹配。(此处是用鼠标光标的位置去对比匹配,而不是拖拽模块的位置)
              binding.value.findAppropriatePosition(
                event.clientX,
                event.clientY,
                belongDiv
              )
            }
          }
          document.onmouseup = (e) => {
            if (permitDrag) {
              const event = e || window.event
              // 鼠标放开后,进行布局
              binding.value.setAppropriatePosition(
                event.clientX,
                event.clientY,
                elId,
                belongDiv
              )
              // 布局完成后,对拖拽模块进行初始化,使其回到默认初始位置
              binding.value.initMoveBlock()
              permitDrag = false
              document.onmousemove = null
              document.onmouseup = null
            }
          }
        }
      }
    }
  },
  created() {
    const currTime = new Date().getTime()
    // const currTime1 = new Date().getTime()
    // const currTime2 = new Date().getTime()
    const layOutItem = {
      id: null,
      label: '',
      uniqueId: currTime,
      minHeight: 60,
      cols: [
        /*      {
          id: null,
          uniqueId: currTime1,
          label: '分组',
          span: 24,
          type: 'group',
          children: [
            {
              id: null,
              label: '',
              uniqueId: currTime,
              cols: [
                {
                  id: null,
                  uniqueId: currTime2,
                  label: '',
                  span: 4
                }
              ]
            }
          ]
        } */
      ]
    }
    this.layOutItems.push(layOutItem)
  },
  methods: {
    // 获取div滚动偏移量,div出现滚动条时,滚动条滚动之后会有位置偏移,滚动条不滚动,偏移为0,无滚动条时,偏移为0
    getScrollDistance(belongDiv) {
      // 若belongDiv为itemTitleDiv groupTitleDiv groupItemTitleDiv layOutContentDiv,则都以layOutContentDiv来计算
      let scrollPosition
      if (
        belongDiv === 'itemTitleDiv' ||
        belongDiv === 'groupTitleDiv' ||
        belongDiv === 'groupItemTitleDiv' ||
        belongDiv === 'layOutContentDiv'
      ) {
        scrollPosition = {
          scrollX: this.$refs.layOutContentDiv.scrollLeft,
          scrollY: this.$refs.layOutContentDiv.scrollTop
        }
      } else if (belongDiv === 'groupLayOutDiv') {
        scrollPosition = {
          scrollX: this.$refs.groupLayOutDiv.scrollLeft,
          scrollY: this.$refs.groupLayOutDiv.scrollTop
        }
      } else if (belongDiv === 'itemLayOutDiv') {
        scrollPosition = {
          scrollX: this.$refs.itemLayOutDiv.scrollLeft,
          scrollY: this.$refs.itemLayOutDiv.scrollTop
        }
      }
      return scrollPosition
    },
    // 初始化可拖动块的样式
    initMoveBlock() {
      this.$refs.moveBlock.style.top = '0px'
      this.$refs.moveBlock.style.left = '0px'
      this.$refs.moveBlock.style.width = '0px'
      this.$refs.moveBlock.style.height = '0px'
      this.$refs.moveBlock.style.lineHeight = '0px'
      this.$refs.moveBlock.style.border = '0px dashed #409eff'
      this.$refs.moveBlock.innerText = ''
      this.$refs.moveBlock.style.cursor = ''
    },
    // 获取可拖动块,相对于整个页面(除浏览器头部坐标)
    getInitMoveBlock() {
      return {
        moveBlockX: getElPosition(this.$refs.moveBlock).left,
        moveBlockY: getElPosition(this.$refs.moveBlock).top
      }
    },
    // 设置可拖动块的样式
    setMoveBlock(x, y, content, width, height, cursor) {
      this.$refs.moveBlock.style.top = y + 'px'
      this.$refs.moveBlock.style.left = x + 'px'
      this.$refs.moveBlock.innerText = content
      this.$refs.moveBlock.style.border = '1px dashed #409eff'
      if (width != null) {
        this.$refs.moveBlock.style.width = width + 'px'
      }
      if (height != null) {
        this.$refs.moveBlock.style.height = height + 'px'
        this.$refs.moveBlock.style.lineHeight = height + 'px'
      }
      if (cursor != null) {
        this.$refs.moveBlock.style.cursor = cursor
      }
    },
    // 先对行进行循环,再对行中的列进行循环。布局字段分组只能放在空行中,检测项字段无此限制。
    findAppropriatePosition(x, y, belongDiv) {
      let layOutItem
      let rowRef
      let elposition
      if (this.lastRowRef != null && this.$refs[this.lastRowRef].length > 0) {
        this.$refs[this.lastRowRef][0].style.borderLeft = '0px solid #409eff'
      }
      if (this.lastColRef != null && this.$refs[this.lastColRef].length > 0) {
        this.$refs[this.lastColRef][0].style.borderRight = '0px solid #409eff'
      }
 
      // 获取layOutContentDiv滚动偏移量,layOutContentDiv出现滚动条时,滚动条滚动之后会有位置偏移,滚动条不滚动,偏移为0,无滚动条时,偏移为0
      const personArrangeTableScrollPosition = this.getScrollDistance(
        'layOutContentDiv'
      )
      // 布局字段分组的拖拽
      if (belongDiv === 'groupLayOutDiv') {
        for (let k = 0; k < this.layOutItems.length; k++) {
          layOutItem = this.layOutItems[k]
          rowRef = 'body_row_' + layOutItem.uniqueId
          elposition = getElPosition(this.$refs[rowRef][0])
          if (
            x > elposition.left - personArrangeTableScrollPosition.scrollX &&
            x <
              elposition.left -
                personArrangeTableScrollPosition.scrollX +
                this.$refs[rowRef][0].offsetWidth &&
            y > elposition.top - personArrangeTableScrollPosition.scrollY &&
            y <
              elposition.top -
                personArrangeTableScrollPosition.scrollY +
                this.$refs[rowRef][0].offsetHeight
          ) {
            if (layOutItem.cols.length <= 0) {
              this.$refs[rowRef][0].style.borderLeft = '3px solid #409eff'
            }
            this.lastRowRef = rowRef
            break
          }
        }
      } else {
        for (let k = 0; k < this.layOutItems.length; k++) {
          layOutItem = this.layOutItems[k]
          rowRef = 'body_row_' + layOutItem.uniqueId
          elposition = getElPosition(this.$refs[rowRef][0])
          if (
            x > elposition.left - personArrangeTableScrollPosition.scrollX &&
            x <
              elposition.left -
                personArrangeTableScrollPosition.scrollX +
                this.$refs[rowRef][0].offsetWidth &&
            y > elposition.top - personArrangeTableScrollPosition.scrollY &&
            y <
              elposition.top -
                personArrangeTableScrollPosition.scrollY +
                this.$refs[rowRef][0].offsetHeight
          ) {
            if (layOutItem.cols.length > 0) {
              // 判断是否拖拽进分组控件,若是拖拽至分组控件,则需按分组的数据结构进行查找,通过第一层的cols中的type对象进行判断,group为分组控件、item为普通列
              const cols = layOutItem.cols
              let colRef
              const col = cols[0]
              if (col.type === 'group') {
                // 分组控件中的行
                const groupRows = col.children
                let groupRow
                for (let i = 0; i < groupRows.length; i++) {
                  groupRow = groupRows[i]
                  rowRef = 'body_row_' + groupRow.uniqueId
                  elposition = getElPosition(this.$refs[rowRef][0])
                  if (
                    x >
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX &&
                    x <
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX +
                        this.$refs[rowRef][0].offsetWidth &&
                    y >
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY &&
                    y <
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY +
                        this.$refs[rowRef][0].offsetHeight
                  ) {
                    // 判断分组中的行,是否已存在检测项列
                    if (groupRow.cols.length > 0) {
                      const groupCols = groupRow.cols
                      let groupCol
                      for (let j = 0; j < groupCols.length; j++) {
                        colRef = 'body_col_' + groupCols[j].uniqueId
                        elposition = getElPosition(this.$refs[colRef][0])
                        if (
                          x >
                            elposition.left -
                              personArrangeTableScrollPosition.scrollX &&
                          x <
                            elposition.left -
                              personArrangeTableScrollPosition.scrollX +
                              this.$refs[colRef][0].offsetWidth &&
                          y >
                            elposition.top -
                              personArrangeTableScrollPosition.scrollY &&
                          y <
                            elposition.top -
                              personArrangeTableScrollPosition.scrollY +
                              this.$refs[colRef][0].offsetHeight
                        ) {
                          this.$refs[colRef][0].style.borderRight =
                            '3px solid #409eff'
                          this.lastColRef = colRef
                        }
                      }
                    } else {
                      this.$refs[rowRef][0].style.borderLeft =
                        '3px solid #409eff'
                    }
                    this.lastRowRef = rowRef
                    break
                  }
                }
              } else {
                for (let i = 0; i < cols.length; i++) {
                  colRef = 'body_col_' + cols[i].uniqueId
                  elposition = getElPosition(this.$refs[colRef][0])
                  if (
                    x >
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX &&
                    x <
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX +
                        this.$refs[colRef][0].offsetWidth &&
                    y >
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY &&
                    y <
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY +
                        this.$refs[colRef][0].offsetHeight
                  ) {
                    this.$refs[colRef][0].style.borderRight =
                      '3px solid #409eff'
                    this.lastColRef = colRef
                  }
                }
              }
            } else {
              this.$refs[rowRef][0].style.borderLeft = '3px solid #409eff'
            }
            this.lastRowRef = rowRef
            break
          }
        }
      }
    },
    // 鼠标键松开弹起时,判断鼠标光标的位置,根据鼠标光标位置,进行布局
    // 分情况进行布局,若是拖拽元素来自于itemLayOutDiv、groupLayOutDiv,则进行普通布局,即往layOutItems插入新增数据
    // 若是拖拽元素来自于itemTitleDiv、groupTitleDiv、groupItemTitleDiv,则进行位置调整布局,即将layOutItems中的元素进行位置的调整。
    // 根据uniqueId查询拖拽元素,并进行位置调整
    setAppropriatePosition(x, y, elId, belongDiv) {
      if (belongDiv === 'itemLayOutDiv' || belongDiv === 'groupLayOutDiv') {
        this.generalLayout(x, y, elId, belongDiv)
      } else {
        this.positionAdjustmentLayout(x, y, elId, belongDiv)
      }
    },
    // 普通布局
    generalLayout(x, y, elId, belongDiv) {
      let layOutItem
      let rowRef
      let elposition
      const checkItem = this.checkItems.find((item) => {
        return item.id == elId
      })
 
      // 获取layOutContentDiv滚动偏移量,layOutContentDiv出现滚动条时,滚动条滚动之后会有位置偏移,滚动条不滚动,偏移为0,无滚动条时,偏移为0
      const personArrangeTableScrollPosition = this.getScrollDistance(
        'layOutContentDiv'
      )
      // 布局字段分组的拖拽定位
      if (belongDiv === 'groupLayOutDiv') {
        for (let k = 0; k < this.layOutItems.length; k++) {
          layOutItem = this.layOutItems[k]
          rowRef = 'body_row_' + layOutItem.uniqueId
          elposition = getElPosition(this.$refs[rowRef][0])
 
          if (
            x > elposition.left - personArrangeTableScrollPosition.scrollX &&
            x <
              elposition.left -
                personArrangeTableScrollPosition.scrollX +
                this.$refs[rowRef][0].offsetWidth &&
            y > elposition.top - personArrangeTableScrollPosition.scrollY &&
            y <
              elposition.top -
                personArrangeTableScrollPosition.scrollY +
                this.$refs[rowRef][0].offsetHeight
          ) {
            const cols = layOutItem.cols
            if (cols.length <= 0) {
              // 当前行 为空行,往里面直接插入分组,并且新增一行
              const groupUniqueId = new Date().getTime()
              layOutItem.minHeight = 100
              cols.push({
                id: null,
                uniqueId: groupUniqueId,
                label: '分组',
                span: 24,
                isSelect: false,
                type: 'group',
                children: [
                  {
                    id: null,
                    label: '',
                    uniqueId: groupUniqueId + 1,
                    cols: []
                  }
                ]
              })
              const layOut = {
                id: null,
                label: '',
                uniqueId: groupUniqueId + 2,
                minHeight: 60,
                cols: []
              }
              this.layOutItems.push(layOut)
            }
            break
          }
        }
      } else {
        for (let k = 0; k < this.layOutItems.length; k++) {
          layOutItem = this.layOutItems[k]
          rowRef = 'body_row_' + layOutItem.uniqueId
          elposition = getElPosition(this.$refs[rowRef][0])
          if (
            x > elposition.left - personArrangeTableScrollPosition.scrollX &&
            x <
              elposition.left -
                personArrangeTableScrollPosition.scrollX +
                this.$refs[rowRef][0].offsetWidth &&
            y > elposition.top - personArrangeTableScrollPosition.scrollY &&
            y <
              elposition.top -
                personArrangeTableScrollPosition.scrollY +
                this.$refs[rowRef][0].offsetHeight
          ) {
            const cols = layOutItem.cols
            if (cols.length > 0) {
              let colRef
              // 判断是否拖拽进分组控件,若是拖拽至分组控件,则需按分组的数据结构进行项增加,通过第一层的cols中的type对象进行判断,group为分组控件、item为普通列
              const col = cols[0]
              if (col.type === 'group') {
                // 分组控件中的行
                const groupRows = col.children
                let groupRow
                for (let i = 0; i < groupRows.length; i++) {
                  groupRow = groupRows[i]
                  rowRef = 'body_row_' + groupRow.uniqueId
                  elposition = getElPosition(this.$refs[rowRef][0])
                  if (
                    x >
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX &&
                    x <
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX +
                        this.$refs[rowRef][0].offsetWidth &&
                    y >
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY &&
                    y <
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY +
                        this.$refs[rowRef][0].offsetHeight
                  ) {
                    // 判断分组中的行,是否已存在检测项列
                    if (groupRow.cols.length > 0) {
                      const groupCols = groupRow.cols
                      for (let j = 0; j < groupCols.length; j++) {
                        colRef = 'body_col_' + groupCols[j].uniqueId
                        elposition = getElPosition(this.$refs[colRef][0])
                        if (
                          x >
                            elposition.left -
                              personArrangeTableScrollPosition.scrollX &&
                          x <
                            elposition.left -
                              personArrangeTableScrollPosition.scrollX +
                              this.$refs[colRef][0].offsetWidth &&
                          y >
                            elposition.top -
                              personArrangeTableScrollPosition.scrollY &&
                          y <
                            elposition.top -
                              personArrangeTableScrollPosition.scrollY +
                              this.$refs[colRef][0].offsetHeight
                        ) {
                          // 删除checkItems中的checkItem,复制到hasLayOutCheckItems中
                          this.hasLayOutCheckItems.push(checkItem)
                          const checkItemIndex = this.checkItems.indexOf(
                            checkItem
                          )
                          this.checkItems.splice(checkItemIndex, 1)
                          // 在此检测项后面,新增检测项
                          const colUniqueId = new Date().getTime()
                          groupCols.splice(j + 1, 0, {
                            id: null,
                            uniqueId: colUniqueId,
                            label: checkItem.name,
                            type: '',
                            remark: checkItem.remark,
                            span: 4,
                            isSelect: false,
                            itemNo: checkItem.itemNo
                          })
                          break
                        }
                      }
                    } else {
                      // 删除checkItems中的checkItem,复制到hasLayOutCheckItems中
                      this.hasLayOutCheckItems.push(checkItem)
                      const checkItemIndex = this.checkItems.indexOf(checkItem)
                      this.checkItems.splice(checkItemIndex, 1)
                      // 当前行 为空行,往里面直接插入检测项,并且新增一行
                      const colUniqueId = new Date().getTime()
                      layOutItem.minHeight = layOutItem.minHeight + 60
                      groupRow.cols.push({
                        id: null,
                        uniqueId: colUniqueId,
                        label: checkItem.name,
                        type: '',
                        remark: checkItem.remark,
                        span: 4,
                        isSelect: false,
                        itemNo: checkItem.itemNo
                      })
 
                      groupRows.push({
                        id: null,
                        label: '',
                        uniqueId: colUniqueId + 1,
                        cols: []
                      })
                    }
                    break
                  }
                }
              } else {
                for (let i = 0; i < cols.length; i++) {
                  colRef = 'body_col_' + cols[i].uniqueId
                  elposition = getElPosition(this.$refs[colRef][0])
                  if (
                    x >
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX &&
                    x <
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX +
                        this.$refs[colRef][0].offsetWidth &&
                    y >
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY &&
                    y <
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY +
                        this.$refs[colRef][0].offsetHeight
                  ) {
                    // 删除checkItems中的checkItem,复制到hasLayOutCheckItems中
                    this.hasLayOutCheckItems.push(checkItem)
                    const checkItemIndex = this.checkItems.indexOf(checkItem)
                    this.checkItems.splice(checkItemIndex, 1)
                    // 在此检测项后面,新增检测项
                    const colUniqueId = new Date().getTime()
                    cols.splice(i + 1, 0, {
                      id: null,
                      uniqueId: colUniqueId,
                      label: checkItem.name,
                      type: 'item',
                      remark: checkItem.remark,
                      span: 4,
                      isSelect: false,
                      itemNo: checkItem.itemNo
                    })
                    break
                  }
                }
              }
            } else {
              // 删除checkItems中的checkItem,复制到hasLayOutCheckItems中
              this.hasLayOutCheckItems.push(checkItem)
              const checkItemIndex = this.checkItems.indexOf(checkItem)
              this.checkItems.splice(checkItemIndex, 1)
              // 当前行 为空行,往里面直接插入检测项,并且新增一行
              const colUniqueId = new Date().getTime()
              cols.push({
                id: null,
                uniqueId: colUniqueId,
                label: checkItem.name,
                type: 'item',
                remark: checkItem.remark,
                span: 4,
                isSelect: false,
                itemNo: checkItem.itemNo
              })
 
              const layOut = {
                id: null,
                label: '',
                uniqueId: colUniqueId + 1,
                minHeight: 60,
                cols: []
              }
              this.layOutItems.push(layOut)
            }
            break
          }
        }
      }
    },
    // 位置调整布局
    positionAdjustmentLayout(x, y, elId, belongDiv) {
      // x、y为鼠标的光标位置
      // 参数中belongDiv值有两种:itemTitleDiv、groupTitleDiv、groupItemTitleDiv
      // elId是拖拽元素的uniqueId,即为layOutItems中的uniqueId
      let layOutItem
      let rowRef
      let elposition
 
      // 获取layOutContentDiv滚动偏移量,layOutContentDiv出现滚动条时,滚动条滚动之后会有位置偏移,滚动条不滚动,偏移为0,无滚动条时,偏移为0
      const personArrangeTableScrollPosition = this.getScrollDistance(
        'layOutContentDiv'
      )
      // 当前拖拽的项,分两种情况去检索,itemTitleDiv、groupTitleDiv一组,groupItemTitleDiv一组
      // 检索出currItem
      const currItem = this.getCurrItem(belongDiv, elId)
      // 拖拽项为groupTitleDiv时,groupTitleDiv是分组,不能被拖拽至另一个分组,且必须占一行。若被拖拽至的行已有项,则放入下一行(新增行),若被拖拽至的行是空行,则直接放入该行
      if (belongDiv === 'groupTitleDiv') {
        for (let k = 0; k < this.layOutItems.length; k++) {
          layOutItem = this.layOutItems[k]
          rowRef = 'body_row_' + layOutItem.uniqueId
          elposition = getElPosition(this.$refs[rowRef][0])
          if (
            x > elposition.left - personArrangeTableScrollPosition.scrollX &&
            x <
              elposition.left -
                personArrangeTableScrollPosition.scrollX +
                this.$refs[rowRef][0].offsetWidth &&
            y > elposition.top - personArrangeTableScrollPosition.scrollY &&
            y <
              elposition.top -
                personArrangeTableScrollPosition.scrollY +
                this.$refs[rowRef][0].offsetHeight
          ) {
            // 删除原有行
            let rowNum
            rowNum = this.getRowNum(currItem, belongDiv)
            if (rowNum !== k) {
              this.layOutItems.splice(rowNum, 1)
              const cols = layOutItem.cols
              if (cols.length <= 0) {
                // 被拖拽至的行是空行,则直接放入该行,并且新增一行
                const groupUniqueId = new Date().getTime()
                layOutItem.minHeight = 40 + currItem.children.length * 60
                cols.push(currItem)
                const layOut = {
                  id: null,
                  label: '',
                  uniqueId: groupUniqueId,
                  minHeight: 60,
                  cols: []
                }
                this.layOutItems.push(layOut)
              } else {
                // 被拖拽至的行已有项,则放入下一行(新增行)
                const groupUniqueId = new Date().getTime()
                rowNum = this.layOutItems.indexOf(layOutItem)
                this.layOutItems.splice(rowNum + 1, 0, {
                  id: null,
                  label: '',
                  uniqueId: groupUniqueId,
                  minHeight: 40 + currItem.children.length * 60,
                  cols: [currItem]
                })
              }
            }
            break
          }
        }
      } else {
        // 拖拽项为itemTitleDiv、groupItemTitleDiv时,若被拖拽至的行已有项,则插入在该项后,若被拖拽至的行是空行,则直接放入该行
        for (let k = 0; k < this.layOutItems.length; k++) {
          layOutItem = this.layOutItems[k]
          rowRef = 'body_row_' + layOutItem.uniqueId
          elposition = getElPosition(this.$refs[rowRef][0])
          if (
            x > elposition.left - personArrangeTableScrollPosition.scrollX &&
            x <
              elposition.left -
                personArrangeTableScrollPosition.scrollX +
                this.$refs[rowRef][0].offsetWidth &&
            y > elposition.top - personArrangeTableScrollPosition.scrollY &&
            y <
              elposition.top -
                personArrangeTableScrollPosition.scrollY +
                this.$refs[rowRef][0].offsetHeight
          ) {
            const cols = layOutItem.cols
            if (cols.length > 0) {
              let colRef
              // 判断是否拖拽进分组控件,若是拖拽至分组控件,则需按分组的数据结构进行项增加,通过第一层的cols中的type对象进行判断,group为分组控件、item为普通列
              const col = cols[0]
              if (col.type === 'group') {
                // 分组控件中的行
                const groupRows = col.children
                let groupRow
                for (let i = 0; i < groupRows.length; i++) {
                  groupRow = groupRows[i]
                  rowRef = 'body_row_' + groupRow.uniqueId
                  elposition = getElPosition(this.$refs[rowRef][0])
                  if (
                    x >
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX &&
                    x <
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX +
                        this.$refs[rowRef][0].offsetWidth &&
                    y >
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY &&
                    y <
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY +
                        this.$refs[rowRef][0].offsetHeight
                  ) {
                    // 判断分组中的行,是否已存在检测项列
                    if (groupRow.cols.length > 0) {
                      const groupCols = groupRow.cols
                      let groupCol
                      for (let j = 0; j < groupCols.length; j++) {
                        groupCol = groupCols[j]
                        colRef = 'body_col_' + groupCols[j].uniqueId
                        elposition = getElPosition(this.$refs[colRef][0])
                        if (
                          x >
                            elposition.left -
                              personArrangeTableScrollPosition.scrollX &&
                          x <
                            elposition.left -
                              personArrangeTableScrollPosition.scrollX +
                              this.$refs[colRef][0].offsetWidth &&
                          y >
                            elposition.top -
                              personArrangeTableScrollPosition.scrollY &&
                          y <
                            elposition.top -
                              personArrangeTableScrollPosition.scrollY +
                              this.$refs[colRef][0].offsetHeight
                        ) {
                          // 删除拖拽的项,若有必要,需删除所属行,分两种类型itemTitleDiv、groupItemTitleDiv,itemTitleDiv为layOutItems外层的col项,groupItemTitleDiv为layOutItems内层的col项
                          const currRowInfo = this.getRow(belongDiv, elId)
                          const currRow = currRowInfo.currRow
                          const rowNum = this.layOutItems.indexOf(currRow)
                          if (belongDiv === 'itemTitleDiv') {
                            if (currRow.cols.length === 1) {
                              // 项所属行内只有该项,则直接删除该行
                              this.layOutItems.splice(rowNum, 1)
                            } else {
                              const currItemNum = currRow.cols.indexOf(currItem)
                              currRow.cols.splice(currItemNum, 1)
                            }
                            // 在此检测项后面,新增检测项
                            currItem.type = ''
                            groupCols.splice(j + 1, 0, currItem)
                          } else {
                            const currChild = currRowInfo.currChild
                            const children = this.layOutItems[rowNum].cols[0]
                              .children
                            const childNum = children.indexOf(currChild)
                            if (children.length > 1) {
                              // 判断项是否是分组内,还是不同分组
                              if (rowNum === k) {
                                // 项在分组内
                                // 项属于分组行,判断是否是分组内跨行拖拽
                                if (i !== childNum) {
                                  // 跨行拖拽,项属于分组行,且有多行,若行内只有该项,则直接删除该行,若有多项,则直接删除该项
                                  if (currChild.cols.length === 1) {
                                    children.splice(childNum, 1)
                                    currRow.minHeight = currRow.minHeight - 60
                                  } else {
                                    const currItemNum = currChild.cols.indexOf(
                                      currItem
                                    )
                                    currChild.cols.splice(currItemNum, 1)
                                  }
                                  // 在此检测项后面,新增检测项
                                  groupCols.splice(j + 1, 0, currItem)
                                } else {
                                  // 行内拖拽,项属于分组行,且有多行,若拖拽项未拖动或者未拖动出自身范围,则不操作,若拖拽项拖拽至其他项目范围,则删除该项
                                  const currItemNum = currChild.cols.indexOf(
                                    currItem
                                  )
                                  if (j !== currItemNum) {
                                    currChild.cols.splice(currItemNum, 1)
                                    // 因删除了项,所以groupCols中项位置发生变化,需重新获取groupCol的位置
                                    const groupColNum = groupCols.indexOf(
                                      groupCol
                                    )
                                    groupCols.splice(
                                      groupColNum + 1,
                                      0,
                                      currItem
                                    )
                                  }
                                }
                              } else {
                                // 项在另一个分组
                                if (currChild.cols.length === 1) {
                                  children.splice(childNum, 1)
                                  currRow.minHeight = currRow.minHeight - 60
                                } else {
                                  const currItemNum = currChild.cols.indexOf(
                                    currItem
                                  )
                                  currChild.cols.splice(currItemNum, 1)
                                }
                                // 在此检测项后面,新增检测项
                                groupCols.splice(j + 1, 0, currItem)
                              }
                            }
                          }
                          break
                        }
                      }
                    } else {
                      // 删除拖拽的项,若有必要,需删除所属行,分两种类型itemTitleDiv、groupItemTitleDiv,itemTitleDiv为layOutItems外层的col项,groupItemTitleDiv为layOutItems内层的col项
                      const currRowInfo = this.getRow(belongDiv, elId)
                      const currRow = currRowInfo.currRow
                      const rowNum = this.layOutItems.indexOf(currRow)
                      if (belongDiv === 'itemTitleDiv') {
                        if (currRow.cols.length === 1) {
                          // 项所属行内只有该项,则直接删除该行
                          this.layOutItems.splice(rowNum, 1)
                        } else {
                          const currItemNum = currRow.cols.indexOf(currItem)
                          currRow.cols.splice(currItemNum, 1)
                        }
                      } else {
                        const currChild = currRowInfo.currChild
                        const children = this.layOutItems[rowNum].cols[0]
                          .children
                        if (children.length > 1) {
                          // 项属于分组行,且有多行,若行内只有该项,则直接删除该行,若有多项,则直接删除该项
                          if (currChild.cols.length === 1) {
                            const childNum = children.indexOf(currChild)
                            children.splice(childNum, 1)
                            currRow.minHeight = currRow.minHeight - 60
                          } else {
                            const currItemNum = currChild.cols.indexOf(currItem)
                            currChild.cols.splice(currItemNum, 1)
                          }
                        } else {
                          // 项属于分组行,且只有一行,行不能删除,只删除项
                          const currItemNum = currChild.cols.indexOf(currItem)
                          currChild.cols.splice(currItemNum, 1)
                        }
                      }
                      // 当前行 为空行,往里面直接插入检测项,并且新增一行
                      const colUniqueId = new Date().getTime()
                      layOutItem.minHeight = layOutItem.minHeight + 60
                      if (belongDiv === 'itemTitleDiv') {
                        currItem.type = ''
                      }
                      groupRow.cols.push(currItem)
 
                      groupRows.push({
                        id: null,
                        label: '',
                        uniqueId: colUniqueId,
                        cols: []
                      })
                    }
                    break
                  }
                }
              } else {
                let itemCol
                for (let i = 0; i < cols.length; i++) {
                  itemCol = cols[i]
                  colRef = 'body_col_' + cols[i].uniqueId
                  elposition = getElPosition(this.$refs[colRef][0])
                  if (
                    x >
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX &&
                    x <
                      elposition.left -
                        personArrangeTableScrollPosition.scrollX +
                        this.$refs[colRef][0].offsetWidth &&
                    y >
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY &&
                    y <
                      elposition.top -
                        personArrangeTableScrollPosition.scrollY +
                        this.$refs[colRef][0].offsetHeight
                  ) {
                    // 删除拖拽的项,若有必要,需删除所属行,分两种类型itemTitleDiv、groupItemTitleDiv,itemTitleDiv为layOutItems外层的col项,groupItemTitleDiv为layOutItems内层的col项
                    const currRowInfo = this.getRow(belongDiv, elId)
                    const currRow = currRowInfo.currRow
                    const rowNum = this.layOutItems.indexOf(currRow)
                    if (belongDiv === 'itemTitleDiv') {
                      // 需考虑拖拽是否跨行,
                      if (rowNum !== k) {
                        // 此时跨行,是跨行拖拽
                        if (currRow.cols.length === 1) {
                          // 项所属行内只有该项,则直接删除该行
                          this.layOutItems.splice(rowNum, 1)
                        } else {
                          // 项所属行内有多项,则直接删除该项
                          const currItemNum = currRow.cols.indexOf(currItem)
                          currRow.cols.splice(currItemNum, 1)
                        }
                        // 在此检测项后面,新增检测项
                        cols.splice(i + 1, 0, currItem)
                      } else {
                        // 此时未跨行,是行内拖拽
                        // 若拖拽项未拖动或者未拖动出自身范围,则不操作,若拖拽项拖拽至其他项目范围,则删除该项
                        const currItemNum = currRow.cols.indexOf(currItem)
                        if (i !== currItemNum) {
                          currRow.cols.splice(currItemNum, 1)
                          // 因删除了项,所以cols中项位置发生变化,需重新获取itemCol的位置
                          const itemColNum = cols.indexOf(itemCol)
                          cols.splice(itemColNum + 1, 0, currItem)
                        }
                      }
                    } else {
                      const currChild = currRowInfo.currChild
                      const children = this.layOutItems[rowNum].cols[0].children
                      if (children.length > 1) {
                        // 项属于分组行,且有多行,若行内只有该项,则直接删除该行,若有多项,则直接删除该项
                        if (currChild.cols.length === 1) {
                          const childNum = children.indexOf(currChild)
                          children.splice(childNum, 1)
                          currRow.minHeight = currRow.minHeight - 60
                        } else {
                          const currItemNum = currChild.cols.indexOf(currItem)
                          currChild.cols.splice(currItemNum, 1)
                        }
                      } else {
                        // 项属于分组行,且只有一行,行不能删除,只删除项
                        const currItemNum = currChild.cols.indexOf(currItem)
                        currChild.cols.splice(currItemNum, 1)
                      }
                      // 在此检测项后面,新增检测项
                      currItem.type = 'item'
                      cols.splice(i + 1, 0, currItem)
                    }
                    break
                  }
                }
              }
            } else {
              // 删除拖拽的项,若有必要,需删除所属行,分两种类型itemTitleDiv、groupItemTitleDiv,itemTitleDiv为layOutItems外层的col项,groupItemTitleDiv为layOutItems内层的col项
              const currRowInfo = this.getRow(belongDiv, elId)
              const currRow = currRowInfo.currRow
              const rowNum = this.layOutItems.indexOf(currRow)
              if (rowNum !== k) {
                if (belongDiv === 'itemTitleDiv') {
                  if (currRow.cols.length === 1) {
                    // 项所属行内只有该项,则直接删除该行
                    this.layOutItems.splice(rowNum, 1)
                  } else {
                    const currItemNum = currRow.cols.indexOf(currItem)
                    currRow.cols.splice(currItemNum, 1)
                  }
                } else {
                  const currChild = currRowInfo.currChild
                  const children = this.layOutItems[rowNum].cols[0].children
                  if (children.length > 1) {
                    // 项属于分组行,且有多行,若行内只有该项,则直接删除该行,若有多项,则直接删除该项
                    if (currChild.cols.length === 1) {
                      const childNum = children.indexOf(currChild)
                      children.splice(childNum, 1)
                      currRow.minHeight = currRow.minHeight - 60
                    } else {
                      const currItemNum = currChild.cols.indexOf(currItem)
                      currChild.cols.splice(currItemNum, 1)
                    }
                  } else {
                    // 项属于分组行,且只有一行,行不能删除,只删除项
                    const currItemNum = currChild.cols.indexOf(currItem)
                    currChild.cols.splice(currItemNum, 1)
                  }
                }
                // 当前行 为空行,往里面直接插入检测项,并且新增一行
                const colUniqueId = new Date().getTime()
                if (belongDiv === 'groupItemTitleDiv') {
                  currItem.type = 'item'
                }
                cols.push(currItem)
 
                const layOut = {
                  id: null,
                  label: '',
                  uniqueId: colUniqueId,
                  minHeight: 60,
                  cols: []
                }
                this.layOutItems.push(layOut)
              }
            }
            break
          }
        }
      }
    },
    // 获取当前项所属的行,itemTitleDiv、groupItemTitleDiv所属行的数据结构不一样,itemTitleDiv是外层行,groupItemTitleDiv是内层行
    getRow(belongDiv, elId) {
      let currItem
      let currRow
      let currChild
      if (belongDiv === 'itemTitleDiv') {
        let layOut
        for (let i = 0; i < this.layOutItems.length; i++) {
          layOut = this.layOutItems[i]
          currItem = layOut.cols.find((item) => {
            return item.uniqueId == elId
          })
          if (currItem) {
            currRow = layOut
            break
          }
        }
      } else {
        let layOut
        let childs
        let child
        let childItem
        for (let i = 0; i < this.layOutItems.length; i++) {
          layOut = this.layOutItems[i]
          if (layOut.cols.length > 0) {
            if (layOut.cols[0].children) {
              childs = layOut.cols[0].children
              for (let j = 0; j < childs.length; j++) {
                child = childs[j]
                childItem = child.cols.find((item) => {
                  return item.uniqueId == elId
                })
                if (childItem) {
                  currRow = layOut
                  currChild = child
                }
              }
            }
          }
        }
      }
      return { currRow: currRow, currChild: currChild }
    },
    // 获取当前项所属的行号
    getRowNum(currItem, belongDiv) {
      let rowNum
      if (belongDiv === 'groupTitleDiv') {
        let layOut
        let layOutCol
        for (let i = 0; i < this.layOutItems.length; i++) {
          layOut = this.layOutItems[i]
          layOutCol = layOut.cols.find((item) => {
            return item.uniqueId === currItem.uniqueId
          })
          if (layOutCol) {
            rowNum = i
            break
          }
        }
      }
      return rowNum
    },
    // 获取当前拖拽的项
    getCurrItem(belongDiv, elId) {
      let currItem
      if (belongDiv === 'itemTitleDiv' || belongDiv === 'groupTitleDiv') {
        let layOut
        for (let i = 0; i < this.layOutItems.length; i++) {
          layOut = this.layOutItems[i]
          currItem = layOut.cols.find((item) => {
            return item.uniqueId == elId
          })
          if (currItem) {
            break
          }
        }
      } else {
        let layOut
        let childs
        let child
        let childItem
        for (let i = 0; i < this.layOutItems.length; i++) {
          layOut = this.layOutItems[i]
          if (layOut.cols.length > 0) {
            if (layOut.cols[0].children) {
              childs = layOut.cols[0].children
              for (let j = 0; j < childs.length; j++) {
                child = childs[j]
                childItem = child.cols.find((item) => {
                  return item.uniqueId == elId
                })
                if (childItem) {
                  currItem = childItem
                }
              }
            }
          }
        }
      }
      return currItem
    },
    // 点击某个检测项或者分组,触发
    itemClick(uniqueId, colType) {
      this.currUniqueId = uniqueId
      this.currColType = colType
      if (this.currClickItem != null) {
        this.currClickItem.isSelect = false
        this.currClickItem = null
      }
      let clickItem
      if (colType === 'firstCol') {
        // 点击的是第一层的col项
        let layOutItem
        for (let i = 0; i < this.layOutItems.length; i++) {
          layOutItem = this.layOutItems[i]
          clickItem = layOutItem.cols.find((item) => {
            return item.uniqueId === uniqueId
          })
          if (clickItem) {
            this.currClickItem = clickItem
            break
          }
        }
      } else {
        // 点击的是第二层的col项
        let layOutItem
        let childs
        let child
        for (let i = 0; i < this.layOutItems.length; i++) {
          layOutItem = this.layOutItems[i]
          if (layOutItem.cols.length > 0) {
            if (layOutItem.cols[0].children) {
              childs = layOutItem.cols[0].children
              for (let j = 0; j < childs.length; j++) {
                child = childs[j]
                clickItem = child.cols.find((item) => {
                  return item.uniqueId === uniqueId
                })
                if (clickItem) {
                  this.currClickItem = clickItem
                }
              }
            }
          }
        }
      }
      if (this.currClickItem != null) {
        this.currClickItem.isSelect = true
        this.widthNum = this.currClickItem.span
        this.itemTitle = this.currClickItem.label
      }
    },
    // 标题改变,更新项标题
    titleChange() {
      if (this.currClickItem != null) {
        this.currClickItem.label = this.itemTitle
      }
    },
    // 宽度改变,更新项宽度
    widthChange(value) {
      if (this.currClickItem != null) {
        this.currClickItem.span = this.widthNum
      }
    },
    // 删除已布局的项
    delItem(
      type,
      firstRowIndex,
      firstColIndex,
      secondRowIndex,
      secondColIndex
    ) {
      // type删除项类型,firstRowIndex外层行号,
      // 需将hasLayOutCheckItems中项移至checkItems
      // 删除普通项时type='0',若所在行存在多项,则只需删除layOutItem.cols中的该项,若所在行只有该项,则需删除整行layOutItem
      // 删除分组中普通项时type='1',若所在行存在多项,则只需删除child.cols中的该项,若所在行只有该项,则需删除整行child
      // 删除分组时type='2',直接删除整行layOutItem
      if (type === '0') {
        const cols = this.layOutItems[firstRowIndex].cols
        const col = cols[firstColIndex]
        const checkItem = this.hasLayOutCheckItems.find((item) => {
          return item.itemNo === col.itemNo
        })
        if (checkItem) {
          this.checkItems.push(checkItem)
          const hasLayOutCheckItemIndex = this.hasLayOutCheckItems.indexOf(
            checkItem
          )
          this.hasLayOutCheckItems.splice(hasLayOutCheckItemIndex, 1)
        }
        if (cols.length > 1) {
          cols.splice(firstColIndex, 1)
        } else {
          this.layOutItems.splice(firstRowIndex, 1)
        }
      } else if (type === '1') {
        const childs = this.layOutItems[firstRowIndex].cols[firstColIndex]
          .children
        const childCols = childs[secondRowIndex].cols
        const childCol = childCols[secondColIndex]
        const checkItem = this.hasLayOutCheckItems.find((item) => {
          return item.itemNo === childCol.itemNo
        })
        if (checkItem) {
          this.checkItems.push(checkItem)
          const hasLayOutCheckItemIndex = this.hasLayOutCheckItems.indexOf(
            checkItem
          )
          this.hasLayOutCheckItems.splice(hasLayOutCheckItemIndex, 1)
        }
        if (childCols.length > 1) {
          childCols.splice(secondColIndex, 1)
        } else {
          childs.splice(secondRowIndex, 1)
          this.layOutItems[firstRowIndex].minHeight =
            this.layOutItems[firstRowIndex].minHeight - 60
        }
      } else if (type === '2') {
        // 判断分组中是否存在项,若存在项,则需将hasLayOutCheckItems中项移至checkItems
        const childs = this.layOutItems[firstRowIndex].cols[firstColIndex]
          .children
        let child
        let cols
        for (let i = 0; i < childs.length; i++) {
          child = childs[i]
          cols = child.cols
          if (cols.length > 0) {
            let col
            for (let j = 0; j < cols.length; j++) {
              col = cols[j]
              const checkItem = this.hasLayOutCheckItems.find((item) => {
                return item.itemNo === col.itemNo
              })
              if (checkItem) {
                this.checkItems.push(checkItem)
                const hasLayOutCheckItemIndex = this.hasLayOutCheckItems.indexOf(
                  checkItem
                )
                this.hasLayOutCheckItems.splice(hasLayOutCheckItemIndex, 1)
              }
            }
          }
        }
        this.layOutItems.splice(firstRowIndex, 1)
      }
      // 置空当前的点击项
      this.currClickItem = null
    },
    // 提交生成的布局json
    submitJson() {
      console.log('this.layOutItems', this.layOutItems)
    },
    // 弹出布局结果预览窗口
    previewLayOut() {
      this.showPreviewLayout = true
      this.layOutJson = []
      // 排除掉cols为空的行(一层和二层)
      let layOutItem
      let firstCols
      let firstCol
      let childs
      let child
      for (let i = 0; i < this.layOutItems.length; i++) {
        layOutItem = this.layOutItems[i]
        firstCols = layOutItem.cols
        if (firstCols.length > 0) {
          // 判断是是否为分组
          firstCol = firstCols[0]
          if (firstCol.type === 'item') {
            // 普通列
            this.layOutJson.push(layOutItem)
          } else {
            const copyChildren = []
            const copyLayOutItem = {
              id: layOutItem.id,
              label: layOutItem.label,
              uniqueId: layOutItem.uniqueId,
              minHeight: layOutItem.minHeight,
              cols: [
                {
                  id: firstCol.id,
                  uniqueId: firstCol.uniqueId,
                  label: firstCol.label,
                  span: firstCol.span,
                  isSelect: firstCol.isSelect,
                  type: firstCol.type,
                  children: copyChildren
                }
              ]
            }
            // 分组列
            childs = firstCol.children
            if (childs.length > 0) {
              for (let j = 0; j < childs.length; j++) {
                child = childs[j]
                if (child.cols.length > 0) {
                  copyChildren.push(child)
                }
              }
            }
            if (copyChildren.length > 0) {
              copyLayOutItem.minHeight = 40 + copyChildren.length * 60
              this.layOutJson.push(copyLayOutItem)
            }
          }
        }
      }
    },
    // 清空布局,相当于页面初始化
    cleanLayOut() {
      const currTime = new Date().getTime()
      // 需调用后台重新加载数据
      this.checkItems = []
      this.hasLayOutCheckItems = []
      this.layOutItems = []
      const layOutItem = {
        id: null,
        label: '',
        uniqueId: currTime,
        minHeight: 60,
        cols: []
      }
      this.layOutItems.push(layOutItem)
      this.lastRowRef = null
      this.lastColRef = null
      this.inputVal = ''
      this.inputVal1 = ''
      this.widthNum = 3
      this.itemTitle = null
      this.currUniqueId = null
      this.currColType = null
      this.currClickItem = null
    }
  }
}
</script>