import { LightningElement, track, api, wire } from 'lwc';
|
import getWrapperClassList from '@salesforce/apex/lexBatchApprovalRecordsController.getSubmittedConsumItems';
|
import processRecords from '@salesforce/apex/lexBatchApprovalRecordsController.processRecords';
|
import gettotalcount from '@salesforce/apex/lexBatchApprovalRecordsController.gettotalcount';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { refreshApex } from '@salesforce/apex';
|
const actions = [
|
{ label: '查看详情', name: 'show_details' }
|
];
|
const columns = [
|
{
|
type: 'action',
|
typeAttributes: { rowActions: actions },
|
},
|
{
|
label: '消耗品订单名称',
|
fieldName: 'recordName',
|
type: 'text',
|
wrapText: true,
|
sortable: true
|
},
|
{
|
label: '类型',
|
fieldName: 'relatedTo',
|
type: 'text',
|
sortable: true
|
},
|
{
|
label: '提交人',
|
fieldName: 'submittedBy',
|
type: 'text',
|
sortable: true
|
},
|
{
|
label: '提交日期',
|
fieldName: 'submittedDate',
|
type: 'date',
|
typeAttributes: {
|
day: 'numeric',
|
month: 'short',
|
year: 'numeric'
|
|
},
|
sortable: true
|
}
|
];
|
|
|
export default class LexBatchApprovalConsumOrder 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;
|
@track selectItemId;
|
@track showDetailPop = false;
|
@api footertext;
|
@track enable_app_rej = true;
|
comment;
|
@track columns = columns;
|
wiredcountResults;
|
@wire(gettotalcount) totalcount(result) {
|
|
console.log(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);
|
}else{
|
this.wrapperListtrue = false;
|
this.title = '要批准的项目';
|
this.totalRecordCount = 0;
|
}
|
console.log('获取数量结束:');
|
}
|
constructor() {
|
console.log('constructor start');
|
super();
|
this.title = 'Your Pending Approvals';
|
this.showinfiniteLoadingSpinner = true;
|
this.wrapperList = [];
|
this.queryOffset = 0;
|
this.queryLimit = 2000;
|
this.loadRecords();
|
|
console.log('constructor end');
|
}
|
reloadrecords() {
|
this.showLoadingSpinner = true;
|
this.showinfiniteLoadingSpinner = true;
|
this.queryOffset = 0;
|
this.queryLimit = 2000;
|
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;
|
if (flatData != undefined) {
|
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: error.body.message,
|
variant: 'info'
|
})
|
);
|
return refreshApex(this.wiredcountResults);
|
})
|
}
|
loadRecords() { //you can build a method for a button
|
// const inputAlignright = document.createElement('style');
|
// inputAlignright .innerText = `
|
// .slds-text-heading_small, .slds-text-heading--small {
|
// font-size:14px;
|
// line-height: var(--lwc-lineHeightHeading,1.25);
|
// }
|
// .slds-truncate {
|
// font-size: 11px;
|
// max-width: 100%;
|
// overflow: hidden;
|
// text-overflow: ellipsis;
|
// white-space: nowrap;
|
// }
|
// .slds-hyphenate {
|
// overflow-wrap: break-word;
|
// word-wrap: break-word;
|
// -webkit-hyphens: auto;
|
// -ms-hyphens: auto;
|
// hyphens: auto;
|
// font-size: 11px;
|
// }
|
// `
|
// ;
|
// document.body.appendChild(inputAlignright);
|
|
console.log('tetst');
|
this.showLoadingSpinner = true;
|
|
let flatData;
|
|
console.log('lr' + this.queryOffset);
|
console.log('lr' + this.queryLimit);
|
return getWrapperClassList({ queryLimit: this.queryLimit, queryOffset: this.queryOffset })
|
.then(result => {
|
console.log("初始化dddd:");
|
console.log(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('ddddd***',this.wrapperList);
|
refreshApex(this.wiredcountResults);
|
}).catch(error => {
|
console.log(error);
|
this.showLoadingSpinner = false;
|
this.error = error;
|
refreshApex(this.wiredcountResults);
|
this.title = 'Your Pending Approvals (' + this.totalRecordCount + ')';
|
this.dispatchEvent(
|
new ShowToastEvent({
|
title: 'Error',
|
message: error.message,
|
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("查询结果:");
|
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: error.message,
|
variant: 'info'
|
})
|
);
|
return refreshApex(this.wiredcountResults);
|
})
|
} else {
|
this.showinfiniteLoadingSpinner = false;
|
target.isLoading = false;
|
return refreshApex(this.wiredcountResults);
|
}
|
|
}
|
|
handleSave(event) {
|
this.showLoadingSpinner = true;
|
console.log(event.detail.draftValues);
|
console.log(this.wrapperList);
|
var draftlst = [];
|
draftlst = event.detail.draftValues;
|
for (var i = 0; i < this.wrapperList.length; i++) {
|
console.log(this.wrapperList[i].workItemId);
|
for (var j = 0; j < draftlst.length; j++) {
|
console.log(draftlst[j].workItemId);
|
if (this.wrapperList[i].workItemId === draftlst[j].workItemId) {
|
this.wrapperList[i].comments = draftlst[j].comments;
|
}
|
}
|
}
|
for (var i = 0; i < this.wrapperList.length; i++) {
|
console.log(this.wrapperList[i].comments);
|
}
|
this.draftValues = [];
|
this.showLoadingSpinner = false;
|
this.dispatchEvent(
|
new ShowToastEvent({
|
message: '评论已添加,批准/拒绝时该项目将优先使用该评论',
|
variant: 'success'
|
})
|
);
|
}
|
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;
|
|
}
|
processrec() {
|
this.showLoadingSpinner = true;
|
console.log('test');
|
var el = this.template.querySelector('lightning-datatable');
|
var selectedrows = el.getSelectedRows();
|
console.log(selectedrows);
|
var varprocessType = this.originalMessage;// event.target.label;
|
var processrows = [];
|
for (var i = 0; i < selectedrows.length; i++) {
|
// selectedrows[i].comments=this.comments;
|
processrows.push(selectedrows[i]);
|
}
|
if (processrows.length > 0) {
|
var str = JSON.stringify(processrows);
|
console.log('类型:'+varprocessType);
|
processRecords({ processType: varprocessType, strwraprecs: str,comment:this.comment })
|
.then(result => {
|
console.log(result);
|
if('successfully'.indexOf(result) == -1){
|
this.showLoadingSpinner = false;
|
this.error = result;
|
this.dispatchEvent(
|
new ShowToastEvent({
|
title: 'Error',
|
message: result,
|
variant: 'error'
|
})
|
);
|
return refreshApex(this.wiredcountResults);
|
}
|
this.showinfiniteLoadingSpinner = true;
|
this.queryOffset = 0;
|
this.queryLimit = 5;
|
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;
|
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);
|
this.showLoadingSpinner = false;
|
var messagetitle;
|
var ivariant;
|
console.log("方法内的操作类型:"+varprocessType);
|
if(varprocessType == 'Approve')
|
{
|
messagetitle = '所选项已批准';
|
ivariant = 'success';
|
}
|
else if(varprocessType == 'Reject')
|
{
|
messagetitle = '所选项已拒绝';
|
ivariant = 'error';
|
}
|
this.dispatchEvent(
|
new ShowToastEvent({
|
title: messagetitle,
|
message: result,
|
variant: ivariant
|
})
|
);
|
return refreshApex(this.wiredcountResults);
|
}).catch(error => {
|
console.log(error);
|
this.showLoadingSpinner = false;
|
this.error = error;
|
this.dispatchEvent(
|
new ShowToastEvent({
|
title: 'Error',
|
message: error.message,
|
variant: 'info'
|
})
|
);
|
return refreshApex(this.wiredcountResults);
|
})
|
})
|
.catch(error => {
|
this.showLoadingSpinner = false;
|
this.dispatchEvent(
|
new ShowToastEvent({
|
title: 'Error',
|
message: error.message,
|
variant: 'error'
|
})
|
);
|
return refreshApex(this.wiredcountResults);
|
});
|
}
|
else {
|
this.dispatchEvent(
|
new ShowToastEvent({
|
title: '未选择项',
|
message: '请选择项目',
|
variant: 'warning'
|
})
|
);
|
this.showLoadingSpinner = false;
|
}
|
}
|
|
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 'show_details':
|
this.showDetailPop = true;
|
this.selectItemId = row.recordId.replace('/','');
|
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');
|
|
}
|
handleconformClick(event) {
|
try {
|
if (event.target.label === '批准') {
|
console.log('label' + event.target.label);
|
this.originalMessage = 'Approve';
|
this.isDialogVisible = true;
|
}
|
else if (event.target.label === '拒绝') {
|
console.log('label' + event.target.label);
|
this.originalMessage = 'Reject';
|
this.isDialogVisible = true;
|
}
|
else if (event.target.name === 'confirmModal') {
|
console.log(event.detail);
|
//when user clicks outside of the dialog area, the event is dispatched with detail value as 1
|
if (event.detail !== 1) {
|
console.log('status' + event.detail.status);
|
if (event.detail.status === 'confirm') {
|
this.processrec();
|
this.isDialogVisible = false;
|
} else if (event.detail.status === 'cancel') {
|
//do something else
|
this.isDialogVisible = false;
|
}
|
}
|
|
}
|
}
|
catch(e) {
|
console.log(e);
|
}
|
}
|
saveDialog(){
|
console.log("评论:"+this.comment);
|
this.processrec();
|
this.isDialogVisible = false;
|
}
|
closeDialog(){
|
this.isDialogVisible = false;
|
this.comments='';
|
}
|
afterChange(event) {
|
this.comment = event.detail.value;
|
}
|
hidePopup(){
|
this.showDetailPop = false;
|
}
|
|
|
|
}
|