Fixiaobai
2023-11-17 1f5009ddcc87f7a7db792d40206bdcf5462089ee
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
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
<template>
  <div class="mod-config">
    <basic-container>
      <ttable :table="table" @handleSelectionChange="handleSelectionChange" :uploadInfo="uploadInfo" :prelang="prelang"
        :options="options" :ajaxFun="ajaxFun" ref="masterProductionScheduleTable">
        <template #toolbar>
          <el-dropdown v-if="permissions.masterproductionschedule_create_order" @command="orderTypeHandleCommand">
            <el-button>
              车间订单<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :key="item" :command="item.command" v-for="item in orderTypeArr" :disabled="item.disabled">{{
                item.label }}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
 
          <el-dropdown v-if="permissions.masterproductionschedule_state_change" @command="handleCommand"
            style="margin-left: 10px">
            <el-button>
              状态改变<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :key="item" :command="item.command" v-for="item in stateTagArr" :disabled="item.disabled">{{
                item.label }}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
 
          <el-dropdown v-if="permissions.masterproductionschedule_doc_relate" @command="documentHandle"
            style="margin-left: 10px">
            <el-button>
              工艺文件<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :key="item" :command="item.command" v-for="item in documentTagArr" :disabled="item.disabled">
                {{ item.label }}
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!--审核状态改变-->
          <el-dropdown v-if="permissions.masterproductionschedule_audit_change" @command="handleCommitCommand"
            style="margin-left: 10px">
            <el-button>
              审核状态改变<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :key="item" :command="item.command" v-for="item in commitStateTagArr" :disabled="item.disabled">{{item.label }}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button v-if="permissions.masterproductionschedule_submit_oa" @click="commitOa()" type="primary"
            style="margin-left:10px;" :loading="loadingOa">提交OA
          </el-button> -->
          <!-- <el-button
            v-if="permissions.masterproductionschedule_sync_scm"
            @click="syncScm()"
            type="primary"
            style="margin-left:10px;"
            >同步SCM
          </el-button>
          <el-button
            v-if="permissions.masterproductionschedule_statechange_scm"
            @click="stateChangeScm()"
            type="primary"
            style="margin-left:10px;"
            >SCM状态变更
          </el-button> -->
          <el-button
            type="primary"
            style="margin-left:10px;"
            @click="addPlanProcure"
            >新增采购计划
          </el-button>
        </template>
      </ttable>
 
      <!-- 弹窗, 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getData" />
      <source-table v-if="masterPlanSourceDialogVisible" ref="source" @refreshDataList="getData" />
      <order-table v-if="orderVisible" ref="order" />
      <manufacturing-order v-if="manufacturingOrderVisible" ref="manufacturingOrder" @refreshDataList="getData" />
      <outsourcing-order v-if="outsourcingOrderVisible" ref="outsourcingOrder" @refreshDataList="getData" />
      <!--库存-->
      <stockDialog :currshowlist.sync="stockVisible" :partName="partName" />
      <!--工艺文件-->
      <DocumentTable :currshowlist.sync="showDocument" :multiSelect="false" :relationOrderList="masterPlanSelection"
        @listenToDocumentEvent="selectDocument">
      </DocumentTable>
      <!--手动创建车间订单-->
      <ManualManufacturingOrder :currshowlist.sync="showManualManufacturingOrder"
        :manualMasterProduction="manualMasterProduction" @refreshOrderFromManual="refreshOrderFromManual">
      </ManualManufacturingOrder>
      <!--自动创建车间订单-->
      <AutoManufacturingorder :currshowlist.sync="showAutoManufacturingOrder" :masterProduction="manualMasterProduction"
        :isReportOperation="isReportOperation" :outPutBatchList="selectedOutPutBatchList" :qtyPlaned="qtyPlaned"
        @refreshDataList="AutoManuFinished">
      </AutoManufacturingorder>
 
      <!--弹窗,新增-->
      <MasterproductionForm :currshowlist.sync="showMasterproductionForm" @refreshDataList="getData">
      </MasterproductionForm>
      <!--产出批次-->
      <!--<OutPutBatch
        :currshowlist.sync="showOutPutBatch"
        :createOrderType="createOrderType"
        :outPutBatchList="outPutBatchList"
        @returnBatchData="returnBatchData"
      ></OutPutBatch>-->
    </basic-container>
  </div>
</template>
 
<script>
import { mapGetters } from 'vuex'
import TableForm from './masterproductionschedule-form'
import MasterproductionForm from './masterproduction-form'
import SourceTable from './source-table'
import OrderTable from './order-table'
import ManufacturingOrder from './manufacturing-order'
import ManualManufacturingOrder from './manual-manufacturingorder'
import AutoManufacturingorder from './auto-manufacturingorder'
import OutsourcingOrder from '../outsourcingorder/outsourcingorder-form'
import {
  delObj,
  fetchList,
  loadOrderHandle,
  addPlanPurchasing
} from '@/api/plan/masterproductionschedule'
import ttable from '@/views/common/ztt-table.vue'
import stockDialog from '@/views/common/stock'
import {
  changeMpsState,
  handleDocument,
  rejectHandleDocument,
  auditMasterProductionSchedule,
  changeAudit
} from '../../../api/plan/masterproductionschedule'
import { highPrecisionReduce } from '@/util/highPrecision'
import DocumentTable from '@/views/common/document.vue'
import { remote } from '@/api/admin/dict'
import { getObj as getSysParam } from '@/api/admin/sys-public-param'
import { sysParam } from '../../../config/sysParam' // 系统参数
import { getByMpsIds } from '@/api/plan/operationtaskproduce'
import { masterProductionScheduleSave, changeState } from '@/api/scm/common'
 
export default {
  data() {
    return {
      ajaxFun: fetchList,
      statesList: [
        { value: '01pending', label: '待处理' },
        { value: '02processed', label: '已处理' },
        { value: '03canceled', label: '已作废' }
      ],
      isAuditList: [
        {
          value: '01draft',
          label: '草稿'
        },
        {
          value: '02pending',
          label: '审核中'
        },
        {
          value: '03accepted',
          label: '通过'
        },
        {
          value: '04reject',
          label: '退回'
        }
      ],
      orderTypeArr: [],
      stateTagArr: [
        {
          label: '标记待处理',
          command: 'PENDING',
          disabled: false,
          permitArr: ['02processed']
        },
        {
          label: '标记已处理',
          command: 'PROCESSED',
          disabled: false,
          permitArr: ['01pending']
        },
        {
          label: '标记已作废',
          command: 'CANCELED',
          disabled: false,
          permitArr: ['01pending']
        }
      ],
      documentTagArr: [
        {
          label: '关联工艺文件',
          command: 'RELEVANCE',
          disabled: false
        },
        {
          label: '移除工艺文件',
          command: 'NORELEVANCE',
          disabled: false
        }
      ],
      commitStateTagArr: [
        {
          label: '标记通过',
          command: 'PROCESSED',
          disabled: false,
          permitArr: ['01draft']
        },
        {
          label: '标记取消',
          command: 'CANCELLED',
          disabled: false,
          permitArr: ['03accepted']
        }
      ],
      events: '',
      showDocument: false,
      masterPlanSourceDialogVisible: false,
      orderVisible: false,
      manufacturingOrderVisible: false,
      outsourcingOrderVisible: false,
      masterPlanSelection: [],
      mpsRequirementsVisible: false,
      coStates: [],
      currentRow: null,
      multipleSelection: [],
      isShowQuery: false,
      uploadInfo: {
        // 是否展示上传EXCEL以及对应的url
        isShow: false,
        url: ''
      },
      dateTimeFilters: {},
      prelang: 'operation',
      options: {
        height: 300, // 默认高度-为了表头固定
        stripe: true, // 是否为斑马纹 table
        highlightCurrentRow: false, // 是否要高亮当前行
        border: true, // 是否有纵向边框
        lazy: false, // 是否需要懒加载
        fit: true, // 列的宽度是否自撑开
        multiSelect: true, //
        seqNo: true,
        isRefresh: true, // 是否显示刷新按钮
        isShowHide: true, // 是否显示显影按钮H
        isSearch: true, // 高级查询按钮
        defaultOrderBy: { column: 'createTime', direction: 'desc' }
      },
      table: {
        total: 0,
        currentPage: 1,
        pageSize: 20,
        data: [],
        // 标题
        column: [
          {
            minWidth: '100',
            prop: 'source',
            label: '来源',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '120',
            prop: 'state',
            label: '状态',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.getScheduleState,
            optList: () => {
              return this.getScheduleStateList()
            }
          },
          {
            minWidth: '120',
            prop: 'isAudit',
            label: '审核状态',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.getIsAudit,
            optList: () => {
              return this.isAuditList
            }
          },
          {
            minWidth: '140',
            prop: 'customerOrderNo',
            label: '订单号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '100',
            prop: 'mpsNo',
            label: '生产计划号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text',
            render: { fun: this.addOrUpdateHandle }
          },
          {
            minWidth: '120',
            prop: 'partNo',
            label: '零件号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '120',
            prop: 'partName',
            label: '零件',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '80',
            prop: 'docNumber',
            label: '工艺文件号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '140',
            prop: 'qtyRequired',
            // label: '主计划需求数量',
            label: '销售数量',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '140',
            prop: 'inventoryReservedQuantity',
            label: '库存预留数量',
            sort: true,
            isTrue: true,
            isSearch: false,
            searchInfoType: 'text'
          },
          {
            minWidth: '140',
            prop: 'outsourcingNumber',
            label: '委外数量',
            sort: true,
            isTrue: true,
            isSearch: false,
            searchInfoType: 'text'
          },
          {
            minWidth: '140',
            prop: 'manufacturingQuantity',
            label: '制造数量',
            sort: true,
            isTrue: true,
            isSearch: false,
            searchInfoType: 'text'
          },
 
          {
            minWidth: '80',
            prop: 'unit',
            label: '零件单位',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '120',
            width: '120',
            prop: 'requiredDate',
            label: '主计划需求日期',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text',
            formatter: this.formatDutyDate
          },
          {
            minWidth: '120',
            width: '120',
            prop: 'promisedDeliveryDate',
            label: '承诺日期',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text',
            formatter: (row, column, cellValue) => {
              var formatVal
              if (cellValue) {
                if (this.getDays(cellValue, row)) {
                  formatVal =
                    '<div style="background-color:red;color: #fff;">' +
                    cellValue.substring(0, 10) +
                    '</div>'
                } else {
                  formatVal =
                    '<span>' +
                    (cellValue != null ? cellValue.substring(0, 10) : '') +
                    '</span>'
                }
              } else {
                formatVal =
                  '<span>' +
                  (cellValue != null ? cellValue.substring(0, 10) : '') +
                  '</span>'
              }
              return formatVal
            }
          },
          {
            minWidth: '120',
            prop: 'manufactureAttr',
            label: '制造属性',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.getManufactureAttr,
            optList: () => {
              return this.manufactureAttrs
            }
          },
          {
            minWidth: '120',
            prop: 'remark',
            label: '备注',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '120',
            width: '120',
            prop: 'updateTime',
            label: '更新时间',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'datetimerange',
            formatter: this.formatDutyDate
          },
          {
            minWidth: '120',
            prop: 'updateUser',
            label: '更新人',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '140',
            width: '120',
            prop: 'createTime',
            label: '创建时间',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'datetimerange',
            formatter: this.formatDutyDate
          },
          {
            minWidth: '140',
            prop: 'createUser',
            label: '创建人',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // {
          //   minWidth: '140',
          //   prop: 'outerColor',
          //   label: '外护颜色',
          //   sort: true,
          //   isTrue: true,
          //   isSearch: true,
          //   searchInfoType: 'text'
          // },
          // {
          //   minWidth: '140',
          //   prop: 'lengthRequirement',
          //   label: '盘长要求',
          //   sort: true,
          //   isTrue: true,
          //   isSearch: true,
          //   searchInfoType: 'text'
          // },
          // {
          //   minWidth: '140',
          //   prop: 'printRequirement',
          //   label: '印字要求',
          //   sort: true,
          //   isTrue: true,
          //   isSearch: true,
          //   searchInfoType: 'text'
          // },
          {
            minWidth: '140',
            prop: 'remark',
            label: '销售订单备注',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          }
        ],
        toolbar: [],
        operator: [
          {
            text: '作废',
            type: 'text',
            size: 'small',
            fun: this.deleteMainPlan
          }
          // {
          //   text: '订单预留',
          //   type: 'text',
          //   size: 'small',
          //   fun: this.customReserved
          // },
          // {
          //   text: '查看库存',
          //   type: 'text',
          //   size: 'small',
          //   fun: this.stockHandle
          // },
          // {
          //   text: '来源',
          //   type: 'text',
          //   size: 'small',
          //   fun: this.searchMasterPlanSourceHandle
          // },
          // {
          //   text: '订单',
          //   type: 'text',
          //   size: 'small',
          //   fun: this.searchOrderHandle
          // }
        ],
        operatorConfig: {
          fixed: 'right',
          label: '操作',
          width: 100,
          minWidth: 100
        }
      },
      addOrUpdateVisible: false,
      stockVisible: false,
      partName: null,
      loadingOa: false,
      showManualManufacturingOrder: false,
      showAutoManufacturingOrder: false,
      showMasterproductionForm: false,
      manualMasterProduction: null,
      manufactureAttrs: [],
      isReportOperation: false,
      createOrderType: 'MANUAL',
      outPutBatchList: [],
      selectedOutPutBatchList: [],
      qtyPlaned: 0,
      hasMore: false
    }
  },
  components: {
    ttable,
    TableForm,
    SourceTable,
    OrderTable,
    ManufacturingOrder,
    OutsourcingOrder,
    stockDialog,
    DocumentTable,
    ManualManufacturingOrder,
    AutoManufacturingorder,
    MasterproductionForm
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  activated() {
    this.getData()
  },
  created() {
    this.getManufactureAttrs()
    /*
          {
            text: '新增',
            type: 'primary',
            fun: this.addMasterProductionSchedule,
            disabled: false,
            permitArr: []
          },
          {
            text: '创建委外订单',
            fun: this.createOutsourcingOrder
          } */
    if (this.permissions.plan_masterproductionschedule_add) {
      this.table.toolbar.push({
        text: '新增',
        type: 'primary',
        fun: this.addMasterProductionSchedule,
        disabled: false,
        permitArr: []
      })
    }
    if (this.permissions.masterproductionschedule_create_outsourcing) {
      this.table.toolbar.push({
        text: '创建委外订单',
        fun: this.createOutsourcingOrder
      })
    }
    if (this.permissions.masterproductionschedule_create_order_manual) {
      this.orderTypeArr.push({
        label: '手动新增',
        command: 'MANUAL',
        disabled: false,
        permitArr: ['02processed']
      })
    }
    if (this.permissions.masterproductionschedule_create_order_auto) {
      this.orderTypeArr.push({
        label: '自动新增',
        command: 'AUTO',
        disabled: false,
        permitArr: ['01pending']
      })
    }
    this.getSysParam(sysParam.IS_REPORT_OPERATION)
  },
  methods: {
    addPlanProcure(){
      let val=this.masterPlanSelection.filter(item=>{
        return item.technologyDocumentId==null||item.technologyDocumentId==''||item.docNumber==''||item.docNumber==null
      })
      if(val.length>0){
        this.$message.warning("当前所选择的计划,含有未绑定工艺文件!")
        return
      }
      addPlanPurchasing(this.masterPlanSelection).then(res=>{
        console.log(res);
      })
    },
    deleteMainPlan(row){
      console.log(row);
    },
    getSysParam(paramKey) {
      getSysParam(paramKey).then((response) => {
        var paramVal = response.data.data
        if (response.data.code === 0) {
          if (paramVal != null && paramVal === 'true') {
            this.isReportOperation = true
          } else {
            this.isReportOperation = false
          }
        } else {
          this.isReportOperation = false
        }
      })
    },
    getManufactureAttr(row, column, cellValue) {
      this.manufactureAttrs.forEach((obj) => {
        if (obj.value === cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    getManufactureAttrs() {
      remote('manufacture_attr_type').then((response) => {
        if (response.data.code === 0) {
          this.manufactureAttrs = response.data.data
        } else {
          this.manufactureAttrs = []
        }
      })
    },
    // 获取数据列表
    getData() {
      this.$refs.masterProductionScheduleTable.getDataList()
    },
    // 新增
    addMasterProductionSchedule() {
      this.showMasterproductionForm = true
    },
    // 修改
    addOrUpdateHandle(row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row ? row.id : row, row ? row.state : row)
      })
    },
    formatDutyDate(row, column, cellValue) {
      if (cellValue) {
        const dutyDateList = /\d{4}-\d{1,2}-\d{1,2}/g.exec(cellValue)
        if (dutyDateList && dutyDateList.length > 0) {
          return dutyDateList[0]
        }
      }
      return ''
    },
    // 删除
    deleteHandle(row) {
      this.$confirm('是否确认删除ID为' + row.id, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      })
        .then(function () {
          return delObj(row.id)
        })
        .then((data) => {
          this.$message.success('删除成功')
          this.getData()
        })
    },
    // 查看生产计划来源
    searchMasterPlanSourceHandle(row) {
      this.masterPlanSourceDialogVisible = true
      this.$nextTick(() => {
        this.$refs.source.init(row.id, row.state)
      })
    },
    // 查看制造订单/委外订单
    searchOrderHandle(row) {
      this.orderVisible = true
      this.$nextTick(() => {
        this.$refs.order.init(row.id)
      })
    },
    // 创建制造订单
    createManufacturingOrder() {
      if (this.masterPlanSelection && this.masterPlanSelection.length === 1) {
        this.$router.push({
          name: 'productorderForm',
          query: {
            id: null,
            partId: this.masterPlanSelection[0].partId,
            partName: this.masterPlanSelection[0].partName,
            partNo: this.masterPlanSelection[0].partNo,
            mpsId: this.masterPlanSelection[0].id,
            // qtyRequired: Number(this.masterPlanSelection[0].qtyRequired - this.masterPlanSelection[0].inventoryReservedQuantity   - this.masterPlanSelection[0].outsourcingNumber
            //  - this.masterPlanSelection[0].manufacturingQuantity ).toFixed(6)
            // ,
            qtyRequired: Number(
              highPrecisionReduce(
                highPrecisionReduce(
                  highPrecisionReduce(
                    this.masterPlanSelection[0].qtyRequired,
                    this.masterPlanSelection[0].inventoryReservedQuantity
                  ),
                  this.masterPlanSelection[0].outsourcingNumber
                ),
                this.masterPlanSelection[0].manufacturingQuantity
              )
            ).toFixed(6),
 
            requiredDate: this.masterPlanSelection[0].requiredDate,
            outerColor: this.masterPlanSelection[0].outerColor
          }
        })
      } else {
        this.$message.error('请选择一条生产计划')
      }
    },
    // 创建委外订单
    createOutsourcingOrder() {
      if (this.masterPlanSelection && this.masterPlanSelection.length === 1) {
        this.outsourcingOrderVisible = true
        this.$nextTick(() => {
          this.$refs.outsourcingOrder.init(null, this.masterPlanSelection[0])
        })
      } else {
        this.$message.error('请选择一条生产计划')
      }
    },
    getScheduleStateList() {
      return this.statesList
    },
 
    getScheduleState(row, column, cellValue) {
      this.statesList.forEach((obj) => {
        if (obj.value === cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    // 创建车间订单
    orderTypeHandleCommand(event) {
      if (event === 'MANUAL') {
        // 手动新增,弹出手动新增的页面
        if (this.masterPlanSelection.length == 0) {
          this.$message.error('请选择生产计划')
        } else {
          if (this.masterPlanSelection.length == 1) {
            const masterPlan = this.masterPlanSelection[0]
            if (
              masterPlan.isAudit != null &&
              masterPlan.isAudit == '03accepted'
            ) {
              this.manualMasterProduction = masterPlan
              this.showManualManufacturingOrder = true
            } else {
              this.$message.error(
                '只有【审核状态】为‘通过’的生产计划,才能进行车间订单的创建'
              )
            }
          } else {
            this.$message.error('只能选择一条生产计划')
          }
        }
      } else {
        // 自动新增,弹出自动新增的页面
        if (this.masterPlanSelection.length == 0) {
          this.$message.error('请选择生产计划')
        } else {
          if (this.masterPlanSelection.length == 1) {
            const masterPlan = this.masterPlanSelection[0]
            if (
              masterPlan.isAudit != null &&
              masterPlan.isAudit == '03accepted'
            ) {
              this.manualMasterProduction = masterPlan
              // 根据主计划id,查询对应的产出批次
              getByMpsIds([masterPlan.id]).then((repsonse) => {
                const resData = repsonse.data.data
                const resCode = repsonse.data.code
                if (resCode === 0) {
                  const _that = this
                  for (const key in resData) {
                    resData[key].forEach((item) => {
                      if (item.moId != null) {
                        _that.$set(item, 'commonChecked', false)
                      } else {
                        _that.$set(item, 'commonChecked', true)
                      }
                    })
                  }
                  this.hasMore = false
                  this.showAutoManufacturingOrder = true
                }
              })
            } else {
              this.$message.error(
                '只有【审核状态】为‘通过’的生产计划,才能进行车间订单的创建'
              )
            }
          } else {
            this.$message.error('只能选择一条生产计划')
          }
        }
      }
    },
    // 选中产出批次时的,回调
    returnBatchData(selectedObj) {
      //
      this.selectedOutPutBatchList = selectedObj.outPutBatchList
      this.qtyPlaned = selectedObj.qtyPlaned
      this.hasMore = selectedObj.hasMore
      if (selectedObj.createOrderType === 'MANUAL') {
        this.showManualManufacturingOrder = true
      } else if (selectedObj.createOrderType === 'AUTO') {
        this.showAutoManufacturingOrder = true
      }
    },
    // 自动创建车间订单-完成后的回调
    AutoManuFinished() {
      if (this.hasMore) {
        this.orderTypeHandleCommand('AUTO')
      } else {
        this.getData()
      }
    },
    // 状态改变
    handleCommand(event) {
      var eventName
      if (event == 'PENDING') {
        eventName = '待处理'
      } else if (event == 'PROCESSED') {
        eventName = '已处理'
      } else {
        eventName = '已作废'
      }
      if (this.masterPlanSelection.length > 0) {
        changeMpsState(
          this.masterPlanSelection.map((item) => {
            return item.id
          }),
          event
        ).then((response) => {
          var data = response.data
          if (data.code == 0) {
            this.$message.success(eventName + '修改成功')
            this.getData()
          } else {
            this.$message.error(eventName + '修改失败')
          }
        })
      } else {
        this.$message.error('请选择' + eventName + '的对象')
      }
    },
    getIsAudit(row, column, cellValue) {
      this.isAuditList.forEach((obj) => {
        if (obj.value === cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    // 审核状态改变
    handleCommitCommand(event) {
      if (this.masterPlanSelection.length > 0) {
        if (this.masterPlanSelection.length > 1) {
          this.$message.error('只能选择一条生产计划')
        } else {
          const masterPlan = this.masterPlanSelection[0]
          if (event == 'CANCELLED') {
            if (
              masterPlan.isAudit != null &&
              masterPlan.isAudit == '03accepted'
            ) {
              loadOrderHandle(masterPlan.id).then((response) => {
                const resData = response.data
                if (resData.code === 0) {
                  if (resData.data.length > 0) {
                    this.$confirm(
                      '主生产计划已创建车间订单, 是否继续?',
                      '提示',
                      {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                      }
                    )
                      .then(() => {
                        if (masterPlan.technologyDocumentId != null) {
                          changeAudit(masterPlan.id, '01draft').then(
                            (response) => {
                              const data = response.data
                              if (data.code == 0) {
                                this.$message.success('审核状态变更成功')
                                this.getData()
                              } else {
                                this.$message.error('审核状态变更失败')
                              }
                            }
                          )
                        } else {
                          this.$message.error('该条生产计划,未关联工艺文件!')
                        }
                      })
                      .catch(() => {
                        this.$message({
                          type: 'info',
                          message: '已取消'
                        })
                      })
                  } else {
                    if (masterPlan.technologyDocumentId != null) {
                      changeAudit(masterPlan.id, '01draft').then((response) => {
                        const data = response.data
                        if (data.code == 0) {
                          this.$message.success('审核状态变更成功')
                          this.getData()
                        } else {
                          this.$message.error('审核状态变更失败')
                        }
                      })
                    } else {
                      this.$message.error('该条生产计划,未关联工艺文件!')
                    }
                  }
                } else {
                  this.$message.error('查询车间订单失败')
                }
              })
            } else {
              this.$message.error(
                '只有【审核状态】为‘通过’的生产计划,才能标记取消!'
              )
            }
          } else {
            if (masterPlan.isAudit != null && masterPlan.isAudit == '01draft') {
              if (masterPlan.technologyDocumentId != null) {
                changeAudit(masterPlan.id, '03accepted').then((response) => {
                  const data = response.data
                  if (data.code == 0) {
                    this.$message.success('审核状态变更成功')
                    this.getData()
                  } else {
                    this.$message.error('审核状态变更失败')
                  }
                })
              } else {
                this.$message.error('该条生产计划,未关联工艺文件!')
              }
            } else {
              this.$message.error(
                '只有【审核状态】为‘草稿’的生产计划,才能标记通过!'
              )
            }
          }
        }
      } else {
        this.$message.error('请选择一条生产计划')
      }
    },
    // table自带事件
    handleSelectionChange(val) {
      // 根据状态,禁用表头按钮
      // 筛选出选中记录的状态
      var stateArr = val.map(function (value, index) {
        return value.state
      })
      // 选中状态数组元素去重
      var uniqueStateArr = []
      for (var i = 0; i < stateArr.length; i++) {
        if (uniqueStateArr.indexOf(stateArr[i]) == -1) {
          uniqueStateArr.push(stateArr[i])
        }
      }
      // 循环自定义按钮,判断每个按钮的permitArr是否完全包含选中状态,若完全包含,则按钮亮,否则按钮灰
      for (var i = 0; i < this.stateTagArr.length; i++) {
        if (
          uniqueStateArr.every((val) =>
            this.stateTagArr[i].permitArr.length <= 0
              ? true
              : this.stateTagArr[i].permitArr.includes(val)
          )
        ) {
          this.stateTagArr[i].disabled = false
        } else {
          this.stateTagArr[i].disabled = true
        }
      }
      this.masterPlanSelection = val
    },
    // 查看库存
    stockHandle(row) {
      this.stockVisible = true
      this.partName = row.partName
    },
    selectDocument(document) {
      if (document) {
        this.changeDocument(document.id)
      }
    },
    documentHandle(event) {
      var status = false
      this.events = event
      if (this.masterPlanSelection.length == 0) {
        this.$message.error('请至少选择一条生产计划')
      } else {
        if (event == 'RELEVANCE') {
          this.masterPlanSelection.forEach((item) => {
            if (item.isDocument) {
              status = true
              this.$message.error(
                '存在生产计划已关联工艺文件,如需更改,请先解除关联'
              )
            }
          })
          if (!status) {
            this.showDocument = true
          }
        } else {
          this.changeDocument(null)
        }
      }
    },
    changeDocument(id) {
      var eventName
      if (this.events == 'RELEVANCE') {
        eventName = '关联工艺文件'
        const masterProductionIds = []
        this.masterPlanSelection.forEach((item) => {
          masterProductionIds.push(item.id)
        })
        handleDocument(masterProductionIds, id).then((res) => {
          if (res.data.code == 0) {
            this.$message.success(eventName + '成功')
            this.getData()
          } else {
            this.$message.error(res.data.msg)
          }
        })
      } else if (this.events == 'NORELEVANCE') {
        eventName = '移除工艺文件'
        const masterProductionIds = []
        this.masterPlanSelection.forEach((item) => {
          masterProductionIds.push(item.id)
        })
        rejectHandleDocument(masterProductionIds).then((res) => {
          if (res.data.code == 0) {
            this.$message.success(eventName + '成功')
            this.getData()
          } else {
            this.$message.error(res.data.msg)
          }
        })
      }
    },
    // 跳转至客户订单预留页面
    customReserved(row) {
      if (row.customerOrderNo != null) {
        localStorage.setItem('masterschedule_customno', row.customerOrderNo)
        localStorage.setItem('masterschedule_partno', row.partNo)
        localStorage.setItem('masterschedule_qtyrequired', row.qtyRequired)
 
        this.$router.push('/warehouse/orderreserved/index').catch(() => { })
      } else {
        this.$message.warning('该生产计划,不可进行客户订单预留!')
      }
    },
    // 同步SCM
    syncScm() {
      masterProductionScheduleSave().then((response) => {
        this.$message.success('同步SCM成功!')
      })
    },
    // SCM状态变更
    stateChangeScm() {
      if (this.masterPlanSelection.length == 0) {
        this.$message.error('请选择一条生产计划')
      } else {
        changeState(this.masterPlanSelection[0].id).then((response) => {
          this.$message.success('SCM状态变更成功!')
        })
      }
    },
    // 提交OA
    commitOa() {
      if (this.masterPlanSelection.length == 0) {
        this.$message.error('请选择一条生产计划')
      } else {
        if (this.masterPlanSelection.length > 1) {
          this.$message.error('只能选择一条生产计划')
        } else {
          const masterPlan = this.masterPlanSelection[0]
          if (masterPlan.isAudit != null && masterPlan.isAudit == '01draft') {
            this.loadingOa = true
            auditMasterProductionSchedule(masterPlan.id)
              .then((response) => {
                const resData = response.data
                if (resData.code === 0) {
                  this.$message.success('提交OA成功!')
                  this.getData()
                } else {
                  this.$message.error('提交OA失败!')
                }
                this.loadingOa = false
              })
              .catch(() => {
                this.loadingOa = false
              })
          } else {
            this.$message.error(
              '只有【审核状态】为‘草稿’的生产计划,才可进行OA提交!'
            )
          }
        }
      }
    },
    // 手动创建车间订单时,刷新主计划
    refreshOrderFromManual() {
      this.getData()
    },
    // 与当前时间比较
    getDays(strDateStart, row) {
      // var time = (new Date(strDateStart).getTime() / 1000) - (new Date(strDateStart).format('YYYY-MM-DD').getTime() / 1000)
      // var days = parseFloat(time / 60 / 60 / 24).toFixed(2);
      // if (days <= 7 && days>=0) {
      //   return true
      // } else {
      //   return false
      // }
 
      const d1 = new Date(strDateStart).format('yyyy-MM-dd')
      const d2 = new Date(row.requiredDate).format('yyyy-MM-dd') // 当前日期
      var a1 = Date.parse(new Date(d1))
      var a2 = Date.parse(new Date(d2))
      var days = parseInt((a1 - a2) / (1000 * 60 * 60 * 24))
      if (days <= 7 && days >= 0) {
        return true
      } else {
        return false
      }
    }
  }
}
</script>