import { LightningElement, api } from 'lwc';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import checkStatus from '@salesforce/apex/LexRepairCloneButtonController.checkStatus'
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
|
export default class LexRepairCloneButton extends NavigationMixin(LightningElement) {
|
@api recordId;
|
|
connectedCallback(){
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
window.clearTimeout(this.delayTimeout);
|
this.delayTimeout = setTimeout(() => {
|
this.handleClick();
|
}, 0);
|
}
|
|
handleClick(){
|
checkStatus({recordId: this.recordId})
|
.then(result => {
|
console.log('result------------------:', result);
|
if (result) {
|
var pageurl = '/lightning/cmp/c__LexRepairPIPLAura?c__isClone=true&c__recordId=' + this.recordId;
|
this.navigate(pageurl);
|
} else {
|
const evt = new ShowToastEvent({
|
title: '',
|
message: '该状态下不能复制',
|
variant: 'warning',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
}
|
this.dispatchEvent(new CloseActionScreenEvent());
|
})
|
}
|
navigate(pageurl) {
|
this[NavigationMixin.GenerateUrl]({
|
type: 'standard__webPage',
|
attributes: {
|
url: pageurl
|
}
|
}).then(generatedUrl => {
|
setTimeout(() => {
|
window.open(generatedUrl, '_self');
|
}, 0);
|
});
|
}
|
}
|