liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
/* 备品智能化 add by dzk
   自动分配确认画面
*/
import { api, LightningElement, track, wire } from 'lwc';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import initRenApply  from '@salesforce/apex/AutomaticAssignController.initRenApply';
import selectRenApply  from '@salesforce/apex/AutomaticAssignController.selectRenApply';
import getAssetLocationOptions  from '@salesforce/apex/AutomaticAssignController.getAssetLocationOptions';
import getDemopurpose1PicklistOptions  from '@salesforce/apex/AutomaticAssignController.getDemopurpose1PicklistOptions';
import getProcategoryPicklistOptions  from '@salesforce/apex/AutomaticAssignController.getProcategoryPicklistOptions';
import autoConfirmation  from '@salesforce/apex/AutomaticAssignController.autoConfirmation';
import autoConfirmationConfirm  from '@salesforce/apex/AutomaticAssignController.autoConfirmationConfirm';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import IFTradeComplianceAlert2 from '@salesforce/label/c.IFTradeComplianceAlert2';
 
export default class lexAutomaticAssign extends LightningElement {
    @track data = [];
    @track selectAll = false;
    @track mainNotLink;
    @track mainLink = false;
    @track mainPartialLink = false;
    @track subNotLink = false;
    @track subLink = false;
    @track noAccessory = false;
    @track subPartialLink = false;
    @track RentalApp = '';
    @track ProCode = '';
    @track UseReason = '全部';
    @track UserSalesdept = '全部';
    @track Procategory = '';
    @track AssetLocation = '';
    @track searchResults = [];
    @track selectedRows =[];
    @track RequestOwner = '';
    @track showSpinner = false;
    @track showProfile = false;
    @track retrievedDataCount = 0;
    selectOptions1 = [];
    selectUseReason = [];
    selectProcategory = [];
    selectAssetLocation = [];
    selectUserSalesdept = [
        { label: '全部', value: '全部'},
        { label: '医疗西南营业本部', value: '医疗西南营业本部' },
        { label: '医疗西北营业本部', value: '医疗西北营业本部' },
        { label: '医疗华南营业本部', value: '医疗华南营业本部' },
        { label: '医疗华东营业本部', value: '医疗华东营业本部' },
        { label: '医疗华北营业本部', value: '医疗华北营业本部' },
        { label: '医疗东北营业本部', value: '医疗东北营业本部' },
        { label: '医疗产品培训本部', value: '医疗产品培训本部' },
        { label: '消化·呼吸内镜事业本部', value: '消化·呼吸内镜事业本部' },
        { label: '外科事业本部', value: '外科事业本部' },
        { label: 'Solution本部', value: 'Solution本部' },
        { label: 'MA本部', value: 'MA本部' },
    ];
 
    connectedCallback() {
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
    }
 
    // 页面数据初始化显示
    @wire(initRenApply, {})
    wiredRenApplyMethod({ data, error }) {
        this.showSpinner = true;
        
        if (data) {
            if(data.userProfileCheck === false){
                this.showToast('当前用户无权限查看。');
                this.showSpinner = false;
                this.showProfile = true;
                this.retrievedDataCount = 0;
            }else{
                this.data = data.RentalApplySet; 
                this.retrievedDataCount = this.data.length;
                this.showSpinner = false;
            }
        } else if (error) {
            this.data = []; 
            this.showSpinner = false;
            this.retrievedDataCount = 0;
            console.log('RenApplyMethod错误------' + JSON.stringify(error));
        }
    }
    
    handleSelect(event) {
        const itemId = event.target.dataset.id;
        const selected = event.target.checked;
        this.data = this.data.map((item) => {
            if (item.id === itemId) {
                return { ...item, selected: selected };
            }
            return item;
        });
        // 更新选中的数据集合
        if (selected) {
            const selectedItem = this.data.find((item) => item.id === itemId);
            this.selectedRows = [...this.selectedRows, selectedItem];
        } else {
            this.selectedRows = this.selectedRows.filter((item) => item.id !== itemId);
        }
    }
 
    //全选按钮
    handleSelectAll(event) {
        this.selectAll = event.target.checked;
        this.data = this.data.map((row) => ({ ...row, selected: this.selectAll }));
        if(this.selectAll){
            this.selectedRows = this.data;
        }else{
            this.selectedRows = [];
        }   
    }
 
    // 查询条件值变更
    handleRentalAppChange(event) {
        this.RentalApp = event.target.value;
    }
 
    handleProCodeChange(event) {
        this.ProCode = event.target.value;
    }
 
    handleUseReasonChange(event) {
        this.UseReason = event.target.value;
    }
 
    handleProcategoryChange(event) {
        this.Procategory = event.target.value;
    }
    handleAssetLocationChange(event) {
        this.AssetLocation = event.target.value;
    }
 
    handleUserSalesdeptChange(event) {
        this.UserSalesdept = event.target.value;
    }
    handleRequestOwnerChange(event) {
        this.RequestOwner = event.target.value;
    }
    
    // 获取用户.办事处选项列表
    @wire(getAssetLocationOptions)
    wiredAssetLocationOptions({ data, error }) {
        if (data) {
            this.selectAssetLocation = data.map(option => {
                return { label: option, value: option };
            });
        } else if (error) {
            console.error('获取用户.办事处选项列表' + error);
        }
    }
 
    // 获取备品借出申请.使用目的1选项列表
    @wire(getDemopurpose1PicklistOptions)
    wiredDemopurpose1PicklistOptions({ data, error }) {
        if (data) {
            this.selectUseReason = data.map(option => {
                return { label: option, value: option };
            });
        } else if (error) {
            console.error('获取备品借出申请.使用目的1选项列表' + error);
        }
    }
 
    // 获取备品借出申请.产品分类选项列表
    @wire(getProcategoryPicklistOptions)
    wiredProcategoryPicklistOptions({ data, error }) {
        if (data) {
            this.selectProcategory = data.map(option => {
                return { label: option, value: option };
            });
        } else if (error) {
            console.error('获取备品借出申请.产品分类选项列表' + error);
        }
    }
 
    // 根据条件对数据进行查询
    handleSearch(event) {
        this.showSpinner = true;
        selectRenApply({ UseReason: this.UseReason,
                           UserSalesdept: this.UserSalesdept, 
                           RentalApp: this.RentalApp,
                           ProCode: this.ProCode,
                           Procategory: this.Procategory,
                           AssetLocation: this.AssetLocation,
                           RequestOwner: this.RequestOwner 
                      }).then(result => {
            // 处理 Apex 方法的返回结果
            this.data = result;
            this.showSpinner = false;
            this.selectedRows = [];
            this.retrievedDataCount = this.data.length;
        }).catch(error => {
           // 处理错误
            console.error('selectAppSetData发生错误:', error);
        });
    }
 
    handleButtonClick(event) {
        this.showSpinner = true;
        const dataId = event.currentTarget.dataset.id;
        const selectedItem = this.data.find((item) => item.id === dataId);
        if(selectedItem.selected == false){
            let msg = '请选择确认分配的数据。';
            this.showToast(msg);
             this.showSpinner = false;
        }else{
            this.selectedRows = [...this.selectedRows, selectedItem];
            this.autoConfirmation(this.selectedRows);
        }
    }
 
    handleAllButtonClick(event) {
        this.showSpinner = true;
        if(this.selectedRows.length === 0){
            let msg = '请选择确认分配的数据。';
            this.showToast(msg);
             this.showSpinner = false;
        }else{
            this.autoConfirmation(this.selectedRows); 
        }
    }
 
    //自动分配按钮
    async autoConfirmation(selectedRows){
        await autoConfirmation({ recordId: JSON.stringify(selectedRows)}).then(result => {
            // 处理 Apex 方法的返回结果
            // 20240122 ljh  贸易合规2 start
            if(result == ''){
                // 继续分配
                autoConfirmationConfirm({ recordId: JSON.stringify(selectedRows)}).then(result => {
                    if(result == 'Success'){
                        const event = new ShowToastEvent({
                            title: '',
                            message: '分配成功。',
                            variant: "success"
                        });
                        this.showSpinner = false;
                        window.location.reload();
                    }else{
                        this.showSpinner = false;
                        this.showToast(result);
                    }
                });
            }else if(result.startsWith('TrandeAlert')){
                LightningConfirm.open({
                    message: '如下申请单'+result.slice(11)+'可能存在贸易合规风险,是否继续分配,'+ IFTradeComplianceAlert2 +'(一般需5-10个工作日)',       //20240305 贸易合规二期邮件发送 话术修改
                    variant: 'headerless',
                    label: 'this is the aria-label value',
                }).then(confirm=>{
                    if(!confirm){
                        console.log('zheli贸易合规');
                        this.showSpinner = false;
                        // window.location.reload();
                    }else{
                        // 继续分配
                        autoConfirmationConfirm({ recordId: JSON.stringify(selectedRows)}).then(result => {
                            if(result == 'Success'){
                                const event = new ShowToastEvent({
                                    title: '',
                                    message: '分配成功。',
                                    variant: "success"
                                });
                                this.showSpinner = false;
                                window.location.reload();
                            }else{
                                this.showSpinner = false;
                                this.showToast(result);
                            }
                        });
                    }
                }) 
            // 20240122 ljh  贸易合规2 end 
            }else{
                this.showSpinner = false;
                this.showToast(result);
            }
        }).catch(error => {
            // 处理错误
            console.error('selectAppSetData发生错误:', error);
        });
        
    }
 
    // 清空检索条件
    handleClear(event){
        this.RentalApp = '';
        this.ProCode = '';
        this.RequestOwner = '';
        this.UseReason = '全部';
        this.UserSalesdept = '全部';
        this.Procategory = '';
        this.AssetLocation = '';
    }   
 
    showToast(msg) {
        const event = new ShowToastEvent({
            message: msg,
            variant: "error",
            mode: 'sticky'
        });
        this.dispatchEvent(event);   
    }
}