WXL (wul)
5 天以前 5319d5b95497b5b546947ac340c14c71e5b54ca6
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
<template>
  <div class="patient-medication-management">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <!-- 搜索区域 -->
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
          <el-form-item label="患者姓名" prop="patientName">
            <el-input
              v-model="queryParams.patientName"
              placeholder="请输入患者姓名"
              clearable
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="药品名称" prop="drugName">
            <el-input
              v-model="queryParams.drugName"
              placeholder="请输入药品名称"
              clearable
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="用药状态" prop="medicationStatus">
            <el-select v-model="queryParams.medicationStatus" placeholder="请选择状态" clearable style="width: 200px">
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="medium" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
 
        <!-- 操作按钮区域 -->
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="medium"
              @click="handleAssignMedication"
            >分配用药</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-close"
              size="medium"
              :disabled="multiple"
              @click="handleStopMedication"
            >停止用药</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="medium"
              :disabled="multiple"
              @click="handleDelete"
            >删除记录</el-button>
          </el-col>
        </el-row>
 
        <!-- 数据表格 -->
        <el-table v-loading="loading" :data="medicationList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="记录ID" align="center" prop="id" width="80" />
          <el-table-column label="患者信息" align="center" width="200">
            <template slot-scope="scope">
              <div class="patient-info">
                <div class="patient-name">{{ scope.row.patientName }}</div>
                <div class="patient-details">
                  {{ scope.row.patientAge }}岁 / {{ scope.row.patientGender === '1' ? '男' : '女' }} / {{ scope.row.patientNo }}
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="过敏信息" align="center" width="120">
            <template slot-scope="scope">
              <el-tag
                v-if="scope.row.allergyHistory"
                type="danger"
                size="small"
                @click="showAllergyDetail(scope.row)"
              >有过敏史</el-tag>
              <span v-else class="no-allergy">无</span>
            </template>
          </el-table-column>
          <el-table-column label="药品信息" align="center" min-width="200">
            <template slot-scope="scope">
              <div class="drug-info">
                <div class="drug-name">{{ scope.row.drugName }} ({{ scope.row.drugSpecification }})</div>
                <div class="dosage-info">{{ scope.row.dosage }} {{ scope.row.dosageUnit }} / 次</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用法用量" align="center" width="150">
            <template slot-scope="scope">
              <div class="usage-info">
                <div>{{ scope.row.frequency }}次/日</div>
                <div>{{ scope.row.usageMethod }}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用药时间" align="center" width="200">
            <template slot-scope="scope">
              <div class="time-info">
                <div>开始: {{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</div>
                <div v-if="scope.row.endTime">结束: {{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</div>
                <div v-else>长期用药</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用药状态" align="center" width="100">
            <template slot-scope="scope">
              <el-tag
                :type="getStatusTagType(scope.row.medicationStatus)"
                size="small"
              >
                {{ getStatusText(scope.row.medicationStatus) }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作医生" align="center" width="120" prop="prescribingDoctor" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-close"
                :class="{ 'stop-button': scope.row.medicationStatus === '1' }"
                @click="handleSingleStop(scope.row)"
                :disabled="scope.row.medicationStatus === '0'"
              >{{ scope.row.medicationStatus === '1' ? '停止' : '已停止' }}</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleViewDetail(scope.row)"
              >详情</el-button>
            </template>
          </el-table-column>
        </el-table>
 
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
 
    <!-- 分配用药对话框 -->
    <el-dialog :title="assignTitle" :visible.sync="assignOpen" width="900px" append-to-body>
      <el-form ref="assignForm" :model="assignForm" :rules="assignRules" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="选择患者" prop="patientId">
              <el-select
                v-model="assignForm.patientId"
                placeholder="请选择患者"
                filterable
                @change="handlePatientChange"
                style="width: 100%"
              >
                <el-option
                  v-for="patient in patientOptions"
                  :key="patient.id"
                  :label="`${patient.name} (${patient.patientNo})`"
                  :value="patient.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="患者信息">
              <div v-if="selectedPatient" class="patient-detail">
                <div>姓名: {{ selectedPatient.name }}</div>
                <div>年龄: {{ selectedPatient.age }}岁</div>
                <div>病历号: {{ selectedPatient.patientNo }}</div>
                <div v-if="selectedPatient.allergyHistory" class="allergy-warning">
                  过敏史: {{ selectedPatient.allergyHistory }}
                </div>
              </div>
              <span v-else class="placeholder">请先选择患者</span>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="药品名称" prop="drugId">
              <el-select
                v-model="assignForm.drugId"
                placeholder="请选择药品"
                filterable
                @change="handleDrugChange"
                style="width: 100%"
              >
                <el-option
                  v-for="drug in drugOptions"
                  :key="drug.id"
                  :label="drug.name"
                  :value="drug.id"
                >
                  <span>{{ drug.name }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">
                    {{ drug.specification }} | 库存: {{ drug.stock }}
                  </span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="药品规格">
              <el-input v-model="selectedDrug.specification" readonly />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="单次剂量" prop="dosage">
              <el-input-number
                v-model="assignForm.dosage"
                :min="0.1"
                :max="10"
                :step="0.1"
                controls-position="right"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="剂量单位" prop="dosageUnit">
              <el-select v-model="assignForm.dosageUnit" style="width: 100%">
                <el-option label="片" value="片" />
                <el-option label="粒" value="粒" />
                <el-option label="mg" value="mg" />
                <el-option label="ml" value="ml" />
                <el-option label="g" value="g" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用药频次" prop="frequency">
              <el-select v-model="assignForm.frequency" style="width: 100%">
                <el-option label="每日1次" value="1" />
                <el-option label="每日2次" value="2" />
                <el-option label="每日3次" value="3" />
                <el-option label="每日4次" value="4" />
                <el-option label="按需服用" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="用药方法" prop="usageMethod">
              <el-select v-model="assignForm.usageMethod" style="width: 100%">
                <el-option label="口服" value="口服" />
                <el-option label="静脉注射" value="静脉注射" />
                <el-option label="肌肉注射" value="肌肉注射" />
                <el-option label="皮下注射" value="皮下注射" />
                <el-option label="外用" value="外用" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用药时间" prop="durationType">
              <el-radio-group v-model="assignForm.durationType">
                <el-radio label="1">长期用药</el-radio>
                <el-radio label="2">指定周期</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-row :gutter="20" v-if="assignForm.durationType === '2'">
          <el-col :span="12">
            <el-form-item label="开始时间" prop="startTime">
              <el-date-picker
                v-model="assignForm.startTime"
                type="datetime"
                placeholder="选择开始时间"
                style="width: 100%"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束时间" prop="endTime">
              <el-date-picker
                v-model="assignForm.endTime"
                type="datetime"
                placeholder="选择结束时间"
                style="width: 100%"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
          </el-col>
        </el-row>
 
        <el-form-item label="用药说明" prop="instructions">
          <el-input
            type="textarea"
            :rows="3"
            v-model="assignForm.instructions"
            placeholder="请输入用药注意事项、特殊说明等"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAssignForm">确 定</el-button>
        <el-button @click="cancelAssign">取 消</el-button>
      </div>
    </el-dialog>
 
    <!-- 停止用药对话框 -->
    <el-dialog :title="stopTitle" :visible.sync="stopOpen" width="600px" append-to-body>
      <el-form ref="stopForm" :model="stopForm" :rules="stopRules" label-width="100px">
        <el-form-item label="停止原因" prop="stopReason">
          <el-select v-model="stopForm.stopReason" placeholder="请选择停止原因" style="width: 100%">
            <el-option label="疗程结束" value="疗程结束" />
            <el-option label="不良反应" value="不良反应" />
            <el-option label="疗效不佳" value="疗效不佳" />
            <el-option label="患者要求" value="患者要求" />
            <el-option label="医生建议" value="医生建议" />
            <el-option label="其他原因" value="其他" />
          </el-select>
        </el-form-item>
 
        <el-form-item label="详细说明" prop="stopDescription">
          <el-input
            type="textarea"
            :rows="4"
            v-model="stopForm.stopDescription"
            placeholder="请详细说明停止用药的原因和情况"
          />
        </el-form-item>
 
        <el-form-item label="停止时间" prop="stopTime">
          <el-date-picker
            v-model="stopForm.stopTime"
            type="datetime"
            placeholder="选择停止时间"
            style="width: 100%"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitStopForm">确 定</el-button>
        <el-button @click="cancelStop">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { parseTime } from '@/utils/ruoyi'
 
export default {
  name: "PatientMedicationManagement",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用药记录数据
medicationList: [
  {
    id: 1,
    patientId: 'P1001',
    patientName: '张清扬',
    patientAge: 65,
    patientGender: '1',
    patientNo: '20241209001',
    allergyHistory: '青霉素过敏',
    drugId: 'D1001',
    drugName: '阿司匹林肠溶片',
    drugSpecification: '100mg*30片/盒',
    dosage: 1,
    dosageUnit: '片',
    frequency: '1',
    usageMethod: '口服',
    startTime: '2024-12-01 08:00:00',
    endTime: '',
    durationType: '1',
    instructions: '饭后服用,注意胃肠道反应。长期服用需定期检查血常规。',
    medicationStatus: '1',
    prescribingDoctor: '李成白',
    stopReason: '',
    stopDescription: ''
  },
  {
    id: 2,
    patientId: 'P1001',
    patientName: '张清扬',
    patientAge: 65,
    patientGender: '1',
    patientNo: '20241209001',
    allergyHistory: '青霉素过敏',
    drugId: 'D1002',
    drugName: '阿托伐他汀钙片',
    drugSpecification: '20mg*7片/盒',
    dosage: 1,
    dosageUnit: '片',
    frequency: '1',
    usageMethod: '口服',
    startTime: '2024-11-20 20:00:00',
    endTime: '',
    durationType: '1',
    instructions: '每晚睡前服用。注意监测肝功能,如有肌肉酸痛请及时就医。',
    medicationStatus: '1',
    prescribingDoctor: '李成白',
    stopReason: '',
    stopDescription: ''
  },
  {
    id: 3,
    patientId: 'P2001',
    patientName: '王芳',
    patientAge: 33,
    patientGender: '0',
    patientNo: '20241115002',
    allergyHistory: '无',
    drugId: 'D1003',
    drugName: '泼尼松片',
    drugSpecification: '5mg*100片/瓶',
    dosage: 2,
    dosageUnit: '片',
    frequency: '3',
    usageMethod: '口服',
    startTime: '2024-12-05 09:00:00',
    endTime: '2024-12-20 09:00:00',
    durationType: '2',
    instructions: '早、中、晚餐后服用。需严格遵医嘱逐渐减量,不可突然停药。',
    medicationStatus: '0',
    prescribingDoctor: '刘翊惠',
    stopReason: '疗程结束',
    stopDescription: '标准疗程用药完毕,血小板计数已恢复正常范围。'
  },
  {
    id: 4,
    patientId: 'P2001',
    patientName: '王芳',
    patientAge: 33,
    patientGender: '0',
    patientNo: '20241115002',
    allergyHistory: '无',
    drugId: 'D1004',
    drugName: '多糖铁复合物胶囊',
    drugSpecification: '150mg*10粒/盒',
    dosage: 1,
    dosageUnit: '粒',
    frequency: '2',
    usageMethod: '口服',
    startTime: '2024-12-05 09:00:00',
    endTime: '',
    durationType: '1',
    instructions: '餐后服用,可减轻胃肠道刺激。服药后可能出现黑便,属正常现象。',
    medicationStatus: '1',
    prescribingDoctor: '刘翊惠',
    stopReason: '',
    stopDescription: ''
  },
  {
    id: 5,
    patientId: 'P3001',
    patientName: '李伟',
    patientAge: 58,
    patientGender: '1',
    patientNo: '20241022005',
    allergyHistory: '磺胺类药物过敏',
    drugId: 'D1005',
    drugName: '盐酸二甲双胍片',
    drugSpecification: '0.5g*20片/板',
    dosage: 1,
    dosageUnit: '片',
    frequency: '2',
    usageMethod: '口服',
    startTime: '2024-10-22 08:00:00',
    endTime: '',
    durationType: '1',
    instructions: '随餐或餐后立即服用,以减少胃肠道不适。',
    medicationStatus: '1',
    prescribingDoctor: '张孟涵',
    stopReason: '',
    stopDescription: ''
  },
  {
    id: 6,
    patientId: 'P4001',
    patientName: '赵磊',
    patientAge: 70,
    patientGender: '1',
    patientNo: '20241202011',
    allergyHistory: '海鲜过敏',
    drugId: 'D1006',
    drugName: '呋塞米片',
    drugSpecification: '20mg*100片/瓶',
    dosage: 1,
    dosageUnit: '片',
    frequency: '1',
    usageMethod: '口服',
    startTime: '2024-12-02 07:00:00',
    endTime: '',
    durationType: '1',
    instructions: '晨起服用,避免夜间多次起夜。注意监测电解质水平。',
    medicationStatus: '1',
    prescribingDoctor: '吴思翰',
    stopReason: '',
    stopDescription: ''
  },
  {
    id: 7,
    patientId: 'P5001',
    patientName: '周华',
    patientAge: 52,
    patientGender: '0',
    patientNo: '20241128009',
    allergyHistory: '无',
    drugId: 'D1007',
    drugName: '硝苯地平控释片',
    drugSpecification: '30mg*7片/盒',
    dosage: 1,
    dosageUnit: '片',
    frequency: '1',
    usageMethod: '口服',
    startTime: '2024-11-28 08:00:00',
    endTime: '',
    durationType: '1',
    instructions: '整片吞服,不可嚼碎或掰开。',
    medicationStatus: '1',
    prescribingDoctor: '陈政倩',
    stopReason: '',
    stopDescription: ''
  }
],
      // 分配用药弹出层
      assignOpen: false,
      assignTitle: "",
      // 停止用药弹出层
      stopOpen: false,
      stopTitle: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientName: undefined,
        drugName: undefined,
        medicationStatus: undefined
      },
      // 分配用药表单
      assignForm: {},
      // 停止用药表单
      stopForm: {},
      // 选中患者信息
      selectedPatient: null,
      // 选中药品信息
      selectedDrug: {},
      // 患者选项
      patientOptions: [
        {
          id: 'P1001',
          name: '张三',
          age: 65,
          patientNo: '20241209001',
          allergyHistory: '青霉素过敏'
        }
      ],
      // 药品选项
      drugOptions: [
        {
          id: 'D1001',
          name: '阿司匹林',
          specification: '100mg',
          stock: 150
        }
      ],
      // 状态选项
      statusOptions: [
        { value: "1", label: "用药中" },
        { value: "0", label: "已停止" }
      ],
      // 表单校验
      assignRules: {
        patientId: [
          { required: true, message: "请选择患者", trigger: "change" }
        ],
        drugId: [
          { required: true, message: "请选择药品", trigger: "change" }
        ],
        dosage: [
          { required: true, message: "请输入单次剂量", trigger: "blur" }
        ],
        frequency: [
          { required: true, message: "请选择用药频次", trigger: "change" }
        ]
      },
      stopRules: {
        stopReason: [
          { required: true, message: "请选择停止原因", trigger: "change" }
        ],
        stopTime: [
          { required: true, message: "请选择停止时间", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    parseTime,
    /** 查询用药记录列表 */
    getList() {
      this.loading = true;
      // 模拟API调用
      setTimeout(() => {
        this.loading = false;
        this.total = this.medicationList.length;
      }, 500);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 分配用药按钮操作 */
    handleAssignMedication() {
      this.resetAssignForm();
      this.assignOpen = true;
      this.assignTitle = "分配用药";
    },
    /** 停止用药按钮操作 */
    handleStopMedication() {
      if (this.ids.length === 0) {
        this.$modal.msgError("请先选择要停止的用药记录");
        return;
      }
      this.resetStopForm();
      this.stopOpen = true;
      this.stopTitle = "停止用药";
    },
    /** 单个停止用药 */
    handleSingleStop(row) {
      this.ids = [row.id];
      this.resetStopForm();
      this.stopForm.patientName = row.patientName;
      this.stopForm.drugName = row.drugName;
      this.stopOpen = true;
      this.stopTitle = `停止用药 - ${row.patientName}`;
    },
    /** 提交分配用药表单 */
    submitAssignForm() {
      this.$refs["assignForm"].validate(valid => {
        if (valid) {
          // 模拟API调用
          const newRecord = {
            id: Math.max(...this.medicationList.map(item => item.id)) + 1,
            ...this.assignForm,
            patientName: this.selectedPatient?.name,
            patientAge: this.selectedPatient?.age,
            patientGender: this.selectedPatient?.gender,
            patientNo: this.selectedPatient?.patientNo,
            allergyHistory: this.selectedPatient?.allergyHistory,
            drugName: this.selectedDrug?.name,
            drugSpecification: this.selectedDrug?.specification,
            medicationStatus: '1',
            prescribingDoctor: '当前用户',
            startTime: this.assignForm.startTime || new Date().toISOString().replace('T', ' ').substr(0, 19)
          };
 
          this.medicationList.unshift(newRecord);
          this.total = this.medicationList.length;
          this.$modal.msgSuccess("分配成功");
          this.assignOpen = false;
        }
      });
    },
    /** 提交停止用药表单 */
    submitStopForm() {
      this.$refs["stopForm"].validate(valid => {
        if (valid) {
          // 更新用药记录状态
          this.medicationList.forEach(item => {
            if (this.ids.includes(item.id)) {
              item.medicationStatus = '0';
              item.endTime = this.stopForm.stopTime;
              item.stopReason = this.stopForm.stopReason;
              item.stopDescription = this.stopForm.stopDescription;
            }
          });
 
          this.$modal.msgSuccess("停止用药成功");
          this.stopOpen = false;
          this.getList();
        }
      });
    },
    /** 患者选择变化 */
    handlePatientChange(patientId) {
      this.selectedPatient = this.patientOptions.find(p => p.id === patientId) || null;
    },
    /** 药品选择变化 */
    handleDrugChange(drugId) {
      this.selectedDrug = this.drugOptions.find(d => d.id === drugId) || {};
    },
    /** 查看详情 */
    handleViewDetail(row) {
      this.$alert(
        `<div>
          <p><strong>患者信息:</strong>${row.patientName} (${row.patientNo})</p>
          <p><strong>药品信息:</strong>${row.drugName} ${row.drugSpecification}</p>
          <p><strong>用法用量:</strong>${row.dosage}${row.dosageUnit}/次,${row.frequency}次/日,${row.usageMethod}</p>
          <p><strong>用药时间:</strong>${this.parseTime(row.startTime, '{y}-{m}-{d}')} - ${row.endTime ? this.parseTime(row.endTime, '{y}-{m}-{d}') : '长期'}</p>
          <p><strong>用药说明:</strong>${row.instructions || '无'}</p>
          ${row.allergyHistory ? `<p><strong>过敏史:</strong><span style="color: red">${row.allergyHistory}</span></p>` : ''}
        </div>`,
        "用药详情",
        {
          dangerouslyUseHTMLString: true,
          customClass: "medication-detail-dialog",
        }
      );
    },
    /** 显示过敏史详情 */
    showAllergyDetail(row) {
      if (row.allergyHistory) {
        this.$alert(`患者 ${row.patientName} 的过敏史:${row.allergyHistory}`, "过敏史详情", {
          confirmButtonText: "确定"
        });
      }
    },
    /** 获取状态标签类型 */
    getStatusTagType(status) {
      const statusMap = {
        '1': 'success', // 用药中
        '0': 'info'     // 已停止
      };
      return statusMap[status] || 'info';
    },
    /** 获取状态文本 */
    getStatusText(status) {
      const statusMap = {
        '1': '用药中',
        '0': '已停止'
      };
      return statusMap[status] || '未知';
    },
    /** 重置分配用药表单 */
    resetAssignForm() {
      this.assignForm = {
        patientId: undefined,
        drugId: undefined,
        dosage: 1,
        dosageUnit: '片',
        frequency: '3',
        usageMethod: '口服',
        durationType: '1',
        startTime: new Date().toISOString().replace('T', ' ').substr(0, 19),
        endTime: undefined,
        instructions: ''
      };
      this.selectedPatient = null;
      this.selectedDrug = {};
      this.resetForm("assignForm");
    },
    /** 重置停止用药表单 */
    resetStopForm() {
      this.stopForm = {
        stopReason: '',
        stopDescription: '',
        stopTime: new Date().toISOString().replace('T', ' ').substr(0, 19)
      };
      this.resetForm("stopForm");
    },
    /** 取消分配用药 */
    cancelAssign() {
      this.assignOpen = false;
      this.resetAssignForm();
    },
    /** 取消停止用药 */
    cancelStop() {
      this.stopOpen = false;
      this.resetStopForm();
    }
  }
};
</script>
 
<style lang="scss" scoped>
.patient-medication-management {
  padding: 20px;
}
 
.patient-info {
  text-align: left;
  .patient-name {
    font-weight: bold;
    margin-bottom: 4px;
  }
  .patient-details {
    font-size: 12px;
    color: #909399;
  }
}
 
.drug-info {
  text-align: left;
  .drug-name {
    font-weight: bold;
    margin-bottom: 4px;
  }
  .dosage-info {
    font-size: 12px;
    color: #67C23A;
  }
}
 
.usage-info, .time-info {
  font-size: 12px;
  line-height: 1.4;
}
 
.allergy-warning {
  color: #F56C6C;
  font-size: 12px;
}
 
.no-allergy {
  color: #909399;
  font-style: italic;
}
 
.patient-detail {
  font-size: 12px;
  line-height: 1.6;
  padding: 8px;
  background: #f5f7fa;
  border-radius: 4px;
}
 
.placeholder {
  color: #c0c4cc;
  font-style: italic;
}
 
.stop-button {
  color: #E6A23C;
  &:hover {
    color: #f56c6c;
  }
}
 
::v-deep .medication-detail-dialog {
  width: 500px;
}
</style>