buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
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
import { LightningElement, wire, api, track } from 'lwc';
import init from '@salesforce/apex/LexOverdueStockController.init';
import barcodeEntry from '@salesforce/apex/LexOverdueStockController.searchorderBean';
import save from '@salesforce/apex/LexOverdueStockController.save';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
//table css 
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
 
 
//过期库存一览
const columns = [
  {
    label: '是否销存',
    fieldName: 'iscount',
    type: 'checkbox',
    hideDefaultActions: true,
    initialWidth: 80,
  },
  {
    label: '消耗品名称',
    fieldName: 'prodname',
    type: 'prodname',
    wrapText: true,
    initialWidth: 350,
 
    hideDefaultActions: true
 
  },
  {
    label: '单位',
    fieldName: 'boxPiece',
    hideDefaultActions: true,
    // initialWidth: 250,
 
  },
  {
    label: '过期数量',
    fieldName: 'overlimitCount',
    hideDefaultActions: true,
    cellAttributes: { alignment: 'right' }
 
    // initialWidth: 250,
 
  },
  {
    label: '销存数量',
    fieldName: 'pandian',
    hideDefaultActions: true,
    cellAttributes: { alignment: 'right' }
    // initialWidth: 250,
    //   cellAttributes: { alignment: 'center' }
  }
];
//销存明细
const column = [
 
  {
    label: '消耗品名称',
    fieldName: 'Name__c',
    type: 'Name',
    wrapText: true,
    // initialWidth : 300,
    hideDefaultActions: true,
    cellAttributes: { alignment: 'left' }
  },
  {
    label: '单位',
    fieldName: 'Box_Piece__c',
    initialWidth: 80,
    hideDefaultActions: true
  },
  {
    label: 'BarCode',
    fieldName: 'Bar_Code__c',
    wrapText: true,
    hideDefaultActions: true,
    // initialWidth: 500,
  },
  {
    label: '使用期限',
    fieldName: 'Sterilization_limit__c',
    hideDefaultActions: true,
    // initialWidth : 250
  }
  ,
  {
    label: '销存原因',
    fieldName: 'diffReason',
    hideDefaultActions: true,
    wrapText: true,
    initialWidth: 160
  }
];
 
 
export default class LexOverdueStock extends NavigationMixin(LightningElement) {
  columns = columns
  column = column
  @track data = [];
  @track overduePageRecords = [];
  @track iSinventory = false
 
 
  //加载框
  // @track casesSpinner = true;
  @track showSpinner = true;
  //显示口
  @track showbutton = false
  @track showTable = false;
  @track showTables = false;
  //销存一览数据
  @track accountName;
  @track agencyProType;
  @track userWorkLocation;
  @track barcode = ''
  @track orderDetZaiku
  @track selectedRows = [];
  @track codPageRecordsLWC;
  @track Id;
  @track overdueList = [];
 
 
  renderedCallback() {
    if (!this.stylesLoaded) {
      Promise.all([loadStyle(this, WrappedHeaderTable)])
        .then(() => {
          console.log("Custom styles loaded");
          this.stylesLoaded = true;
        })
        .catch((error) => {
          console.error("Error loading custom styles");
        });
    }
  }
 
 
  //初始化
  connectedCallback() {
    console.log('初始化');
    this.showSpinner = true;
 
    init().then((result) => {
      result = JSON.parse(JSON.stringify(result));
      console.log('result =' + JSON.stringify(result));
      console.log('result 1=' + result.entity.codPageRecords);
      if (result.status = 'Success') {
        this.data = JSON.parse(result.entity.codPageRecords);
        this.codPageRecordsLWC = result.entity.codPageRecords;
        console.log('this.data' + this.data);
        this.accountName = result.entity.accountName;
        this.agencyProType = result.entity.agencyProType;
        this.userWorkLocation = result.entity.userWorkLocation;
        for (var i in this.data) {
          this.data[i]["key"] = this.data[i]["prodid"] + this.data[i]["boxPiece"];
        }
        this.showTable = true;
        // this.casesSpinner = false;
        this.showSpinner = false;
      } else {
        this.showMyToast('初始化失败', result.msg, 'error');
        this.showSpinner = false;
      }
    }).catch((error) => {
      console.log('error = ' + JSON.stringify(error));
      this.showSpinner = false;
    });
  }
  //barcode录入
  barcodeEntrys() {
    this.showSpinner = true;
    this.showTable = false;
    console.log('code' + this.barcode);
    console.log(' this.accountName' + this.accountName);
    console.log(' this.barcode' + this.barcode);
    const selectedRows = this.template.querySelector('c-lex-custom-lightning-datatable').getSelectedRows();
    console.log('selectedRows========> ' + JSON.stringify(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 + this.data[i]["boxPiece"] == selectedRows[j].prodid + selectedRows[j]["boxPiece"]) {
          this.data[i]["check"] = true;
        }
      }
    }
    barcodeEntry({
      accountNameLWC: this.accountName,
      agencyProTypeLWC: this.agencyProType,
      userWorkLocationLWC: this.userWorkLocation,
      barcodeLWC: this.barcode,
      codPageRecordsLWC:  JSON.stringify(this.data)
    }).then((result) => {
      result = JSON.parse(JSON.stringify(result));
      if (result.status == 'Success') {
        this.overduePageRecords = JSON.parse(result.entity.overduePageRecords);
        this.overdueList = result.entity.overdueList;
        this.iSinventory = result.entity.iSinventory;
        console.log('result录入' + JSON.stringify(result));
        console.log('overdueList==>' + JSON.stringify(this.overdueList));
        for (let i in this.overduePageRecords) {
          if (this.overduePageRecords[i].Prod != null) {
            this.overduePageRecords[i]['Name__c'] = this.overduePageRecords[i].Prod.Name__c;
 
          }
          this.overduePageRecords[i]['Bar_Code__c'] = this.overduePageRecords[i].orderdetails2.Bar_Code__c;
          this.overduePageRecords[i]['Box_Piece__c'] = this.overduePageRecords[i].orderdetails2.Box_Piece__c;
          this.overduePageRecords[i]['Sterilization_limit__c'] = this.overduePageRecords[i].orderdetails2.Sterilization_limit__c;
        }
        this.data = JSON.parse(result.entity.codPageRecords);
        console.log(' this.data' + JSON.stringify(this.data));
        for (var i in this.data) {
          this.data[i]["key"] = this.data[i]["prodid"] + this.data[i]["boxPiece"];
        }
        for (var i in this.data) {
          if (this.data[i]['check']) {
            this.selectedRows.push(this.data[i].prodid + this.data[i]["boxPiece"]);
            console.log("selectedRows:" + this.selectedRows);
          }
        }
        this.showSpinner = false;
        this.showTable = true;
      } else {
        if (result.status == 'Success1') {
          this.overduePageRecords = JSON.parse(result.entity.overduePageRecords);
          this.overdueList = result.entity.overdueList;
          this.iSinventory = result.entity.iSinventory;
          console.log('result录入' + JSON.stringify(result));
          console.log('overdueList==>' + JSON.stringify(this.overdueList));
          for (let i in this.overduePageRecords) {
            if (this.overduePageRecords[i].Prod != null) {
              this.overduePageRecords[i]['Name__c'] = this.overduePageRecords[i].Prod.Name__c;
  
            }
            this.overduePageRecords[i]['Bar_Code__c'] = this.overduePageRecords[i].orderdetails2.Bar_Code__c;
            this.overduePageRecords[i]['Box_Piece__c'] = this.overduePageRecords[i].orderdetails2.Box_Piece__c;
            this.overduePageRecords[i]['Sterilization_limit__c'] = this.overduePageRecords[i].orderdetails2.Sterilization_limit__c;
          }
          this.data = JSON.parse(result.entity.codPageRecords);
          console.log(' this.data' + JSON.stringify(this.data));
          for (var i in this.data) {
            this.data[i]["key"] = this.data[i]["prodid"] + this.data[i]["boxPiece"];
          }
          for (var i in this.data) {
            if (this.data[i]['check']) {
              this.selectedRows.push(this.data[i].prodid + this.data[i]["boxPiece"]);
              console.log("selectedRows:" + this.selectedRows);
            }
          }
          this.showSpinner = false;
          // this.showTables = true;
          this.showTable = true;
        }else {
          console.log('Error:' + result.msg);
          this.showMyToast(result.msg,'','error');
          this.showSpinner = false;
          this.showTable = true;
          
        }
 
        // this.showMyToast('获取失败', result.msg, 'error');
        // this.showSpinner = false;
      }
 
    }).catch((error) => {
      this.showSpinner = false;
      console.log('error = ' + JSON.stringify(error));
    });
 
  }
  //获取当前输入值
  handleChange(event) {
    let value = event.detail.value;
    console.log('value' + value);
    this.barcode = value;
    console.log('this.barcode' + this.barcode);
  }
  getSelectedRows(event) {
            let selectedRowsEvent = event.detail.selectedRows;
            this.selectedRows = [];
            for (var i in selectedRowsEvent) {
                this.selectedRows.push(selectedRowsEvent[i].prodid+this.data[i]["boxPiece"]);
            }
        console.log('this.selectedRows==>'+this.selectedRows);
 
  }
  //保存
  saveConfirm() {
    console.log('进入销存确认');
    this.showSpinner = true;
        //查询有哪些选择了的然后check
        const selectedRows = this.template.querySelector('c-lex-custom-lightning-datatable').getSelectedRows();
        console.log('selectedRows========> ' + JSON.stringify(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+this.data[i]["boxPiece"] == selectedRows[j].prodid+ selectedRows[j]["boxPiece"]) {
                    this.data[i]["check"] = true;
                }
            }
        }
    save({
      iSinventory: this.iSinventory,
      saveCodPageRecords: JSON.stringify(this.data),
      // saveoverdueList:JSON.stringify(this.overdueList)
      saveoverdueList: this.overdueList
    }).then((result) => {
      result = JSON.parse(JSON.stringify(result));
      console.log('result保存 = ' + JSON.stringify(result));
      if (result.status == 'Success') {
        this[NavigationMixin.Navigate]({
          type: 'standard__recordPage',
          attributes: {
            recordId: result.entity.Id,
            objectApiName: 'Consumable_order__c',
            actionName: 'view'
          }
        });
        this.showSpinner = false;
      } else {
        this.showMyToast('销存失败', result.msg, 'error');
        this.showSpinner = false;
        
      }
    })
      .catch((error) => {
        console.log('error = ' + JSON.stringify(error));
        this.showSpinner = false;
      });
  }
 
  showMyToast(title, message, variant) {
    console.log('show custom message');
    var iconName = '';
    var content = '';
    if (variant == 'success') {
      iconName = 'utility:check';
    } else {
      iconName = 'utility:error';
    }
    if (message != '') {
      content = '<h2><strong>' + title + '<strong/></h2><h5>' + message + '</h5>';
    } else {
      content = '<h2><strong>' + title + '<strong/></h2>';
    }
    this.template.querySelector('c-common-toast').showToast(variant, content, iconName, 10000);
  }
 
}