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