Fixiaobai
2023-09-12 72ac5494a32173d69ed739e1dd672cc1b9c03f92
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
<template>
  <div class="standard">
    <div class="title">
      <el-row>
        <el-col :span="12" style="line-height: 32px;">标准BOM</el-col>
        <el-col :span="12" style="text-align: right;">
          <el-button type="primary" icon="el-icon-plus" style="background: #004EA2;"
            @click="bomAddModelVisible = true">新增</el-button>
          <el-button icon="el-icon-plus">新增版本</el-button>
          <el-button @click="bomRightDl=true" icon="el-icon-delete">删除</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="thing">
      <div class="left">
        <el-row>
          <el-col :span="21">
            <el-input v-model="search" suffix-icon="el-icon-search" placeholder="请输入搜索内容" size="small" clearable></el-input>
          </el-col>
          <el-col :span="2">
            <el-button  size="mini" icon="el-icon-plus" @click="bomLeftAdd=true"></el-button>
          </el-col>
        </el-row>
        <el-tree style="width: ;" :data="list" ref="tree" default-expand-all :props="{ children: 'children', label: 'name' }"
          node-key="id" :filter-node-method="filterNode" @node-click="handleNodeClick" highlight-current>
          <div class="custom-tree-node" slot-scope="{ node, data }">
            <span><i :class="`node_i ${data.code != '[5]' ? 'el-icon-folder-opened' : 'el-icon-tickets'}`"></i>
              {{ data.code }}{{ data.name }}</span>
            <el-button type="text" size="mini" @click.stop="remove(node, data)">
              <i class="el-icon-delete"></i>
            </el-button>
          </div>
        </el-tree>
      </div>
 
 
      <div class="right">
        <div class="choose">
          <span>类型:</span>
          <el-select v-model="tableType" size="small" placeholder="请选择" @change="TYPE"
            style="width: 224px;margin-right: 52px;">
            <el-option :value="0" label="工艺路线"></el-option>
            <el-option :value="1" label="技术指标"></el-option>
            <el-option :value="2" label="物料清单"></el-option>
            <el-option :value="3" label="生产工艺"></el-option>
          </el-select>
          <span>{{ tableType == 1 ? '项目:' : '工艺名称:' }}</span>
          <el-input v-model="searchName" size="small" placeholder="请输入" style="width: 224px;margin-right: 24px;"
            clearable></el-input>
          <span>{{ tableType == 1 ? '版本:' : '版本:' }}</span>
          <el-select v-model="VER" @change="verevent" style="width: 280px;" placeholder="请选择">
            <el-option v-for="item in version" :key="item" :label="item" :value="item">
            </el-option>
          </el-select>
          <el-button size="mini" @click="() => { searchName = ''; selectProductTableData() }"><span>重 置</span></el-button>
          <el-button size="mini" type="primary" style="background: #004EA2;" @click="selectProductTableData"><span>查
              询</span></el-button>
        </div>
 
        <div class="contentTable" v-if="this.typeselect == 0">
          <technology  :tableType="tableType" :tableData="tableData"></technology>
        </div>
        <div v-if="this.typeselect == 1">
          <target :tableType="tableType" :tableData="tableData"></target>
        </div>
        <div v-if="this.typeselect == 2">
          <bom  :tableType="tableType" :tableData="tableData"></bom>
        </div>
        <div v-if="this.typeselect == 3">生产工艺</div>
        
      </div>
    </div>
 
 
    <div class="bom-add-model">
      <el-dialog title="BOM新增" :visible.sync="bomAddModelVisible" width="45%">
        <!-- 工艺路线 -->
        <div v-if="typeselect == 0">
          <el-form :model="technologyForm" :inline="true" label-position="right"
           ref="technologyForm" :rules="technologyRules" label-width="90px">
            <el-form-item label="工序:" prop="tefather">
              <el-select id="tefather" size="small" 
              filterable allow-create default-first-option
              v-model="technologyForm.tefather" placeholder="请输入或选择工序">
                <el-option :value="item.father" :label="item.father" v-for="(item,index) in fatherList" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="工艺名称:" prop="tename">
              <el-input id="tename" size="small" placeholder="请输入工艺名称" 
              clearable v-model="technologyForm.tename"></el-input>
            </el-form-item>
            <el-form-item label="设备组:" prop="deviceGroup">
              <el-select id="deviceGroup" placeholder="请选择设备组" size="small"
              v-model="technologyForm.deviceGroup">
              <el-option :value="item.father" 
              v-for="(item,index) in deviceList" :key="index" :label="item.father"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="生产定额:" prop="productionQuota">
              <el-input id="productionQuota" size="small" clearable v-model.number="technologyForm.productionQuota" placeholder="请输入生产定额" />
            </el-form-item>
          </el-form>
          <div style="width:100%;text-align: right;">
            <span slot="footer" class="dialog-footer" >
              <el-button type="primary" @click="confirmAdd('technologyForm')">确 定</el-button>
              <el-button @click="bomAddModelVisible = false">取 消</el-button>
            </span>
          </div>
        </div>
        <!-- 技术指标 -->
        <div v-if="typeselect == 1">
          <el-form :model="targetForm" :inline="true" label-position="right"
          :rules="targetRules" ref="targetForm" label-width="90px">
            <el-form-item label="工序:" prop="pfather">
              <el-select v-model="targetForm.pfather" 
              @change="changeFather"
              style="width:200px;" placeholder="请选择工序">
                <el-option :value="item.name" :label="item.name" v-for="(item,index) in targetFormList" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="工艺名称:" prop="technologyId">
              <el-select v-model="targetForm.technologyId"
              @change="changeTechnologyId" 
              style="width:200px;" placeholder="请选择工艺名称">
                <el-option :value="item.id" :label="item.name" v-for="(item,index) in technologyIdList" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目:" prop="father">
              <el-select v-model="targetForm.father"
              filterable allow-create default-first-option
              style="width:200px;" placeholder="请输入或选择项目">
                <el-option :value="item.father" :label="item.father" v-for="(item,index) in projectList" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="指标名称:" prop="name">
              <el-input style="width:200px;" v-model="targetForm.name" placeholder="请输入指标名称"/>
            </el-form-item>
            <el-form-item label="单位:" prop="unit">
              <el-input style="width:200px;" v-model="targetForm.unit" placeholder="请输入单位"/>
            </el-form-item>
            <el-form-item label="内控值:" prop="internal">
              <el-input style="width:200px;" v-model="targetForm.internal" placeholder="请输入内控值"/>
            </el-form-item>
            <el-form-item label="标准值:" prop="required">
              <el-input style="width:200px;" v-model="targetForm.required" placeholder="请输入标准值"/>
            </el-form-item>
          </el-form>
          <div style="width:100%;text-align: right;">
            <span slot="footer" class="dialog-footer" >
              <el-button type="primary" @click="confirmAdd('targetForm')">确 定</el-button>
              <el-button @click="bomAddModelVisible = false">取 消</el-button>
            </span>
          </div>
        </div>
        <!-- 物料清单 -->
        <div v-if="typeselect == 2">
          <el-form :model="materialForm" label-position="right"
          :rules="materialRules" ref="materialForm" label-width="80px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="规格型号:" width="250">
                <el-input style="width:200px;" v-model="materialForm.pname" placeholder="请输入单位"/>
              </el-form-item>
              </el-col>
              <el-col :span="12" style="text-align: right;">
              <el-form-item label="产品大类:" width="250">
                <el-select placeholder="请选择产品大类"
                style="width:240px;" v-model="materialForm.dg">
                <el-option value="1">1</el-option>
                  <el-option value="2">2</el-option>
                  <el-option value="3">3</el-option>
                  <el-option value="4">4</el-option>
                </el-select>            
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="材料信息"></el-form-item>
            </el-col>
            <el-col :span="12" style="text-align: right;">
              <el-button size="mini" style="text-align: right;">添加行</el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-table >
                <el-table-column label="材料名称"></el-table-column>
                <el-table-column label="规格型号"></el-table-column>
                <el-table-column label="单位"></el-table-column>
                <el-table-column label="数量"></el-table-column>
              </el-table>
            </el-col>
          </el-row>
          </el-form>
          <div style="width:100%;text-align: right;">
            <span slot="footer" class="dialog-footer" >
              <el-button type="primary" @click="confirmAdd('materialForm')">确 定</el-button>
              <el-button @click="bomAddModelVisible = false">取 消</el-button>
            </span>
          </div>
        </div>
        <!-- 生产工艺 -->
        <div v-if="typeselect == 3">
          <el-form :model="productForm" :inline="true" label-position="right"
          label-width="80px">
            <el-form-item label="工序:" width="250">
              <el-select v-model="productForm.father" 
              style="width:200px;"
              placeholder="请输入或选择生产定额">
                <el-option value="1">1</el-option>
                <el-option value="2">2</el-option>
                <el-option value="3">3</el-option>
                <el-option value="4">4</el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="工艺名称:" width="250">
              <el-select placeholder="请输入或选择工艺名称"
              style="width:200px;"
              v-model="productForm.name">
              <el-option value="1">1</el-option>
                <el-option value="2">2</el-option>
                <el-option value="3">3</el-option>
                <el-option value="4">4</el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="设备:" width="250">
              <el-select placeholder="请选择设备"
              style="width:200px;"
              v-model="productForm.dg">
              <el-option value="1">1</el-option>
                <el-option value="2">2</el-option>
                <el-option value="3">3</el-option>
                <el-option value="4">4</el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目:" width="250">
              <el-select placeholder="请选择项目"
              style="width:200px;"
              v-model="productForm.dg">
              <el-option value="1">1</el-option>
                <el-option value="2">2</el-option>
                <el-option value="3">3</el-option>
                <el-option value="4">4</el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="单位:" width="250">
              <el-input style="width:200px;" v-model="productForm.unit" placeholder="请输入单位"/>
            </el-form-item>
            <el-form-item label="指标:" width="250">
              <el-input style="width:200px;" v-model="productForm.pq" placeholder="请输入指标" />
            </el-form-item>
          </el-form>
          <div style="width:100%;text-align: right;">
              <span slot="footer" class="dialog-footer" >
                <el-button type="primary" @click="confirmAdd('productForm')">确 定</el-button>
                <el-button @click="bomAddModelVisible = false">取 消</el-button>
              </span>
            </div>
          </div>
      </el-dialog>
      <!-- 左侧点击+按钮 -->
      <el-dialog title="BOM新增" :visible.sync="bomLeftAdd" width="29%">
        <el-form ref="leftAdd" :model="leftAdd">
            <el-form-item :rules="[{ required: true, message: '请选择产品类型', trigger: 'blur' }]" label="产品类型" prop="type">
              <el-cascader @change="changeLeftAdd" v-model="leftAdd.type"  style="width: 86%;" :options="formTypeOptions" :props="{ checkStrictly: true }" clearable></el-cascader>
            </el-form-item>
            <el-form-item v-if="leftAdd.type.length<2" label="产品大类" prop="father">
              <el-autocomplete  class="inline-input" style="width: 88%;" v-model="leftAdd.father" :fetch-suggestions="querySearch" placeholder="请选择产品大类" @select="handleSelect"></el-autocomplete>
            </el-form-item>
            <el-form-item v-if="leftAdd.type.length<3"  label="产品名称" prop="name">
              <el-autocomplete class="inline-input" style="width: 88%;" v-model="leftAdd.name" :fetch-suggestions="querySearchName" placeholder="请选择产品名称" @select="handleSelect"></el-autocomplete>
            </el-form-item>
            <el-form-item v-if="leftAdd.type.length<4"  label="产品标准" prop="standard">
              <el-autocomplete class="inline-input" style="width: 88%;" v-model="leftAdd.standard" :fetch-suggestions="querySearchStandar" placeholder="请选择产品标准" @select="handleSelect"></el-autocomplete>
            </el-form-item>
            <el-form-item  label="产品型号" prop="specifications">
              <el-input v-model="leftAdd.specifications" style="width: 88%;" placeholder="请输入产品型号"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="resetForm('leftAdd')">取 消</el-button>
          <el-button type="primary" @click="submitForm('leftAdd')">确 定</el-button>
        </span>
      </el-dialog>
        <!-- 右上侧点击删除按钮 -->
      <el-dialog title="BOM删除" :visible.sync="bomRightDl" width="30%">
        <el-form>
            删除
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="bomRightDl=false">取 消</el-button>
          <el-button type="primary" @click="bomRightDl = false">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
 
<script>
import technology from "./standard-table/technology.vue"
import material from "./standard-table/material.vue"
// import bom from "./standard-table/bom.vue"
import bomClickAdd from '@/components/view/standard-box/bomClickAdd'
export default {
  components: { technology,material,bomClickAdd },
 
  data() {
    var checkPq = (rule,value,callback)=>{
      if(value!='' && !Number.isInteger(value)){
        return callback(new Error('请输入数字值'));
      }
      callback();
    };
    var checkVal = (rule,value,callback)=>{
      let arr = [">","<","="];
      if(value!='' && arr.indexOf(value.substring(0,1))==-1){
        callback(new Error("开头需包含 > 或 < 或 = "))
      }
      callback();
    };
    return {
      //技术指标-新增-工序,工艺下拉框数据
      targetFormList:[],
      technologyIdList:[],
      //技术指标-新增-项目下拉框数据
      projectList:[],
      //工序列表
      fatherList:[],
      //设备组列表
      deviceList:[],
      technologyForm:{
        tefather:'',
        tename:'',
        deviceGroup:'',
        productionQuota:''
      },
      targetForm:{
        pfather:'',
        father: '',
        technologyId:'',
        name:'',
        unit:'',
        internal:'',
        required: ''
      },
      materialForm:{},
      productForm:{},
      technologyRules:{
        tefather:{required:true,message:'工序不能为空',trigger:'change'},
        tename:{required:true,message:'工艺名称不能为空',trigger:'blur'},
        deviceGroup:{required:true,message:'设备组不能为空',trigger:'change'},
        productionQuota:{validator:checkPq,trigger:'change'}
      },
      targetRules:{
        pfather:{required:true,message:'工序不能为空',trigger:'change'},
        technologyId:{required:true,message:'工艺名称不能为空',trigger:'change'},
        father:{required:true,message:'项目不能为空',trigger:'change'},
        name:{required:true,message:'指标名称不能为空',trigger:'blur'},
        unit:{required:true,message:'单位不能为空',trigger:'change'},
        internal:{validator:checkVal,trigger:'change'},
        required:{validator:checkVal,trigger:'change'}
      },
      materialRules:{
 
      },
      productRules:{
 
      },
      // BOM树数据结构
      list: [],
      search: null,
      tableType: 1, // 表格类型 1:技术指标,0:工艺路线
      searchName: "",// 查询条件-名称
      checkTreeNode: {},// 点击选中树节点
      tableData: [],
      bomAddModelVisible: false,// 控制bom新增模态框是否显示
      bomLeftAdd: false,
      bomRightUp: false,
      bomRightDl: false,
      formTypeOptions: null,
      typeselect: 0,
      returntree: {
        id:28,
      },
      version: {},
      leftAdd:{
        type: [],
        father: null,
        standard: null,
        name: null,
        specifications: null
      },
      VER: {},
      verdata: {},
      character: 0,
      restaurants: [],
      bomName:[],
      bomStandard:[],
      isLeftAdd: true
    }
  },
  mounted() {
    this.tableType=0
    this.selectMaterialTree()
    this.selectVersion()
  },
  methods: {
    changeLeftAdd(){
        if(this.leftAdd.type.length===2){
          this.leftAdd.father=null
          this.leftAdd.father=this.leftAdd.type[1]
        }
        if(this.leftAdd.type.length===3){
          this.leftAdd.name=null
          this.leftAdd.father=this.leftAdd.type[1]
          this.leftAdd.name=this.leftAdd.type[2]
        }
        if(this.leftAdd.type.length===4){
          this.leftAdd.standard=null
          this.leftAdd.father=this.leftAdd.type[1]
          this.leftAdd.name=this.leftAdd.type[2]
          this.leftAdd.standard=this.leftAdd.type[3]
        }
    },
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let obj=JSON.parse(JSON.stringify(this.leftAdd))
            console.log(obj);
            let one=this.list.filter(item=>{
                return item.name===obj.type[0]
              })[0]
              let two=one.children.filter(item=>{
                return item.name===obj.father
              })[0]
              console.log("two",two);
              //执行一二级新增
              if(two===undefined||two===null){
                  obj.type=this.getType(obj.type[0])
                  this.$axios.post(this.$api.url.leftAddOneTwo,obj,{
                     headers: { "Content-Type": "application/json" }
                 }).then(res=>{
                     this.$message({
                      message: res.message,
                      type: 'success'
                      });
                      this.selectMaterialTree()   
                  })
              }else{
                let three=two.children.filter(item=>{
                  return item.name===obj.name
                })[0]
                console.log("three",three);
                if(three===undefined||three===null){
                  obj.type=this.getType(obj.type[0])
                  this.$axios.post(this.$api.url.leftAddOneTwo,obj,{
                     headers: { "Content-Type": "application/json" }
                 }).then(res=>{
                     this.$message({
                      message: res.message,
                      type: 'success'
                      });
                      this.selectMaterialTree()   
                  })
                }else{
                  //新增标准型号
                  let four=three.children.filter(item=>{
                    return item.name===obj.standard
                  })[0]
                  if(four===undefined||four===null){
                     let StandardDto={
                        "id": three.id,
                       "specifications": obj.specifications,
                       "standard": obj.standard
                     }
                     this.$axios.post(this.$api.url.leftAddThree,StandardDto,{
                     headers: { "Content-Type": "application/json" }
                 }).then(res=>{
                     this.$message({
                      message: res.message,
                      type: 'success'
                      });
                      this.selectMaterialTree()   
                   })
                  }else{
                     let specificationsDto={
                      "id": four.id,
                       "specifications": obj.specifications
                     }
                     this.$axios.post(this.$api.url.leftAddFour,specificationsDto,{
                     headers: { "Content-Type": "application/json" }
                 }).then(res=>{
                     this.$message({
                      message: res.message,
                      type: 'success'
                      });
                      this.selectMaterialTree()
                      this.selectVersion()
                   })
                  }
                }
              }
              this.resetForm('leftAdd')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.bomLeftAdd=false
        this.$refs[formName].resetFields();
      },
    leftAddBom(){
      
    },
    confirmAdd(formName){
      this.$refs[formName].validate(valid=>{
        if(valid){
          let type = this.typeselect;
          let obj = {}
          if(type == 0){
            obj = {
                specificationsId: Number.parseInt(this.returntree.id),
                deviceGroup: this.technologyForm.deviceGroup,
                father: this.technologyForm.tefather,
                name: this.technologyForm.tename,
                productionQuota: Number.parseInt(this.technologyForm.productionQuota),
              }
              this.submitBomAdd(this.$api.url.addTechnology,obj);
          }else if(type == 1){
            this.submitBomAdd(this.$api.url.addProductByStandard,this.targetForm);
          }
          
        }
      })
    },
    submitBomAdd(url,data){
      this.$axios.post(
          url,data,
          {headers: { "Content-Type": "application/json" }}
      ).then(res=>{
        this.selectAll();
        this.$message.success(res.message);
      }).catch(error=>{
        this.$message.error(error.message);
      })
      this.bomAddModelVisible = false;
    },
    clearBomAddModel(){
      if(this.typeselect == 0){
        this.$refs["technologyForm"].resetFields();
      }else if(this.typeselect == 1){
        this.$refs["targetForm"].resetFields();
      }else if(this.typeselect == 2){
        this.$refs["materialForm"].resetFields();
      }else{
        this.$refs["productForm"].resetFields();
      }
    },
    changeTechnologyId(val){
      this.$axios.get(this.$api.url.chooseFatherByStandard,{
        params:{technologyId : val}
      }).then(res=>{
        this.projectList = res.data;
      }).catch(error=>{
        this.$message.error(error.message);
      });
    },
    changeFather(val){
      let arr = this.targetFormList.filter(item=>{
        return item.name == val;
      });
      if(arr != undefined || arr.children != null){
        this.technologyIdList = arr[0].children;
      }
    },
    //获取工序,工艺列表
    getTargetFormList(){
      this.$axios.get(this.$api.url.chooseTechByStandard,{
        params:{specificationsId : this.returntree.id}
      }).then(res=>{
        this.targetFormList = res.data;
      }).catch(error=>{
        this.$message.error(error.message);
      })
    },
    //获取项目列表
    getProjectFormList(){
 
    },
    //获取工序列表
    getFatherList(){
      this.$axios.get(this.$api.url.chooseFather,{
        params:{specificationsId : this.returntree.id}
      }).then(res=>{
        this.fatherList = res.data;
      }).catch(error=>{
        this.$message.error(error.message);
      })
    },
    //获取设备组列表
    getDeviceList(){
      this.$axios.get(this.$api.url.chooseDevice).then(res=>{
        this.deviceList = res.data;
      }).catch(error=>{
        this.$message.error(error.message);
      })
    },
    showBomAddModel(){
      this.getFatherList();
      this.getDeviceList();
      this.getTargetFormList();
      this.bomAddModelVisible = true
    },
    startLeftAdd(){
      
    },
    getType(typeName){
      return typeName==="成品"?1:2
    },
    handleSelect(item) {
        console.log(item);
      },
      querySearch(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      querySearchName(queryString, cb) {
        var restaurants = this.bomName;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      querySearchStandar(queryString, cb) {
        var restaurants = this.bomStandard;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      loadFatherType(){
        return [{label:"橡胶连接器",value: "橡胶连接器"},{label:"金属连接器",value: "金属连接器"},
        {label:"湿插拔电连接器",value: "湿插拔电连接器"},{label:"分支组件",value: "分支组件"}]
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
    selectDataList() {
                this.list.forEach(a => {
                    a.code = '[1]'
                    if (a.children != undefined) {
                        a.children.forEach(b => {
                            b.code = '[2]'
                            if (b.children != undefined) {
                                b.children.forEach(c => {
                                    c.code = '[3]'
                  if (c.children != undefined) {
                                c.children.forEach(d => {
                                    d.code = '[4]'
                  if (d.children != undefined) {
                                d.children.forEach(e => {
                                    e.code = '[5]'
                                })
                            }
                                })
                            }
                                })
                            }
                        })
                    }
                })
            },
    handleSelectionChange() {
 
    },
    TYPE(val) {//类型.数据
      // console.log(val);
      this.typeselect = val
 
      // console.log(this.typeselect);
      this.selectVersion()
    },
    handleNodeClick(val) {//树的值
      if(val.code==='[5]'&&val.children===undefined){
        console.log(val);
        this.returntree = val
        this.typeselect=0
        this.selectVersion()
      }
    },
    async selectVersion() {//版本
      let v=await this.$axios.get(this.$api.url.selectVersion, {
        params: {
          specificationsId: this.returntree.id,
          type: this.typeselect,
        }
      }).then(res => {
        this.verdata = res.data
        this.version = this.verdata.map(el => {
          return el = `v${el}`
        })
        // console.log("版本");
        return this.verdata[0]
      })
      this.character=v
      this.VER="v"+v
      this.selectAll()
    },
    //右侧数据
    selectAll() {
      this.$axios.get(this.$api.url.selectAll, {
        params: {
          specificationsId: this.returntree.id,//tree的点击反馈
          type: this.typeselect,//类型
          version: this.character,//版本
        }
      }).then(res => {
        let arr = res.data;
        this.formatData(arr)
        this.tableData = arr;
      })
    },
    formatData(data){
      let arr = data;
      for(var i=0;i<arr.length;i++){
            arr[i].rowId = Math.random();
            if(arr[i].children != undefined){
              this.formatData(arr[i].children);
            }
        }
    },
    verevent(val) {
      // console.log(val);
      let cc = val.replace('v', '')
      // console.log(cc);
      this.character = cc
      this.selectAll()
      // const { v, ...newObj } = val;
      // delete newObj.v
      // console.log(newObj);
    },
    //五级树
    selectMaterialTree() {
      this.$axios.get(this.$api.url.selectTreeByMaterial).then( res => {
        this.list=res.data
        this.list.forEach((el, idx, arr) => {
          if (idx == 0) {
            arr[idx].name = '成品'
          }
          if (idx == 1) {
            arr[idx].name = '半成品'
          }
        })
        this.selectDataList()
        // 默认第一个五级节点搜索,新增配置项
        const treeOptions = JSON.parse(JSON.stringify(this.list));
        this.getDefault(treeOptions, 0);
        this.formTypeOptions = treeOptions;
        this.$nextTick().then(() => {
          const firstNode = document.querySelector(
            ".el-tree-node .el-tree-node__children .el-tree-node .el-tree-node__children .el-tree-node .el-tree-node__children .el-tree-node .el-tree-node__children .el-tree-node"
          );
          try {
            firstNode.click();
          } catch (e) {
            //TODO handle the exception
          }
        });
      })
    },
    getDefault(arr, index) {
            for (const item of arr) {
                if (item.children && item.children.length > 0) {
                    // 有子节点
                    this.getDefault(item.children, index + 1);
                    if (index === 2) {
                        item.children = null;
                    }
                }
            }
        },
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    remove(node, data) {
      this.$confirm("是否删除", "警告", {
        type: "warning"
      }).then(res => {
        const parent = node.parent;
        const children = parent.data.children || parent.data;
        const index = children.findIndex(d => d.id === data.id);
        children.splice(index, 1);
      }).catch(e => { })
    },
    nodeOpen(data, node, el) {
      $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder-opened')
    },
    nodeClose(data, node, el) {
      $($(el.$el).find('.node_i')[0]).attr('class', 'node_i el-icon-folder')
    },
    async selectProductTableData() {
      switch (this.tableType) {
        case 0:
          const { data: technologyList } = await this.$axios.get(this.$api.url.selectTechnologyByMaterial, { params: { specificationId: this.checkTreeNode.id, technologyName: this.searchName } })
          this.tableData = technologyList
          break;
        case 1:
          const { data: productList } = await this.$axios.get(this.$api.url.selectProductByMaterial, { params: { specifications: this.checkTreeNode.id, project: this.searchName } })
          productList.forEach((item, index) => {
            item.name = item.father
            item.index = index + 1
            item.id = item.father
            if (item.children.length === 1) {
              productList[index] = { ...item.children[0], index: index + 1, name: item.father }
            }
          })
          this.tableData = productList
          break;
      }
    },
    // 递归更改添加级联所需属性
    replaceProp(arr){
      for (let index = 0; index < arr.length; index++) {
        let element = arr[index];
        element.label=element.name
        element.value=element.name
        if(element.children!=undefined){
          if(element.code==='[4]'){
            delete element['children']
            continue
          }
          this.replaceProp(element.children)
        }
      }
    }
  },
  watch:{
    leftAdd: {
    handler(newVal, oldVal) {
    if(this.isLeftAdd){
      let tree=JSON.parse(JSON.stringify(this.list))
      let father=null;
      if(newVal.father!=null&&newVal.father!=''&&newVal.type.length>0){
          let one=tree.filter(item=>{
            return item.name===newVal.type[0]
          })[0]
          console.log(one);
          let two=one.children.filter(item=>{
            return item.name===newVal.father
          })[0]
          if(two!=undefined){
            this.bomName=[]
            father=JSON.parse(JSON.stringify(two))
            two.children.forEach(item=>{
              let obj={label: item.name,value: item.name}
              this.bomName.push(obj)
            })
          }
      }
      if(newVal.name!=null&&newVal!=''&&newVal.father!=null&&newVal.father!=''&&newVal.type.length>0){
          let three=null
          if(father!=undefined&&father!=null){
            three=father.children.filter(item=>{
            return item.name===newVal.name
          })[0]
          }
          if(three!=undefined&&three!=null){
            this.bomStandard=[]
            three.children.forEach(item=>{
              let obj={label: item.name,value: item.name}
              this.bomStandard.push(obj)
            })
          }
      }
      }
    },
     deep: true // 深度监听对象内部属性的变化,可选的
  },
  bomLeftAdd:{
    handler(newval,oldVal){
      if(newval){
       let treeOptions = JSON.parse(JSON.stringify(this.list));
       this.replaceProp(treeOptions)
             this.formTypeOptions=treeOptions
       this.restaurants=this.loadFatherType()
      }
    }
  },
  bomAddModelVisible(newVal){
    if(!newVal){
      this.clearBomAddModel();
    }
  }
  }
}
</script>
 
 
<style scoped>
 
.standard .bom-add-model{
  width: 100%;
}
 
.standard .bom-add-model form{
  width: 90%;
  margin-left: 5%;
}
 
.standard .title .el-button {
  height: 32px;
  border: 1px solid rgba(190, 190, 190, 0.44);
  box-shadow: 0px 2px 4px rgba(220, 220, 220, 0.41);
  padding: 0 12px;
}
 
.standard .title {
  margin-bottom: 10px;
  padding: 0 20px;
}
 
.standard .title * {
  font-size: 16px;
}
 
.thing {
  width: 100%;
  height: calc(100% - 48px);
  background-color: #fff;
  display: flex;
}
 
.thing .left {
  width: 295px;
  height: calc(100% - 32px);
  overflow-y: auto;
  border-right: 3px solid rgb(245, 247, 251);
  padding: 16px;
}
 
.thing .left .custom-tree-node span {
  font-size: 14px;
}
 
.thing .left .custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
 
.node_i {
  color: orange;
}
 
.el-icon-delete {
  display: none;
  color: #004EA2;
}
 
.custom-tree-node:hover .el-icon-delete {
  display: inline;
}
 
.thing .right {
  width: calc(100% - 295px);
  height: 100%;
  overflow: hidden;
}
 
.thing .right .choose {
  padding: 21px 24px;
  display: flex;
  align-items: center;
}
 
.thing .right .choose * {
  font-size: 14px;
}
 
.thing .right .choose .el-button {
  height: 32px;
  border: 1px solid rgba(190, 190, 190, 0.44);
  box-shadow: 0px 2px 4px rgba(220, 220, 220, 0.41);
  padding: 0 12px;
}
 
.thing .right .table {
  margin-right: 24px;
  height: calc(100% - 74px);
}
</style>
<style>
.standard .title .el-button * {
  font-size: 14px;
}
 
.standard .title .el-button--default {
  color: #004EA2;
}
 
.standard .thing .left .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
  background: rgba(58, 124, 253, 0.3);
  color: #004EA2;
}
 
.el-tree-node__content {
  height: 30px;
  border-radius: 2px;
}
</style>