陈婷婷
2025-11-26 9dee5e1c040c5f17f3e49b86f7fc615af0068d95
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
<template>
  <div class="app-container">
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="90%"
      top="5vh"
      @close="handleClose"
    >
      <!-- 表单内容 -->
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-tabs v-model="activeTab">
          <!-- 基本信息标签页 -->
          <el-tab-pane label="基本信息" name="basic">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="单据号" prop="HBillNo">
                  <el-input v-model="form.HBillNo" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="日期" prop="HDate">
                  <el-date-picker
                    v-model="form.HDate"
                    type="date"
                    placeholder="选择日期"
                    style="width: 100%"
                    value-format="yyyy-MM-dd"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="源单类型" prop="HSourceBillType">
                  <el-select v-model="form.HSourceBillType" placeholder="请选择源单类型" style="width: 100%">
                    <el-option
                      v-for="item in sourceBillTypes"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
 
            <el-row :gutter="20">
              <!-- <el-col :span="8">
                <el-form-item label="选单号">
                  <el-input v-model="form.sourceBillNo" placeholder="选单号" style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="handleSelectSourceBill">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                <el-form-item label="供应商" prop="supplier">
                  <el-input v-model="form.HSupName" placeholder="供应商" style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="showSupplierDialog">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="仓管员">
                  <el-input v-model="form.HEmpName" placeholder="仓管员" style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="showEmployeeDialog('Employee')">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col>
            </el-row>
 
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="负责人">
                  <el-input v-model="form.HManagerName" placeholder="负责人" style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="showEmployeeDialog('manager')">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="调入仓库" prop="HWHID">
                  <el-input v-model="form.HWHName" placeholder="调入仓库" readonly style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="handleSelectInWarehouse">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="调出仓库" prop="HSCWHID">
                  <el-input v-model="form.HSCWHName" placeholder="调出仓库" readonly style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="handleSelectOutWarehouse">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col>
            </el-row>
 
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="验收">
                  <el-input v-model="form.HSecManagerName" placeholder="验收" style="width: calc(100% - 50px)" /> 
                   <el-button type="primary" icon="el-icon-search" @click="showEmployeeDialog('inspector')">
                   </el-button>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="保管员">
                  <el-input v-model="form.HKeeperName" placeholder="保管员" style="width: calc(100% - 50px)" />
                  <el-button type="primary" icon="el-icon-search" @click="showEmployeeDialog('keeper')">
                  </el-button>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="部门" prop="HDeptID">
                  <el-input v-model="form.HDeptName" placeholder="部门" readonly style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="handleSelectDept">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col>
            </el-row>
 
            <el-row :gutter="20">
              <!-- <el-col :span="8">
                <el-form-item label="项目代码">
                  <el-input v-model="form.HProNumber" placeholder="项目代码" readonly style="width: calc(100% - 50px)" />
                  <el-button type="primary" style="width: 40px; margin-left: 10px" @click="handleSelectProject">
                    <i class="el-icon-search"></i>
                  </el-button>
                </el-form-item>
              </el-col> -->
              <!-- <el-col :span="8">
                <el-form-item label="项目名称">
                  <el-input v-model="form.HProName" placeholder="项目名称" readonly />
                </el-form-item>
              </el-col> -->
              <el-col :span="8">
                <el-form-item label="备注">
                  <el-input v-model="form.HRemark" placeholder="备注" />
                </el-form-item>
              </el-col>
            </el-row>
 
            <!-- 表格部分 -->
            <div class="table-section">
              <div class="table-toolbar">
                <el-button size="mini" @click="handleAddLine">增加一行</el-button>
                <el-button size="mini" @click="handleCopyLine">复制一行</el-button>
                <el-button size="mini" @click="handleInventoryQuery">库存查询</el-button>
                <el-button size="mini" @click="handleInOutQuery">出入库记录查询</el-button>
              </div>
 
              <el-table
                :data="tableData"
                border
                style="width: 100%"
                height="400"
                @selection-change="handleSelectionChange"
              >
                <el-table-column type="selection" width="55" />
                <el-table-column type="index" label="序号" width="60" />
                <el-table-column prop="物料代码" label="物料代码" width="150">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.物料代码"
                      placeholder="物料代码"
                      @focus="handleMaterialFocus(scope.$index, scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="物料名称" label="物料名称" width="150" />
                <el-table-column prop="规格型号" label="规格型号" width="100" />
                <el-table-column prop="计量单位" label="计量单位" width="100">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.计量单位"
                      placeholder="计量单位"
                      @focus="handleUnitFocus(scope.$index, scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="HQtyMust" label="应收数量" width="100">
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.HQtyMust"
                      :min="0"
                      :precision="2"
                      controls-position="right"
                      style="width: 100%"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="HQty" label="实收数量" width="100">
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.HQty"
                      :min="0"
                      :precision="2"
                      controls-position="right"
                      style="width: 100%"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="HPrice" label="单价" width="100">
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.HPrice"
                      :min="0"
                      :precision="2"
                      controls-position="right"
                      style="width: 100%"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="HMoney" label="金额" width="100">
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.HMoney"
                      :min="0"
                      :precision="2"
                      controls-position="right"
                      style="width: 100%"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="调入仓库" label="调入仓库" width="150">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.调入仓库"
                      placeholder="调入仓库"
                      readonly
                      @focus="handleInWarehouseFocus(scope.$index, scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="调出仓库" label="调出仓库" width="100">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.调出仓库"
                      placeholder="调出仓库"
                      readonly
                      @focus="handleOutWarehouseFocus(scope.$index, scope.row)"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="HBatchNo" label="批次" width="100">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.HBatchNo" placeholder="批次" />
                  </template>
                </el-table-column>
                <el-table-column prop="HRemark" label="备注" width="100">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.HRemark" placeholder="备注" />
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="70" fixed="right">
                  <template slot-scope="scope">
                    <el-button size="mini" type="danger" @click="handleDeleteLine(scope.$index)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
 
          <!-- 制单信息标签页 -->
          <el-tab-pane label="制单信息" name="maker">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="制单人">
                  <el-input v-model="form.HMaker" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="审核人">
                  <el-input v-model="form.HChecker" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="关闭人">
                  <el-input v-model="form.HCloseMan" readonly />
                </el-form-item>
              </el-col>
            </el-row>
 
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="修改人">
                  <el-input v-model="form.HUpDater" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="作废人">
                  <el-input v-model="form.HDeleteMan" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="制单日期">
                  <el-input v-model="form.HMakeDate" readonly />
                </el-form-item>
              </el-col>
            </el-row>
 
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="审核日期">
                  <el-input v-model="form.HCheckDate" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="关闭日期">
                  <el-input v-model="form.HCloseDate" readonly />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="修改日期">
                  <el-input v-model="form.HUpDateDate" readonly />
                </el-form-item>
              </el-col>
            </el-row>
 
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="作废日期">
                  <el-input v-model="form.HDeleteDate" readonly />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-form>
 
      <!-- 底部按钮 -->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSave">保存</el-button>
        <el-button @click="handleClose">退出</el-button>
      </div>
    </el-dialog>
 
  <!-- 部门选择对话框 -->
    <el-dialog
      title="选择部门"
      :visible.sync="deptVisible"
      width="80%"
      top="5vh"
      @close="deptVisible = false"
    >
      <dept
        ref="deptDialog"
        @deptEmit="handleDeptSelect"
        @deptEmitDb="handleDeptSelectDb"
      />
    </el-dialog>
 
    <!-- 仓库选择对话框 -->
    <el-dialog
      :visible.sync="warehouseVisible"
      width="80%"
      top="5vh"
      @close="warehouseVisible = false"
    >
      <warehouse
        ref="warehouseDialog"
        :warehouse-type="warehouseType"
        @deptEmit="handleWarehouseSelect"
        @deptEmitDb="handleWarehouseSelectDb"
      />
    </el-dialog>
 
    <!-- 供应商弹窗 -->
    <SupplierDialog
      :visible.sync="supplierDialogVisible"
      :dialog-type="currentDialogType"
      @select="handleSupplierSelect"
    />
 
    <!-- 职员弹窗 -->
    <EmployeeDialog
      :visible.sync="employeeDialogVisible"
      :dialog-type="currentDialogType"
      :dialog-title="employeeDialogTitle"
      @select="handleEmployeeSelect"
    />    
  </div>
</template>
 
<script>
import Dept from '@/views/component/dept'
import Warehouse from '@/views/component/warehouse'
import axios from 'axios'
import SupplierDialog from '@/views/FbStepFoldinBillList/SupplierDialog'
import EmployeeDialog from '@/views/FbStepFoldinBillList/EmployeeDialog'
export default {
  name: 'FbStepFoldOutBillEdit',
  components: {
    Dept,
    Warehouse,
    SupplierDialog,
        EmployeeDialog
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    operationType: {
      type: String,
      default: '1' // 1:新增, 3:编辑
    },
    linterid: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      dialogVisible: false,
      activeTab: 'basic',
      deptVisible: false,
      warehouseVisible: false,
      warehouseType: '',
      currentRowIndex: null,
      currentField: '',
      sourceBillTypes: [
        { value: '1250', label: '分步式调出单' }
      ],
      supplierDialogVisible: false,
            employeeDialogVisible: false,
            currentDialogType: '',
            employeeDialogTitle: '选择职员',
      form: {
        HInterID: 0,
        HBillNo: '',
        HDate: '',
        HSourceBillType: '',
        sourceBillNo: '',
        HSupName: '',
        HSupID: 0,
        HEmpName: '',
        HEmpID: 0,
        HManagerName: '',
        HManagerID: 0,
        HWHName: '',
        HWHID: 0,
        HSCWHName: '',
        HSCWHID: 0,
        HSecManagerName: '',
        HSecManagerID: 0,
        HKeeperName: '',
        HKeeperID: 0,
        HDeptName: '',
        HDeptID: 0,
        HProNumber: '',
        HProName: '',
        HProjectID: 0,
        HRemark: '',
        HMaker: '',
        HChecker: '',
        HCloseMan: '',
        HUpDater: '',
        HDeleteMan: '',
        HMakeDate: '',
        HCheckDate: '',
        HCloseDate: '',
        HUpDateDate: '',
        HDeleteDate: '',
        supplierId: '',
        keeperId: '',
        keeperName: '',
        inspectorId: '',
        inspectorName: '',
        managerId: '',
        managerName: ''
      },
      rules: {
        HWHID: [{ required: true, message: '请选择调入仓库', trigger: 'change' }],
        HSCWHID: [{ required: true, message: '请选择调出仓库', trigger: 'change' }],
        HDeptID: [{ required: true, message: '请选择部门', trigger: 'change' }]
      },
      tableData: [
        {
          HMaterID: 0,
          物料代码: '',
          物料名称: '',
          规格型号: '',
          HUnitID: 0,
          计量单位: '',
          HSecUnitRate: '0',
          HSecUnitID: '0',
          辅助计量单位: '',
          HQtyMust: 0,
          HQty: 0,
          HPrice: 0,
          HMoney: 0,
          HOrderPrice: 0,
          HWHID: 0,
          调入仓库: '',
          HSCWHID: 0,
          调出仓库: '',
          HBatchNo: '',
          HRemark: ''
        }
      ],
      selectedRows: [],
      baseURL: process.env.VUE_APP_BASE_URL || 'http://47.96.97.237/API/'
    }
  },
  computed: {
    dialogTitle() {
      return this.operationType === '1' ? '新增分步式调入单' : '编辑分步式调入单'
    }
  },
  watch: {
    visible: {
      immediate: true,
      handler(val) {
        this.dialogVisible = val
        if (val) {
          this.initForm()
        }
      }
    }
  },
  methods: {
    // 初始化表单
    initForm() {
      console.log('当前操作类型:', this.operationType)
      if (this.operationType === '1') {
        // 新增
        this.resetForm()
        this.getMaxBillNo()
        this.form.HMaker = sessionStorage['HUserName'] || 'admin'
        this.form.HMakeDate = this.formatDate(new Date())
        this.form.HDate = this.formatDate(new Date())
      } else if (this.operationType === '3' ) {
        console.log('编辑模式,无主id',this.linterid)
        // 编辑
        this.loadBillData(this.linterid)
      }
    },
 
    // 重置表单
    resetForm() {
      this.form = {
        HInterID: 0,
        HBillNo: '',
        HDate: '',
        HSourceBillType: '',
        sourceBillNo: '',
        HSupName: '',
        HSupID: 0,
        HEmpName: '',
        HEmpID: 0,
        HManagerName: '',
        HManagerID: 0,
        HWHName: '',
        HWHID: 0,
        HSCWHName: '',
        HSCWHID: 0,
        HSecManagerName: '',
        HSecManagerID: 0,
        HKeeperName: '',
        HKeeperID: 0,
        HDeptName: '',
        HDeptID: 0,
        HProNumber: '',
        HProName: '',
        HProjectID: 0,
        HRemark: '',
        HMaker: '',
        HChecker: '',
        HCloseMan: '',
        HUpDater: '',
        HDeleteMan: '',
        HMakeDate: '',
        HCheckDate: '',
        HCloseDate: '',
        HUpDateDate: '',
        HDeleteDate: ''
      }
      this.tableData = [{
        HMaterID: 0,
        物料代码: '',
        物料名称: '',
        规格型号: '',
        HUnitID: 0,
        计量单位: '',
        HSecUnitRate: '0',
        HSecUnitID: '0',
        辅助计量单位: '',
        HQtyMust: 0,
        HQty: 0,
        HPrice: 0,
        HMoney: 0,
        HOrderPrice: 0,
        HWHID: 0,
        调入仓库: '',
        HSCWHID: 0,
        调出仓库: '',
        HBatchNo: '',
        HRemark: ''
      }]
    },
 
    // 获取最大单据号
    async getMaxBillNo() {
      try {
        const response = await axios.get(`${this.baseURL}/Web/GetMAXNum`, {
          params: { HBillType: '1251' }
        })
        if (response.data && response.data.data && response.data.data.length > 0) {
          this.form.HBillNo = response.data.data[0].HBillNo
          this.form.HInterID = response.data.data[0].HInterID
        }
      } catch (error) {
        console.error('获取单据号失败:', error)
        this.$message.error('获取单据号失败')
      }
    },
 
    // 加载单据数据
    async loadBillData(linterid) {
      try {
        const response = await axios.get(`${this.baseURL}/Kf_StepFoldOutBill/cx`, {
          params: { HInterID: linterid }
        })
        console.log('编辑传入的主id:', linterid)
         console.log('加载的单据数据:', response.data)
        if (response.data.code == 1) {
          const data = response.data.data[0]
          console.log('单据头数据:', data)
          Object.keys(this.form).forEach(key => {
            if (data[key] !== undefined) {
              this.form[key] = data[key]
            }
          })
          this.form.HInterID = linterid;
          this.HInterID=data.HInterID;
          this.form.HBillNo = data.单据号
          this.form.HDate = data.日期
          this.form.HSourceBillType = '分布式调出单'
          this.form.sourceBillNo = data.源单号
          this.form.HSupName = data.供应商
          this.form.HSupID = data.HSupID
          this.form.HEmpName = data.仓管员
          this.form.HEmpID = data.HEmpID
          this.form.HManagerName = data.负责人
          this.form.HManagerID = data.HManagerID
          this.form.HWHName = data.调入仓库
          this.form.HWHID = data.HWHID
          this.form.HSCWHName = data.调出仓库
          this.form.HSCWHID = data.HSCWHID
          this.form.HSecManagerName = data.验收
          this.form.HSecManagerID = data.HSecManagerID
          this.form.HKeeperName = data.保管员
          this.form.HKeeperID = data.HKeeperID
          this.form.HDeptName = data.部门
          this.form.HDeptID = data.HDeptID
          this.form.HProNumber = data.项目代码
          this.form.HProName = data.项目名称
          this.form.HProjectID = data.HProjectID
          this.form.HRemark = data.备注
          this.form.HMaker = data.制单人
          this.form.HChecker = data.审核人
          this.form.HCloseMan = data.关闭人
          this.form.HUpDater = data.修改人
          this.form.HDeleteMan = data.作废人
          this.form.HMakeDate = data.制单日期
          this.form.HCheckDate = data.审核日期
          this.form.HCloseDate = data.关闭日期
          this.form.HUpDateDate = data.修改日期
          this.form.HDeleteDate = data.作废日期
 
 
          if (response.data.data.length > 0) {
            this.tableData = response.data.data.map(item => ({
              HMaterID: item.HMaterID,
              物料代码: item.物料代码,
              物料名称: item.物料名称,
              规格型号: item.规格型号,
              HUnitID: item.HUnitID,
              计量单位: item.计量单位,
              HQtyMust: item.应收数量,
              HQty: item.实收数量,
              HPrice: item.单价,
              HMoney: item.金额,
              HOrderPrice: item.采购金额,
              HWHID: item.HWHID,
              调入仓库: item.调入仓库,
              HSCWHID: item.HSCWHID,
              调出仓库: item.调出仓库,
              HBatchNo: item.批次,
              HRemark: item.表体备注
            }))
          }
        } else {
          this.$message.error(response.data.msg || '加载数据失败')
        }
      } catch (error) {
        console.error('加载单据数据失败:', error)
        this.$message.error('加载单据数据失败')
      }
    },
 
    // 部门选择
    handleSelectDept() {
      console.log('打开部门选择')
      this.deptVisible = true
    },
 
    // 调入仓库选择
    handleSelectInWarehouse() {
      console.log('打开调入仓库选择')
      this.warehouseType = 'HWH'
      this.warehouseVisible = true
      this.currentField = 'inWarehouse'
    },
 
    // 调出仓库选择
    handleSelectOutWarehouse() {
      console.log('打开调入仓库选择')
      this.warehouseType = 'HSCWH'
      this.warehouseVisible = true
      this.currentField = 'outWarehouse'
    },
 
    // 部门选择回调 - 单击
    handleDeptSelect(selectedData) {
      if (selectedData) {
        this.form.HDeptName = selectedData.部门名称
        this.form.HDeptID = selectedData.HItemID
        this.deptVisible = false
      }
    },
 
    // 部门选择回调 - 双击
    handleDeptSelectDb(selectedData) {
      this.handleDeptSelect(selectedData)
    },
 
    // 仓库选择回调 - 单击
    handleWarehouseSelect(selectedData) {
      if (selectedData) {
        const warehouse = selectedData
        if (this.currentField === 'inWarehouse') {
          this.form.HWHName = warehouse.仓库名称
          this.form.HWHID = warehouse.HItemID
        } else if (this.currentField === 'outWarehouse') {
          this.form.HSCWHName = warehouse.仓库名称
          this.form.HSCWHID = warehouse.HItemID
        } else if (this.currentField === 'tableInWarehouse') {
          this.tableData[this.currentRowIndex].调入仓库 = warehouse.仓库名称
          this.tableData[this.currentRowIndex].HWHID = warehouse.HItemID
        } else if (this.currentField === 'tableOutWarehouse') {
          this.tableData[this.currentRowIndex].调出仓库 = warehouse.仓库名称
          this.tableData[this.currentRowIndex].HSCWHID = warehouse.HItemID
        }
        this.warehouseVisible = false
        // 重置当前选择
        this.currentRowIndex = null
        this.currentField = ''
      }
    },
 
    // 仓库选择回调 - 双击
    handleWarehouseSelectDb(selectedData) {
      this.handleWarehouseSelect(selectedData)
    },
 
    // 表格行仓库选择
    handleInWarehouseFocus(index, row) {
      this.currentRowIndex = index
      this.warehouseType = 'HWH'
      this.warehouseVisible = true
      this.currentField = 'tableInWarehouse'
    },
 
    handleOutWarehouseFocus(index, row) {
      this.currentRowIndex = index
      this.warehouseType = 'HSCWH'
      this.warehouseVisible = true
      this.currentField = 'tableOutWarehouse'
    },
    showSupplierDialog() {
      this.currentDialogType = 'supplier'
      this.supplierDialogVisible = true
    },
    // 显示职员弹窗
    showEmployeeDialog(type) {
      this.currentDialogType = type
      const titleMap = {
        keeper: '选择保管员',
        inspector: '选择验收员',
        manager: '选择负责人',
        worker: '选择负责人',
        Employee: '选择仓管员'
      }
      this.employeeDialogTitle = titleMap[type] || '选择职员'
      this.employeeDialogVisible = true
    },
    handleEmployeeSelect(data, type) {
      const fieldMap = {
        keeper: { id: 'HkeeperId', name: 'HkeeperName' },
        inspector: { id: 'HSecManagerID', name: 'HSecManagerName' },
        manager: { id: 'HManagerID', name: 'HManagerName' },
        Employee: { id: 'HEmpID', name: 'HEmpName' }
      }
 
      const field = fieldMap[type]
      if (field) {
        this.form[field.id] = data.HItemID
        this.form[field.name] = data.职员名称 || data.职员代码
      }
      console.log(`选择的${type}:`, data)
    },
    
 
    handleSupplierSelect(data, type) {
      this.form.HSupID = data.HItemID
      this.form.HSupName = data.供应商名称 || data.供应商代码
      console.log('选择的供应商:', data)
    },
 
    
    // 表格操作
    handleAddLine() {
      this.tableData.push({
        HMaterID: 0,
        物料代码: '',
        物料名称: '',
        规格型号: '',
        HUnitID: 0,
        计量单位: '',
        HSecUnitRate: '0',
        HSecUnitID: '0',
        辅助计量单位: '',
        HQtyMust: 0,
        HQty: 0,
        HPrice: 0,
        HMoney: 0,
        HOrderPrice: 0,
        HWHID: 0,
        调入仓库: '',
        HSCWHID: 0,
        调出仓库: '',
        HBatchNo: '',
        HRemark: ''
      })
    },
 
    handleCopyLine() {
      if (this.selectedRows.length === 1) {
        const copyData = JSON.parse(JSON.stringify(this.selectedRows[0]))
        this.tableData.push(copyData)
      } else {
        this.$message.warning('请选择一行数据进行复制')
      }
    },
 
    handleDeleteLine(index) {
      if (this.tableData.length > 1) {
        this.tableData.splice(index, 1)
      } else {
        this.$message.warning('至少保留一行数据')
      }
    },
 
    handleSelectionChange(selection) {
      this.selectedRows = selection
    },
 
    handleInventoryQuery() {
      this.$message.info('库存查询功能待实现')
    },
 
    handleInOutQuery() {
      this.$message.info('出入库记录查询功能待实现')
    },
 
    // 保存
    async handleSave() {
      try {
        await this.$refs.form.validate()
        // 确保关键字段有值
    if (!this.form.HWHID || this.form.HWHID === 0) {
      this.$message.error('请选择调入仓库')
      return
    }
    if (!this.form.HSCWHID || this.form.HSCWHID === 0) {
      this.$message.error('请选择调出仓库')
      return
    }
    if (!this.form.HDeptID || this.form.HDeptID === 0) {
      this.$message.error('请选择部门')
      return
    }
 
    // 确保表格数据中的仓库ID也有值
    const hasValidTableData = this.tableData.every(row => 
      row.HMaterID && row.HMaterID !== 0 && 
      row.HUnitID && row.HUnitID !== 0
    )
    
    if (!hasValidTableData) {
      // this.$message.error('请完善表格中的物料和单位信息')
      // return
      this.tableData=[];
    }
      //  const formData = {
      //     mainData: JSON.stringify([this.form]), // 主表数据,包装成数组
      //     tableData: JSON.stringify(this.tableData), // 子表数据
      //     operationType: this.operationType,
      //     user: sessionStorage['HUserName'] || 'admin',
      //     allData: JSON.stringify({ // 主表+子表所有数据
      //       main: this.form,
      //       table: this.tableData
      //     })
      //   }
        //const formData=JSON.stringify(this.form)+';'+JSON.stringify(this.tableData)+';'+this.operationType+';'+(sessionStorage['HUserName'] || 'admin');
       const submitData = 
          JSON.stringify(this.form) + ';' + 
          JSON.stringify(this.tableData) + ';' + 
          this.operationType + ';' + 
          (sessionStorage['HUserName'] || 'admin') + ';' +
          JSON.stringify({ main: this.form, table: this.tableData })
          console.log('提交的完整数据:', submitData)
        
        const response = await axios.post(`${this.baseURL}/Kf_StepFoldOutBill/Kf_StepFoldOutBillEdit`, {
          sMainSub: submitData
        })
 
        if (response.data && response.data.count === 1) {
          this.$message.success(response.data.Message || '保存成功')
          this.handleClose()
          this.$emit('saved')
        } else {
          this.$message.error(response.data.Message || '保存失败')
        }
      } catch (error) {
        console.error('保存失败:', error)
        if (error.response && error.response.data) {
          this.$message.error(error.response.data.Message || '保存失败')
        } else {
          this.$message.error('保存失败')
        }
      }
    },
 
    // 关闭
    handleClose() {
      this.dialogVisible = false
      this.$emit('update:visible', false)
      this.$emit('closed')
    },
 
    // 工具方法
    formatDate(date) {
      if (!date) return ''
      const d = new Date(date)
      const year = d.getFullYear()
      const month = String(d.getMonth() + 1).padStart(2, '0')
      const day = String(d.getDate()).padStart(2, '0')
      return `${year}-${month}-${day}`
    }
  }
}
</script>
 
<style scoped>
.app-container {
  padding: 0;
}
 
.dialog-footer {
  text-align: center;
  padding: 20px 0 0;
}
 
.table-section {
  margin-top: 20px;
  border: 1px solid #e6ebf5;
  border-radius: 4px;
  padding: 10px;
}
 
.table-toolbar {
  margin-bottom: 10px;
}
 
.el-form-item {
  margin-bottom: 18px;
}
 
.el-tabs {
  margin-top: -20px;
}
 
.el-table {
  margin-top: 10px;
}
 
.el-input-number {
  width: 100%;
}
</style>