buli
2023-06-05 3962c2bb0435484b60a3e408e4738d792e249a53
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
import { LightningElement, wire, api, track } from 'lwc';
import init from '@salesforce/apex/LexRemoveBoxController.init';
import searchDeatail from '@salesforce/apex/LexRemoveBoxController.searchConsumableorderdetails';
import saveconfirm from '@salesforce/apex/LexRemoveBoxController.removeBoxConfirm';
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: 'Name__c',
    wrapText:true,
    hideDefaultActions: true,
    initialWidth: 400,
 
  },
  {
    label: '规格',
    fieldName: 'ProductPacking_list_manual__c',
    hideDefaultActions: true,
    initialWidth: 50,
    cellAttributes: { alignment: "right" },
 
 
  },
  {
    label: 'CFDA状态',
    fieldName: 'CFDA_Status__c',
    hideDefaultActions: true,
    initialWidth: 200,
 
  },
  {
    label: '注册证编码号',
    fieldName: 'Report_Product_Approbation__c',
    hideDefaultActions: true,
    initialWidth: 200,
  },
  {
    label: '注册证效期',
    fieldName: 'Report_Product_Expiration__c',
    hideDefaultActions: true,
    // initialWidth: 250,
  },
  {
    label: 'BarCode',
    fieldName: 'Bar_Code__c',
    hideDefaultActions: true,
    wrapText:true,
    initialWidth:400,
  }
];
 
const column = [
  {
    label: '消耗品名称',
    fieldName: 'Name__c',
    hideDefaultActions: true,
 
  },
  {
    label: 'BarCode',
    fieldName: 'Bar_Code__c',
    hideDefaultActions: true,
 
   
  }
  ,
  {
    label: '错误原因',
    fieldName: 'ErrorReason',
    hideDefaultActions: true,
  }
];
 
 
 
 
export default class LexRemoveBox extends LightningElement {
  columns = columns;
  column = column;
  @track selectedRows = [];
  @track data = [];
  @track errorDetail = [];
 
  // 显示
  @track showTable = false
  @track accountName
  @track userWorkLocation
  @track agencyProType
  @track barcode = ''
  @track saveFLGbln = false
  @track dataSize = 0;
 
  //加载框
  @track showSpinner = false
 
  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.showTable = false;
 
    init().then((result) => {
      result = JSON.parse(JSON.stringify(result));
      console.log('result =' + JSON.stringify(result));
      if (result.status = 'Success') {
        console.log('result');
        this.agencyProType = result.entity.agencyProType;
        this.userWorkLocation = result.entity.userWorkLocation;
        this.accountName = result.entity.accountName;
        // this.data = JSON.parse(result.entity.codPageRecords);
        // this.showTable = true;
      } else {
        this.showMyToast('初始化失败',result.msg,'error');
      }
    }).catch((error) => {
      console.log('error = ' + JSON.stringify(error));
    });
  }
  //录入
  getDetails() {
    searchDeatail({
      accountName: this.accountName,
      userWorkLocation: this.userWorkLocation,
      agencyProType: this.agencyProType,
      barcode: this.barcode
    }).then((result) => {
      result = JSON.parse(JSON.stringify(result));
      console.log('result =' + JSON.stringify(result));
      if (result.status == 'Success') {
        console.log('成功');
        this.data = JSON.parse(result.entity.ConsumableorderdetailsRecordsdummy);
        this.errorDetail = JSON.parse(result.entity.ConsumableorderdetailsRecordserror);
        this.dataSize = result.entity.dataSize;
        console.log('this.dataSize'+this.dataSize);
        for (let i in this.data) {
          this.data[i]['Name__c'] = this.data[i].Prod.Name__c;
          this.data[i]['ProductPacking_list_manual__c'] = this.data[i].esd.ProductPacking_list_manual__c;
          this.data[i]['CFDA_Status__c'] = this.data[i].esd.CFDA_Status__c;
          this.data[i]['Report_Product_Approbation__c'] = this.data[i].esd.Report_Product_Approbation__c;
          this.data[i]['Report_Product_Expiration__c'] = this.data[i].esd.Report_Product_Expiration__c;
          this.data[i]['Bar_Code__c'] = this.data[i].esd.Bar_Code__c;
        }
        for (let i in this.errorDetail) {
          this.errorDetail[i]['Name__c'] = this.errorDetail[i].Prod.Name__c;
          this.errorDetail[i]['Bar_Code__c'] = this.errorDetail[i].esd.Bar_Code__c;
          this.errorDetail[i]['ErrorReason'] = this.errorDetail[i].ErrorReason;
        }
        this.showTables = true;
        this.showTable = true;
      } else{
        console.log('result.msg = ' + result.msg);
        this.showMyToast('获取失败',result.msg,'error');
      }
    }).catch((error) => {
      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);
  }
  saveConfirm() {
    console.log('进入确认');
    let msg = "确认拆盒吗";
    if (this.dataSize>0) {
        if (confirm(msg) == true) {
            this.removeBox();
        }
    } else {
        this.removeBox();
    }
 
  }
  removeBox(){
    this.showSpinner = true;
    saveconfirm({
      saveConsumableorderdetailsRecordsdummy: JSON.stringify(this.data),
      accountName: this.accountName,
      userWorkLocation: this.userWorkLocation,
      agencyProType: this.agencyProType
    }).then((result) => {
      result = JSON.parse(JSON.stringify(result));
      console.log('result保存 = ' + JSON.stringify(result));
      if (result.status == 'Success') {
         this.saveFLGbln = result.entity.saveFLGbln;
        //  this.showSpinner = false;
         if(this.saveFLGbln){
          this.showMyToast(result.msg,'','success');
          this.showSpinner = false;
         }
      } else {
        console.log('result.msg = ' + result.msg);
        this.showMyToast('拆盒失败',result.msg,'error');
        this.showSpinner = false;
      }
    })
      .catch((error) => {
        console.log('error = ' + JSON.stringify(error));
      });
 
 
  }
  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);
    }
 
 
 
 
}