binxie
2024-01-18 b1d36ea3e6653e59bd767aa192c688ee0d9d4c58
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
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/LexQISCloneButtonController.checkStatus';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';  //deloitte-zhj 20231210 PIPL还原 现在使用标准的克隆
 
 
export default class lexQISCloneButton 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) { 
                    //deloitte-zhj 20231210 PIPL还原 现在使用标准的克隆 start
                    var pageurl = '/lightning/cmp/c__LexQISPIPLAura?c__isClone=true&c__recordId=' + this.recordId;
                    this.navigate(pageurl); 
                    
                    
                    // 创建导航事件
                    // const defaultFieldValues =encodeDefaultFieldValues({
                    //     QIS_pre__c: this.recordId
                    // });
                    // console.log('defaultFieldValues = ' + JSON.stringify(defaultFieldValues));
                    // console.log('this.recordId = ' + this.recordId);
                    // this[NavigationMixin.Navigate]({
                    //     type: "standard__objectPage",
                    //     attributes: {
                    //         objectApiName: 'QIS_Report__c',
                    //         actionName: "clone",
                    //         recordId: this.recordId,
                    //     },state: {
                    //         nooverride: '1',
                    //         defaultFieldValues:defaultFieldValues
                    //     }
                    // });
                    //deloitte-zhj 20231210 PIPL还原 现在使用标准的克隆 end
                } else {
                    const evt = new ShowToastEvent({
                        title: 'Warning',
                        message: '状态为取消的QIS才可以被复制并新建',
                        variant: 'warning',
                        mode: 'dismissable'
                    }); 
                    this.dispatchEvent(evt);
                }
                this.dispatchEvent(new CloseActionScreenEvent());
            }) 
    }
    navigate(pageurl) {
        window.open(pageurl, '_self');
        // this[NavigationMixin.GenerateUrl]({
        //     type: 'standard__webPage',
        //     attributes: {
        //         url: pageurl
        //     }
        // }).then(generatedUrl => {
        //     console.log('generatedUrl = ' + generatedUrl);
        //     // setTimeout(() => {
        //     //     window.open(generatedUrl, '_self');
        //     // }, 0);
        // });
    }
}