董国庆
2025-06-16 c67b37d706daedbc7c4efc74ddadc8f591524b46
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
<template>
  <div>
    <Card>
      <el-form ref="form" :model="form" :rules="rules" inline label-position="top">
        <div class="header-title" style="width: 100%">
          <div class="header-title-left">
            <img src="@/assets/public/headercard.png" />
            <div>来源类型</div>
          </div>
        </div>
        <div class="flex" style="margin-bottom: 20px">
          <div class="tabs">
            <div :class="{ active: activeTab === 'strain' }" @click="activeTab = 'strain'">
              来源菌株
            </div>
            <div :class="{ active: activeTab === 'material' }" @click="activeTab = 'material'">
              来源物资
            </div>
          </div>
        </div>
        <!-- 来源菌株 -->
        <el-row v-if="activeTab === 'strain'" :gutter="10">
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item label="菌株编号" prop="strainCode">
              <el-input :disabled="$route.query.isDetail" v-model="form.strainCode" class="w-380"
                placeholder="请输入菌株编号" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item label="菌株名称" prop="strainName">
              <el-input :disabled="$route.query.isDetail" v-model="form.strainName" class="w-380"
                placeholder="请输入菌株名称" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item label="培养基配方" prop="formula">
              <el-input :disabled="$route.query.isDetail" v-model="form.formula" class="w-380" placeholder="请输入培养基配方" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 来源物资 -->
        <el-row v-if="activeTab === 'material'" :gutter="10">
          <el-col :span="24">
            <el-form-item label="来源物资、时间及批号" prop="sourceMaterialTimeBatchNumber">
              <el-input :disabled="$route.query.isDetail" v-model="form.sourceMaterialTimeBatchNumber"
                placeholder="请输入物资编号" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="培养基配方" prop="formula">
              <el-input :disabled="$route.query.isDetail" v-model="form.formula" placeholder="请输入培养基配方" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="分离菌落编号" prop="separateColonyNumber">
              <el-input :disabled="$route.query.isDetail" v-model="form.separateColonyNumber" placeholder="请输入分离菌落编号" />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="header-title" style="margin-top: 20px;">
          <div class="header-title-left">
            <img src="@/assets/public/headercard.png" />
            <div>培养条件</div>
          </div>
        </div>
        <el-row :gutter="10">
          <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
            <el-form-item label="培养基" prop="cultureMedium">
              <el-input :disabled="$route.query.isDetail" v-model="form.cultureMedium" class="w-380"
                placeholder="请输入培养基" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
            <el-form-item label="培养温度" prop="temperature">
              <el-input :disabled="$route.query.isDetail" v-model="form.temperature" class="w-380"
                placeholder="请输入培养温度" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
            <el-form-item label="需氧类型" prop="aerobicType">
              <el-select :disabled="$route.query.isDetail" v-model="form.aerobicType" class="w-380"
                placeholder="请选择需氧类型">
                <el-option label="专性需氧" value="1"></el-option>
                <el-option label="专性厌氧" value="2"></el-option>
                <el-option label="兼性需氧" value="3"></el-option>
                <el-option label="耐氧厌氧" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6">
            <el-form-item label="培养时间" prop="cultureTime">
              <el-input :disabled="$route.query.isDetail" v-model="form.cultureTime" class="w-380"
                placeholder="请输入培养时间" />
              <!-- <el-date-picker v-model="form.cultureTime" class="w-380" placeholder="请选择培养时间" type="date" value-format="yyyy-MM-dd" /> -->
            </el-form-item>
          </el-col>
        </el-row>
        <div class="header-title" style="margin-top: 20px;">
          <div class="header-title-left">
            <img src="@/assets/public/headercard.png" />
            <div>一、培养皿分离记录</div>
          </div>
          <div class="header-title-right">
            <el-button @click="handleAddSeparation" v-if="!$route.query.isDetail && [1, 4].includes(roleType)"
              class="el-icon-circle-plus-outline" type="primary">
              新增培养皿分离记录</el-button>
          </div>
        </div>
        <Table :data="form.separationOfCultureDishesList" :height="null" :queryForm="queryForm" :total="0">
          <el-table-column width="100" type="index" label="培养皿序号" />
          <el-table-column prop="separateBacterialColoniesCode" label="分离菌落编号" />
          <el-table-column prop="handleSignature" label="接种操作人签字">
            <template slot-scope="scope">
              <el-image :preview-src-list="[scope.row.handleSignature]" style="width: 40px;"
                :src="scope.row.handleSignature" alt="操作人签字" />
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="操作时间" />
          <el-table-column prop="address" label="操作" v-if="!$route.query.isDetail">
            <template slot-scope="scope" v-if="[1, 4].includes(roleType)">
              <el-button type="text" @click="handleEditSeparation(scope.row, scope.$index)"
                v-if="!$route.query.isDetail">编辑</el-button>
              <el-button type="text" @click="handleDeleteSeparation(scope.$index)"
                v-if="!$route.query.isDetail">删除</el-button>
            </template>
          </el-table-column>
        </Table>
        <div class="header-title" style="margin-top: 20px;">
          <div class="header-title-left">
            <img src="@/assets/public/headercard.png" />
            <div>二、培养皿生物学形态观察记录</div>
          </div>
          <div class="header-title-right">
            <el-button @click="handleAddObservation" v-if="!$route.query.isDetail && [1, 4].includes(roleType)"
              class="el-icon-circle-plus-outline" type="primary">
              新增观察记录</el-button>
          </div>
        </div>
        <Table :data="form.observationOfPetriDishes" :height="null" :queryForm="queryForm" :total="0">
          <el-table-column prop="separateColonyCode" label="分离菌落编号" />
          <el-table-column prop="strength" label="形状强壮度排名" />
          <el-table-column prop="address" label="操作">
            <template slot-scope="scope">
              <!-- <el-button type="text" @click="handleEditObservation(scope.row)" v-if="!$route.query.isDetail">编辑</el-button> -->
              <el-button type="text" @click="handleEditObservation(scope.row)">形态记录</el-button>
              <el-button type="text" @click="handleDeleteObservation(scope.$index)"
                v-if="!$route.query.isDetail && [1, 4].includes(roleType)">删除</el-button>
            </template>
          </el-table-column>
        </Table>
        <div class="header-title" style="margin-top: 20px;">
          <div class="header-title-left">
            <img src="@/assets/public/headercard.png" />
            <div>三、接种斜面记录</div>
          </div>
          <div class="header-title-right">
            <el-button @click="handleAddInoculation" v-if="!$route.query.isDetail && [1, 4].includes(roleType)"
              class="el-icon-circle-plus-outline" type="primary">
              新增斜面记录</el-button>
          </div>
        </div>
        <el-table :data="form.vaccinationSlopes" border style="width: 100%; margin-bottom: 16px;"
          :span-method="inoculationRowSpan">
          <el-table-column prop="separateColonyCode" label="分离菌落编号" />
          <el-table-column prop="vaccinationSlopeCode" label="接种斜面编号" />
          <el-table-column prop="handleName" label="接种操作人" />
          <el-table-column prop="handleSignature" label="接种操作人签字">
            <template slot-scope="scope">
              <el-image v-if="scope.row.handleSignature" :preview-src-list="[scope.row.handleSignature]"
                style="width: 40px;" :src="scope.row.handleSignature" alt="操作人签字" />
            </template>
          </el-table-column>
          <el-table-column prop="handleTime" label="接种操作时间" />
          <el-table-column prop="handleType" label="入库/废弃">
            <template slot-scope="scope">
              {{ scope.row.handleType === '保存' ? '入库' : '废弃' }}
            </template>
          </el-table-column>
          <el-table-column label="入库总数(只)">
            <template slot-scope="scope">
              <span v-if="scope.$index === firstInoculationOrDiscardIndex">{{ totalInoculationCount }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="preserveSignature" label="菌种保藏人签字">
            <template slot-scope="scope">
              <el-image v-if="scope.row.preserveSignature" :preview-src-list="[scope.row.preserveSignature]"
                style="width: 40px;" :src="scope.row.preserveSignature" alt="操作人签字" />
            </template>
          </el-table-column>
          <el-table-column prop="preserveTime" label="入库保藏/废弃时间" />
          <el-table-column label="操作"
            v-if="[1, 3].includes(roleType) && $route.query.isDetail&& !scope.row.preserveSignature || (!$route.query.isDetail && [4].includes(roleType))">
            <template slot-scope="scope">
              <el-button type="text" @click="handleEditInoculation(scope.row, scope.$index)"
                v-if="!$route.query.isDetail && [1, 4].includes(roleType)">编辑</el-button>
              <el-button type="text" @click="handleConfirmStorageClick(scope.row, scope.$index)"
                v-if="$route.query.isDetail && [3].includes(roleType) && !scope.row.preserveSignature">确认入库</el-button>
              <el-button type="text" @click="handleDeleteInoculation(scope.$index)"
                v-if="!$route.query.isDetail && !scope.row.preserveSignature && [1, 4].includes(roleType)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="header-title" style="margin-top: 20px;">
          <div class="header-title-left">
            <img src="@/assets/public/headercard.png" />
            <div>四、菌种保藏记录</div>
          </div>
          <div class="header-title-right">
            <el-button @click="handleAddPreserve" v-if="!$route.query.isDetail && [1, 4].includes(roleType)"
              class="el-icon-circle-plus-outline" type="primary">
              新增菌种保藏记录</el-button>
          </div>
        </div>
        <Table :data="form.culturePreservations" :height="null" :queryForm="queryForm" :total="0">
          <el-table-column prop="forPreserveCode" label="用于保藏的菌种编号" />
          <el-table-column prop="verificationConclusion" label="实验验证结论" />
          <el-table-column prop="preserveMethod" label="保藏方法" />
          <el-table-column prop="preserveCode" label="保藏菌种编号" />
          <el-table-column prop="handleSignature" label="菌种操作人签字">
            <template slot-scope="scope">
              <el-image v-if="scope.row.handleSignature" :preview-src-list="[scope.row.handleSignature]"
                style="width: 40px;" :src="scope.row.handleSignature" alt="签字" />
            </template>
          </el-table-column>
          <el-table-column prop="handleTime" label="操作人" />
          <el-table-column prop="preserveSignature" label="菌种保藏人签字">
            <template slot-scope="scope">
              <el-image v-if="scope.row.preserveSignature" :preview-src-list="[scope.row.preserveSignature]"
                style="width: 40px;" :src="scope.row.preserveSignature" alt="签字" />
            </template>
          </el-table-column>
          <el-table-column prop="preserveTime" label="保藏时间" />
          <el-table-column label="操作"
            v-if="[1, 3].includes(roleType) && $route.query.isDetail&& !scope.row.preserveSignature || (!$route.query.isDetail && [4].includes(roleType))">
            <template slot-scope="scope">
              <el-button type="text" @click="handleEditPreserve(scope.row, scope.$index)"
                v-if="!$route.query.isDetail && [1, 4].includes(roleType)">编辑</el-button>
              <el-button type="text" @click="handleConfirmPreserve(scope.row, scope.$index)"
                v-if="$route.query.isDetail && [3].includes(roleType) && !scope.row.preserveSignature">确认入库</el-button>
              <el-button type="text" @click="handleDeletePreserve(scope.$index)"
                v-if="!$route.query.isDetail && !scope.row.preserveSignature && [1, 4].includes(roleType)">删除</el-button>
            </template>
          </el-table-column>
        </Table>
        <!-- 弹窗组件 -->
        <SeparationRecordDialog :visible.sync="showSeparationDialog" :editData="editSeparationData"
          @confirm="handleSeparationConfirm" @close="resetSeparationEdit" />
        <SlantRecordDialog :visible.sync="showObservationDialog" :editData="editObservationData"
          @ok="handleObservationConfirm" />
        <InoculationSlopeRecordDialog :visible.sync="showInoculationDialog" :editData="editInoculationData"
          @save="handleInoculationConfirm" />
        <PreserveStrainRecordDialog :visible.sync="showPreserveDialog" :editData="editPreserveData"
          @save="handlePreserveConfirm" />
        <ConfirmStorageDialog :visible.sync="showConfirmStorageDialog" :editData="editInoculationData"
          @confirm="handleConfirmStorage" />
        <ConfirmPreserveDialog :visible.sync="showConfirmPreserveDialog" :editData="editPreserveData"
          @confirm="handleConfirmPreserveSubmit" />
        <div class="end-btn" style="margin-top: 20px;" v-if="!$route.query.isDetail && [3, 4].includes(roleType)">
          <el-button type="primary" @click="handleSubmit(1)">提交</el-button>
          <el-button type="primary" @click="handleSubmit(3)">同步给保藏人</el-button>
          <el-button type="default" @click="handleSubmit(2)">存草稿</el-button>
        </div>
      </el-form>
    </Card>
  </div>
</template>
<script>
import AiEditor from "@/components/AiEditor";
import SeparationRecordDialog from "./separation-record-dialog.vue";
import SlantRecordDialog from "./SlantRecordDialog.vue";
import InoculationSlopeRecordDialog from "./inoculation-slope-record-dialog.vue";
import PreserveStrainRecordDialog from "./preserve-strain-record-dialog.vue";
import ConfirmStorageDialog from "./confirm-storage-dialog.vue";
import ConfirmPreserveDialog from "./confirm-preserve-dialog.vue";
 
import { add, detail, edit, vaccinationSlopesConfirm, culturePreservationsConfirm } from './service'
export default {
  components: {
    AiEditor,
    SeparationRecordDialog,
    SlantRecordDialog,
    InoculationSlopeRecordDialog,
    PreserveStrainRecordDialog,
    ConfirmStorageDialog,
    ConfirmPreserveDialog,
 
  },
  name: "AddBreedingRecord",
  data() {
    return {
      form: {
        id: '', // 主键
        strainCode: '', // 菌株编号
        strainName: '', // 菌株名称
        formula: '', // 培养基配方
        cultureMedium: '', // 培养基
        cultureTime: '', // 培养时间
        aerobicType: '', // 需氧类型
        temperature: '', // 培养温度
        status: '', // 状态
        createBy: '', // 创建人
        createTime: '', // 创建时间
        updateBy: '', // 修改人
        updateTime: '', // 修改时间
        disabled: 0, // 是否删除
        preserveSource: '', // 来源类型
        separateColonyNumber: '', // 分离菌落编号
        sourceMaterialTimeBatchNumber: '', // 来源物资存值批号
        // 下面是 array 类型字段
        culturePreservations: [],
        observationOfPetriDishes: [],
        separationOfCultureDishesList: [],
        vaccinationSlopes: [],
        // 兼容原有表单字段
        mediumFormula: '',
        materialCode: '',
        materialName: '',
        materialDescription: '',
        planName: '',
        planCode: '',
        stage: '',
        creator: '',
        approvalComment: '',
        approver: '',
        approveTime: '',
        culturePreservations: [], // 新增:菌种保藏记录数组
      },
      rules: {
        strainCode: [{ required: true, message: "请输入菌株编号", trigger: "blur" }],
        strainName: [{ required: true, message: "请输入菌株名称", trigger: "blur" }],
        formula: [{ required: true, message: "请输入培养基配方", trigger: "blur" }],
        cultureMedium: [{ required: true, message: "请输入培养基", trigger: "blur" }],
        cultureTime: [{ required: true, message: "请输入培养时间", trigger: "blur" }],
        aerobicType: [{ required: true, message: "请输入需氧类型", trigger: "blur" }],
        temperature: [{ required: true, message: "请输入培养温度", trigger: "blur" }],
        sourceMaterialTimeBatchNumber: [{ required: true, message: "请输入物资编号", trigger: "blur" }],
        materialName: [{ required: true, message: "请输入物资名称", trigger: "blur" }],
        materialDescription: [{ required: true, message: "请输入物资描述", trigger: "blur" }],
      },
      activeTab: "strain", // 默认显示来源菌株表单
      fileList: [], // 附件列表
      showChoose: false,
      radio1: 1,
      status: "1",
      remark: "",
      queryForm: {},
      showSeparationDialog: false,
      showObservationDialog: false,
      showInoculationDialog: false,
      showPreserveDialog: false,
      showConfirmStorageDialog: false,
      showConfirmPreserveDialog: false,
      editSeparationIndex: null,
      editSeparationData: null,
      editObservationData: null,
      editInoculationIndex: null,
      editInoculationData: null,
      editPreserveIndex: null,
      editPreserveData: null,
      roleType: Number(JSON.parse(sessionStorage.getItem('userInfo')).roleType || 1),  // 1.超级管理员 2.审批人 3.工程师 4.实验员
    };
  },
  computed: {
    totalInoculationCount() {
      // 只统计入库(保存)
      return this.form.vaccinationSlopes
        .filter(item => item.handleType === '保存')
        .length;
    },
    firstInoculationOrDiscardIndex() {
      // 第一个入库或废弃行
      return this.form.vaccinationSlopes.findIndex(item => item.handleType === '保存' || item.handleType === '废弃');
    }
  },
  mounted() {
    if (this.$route.query.id) {
      this.getDetail()
    }
  },
  methods: {
    async getDetail() {
      const res = await detail({ id: this.$route.query.id })
      if (res.preserveSource == 1) {
        this.activeTab = 'strain'
      } else {
        this.activeTab = 'material'
      }
      res.vaccinationSlopes = res.vaccinationSlopes.map(item => {
        return {
          ...item,
          handleType: item.handleType === 1 ? '保存' : '废弃'
        }
      })
      this.form = res
    },
    handleSeparationConfirm(data) {
      console.log('分离', data)
      if (this.editSeparationIndex !== null) {
        // 编辑
        this.$set(this.form.separationOfCultureDishesList, this.editSeparationIndex, data);
        this.resetSeparationEdit();
      } else {
        // 新增
        console.log('新增', data)
        this.form.separationOfCultureDishesList.push(data);
      }
    },
    handleObservationConfirm(data) {
      if (this.editObservationData) {
        // 编辑
        const index = this.form.observationOfPetriDishes.findIndex(item => item.id === data.id);
        if (index !== -1) {
          this.$set(this.form.observationOfPetriDishes, index, data);
        }
      } else {
        // 新增
        this.form.observationOfPetriDishes.push({
          ...data,
          id: Date.now().toString(), // 临时ID,实际应该由后端生成
        });
      }
      this.editObservationData = null;
    },
    handleInoculationConfirm(data) {
      console.log('接种', data)
      if (this.editInoculationIndex !== null) {
        // 编辑模式:更新指定索引的数据
        this.$set(this.form.vaccinationSlopes, this.editInoculationIndex, {
          ...data,
          // 保留原有的ID和其他必要字段
          id: this.form.vaccinationSlopes[this.editInoculationIndex].id
        });
      } else {
        // 新增模式:添加新数据
        this.form.vaccinationSlopes.push({
          ...data,
          id: Date.now().toString() // 临时ID,实际应该由后端生成
        });
      }
      this.showInoculationDialog = false;
      this.editInoculationIndex = null;
      this.editInoculationData = null;
    },
    handlePreserveConfirm(data) {
      if (this.editPreserveIndex !== null) {
        // 编辑
        this.$set(this.form.culturePreservations, this.editPreserveIndex, data);
      } else {
        // 新增
        this.form.culturePreservations.push(data);
      }
      this.showPreserveDialog = false;
      this.editPreserveIndex = null;
      this.editPreserveData = null;
    },
    handleSubmit(type) {
      if (this.activeTab === 'material') {
        this.form.preserveSource = 2
      } else {
        this.form.preserveSource = 1
      }
 
      if (type == 1) {
        this.form.status = 1
      } else if (type == 3) {
        this.form.status = 2
      } else {
        this.form.status = 3
      }
 
      this.$refs.form.validate(async (valid) => {
        if (!valid) return;
        try {
          if (this.form.vaccinationSlopes.length > 0) {
            let arr = this.form.vaccinationSlopes
            this.form.vaccinationSlopes = arr.map(item => {
              return {
                ...item,
                handleType: item.handleType === '保存' ? 1 : 2,
              }
            })
          }
          if (this.form.id && this.form.isDraft == 0) {
            edit(this.form).then(res => {
              if (res.code === 200) {
                this.$message.success('编辑成功');
                this.$router.back();
              } else {
                this.$message.error('编辑失败');
              }
            })
          } else {
            add(this.form).then(res => {
              if (res.code === 200) {
                this.$message.success('添加成功');
                this.$router.back();
              } else {
                this.$message.error('添加失败');
              }
            });
          }
 
        } catch (e) {
          this.$message.error('添加失败');
        }
      });
    },
    handleEditSeparation(row, index) {
      this.editSeparationIndex = index;
      this.editSeparationData = { ...row };
      this.showSeparationDialog = true;
    },
    handleDeleteSeparation(index) {
      this.form.separationOfCultureDishesList.splice(index, 1);
    },
    resetSeparationEdit() {
      this.editSeparationIndex = null;
      this.editSeparationData = null;
    },
    handleAddSeparation() {
      this.editSeparationIndex = null;
      this.editSeparationData = null;
      this.showSeparationDialog = true;
    },
    handleAddObservation() {
      this.editObservationData = null;
      this.showObservationDialog = true;
    },
    handleEditObservation(row) {
      this.editObservationData = { ...row };
      this.showObservationDialog = true;
    },
    handleDeleteObservation(index) {
      this.form.observationOfPetriDishes.splice(index, 1);
    },
    handleAddInoculation() {
      this.editInoculationIndex = null;
      this.editInoculationData = null;
      this.showInoculationDialog = true;
    },
    handleEditInoculation(row, index) {
      this.editInoculationIndex = index;
      // 深拷贝当前行数据,避免直接修改原数据
      this.editInoculationData = JSON.parse(JSON.stringify(row));
      this.showInoculationDialog = true;
    },
    handleConfirmStorageClick(row, index) {
      this.editInoculationIndex = index;
      // 深拷贝当前行数据,避免直接修改原数据
      this.editInoculationData = JSON.parse(JSON.stringify(row));
      this.showConfirmStorageDialog = true;
    },
    handleConfirmStorage(data) {
      if (data.preserveSignature) {
        vaccinationSlopesConfirm({ id: this.form.vaccinationSlopes[this.editInoculationIndex].id, preserveSignature: data.preserveSignature }).then(res => {
          if (this.editInoculationIndex !== null) {
            this.$set(this.form.vaccinationSlopes, this.editInoculationIndex, {
              ...this.form.vaccinationSlopes[this.editInoculationIndex],
              preserveSignature: data.preserveSignature, // 更新签名数据
              status: '保存' // 更新状态为保存
            });
          }
          this.showConfirmStorageDialog = false;
          this.editInoculationIndex = null;
          this.editInoculationData = null;
        })
      }
    },
    handleDeleteInoculation(index) {
      this.form.vaccinationSlopes.splice(index, 1);
    },
    inoculationRowSpan({ row, rowIndex, columnIndex }) {
      // 入库总数(只)列合并
      if (columnIndex === 6) {
        // 合并所有入库或废弃行
        const mergeCount = this.form.vaccinationSlopes.filter(item => item.handleType === '保存' || item.handleType === '废弃').length;
        if (rowIndex === this.firstInoculationOrDiscardIndex) {
          return { rowspan: mergeCount, colspan: 1 };
        } else if (row.handleType === '保存' || row.handleType === '废弃') {
          return { rowspan: 0, colspan: 0 };
        }
      }
    },
    handleAddPreserve() {
      this.editPreserveIndex = null;
      this.editPreserveData = null;
      this.showPreserveDialog = true;
    },
    handleEditPreserve(row, index) {
      this.editPreserveIndex = index;
      this.editPreserveData = { ...row };
      this.showPreserveDialog = true;
    },
    handleDeletePreserve(index) {
      this.form.culturePreservations.splice(index, 1);
    },
    handleConfirmPreserve(row, index) {
      this.editPreserveIndex = index;
      // 深拷贝当前行数据,避免直接修改原数据
      this.editPreserveData = JSON.parse(JSON.stringify(row));
      this.showConfirmPreserveDialog = true;
    },
    handleConfirmPreserveSubmit(data) {
      if (data.preserveSignature) {
        culturePreservationsConfirm({ id: this.form.culturePreservations[this.editPreserveIndex].id, preserveSignature: data.preserveSignature }).then(res => {
          if (this.editPreserveIndex !== null) {
            this.$set(this.form.culturePreservations, this.editPreserveIndex, {
              ...this.form.culturePreservations[this.editPreserveIndex],
              preserveSignature: data.preserveSignature, // 更新签名数据
              preserveTime: data.preserveTime,
            });
          }
          this.showConfirmPreserveDialog = false;
          this.editPreserveIndex = null;
          this.editPreserveData = null;
        })
      }
 
    },
  },
};
</script>
 
<style lang="less" scoped>
::v-deep(.el-form-item) {
  width: 100%;
 
  .el-input__inner {
    width: 100%;
  }
 
  .w-380 {
    width: 280px;
  }
}
 
.mt-unset {
  margin-top: unset !important;
}
 
.flex {
  display: flex;
}
 
.tabs {
  display: flex;
  align-items: center;
  border: 2px solid rgba(4, 156, 154, 0.5);
  border-radius: 10px;
  padding: 4px;
 
  div {
    width: 183px;
    height: 32px;
    border-radius: 10px;
    text-align: center;
    line-height: 32px;
    font-size: 16px;
    cursor: pointer;
  }
 
  .active {
    background: #ebfefd;
    color: #049c9a;
  }
 
  .inactive {
    background: #fff;
    color: #333333;
  }
}
 
.header-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
  gap: 13px;
 
  .header-title-left {
    display: flex;
    align-items: center;
    gap: 13px;
 
    img {
      width: 12px;
      height: 19px;
    }
 
    div {
      flex-shrink: 0;
      font-weight: bold;
      font-size: 18px;
      color: #222222;
      line-height: 27px;
      font-family: "Source Han Sans CN Bold Bold";
 
    }
 
    span {
      flex-shrink: 0;
      font-weight: bold;
      font-size: 18px;
      color: #222222;
      line-height: 27px;
      font-family: "Source Han Sans CN Bold Bold";
    }
  }
 
  .header-title-left :first-child {
    margin-top: 0;
  }
}
 
.header-title:first-child {
  .header-title-left {
    margin-top: 0;
  }
}
 
.end-btn {
  display: flex;
  align-items: center;
  gap: 10px;
 
  button {
    width: 180px;
    height: 36px;
    // background: #409EFF;
  }
}
 
.member-list {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
 
  .member-list-card {
    width: 340px;
    height: 400px;
    border-radius: 8px;
    border: 1px solid #dcdfe6;
    background: linear-gradient(to bottom,
        rgba(5, 160, 193, 0.2) 0%,
        rgba(5, 242, 194, 0) 70%);
 
    .member-item {
      height: 100%;
      display: flex;
      flex-direction: column;
 
      .member-title {
        margin-top: 20px;
        width: 100%;
        font-family: "Source Han Sans CN Bold Bold";
        font-weight: bold;
        font-size: 16px;
        color: rgba(0, 0, 0, 0.8);
        line-height: 16px;
        text-align: center;
      }
 
      .flex1 {
        flex: 1;
      }
 
      .member-name-box {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
      }
 
      .member-name-box-2 {
        flex: 1;
        padding: 0 20px;
        padding-top: 40px;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
        justify-items: center;
        align-items: start;
      }
 
      .member-name {
        width: 60px;
        height: 60px;
        background: #7d8b79;
        border-radius: 50%;
        text-align: center;
        line-height: 60px;
        font-weight: 500;
        font-size: 16px;
        color: #ffffff;
        margin: 0;
      }
 
      .member-change {
        display: flex;
        justify-content: center;
        padding: 10px 0;
        margin-top: auto;
        cursor: pointer;
 
        .member-change-btn {
          background: #fff1f0;
          border-radius: 4px;
          border: 1px solid #ffccc7;
          padding: 1px 8px;
          font-weight: 400;
          font-size: 12px;
          color: #ff4d4f;
        }
      }
    }
  }
}
</style>