buli
2023-04-26 d6a096fadfe9c8f261f56a827cfceed663c36b8b
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
import { LightningElement, wire, api, track } from "lwc";
import oninit from "@salesforce/apex/LexInventoryController.init";
import barcodeEntry from "@salesforce/apex/LexInventoryController.searchConsumableorderdetails";
// import saveConfirm from '@salesforce/apex/LexInventoryController.saveConfirm';
import save from "@salesforce/apex/LexInventoryController.save";
import datainit from "@salesforce/apex/LexInventoryListController.init";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import { NavigationMixin } from "lightning/navigation";
 
//库存盘点主页面数据
const columns = [
    {
        label: "是否盘点",
        fieldName: "iscount",
        hideDefaultActions: true,
        cellAttributes: { alignment: "left" },
    },
    {
        label: "消耗品名称",
        fieldName: "Name__c",
        hideDefaultActions: true,
        initialWidth: 250,
        cellAttributes: { alignment: "left" },
    },
    {
        label: "规格",
        fieldName: "Packing_list_manual__c",
        hideDefaultActions: true,
    },
    {
        label: "单位",
        fieldName: "boxPiece",
        hideDefaultActions: true,
    },
    {
        label: "有效期内库存",
        fieldName: "limitCount",
        hideDefaultActions: true,
    },
 
    {
        label: "过期库存",
        fieldName: "overlimitCount",
        hideDefaultActions: true,
        initialWidth: 100,
    },
    {
        label: "盘点",
        fieldName: "Pandian",
        hideDefaultActions: true,
        initialWidth: 100,
    },
    {
        label: "丢失",
        fieldName: "Diff",
        hideDefaultActions: true,
        initialWidth: 100,
    },
    {
        label: "寻回    ",
        fieldName: "refind",
        hideDefaultActions: true,
        initialWidth: 150,
    },
    {
        label: "差异原因",
        // fieldName: "DiffReason",
        hideDefaultActions: true,
        type: "customDiffReason",
        typeAttributes: {
            DiffReason: { fieldName: "DiffReason" },
            ProdId: { fieldName: "ProdId" },
        },
    },
];
 
//调整明细
const column = [
    {
        label: "消耗品名称",
        fieldName: "Name__c",
        hideDefaultActions: true,
        cellAttributes: { alignment: "left" },
    },
    {
        label: "单位",
        fieldName: "Box_Piece__c",
        hideDefaultActions: true,
    },
    {
        label: "barcode",
        fieldName: "Bar_Code__c",
        hideDefaultActions: true,
        initialWidth: 150,
    },
    {
        label: "调整原因",
        fieldName: "DiffReason",
        hideDefaultActions: true,
    },
];
//盘点明细
const dcolumns = [
    {
        label: "消耗品名称",
        fieldName: "Name__c",
        hideDefaultActions: true,
        cellAttributes: { alignment: "left" },
    },
    {
        label: "库存",
        fieldName: "Count_Sum__c",
        hideDefaultActions: true,
    },
    {
        label: "盘点",
        fieldName: "inventory_sum__c",
        hideDefaultActions: true,
        initialWidth: 150,
    },
    {
        label: "丢失",
        fieldName: "Diff__c",
        hideDefaultActions: true,
    },
    {
        label: "寻回",
        fieldName: "Product_Refind__c",
        hideDefaultActions: true,
    },
    {
        label: "差异原因",
        fieldName: "Lose_reason__c",
        hideDefaultActions: true,
    },
];
 
//在库调整明细
const stockadjustcolumns = [
    {
        label: "消耗品名称",
        fieldName: "Name__c",
        cellAttributes: { alignment: "left" },
    },
    {
        label: "产品型号",
        fieldName: "Asset_Model_No__c",
        hideDefaultActions: true,
    },
    {
        label: "差异原因",
        fieldName: "Lose_reason__c",
        hideDefaultActions: true,
        initialWidth: 150,
    },
    {
        label: "是否丢失",
        type: "boolean",
        fieldName: "Lose_Flag__c",
        hideDefaultActions: true,
    },
];
 
export default class LexInventoryCount extends NavigationMixin(
    LightningElement
) {
    columns = columns;
    column = column;
    stockadjustcolumns = stockadjustcolumns;
    dcolumns = dcolumns;
    @track data = [];
    @track codPageRecords = [];
    @track accountName;
    @track agencyProType;
    @track userWorkLocation;
    @track accountid
    @track pandiandetailsMap
    @track reSet
 
    @track showTable = false;
    @track showbutton = false;
    @track barcode = "";
    @track ConsumableorderdetailsRecordsview = [];
    @track consumableorderdetailsRecords = [];
    @track showcount = true;
 
    @track iSinventory = false
    @track numberDetail;
    @track hidecheckbox = true;
 
 
    //加载框
    // @track casesSpinner = true;
    @track showSpinner = true;
 
    //row
    @track selectedRows = [];
    //inventoryList
    @track isSummonsFlag;
    //展开栏
    activeSections = ["dataExpand"];
    columnHeader = ["消耗品名称", "单位", "barCode", "调整原因"];
    //确认一览
    @track eSetId = "";
    @track EditAble = false;
    @track selectedData;
    @track conId;
    @track detailData = [];
    @track adjustdata = [];
 
    //获取链接参数
    getQueryString(name) {
        console.log("getQueryString name " + name);
        let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        let r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        }
        return null;
    }
 
    connectedCallback() {
        console.log("===>初始化");
        this.showSpinner = true;
        //获取ESetid
        this.eSetId = this.getQueryString("eSetId");
        this.eSetId = this.eSetId == null ? "" : this.eSetId;
        console.log(" this.eSetId" + this.eSetId);
        if (this.eSetId == "") {
            this.EditAble = false;
        } else {
            this.inits();
            this.showcount = false;
            this.EditAble = true;
        }
 
        oninit()
            .then((result) => {
                console.log("1112" + JSON.stringify(result));
                result = JSON.parse(JSON.stringify(result));
                console.log("result.status = " + result.status);
                console.log(
                    " ConsumableorderdetailsRecordsview= " +
                    result.entity.ConsumableorderdetailsRecordsview
                );
                this.ConsumableorderdetailsRecordsview = JSON.parse(
                    result.entity.ConsumableorderdetailsRecordsview
                );
                this.consumableorderdetailsRecords =
                    result.entity.consumableorderdetailsRecords;
                console.log(
                    " consumableorderdetailsRecords= " +
                    result.entity.consumableorderdetailsRecords
                );
 
                console.log("传参类型", typeof this.consumableorderdetailsRecords);
                if (result.status == "Success") {
                    console.log(
                        "this.ConsumableorderdetailsRecordsview[0] = " +
                        JSON.stringify(this.ConsumableorderdetailsRecordsview[0])
                    );
                    console.log(
                        "this.ConsumableorderdetailsRecordsview[0].length = " +
                        this.ConsumableorderdetailsRecordsview[0].length
                    );
 
                    // let cloneData = [];
                    // for (let i in this.ConsumableorderdetailsRecordsview[0]) {
                    //   cloneData.push(JSON.parse(this.ConsumableorderdetailsRecordsview[0][i]));
                    // }
                    // console.log('cloneData = ' + typeof cloneData);
                    // console.log('cloneData = ' + cloneData);
                    // this.data = cloneData;
                    this.data = [];
                    this.data = this.ConsumableorderdetailsRecordsview[0];
                    console.log("this.data ==>" + JSON.stringify(this.data));
                    for (let i in this.data) {
                        this.data[i]["Name__c"] = this.data[i].Prod.Name__c;
                        this.data[i]["Packing_list_manual__c"] =
                            this.data[i].Prod.Packing_list_manual__c;
                    }
                    this.accountName = result.entity.accountName;
                    this.agencyProType = result.entity.agencyProType;
                    this.userWorkLocation = result.entity.userWorkLocation;
                    this.showSpinner = false;
                    this.accountid = result.entity.accountid;
                    // this.casesSpinner = false;
                    this.showTable = true;
                } else {
                    console.log("Error:" + result.errorMsg);
                    const evt = new ShowToastEvent({
                        title: "解析失败",
                        message: result.errorMsg,
                        variant: "error",
                    });
                    this.dispatchEvent(evt);
                }
            })
            .catch((error) => {
                console.log("error = " + JSON.stringify(error));
            });
        //默认展开栏
        this.activeSections = ["dataExpand"];
        this.showTable = false;
        this.showbutton = false;
        //init
    }
    //录入barcode
 
    barcodeEntrys() {
        this.showTable = false;
        this.showbutton = false;
        this.showSpinner = true;
        console.log("进入录入");
        console.log(
            "this.consumableorderdetailsRecords===>" +
            this.consumableorderdetailsRecords
        );
 
        barcodeEntry({
            accountName: this.accountName,
            agencyProType: this.agencyProType,
            userWorkLocation: this.userWorkLocation,
            barcode: this.barcode,
            consumableorderdetailsRecordsLWC: this.consumableorderdetailsRecords,
        })
            .then((result) => {
                result = JSON.parse(JSON.stringify(result));
                console.log("result ===>" + JSON.stringify(result));
 
                console.log("1111");
                if (result.status == "Sucess") {
                    this.codPageRecords = JSON.parse(result.entity.codPageRecords);
                    for (var i in this.codPageRecords) {
                        this.codPageRecords[i]["Name__c"] = this.codPageRecords[i].Prod.Name__c;
                        this.codPageRecords[i]["Box_Piece__c"] = this.codPageRecords[i].orderdetails2.Box_Piece__c;
                        this.codPageRecords[i]["Bar_Code__c"] = this.codPageRecords[i].orderdetails2.Bar_Code__c;
                    }
                    this.data = JSON.parse(result.entity.consumableorderdetailsRecords);
                    for (var i in this.data) {
                        this.data[i]["Name__c"] = this.data[i].Prod.Name__c;
                        this.data[i]["Packing_list_manual__c"] = this.data[i].Prod.Packing_list_manual__c;
                    }
                    for (var i in this.data) {
                        if (this.data[i]["check"]) {
                            this.selectedRows.push(this.data[i].ProdId);
                            console.log("selectedRows:" + this.selectedRows);
                        }
                    }
                    this.iSinventory = result.entity.iSinventory;
                    this.pandiandetailsMap = result.entity.pandiandetailsMap;
                    this.reSet = result.entity.reSet;
                    console.log("iSinventory:" + this.iSinventory);
                    this.showTable = true;
                    this.showbutton = true;
                    this.showSpinner = false;
                    console.log('reSet' + this.reSet);
                    console.log('pandiandetailsMap' + this.pandiandetailsMap);
 
 
                    console.log(
                        "this.codPageRecords=11111 " + result.entity.codPageRecords
                    );
                    console.log("result录入= " + JSON.stringify(result));
                    console.log(
                        "result主页数据= " + result.entity.consumableorderdetailsRecords
                    );
                } else {
                    console.log('Error:' + result.errorMsg);
                    const evt = new ShowToastEvent({
                      title: '',
                      message: result.msg,
                      variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.showSpinner = false;
                    this.showTable = true;
                    
                }
            })
            .catch((error) => {
                console.log("error = " + JSON.stringify(error));
            });
    }
    //获取当前输入值
    handleChange(event) {
        let value = event.detail.value;
        console.log("value" + value);
        this.barcode = value;
    }
 
    getSelectedRows(event) {
        const selectedRows = event.detail.selectedRows;
        console.log("this.selectedRows = " + this.selectedRows);
        for (var i in this.data) {
            this.data[i]["check"] = false;
        }
        for (var i in this.data) {
            for (var j in selectedRows) {
                if (this.data[i].ProdId == selectedRows[j].ProdId) {
                    this.data[i]["check"] = true;
                }
            }
        }
    }
 
    //导出为csv
    exportData() {
        console.log("导出");
        // Prepare a html table
        let doc = "<table>";
        // Add styles for the table
        doc += "<style>";
        doc += "table, th, td {";
        doc += "    border: 1px solid black;";
        doc += "    border-collapse: collapse;";
        doc += "}";
        doc += "</style>";
        // Add all the Table Headers
        doc += "<tr>";
        this.columnHeader.forEach((element) => {
            doc += "<th>" + element + "</th>";
        });
        doc += "</tr>";
        // Add the data rows
        this.codPageRecords.forEach((record) => {
            doc += "<tr>";
            doc += "<th>" + record.Name__c + "</th>";
            doc += "<th>" + record.Box_Piece__c + "</th>";
            doc += "<th>" + record.Bar_Code__c + "</th>";
            doc += "<th>" + record.DiffReason + "</th>";
            doc += "</tr>";
        });
        doc += "</table>";
        var element = "data:application/vnd.ms-excel," + encodeURIComponent(doc);
        let downloadElement = document.createElement("a");
        downloadElement.href = element;
        downloadElement.target = "_self";
        // use .csv as extension on below line if you want to export data as csv
        downloadElement.download = "库存变化明细.xls";
        document.body.appendChild(downloadElement);
        downloadElement.click();
    }
 
    //自定义dataType
 
    diffreasons(event) {
        const numberDetail = event.detail;
        // this.numberDetail = numberDetail;
        console.log("numberDetail" + JSON.stringify(numberDetail));
        for (var i in this.data) {
            if (this.data[i]["ProId"] == numberDetail.data.ProId) {
                this.data[i]["DiffReason"] = numberDetail.data.DiffReason;
            }
        }
        console.log(" this.data==>" + JSON.stringify(this.data));
    }
 
    saveConfirm() {
        console.log("进入盘点确认");
        console.log('reSet' + this.reSet);
        console.log('pandiandetailsMap' + this.pandiandetailsMap);
        var el = this.template.querySelector("c-lex-custom-lightning-datatable");
        var selected = el.getSelectedRows();
        this.selectedData = selected;
        console.log("选中数据" + JSON.stringify(this.selectedData));
        save({
            iSinventory: this.iSinventory,
            consumableorderdetailsRecordsLWC: JSON.stringify(this.selectedData),
            accountid: this.accountid,
            agencyProType: this.agencyProType,
            reSet: this.reSet,
            pandiandetailsMap: this.pandiandetailsMap
        })
            .then((result) => {
                result = JSON.parse(JSON.stringify(result));
                console.log("result = " + JSON.stringify(result));
                console.log("111111");
 
                if (result.status == "Success") {
                    let url = "/lexInventoryCount?ESetid=" + result.entity.eSetId;
                    this[NavigationMixin.Navigate]({
                        type: "standard__webPage",
                        attributes: {
                            url: url,
                        },
                    });
                    console.log("Id" + this.eSetId);
                    // this.EditAble = true;
                    // this.showcount = false;
                } else {
                    console.log("result.msg = " + result.msg);
                    const evt = new ShowToastEvent({
                        title: "失败",
                        message: result.msg,
                        variant: "error",
                    });
                    this.dispatchEvent(evt);
                }
            })
            .catch((error) => {
                console.log("error = " + JSON.stringify(error));
            });
    }
 
    inits() {
        datainit({
            eSetId: this.eSetId,
        })
            .then((result) => {
                result = JSON.parse(JSON.stringify(result));
                console.log('盘点一览===>' + JSON.stringify(result));
                for (var i in result.entity.qs) {
                    this.conId = result.entity.qs[i].Id;
                }
                console.log("this.conId" + typeof this.conId);
                this.detailData = JSON.parse(
                    result.entity.consumableorderdetailsRecords
                );
                if (result.entity.ConsumableorderdetailsRecordsError != null) {
                    this.adjustdata = JSON.parse(
                        result.entity.ConsumableorderdetailsRecordsError
                    );
                    for (let i in this.detailData) {
                        this.detailData[i].Name__c = this.detailData[i].Prod.Name__c;
                        this.detailData[i].Count_Sum__c = this.detailData[i].orderdetails1.Count_Sum__c;
                        this.detailData[i].inventory_sum__c = this.detailData[i].orderdetails1.inventory_sum__c;
                        this.detailData[i].Diff__c = this.detailData[i].orderdetails1.Diff__c;
                        this.detailData[i].Product_Refind__c = this.detailData[i].orderdetails1.Product_Refind__c;
                        this.detailData[i].Lose_reason__c = this.detailData[i].orderdetails1.Lose_reason__c;
                    }
                    for (let i in this.adjustdata) {
                        this.adjustdata[i].Name__c = this.adjustdata[i].Prod.Name__c;
                        this.adjustdata[i].Asset_Model_No__c = this.adjustdata[i].Prod.Asset_Model_No__c;
                        this.adjustdata[i].Lose_reason__c = this.adjustdata[i].orderdetails2.Lose_reason__c;
                        this.adjustdata[i].Lose_Flag__c = this.adjustdata[i].orderdetails2.Lose_Flag__c;
 
 
 
 
 
                    }
 
 
 
 
                }
                console.log("result盘点Id" + JSON.stringify(this.conId));
                console.log("调整明细" + JSON.stringify(this.adjustdata));
            })
            .catch((error) => {
                console.log("error = " + JSON.stringify(error));
            });
    }
}