liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
import { LightningElement, track, api, wire } from 'lwc';
import getWrapperClassList from '@salesforce/apex/RetrieveApprovalRecordsController.getSubmittedRecords';
import gettotalcount from '@salesforce/apex/RetrieveApprovalRecordsController.gettotalcount';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { refreshApex } from '@salesforce/apex';
export default class ApprovalRecords extends LightningElement {
    @api wrapperList = [];
    @api draftValues = [];
    @track error;
    @track sortBy;
    @track sortDirection;
    @track bShowModal = false;
    @track selectedcommentrowno;
    @track icomments = '';
    @track record;
    @track queryOffset;
    @track queryLimit;
    @track totalRecordCount;
    @track showinfiniteLoadingSpinner = true;
    @track showLoadingSpinner = false;
    @track isDialogVisible = false;
    @track originalMessage;
    @track wrapperListtrue = true;
    @track title;
    @api footertext;
    @track enable_app_rej = true;
    @track columns = [
 
        /* {
             label: '#',
             fieldName: 'recordId',
             type: 'url',
             initialWidth:50,
             typeAttributes: { label: 'View', target: '_blank' }
         },*/
        {
            label: '待审批项目',
            fieldName: 'nameUrl',
            type: 'url',
            typeAttributes:{
                label:{fieldName: 'recordName'},
                target:'_blank'
            },
            // initialWidth: 200,
            wrapText: true,
            sortable: false,
            hideDefaultActions: true
        },
        {
            label: '相关项',
            fieldName: 'relatedTo',
            type: 'text',
            initialWidth: 120,
            sortable: false,
            hideDefaultActions: true
        },
        {
            label: '提交人',
            fieldName: 'submittedBy',
            type: 'text',
            initialWidth: 80,
            sortable: false,
            hideDefaultActions: true
        }
        // {
        //     label: '提交时间',
        //     fieldName: 'submittedDate',
        //     type: 'date',
        //     initialWidth: 120,
        //     typeAttributes: {
        //         day: 'numeric',
        //         month: 'short',
        //         year: 'numeric'
        //         //hour: '2-digit',
        //         //minute: '2-digit',
        //         //second: '2-digit',
        //         //hour12: true
        //     },
        //     sortable: true
        // }
    ];
    wiredcountResults;
    @wire(gettotalcount) totalcount(result) {
        console.log('result.data' + result.data);
        this.wiredcountResults = result;
        if (result.data != undefined) {
        this.totalRecordCount = result.data;
        console.log('tota' + this.totalRecordCount);
        this.title = '要批准的项目';
        if (result.data > 0)
        this.wrapperListtrue = true;
        else {
        this.totalRecordCount = 0;
        this.title = '要批准的项目';
        this.wrapperListtrue = false;
        console.log('tota' + this.totalRecordCount);
        }
        } else if (result.error) {
        this.error = result.error;
        this.totalRecordCount = 0;
        this.title = '要批准的项目';
        this.wrapperListtrue = false;
        console.log('tota' + this.totalRecordCount);
        }
    }
    constructor() {
        super();
        this.title = '要批准的项目';
        this.showinfiniteLoadingSpinner = true;
        this.wrapperList = [];
        this.queryOffset = 0;
        this.queryLimit = 1000;
        this.loadRecords();
    }
    reloadrecords() {
        this.showLoadingSpinner = true;
        this.showinfiniteLoadingSpinner = true;
        this.queryOffset = 0;
        this.queryLimit = 1000;
        let flatData;
        this.wrapperList = [];
        console.log(this.totalRecordCount);
        return getWrapperClassList({ queryLimit: this.queryLimit, queryOffset: this.queryOffset })
            .then(result => {
                console.log(result);
                console.log(this.totalRecordCount);
                flatData = result;
                //deloitte-zhj 20231130 undefined 换成null
                console.log('flatData = ' + flatData);
                if (flatData != null) {
                    for (var i = 0; i < flatData.length; i++) {
                        flatData[i].recordId = '/' + flatData[i].recordId;
                    }
                    this.wrapperList = flatData;
                }
                this.showLoadingSpinner = false;
                console.log(this.wrapperList);
                this.showLoadingSpinner = false;
                return refreshApex(this.wiredcountResults);
                //this.error = undefined;
            }).catch(error => {
                console.log(error);
                this.showLoadingSpinner = false;
                this.error = error;
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error',
                        message: result,
                        variant: 'info'
                    })
                );
                return refreshApex(this.wiredcountResults);
            })
    }
    loadRecords() { //you can build a method for a button
        this.showLoadingSpinner = true;
 
        let flatData;
 
        console.log('lr' + this.queryOffset);
        console.log('lr' + this.queryLimit);
        console.log('here is 0>>>>>>>>');
        return getWrapperClassList({ queryLimit: this.queryLimit, queryOffset: this.queryOffset })
            .then(result => {
                console.log('result>>>>'  + result);
                flatData = result;
                if (flatData != undefined) {
                    for (var i = 0; i < flatData.length; i++) {
                        flatData[i].recordId = '/' + flatData[i].recordId;
                    }
 
                    let updatedRecords = [...this.wrapperList, ...flatData];
                    this.wrapperList = updatedRecords;
                }
                this.showLoadingSpinner = false;
                console.log(this.wrapperList);
                refreshApex(this.wiredcountResults);
                this.title = '要批准的项目';
            }).catch(error => {
                console.log(error);
                this.showLoadingSpinner = false;
                this.error = error;
                refreshApex(this.wiredcountResults);
                this.title = '要批准的项目';
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error',
                        message: result,
                        variant: 'info'
                    })
                );
            })
    }
    loadMoreData(event) {
        const { target } = event;
        this.showinfiniteLoadingSpinner = true;
        //Display a spinner to signal that data is being loaded
        console.log('lmr totalRecordCount' + this.totalRecordCount);
        console.log('lmr queryLimit' + this.queryLimit);
        console.log('lmr queryOffset' + this.queryOffset);
        if (this.totalRecordCount < this.queryLimit) {
            console.log(this.wrapperList);
            this.showinfiniteLoadingSpinner = false;
            return refreshApex(this.wiredcountResults);
        }
        else if (this.totalRecordCount > this.queryOffset) {
            this.queryOffset = this.queryOffset + 5;
            console.log('lmir queryLimit' + this.queryLimit);
            console.log('lmir queryOffset' + this.queryOffset);
            let flatData;
            return getWrapperClassList({ queryLimit: this.queryLimit, queryOffset: this.queryOffset })
                .then(result => {
                    target.isLoading = false;
                    console.log(result);
                    console.log(this.totalRecordCount);
                    flatData = result;
                    if (flatData != undefined) {
                        for (var i = 0; i < flatData.length; i++) {
                            flatData[i].recordId = '/' + flatData[i].recordId;
                        }
                        //this.wrapperList = this.wrapperList.concat(flatData);
                        let updatedRecords = [...this.wrapperList, ...flatData];
                        this.wrapperList = updatedRecords;
                    }
                    target.isLoading = false;
                    console.log(this.wrapperList);
                    this.showinfiniteLoadingSpinner = false;
                    return refreshApex(this.wiredcountResults);
                }).catch(error => {
                    console.log(error);
                    this.showinfiniteLoadingSpinner = false;
                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Error',
                            message: result,
                            variant: 'info'
                        })
                    );
                    return refreshApex(this.wiredcountResults);
                })
        } else {
            this.showinfiniteLoadingSpinner = false;
            target.isLoading = false;
            return refreshApex(this.wiredcountResults);
        }
 
    }
 
    enablebuttons(event)
    {
         const selectedRows = event.detail.selectedRows;
         var recordsCount = event.detail.selectedRows.length;
         if(recordsCount > 0)
         this.enable_app_rej = false;
         else
         this.enable_app_rej = true;
         
    }
 
    handleSortdata(event) {
        this.sortBy = event.detail.fieldName;
        this.sortDirection = event.detail.sortDirection;
        this.sortData(event.detail.fieldName, event.detail.sortDirection);
    }
    sortData(fieldname, direction) {
        this.showLoadingSpinner = true;
        let parseData = JSON.parse(JSON.stringify(this.wrapperList));
        let keyValue = (a) => {
            return a[fieldname];
        };
        let isReverse = direction === 'asc' ? 1 : -1;
        parseData.sort((x, y) => {
            x = keyValue(x) ? keyValue(x) : '';
            y = keyValue(y) ? keyValue(y) : '';
 
            return isReverse * ((x > y) - (y > x));
        });
        this.wrapperList = parseData;
        this.showLoadingSpinner = false;
    }
    openModal() { this.bShowModal = true; }
    closeModal() { this.bShowModal = false; }
    handleRowAction(event) {
        const actionName = event.detail.action.name;
        var row = event.detail.row;
        console.log(row);
        switch (actionName) {
            case 'view_record':
                this.viewrecord(row);
                break;
            case 'submitter_comments':
                this.opencomment(row);
                break;
            default:
        }
    }
    opencomment(row) {
        this.bShowModal = true;
        console.log(row);
        const { workItemId } = row;
        console.log(workItemId);
        this.record = row;
        console.log(this.record);
        this.icomments = this.record.submittercomment;
        console.log(this.bShowModal);
    }
    viewrecord(row) {
        this.record = row;
        console.log(this.record.recordId);
        window.open(this.record.recordId, '_blank');
 
    }
}