liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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 getClonedValues from '@salesforce/apex/LexQISCloneButtonController.getClonedValues';
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); 
                    getClonedValues({ recordId: this.recordId, objectAPIName : 'QIS_Report__c' }).then(data => {
                        console.log('this.recordId = ' + this.recordId);
                        const map = new Map(Object.entries(data));
                        let keys = Object.keys(data);
                        let finalObj = {};
                        for (let i = 0; i < keys.length; i++) {
                            var skey = keys[i];
                            var val =  map.get(keys[i]);
                            if(val) {
                                finalObj[skey] = val;
                            }
                            if (skey == 'QIS_Status__c') {
                                finalObj[skey] = '草案中';
                            }
                        }
                        finalObj['QIS_pre__c'] = this.recordId;
                        console.log('finalObj>>'+ JSON.stringify(finalObj));
 
                        // 创建导航事件
                        const defaultFieldValues = encodeDefaultFieldValues(finalObj);
                        console.log('defaultFieldValues = ' + JSON.stringify(defaultFieldValues));
                        console.log('this.recordId = ' + this.recordId);
                        this[NavigationMixin.Navigate]({
                            type: "standard__objectPage",
                            attributes: {
                                objectApiName: 'QIS_Report__c',
                                actionName: "new",
                                recordId: this.recordId,
                            },state: {
                                nooverride: '1',
                                defaultFieldValues:defaultFieldValues
                            }
                        });
                    }).catch(error => {
                        console.log('error>> ' + JSON.stringify(error));
                    });
                    
                    //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);
        // });
    }
}