zxl
2025-07-31 7ac56f27fd501739a21dcb542ea3940b25fa038e
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
<template>
  <div class="activity-management">
    <Card>
      <!-- 搜索表单 -->
      <Form
        ref="searchForm"
        @keydown.enter.native="handleSearch"
        :model="searchForm"
        inline
        :label-width="80"
        class="search-form"
      >
        <FormItem label="活动名称" prop="activityName">
          <Input
            type="text"
            v-model="searchForm.activityName"
            placeholder="请输入活动名称"
            clearable
            @on-clear="handleSearch"
            style="width: 180px"
          />
        </FormItem>
        <FormItem label="活动类型" prop="activityType">
          <Select
            v-model="searchForm.activityType"
            placeholder="请选择活动类型"
            style="width: 180px"
            clearable
            @on-clear="handleSearch"
            @on-change="handleSearch"
          >
            <Option
              v-for="item in typeSelect"
              :value="item.value"
              :key="item.id"
            >
              {{ item.label }}
            </Option>
          </Select>
        </FormItem>
        <FormItem label="审核情况" prop="audit">
          <Select
            v-model="searchForm.audit"
            placeholder="请选择审核情况"
            style="width: 180px"
            clearable
            @on-clear="handleSearch"
            @on-change="handleSearch"
          >
            <Option
              v-for="item in auditSelect"
              :value="item.value"
              :key="item.id"
            >
              {{ item.label }}
            </Option>
          </Select>
        </FormItem>
        <FormItem label="报名开始时间" prop="reportStartTime">
          <DatePicker
            :value="searchForm.reportStartTime"
            type="datetime"
            placeholder="选择开始时间"
            style="width: 180px"
            @on-change="handleSearch('reportStart', $event)"
            @on-clear="handleSearch"
          ></DatePicker>
        </FormItem>
        <FormItem label="报名结束时间" prop="reportEndTime">
          <DatePicker
            :value="searchForm.reportEndTime"
            type="datetime"
            placeholder="选择结束时间"
            style="width: 180px"
            @on-clear="handleSearch"
            @on-change="handleSearch('reportEnd', $event)"
          ></DatePicker>
        </FormItem>
        <Button
          @click="handleSearch"
          type="primary"
          icon="ios-search"
          class="search-btn"
        >搜索</Button>
        <Button
          @click="resetSearch"
          icon="md-refresh"
          style="margin-left: 8px"
        >重置</Button>
      </Form>
 
      <!-- 操作按钮 -->
      <Row class="operation">
        <Button @click="openAdd" type="primary" icon="md-add">新增活动</Button>
        <Button @click="delBatch" type="error" icon="md-trash" :disabled="selectCount === 0">批量删除</Button>
      </Row>
 
      <!-- 活动表格 -->
      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="activityList"
        ref="table"
        @on-selection-change="showSelect"
        class="activity-table"
      >
        <!-- 封面展示插槽 -->
        <template slot-scope="{ row }" slot="url">
          <div class="media-container">
            <!-- 图片类型 -->
            <template v-if="row.coverType === 'image'">
              <img
                :src="row.url"
                alt="活动封面"
                class="thumbnail"
                @click="previewImage(row.url)"
              >
            </template>
            <!-- 视频类型 -->
            <template v-else-if="row.coverType === 'video'">
              <video
                :src="row.url"
                class="video-player"
                controls
              ></video>
            </template>
            <!-- 文字类型 -->
            <template v-else>
              <div class="text-cover">{{ row.cover || '暂无封面内容' }}</div>
            </template>
          </div>
        </template>
 
        <!-- 操作按钮插槽 -->
        <template slot-scope="{ row }" slot="action">
          <div class="action-btns">
            <Button
              type="primary"
              size="small"
              @click="changeRecommend(row, row.recommend ? '取消推荐' : '推荐')"
              :loading="row.recommendLoading"
            >
              {{ row.recommend ? '取消推荐' : '推荐' }}
            </Button>
            <Button
              type="primary"
              size="small"
              @click="changeStatus(row, row.publish ? '下架' : '发布')"
              :loading="row.statusLoading"
            >
              {{ row.publish  ? '下架' : '发布' }}
            </Button>
            <Button
              type="info"
              size="small"
              @click="detail(row)"
            >详情</Button>
            <Button
              type="info"
              size="small"
              @click="openEdit(row)"
            >编辑</Button>
            <Button
              type="error"
              size="small"
              @click="delById(row)"
            >删除</Button>
            <Button
              type="success"
              size="small"
              @click="openMembersModal(row)"
            >报名人员</Button>
            <Button
              type="success"
              size="small"
              :disabled="row.auditStatus !== 0"
              @click="openAuditModal(row)"
            >审核活动</Button>
          </div>
        </template>
      </Table>
 
      <!-- 分页 -->
      <Row type="flex" justify="end" class="page-footer">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
 
      <!-- 活动编辑/新增模态框 -->
      <Modal
        v-model="modelShow"
        :title="modelTitle"
        @on-cancel="modelClose"
        width="800"
        :mask-closable="false"
      >
        <Form ref="form" :model="activityFrom" :label-width="100" :rules="rules">
          <Row :gutter="16">
            <Col span="12">
              <FormItem label="活动名称" prop="activityName">
                <Input
                  v-model="activityFrom.activityName"
                  placeholder="请输入活动名称"
                  clearable
                />
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="活动类型" prop="activityType" :label-width="100">
                <Select
                  v-model="activityFrom.activityType"
                  placeholder="请选择活动类型"
                  clearable
                >
                  <Option
                    v-for="item in typeSelect"
                    :value="item.value"
                    :key="item.id"
                  >
                    {{ item.label }}
                  </Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="报名时间段" prop="reportTime">
                <DatePicker
                  v-model="activityFrom.reportTime"
                  type="datetimerange"
                  format="yyyy-MM-dd HH:mm"
                  placeholder="请选择报名时间段"
                  style="width: 100%"
                ></DatePicker>
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="活动时间段" prop="time">
                <DatePicker
                  v-model="activityFrom.time"
                  type="datetimerange"
                  format="yyyy-MM-dd HH:mm"
                  placeholder="请选择活动时间段"
                  style="width: 100%"
                ></DatePicker>
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="封面类型" prop="coverType" :labelWidth="100">
                <Select
                  v-model="coverType"
                  placeholder="请选择封面类型"
                  @on-change="handleCoverTypeChange"
                >
                  <Option
                    v-for="item in coverTypeOptions"
                    :value="item.value"
                    :key="item.id"
                  >
                    {{ item.value }}
                  </Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="24" v-if="coverType === '输入文字封面'">
              <FormItem label="封面文字" prop="cover">
                <Input
                  v-model="activityFrom.cover"
                  type="textarea"
                  :rows="2"
                  placeholder="请输入封面文字"
                  style="width: 50%"
                />
              </FormItem>
            </Col>
            <Col span="24" v-if="coverType === '选择文件封面'">
              <FormItem label="上传封面" prop="cover">
                <Upload
                  :before-upload="handleBeforeUpload"
                  :format="['jpg','jpeg','png','gif','mp4','mov']"
                  :max-size="20480"
                  action=""
                  accept="image/*,video/*"
                >
                  <Button icon="ios-cloud-upload-outline">上传封面文件</Button>
                  <div class="upload-tip">支持图片或视频文件,最大20MB</div>
                </Upload>
                <div v-if="file" class="upload-file-info">
                  已选文件: {{ file.name }}
                  <Button type="text" @click="handleRemove">删除</Button>
                </div>
              </FormItem>
            </Col>
            <!-- 这两个表单项在同一Row内,会显示在同一行 -->
            <Col span="12">
              <FormItem label="人数限制" prop="limitUserNum">
                <InputNumber
                  v-model="activityFrom.limitUserNum"
                  :min="1"
                  placeholder="请输入最大人数"
                  style="width: 100%"
                />
              </FormItem>
            </Col>
            <Col span="12" v-if="activityFrom.activityType === 'offline'">
              <FormItem label="活动地点" prop="activityLocation" >
                <Input
                  v-model="activityFrom.activityLocation"
                  placeholder="请输入活动地点"
                />
              </FormItem>
            </Col>
            <Col span="24">
              <FormItem label="活动内容:" prop="activityContent">
 
                  <!-- 基于elementUi的上传组件 el-upload begin-->
                  <Upload
                    :show-upload-list="false"
                    ref="upload"
                    style="display: none"
                    :before-upload="handleUploadEdit"
                    :format="['jpg','jpeg','png','gif','mp4','mov']"
                    :max-size="20480"
                    action=""
                    accept="image/*,video/*"
                  >
                  </Upload>
                  <!-- 基于elementUi的上传组件 el-upload end-->
                  <quill-editor
                    v-model="activityFrom.activityContent"
                    ref="QuillEditor"
                    class="editor"
                    :options="editorOption"
                    @blur="onEditorBlur($event)"
                    @focus="onEditorFocus($event)"
                    @ready="onEditorReady($event)"
                  >
                  </quill-editor>
              </FormItem>
            </Col>
          </Row>
        </Form>
 
        <div slot="footer">
          <Button @click="modelClose">取消</Button>
          <Button type="primary" :loading="submitLoading" @click="saveOrUpdate">提交</Button>
        </div>
      </Modal>
 
      <!-- 报名人员模态框 -->
      <Modal
        v-model="membersModelShow"
        :title="membersModelTitle"
        @on-cancel="membersModelClose"
        width="1000"
        class="members-modal"
      >
        <Table
          :loading="membersLoading"
          border
          :columns="membersColumns"
          :data="membersList"
          class="members-table"
        ></Table>
        <Row type="flex" justify="end" class="page-footer">
          <Page
            :current="memberForm.pageNumber"
            :total="memberTotal"
            :page-size="memberForm.pageSize"
            @on-change="memberChangePage"
            @on-page-size-change="memberChangePageSize"
            :page-size-opts="[10, 20, 50]"
            size="small"
            show-total
            show-elevator
            show-sizer
          ></Page>
        </Row>
      </Modal>
 
      <Modal
        v-model="infoModelShow"
        :title="modelTitle"
        @on-cancel="infoModelClose"
        width="800"
        :mask-closable="false"
      >
        <div class="detail-container">
          <Row :gutter="16">
            <Col span="12">
              <div class="detail-item">
                <label>活动名称:</label>
                <span>{{ activityInfo.activityName || '-' }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动类型:</label>
                <span>{{activityInfo.activityType === 'online' ? '线上':'线下'}}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>报名时间段:</label>
                <span>{{ activityInfo.reportStartTime }} - {{ activityInfo.reportEndTime }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动时间段:</label>
                <span>{{ activityInfo.startTime }} - {{ activityInfo.endTime }}</span>
              </div>
            </Col>
 
            <Col span="24" v-if="coverType === '输入文字封面'">
              <div class="detail-item">
                <label>封面文字:</label>
                <span>{{ activityInfo.cover || '-' }}</span>
              </div>
            </Col>
            <Col span="24" v-if="coverType === '选择文件封面'">
              <div class="detail-item">
                <label>上传封面:</label>
                <span>{{ activityInfo.cover }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>人数限制:</label>
                <span>{{ activityInfo.limitUserNum || '无限制' }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动地点:</label>
                <span>{{ activityInfo.activityLocation || '-' }}</span>
              </div>
            </Col>
            <Col span="24">
              <div class="detail-item">
                <label>活动内容:</label>
                <div
                  class="activity-content"
                  v-html="activityInfo.activityContent || '无内容'"
                ></div>
              </div>
            </Col>
          </Row>
        </div>
 
        <div slot="footer">
          <Button @click="infoModelClose">关闭</Button>
        </div>
      </Modal>
 
 
      <Modal
        v-model="auditModelShow"
        :title="modelTitle"
        @on-cancel="closeAuditModel"
        width="800"
        :mask-closable="false"
      >
        <div class="detail-container">
          <Row :gutter="16">
            <Col span="12">
              <div class="detail-item">
                <label>活动名称:</label>
                <span>{{ activityInfo.activityName || '-' }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动类型:</label>
                <span>{{activityInfo.activityType === 'online' ? '线上':'线下'}}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>报名时间段:</label>
                <span>{{ activityInfo.reportStartTime }} - {{ activityInfo.reportEndTime }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动时间段:</label>
                <span>{{ activityInfo.startTime }} - {{ activityInfo.endTime }}</span>
              </div>
            </Col>
 
            <Col span="24" v-if="coverType === '输入文字封面'">
              <div class="detail-item">
                <label>封面文字:</label>
                <span>{{ activityInfo.cover || '-' }}</span>
              </div>
            </Col>
            <Col span="24" v-if="coverType === '选择文件封面'">
              <div class="detail-item">
                <label>上传封面:</label>
                <span>{{ activityInfo.cover }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>人数限制:</label>
                <span>{{ activityInfo.limitUserNum || '无限制' }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动地点:</label>
                <span>{{ activityInfo.activityLocation || '-' }}</span>
              </div>
            </Col>
            <Col span="24">
              <div class="detail-item">
                <label>活动内容:</label>
                <div
                  class="activity-content"
                  v-html="activityInfo.activityContent || '无内容'"
                  ref="“activityHTMLContent"
                ></div>
              </div>
            </Col>
            <Col span="24">
              <Form :model="auditForm" :rules="auditRules" ref="auditForm" class="audit-form">
                <FormItem label="审核结果:" prop="audit">
                  <RadioGroup v-model="auditForm.audit">
                    <Radio label="1">通过</Radio>
                    <Radio label="2">未通过</Radio>
                  </RadioGroup>
                </FormItem>
                <FormItem label="审核备注:" prop="remarks">
                  <Input
                    v-model="auditForm.remarks"
                    type="textarea"
                    :rows="4"
                    placeholder="请输入审核备注(选填)"
                    :disabled="!auditForm.audit"
                  />
                </FormItem>
              </Form>
            </Col>
          </Row>
        </div>
 
        <!-- 审核表单 -->
 
 
        <div slot="footer">
          <Button @click="closeAuditModel">关闭</Button>
          <Button
            type="primary"
            @click="handleAuditSubmit(activityInfo.id)"
            :disabled="!auditForm.audit"
          >提交审核</Button>
        </div>
      </Modal>
 
 
      <!-- 图片预览模态框 -->
      <Modal v-model="previewVisible" title="图片预览" footer-hide>
        <img :src="previewImageUrl" style="width: 100%">
      </Modal>
    </Card>
  </div>
</template>
 
<script>
import {
  getActivityList,
  addActivity,
  editActivity,
  delActivityById,
  delActivityBatch,
  activityChangeStatus,
  activityChangeRecommend,
  activityMembersPage,
  auditActivity
} from "@/api/activity.js"
import { uploadFileByLmk, delByKey } from "@/api/common.js"
 
import { quillEditor } from 'vue-quill-editor'
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
 
import * as Quill from 'quill' //引入编辑器
import VideoBlot from './video.js';
 
const toolbarOptions = [
  ['bold', 'italic', 'underline', 'strike'],        // 加粗,斜体,下划线,删除线
  ['blockquote', 'code-block'],                     //引用,代码块
  [{ 'header': 1 }, { 'header': 2 }],               // 几级标题
  [{ 'list': 'ordered' }, { 'list': 'bullet' }],    // 有序列表,无序列表
  [{ 'script': 'sub' }, { 'script': 'super' }],     // 下角标,上角标
  [{ 'indent': '-1' }, { 'indent': '+1' }],         // 缩进
  [{ 'direction': 'rtl' }],                         // 文字输入方向
  [{ 'size': ['small', false, 'large', 'huge'] }],  // 字体大小
  [{ 'header': [1, 2, 3, 4, 5, 6, false] }],        // 标题
  [{ 'color': [] }, { 'background': [] }],          // 颜色选择
  // [{ 'font': [] }], // 字体
  [{ 'align': [] }],    // 居中
  ['clean'],            // 清除样式,
  ['link'],
  ['myUploadBtn'],
]
 
// toolbar标题
const titleConfig = [
  { Choice: '.ql-insertMetric', title: '跳转配置' },
  { Choice: '.ql-bold', title: '加粗' },
  { Choice: '.ql-italic', title: '斜体' },
  { Choice: '.ql-underline', title: '下划线' },
  { Choice: '.ql-header', title: '段落格式' },
  { Choice: '.ql-strike', title: '删除线' },
  { Choice: '.ql-blockquote', title: '块引用' },
  { Choice: '.ql-code', title: '插入代码' },
  { Choice: '.ql-code-block', title: '插入代码段' },
  { Choice: '.ql-font', title: '字体' },
  { Choice: '.ql-size', title: '字体大小' },
  { Choice: '.ql-list[value="ordered"]', title: '编号列表' },
  { Choice: '.ql-list[value="bullet"]', title: '项目列表' },
  { Choice: '.ql-direction', title: '文本方向' },
  { Choice: '.ql-header[value="1"]', title: 'h1' },
  { Choice: '.ql-header[value="2"]', title: 'h2' },
  { Choice: '.ql-align', title: '对齐方式' },
  { Choice: '.ql-color', title: '字体颜色' },
  { Choice: '.ql-background', title: '背景颜色' },
  { Choice: '.ql-image', title: '图像' },
  { Choice: '.ql-video', title: '视频' },
  { Choice: '.ql-link', title: '添加链接' },
  { Choice: '.ql-formula', title: '插入公式' },
  { Choice: '.ql-clean', title: '清除字体格式' },
  { Choice: '.ql-script[value="sub"]', title: '下标' },
  { Choice: '.ql-script[value="super"]', title: '上标' },
  { Choice: '.ql-indent[value="-1"]', title: '向左缩进' },
  { Choice: '.ql-indent[value="+1"]', title: '向右缩进' },
  { Choice: '.ql-header .ql-picker-label', title: '标题大小' },
  { Choice: '.ql-header .ql-picker-item[data-value="1"]', title: '标题一' },
  { Choice: '.ql-header .ql-picker-item[data-value="2"]', title: '标题二' },
  { Choice: '.ql-header .ql-picker-item[data-value="3"]', title: '标题三' },
  { Choice: '.ql-header .ql-picker-item[data-value="4"]', title: '标题四' },
  { Choice: '.ql-header .ql-picker-item[data-value="5"]', title: '标题五' },
  { Choice: '.ql-header .ql-picker-item[data-value="6"]', title: '标题六' },
  { Choice: '.ql-header .ql-picker-item:last-child', title: '标准' },
  { Choice: '.ql-size .ql-picker-item[data-value="small"]', title: '小号' },
  { Choice: '.ql-size .ql-picker-item[data-value="large"]', title: '大号' },
  { Choice: '.ql-size .ql-picker-item[data-value="huge"]', title: '超大号' },
  { Choice: '.ql-size .ql-picker-item:nth-child(2)', title: '标准' },
  { Choice: '.ql-align .ql-picker-item:first-child', title: '居左对齐' },
  { Choice: '.ql-align .ql-picker-item[data-value="center"]', title: '居中对齐' },
  { Choice: '.ql-align .ql-picker-item[data-value="right"]', title: '居右对齐' },
  { Choice: '.ql-align .ql-picker-item[data-value="justify"]', title: '两端对齐' }
]
 
export default {
  name: "ActivityManagement",
  components: { quillEditor},
  data() {
    return {
      auditForm: {
        activityId: '',
        audit: null,
        remarks: ''
      },
      auditRules: {
        audit: [
          {required: true, message: '请选择审核结果', trigger: 'change'}
        ]
      },
      infoModelShow: false,
      auditModelShow: false,
 
      loading: false,
      membersLoading: false,
      submitLoading: false,
 
      // 搜索表单
      searchForm: {
        audit: '',
        activityName: '',
        activityType: '',
        reportStartTime: '',
        reportEndTime: '',
        pageNumber: 1,
        pageSize: 10
      },
 
      // 活动列表数据
      activityList: [],
      total: 0,
      selectList: [],
      selectCount: 0,
 
      // 活动类型选项
      typeSelect: [
        {id: 1, value: 'online', label: '线上'},
        {id: 2, value: 'offline', label: '线下'}
      ],
      auditSelect: [
        {id: 1, value: '1', label: '已审核'},
        {id: 2, value: '0', label: '未审核'}
      ],
 
      // 封面类型选项
      coverTypeOptions: [
        {id: 1, value: '输入文字封面'},
        {id: 2, value: '选择文件封面'}
      ],
      coverType: '',
      file: null,
 
      // 活动表单
      activityFrom: {
        id: '',
        activityName: '',
        activityType: '',
        reportTime: [],
        time: [],
        activityContent: '',
        cover: '',
        coverType: '',
        status: '',
        reportStartTime: '',
        reportEndTime: '',
        startTime: '',
        endTime: '',
        recommend: false,
        limitUserNum: 0,
        activityLocation: '',
      },
      activityInfo: {
        id: '',
        activityName: '',
        activityType: '',
        reportTime: [],
        time: [],
        activityContent: '',
        cover: '',
        coverType: '',
        status: '',
        reportStartTime: '',
        reportEndTime: '',
        startTime: '',
        endTime: '',
        recommend: false,
        limitUserNum: 0,
        activityLocation: '',
      },
 
      // 表单验证规则
      rules: {
        activityName: [
          {required: true, message: '请输入活动名称', trigger: 'blur'},
          {max: 50, message: '长度不能超过50个字符', trigger: 'blur'}
        ],
        activityType: [
          {required: true, message: '请选择活动类型', trigger: 'change'}
        ],
        reportTime: [
          {type: 'array', required: true, message: '请选择报名时间段', trigger: 'change'},
          {validator: this.validateReportTime, trigger: 'change'}
        ],
        time: [
          {type: 'array', required: true, message: '请选择活动时间段', trigger: 'change'},
          {validator: this.validateActivityTime, trigger: 'change'}
        ],
        cover: [
          {required: true, message: '请输入封面内容', trigger: 'blur'}
        ],
        coverType: [
          {required: true, message: '请选择封面类型', trigger: 'blur'}
        ],
        limitUserNum: [
          {required: true, type: 'number', message: '请输入人数限制', trigger: 'blur'},
          {type: 'number', min: 1, message: '人数不能少于1人', trigger: 'blur'}
        ],
        activityLocation: [
          {required: true, message: '请输入活动地点', trigger: 'blur'},
          {max: 100, message: '长度不能超过100个字符', trigger: 'blur'}
        ],
        activityContent: [
          {required: false, message: '请输入活动内容', trigger: 'blur'}
        ]
      },
 
      // 表格列配置
      columns: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '活动名称',
          key: 'activityName',
          minWidth: 120,
          tooltip: true
        },
        {
          title: '活动类型',
          key: 'activityType',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h('Tag', {}, params.row.activityType === 'online' ? '线上' : '线下')
          }
        },
        {
          title: '推荐',
          key: 'recommend',
          width: 80,
          align: 'center',
          render: (h, params) => {
            return h('Tag', {
              props: {
                color: params.row.recommend ? 'green' : 'default'
              }
            }, params.row.recommend ? '是' : '否')
          }
        },
        {
          title: '发布',
          key: 'publish',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h('Tag', {
              props: {
                color: params.row.publish ? 'green' : 'default'
              }
            }, params.row.publish ? '已发布' : '未发布')
          }
        },
        {
          title: '审核状态',
          key: 'auditStatus',
          width: 100,
          align: 'center',
          render: (h, params) => {
            const status = params.row.auditStatus;
            let tagText, tagColor;
 
            // 根据状态设置文案和颜色
            switch (status) {
              case 0:
                tagText = '审核中';
                tagColor = 'orange';  // 橙色表示进行中
                break;
              case 1:
                tagText = '已通过';
                tagColor = 'green';   // 绿色表示通过
                break;
              case 2:
                tagText = '未通过';
                tagColor = 'red';     // 红色表示拒绝
                break;
              default:
                tagText = '未知状态';
                tagColor = 'default'; // 默认灰色
            }
 
            return h('Tag', {
              props: {
                color: tagColor,
              },
            }, tagText);
          },
        },
        {
          title: '状态',
          key: 'status',
          width: 100,
          align: 'center',
          render: (h, params) => {
            const status = params.row.status;
            const statusMap = {
              'noStart': {text: '未开始', color: 'default'},
              'report': {text: '报名中', color: 'green'},
              'inProgress': {text: '进行中', color: 'cyan'},
              'end': {text: '已结束', color: 'red'}
            };
            const currentStatus = statusMap[status] || {text: status, color: 'default'};
            return h('Tag', {
              props: {
                color: currentStatus.color
              }
            }, currentStatus.text);
          }
        },
        {
          title: '活动报名时间段',
          key: 'activityReportTimeRange',
          width: 300,
          render: (h, params) => {
            return h('div', [
              h('div', `开始: ${this.formatDate(params.row.reportStartTime)}`),
              h('div', `结束: ${this.formatDate(params.row.reportEndTime)}`)
            ])
          }
        },
        {
          title: '活动时间段',
          key: 'activityTimeRange',
          width: 300,
          render: (h, params) => {
            return h('div', [
              h('div', `开始: ${this.formatDate(params.row.startTime)}`),
              h('div', `结束: ${this.formatDate(params.row.endTime)}`)
            ])
          }
        },
        {
          title: '封面',
          key: 'url',
          slot: 'url',
          width: 150,
          align: 'center'
        },
        {
          title: '封面类型',
          key: 'coverType',
          width: 100,
          align: 'center',
          render: (h, params) => {
            const typeMap = {
              text: '文本',
              video: '视频',
              image: '图片'
            };
            const text = typeMap[params.row.coverType] || params.row.coverType;
            return h('span', text);
          }
        },
        {
          title: '人数限制',
          key: 'limitUserNum',
          width: 100,
          align: 'center'
        },
        {
          title: '活动地点',
          key: 'activityLocation',
          minWidth: 120,
          tooltip: true
        },
        {
          title: '操作',
          slot: 'action',
          width: 280,
          align: 'center',
          fixed: 'right'
        }
      ],
 
      // 报名人员相关
      membersModelShow: false,
      membersModelTitle: '',
      membersList: [],
      memberForm: {
        id: '',
        pageNumber: 1,
        pageSize: 10
      },
      memberTotal: 0,
      membersColumns: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '用户名',
          key: 'username',
          minWidth: 100
        },
        {
          title: '昵称',
          key: 'nickName',
          minWidth: 100
        },
        {
          title: '性别',
          key: 'sex',
          width: 80,
          render: (h, params) => {
            return h('Tag', {
              props: {
                color: params.row.sex === 1 ? 'blue' : 'magenta'
              }
            }, params.row.sex === 1 ? '男' : '女')
          }
        },
        {
          title: '地区',
          key: 'region',
          minWidth: 120
        },
        {
          title: '状态',
          key: 'disabled',
          width: 100,
          render: (h, params) => {
            return h('Tag', {
              props: {
                color: params.row.disabled ? 'green' : 'red' //true 正常 false被禁用
              }
            }, params.row.disabled ? '正常' : '禁用')
          }
        }
      ],
 
      // 图片预览
      previewVisible: false,
      previewImageUrl: '',
 
      // 模态框控制
      modelShow: false,
      modelTitle: '',
 
      //编辑器配置
      // 富文本编辑器配置
      Quill:'',
      defaultValue: '',
      editorOption: {
        placeholder: '请在这里输入',
        theme: 'snow', //主题 snow/bubble
        modules: {
          history: {
            delay: 1000,
            maxStack: 50,
            userOnly: false
          },
          toolbar: {
            container: toolbarOptions,
            handlers: {
              myUploadBtn: this.myMethod,
            }
          }
        }
      }
 
    }
  },
  // 在组件创建前注册
  beforeCreate() {
    Quill.register(VideoBlot, true);
  },
  mounted() {
    //初始化
    this.Quill=this.$refs.QuillEditor.quill
    this.init()
    this.initTitle()
    this.initButton();
  },
  methods: {
    myMethod(){
      this.$refs.upload.handleClick();
    },
    initButton(){
      const editorButton = document.querySelector('.ql-myUploadBtn')
      editorButton.innerHTML = '<svg t="1751966766109" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1530" fill="currentColor"  style="width: 1em; height: 1em; vertical-align: middle;"><path d="M1024 693.248q0 25.6-8.704 48.128t-24.576 40.448-36.864 30.208-45.568 16.384l1.024 1.024-17.408 0-4.096 0-4.096 0-675.84 0q-5.12 1.024-16.384 1.024-39.936 0-74.752-15.36t-60.928-41.472-40.96-60.928-14.848-74.752 14.848-74.752 40.96-60.928 60.928-41.472 74.752-15.36l1.024 0q-1.024-8.192-1.024-15.36l0-16.384q0-72.704 27.648-137.216t75.776-112.128 112.128-75.264 136.704-27.648 137.216 27.648 112.64 75.264 75.776 112.128 27.648 137.216q0 37.888-8.192 74.24t-22.528 69.12q5.12-1.024 10.752-1.536t10.752-0.512q27.648 0 52.736 10.752t43.52 29.696 29.184 44.032 10.752 53.76zM665.6 571.392q20.48 0 26.624-4.608t-8.192-22.016q-14.336-18.432-31.744-48.128t-36.352-60.416-38.4-57.344-37.888-38.912q-18.432-13.312-27.136-14.336t-25.088 12.288q-18.432 15.36-35.84 38.912t-35.328 50.176-35.84 52.224-36.352 45.056q-18.432 18.432-13.312 32.768t25.6 14.336l16.384 0q9.216 0 19.968 0.512t20.992 0.512l17.408 0q14.336 1.024 18.432 9.728t4.096 24.064q0 17.408-0.512 30.72t-0.512 25.6-0.512 25.6-0.512 30.72q0 7.168 1.536 15.36t5.632 15.36 12.288 11.776 21.504 4.608l23.552 0q9.216 0 27.648 1.024 24.576 0 28.16-12.288t3.584-38.912q0-23.552 0.512-42.496t0.512-51.712q0-23.552 4.608-36.352t19.968-12.8q11.264 0 32.256-0.512t32.256-0.512z" p-id="1531"></path></svg>'
    },
 
    initTitle() {
      document.getElementsByClassName('ql-editor')[0].dataset.placeholder = ''
      for (let item of titleConfig) {
        let tip = document.querySelector('.quill-editor ' + item.Choice)
        if (!tip) continue
        tip.setAttribute('title', item.title)
      }
    },
 
    // 失去焦点
    onEditorBlur(editor) {
    },
 
    // 获得焦点
    onEditorFocus(editor) {
 
    },
 
    // 开始
    onEditorReady(editor) {
    },
  handleUploadEdit(file){
    const fileType = file.type
    const isImage = fileType.includes('image')
    const isVideo = fileType.includes('video')
 
    if (!isImage && !isVideo) {
      this.$Message.error('请上传图片或视频文件')
      return false
    }
 
    if (file.size > 20 * 1024 * 1024) {
      this.$Message.error('文件大小不能超过20MB')
      return false
    }
 
    this.file = file
    this.uploadFile2()
    return false
  },
// 上传文件
  uploadFile2() {
    if (!this.file) return
 
    this.submitLoading = true
    const formData = new FormData()
    formData.append('file', this.file)
    uploadFileByLmk(formData).then(res => {
      this.submitLoading = false
      if (res.code === 200) {
        let url = res.data.url;
        let fileKey = res.data.fileKey;
        let fileType = this.getFileType(this.file);
 
        const range = this.Quill.getSelection();
        const index = range ? range.index : this.Quill.getLength();
 
 
        if (fileType === 'video') {
          this.Quill.insertEmbed(index, 'video', {
            url:url,
            controls:'controls',
            width:'100%',
            height:'auto'
          });
        } else if (fileType === 'image') {
          this.Quill.insertEmbed(index, "image", url);
        } else {
          // 如果不是图片或视频,可以处理其他类型或给出提示
          this.$Message.warning('不支持的文件类型');
          return;
        }
        console.log(this.activityFrom.activityContent)
        this.Quill.setSelection(index + 1);
        this.$Message.success('上传成功')
      }else{
        this.$Message.error(res.msg)
      }
    }).catch(() => {
      this.submitLoading = false
    })
  },
    getFileType(file) {
      // 获取文件类型或扩展名
      let type, extension;
 
      if (file instanceof File) {
        // 如果是File对象
        type = file.type;
        const name = file.name.toLowerCase();
        extension = name.substring(name.lastIndexOf('.') + 1);
      } else if (typeof file === 'string') {
        // 如果是字符串(文件名或URL)
        const name = file.toLowerCase();
        extension = name.substring(name.lastIndexOf('.') + 1);
 
        // 尝试从URL中提取MIME类型(如果有)
        const mimeMatch = file.match(/^data:(.+?);/);
        if (mimeMatch) {
          type = mimeMatch[1];
        }
      } else {
        return 'unknown';
      }
 
      // 常见图片和视频的MIME类型
      const imageTypes = [
        'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/bmp', 'image/svg+xml'
      ];
 
      const videoTypes = [
        'video/mp4', 'video/webm', 'video/ogg', 'video/quicktime', 'video/x-msvideo', 'video/x-matroska'
      ];
 
      // 检查MIME类型
      if (type) {
        if (imageTypes.includes(type)) return 'image';
        if (videoTypes.includes(type)) return 'video';
      }
 
      // 常见图片和视频的扩展名
      const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'];
      const videoExtensions = ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv'];
 
      // 检查文件扩展名
      if (extension) {
        if (imageExtensions.includes(extension)) return 'image';
        if (videoExtensions.includes(extension)) return 'video';
      }
 
      return 'unknown';
    },
 
  handleAuditSubmit(activityId) {
    console.log(this.auditForm)
    this.$refs.auditForm.validate(valid => {
      if (valid) {
        const form = {
          activityId: activityId,
          audit: this.auditForm.audit,
          remarks: this.auditForm.remarks,
        }
        // 提交时 auditForm.audit 已经是数字类型(0 或 1)
        auditActivity(form).then(res => {
          if (res.code === 200) {
            // 为每一行添加loading状态
            this.$Message.success(res.msg);
            this.getActivityList();
            this.closeAuditModel();
          }else{
            this.$Message.error(res.msg)
          }
        })
      }
    });
 
 
  },
  openAuditModal(row) {
    this.modelTitle = '活动审核'
    this.auditModelShow = true
    this.activityInfo = row
  },
  closeAuditModel() {
    this.$refs.auditForm.resetFields();
    this.auditModelShow = false
  },
    escapeStringHTML(str) {
      if (!str) return str;
      str = str.replace(/&lt;/g, '<');
      str = str.replace(/&gt;/g, '>');
      return str;
    },
    // 提交
  detail(row) {
    this.modelTitle = '活动详情'
    this.infoModelShow = true
    this.activityInfo = row
    this.activityInfo.activityContent = this.escapeStringHTML(this.activityInfo.activityContent);
    this.$nextTick(() => {
      this.processVideos();
    });
 
  },
    processVideos() {
      const videos = this.$el.querySelectorAll('video');
      videos.forEach(video => {
        // 确保视频元素有必要的属性
        video.setAttribute('controls', '');
        video.setAttribute('playsinline', ''); // 针对移动端
        video.load();
      });
  },
  // 获取富文本编辑器的内容
  // 初始化数据
  init() {
    this.getActivityList()
  },
 
  // 获取活动列表
  getActivityList() {
    this.loading = true
    getActivityList(this.searchForm).then(res => {
      this.loading = false
      if (res.code === 200) {
        // 为每一行添加loading状态
        this.activityList = res.data.map(item => ({
          ...item,
          recommendLoading: false,
          statusLoading: false
        }))
        this.total = res.total
      }else{
        this.$Message.error(res.msg)
      }
    }).catch(() => {
      this.loading = false
    })
  },
 
  // 搜索活动
  handleSearch(type, value) {
    if (type === 'reportStart') {
      this.searchForm.reportStartTime = value
    } else if (type === 'reportEnd') {
      this.searchForm.reportEndTime = value
    }
 
    this.searchForm.pageNumber = 1
    this.getActivityList()
  },
 
  // 重置搜索
  resetSearch() {
    this.$refs.searchForm.resetFields()
    this.searchForm.pageNumber = 1
    this.getActivityList()
  },
 
  // 改变页码
  changePage(page) {
    this.searchForm.pageNumber = page
    this.getActivityList()
  },
 
  // 改变每页条数
  changePageSize(pageSize) {
    this.searchForm.pageNumber = 1
    this.searchForm.pageSize = pageSize
    this.getActivityList()
  },
 
  // 表格选择变化
  showSelect(selection) {
    this.selectList = selection.map(item => item.id)
    this.selectCount = selection.length
  },
 
  // 打开新增模态框
  openAdd() {
    this.modelTitle = '新增活动'
    this.modelShow = true
    this.coverType = '输入文字封面'
    this.file = null
    this.$refs.form.resetFields()
    this.activityFrom.id = ''
  },
 
  // 打开编辑模态框
  openEdit(row) {
    this.modelTitle = '编辑活动'
    this.modelShow = true
    this.$nextTick(() => {
      this.$refs.form.resetFields()
      console.log(row)
      // 填充表单数据
      this.activityFrom = {
        id: row.id,
        activityName: row.activityName,
        activityType: row.activityType,
        reportTime: [
          this.formatDate(row.reportStartTime, 'YYYY-MM-DD HH:mm:ss'),
          this.formatDate(row.reportEndTime, 'YYYY-MM-DD HH:mm:ss')
        ],
        time: [
          this.formatDate(row.startTime, 'YYYY-MM-DD HH:mm:ss'),
          this.formatDate(row.endTime, 'YYYY-MM-DD HH:mm:ss')
        ],
        activityContent: row.activityContent,
        cover: row.cover,
        coverType: row.coverType,
        status: row.status,
        reportStartTime: row.reportStartTime,
        reportEndTime: row.reportEndTime,
        startTime: row.startTime,
        endTime: row.endTime,
        recommend: row.recommend,
        limitUserNum: row.limitUserNum,
        activityLocation: row.activityLocation
      }
      // 设置封面类型
      this.coverType = row.coverType === 'text' ? '输入文字封面' : '选择文件封面'
    })
  },
 
  infoModelClose() {
    this.infoModelShow = false
  },
  // 关闭模态框
  modelClose() {
    this.modelShow = false
    this.file = null
    this.submitLoading = false
    this.handleRemove();
    this.$refs.form.resetFields()
  },
 
  // 保存或更新活动
  saveOrUpdate() {
    // 设置封面类型
    this.activityFrom.coverType = this.coverType === '输入文字封面' ? 'text' :
      this.file ? this.getFileCategory(this.file.type) :
        this.activityFrom.coverType
 
    this.$refs.form.validate(valid => {
      if (valid) {
        this.submitLoading = true
 
        // 处理时间数据
        if (this.activityFrom.reportTime && this.activityFrom.reportTime.length === 2) {
          this.activityFrom.reportStartTime = this.formatDate(this.activityFrom.reportTime[0], 'YYYY-MM-DD HH:mm:ss')
          this.activityFrom.reportEndTime = this.formatDate(this.activityFrom.reportTime[1], 'YYYY-MM-DD HH:mm:ss')
        }
 
        if (this.activityFrom.time && this.activityFrom.time.length === 2) {
          this.activityFrom.startTime = this.formatDate(this.activityFrom.time[0], 'YYYY-MM-DD HH:mm:ss')
          this.activityFrom.endTime = this.formatDate(this.activityFrom.time[1], 'YYYY-MM-DD HH:mm:ss')
        }
 
        const api = this.activityFrom.id ? editActivity : addActivity
        api(this.activityFrom).then(res => {
          this.submitLoading = false
          if (res.code === 200) {
            this.$Message.success(res.msg)
            this.modelClose()
            this.getActivityList()
          }else{
            this.$Message.error(res.msg)
          }
        }).catch(() => {
          this.submitLoading = false
        })
      }
    })
  },
 
  // 删除活动
  delById(row) {
    this.$Modal.confirm({
      title: '确认删除',
      content: `确定要删除活动 "${row.activityName}" 吗?`,
      onOk: () => {
        //TODO 先判断活动是否发布,发布则需要先下架
 
        delActivityById(row.id).then(res => {
          if (res.code === 200) {
            this.$Message.success(res.msg)
            this.getActivityList()
          }else{
            this.$Message.error(res.msg)
          }
        })
      }
    })
  },
 
  // 批量删除
  delBatch() {
    //TODO 先判断活动是否发布,发布则需要先下架
    if (this.selectCount === 0) {
      this.$Message.warning('请至少选择一条数据')
      return
    }
 
    this.$Modal.confirm({
      title: '确认删除',
      content: `确定要删除选中的 ${this.selectCount} 条数据吗?`,
      onOk: () => {
        delActivityBatch(this.selectList).then(res => {
          if (res.code === 200) {
            this.$Message.success(res.msg)
            this.selectList = []
            this.selectCount = 0
            this.getActivityList()
          } else {
            this.$Message.error(res.msg || '删除失败')
          }
        })
      }
    })
  },
 
  // 改变推荐状态
  changeRecommend(row, action) {
    row.recommendLoading = true
    const recommend = action === '推荐'
 
    activityChangeRecommend({
      id: row.id,
      recommend: recommend
    }).then(res => {
      row.recommendLoading = false
      if (res.code === 200) {
        this.$Message.success(res.msg)
        row.recommend = recommend
      }else{
        this.$Message.error(res.msg)
      }
    }).catch(() => {
      row.recommendLoading = false
    })
  },
 
  // 改变活动状态
  changeStatus(row, action) {
    //判断是否存在审核记录
    if (row.audit === null) {
      this.$Message.error("发布前请先审核!")
      return
    }
 
    row.statusLoading = true
    const publish = action === '发布'
 
    activityChangeStatus({
      id: row.id,
      publish: publish
    }).then(res => {
      row.statusLoading = false
      if (res.code === 200) {
        this.$Message.success(res.msg)
        row.publish = publish
      }else{
        this.$Message.error(res.msg)
      }
    }).catch(() => {
      row.statusLoading = false
    })
  },
 
  // 打开报名人员模态框
  openMembersModal(row) {
    this.membersModelTitle = `${row.activityName} - 报名人员`
    this.membersModelShow = true
    this.memberForm.id = row.id
    this.memberForm.pageNumber = 1
    this.activityMembersPage()
  },
 
  // 获取报名人员列表
  activityMembersPage() {
    this.membersLoading = true
    activityMembersPage(this.memberForm).then(res => {
      this.membersLoading = false
      if (res.code === 200) {
        this.membersList = res.data
        this.memberTotal = res.total
      }else{
        this.$Message.error(res.msg)
      }
    }).catch(() => {
      this.membersLoading = false
    })
  },
 
  // 改变报名人员页码
  memberChangePage(page) {
    this.memberForm.pageNumber = page
    this.activityMembersPage()
  },
 
  // 改变报名人员每页条数
  memberChangePageSize(pageSize) {
    this.memberForm.pageNumber = 1
    this.memberForm.pageSize = pageSize
    this.activityMembersPage()
  },
 
  // 关闭报名人员模态框
  membersModelClose() {
    this.membersModelShow = false
  },
 
  // 封面类型变化处理
  handleCoverTypeChange(type) {
    if (type === '选择文件封面') {
      this.activityFrom.cover = ''
    } else {
      this.file = null
    }
  },
  // 文件上传前处理
  handleBeforeUpload(file) {
    const fileType = file.type
    const isImage = fileType.includes('image')
    const isVideo = fileType.includes('video')
 
    if (!isImage && !isVideo) {
      this.$Message.error('请上传图片或视频文件')
      return false
    }
 
    if (file.size > 20 * 1024 * 1024) {
      this.$Message.error('文件大小不能超过20MB')
      return false
    }
 
    this.file = file
    this.uploadFile()
    return false
  },
  // 上传文件
  uploadFile() {
    if (!this.file) return
 
    this.submitLoading = true
    const formData = new FormData()
    formData.append('file', this.file)
 
    uploadFileByLmk(formData).then(res => {
      this.submitLoading = false
      if (res.code === 200) {
        this.activityFrom.cover = res.data.fileKey
        this.$Message.success('上传成功')
      }else{
        this.$Message.error(res.msg)
      }
    }).catch(() => {
      this.submitLoading = false
    })
  },
 
  // 删除文件
  handleRemove() {
    //点击关闭窗口时确保文件已被清除
    if (this.file === null) {
      return;
    }
    if (!this.activityFrom.cover) {
      this.file = null
      return
    }
    delByKey(this.activityFrom.cover).then(res => {
      if (res.code === 200) {
        this.file = null
        this.activityFrom.cover = ''
      }else{
        this.$Message.error(res.msg)
      }
    })
  },
 
  // 预览图片
  previewImage(url) {
    this.previewImageUrl = url
    this.previewVisible = true
  },
 
  // 获取文件分类
  getFileCategory(mimeType) {
    const typeMap = {
      'image': 'image',
      'video': 'video',
      'audio': 'audio',
      'application': 'application'
    }
 
    const typePrefix = mimeType.split('/')[0]
    return typeMap[typePrefix] || 'unknown'
  },
 
  // 格式化日期
  formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
    if (!date) return '';
 
    const d = new Date(date);
    if (isNaN(d.getTime())) return '';
 
    const padZero = (num) => String(num).padStart(2, '0'); // 更可靠的补零方法
 
    const year = d.getFullYear();
    const month = padZero(d.getMonth() + 1); // 月份 0-11 → +1
    const day = padZero(d.getDate());
    const hours = padZero(d.getHours());
    const minutes = padZero(d.getMinutes());
    const seconds = padZero(d.getSeconds());
    return format
      .replace('YYYY', year)
      .replace('MM', month)
      .replace('DD', day)
      .replace('HH', hours)
      .replace('mm', minutes)
      .replace('ss', seconds);
  },
 
  // 验证报名时间
  validateReportTime(rule, value, callback) {
    if (!value || value.length !== 2) {
      callback(new Error('请选择完整的报名时间段'))
      return
    }
 
    const [start, end] = value
    if (new Date(start) >= new Date(end)) {
      callback(new Error('报名结束时间必须晚于开始时间'))
      return
    }
 
    if (this.activityFrom.time && this.activityFrom.time.length === 2) {
      const activityStart = this.activityFrom.time[0]
      if (new Date(end) > new Date(activityStart)) {
        callback(new Error('报名结束时间不能晚于活动开始时间'))
        return
      }
    }
 
    callback()
  },
 
  // 验证活动时间
  validateActivityTime(rule, value, callback) {
    if (!value || value.length !== 2) {
      callback(new Error('请选择完整的活动时间段'))
      return
    }
 
    const [start, end] = value
    if (new Date(start) >= new Date(end)) {
      callback(new Error('活动结束时间必须晚于开始时间'))
      return
    }
 
    if (this.activityFrom.reportTime && this.activityFrom.reportTime.length === 2) {
      const reportEnd = this.activityFrom.reportTime[1]
      if (new Date(reportEnd) > new Date(start)) {
        callback(new Error('活动开始时间必须晚于报名结束时间'))
        return
      }
    }
 
    callback()
    }
  },
}
</script>
 
<style lang="scss" scoped>
.quill-editor {
 
}
 
.ql-editor .ql-video {
  width: 50%;
  height: auto; /* 根据你的需求调整高度 */
  max-width: 100%;
}
 
.activity-management {
  .search-form {
    padding: 16px;
    background: #f8f8f9;
    border-radius: 4px;
    margin-bottom: 16px;
 
    .ivu-form-item {
      margin-bottom: 16px;
      margin-right: 16px;
    }
 
    .search-btn {
      margin-left: 8px;
    }
  }
 
  .operation {
    margin-bottom: 16px;
 
    .ivu-btn {
      margin-right: 8px;
    }
  }
 
  .activity-table {
    .media-container {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100px;
 
      .thumbnail {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
        cursor: pointer;
        transition: all 0.3s;
 
        &:hover {
          transform: scale(1.05);
          box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
        }
      }
 
      .video-player {
        max-width: 100%;
        max-height: 100px;
        background: #000;
      }
 
      .text-cover {
        padding: 8px;
        background: #f8f8f9;
        border-radius: 4px;
        max-width: 100%;
        word-break: break-all;
      }
    }
 
    .action-btns {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
 
      .ivu-btn {
        margin: 4px;
        font-size: 12px;
        padding: 2px 6px;
        min-width: 60px;
      }
    }
  }
 
  .page-footer {
    margin-top: 16px;
    padding: 8px 0;
  }
 
  .members-modal {
    .members-table {
      margin-bottom: 16px;
    }
  }
 
  .upload-file-info {
    margin-top: 8px;
    padding: 8px;
    background: #f8f8f9;
    border-radius: 4px;
  }
 
  .upload-tip {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
  }
}
.detail-container {
  padding: 16px;
}
 
.detail-item {
  margin-bottom: 18px;
  line-height: 1.5;
 
  label {
    display: inline-block;
    width: 100px;
    color: #666;
    font-weight: bold;
    vertical-align: top;
  }
 
  span {
    display: inline-block;
    width: calc(100% - 110px);
  }
}
 
.activity-content {
  border: 1px solid #dcdee2;
  border-radius: 4px;
  padding: 12px;
  min-height: 100px;
  margin-top: 8px;
}
/*
  文字大小
*/
.ql-snow .ql-picker.ql-size{
  width: 70px;  // 菜单栏占比宽度
}
/*
  字体
*/
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value=SimHei]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value=SimHei]::before {
  content: "黑体";
  font-family: "SimHei";
}
 
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value=Microsoft-YaHei]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value=Microsoft-YaHei]::before {
  content: "微软雅黑";
  font-family: "Microsoft YaHei";
}
 
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value=KaiTi]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value=KaiTi]::before {
  content: "楷体";
  font-family: "KaiTi";
}
 
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value=FangSong]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value=FangSong]::before {
  content: "仿宋";
  font-family: "FangSong";
}
 
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value=Arial]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value=Arial]::before {
  content: "Arial";
  font-family: "Arial";
}
 
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value=Times-New-Roman]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value=Times-New-Roman]::before {
  content: "Times New Roman";
  font-family: "Times New Roman";
}
 
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value=sans-serif]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value=sans-serif]::before {
  content: "sans-serif";
  font-family: "sans-serif";
}
 
.ql-font-SimSun {
  font-family: "SimSun";
}
 
.ql-font-SimHei {
  font-family: "SimHei";
}
 
.ql-font-Microsoft-YaHei {
  font-family: "Microsoft YaHei";
}
 
.ql-font-KaiTi {
  font-family: "KaiTi";
}
 
.ql-font-FangSong {
  font-family: "FangSong";
}
 
.ql-font-Arial {
  font-family: "Arial";
}
 
.ql-font-Times-New-Roman {
  font-family: "Times New Roman";
}
 
.ql-font-sans-serif {
  font-family: "sans-serif";
}
</style>