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
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
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import UserInfo_Owner  from '@salesforce/apex/NewAgencyContractController.UserInfo_Owner';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import { CloseActionScreenEvent } from 'lightning/actions';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';        
import {loadStyle} from 'lightning/platformResourceLoader'    
import LightningConfirm from 'lightning/confirm';
 
export default class LexNewAgencyContract extends NavigationMixin(LightningElement) {
    @api recordId;
    ProfileId;
    IsLoading=false;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                this.recordId=str;
            }
        }
    }
 
    connectedCallback(){
        Promise.all([            
            loadStyle(this, lwcCSS)            
        ]);    
        UserInfo_Owner().then(res => {
            console.log('result===>',res,this.recordId)
            if (res.id == '李东凤' || res.profileId == '系统管理员') {
                this.IsLoading = false;
                LightningConfirm.open({
                    message: '会自动分配新建合同的客户编码,保留旧编码的时候请用复制合同。',
                    variant: 'headerless',
                    label: 'this is the aria-label value',
                }).then(cancel=>{
                    if(!cancel){
                        this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }else{
                        const defaultFieldValues = encodeDefaultFieldValues({
                            Agent_Ref__c:this.recordId,
                            ParentId:this.recordId,
                            retURL:this.recordId,
                            Name:'*'
                        });
                        console.log(defaultFieldValues)
                        this[NavigationMixin.Navigate]({
                            type: 'standard__objectPage',
                            attributes: {
                                objectApiName: 'Account',
                                actionName:'new'
                            },
                            state:{
                                defaultFieldValues:defaultFieldValues,
                                recordTypeId:res.recordTypeId
                            }
                        });
                    }
                })
                
            } else {
                this.showToast('没有新建的权限','error');
            }
        }).catch(err => {
            console.log('err:',err)
        })
        
    }
 
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode:'Sticky'
            });
            this.dispatchEvent(event);
        }
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}