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'); } }