WXL (wul)
4 天以前 38c2fe23d77c9f27d52941dab77a100bb1839dd7
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
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
<template>
  <!-- 聊连页面记录 -->
  <div class="Followupdetailspage" id="app-container">
    <div class="Followuserinfo">
      <div>
        <div class="userinfo-text">
          <!-- <span>患者服务详情</span> -->
          <div class="headline">
            <div>患者服务详情</div>
            <div style="margin-left: 20px">
              <el-button
                v-if="!Whetherall"
                type="primary"
                @click="getTaskservelist()"
                >查看患者全部服务</el-button
              >
              <el-button v-else type="success" @click="getTaskservelist(id)"
                >只展示本次服务信息</el-button
              >
            </div>
            <div style="margin-left: 20px; color: #59a0f0">
              <el-link
                href="https://9.208.2.207:6060/search-homepage"
                target="_blank"
                :underline="true"
              >
                前往CDSS查询
              </el-link>
            </div>
            <div class="merge-controls" v-if="Whetherall">
              <el-button
                type="primary"
                @click="toggleMergeMode"
                :disabled="selectedServices.length < 2"
              >
                {{ isMergeMode ? "取消合并" : "合并编辑问卷" }}
              </el-button>
              <el-button
                v-if="isMergeMode"
                type="success"
                @click="openMergeDialog"
                :disabled="selectedServices.length < 2"
              >
                开始合并 (已选 {{ selectedServices.length }} 个服务)
              </el-button>
            </div>
          </div>
          <!-- <el-button type="success">随访后短信</el-button> -->
        </div>
      </div>
      <div>
        <el-table
          :data="logsheetlist"
          :row-class-name="tableRowClassName"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            width="55"
            :selectable="checkSelectable"
            v-if="Whetherall"
          ></el-table-column>
          <el-table-column
            prop="sendname"
            align="center"
            label="姓名"
            width="100"
          >
            <template slot-scope="scope">
              <el-button
                size="medium"
                type="text"
                @click="
                  gettoken360(
                    scope.row.sfzh,
                    scope.row.drcode,
                    scope.row.drname
                  )
                "
                ><span class="button-textsc">{{
                  scope.row.sendname
                }}</span></el-button
              >
            </template>
          </el-table-column>
          <el-table-column
            prop="taskName"
            align="center"
            width="200"
            show-overflow-tooltip
            label="任务名称"
          >
          </el-table-column>
          <el-table-column
            prop="sendstate"
            align="center"
            width="200"
            label="任务状态"
          >
            <template slot-scope="scope">
              <div v-if="scope.row.sendstate == 1">
                <el-tag type="primary" :disable-transitions="false"
                  >表单已领取</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 2">
                <el-tag type="primary" :disable-transitions="false"
                  >待随访</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 3">
                <el-tag type="success" :disable-transitions="false"
                  >表单已发送</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 4">
                <el-tag type="info" :disable-transitions="false">不执行</el-tag>
              </div>
              <div v-if="scope.row.sendstate == 5">
                <el-tag type="danger" :disable-transitions="false"
                  >发送失败</el-tag
                >
              </div>
              <div v-if="scope.row.sendstate == 6">
                <el-tag type="success" :disable-transitions="false"
                  >已完成</el-tag
                >
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="finishtime"
            align="center"
            label="随访完成时间"
            width="200"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            label="出院日期"
            width="200"
            align="center"
            key="endtime"
            prop="endtime"
          >
            <template slot-scope="scope">
              <span>{{ formatTime(scope.row.endtime) }}</span>
            </template></el-table-column
          >
          <el-table-column
            label="责任护士"
            width="120"
            align="center"
            key="nurseName"
            prop="nurseName"
          />
          <el-table-column
            label="主治医生"
            width="120"
            align="center"
            key="drname"
            prop="drname"
          />
 
          <el-table-column
            label="结果状态"
            align="center"
            key="excep"
            prop="excep"
            width="120"
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.sys_yujing"
                :value="scope.row.excep"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="处理意见"
            align="center"
            key="suggest"
            prop="suggest"
            width="120"
          >
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.sys_suggest"
                :value="scope.row.suggest"
              />
            </template>
          </el-table-column>
 
          <el-table-column
            prop="templatename"
            align="center"
            label="服务模板"
            width="200"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="remark"
            align="center"
            label="服务记录"
            width="200"
            show-overflow-tooltip
          >
          </el-table-column>
 
          <el-table-column
            prop="bankcardno"
            align="center"
            label="呼叫状态"
            width="210"
          >
          </el-table-column>
          <el-table-column
            label="操作"
            fixed="right"
            align="center"
            width="200"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="medium"
                type="text"
                @click="Seedetails(scope.row)"
                ><span class="button-zx"
                  ><i class="el-icon-s-order"></i>查看</span
                ></el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!-- 添加合并编辑对话框 -->
    <el-dialog
      title="合并编辑问卷"
      :visible.sync="mergeDialogVisible"
      width="80%"
      top="5vh"
      v-dialogDrag
    >
      <MergeAndModify
        v-if="mergeDialogVisible"
        :selected-services="selectedServices"
        :patid="patid"
        @save="handleMergeSave"
        @cancel="mergeDialogVisible = false"
      />
    </el-dialog>
    <div class="action-container">
      <div class="call-action">
        <div class="call-container">
          <!-- <div class="call-header">
            <h2>一键呼叫功能</h2>
          </div> -->
 
          <div class="headline">
            <div>随访内容</div>
          </div>
          <div>
            <el-tabs v-model="activeName" type="border-card">
              <el-tab-pane name="wj">
                <span class="mulsz" slot="label"
                  ><i class="el-icon-notebook-1"></i> 问卷随访结果</span
                >
                <div class="CONTENT">
                  <div class="title">{{ taskname ? taskname : "问卷" }}</div>
 
                  <div class="preview-left" v-if="!Voicetype">
                    <div
                      class="topic-dev"
                      v-for="(item, index) in tableDatatop"
                      :key="item.id"
                    >
                      <!-- 单选 -->
                      <div
                        :class="
                          item.isabnormal
                            ? 'scriptTopic-isabnormal'
                            : 'scriptTopic-dev'
                        "
                        :key="index"
                        v-if="item.scriptType == 1 && !item.astrict"
                      >
                        <div class="dev-text">
                          {{ index + 1 }}、[单选]<span>{{
                            item.scriptContent
                          }}</span>
                        </div>
                        <div class="dev-xx">
                          <el-radio-group
                            v-model="item.scriptResult"
                            @change="
                              handleOptionChange(
                                $event,
                                index,
                                item.svyLibTemplateTargetoptions,
                                item
                              )
                            "
                          >
                            <el-radio
                              v-for="(
                                items, indexs
                              ) in item.svyLibTemplateTargetoptions"
                              :class="items.isabnormal ? 'red-star' : ''"
                              :key="indexs"
                              :label="items.optioncontent"
                              >{{ items.optioncontent }}</el-radio
                            >
                          </el-radio-group>
                        </div>
                        <div
                          v-if="item.showAppendInput||item.answerps"
                          class="append-input-container"
                        >
                          <el-input
                            type="textarea"
                            :rows="2"
                            placeholder="请输入具体信息"
                            v-model="item.answerps"
                            clearable
                          ></el-input>
                        </div>
                        <div v-show="item.prompt">
                          <el-alert :title="item.prompt" type="warning">
                          </el-alert>
                        </div>
                      </div>
                      <!-- 多选 -->
                      <div
                        :class="
                          item.isabnormal
                            ? 'scriptTopic-isabnormal'
                            : 'scriptTopic-dev'
                        "
                        :key="index"
                        v-if="item.scriptType == 2 && !item.astrict"
                      >
                        <div class="dev-text">
                          {{ index + 1 }}、[多选]<span>{{
                            item.scriptContent
                          }}</span>
                        </div>
                        <div class="dev-xx">
                          <el-checkbox-group
                            v-model="item.scriptResult"
                            @change="updateScore($event, index, item)"
                          >
                            <el-checkbox
                              :class="items.isabnormal ? 'red-star' : ''"
                              @change="$forceUpdate()"
                              v-for="(
                                items, indexs
                              ) in item.svyLibTemplateTargetoptions"
                              :key="indexs"
                              :label="items.optioncontent"
                            >
                              {{ items.optioncontent }}
                            </el-checkbox>
                          </el-checkbox-group>
                        </div>
                        <div v-show="item.prompt && item.scriptResult[0]">
                          <el-alert :title="item.prompt" type="warning">
                          </el-alert>
                        </div>
                      </div>
                      <!-- 填空 -->
                      <div
                        class="scriptTopic-dev"
                        :key="index"
                        v-if="item.scriptType == 4 && !item.astrict"
                      >
                        <div class="dev-text">
                          {{ index + 1 }}、[问答]<span>{{
                            item.scriptContent
                          }}</span>
                        </div>
                        <div class="dev-xx">
                          <el-input
                            type="textarea"
                            :rows="2"
                            placeholder="请输入答案"
                            v-model="item.scriptResult"
                            clearable
                          >
                          </el-input>
                        </div>
                      </div>
                    </div>
                  </div>
 
                  <div class="preview-left" v-else>
                    <div
                      class="topic-dev"
                      v-for="(item, index) in tableDatatop"
                      :key="item.id"
                    >
                      <div v-if="item.targetvalue">
                        <div class="dev-text">
                          {{ index + 1 }}、[单选]<span>{{
                            item.questiontext
                          }}</span>
                        </div>
                        <div class="dev-xx">
                          <el-radio-group
                            v-model="item.matchedtext"
                            @change="
                              handleOptionChange(
                                $event,
                                index,
                                item.ivrTaskScriptTargetoptionList,
                                item
                              )
                            "
                          >
                            <el-radio
                              v-for="(items, index) in item.scriptResult"
                              :key="items"
                              :label="items"
                              >{{ items }}</el-radio
                            >
                          </el-radio-group>
                        </div>
                        <div v-show="item.prompt">
                          <el-alert :title="item.prompt" type="warning">
                          </el-alert>
                        </div>
                      </div>
 
                      <div class="scriptTopic-dev" :key="index" v-else>
                        <div class="dev-text">
                          {{ index + 1 }}、[问答]<span>{{
                            item.questiontext
                          }}</span>
                        </div>
                        <div class="dev-xx">
                          <el-input
                            type="textarea"
                            :rows="2"
                            placeholder="请输入答案"
                            v-model="item.matchedtext"
                            clearable
                          >
                          </el-input>
                        </div>
                      </div>
                    </div>
                  </div>
                  <el-button
                    v-if="Voicetype"
                    type="primary"
                    @click="yuyingetdetail"
                    >保存服务详情</el-button
                  >
                  <el-button v-else type="primary" @click="getdetail"
                    >保存服务详情</el-button
                  >
                </div>
              </el-tab-pane>
 
              <el-tab-pane name="yy">
                <span class="mulsz" slot="label"
                  ><i class="el-icon-headset"></i> 语音随访详情</span
                >
                <div class="borderdiv">
                  <div class="title">{{ taskname ? taskname : "问卷" }}</div>
                  <div
                    style="
                      display: flex;
                      text-align: center;
                      align-items: center;
                      color: #59a0f0;
                    "
                  >
                    完整语音:
                    <mini-audio
                      :audio-source="
                        voice ? voice : '@assets/order/example.mp3'
                      "
                    ></mini-audio>
                  </div>
                  <div class="preview-left">
                    <div v-for="item in voiceDatatop">
                      <div class="leftside">
                        <i class="el-icon-phone-outline"></i
                        ><span>{{ item.questiontext }}</span>
                      </div>
                      <div class="offside">
                        <i class="el-icon-user"></i>
                        <div class="offside-value">
                          <el-input
                            type="textarea"
                            :autosize="{ minRows: 1 }"
                            v-model="item.asrtext"
                          ></el-input>
 
                          <div>
                            <mini-audio
                              :audio-source="
                                item.questionvoice
                                  ? item.questionvoice
                                  : '@assets/order/example.mp3'
                              "
                            ></mini-audio>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <el-button
                    v-if="Voicetype"
                    type="primary"
                    @click="yuyingetdetail"
                    >保存随访详情</el-button
                  >
                  <el-button v-else type="primary" @click="getdetail"
                    >保存随访详情</el-button
                  >
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
      </div>
      <div class="manual-action">
        <div class="Followuserinfos">
          <div>
            <el-form
              ref="userform"
              :model="form"
              :rules="userrules"
              label-width="120px"
            >
              <div class="headline">
                <div>人工处理</div>
                <div style="margin: 0 30px">
                  <el-button
                    type="primary"
                    plain
                    @click="Editsingletasksonyic('')"
                    >保存基础信息</el-button
                  >
                </div>
                <div>
                  <el-button
                    type="primary"
                    round
                    v-if="this.form.isVisitAgain != 2"
                    @click="sendAgain()"
                    >再次随访</el-button
                  >
                </div>
              </div>
              <el-row>
                <el-col :span="14"
                  ><el-form-item label="联系电话">
                    <el-input
                      placeholder="联系电话缺失"
                      v-model="userform.telcode"
                    >
                      <el-button
                        slot="append"
                        icon="el-icon-phone"
                        @click="handleCall(userform.telcode, 'tel')"
                        :disabled="!isValidPhone(userform.telcode)"
                      ></el-button
                    ></el-input> </el-form-item
                ></el-col>
              </el-row>
              <el-row>
                <el-col :span="14"
                  ><el-form-item label="联系人电话">
                    <el-input
                      placeholder="联系人电话缺失"
                      v-model="userform.relativetelcode"
                    >
                      <el-button
                        slot="append"
                        icon="el-icon-phone"
                        @click="
                          handleCall(userform.relativetelcode, 'relative')
                        "
                        :disabled="!isValidPhone(userform.relativetelcode)"
                      ></el-button
                    ></el-input> </el-form-item
                ></el-col>
                <el-col :span="10"
                  ><el-form-item label="联系人关系">
                    <el-input
                      placeholder="联系人关系缺失"
                      v-model="userform.relation"
                    ></el-input> </el-form-item
                ></el-col>
              </el-row>
              <div class="call-controls">
                <CallButton
                  ref="callButton"
                  :phoneNumber="currentPhoneNumber"
                  style="display: none"
                />
 
                <div v-if="callStatus === 'connected'" class="hangup-btn">
                  <el-button
                    type="danger"
                    icon="el-icon-phone"
                    @click="endCurrentCall"
                    :loading="isEndingCall"
                  >
                    挂断电话
                  </el-button>
                </div>
                <div class="call-status" v-if="callStatus !== 'idle'">
                  <el-alert
                    :title="callStatusText"
                    :type="callStatusType"
                    :closable="false"
                    show-icon
                  />
                </div>
              </div>
              <el-form-item label="随访记录">
                <el-input type="textarea" v-model="form.remark"></el-input>
              </el-form-item>
 
              <el-form-item label="处理意见">
                <div>
                  <el-button
                    plain
                    type="warning"
                    @click="Editsingletaskson('1')"
                    >暂不处理</el-button
                  >
                  <el-button
                    plain
                    type="success"
                    @click="Editsingletaskson('2')"
                    >病情稳定</el-button
                  >
                  <el-button
                    plain
                    type="primary"
                    @click="Editsingletaskson('3')"
                    >通知就诊</el-button
                  >
                  <el-button plain type="info" @click="Editsingletaskson('5')"
                    >中心随访</el-button
                  >
                </div>
              </el-form-item>
            </el-form>
 
            <div class="detailed">
              <h3>患者档案信息</h3>
              <el-form ref="userform" :model="userform" label-width="100px">
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="患者姓名" prop="name">
                      <el-input
                        v-model="userform.name"
                        placeholder="请输入姓名"
                        maxlength="30"
                      ></el-input> </el-form-item
                  ></el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="12"
                    ><el-form-item label="联系方式" prop="telcode">
                      <el-input
                        v-model="userform.telcode"
                        placeholder="请输入联系方式"
                        maxlength="20"
                      /> </el-form-item
                  ></el-col>
                  <el-col :span="12">
                    <el-form-item label="亲属联系方式" prop="name">
                      <el-input
                        v-model="userform.relativetelcode"
                        placeholder="请输入姓名"
                        maxlength="20"
                      ></el-input> </el-form-item
                  ></el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="24">
                    <el-form-item label="出生地" prop="birthplace">
                      <el-input
                        v-model="userform.birthplace"
                        placeholder="国、省、地市、区县、街道等详细信息"
                        maxlength="50"
                      /> </el-form-item
                  ></el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="24"
                    ><el-form-item label="居住地" prop="placeOfResidence">
                      <el-input
                        v-model="userform.placeOfResidence"
                        placeholder="国、省、地市、区县、街道等详细信息"
                        maxlength="50"
                      /> </el-form-item
                  ></el-col>
                </el-row>
              </el-form>
            </div>
          </div>
        </div>
      </div>
    </div>
 
    <el-dialog
      title="患者再次随访"
      v-dialogDrags
      :visible.sync="dialogFormVisible"
    >
      <el-form ref="zcform" :rules="zcrules" :model="form" label-width="80px">
        <el-form-item label="任务名称">
          <el-input
            style="width: 400px"
            disabled
            v-model="form.taskName"
          ></el-input>
        </el-form-item>
        <el-form-item label="患者名称">
          <el-input
            style="width: 400px"
            disabled
            v-model="form.sendname"
          ></el-input>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input style="width: 400px" disabled v-model="form.age"></el-input>
        </el-form-item>
        <el-form-item label="科室">
          <el-input
            style="width: 400px"
            disabled
            v-model="form.deptname"
          ></el-input>
        </el-form-item>
        <el-form-item label="病区">
          <el-input
            style="width: 400px"
            disabled
            v-model="form.leavehospitaldistrictname"
          ></el-input>
        </el-form-item>
        <el-form-item label="出院时间">
          <el-input
            style="width: 400px"
            disabled
            v-model="form.endtime"
          ></el-input>
        </el-form-item>
        <div class="headline">上次随访</div>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="随访方式">
              <el-select
                v-model="form.visitType2"
                filterable
                allow-create
                default-first-option
                disabled
                placeholder="请选择随访方式"
                class="custom-disabled"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="随访时间">
              <el-date-picker
                type="date"
                disabled
                placeholder="选择日期"
                :picker-options="pickerOptions"
                align="right"
                v-model="form.date2"
                class="custom-disabled"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-form-item label="随访记录">
          <el-input
            class="custom-disabled"
            type="textarea"
            disabled
            v-model="form.remark2"
          ></el-input>
        </el-form-item>
        <div class="headline">下次随访</div>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="随访方式" prop="date1">
              <el-select
                v-model="form.visitType"
                filterable
                allow-create
                default-first-option
                @change="visitChange"
                placeholder="请选择随访方式(依出院时间技计算)"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="随访时间" prop="date1">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                :picker-options="pickerOptions"
                align="right"
                v-model="form.date1"
                class="custom-disabled"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="随访方式" prop="resource">
          <el-radio-group v-model="form.resource">
            <el-radio label="1">本病区随访</el-radio>
            <el-radio label="2">随访中心随访</el-radio>
          </el-radio-group>
        </el-form-item>
 
        <el-form-item label="随访记录">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="warning" @click="dialogFormVisible = false"
          >取 消</el-button
        >
        <el-button type="primary" @click="setupsubtask">确认创建服务</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  getsearchrResults,
  getPersonVoices,
  addserviceSubtask,
  getTaskservelist,
  getTaskFollowup,
  Editsingletaskson,
  serviceSubtaskDetailedit,
  serviceSubtaskDetailadd,
  updatePersonVoices,
  addPersonVoices,
  query360PatInfo,
} from "@/api/AiCentre/index";
import {
  messagelistpatient,
  alterpatient,
  listcontactinformation,
} from "@/api/patient/homepage";
import CallButton from "@/components/CallButton";
import MergeAndModify from "./MergeAndModify.vue";
export default {
  components: {
    CallButton,
    MergeAndModify,
  },
 
  dicts: ["sys_normal_disable", "sys_user_sex", "sys_yujing", "sys_suggest"],
  data() {
    const validatePhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请输入联系电话"));
      }
      setTimeout(() => {
        if (!/^1[3-9]\d{9}$/.test(value)) {
          callback(new Error("请输入正确的11位手机号码"));
        } else {
          callback();
        }
      }, 300);
    };
    return {
      userid: "",
      currentPhoneNumber: "",
      callType: "", // 用于区分是哪个电话
      // 已有数据...
      callStatus: "idle", // idle, calling, connected, ended, failed
      isEndingCall: false,
      currentCall: null, // 当前通话对象
      input: "今天身体还不错",
      radio: "2",
      taskname: "",
      activeName: "wj",
      voice: "",
      templateid: "",
      again: "",
      zcform: {},
      form: {},
      tableDatatop: [], //题目表
      voiceDatatop: [], //题目表
      dynamicTags: [],
      isMergeMode: false,
      mergeDialogVisible: false,
      selectedServices: [], // 选中的服务列表
      zcrules: {
        resource: [
          { required: true, message: "请选择随访方式", trigger: "change" },
        ],
        date1: [{ required: true, message: "请选择随访时间", trigger: "blur" }],
      },
      userrules: {
        telcode: [{ validator: validatePhone, trigger: "blur" }],
        relativetelcode: [{ validator: validatePhone, trigger: "blur" }],
      },
      url: "http://9.208.2.190:8090/smartor/serviceExternal/query360PatInfo",
      postData: {
        XiaoXiTou: {
          FaSongFCSJC: "ZJHES",
          FaSongJGID: localStorage.getItem("orgid"),
          FaSongJGMC: localStorage.getItem("orgname"),
          FaSongSJ: "2025-01-09 17:29:36",
          FaSongXTJC: "SUIFANGXT",
          FaSongXTMC: "随访系统",
          XiaoXiID: "5FA92AFB-9833-4608-87C7-F56A654AC171",
          XiaoXiLX: "SC_LC_360STCX",
          XiaoXiMC: "360 视图查询",
          ZuHuID: localStorage.getItem("ZuHuID"),
          ZuHuMC: localStorage.getItem("orgname"),
        },
        YeWuXX: {
          BingRenXX: {
            ZhengJianHM: "",
            ZhengJianLXDM: "01",
            ZhengJianLXMC: "居民身份证",
            ZuZhiJGID: localStorage.getItem("orgid"),
            ZuZhiJGMC: localStorage.getItem("orgname"),
          },
          YongHuXX: {
            XiTongID: "SUIFANGXT",
            XiTongMC: "随访系统",
            YongHuID: "1400466972205912064",
            YongHuXM: "JNRMYY",
            ZuZhiJGID: localStorage.getItem("orgid"),
            ZuZhiJGMC: localStorage.getItem("orgname"),
            idp: "lyra",
          },
        },
      },
      pickerOptions: {
        disabledDate(time) {
          // 禁用今天及之前的日期
          return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
        },
        shortcuts: [
          {
            text: "七天后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
          {
            text: "15天后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 15);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一个月后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30);
              picker.$emit("pick", date);
            },
          },
          {
            text: "三个月后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 90);
              picker.$emit("pick", date);
            },
          },
          {
            text: "六个月后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 180);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一年后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 365);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      options: [
        {
          value: "七天后",
          label: "七天后",
        },
        {
          value: "15天后",
          label: "15天后",
        },
        {
          value: "一个月后",
          label: "一个月后",
        },
        {
          value: "三个月后",
          label: "三个月后",
        },
        {
          value: "六个月后",
          label: "六个月后",
        },
        {
          value: "一年后",
          label: "一年后",
        },
      ],
      userform: {},
      Whetherall: true, //是否全部记录展示
      dialogFormVisible: false,
      Voicetype: 0, //是否为语音服务
      visitCount: null,
      logsheetlist: [],
      topicobj: {},
      sendname: null,
      serviceType: null,
      id: null,
      taskid: null,
      patid: null,
    };
  },
  computed: {
    callStatusText() {
      const statusMap = {
        idle: "准备呼叫",
        calling: `正在呼叫 ${this.currentPhoneNumber}...`,
        connected: `已接通 ${this.currentPhoneNumber}`,
        ended: "通话已结束",
        failed: "呼叫失败",
      };
      return statusMap[this.callStatus];
    },
    callStatusType() {
      const typeMap = {
        idle: "info",
        calling: "warning",
        connected: "success",
        ended: "info",
        failed: "error",
      };
      return typeMap[this.callStatus];
    },
  },
  created() {
    this.taskid = this.$route.query.taskid;
    this.id = this.$route.query.id;
    this.sendname = this.$route.query.sendname;
    this.patid = this.$route.query.patid;
    this.again = this.$route.query.again;
    this.Voicetype = this.$route.query.Voicetype;
    this.visitCount = this.$route.query.visitCount;
    this.serviceType = this.$route.query.serviceType;
 
    this.getTaskservelist();
  },
 
  methods: {
    // 获取问卷数据
    getsearchrResults(id) {
      getsearchrResults({
        taskid: this.taskid,
        patid: this.patid,
        subId: id ? id : this.id,
        isFinish: false,
      }).then((res) => {
        if (res.code === 200) {
          // 针对再次随访服务进行删除结果赋值
          if (this.again && res.data.upScriptResult) {
            res.data.upScriptResult.forEach((itemA) => {
              const itemB = res.data.scriptResult.find(
                (item) => item.scriptContent === itemA.scriptContent
              );
              if (itemB) {
                itemB.scriptResult = itemA.scriptResult;
              }
            });
          }
          this.tableDatatop = res.data.scriptResult;
 
          this.tableDatatop.forEach((item) => {
            if (item.scriptType == 2) item.scriptResult = [];
            if (item.scriptResultId && item.scriptType != 2) {
              item.isoption = 3;
              item.scriptResult = item.scriptResult;
            } else if (item.scriptResultId && item.scriptType == 2) {
              item.scriptResult = item.scriptResult.split("&");
              item.isoption = 3;
            }
          });
          this.taskname = res.data.taskName;
          this.overdata();
        }
      });
    },
    //患者360跳转
    gettoken360(sfzh, drcode, drname) {
      this.postData.YeWuXX.BingRenXX.ZhengJianHM = sfzh;
      if (this.postData.XiaoXiTou.ZuHuMC == "丽水市中医院") {
        this.postData.YeWuXX.YongHuXX.YongHuID = "1400398571877961728";
        this.postData.YeWuXX.YongHuXX.YongHuXM = "LSZYY";
      }
      query360PatInfo(this.postData).then((res) => {
        if (res.data.url) {
          window.open(res.data.url, "_blank");
          // this.linkUrl = res.data.url;
        } else {
          this.$modal.msgWarning("360查询无结果");
        }
      });
    },
    // 获取基础信息
    getuserinfo() {
      const queryParams = {
        pid: Number(this.patid),
        allhosp: "0",
      };
      // 患者基础信息
      messagelistpatient(queryParams).then((response) => {
        if (response.rows[0]) {
          this.userform = response.rows[0];
          // this.dynamicTags = response.rows[0].tagList.map(this.processElement);
        }
      });
      listcontactinformation({ patid: this.patid }).then((response) => {
        this.tableData = response.rows;
        if (this.tableData.length) {
          this.userform.relativetelcode = this.tableData[0].contactway;
          this.userform.relation = this.tableData[0].relation;
        }
      });
    },
    // 再次随访时间选取
    visitChange(value) {
      // 根据选择的随访方式设置时间
      const now = new Date();
      if (value.includes("七天后")) {
        this.form.date1 = new Date(
          Date.parse(this.form.endtime) + 3600 * 1000 * 24 * 7
        );
      } else if (value.includes("15天后")) {
        this.form.date1 = new Date(
          Date.parse(this.form.endtime) + 3600 * 1000 * 24 * 15
        );
      } else if (value.includes("一个月后")) {
        this.form.date1 = new Date(
          Date.parse(this.form.endtime) + 3600 * 1000 * 24 * 30
        );
      } else if (value.includes("三个月后")) {
        this.form.date1 = new Date(
          Date.parse(this.form.endtime) + 3600 * 1000 * 24 * 90
        );
      } else if (value.includes("六个月后")) {
        this.form.date1 = new Date(
          Date.parse(this.form.endtime) + 3600 * 1000 * 24 * 180
        );
      } else if (value.includes("一年后")) {
        this.form.date1 = new Date(
          Date.parse(this.form.endtime) + 3600 * 1000 * 24 * 365
        );
      }
    },
 
    // 获取语音数据
    getPersonVoices(id) {
      let obj = {
        taskid: this.taskid,
        patid: this.patid,
        subId: id ? id : this.id,
      };
 
      getPersonVoices(obj).then((res) => {
        if (res.code == 200) {
          this.voiceDatatop = res.data.serviceSubtaskDetails;
          this.voice = res.data.voice;
          this.activeName = "yy";
          this.taskname = res.data.taskName;
          // 问卷展示数据处理
          this.tableDatatop = res.data.filteredDetails;
          this.tableDatatop.forEach((item) => {
            if (item.targetvalue) {
              item.scriptResult = item.targetvalue.split("&");
            } else {
              item.scriptResult = [];
            }
          });
 
          if (!this.tableDatatop.length) {
            this.puttaskid(this.templateid);
          }
        }
      });
    },
    // 获取问卷完整数据比对
    puttaskid(id) {
      getTaskFollowup(id).then((res) => {
        if (res.code == 200) {
          this.tableDatatop = res.data.ivrTaskTemplateScriptVOList;
          this.tableDatatop.forEach((item) => {
            item.id = null;
            // 类型判断赋值
            if (item.ivrTaskScriptTargetoptionList) {
              item.targetvalue = 1;
              item.questiontext = item.scriptContent;
              item.targetvalue = item.ivrTaskScriptTargetoptionList
                .map((obj) => obj.targetvalue)
                .join("&");
            }
            if (item.targetvalue) {
              item.scriptResult = item.targetvalue.split("&");
            } else {
              item.scriptResult = [];
            }
          });
        }
      });
    },
    // 医护人员存储数据
    getdetail() {
      let excep = "";
      const promises = [];
      this.tableDatatop.forEach((item) => {
        var objs = item.svyLibTemplateTargetoptions.find(
          (items) => items.optioncontent == item.scriptResult
        );
        if (obj) {
          if (objs.isabnormal) {
            excep = 1;
          }
        }
        let obj = {
          asrtext: null,
          patid: this.patid,
          subId: this.id,
          taskid: this.taskid,
          scriptid: item.id,
          excep: excep,
          questiontext: item.scriptContent,
          answerps: item.answerps || null, // 添加附加信息
        };
        if (item.scriptType == 2 && item.scriptResult[0]) {
          obj.asrtext = item.scriptResult.join("&");
        } else if (item.scriptType != 2 && item.scriptResult) {
          obj.asrtext = item.scriptResult;
        }
 
        if (item.isoption == 3) {
          promises.push(serviceSubtaskDetailedit(obj));
        } else {
          promises.push(serviceSubtaskDetailadd(obj));
        }
      });
      // 使用 Promise.all 等待所有异步操作完成
      Promise.all(promises)
        .then((results) => {
          // 所有异步操作成功完成后的逻辑
          results.forEach((res) => {
            if (res.code !== 200) {
              this.$modal.error("修改失败");
            }
          });
          this.Editsingletasksonyic(6);
 
          this.$modal
            .confirm(
              '任务保存成功是否针对患者:"' +
                this.logsheetlist[0].sendname +
                '"再次随访?',
              "确认",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                showCancelButton: true,
                dangerouslyUseHTMLString: true,
                confirmButtonClass: "custom-confirm-button", // 自定义确认按钮的类名
                cancelButtonClass: "custom-cancel-button", // 自定义取消按钮的类名
              }
            )
            .then(() => {
              document.querySelector("#app").scrollTo(0, 0);
              this.formtidy();
              this.dialogFormVisible = true;
            })
            .catch(() => {
              if (this.form.serviceType == 13) {
                if (this.visitCount != 1) {
                  this.$router.push({
                    path: "/logisticsservice/zbAgain",
                  });
                } else {
                  this.$router.push({
                    path: "/logisticsservice/record",
                  });
                }
              } else if (this.form.serviceType == 2) {
                if (this.visitCount != 1) {
                  this.$router.push({
                    path: "/logisticsservice/again",
                  });
                } else {
                  this.$router.push({
                    path: "/followvisit/discharge",
                  });
                }
              }
            });
        })
        .catch((error) => {
          // 如果有任何一个异步操作失败,会进入这里
          console.error("发生错误:", error);
        });
    },
    // 电话============================
    // 验证电话号码格式并返回错误信息
    validatePhoneNumber(phone) {
      if (!phone) {
        return { isValid: false, message: "请输入电话号码" };
      }
 
      // 手机号正则
      const mobileRegex = /^1[3-9]\d{9}$/;
 
      // 带区号的固定电话(完整格式)
      const landlineFullRegex = /^0\d{2,3}-?\d{7,8}$/;
 
      // 不带区号的固定电话(仅本地号码)
      const landlineLocalRegex = /^\d{7,8}$/;
 
      if (mobileRegex.test(phone)) {
        return { isValid: true, type: "mobile" };
      } else if (landlineFullRegex.test(phone)) {
        return { isValid: true, type: "landline" };
      } else if (landlineLocalRegex.test(phone)) {
        return {
          isValid: false,
          message: "本地号码请添加区号(如028-1234567)",
        };
      } else {
        return {
          isValid: false,
          message: "请输入正确的电话号码(手机号或带区号的固定电话)",
        };
      }
    },
    // 使用示例
    isValidPhone(phone) {
      return this.validatePhoneNumber(phone).isValid;
    },
    handleCall(phone, type) {
      if (!this.isValidPhone(phone)) {
        this.$message.error("请输入正确的手机号码");
        return;
      }
 
      this.currentPhoneNumber = phone;
      this.callType = type;
      this.callStatus = "calling";
 
      this.$nextTick(() => {
        this.$refs.callButton.startCall();
 
        // 监听通话状态变化
        this.$refs.callButton.$on("call-status-change", (status) => {
          this.handleCallStatusChange(status);
        });
      });
    },
    // 处理通话状态变化
    handleCallStatusChange(status) {
      console.log(status, "status");
 
      this.callStatus = status.type;
 
      if (status.type === "connected") {
        this.currentCall = {
          phone: this.currentPhoneNumber,
          type: this.callType,
          startTime: new Date(),
        };
      } else if (status.type === "ended" || status.type === "failed") {
        this.currentCall = null;
      }
 
      // 可以根据状态执行其他操作
      if (status.type === "failed") {
        this.$message.error(`呼叫失败: ${status.text}`);
      }
    },
    // 结束当前通话
    endCurrentCall() {
      if (!this.currentCall) return;
 
      this.isEndingCall = true;
      this.$refs.callButton.endCall();
 
      // 3秒后重置状态
      setTimeout(() => {
        this.isEndingCall = false;
      }, 3000);
    },
    yuyingetdetail() {
      this.tableDatatop.forEach((item, index) => {
        item.scriptResult = item.scriptResult.join("&");
        item.templatequestionnum = index + 1;
        item.subId = this.id;
        item.taskid = this.taskid;
        item.asrtext = item.matchedtext;
        if (!item.id) {
          item.isoperation = 1;
        }
        item.patid = this.patid;
        item.templateid = item.templateID;
      });
      let obj = {
        serviceSubtaskDetailList: this.tableDatatop,
        param1: this.taskid,
        param2: this.patid,
        subId: this.id,
      };
 
      addPersonVoices(obj).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess("服务保存成功");
          this.$modal
            .confirm(
              '任务保存成功是否针对患者:"' +
                this.userform.name +
                '"再次随访?',
              "确认",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                showCancelButton: true,
                dangerouslyUseHTMLString: true,
                confirmButtonClass: "custom-confirm-button", // 自定义确认按钮的类名
                cancelButtonClass: "custom-cancel-button", // 自定义取消按钮的类名
              }
            )
            .then(() => {
              document.querySelector("#app").scrollTo(0, 0);
              this.formtidy();
              this.dialogFormVisible = true;
            })
            .catch(() => {
              if (this.form.serviceType == 13) {
                if (this.visitCount != 1) {
                  this.$router.push({
                    path: "/logisticsservice/zbAgain",
                  });
                } else {
                  this.$router.push({
                    path: "/logisticsservice/record",
                  });
                }
              } else if (form.serviceType == 2) {
                if (this.visitCount != 1) {
                  this.$router.push({
                    path: "/followvisit/again",
                  });
                } else {
                  this.$router.push({
                    path: "/followvisit/discharge",
                  });
                }
              }
            });
        }
      });
    },
    // 再次随访数据更替
    formtidy() {
      this.form.visitType2 = this.form.visitType;
      this.form.date2 = this.form.longSendTime;
      this.form.remark2 = this.form.remark;
    },
    // 获取患者记录
    getTaskservelist(id) {
      if (id) {
        this.Whetherall = false;
      } else {
        this.Whetherall = true;
      }
 
      getTaskservelist({
        patid: this.patid,
        subId: id,
      }).then((res) => {
        if (res.code == 200) {
          this.form = res.rows[0].serviceSubtaskList.find(
            (item) => item.id == this.id
          );
          console.log(this.form.serviceType, "serviceType");
 
          this.logsheetlist = res.rows[0].serviceSubtaskList;
          this.templateid = this.logsheetlist[0].templateid;
          const targetDate = new Date(this.form.longSendTime); // 目标日期
          const now = new Date(); // 当前时间
          if (now < targetDate && this.form.sendstate == 2) {
            this.$confirm("当前服务未到发送时间请谨慎修改", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {})
              .catch(() => {});
          }
          this.getuserinfo();
        }
        if (this.Voicetype) {
          this.getPersonVoices();
        } else {
          this.getsearchrResults();
        }
      });
    },
    Editsingletaskson(son) {
      let objson = {};
      getTaskservelist({
        patid: this.patid,
        subId: this.id,
      }).then((res) => {
        if (res.code == 200) {
          objson = res.rows[0].serviceSubtaskList[0];
          objson.suggest = son;
          Editsingletaskson(objson).then((res) => {
            if (res.code) {
              this.$modal.msgSuccess("服务记录成功");
              this.getTaskservelist();
            }
          });
        }
      });
    },
    Editsingletasksonyic(sendstate) {
      let objson = {};
      getTaskservelist({
        patid: this.patid,
        subId: this.id,
      }).then((res) => {
        if (res.code == 200) {
          objson = res.rows[0].serviceSubtaskList.find(
            (item) => item.id == this.id
          );
          objson.remark = this.form.remark;
          if (sendstate) objson.sendstate = sendstate;
          Editsingletaskson(objson).then((res) => {
            if (res.code) {
              this.$modal.msgSuccess("服务修改成功");
              alterpatient(this.userform).then((res) => {
                if (res.code == 200) {
                  this.$modal.msgSuccess("基础信息保存成功");
                } else {
                  this.$modal.msgError("基础信息修改失败");
                }
              });
              this.getTaskservelist();
            }
          });
        }
      });
    },
    // 异常列渲染
    tableRowClassName({ row, rowIndex }) {
      if (row.id == this.id) {
        return "warning-row";
      }
      return "";
    },
    // 调起再次发送
    sendAgain() {
      document.querySelector("#app").scrollTo(0, 0);
      // scrollTo(0, 0)
      this.formtidy();
      this.dialogFormVisible = true;
    },
    // 查看详情
    Seedetails(row) {
      this.$modal
        .confirm('是否查看任务为"' + row.taskName + '"的服务详情数据?')
        .then(() => {
          if (row.preachformson) {
            if (row.preachformson.includes("3")) {
              this.Voicetype = 1;
            }
          }
          this.taskid = row.taskid;
          this.id = row.id;
          this.patid = row.patid;
          this.serviceType = row.serviceType;
          this.getTaskservelist();
        })
        .catch(() => {});
    },
    aahandleOptionChange(a, b, c) {
      const result = c.find((item) => item.optioncontent == a);
      if (result.nextQuestion == 0) {
        this.tableDatatop = this.tableDatatop.reduce((acc, item, i) => {
          acc.push(i > b ? { ...item, astrict: 1 } : item);
          return acc;
        }, []);
      } else {
        this.tableDatatop = this.tableDatatop.reduce((acc, item, i) => {
          acc.push(i > b ? { ...item, astrict: 0 } : item);
          return acc;
        }, []);
      }
      if (this.Voicetype) {
        var obj = this.tableDatatop[b].ivrTaskScriptTargetoptionList.find(
          (item) => item.optioncontent == a
        );
      } else {
        var obj = this.tableDatatop[b].svyLibTemplateTargetoptions.find(
          (item) => item.optioncontent == a
        );
      }
      if (obj.isabnormal) {
        this.tableDatatop[b].isabnormal = true;
      } else {
        this.tableDatatop[b].isabnormal = false;
      }
      this.$forceUpdate();
    },
    // 在methods部分,修改handleOptionChange方法:
    handleOptionChange(selectedOption, questionIndex, options, a) {
      if (document.activeElement) {
        document.activeElement.blur();
      }
 
      // 找到被选中的选项对象
      const selectedOptionObj = options.find(
        (item) => item.optioncontent == selectedOption
      );
 
      // 处理异常状态高亮
      this.tableDatatop[questionIndex].isabnormal =
        !!selectedOptionObj.isabnormal;
      // 处理附加输入框显示
 
      this.tableDatatop[questionIndex].showAppendInput =
        selectedOptionObj.appendflag == 1;
      console.log(this.tableDatatop);
 
      // if (!this.tableDatatop[questionIndex].showAppendInput) {
      //   this.tableDatatop[questionIndex].answerps = ""; // 清除附加信息
      // }
      // 保存当前题目之前已经隐藏的题目状态
      const previouslyHiddenBeforeCurrent = this.tableDatatop
        .slice(0, questionIndex)
        .map((item, index) => (item.astrict ? index : -1))
        .filter((index) => index !== -1);
 
      // 保存之前因nextQuestion=0而隐藏的题目范围
      const previouslyHiddenByEnd = this.tableDatatop
        .map((item, index) => (item.hiddenByEnd ? index : -1))
        .filter((index) => index !== -1);
 
      // 如果branchFlag为1,处理题目跳转
      if (a.branchFlag == 1) {
        if (selectedOptionObj.nextQuestion == 0) {
          // 结束问答 - 隐藏后面所有题目并标记
          this.tableDatatop = this.tableDatatop.map((item, index) => ({
            ...item,
            astrict: index > questionIndex,
            hiddenByEnd: index > questionIndex, // 标记这些题目是被结束问答隐藏的
          }));
        } else {
          // 正常跳转逻辑
          const nextQuestionIndex = selectedOptionObj.nextQuestion - 1;
 
          this.tableDatatop = this.tableDatatop.map((item, index) => {
            // 保留当前题目之前的隐藏状态
            if (index < questionIndex) {
              return {
                ...item,
                astrict: previouslyHiddenBeforeCurrent.includes(index),
                hiddenByEnd: false, // 清除结束标记
              };
            }
 
            // 当前题目总是可见
            if (index === questionIndex) {
              return { ...item, astrict: 0, hiddenByEnd: false };
            }
 
            // 显示目标下一题
            if (index === nextQuestionIndex) {
              return { ...item, astrict: 0, hiddenByEnd: false };
            }
 
            // 如果是之前被结束问答隐藏的题目,现在应该恢复显示
            if (item.hiddenByEnd) {
              return { ...item, astrict: 0, hiddenByEnd: false };
            }
 
            // 隐藏当前题和目标题之间的题目
            if (index > questionIndex && index < nextQuestionIndex) {
              return { ...item, astrict: 1, hiddenByEnd: false };
            }
 
            // 其他情况保持原状
            return item;
          });
        }
      } else {
        // 如果没有跳转,只需确保下一题可见
        this.tableDatatop = this.tableDatatop.map((item, index) => ({
          ...item,
          astrict: index === questionIndex + 1 ? 0 : item.astrict,
          hiddenByEnd: index === questionIndex + 1 ? false : item.hiddenByEnd,
        }));
      }
 
      this.$forceUpdate();
    },
    overdata() {
      this.tableDatatop.forEach((item, index) => {
        var obj = item.svyLibTemplateTargetoptions.find(
          (items) => items.optioncontent == item.scriptResult
        );
        if (obj) {
          if (obj.isabnormal) {
            this.tableDatatop[index].isabnormal = true;
          } else {
            this.tableDatatop[index].isabnormal = false;
          }
          this.$forceUpdate();
        }
      });
    },
    // 创建再次随访服务
    setupsubtask() {
      this.$refs["zcform"].validate((valid) => {
        if (valid) {
          if (this.form.date1 && new Date(this.form.date1) < new Date()) {
            this.$message.error("随访时间不能小于当前时间");
            return false;
          }
          this.form.remark =
            this.form.remark + "【" + this.getCurrentTime() + "】";
          let form = structuredClone(this.form);
          form.longSendTime = this.formatTime(form.date1);
          form.finishtime = "";
          if (form.resource) {
            if (form.resource == 2) {
              form.visitDeptCode = localStorage.getItem("deptCode");
              form.visitDeptName = "随访中心";
            } else {
              form.visitDeptCode = form.deptcode;
              form.visitDeptName = form.deptname;
            }
          } else {
            this.$modal.msgError("未选择随访方式");
            return;
          }
          // form.id = null;
          form.sendstate = 2;
          console.log(form.serviceType, "form.serviceType");
 
          addserviceSubtask(form).then((res) => {
            if (res.code == 200) {
              this.$modal.msgSuccess("创建成功");
              if (form.serviceType == 13) {
                this.$router.push({
                  path: "/logisticsservice/zbAgain",
                });
              } else if (form.serviceType == 2) {
                this.$router.push({
                  path: "/logisticsservice/again",
                });
              }
            } else {
              this.$modal.msgError("创建失败");
            }
            document.querySelector("#app").scrollTo(0, 0);
            this.dialogFormVisible = false;
          });
        }
      });
    },
    getCurrentTime() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, "0");
      const day = String(now.getDate()).padStart(2, "0");
      const hours = String(now.getHours()).padStart(2, "0");
      const minutes = String(now.getMinutes()).padStart(2, "0");
      const seconds = String(now.getSeconds()).padStart(2, "0");
 
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    updateScore(a, b, c) {},
    // 合并修改相关=============================
    toggleMergeMode() {
      this.isMergeMode = !this.isMergeMode;
      if (!this.isMergeMode) {
        this.selectedServices = [];
      }
    },
 
    handleSelectionChange(selection) {
      this.selectedServices = selection
        .filter(
          (item) => !item.preachformson || !item.preachformson.includes("3")
        )
        .map((item) => ({
          id: item.id,
          taskid: item.taskid,
          taskName: item.taskName,
          sendname: item.sendname,
        }));
    },
    checkSelectable(row, index) {
      // 当 sendstate 为 6 时不可选
      return row.sendstate !== 6;
    },
    openMergeDialog() {
      if (this.selectedServices.length < 2) {
        this.$message.warning("请至少选择2个问卷服务进行合并");
        return;
      }
      this.mergeDialogVisible = true;
    },
 
    handleMergeSave(mergedData) {
      // 处理合并保存逻辑
      this.mergeDialogVisible = false;
      this.isMergeMode = false;
      this.selectedServices = [];
 
      // 显示保存结果
      if (mergedData.successCount == mergedData.totalCount) {
        this.$message.success(`成功保存 ${mergedData.successCount} 个问卷`);
      } else if (mergedData.successCount > 0) {
        this.$message.warning(
          `成功保存 ${mergedData.successCount} 个问卷,失败 ${
            mergedData.totalCount - mergedData.successCount
          } 个`
        );
      } else {
        this.$message.error("所有问卷保存失败");
      }
 
      // 刷新数据
      this.getTaskservelist();
    },
  },
};
</script>
 
<style lang="scss" scoped>
.Followupdetailspage {
  margin: 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
 
.action-container {
  display: flex;
  gap: 20px;
  margin: 0 10px 20px 10px;
 
  .manual-action {
    flex: 1;
    min-width: 0;
    height: 100%; /* 确保高度继承 */
  }
 
  .call-action {
    width: 60%;
    min-width: 0;
    height: 100%; /* 确保高度继承 */
  }
}
 
.call-container {
  padding: 20px;
  background: #fff;
  border: 1px solid #dcdfe6;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
  border-radius: 4px;
  height: 100%;
 
  .call-header {
    margin-bottom: 20px;
 
    h2 {
      font-size: 20px;
      color: #333;
      margin: 0;
      padding-bottom: 10px;
      border-bottom: 1px solid #eee;
    }
  }
 
  .call-status {
    margin-bottom: 20px;
  }
 
  .hangup-btn {
    text-align: center;
    margin-top: 20px;
  }
}
.merge-controls {
  background: #f5f7fa;
  border-radius: 4px;
  margin-left: 20px;
}
.Followuserinfo {
  margin: 10px 10px 0 10px;
  align-items: center;
  padding: 30px;
  background: #ffff;
  border: 1px solid #dcdfe6;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
 
  .userinfo-text {
    font-size: 20px;
    margin-right: 20px;
    margin-bottom: 10px;
  }
 
  .userinfo-value {
    color: rgb(15, 139, 211);
 
    span {
      margin-right: 20px;
    }
  }
}
 
::v-deep.el-table .warning-row {
  background: #c4e2ee;
}
 
.Followuserinfos {
  align-items: center;
  padding: 30px;
  background: #ffff;
  border: 1px solid #dcdfe6;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
  height: 100%; /* 确保高度继承 */
  min-height: 880px; /* 最小高度与随访内容一致 */
  display: flex;
  flex-direction: column;
 
  .userinfo-text {
    font-size: 20px;
    margin-right: 20px;
    margin-bottom: 10px;
  }
 
  .userinfo-value {
    color: rgb(15, 139, 211);
 
    span {
      margin-right: 20px;
    }
  }
 
  .el-form {
    flex: 1;
    overflow-y: auto; /* 内容超过高度时显示滚动条 */
    max-height: calc(880px - 60px); /* 减去padding */
    padding-right: 10px; /* 防止滚动条遮挡内容 */
  }
}
.append-input-container {
  margin-top: 15px;
  padding: 10px;
  background-color: #f5f7fa;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
}
.borderdiv {
  min-height: 60vh;
  font-size: 20px;
  padding: 30px;
 
  .title {
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 20px;
    text-align: center;
  }
 
  .leftside {
    margin: 30px 0;
 
    span {
      width: 400px;
      margin-left: 20px;
      padding: 10px;
      color: #fff;
      background: rgb(110, 196, 247);
      border-radius: 10px;
    }
  }
 
  .offside {
    display: flex;
    flex-direction: row-reverse;
 
    .offside-value {
      padding: 10px;
      background: rgb(217, 173, 253);
      border-radius: 10px;
      color: #fff;
      margin-right: 20px;
    }
  }
}
.topic-dev[inert] {
  opacity: 0.5;
  pointer-events: none;
}
.CONTENT {
  padding: 10px;
  height: 100%;
  min-height: 660px; /* 设置最小高度 */
 
  .title {
    font-size: 22px;
    font-weight: bold;
    margin-bottom: 20px;
    text-align: center;
  }
}
 
.preview-left {
  margin: 20px;
  padding: 30px;
  border: 1px solid #dcdfe6;
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
  max-height: 580px; /* 设置最大高度 */
  overflow-y: auto; /* 内容超过高度时显示滚动条 */
 
  .topic-dev {
    margin-bottom: 25px;
    font-size: 20px !important;
 
    .dev-text {
      margin-bottom: 10px;
    }
  }
}
 
.scriptTopic-isabnormal {
  color: red;
}
 
.detailed {
  width: 88%;
  border-radius: 8px;
  padding: 30px;
  margin-bottom: 30px;
  background-color: #ddf0f8;
 
  .bg-purple {
    margin-bottom: 20px;
  }
 
  .spanvalue {
    display: inline-block;
    min-width: 200px;
    border-bottom: 1px solid rgb(172, 172, 172);
  }
}
 
.headline {
  font-size: 24px;
  height: 40px;
  border-left: 5px solid #41a1be;
  padding-left: 5px;
  margin-bottom: 10px;
  display: flex;
 
  .Add-details {
    font-size: 18px;
    color: #02a7f0;
    cursor: pointer;
  }
}
 
.red-star {
  ::v-deep.el-radio__label {
    position: relative;
    padding-right: 10px;
  }
 
  ::v-deep.el-radio__label::after {
    content: "*";
    color: red;
    position: absolute;
    right: -5px;
    top: 0;
  }
 
  ::v-deep.el-input-group__textarea {
    white-space: pre-wrap;
    word-break: break-all;
  }
 
  ::v-deep.el-checkbox__label {
    position: relative;
    padding-right: 10px;
  }
 
  ::v-deep.el-checkbox__label::after {
    content: "*";
    color: red;
    position: absolute;
    right: -5px;
    top: 0;
  }
}
 
::v-deep.offside-value .el-radio__label {
  color: #fff;
}
 
::v-deep.el-link.el-link--default {
  color: #02a7f0 !important;
}
 
.el-message-box__btns button:nth-child(2) {
  margin-left: 10px;
  background-color: #f57676;
  border-color: #f57676;
}
 
.el-icon-phone {
  transition: all 0.3s;
}
 
.el-button[disabled] .el-icon-phone {
  color: #c0c4cc;
}
 
.el-button:not([disabled]) .el-icon-phone {
  color: #409eff;
}
 
.el-button:not([disabled]):hover .el-icon-phone {
  color: #66b1ff;
  transform: scale(1.1);
}
 
.mulsz {
  font-size: 25px;
  margin-top: 20px;
}
 
.el-input.is-disabled .el-input__inner {
  background-color: #fff;
  border-color: #dcdfe6;
  color: #080808 !important;
  cursor: not-allowed;
}
 
.el-textarea.is-disabled .el-textarea__inner {
  background-color: #fff;
  border-color: #dcdfe6;
  color: #080808 !important;
  cursor: not-allowed;
}
</style>