wangyi
8 天以前 76cca4b3bd9d7a1e62f421b215ca5efd8d975ee3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
<template>
  <div v-loading="formLoading" v-if="formShow" style="padding: 20px">
    <div style="margin-bottom: 10px; border-bottom: 1px solid #f6f6f6">
      <el-button type="primary" @click="handleAdd((OperationType = 1))" v-if="addBtnShow"
        >新增</el-button
      >
      <el-button type="primary" @click="submitForm" :disabled="subDisabled"
        >保 存</el-button
      >
      <el-button type="primary" @click="set_CheckBill(0, form)" :disabled="checkDisabled"
        >审 核</el-button
      >
      <el-button type="primary" @click="close">退 出</el-button>
      <!-- <el-button @click="cancel">取 消</el-button> -->
    </div>
    <div style="margin: 10px; font-size: 28px; font-weight: bold; text-align: center">
      车辆
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row>
            <el-col :span="6">
              <el-form-item label="车牌号" prop="HNumber">
                <el-input v-model="form.HNumber" placeholder="请输入车牌号" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="车辆名称" prop="HName">
                <el-input v-model="form.HName" placeholder="请输入车辆名称" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="短代码" prop="HShortNumber">
                <el-input
                  v-model="form.HShortNumber"
                  placeholder="请输入短代码"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="助记码" prop="HHelpCode">
                <el-input v-model="form.HHelpCode" placeholder="请输入助记码"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="父级" prop="HParentName">
                <el-input v-model="form.HParentName" placeholder="请选择父级" disabled>
                  <el-button
                    class="select-btn-primary"
                    slot="append"
                    icon="el-icon-search"
                    @click.stop="openDataDialog(1)"
                  ></el-button>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="车架号" prop="HCarSN">
                <el-input v-model="form.HCarSN" placeholder="请输入车架号"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="16">
              <el-form-item label="车辆行驶证照片" prop="HCarCardIDPic" label-width="8em">
                <div
                  class="image-input-outer"
                  @click.stop="openImagePreview('HCarCardIDPic')"
                >
                  <el-input v-model="form.HCarCardIDPic" readonly> </el-input>
                </div>
                <el-upload
                  class="upload-employee"
                  ref="upload"
                  action=""
                  accept=".jpg,.png,.jpeg"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :file-list="preUploadFiles.HCarPric"
                  :auto-upload="false"
                  :show-file-list="false"
                  style="display: inline-block; margin-left: 10px"
                  :on-change="
                    (file, fileList, uploadFiles) =>
                      fileChangeHandler(file, fileList, 'HCarCardIDPic')
                  "
                >
                  <el-button
                    slot="trigger"
                    size="small"
                    type="primary"
                    @click.capture="handleBeforeUpload"
                    >选择图片</el-button
                  >
                  <el-button
                    style="display: inline-block; margin-left: 1em"
                    size="small"
                    type="primary"
                    @click="HCarCardIDPic_BT_UploadFile"
                    >上传图片</el-button
                  >
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="车辆年检日期" prop="HCarCheckDate" label-width="7em">
                <el-date-picker
                  v-model="form.HCarCheckDate"
                  type="date"
                  placeholder="选择车辆年检日期"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="16">
              <el-form-item label="车辆照片" prop="HCarPric" label-width="8em">
                <div class="image-input-outer" @click="openImagePreview('HCarPric')">
                  <el-input v-model="form.HCarPric"> </el-input>
                </div>
                <el-upload
                  class="upload-employee"
                  ref="upload"
                  action=""
                  accept=".jpg,.png,.jpeg"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :file-list="preUploadFiles.HCarPric"
                  :auto-upload="false"
                  :show-file-list="false"
                  style="display: inline-block; margin-left: 10px"
                  :on-change="
                    (file, fileList, uploadFiles) =>
                      fileChangeHandler(file, fileList, 'HCarPric')
                  "
                >
                  <el-button
                    slot="trigger"
                    size="small"
                    type="primary"
                    @click.capture="handleBeforeUpload"
                    >选择图片</el-button
                  >
                  <el-button
                    style="display: inline-block; margin-left: 1em"
                    size="small"
                    type="primary"
                    @click="HCarPric_BT_UploadFile"
                    >上传图片</el-button
                  >
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="车型" prop="HCarTypeName">
                <el-input v-model="form.HCarTypeName" placeholder="请选择车型" disabled>
                  <el-button
                    class="select-btn-primary"
                    slot="append"
                    icon="el-icon-search"
                    @click.stop="openDataDialog(2)"
                  ></el-button>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="所属公司" prop="HCompName">
                <el-input v-model="form.HCompName" placeholder="请选择所属公司" disabled>
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    class="select-btn-primary"
                    @click.stop="openDataDialog(3)"
                  ></el-button>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="车辆型号" prop="HModel">
                <el-input v-model="form.HModel" placeholder="请输入车辆型号"> </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="车辆颜色" prop="HColor">
                <el-input v-model="form.HColor" placeholder="请输入车辆颜色" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="购买日期" prop="HBuyDate">
                <el-date-picker
                  v-model="form.HBuyDate"
                  type="date"
                  placeholder="选择车辆购买日期"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="使用组织" prop="HUSEORGID">
                <el-select
                  v-model="form.HUSEORGID"
                  placeholder="请选择组织"
                  :disabled="zzSelDis"
                >
                  <el-option
                    v-for="(item, index) in organizationList"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="制单信息" name="third">
          <el-row>
            <el-col :span="6">
              <el-form-item label="制单人" prop="HMakeEmp">
                <el-input v-model="form.HMakeEmp" placeholder="请输入制单人" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="修改人" prop="HUpdateEmp">
                <el-input v-model="form.HUpdateEmp" placeholder="请输入修改人" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="审核人" prop="HCheckEmp">
                <el-input v-model="form.HCheckEmp" placeholder="请输入审核人" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="关闭人" prop="HCloseMan">
                <el-input v-model="form.HCloseMan" placeholder="请输入关闭人" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="制单日期" prop="HMakeTime">
                <el-date-picker
                  v-model="form.HMakeTime"
                  type="date"
                  placeholder="选择制单日期"
                  disabled
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="修改日期" prop="HUpDateTime">
                <el-date-picker
                  v-model="form.HUpdateTime"
                  type="date"
                  placeholder="选择审核日期"
                  disabled
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="审核日期" prop="HCheckTime">
                <el-date-picker
                  v-model="form.HCheckTime"
                  type="date"
                  placeholder="选择审核日期"
                  disabled
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="关闭日期" prop="HCloseTime">
                <el-date-picker
                  v-model="form.HCloseTime"
                  type="date"
                  placeholder="选择关闭日期"
                  disabled
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="作废人" prop="HDeleteMan">
                <el-input v-model="form.HDeleteMan" placeholder="请输入作废人" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="作废日期" prop="HDeleteTime">
                <el-date-picker
                  v-model="form.HDeleteDate"
                  type="date"
                  placeholder="选择作废日期"
                  disabled
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <!-- 部门弹窗 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="openData"
      width="1280px"
      append-to-body
    >
      <!-- <Dept @deptEmitDb="dbEmitData" @deptEmit="emitData" v-if="deptShow" />
      <Warehouse @deptEmitDb="dbEmitData" @deptEmit="emitData" v-if="warehouseShow" />
      <Material @deptEmitDb="dbEmitData" @deptEmit="emitData" v-if="materialShow" /> -->
      <div style="height: 60vh" v-if="openData">
        <iframe
          :src="iframeUrl"
          frameborder="0"
          width="100%"
          height="100%"
          ref="iframeInstance"
        ></iframe>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="deptClickSub">确 定</el-button>
        <el-button @click="deptClose">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="隐藏列设置"
      :visible.sync="openRowHide"
      width="816px"
      append-to-body
    >
      <RowSettings
        :colName="btResList"
        HModName="Kf_SellOutBillList"
        @rowEditClose="rowSetClose"
        v-if="rowHideShow"
      />
    </el-dialog>
  </div>
</template>
 
<script>
import axios from "axios";
import Dept from "@/views/component/dept";
import Warehouse from "@/views/component/warehouse";
import Material from "@/views/component/material";
import RowSettings from "@/views/component/rowSettings";
import moment from "moment";
import dayjs from "dayjs";
 
export default {
  name: "GyCarEdit",
  components: { Dept, Warehouse, Material, RowSettings },
  data() {
    return {
      dialogEnabledNum: -1,
      iframeInstance: null,
      iframeUrl: "",
      OperationType: 1,
      HInterID: 0,
      formShow: false,
      temp: undefined,
      formLoading: true,
      zzSelDis: false,
      rowHideShow: false,
      checkDisabled: false,
      openRowHide: false,
      hPriceTypeList: ["成本价", "结算价"],
      HSourceBillTypeList: [],
      addBtnShow: false,
      zbIndex: null,
      zbSelForm: {}, //子表选中数据
      dialogTypeNum: null, //部门弹窗1,仓库弹窗2
      deptShow: false, //部门数据组件
      warehouseShow: false, //仓库数据组件
      materialShow: false, //物料数据组件
      deptform: {}, //弹窗选中数据
      openData: false, //数据弹窗
      dialogTitle: "",
      organizationList: [], //组织列表
      subDisabled: false, //编辑页面保存按钮是否禁用(true禁用,false可用)
      HInterID: null,
      baseURL: process.env.VUE_APP_BASE_API,
      checkedSysZb: [],
      editData: [], //车辆子表
      editBtData: [], //子表表头
      activeName: "first",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        HBillNo: "",
        HInitTimeCycle: 29,
        HProjectNumber: "",
        HCusID: null,
        HMaterNumber: "",
        HMaterName: "",
        ColName1: "",
        ColName2: "",
        ColName: "",
        Comparator1: "",
        Comparator2: "",
        Comparator: "",
        ColContent1: "",
        ColContent2: "",
        ColContent: "",
      },
      // 显示搜索条件
      showSearch: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: true,
      btResList: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        HNumber: [{ required: true, message: "车牌号不能为空", trigger: "blur" }],
        HName: [{ required: true, message: "车辆名称不能为空", trigger: "blur" }],
      },
      preUploadFiles: {
        HCarPric: [], // 车辆照片 文件缓存(只保存一张)
        HCarCardIDPic: [], // 车辆行驶证照片 文件缓存(只保存一张)
      },
      imagePreviewSrc: {
        HCarPric: "", // 车辆照片
        HCarCardIDPic: "", // 车辆行驶证照片
      },
    };
  },
  mounted() {
    this.fetchData();
    this.getdata();
 
    // 父级 回调
    window.iframeCarCallBack = (info) => {
      // 回调赋值
      this.form.HParentID = info.HItemID;
      this.form.HParentName = info["车辆名称"];
      // 关闭弹窗
      this.deptClose();
    };
    // 车型 回调
    window.iframeCarTypeCallBack = (info) => {
      // 回调赋值
      console.log(info);
      this.form.HCarTypeID = info.HItemID;
      this.form.HCarTypeName = info["车型名称"];
      // 关闭弹窗
      this.deptClose();
    };
    // 所属公司 回调
    window.iframeSupplierCallBack = (info) => {
      // 回调赋值
      console.log(info);
      this.form.HCompID = info.HItemID;
      this.form.HCompName = info["组织名称"];
      // 关闭弹窗
      this.deptClose();
    };
  },
  beforeDestroy() {
    if (window.top != window.this) {
      console.log(window.parent);
    } else {
      this.$destroy();
    }
  },
  methods: {
    UploadFile(file, fileName, prefix) {
      let formData = new FormData();
      formData.append("file", file.raw, fileName);
      formData.append("HNumber", this.form.HNumber);
      formData.append("HPrefix", prefix);
      formData.append("HUserName", sessionStorage["HUserName"]);
      axios({
        method: "post",
        url: this.$baseUrl + "/Gy_Car/Gy_Car_UploadFile",
        data: formData,
        headers: {
          "Content-Type": "multipart/form-data",
          Accept: "application/json",
        },
      })
        .then((res) => {
          console.log(res);
          if (res.data.count == 1) {
            this.$modal.msgSuccess(res.data.Message);
          } else {
            this.$modal.msgError(res.data.Message);
          }
        })
        .catch((err) => {
          this.$modal.msgError(`接口请求失败: ${err}`);
        });
    },
    HCarPric_BT_UploadFile() {
      if (!this.preUploadFiles.HCarPric[0]) {
        this.$modal.msgWarning("未上传车辆图片,请先上传车辆图片");
      }
      // 车辆照片上传
      this.UploadFile(this.preUploadFiles.HCarPric[0], this.form.HCarPric, "/HCarPric");
    },
    HCarCardIDPic_BT_UploadFile() {
      if (!this.preUploadFiles.HCarCardIDPic[0]) {
        this.$modal.msgWarning("未上传车辆行驶证图片,请先上传车辆行驶证图片");
      }
      // 车辆行驶证照片上传
      this.UploadFile(
        this.preUploadFiles.HCarCardIDPic[0],
        this.form.HCarCardIDPic,
        "/HCarCardIDPic"
      );
    },
    handleRemove() {},
    handlePreview() {},
    fileChangeHandler(file, fileList, key) {
      this.preUploadFiles[key] = fileList;
 
      const rawFile = file.raw;
 
      // 仅处理图片文件
      if (rawFile && rawFile.type.startsWith("image/")) {
        const reader = new FileReader(); // 初始化 FileReader
 
        // 读取完成后生成预览 URL
        reader.onload = (e) => {
          this.form[key] = file.name;
          this.imagePreviewSrc[key] = e.target.result;
        };
 
        // 以 DataURL 格式读取文件
        reader.readAsDataURL(rawFile);
      }
    },
    handleBeforeUpload(e) {
      if (!this.form.HNumber) {
        // 1. 阻止默认行为(阻止打开文件选择窗口)
        e.preventDefault();
        // 2. 阻止事件传播(防止触发其他可能的事件处理器)
        e.stopPropagation();
        this.$modal.msgError("车牌号未填写,不可上传文件");
      }
    },
    openImagePreview(key) {
      if (!this.imagePreviewSrc[key]) {
        return;
      }
      const h = this.$createElement;
      this.$msgbox({
        title: "预览",
        lockScroll: false,
        message: h("img", {
          attrs: {
            src: this.imagePreviewSrc[key],
          },
          style: { width: "100%", maxHeight: "80vh", objectFit: "contain" },
        }),
      });
    },
    getHSourceBillType() {
      axios
        .get(this.$baseUrl + "/Web/GetHSourceBillType", {
          params: { HName: "退货通知单", Num: 2 },
        })
        .then((res) => {
          this.HSourceBillTypeList = res.data.data.map((e) => {
            return {
              label: e.HSourceBillTypeName,
              value: e.HSourceBillType,
            };
          });
        })
        .error((err) => {
          this.$modal.msgError(`获取源单错误: ${err}`);
        });
    },
    fetchData() {
      axios
        .get(this.$baseUrl + "/Web/GetOrganizations", {})
        .then((response) => {
          if (response.data.count == 1) {
            this.organizationList = response.data.data.map((item) => {
              return {
                label: item.Name,
                value: item.ID,
              };
            }); //组织列表
          }
        })
        .catch((error) => {
          this.$modal.msgError("接口请求失败!");
        });
    },
    getdata() {
      this.HInterID = this.$route.query.HInterID || 0;
      this.OperationType = this.$route.query.OperationType || 1;
      this.formShow = false;
      this.formLoading = true;
 
      if (this.OperationType == 3) {
        // 编辑
        this.handleUpdate();
      } else if (this.OperationType == 1) {
        // 新增
        this.handleAdd();
      } else if (this.OperationType == 2) {
        // 复制
        this.handleUpdate();
      } else {
        // 浏览
        this.handleUpdate();
        this.subDisabled = false;
      }
    },
    // 获取参数_传递的JSON格式参数
    getUrlVars_JSON() {
      var datajson;
      var str = this.propsData; //获取链接中传递的参数
      var arr = str.substring(str.lastIndexOf("=") + 1);
      datajson = JSON.parse(decodeURI(arr));
      return datajson;
    },
    //根据主内码与子内码获取源单销售订单数据
    getPushSourceBillInit(HSourceInterID, HSourceEntryID) {
      axios
        .get(this.$baseUrl + "/Xs_SeOrderBill/loadXs_SeOrderBill_Push", {
          params: {
            HInterID: HSourceInterID,
            HSubID: HSourceEntryID,
          },
        })
        .then((response) => {
          let result = response.data;
          if (result.code == 1) {
            // 说明验证成功了,
            this.temp = result.data[0];
          } else {
            this.temp = result.data;
          }
        })
        .catch((error) => {
          this.$modal.msgError("接口请求失败!");
        });
    },
    handleRowHide() {
      this.rowHideShow = true;
      this.openRowHide = true;
    },
    rowSetClose(val) {
      this.rowHideShow = false;
      this.openRowHide = val;
      this.$destroy();
    },
 
    organizationChange(val) {
      // let options=undefined
      //  this.form=this.organizationList.find(option => option.ID === val)?.Name || '';
    },
    //部门弹窗赋值
    dbEmitData(deptRow, num) {
      // num=1部门 num=2出库仓库
      if (num == 1) {
        this.form.HDeptName = deptRow.部门名称;
        this.form.HDeptID = deptRow.HItemID;
        this.form.HEmpID = deptRow.HEmpID;
        this.form.HManagerName = deptRow.负责人;
        this.openData = false;
      } else if (num == 2) {
        this.editData[this.zbIndex].HWHID = deptRow.HItemID;
        this.editData[this.zbIndex].发货仓库 = deptRow.仓库名称;
        this.openData = false;
      } else if (num == 3) {
        this.editData[this.zbIndex].HMaterID = deptRow.HItemID;
        this.editData[this.zbIndex].物料代码 = deptRow.物料代码;
        this.editData[this.zbIndex].物料名称 = deptRow.物料名称;
        this.editData[this.zbIndex].HUnitID = deptRow.HUnitID;
        this.editData[this.zbIndex].规格型号 = deptRow.规格型号;
        this.editData[this.zbIndex].计量单位 = deptRow.计量单位名称;
        this.editData[this.zbIndex].HTaxPrice = deptRow.含税成本价;
        this.editData[this.zbIndex].HTaxRate = deptRow.默认税率;
        this.openData = false;
      }
    },
    emitData(deptRow, num) {
      this.dialogTypeNum = num;
      this.deptform = deptRow;
    },
    deptClickSub() {
      // this.dbEmitData(this.deptform, this.dialogTypeNum);
      let selectedRow = this.$refs.iframeInstance.contentWindow.selectedRow;
      console.log(selectedRow);
      if (this.dialogEnabledNum == 1) {
        // 父级
        this.form.HParentID = selectedRow.HItemID;
        this.form.HParentName = selectedRow["车辆名称"];
      } else if (this.dialogEnabledNum == 2) {
        // 车型
        this.form.HCarTypeID = selectedRow.HItemID;
        this.form.HCarTypeName = selectedRow["车型名称"];
      } else if (this.dialogEnabledNum == 3) {
        // 所属公司
        this.form.HCompID = selectedRow.HItemID;
        this.form.HCompName = selectedRow["组织名称"];
      }
      this.deptClose()
    },
    deptClose() {
      this.deptform = {};
      this.openData = false;
    },
 
    //车辆新增编辑表单初始化
    reset() {
      this.form = {
        HItemID: 0,
        HNumber: "",
        HName: "",
        HShortNumber: "",
        HHelpCode: "",
        HParentName: "",
        HParentID: 0,
        HLevel: 0,
        HCarSN: "",
        HCarCheckDate: dayjs(new Date()).format("YYYY-MM-DD"),
        HCarTypeID: 0,
        HCarTypeName: "",
        HCarPric: "",
        HCarCardIDPic: "",
        HCompID: 0,
        HCompName: "",
        HModel: "",
        HColor: "",
        HBuyDate: dayjs(new Date()).format("YYYY-MM-DD"),
        HCREATEORGID: sessionStorage["OrganizationID"],
        HUSEORGID: sessionStorage["OrganizationID"],
        HMakeEmp: sessionStorage["HUserName"],
        HStopEmp: "",
        HCheckEmp: "",
        HMakeTime: dayjs(new Date()).format("YYYY-MM-DD"),
        HStopTime: "",
        HCheckTime: "",
        HModifyEmp: "",
        HModifyTime: "",
      };
      this.editData = [];
      this.editBtData = [];
      this.ids = [];
      this.subDisabled = false;
      this.addBtnShow = false;
      // this.$refs.tableData.clearSelection()
      this.activeName = "first";
      this.resetForm("form");
    },
    //退出
    close() {
      this.reset();
      if (window.top != window.self) {
        // iframe 页面 调用父页面的函数关闭弹窗
        window.parent.editGyClose();
      } else if (!this.OperationType2 && !this.copyType) {
        // this.$router.back()
        window.close();
      } else {
        this.formShow = false;
        this.$emit("editClose", false);
      }
    },
    //根据用户获取对应职员、部门、销售主管
    getCzyglByUser() {
      axios
        .get(this.$baseUrl + "/Xs_SeOrderBill/getCzyglByUser", {
          params: { CurUserName: sessionStorage["HUserName"] },
        })
        .then((response) => {
          let dataForm = response.data.data[0];
          this.form.HDeptID = dataForm.HDeptID;
          this.form.HDeptName = dataForm.HDeptName;
          this.form.HEmpID = dataForm.HEmpID;
          this.form.HEmpName = dataForm.HEmpName;
          this.form.HManagerID = dataForm.HManagerID;
          this.form.HManagerName = dataForm.HManagerName;
        })
        .catch((error) => {
          this.$modal.msgError("接口请求失败!");
        });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      //新增获取单据号
      // this.getHBillNo();
      let date = new Date();
      this.form.HDate = moment(date).format("YYYY-MM-DDTHH:mm:ss");
      this.resetForm();
      if (this.OperationType == 1) {
      }
      this.$nextTick(() => {
        this.formShow = true;
        this.formLoading = false;
      });
    },
    /** 修改按钮操作 */
    handleUpdate() {
      this.reset();
      let rowHmainid = this.HInterID;
      axios
        .get(this.$baseUrl + "/Gy_Car/GetGy_CarDetail", {
          params: { HID: rowHmainid },
        })
        .then((res) => {
          if (res.data.count == 1) {
            var data = res.data.data[0];
            this.form = {
              ...{
                HItemID: this.OperationType == 2 ? 0 : data.HItemID,
                HNumber: this.OperationType == 2 ? "" : data.车牌号,
                HName: data.车辆名称,
                HShortNumber: data.短代码,
                HHelpCode: data.助记码,
                HParentName: data.父类名称 || "",
                HParentID: data.HParentID,
                HLevel: data.等级,
                HCarSN: data.车架号,
                HCarCheckDate: data.车辆年检日期
                  ? dayjs(data.车辆年检日期).format("YYYY-MM-DD")
                  : "",
                HCarTypeID: data.车型,
                HCarTypeName: data.车型名称 || "",
                HCarPric: data.车辆照片,
                HCarCardIDPic: data.车辆行驶证照片,
                HCompID: data.HCompID,
                HCompName: data.所属公司,
                HModel: data.车辆型号,
                HColor: data.车辆颜色,
                HBuyDate: data.购买日期 ? dayjs(data.购买日期).format("YYYY-MM-DD") : "",
                HCREATEORGID: data.HCREATEORGID,
                HUSEORGID: data.HUSEORGID,
                HMakeEmp: data.创建人,
                HStopEmp: data.禁用人,
                HCheckEmp: data.审核人,
                HMakeTime: data.建立时间 ? dayjs(data.建立时间).format("YYYY-MM-DD") : "",
                HStopTime: data.禁用时间 ? dayjs(data.禁用时间).format("YYYY-MM-DD") : "",
                HCheckTime: data.审核时间
                  ? dayjs(data.审核时间).format("YYYY-MM-DD")
                  : "",
                HModifyEmp: data.修改人,
                HModifyTime: data.修改时间
                  ? dayjs(data.修改时间).format("YYYY-MM-DD")
                  : "",
              },
            };
 
            if (this.OperationType == 2) {
              Object.assign(this.form, {
                HMakeEmp: sessionStorage["HUserName"],
                HStopEmp: "",
                HCheckEmp: "",
                HMakeTime: dayjs(new Date()).format("YYYY-MM-DD"),
                HStopTime: "",
                HCheckTime: "",
                HModifyEmp: "",
                HModifyTime: "",
                HBuyDate: "",
                HCarPric: "",
                HCarCardIDPic: "",
                HParentID: 0,
                HParentName: "",
                HCarSN: "",
                HCarCheckDate: "",
              });
            } else {
              // 编辑模式下 生成图片预览src 复制模式下需重新上传图片
              let apiIndex = this.$baseUrl.indexOf("/API/");
              let filePath = this.$baseUrl.slice(0, apiIndex) + "/";
 
              this.imagePreviewSrc.HCarPric = data.车辆照片
                ? `${filePath}Files/Gy_Car/${data.车牌号}/HCarPric/${data.车辆照片}`
                : "";
              this.imagePreviewSrc.HCarCardIDPic = data.车辆行驶证照片
                ? `${filePath}Files/Gy_Car/${data.车牌号}/HCarCardIDPic/${data.车辆行驶证照片}`
                : "";
 
              this.checkDisabled = !!data.审核人;
              this.subDisabled = !!data.审核人;
            }
 
            //this.$nextTick(() => {
            this.formShow = true;
            this.formLoading = false;
            //})
          }
        })
        .catch((error) => {
          this.$modal.msgError("接口请求失败! ");
          console.error(error);
        });
    },
    //根据客户带出联系人、联系电话
    getCustomerByCusID(HCusID) {
      axios
        .get(this.$baseUrl + "/Xs_SeOrderBill/getCustomerByCusID", {
          params: {
            HCusID: HCusID,
          },
        })
        .then((response) => {
          this.form.联系人 = response.data.data[0].HLinkMan;
          this.form.联系电话 = response.data.data[0].HLinkPhone;
          // this.form = response.data.data[0]
        })
        .catch((error) => {
          this.$modal.msgError("接口请求失败!");
        });
    },
    /** 销售出库子表明细序号 */
    rowSysZbIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 编辑页子表添加按钮操作 */
    handleAddSysZb(index, num) {
      if (num == 1 && !index) {
        this.$modal.msgError("请选择一行数据编辑!");
      } else {
        let obj = {
          HMaterID: 0,
          物料代码: "",
          物料名称: "",
          规格型号: "",
          HUnitID: 0,
          计量单位: "",
          HQtyMust: 1,
          HQty: 1,
          HPieceQty: 0,
          HPrice: 0,
          HTaxPrice: 0,
          HTaxRate: 0,
          HMoney: 0,
          HTaxMoney: 0,
          HWHID: 0,
          发货仓库: "",
          HRemark: "",
          HQty_Full: 0,
          HQty_Empty: 0,
          HQty_Back: 0,
          HCostPrice: 0,
          HCostMoney: 0,
          HSalePrice: 0,
          HSeOrderInterID: 741,
          HSeOrderEntryID: 18,
          HSeOrderBillNo: "XSFH00000747",
          HSourceInterID: 741,
          HSourceEntryID: 18,
          HSourceBillNo: "XSFH00000747",
          HSourceBillType: 1402,
          HRelationQty: 0,
          HRelationMoney: 0,
          HSPID: 0,
          HSPName: "",
          HSPGroupID: 0,
          HSPGroupName: "",
          HSCWHID: 0,
          HSCWHName: "",
          HSCSPID: 0,
          HSCSPName: "",
          HBatchNo: "",
          HPOOrderInterID: 0,
          HPOOrderEntryID: 0,
          HPOOrderBillNo: "",
          HPropertyID: 0,
          HPropertyName: "",
          HSecUnitID: 0,
          HSecUnitName: "",
          HSecUnitRate: 0,
          HEngineNum: "",
          HUnderPanNum: "",
          HLeaveFactCard: "",
          HReqBuyQty: 0,
          HReqOutQty: 0,
          HCurrentInventory: 0,
        };
        if (index) {
          this.editData.splice(index, 0, obj);
          this.$set(this.editData, index, obj);
        } else {
          this.editData.push(obj);
        }
      }
    },
    handleCopyZbRow() {
      if (!this.zbIndex) {
        this.$modal.msgError("请选择一行数据");
      } else {
        let copyRow = JSON.parse(JSON.stringify(this.zbSelForm));
        this.editData.push(copyRow);
      }
    },
    handleMoveRowUp(zbSelForm) {
      if (!this.zbIndex) {
        this.$modal.msgError("请选择一行数据");
      } else {
        if (zbSelForm.index == 1) {
          this.$modal.msgError("第一行数据无法上移");
        } else {
          // 确保不是第一行
          let num = zbSelForm.index - 1;
          const record = this.editData.splice(num, 1)[0];
          this.editData.splice(num - 1, 0, record);
        }
      }
    },
    handleMoveRowDown(zbSelForm) {
      if (!this.zbIndex) {
        this.$modal.msgError("请选择一行数据");
      } else {
        if (zbSelForm.index == this.editData.length) {
          this.$modal.msgError("最后一行数据无法下移");
        } else {
          // 确保不是第一行
          let num = zbSelForm.index - 1;
          const record = this.editData.splice(num, 1)[0];
          this.editData.splice(num + 1, 0, record);
        }
      }
    },
    /** 编辑页子表删除按钮操作 */
    handleDeleteSysZb(row) {
      this.checkedSysZb = [];
      this.checkedSysZb.push(row.index);
      if (this.checkedSysZb.length == 0) {
        this.$modal.msgError("请先选择要删除的商品订单明细数据");
      } else {
        const editData = this.editData;
        const checkedSysZb = this.checkedSysZb;
        this.editData = editData.filter(function (item) {
          return checkedSysZb.indexOf(item.index) == -1;
        });
      }
    },
    /** 编辑页子表复选框选中数据 */
    handleTableZbEdit(selection) {
      this.checkedSysZb = selection.map((item) => item.index);
      this.zbSelForm = selection[0];
      this.zbIndex = this.checkedSysZb[0];
      if (selection.length > 1) {
        const del_row = selection.shift();
        this.$refs.zbTable.toggleRowSelection(del_row, false); //设置这一行取消选中
      }
    },
    // 编辑提交保存
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let fhck = false;
          this.$nextTick(() => {
            if (!fhck) {
              let sMainStr =
                JSON.stringify(this.form) + ";" + sessionStorage["HUserName"];
 
              axios({
                method: "post",
                url: this.$baseUrl + "/Gy_Car/SaveGy_Car",
                data: {
                  msg: sMainStr,
                },
              })
                .then((response) => {
                  if (response.data.count == 1) {
                    this.subDisabled = true; //设置保存按钮不可用
                    this.$modal.msgSuccess(response.data.Message);
                    this.addBtnShow = true;
                  }
                })
                .catch((error) => {
                  this.$modal.msgError("接口请求失败!");
                });
            }
          });
        }
      });
    },
    // 反审核/审核数据
    set_CheckBill(num, form) {
      var InterID = form.hmainid || form.HInterID;
      //逻辑审核方法
      axios
        .get(this.$baseUrl + "/Kf_SellOutBill/AuditKf_SellOutBill", {
          params: {
            HInterID: InterID,
            IsAudit: num,
            CurUserName: sessionStorage["HUserName"],
          },
        })
        .then((response) => {
          let result = response.data;
          if (result.code == 1) {
            this.$modal.msgSuccess("操作成功");
          } else {
            this.$modal.msgError("错误:" + result.code + result.Message);
          }
        })
        .catch((error) => {
          this.$modal.msgError("接口请求失败!");
        });
    },
    showReset() {
      this.deptShow = false;
      this.warehouseShow = false;
      this.materialShow = false;
    },
    //  打开数据列表弹窗
    openDataDialog(num, row) {
      this.dialogEnabledNum = num;
      if (row) {
        this.zbIndex = row.index - 1;
      }
      this.showReset();
      if (num == 1) {
        // 父级
        this.dialogTitle = "父级";
        this.iframeUrl = "/iframe/GyCar";
 
        // this.deptShow = true;
        this.openData = true;
      } else if (num == 2) {
        // 车型
        this.iframeUrl = "/iframe/GyCarType";
        this.dialogTitle = "车型";
        // this.warehouseShow = true;
        this.openData = true;
      } else if (num == 3) {
        // 所属公司
        this.iframeUrl = "/iframe/GySupplier";
 
        this.dialogTitle = "所属公司";
        // this.materialShow = true;
        this.openData = true;
      }
    },
  },
};
</script>
<style>
.xsckdBox .el-date-editor.el-input {
  width: 100%;
}
 
.select-btn-primary {
  background-color: rgba(24, 144, 255, 1) !important;
  color: #fff !important;
}
 
.image-input-outer {
  display: inline-flex;
  width: 60%;
  padding-right: 1em;
}
 
.image-input-outer .el-input input {
  color: rgba(24, 144, 255, 1) !important;
  cursor: pointer !important;
}
</style>