schangxiang@126.com
2024-11-21 60735779c303c2dd10feea45d7fd761103b225e0
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
<template>
    <!-- 看板详情 -->
    <el-dialog v-model="dialogVisible" width="80%" @close="closeDialog" :close-on-click-modal="false">
        <template #header>
            <div style="color: #fff">
                <span>看板详情</span>
            </div>
        </template>
        <div class="msi-content" style="margin-top: 10px">
            <div class="msi-form" style="padding-top: 0px">
                <el-form :model="materialForm">
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="物料编号">
                                <el-input v-model="materialForm.materialCode" placeholder="请输入物料编号" clearable></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label-width="20px">
                                <el-button type="primary" icon="el-icon-search" @click="getMaterialList">查询</el-button>
                                <!-- <el-button icon="el-icon-refresh-right" @click="resetMaterialForm">重置</el-button> -->
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <el-table :data="warehousOrderDetails" border style="width: 100%" row-key="setRowKey" ref="detailRef" max-height="480">
                <el-table-column label="序号" align="center" width="60" type="index" />
                
                <el-table-column label="物料编号" min-width="140" prop="materialCode" align="center" show-overflow-tooltip />
                <el-table-column prop="materialName" min-width="110px" label="物料名称" show-overflow-tooltip="" />
                <el-table-column prop="materialUnit" min-width="110px" label="单位" show-overflow-tooltip="" />
                <el-table-column prop="abcClassName" label="ABC分类"  show-overflow-tooltip="" />
                <!-- <el-table-column prop="snCode" min-width="110px" label="跟踪码" show-overflow-tooltip="" /> -->
                <el-table-column prop="quantity" label="数量" show-overflow-tooltip="" />
            </el-table>
 
            <Pagination :total="materialTotal" v-model:page="materialForm.Page" v-model:limit="materialForm.PageSize" @pagination="getMaterialList" style="margin-top: 20px; text-align: center"></Pagination>
 
        </div>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <!-- <el-button type="primary" :disabled="disabled_btn" @click="confirm">确认</el-button> -->
            </span>
        </template>
    </el-dialog>
    <!-- 添加物料 -->
    <el-dialog v-model="addMaterialVisible" width="70%" @close="closeMaterialDialog">
        <template #header>
            <div style="color: #fff">
                <span v-if="isMaterialBox == 1">添加物料详情</span>
                <span v-if="isPoBox == 1">关联ASN单物料</span>
            </div>
        </template>
 
        <div class="msi-form" style="padding-top: 0px">
            <el-form :model="materialForm">
                <el-row>
                    <el-col :span="8" v-if="isMaterialBox == 1">
                        <el-form-item label="物料编号">
                            <el-input v-model="materialForm.Code" placeholder="请输入物料编号" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" v-if="isPoBox == 1">
                        <el-form-item label="关联ASN单号:">
                            <el-input v-model="materialForm.poNo" placeholder="请输入关联ASN单号" clearable></el-input>
                        </el-form-item>
                    </el-col>
 
                    <el-col :span="8">
                        <el-form-item label-width="20px">
                            <el-button type="primary" icon="el-icon-search" @click="getMaterialList">查询</el-button>
                            <!-- <el-button icon="el-icon-refresh-right" @click="resetMaterialForm">重置</el-button> -->
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="msi-content" style="padding-top: 0; margin-top: 10px">
            <el-table :data="materialList" border style="width: 100%" row-key="id" ref="materialRef" @selection-change="materialSelectionChange" :max-height="480" v-if="isMaterialBox == 1">
                <el-table-column align="center" width="60" type="selection" />
                <el-table-column label="序号" align="center" width="60" type="index" />
                <el-table-column label="物料编号" prop="materialCode" align="center" min-width="140" show-overflow-tooltip />
                <el-table-column label="物料名称" prop="materialName" align="center" min-width="140" show-overflow-tooltip />
 
                <el-table-column label="单位" prop="poUnit" align="center" min-width="140" show-overflow-tooltip />
            </el-table>
 
            <Pagination :total="materialTotal" v-model:page="materialForm.Page" v-model:limit="materialForm.PageSize" @pagination="getMaterialList" style="margin-top: 20px; text-align: center"></Pagination>
        </div>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="addMaterialVisible = false">取消</el-button>
                <el-button type="primary" @click="confirmAddMaterial">确认</el-button>
            </span>
        </template>
    </el-dialog>
    <!-- 单详情 -->
    <el-drawer v-model="drawerVisible" :title="`${detailForm.asnId}订单详情`" direction="rtl" size="80%" @close="handleDrawerClose">
        <template #title>
            <div class="slot_title">
                <div class="title_orderNo">{{ title }}</div>
                <div>订单详情</div>
            </div>
        </template>
 
        <div class="detailBoxWrap">
            <!-- 详情组件 -->
            <open-details ref="propDetailRef"></open-details>
            <div class="msi-form">
                <el-form :model="detailForm">
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="物料编号">
                                <el-input v-model="detailForm.materialCode" clearable placeholder="请输入物料编号" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="2">
                            <el-form-item label-width="20px">
                                <el-button type="primary" icon="el-icon-search" @click="getDetail">查询</el-button>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <div class="msi-content">
                <!-- <p style="margin-bottom: 10px">物料明细</p> -->
                <el-table :data="drawerList" border striped :max-height="480">
                    <el-table-column label="序号" align="center" width="60" type="index" />
 
    
 
                    <el-table-column prop="materialCode" min-width="130px" label="物料编号" show-overflow-tooltip="" />
                    <el-table-column prop="materialName" min-width="110px" label="物料名称" show-overflow-tooltip="" />
                    <el-table-column prop="qcQuantity" label="实检数量" show-overflow-tooltip="" />
                    <!-- <el-table-column prop="qCStatus" label="质检状态"  show-overflow-tooltip="" >
            <template #default="scope">
              <el-tag>{{ getEnumDesc(scope.row.qCStatus, getEnumQCStatusData_Index)}}</el-tag>
            </template>
          </el-table-column> -->
                    <el-table-column prop="qcStatus" label="质检状态" show-overflow-tooltip="">
                        <template #default="scope">
                            <el-tag>{{ getEnumDesc(scope.row.qCStatus, getEnumQCStatusData_Index) }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="passQuantity" label="合格数量" show-overflow-tooltip="" />
                    <el-table-column prop="rejectQuantity" label="不合格数量" show-overflow-tooltip="" />
                    <el-table-column prop="goodsQuantity" label="已收数量" show-overflow-tooltip="" />
 
                    <el-table-column prop="businessTypeName" label="业务类型" show-overflow-tooltip="" />
                    <el-table-column prop="qCOrderStatus" label="单据状态" show-overflow-tooltip="">
                        <template #default="scope">
                            <el-tag>{{ getEnumDesc(scope.row.qcOrderStatus, getEnumAsnStatusData_Index) }}</el-tag>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column prop="qcOrderStatusName" label="单据状态"  show-overflow-tooltip="" /> -->
 
                    <el-table-column prop="unit" label="单位" show-overflow-tooltip="" />
                    <el-table-column prop="supplierName" label="供应商名称" show-overflow-tooltip="" />
                    <el-table-column prop="supplierCode" label="供应商编号" show-overflow-tooltip="" />
                    <el-table-column prop="custCode" label="客户编号" show-overflow-tooltip="" />
                    <el-table-column prop="custChinaName" min-width="110px" label="客户中文名称" show-overflow-tooltip="" />
                    <el-table-column prop="custEnglishName" min-width="110px" label="客户英文名称" show-overflow-tooltip="" />
                    <el-table-column prop="relationNo" label="关联单号" show-overflow-tooltip="" />
                    <!-- <el-table-column prop="relationOrderType" label="关联单据类型"  show-overflow-tooltip="" /> -->
                    <el-table-column prop="relationOrderTypeName" min-width="110px" label="关联单据类型" show-overflow-tooltip="" />
                    <!-- <el-table-column prop="factoryId" label="工厂ID"  show-overflow-tooltip="" /> -->
                    <!-- <el-table-column prop="factoryName" label="工厂名称" show-overflow-tooltip="" /> -->
                    <!-- <el-table-column prop="factoryCode" label="工厂编号" show-overflow-tooltip="" /> -->
                    <el-table-column prop="remarks" label="备注" show-overflow-tooltip="" />
                    <el-table-column prop="createTime" label="创建时间" width="130" :formatter="formatDate_T_Time" show-overflow-tooltip="" />
                    <el-table-column prop="updateTime" label="修改时间" width="130" :formatter="formatDate_T_Time" show-overflow-tooltip="" />
                    <el-table-column prop="createUserName" label="创建人" show-overflow-tooltip="" />
                    <el-table-column prop="updateUserName" label="修改人" show-overflow-tooltip="" />
                </el-table>
                <Pagination :total="detailCount" v-model:page="detailForm.PageNo" v-model:limit="detailForm.PageSize" @pagination="getDetail" style="margin-top: 20px; text-align: center"></Pagination>
 
                <div></div>
            </div>
        </div>
    </el-drawer>
 
    <el-dialog v-model="outVisible2" title="SPA获取" width="20%" @close="closeOutDialog2">
        <el-form :model="outerForm2" label-width="120px">
            <el-row style="font-size: 16px">
                <el-col :span="23">
                    <el-form-item label="单号:" required>
                        <el-input v-model="outerForm2.purchaseNo" clearable placeholder="请输入单号" />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
 
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="outVisible2 = false">取消</el-button>
                <el-button type="primary" @click="getSapOrderPO">确认</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script lang="ts" setup>
import Pagination from '/@/components/Pagination/index.vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { ref, nextTick, computed, getCurrentInstance, watch, defineExpose, defineProps, onMounted } from 'vue';
 
import { formatDecimalData } from '/@/utils/formate';
 
import cache from '/@/utils/cache';
import { pageWmsMaterial } from '/@/api/main/WmsBase/wmsMaterial';
import { getTypeStatus } from '/@/utils/formate';
import { getAPI } from '/@/utils/axios-utils';
import { SysEnumApi } from '/@/api-services/api';
import { addWmsOrderPurchase, updateWmsOrderPurchase, detailWmsOrderPurchase } from '/@/api/main/WmsOrder/wmsOrderPurchase';
import OpenDetails from '/@/components/openDetails/openDetails.vue';
import { pageBaseCustomer } from '/@/api/main/WmsBase/baseCustomer';
import { pageWmsOrderPurchaseDetails } from '/@/api/main/WmsOrder/wmsOrderPurchaseDetails';
import { pageWmsOrderAsnDetails, deleteWmsOrderAsnDetails } from '/@/api/main/WmsOrder/wmsOrderAsnDetails';
import commonFunction from '/@/utils/commonFunction';
import { addWmsOrderAsn, updateWmsOrderAsn, detailWmsOrderAsn } from '/@/api/main/WmsOrder/wmsOrderAsn';
 
import { addWmsQc, updateWmsQc, detailWmsQc, confirmWmsQc } from '/@/api/main/WmsQC/wmsOrderQc';
import { pageWmsQcDetails } from '/@/api/main/WmsQC/wmsOrderQcDetails';
import { pageWmsAbcDetails } from '/@/api/main/ReportCenter/wmsStockBoardabc';
const { proxy }: any = getCurrentInstance(); // 访问实例上下文 proxy同时支持开发 线上环境
const getEnumOrderTypeData = ref<any>([]);
const getEnumBusinessTypeData = ref<any>([]);
const getEnumPoStatusData = ref<any>([]);
const { getEnumDesc } = commonFunction();
const emits = defineEmits(['getTabelData']);
const getEnumAsnStatusData_Index = ref<any>([]);
const getEnumOrderTypeData_Index = ref<any>([]);
const getEnumQCStatusData_Index = ref<any>([]);
 
const getEnumDockData = ref<any>([]);
const props = defineProps({
    titleAuthor: {
        type: Number,
        required: true,
    },
    hexiao: {
        type: Number,
        default: 1,
        required: true,
    },
});
//控制订单类型 - 下拉菜单
const titleAuthor = computed(() => props.titleAuthor);
// 是否显示核销按钮
const hexiao = computed(() => props.hexiao);
const loading = ref(false);
 
 
 
// form表单展开
 
const orderType = ref('');
const orderDoRuType = ref(); // 用于导入的变量
const itemBtn = ref(1);
// 控制bom物料权限
const isShowBomBtn = ref(0);
 
// 禁止之前的日期
const disabledDate = (time: Date) => {
    return time.getTime() + 3600 * 1000 * 24 < Date.now();
};
// 上传窗口
const uploadVisible = ref(false);
//打开导入窗口
const openUploadDialog = (param: any) => {
    orderDoRuType.value = param;
    uploadVisible.value = true;
};
//关闭窗口
const closeUploadDialog = () => {
    getTabelData();
};
//sap获取
const getSapOrder = () => {
    ElMessageBox.confirm('是否确认获取更新?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
    }).then(() => {
    });
};
 
//------------sap获取PO单
const outVisible2 = ref(false);
const outerForm2 = ref({
    purchaseNo: '',
});
const getSapOrderPO = (param?: number) => {
    if (param && param == 1) {
        outVisible2.value = true;
        return;
    }
    if (outerForm2.value.purchaseNo == '') {
        ElMessage.warning('请输入单号');
        return;
    }
};
//关闭出库窗口的回调
const closeOutDialog2 = () => {
    outerForm2.value.purchaseNo = '';
};
 
//------------sap获取PO单
 
// --------------------PO单列表-----------------------------------
//查询
const formModel = ref({
    WareMaterialCode: '',
    WareMaterialName: '',
    PurchaseNo: '',
    CreatedUserName: '',
    CreatedTimeBegin: '',
    CreatedTimeEnd: '',
    CreateDate: [],
    IssueTimeBegin: '',
    IssueTimeEnd: '',
    IssueDate: [],
    MaterialTypeStaus: '',
    SourceBy: '',
    WriteOffState: '',
    signStatus: '',
    status: '',
    freeOrderType: '',
    IsQueryAll: false, //是否显示全部数据
    // LoginUserID: LoginUserID, //用户id
    OrderMenuType: '', //判断是哪个菜单入库
    Page: 1,
    PageSize: 10,
    poApprovalStatus: '',
    keyCode: '',
    IsDisable: '', //是否作废
});
 
//入库单列表数据
let tableData = ref([]);
const tableRef = ref();
 
//列表的数据条数
const totalItems = ref<number>(0);
 
//缓存枚举
const enumList: any = cache.getCache('enumList');
console.log(enumList.inEnumOrderType);
 
// .inEnumOrderType
 
//获取PO单列表
const getTabelData = () => {
    //判断创建时间是否有选择
    if (formModel.value.CreateDate && formModel.value.CreateDate.length > 0) {
        formModel.value.CreatedTimeBegin = formModel.value.CreateDate[0];
        formModel.value.CreatedTimeEnd = ''; //addDate(formModel.value.CreateDate[1], 1); //日期查询 结束时间 需要加一天
    } else {
        // 日历清空 再查询bug
        if (formModel.value.CreatedTimeBegin || formModel.value.CreatedTimeEnd) {
            formModel.value.CreatedTimeBegin = '';
            formModel.value.CreatedTimeEnd = '';
        }
    }
    //判断下发时间是否有选择
    if (formModel.value.IssueDate && formModel.value.IssueDate.length > 0) {
        formModel.value.IssueTimeBegin = formModel.value.IssueDate[0];
        formModel.value.IssueTimeEnd = formModel.value.IssueDate[1];
    } else {
        // 日历清空 再查询bug
        if (formModel.value.IssueTimeBegin || formModel.value.IssueTimeEnd) {
            formModel.value.IssueTimeBegin = '';
            formModel.value.IssueTimeEnd = '';
        }
    }
};
getTabelData();
 
//重置搜索
const resetForm = () => {
    formModel.value = {
        WareMaterialCode: '',
        WareMaterialName: '',
        PurchaseNo: '',
        CreatedUserName: '',
        CreatedTimeBegin: '',
        CreatedTimeEnd: '',
        CreateDate: [],
        IssueTimeBegin: '',
        IssueTimeEnd: '',
        IssueDate: [],
        MaterialTypeStaus: '',
        SourceBy: '',
        WriteOffState: '',
        signStatus: '',
        status: '',
        freeOrderType: '',
        IsQueryAll: false, //是否显示全部数据
        //  LoginUserID: LoginUserID, //用户id
        OrderMenuType: '', //判断是哪个菜单入库
        Page: 1,
        PageSize: 10,
        poApprovalStatus: '',
        keyCode: '',
        IsDisable: '', //是否作废
    };
    getTabelData();
};
// -----------------删除、导出操作--------------------------
//选中的行
const checkRows = ref<{ id: number }[]>([]);
// 选择
const handleSelectionChange = (val: any) => {
    checkRows.value = val;
};
//导出PO单详情
const handExport = () => {
    // rkExport(formModel.value)
    //   .then((res) => {
    //     const link = document.createElement("a"); //创建a标签
    //     let blob = new Blob([res], { type: "application/vnd.ms-excel" }); // response就是接口返回的文件流
    //     let objectUrl = URL.createObjectURL(blob);
    //     link.href = objectUrl;
    //     link.download = `入库管理导出${formatUtcToData(
    //       new Date().toString(),
    //       "YYYY-MM-DD hh:mm:ss"
    //     )}`; // 自定义文件名
    //     link.click(); // 下载文件
    //     URL.revokeObjectURL(objectUrl); // 释放内存
    //   }).catch((err) => ElMessage.error(JSON.stringify(err)));
    //导出调用接口
    // let entozh = entozhExcell
    //   const { PageNo, PageSize, ...rest } = formModel.value
    //   getPurchasePage({ Page: 1, PageSize: 1000000, ...rest }).then(res => {
    //     if(res.code==200){
    //       res.data.rows.forEach((item)=>{
    //         item.writeOffState = EnumWriteOffState.value.filter((v: any) => v.value == item.writeOffState)[0].title;
    //         item.sourceBy =  sourceEnum.value.filter((v: any) => v.value == item.sourceBy)[0].title;
    //       })
    //       exportExcel(res.data.rows, entozh, "xlsx", `入库管理表${formatUtcToData(new Date().toString(), 'YYYY-MM-DD hh:mm:ss')}`);
    //     }
    //   })
    // 后端导出-字段不全
    // if (checkRows.value.length <= 0) {
    //   ElMessage.warning("请选择一个订单!");
    //   return
    // }
    // const arr = checkRows.value.reduce((curr, item) => {
    //   curr.push(item.purchaseNo);
    //   return curr;
    // }, []);
    // puchaseExport({ PurchaseNo: arr })
    //   .then((res) => {
    //     const link = document.createElement("a"); //创建a标签
    //     let blob = new Blob([res], { type: "application/vnd.ms-excel" }); // response就是接口返回的文件流
    //     let objectUrl = URL.createObjectURL(blob);
    //     link.href = objectUrl;
    //     link.download = `入库管理导出${formatUtcToData(
    //       new Date().toString(),
    //       "YYYY-MM-DD hh:mm:ss"
    //     )}`; // 自定义文件名
    //     link.click(); // 下载文件
    //     URL.revokeObjectURL(objectUrl); // 释放内存
    //   })
    //   .catch((err) => ElMessage.error(JSON.stringify(err)));
};
 
// -------------------获取PO单下物料详情-----------------------------------
//入库单下物料详情请求
const detailForm = ref({
    materialCode: '',
    Page: 1,
    PageSize: 10,
});
 
// 物料详情抽屉
const drawerVisible = ref(false);
const drawerType = ref('drawerAll');
// const
//单号
const purchaseNo = ref('');
const detailCount2 = ref(0);
const detailForm2 = ref({
    Page: 1,
    PageSize: 10,
    qcOrderId: '',
    IsConfirmQC: true, //质检单确认传参:1质检状态不是待检验  2单据状态是新建
});
const getEnumPoDetailStatusData_Index = ref<any>([]);
 
const drawerList2 = ref<DetailType[]>([]);
//------------------获取物料列表物料明细
const getDetail = async () => {
    loading.value = true;
    var res = await pageWmsQcDetails(Object.assign(detailForm.value));
    var listD = res.data.result?.items ?? [];
    drawerList.value = listD;
    detailCount.value = res.data.result?.total;
    loading.value = false;
    getEnumPoDetailStatusData_Index.value = (await getAPI(SysEnumApi).apiSysEnumEnumDataListGet('OrderStatusEnum')).data.result ?? [];
 
    getEnumAsnStatusData_Index.value = (await getAPI(SysEnumApi).apiSysEnumEnumDataListGet('OrderStatusEnum')).data.result ?? [];
};
 
//----------------物料明细
//打开抽屉
const openDrawer = async (type: number, scope: any = {}, entozhExcell?: any) => {
    detailForm.value.PageNo = 1;
    detailForm.value.PageSize = 10;
    if (scope.asnNo) {
        title.value = `${scope.asnNo}`;
    }
    drawerType.value = 'drawerAll';
    drawerVisible.value = true;
    //当前入库单号id
    detailForm.value.asnId = scope.id;
    //入库单
    purchaseNo.value = scope.purchaseNo;
    detailForm2.value.asnId = scope.id;
    //获取物料列表
    if (detailForm2.value.asnId == '') {
        drawerList2.value = [];
        detailCount2.value = 0;
        return;
    }
    // 获取物料列表物料明细
    getDetail();
 
    getEnumPoDetailStatusData_Index.value = (await getAPI(SysEnumApi).apiSysEnumEnumDataListGet('OrderStatusEnum')).data.result ?? [];
    let scopetrans = JSON.parse(JSON.stringify(scope));
    scopetrans.qcOrderStatus = getEnumDesc(scopetrans.qcOrderStatus, getEnumPoDetailStatusData_Index.value);
    nextTick(() => {
        proxy.$refs['propDetailRef'].openADialog(scopetrans, entozhExcell);
    });
};
 
//关闭抽屉
const handleDrawerClose = () => {
    detailForm.value = {
        materialCode: '',
        asnId: '',
        Page: 1,
        PageSize: 10,
    };
    deltailList.value = [];
    detailCount.value = 0;
    drawerList.value = [];
    drawerList2.value = [];
    detailCount2.value = 0;
    drawerList2.value = [];
};
 
//物料详情类型
interface DetailType {
    id: number;
}
 
//入库单详情列表
const deltailList = ref<DetailType[]>([]);
//弹出层数据
const drawerList = ref<DetailType[]>([]);
 
//入库单详情列表数据条数
const detailCount = ref(0);
 
//弹出层标题
let title = ref('');
 
// ----------------新增、编辑-------------------------------
//窗口类型
const dialogType = ref('add');
 
const dialogVisible = ref(false);
 
//添加编辑表单ref
const dialogRef = ref();
 
//添加/编辑参数
let addForm = ref({
    hasTMCode: false,
    asnType: '',
    dock: '',
    projectNo: '',
    OrderDetails: [] as any[],
});
//物料基础数据form
const materialForm = ref({
    materialCode:'',
    aBCClass: '',
    Page: 1,
    PageSize: 10,
    recordInsertTimeRange:[]
});
 
//打开
const openDialog = async (type: number, scope: any = {}) => {
    debugger
    materialForm.value.aBCClass = scope.aBCClass;
    materialForm.value.recordInsertTimeRange = scope.recordInsertTimeRange;
    //------------------获取物料列表物料明细
    getMaterialList()
    //----------------物料明细
    dialogVisible.value = true;
    disabled_btn.value = false;
    //清除选中项
    // nextTick(() => {
    //     dialogRef.value.clearValidate();
    // });
};
 
//物料详情的table ref
const detailRef = ref();
const setRowKey = (row: any) => {
    return row.id + row.asnLineNumber;
};
//关闭窗口
const closeDialog = () => {
    addForm.value = {
        hasTMCode: false,
        asnType: '',
        dock: '',
        projectNo: '',
        OrderDetails: [] as any[],
    };
    warehousOrderDetails.value = [];
    checkedDetails.value = [];
    deltailList.value = [];
    detailCount.value = 0;
    disabled_btn.value = false;
    detailRef.value.clearSelection();
};
 
//添加编辑窗口物料列表
const warehousOrderDetails = ref<any[]>([]);
 
//物料详情列表选中的物料
const checkedDetails = ref<any[]>([]);
 
//物料详情列表中勾选事件
const detailsCheckChange = (val: any) => {
    checkedDetails.value = val;
};
 
//删除选中的物料详情
const delCheckedDetails = () => {
    ElMessageBox.confirm('是否确认删除?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
    })
        .then(() => {
            let arr = [];
            if (checkedDetails.value[0].diRelationID) {
                checkedDetails.value.forEach((item) => {
                    console.log(item);
                    let index = warehousOrderDetails.value.findIndex((detail) => detail.materialCode == item.materialCode && detail.diRelationID == item.diRelationID);
                    if (index > -1) {
                        warehousOrderDetails.value.splice(index, 1);
                    }
                });
            } else {
                checkedDetails.value.forEach((item) => {
                    let index = warehousOrderDetails.value.findIndex((detail) => detail.materialCode == item.materialCode && detail.asnLineNumber == item.asnLineNumber);
                    warehousOrderDetails.value.splice(index, 1);
                });
            }
            arr = warehousOrderDetails.value;
            warehousOrderDetails.value = [];
            //bug 相同物料 不同Bom
            nextTick(() => {
                warehousOrderDetails.value = arr;
                checkedDetails.value = [];
                detailRef.value.clearSelection();
            });
        })
        .catch(() => ElMessage.info('已取消删除'));
};
//编辑、添加提交
const disabled_btn = ref(false);
const confirm = async () => {
    console.log('确认');
    if (warehousOrderDetails.value.length <= 0) {
        ElMessage.warning('没有需要完成质检的物料!');
        return;
    }
    addForm.value.OrderDetails = [];
    warehousOrderDetails.value.forEach((item) => {
        const obj = {
            ...item,
            QCQuantity: item.quantity,
            asnLineNumber: item.asnLineNumber,
        };
        addForm.value.OrderDetails.push(obj);
    });
    disabled_btn.value = true;
    let res = await confirmWmsQc(addForm.value);
    if (res.data && res.data.code == 200) {
        ElMessage.success('完成质检成功');
        dialogVisible.value = false;
        emits('getTabelData');
    }
    disabled_btn.value = false;
};
// -----------------添加物料操作-------------------------
//物料基础数据窗口
const addMaterialVisible = ref(false);
 
//物料基础数据列表
const materialList = ref([]);
 
//物料基础数据条数
const materialTotal = ref(0);
 
 
//获取物料基础列表
const getMaterialList = async () => {
    loading.value = true;
    var res = await pageWmsAbcDetails({
        ...materialForm.value
    });
    var listD = res.data.result?.items ?? [];
    warehousOrderDetails.value = listD;
    materialList.value = res.data.result?.items ?? [];
    materialTotal.value = res.data.result?.total;
    loading.value = false;
};
 
 
 
//选中的基础物料数据
const checkedMaterial = ref<any[]>([]);
 
//物料基础数据勾选
const materialSelectionChange = (val: any) => {
    checkedMaterial.value = val;
};
const isMaterialBox: any = ref(true);
const isPoBox: any = ref(true);
//打开新增物料窗口
const addMaterialDialog = (param?: any) => {
    if (param && param == 'po') {
        isPoBox.value = 1;
        isMaterialBox.value = 0;
    } else {
        isPoBox.value = 0;
        isMaterialBox.value = 1;
    }
    getMaterialList();
    addMaterialVisible.value = true;
};
 
//基础物料table的ref对象
const materialRef = ref();
 
//确认添加材料
const confirmAddMaterial = () => {
    //物料列表没数据,直接添加
    if (warehousOrderDetails.value.length == 0) {
        // 自动给行号复值
        checkedMaterial.value.forEach((item, index) => {
            item.unit = item.poUnit || item.unit;
            item.asnLineNumber = index + 1;
            if (!item.asnLineNumber) {
                item.asnLineNumber = index + 1 + warehousOrderDetails.value.length;
            }
        });
 
        warehousOrderDetails.value.push(...checkedMaterial.value);
    } else {
        for (let i = 0; i < checkedMaterial.value.length; i++) {
            let idx = warehousOrderDetails.value.findIndex(
                (item: { poLineNumber: any; code: any }) => item.code == checkedMaterial.value[i].materialCode && item.asnLineNumber == checkedMaterial.value[i].asnLineNumber
            );
            if (idx > -1) {
                return ElMessage.warning(`物料编号${checkedMaterial.value[i].materialCode},ASN行号:${checkedMaterial.value[i].asnLineNumber || ''}在物料列表中已存在,请去除勾选`);
            }
        }
 
        // 自动给行号复值
        checkedMaterial.value.forEach((item, index) => {
            item.unit = item.poUnit || item.unit;
            if (!item.asnLineNumber) {
                item.asnLineNumber = index + 1 + warehousOrderDetails.value.length;
            }
        });
        warehousOrderDetails.value.push(...checkedMaterial.value);
    }
 
    addMaterialVisible.value = false;
};
 
//关闭新增物料窗口
const closeMaterialDialog = () => {
    materialForm.value = {
        poNo: '',
        Code: '',
        Page: 1,
        PageSize: 10,
    };
    materialList.value = [];
    checkedMaterial.value = [];
    materialRef.value.clearSelection();
};
 
// 页面加载时
onMounted(async () => {});
 
// 暴露方法
defineExpose({ openDialog, openDrawer });
</script>
<style lang="less" scoped>
.detailBoxWrap {
    margin: 10px;
}
 
.msi-form {
    margin-top: 10px;
}
 
.msi-form {
    margin-bottom: 10px;
}
 
.slot_title {
    display: flex;
    align-items: center;
 
    // margin-left: 20px;
    .title_orderNo {
        font-size: 18px;
        color: #f18201;
        font-weight: bold;
        margin-right: 5px;
    }
}
</style>