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
94
95
96
97
98
99
100
101
/*
 * @Description: 
 * @Author: [lijinhuan]
 * @Date: 2023-08-14 22:10:38
 * @LastEditors: [lijinhuan]
 * @LastEditTime: 2023-09-13 20:38:00
 */
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import recordTypeId from '@salesforce/apex/toBatchOwnerController.TypeId';
 
export default class LexAssignTaskButtonAccount extends NavigationMixin(LightningElement) {
    @api recordId;
    IsLoading=true;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                console.log('str');
                console.log(str);
                this.recordId=str;
            }
        }
    }
    connectedCallback(){
        recordTypeId().then(res => {
            // const defaultValues = encodeDefaultFieldValues({
            //     account__c: this.recordId,
            //     taskStatus__c: '01 分配',
            //     taskDifferent__c: '上级分配任务',
            //     Name:'*'
            // });
            // let url = '/setup/ui/recordtypeselect.jsp?ent=' + res.endId + '&p3=' + res.recordTypeId.slice(0,res.recordTypeId.length - 3) +'&retURL=%2F' +'&save_new_url=%2Fa3V%2Fe%3FretURL%3D%252Fa3V%252Fo'+
            // '&account__c=' + this.recordId +
            // '&taskStatus__c=01 分配' + 
            // '&taskDifferent__c=上级分配任务' +
            // '&Name=*'
            // this[NavigationMixin.Navigate]({
            //     type: 'standard__webPage',
            //     attributes: {
            //         url:url
            //     }});
                // window.open(url);
 
            const defaultValues = encodeDefaultFieldValues({
                account__c: this.recordId,
                taskStatus__c: '01 分配',
                taskDifferent__c: '上级分配任务',
                Name: '*'
            });
            let states = 
                {
                    nooverride: '1',
                    navigationLocation: 'LIST_VIEW',
                    // backgroundContext: '/lightning/o/Account/list?filterName=Recent&0.source=alohaHeader',
                    backgroundContext: '/lightning/r/Account/'+this.recordId+'/view',
                    defaultFieldValues: defaultValues,
                };
 
            // states['recordTypeId'] =  res.recordTypeId;
            states['useRecordTypeCheck'] =  true;
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'task__c',
                    actionName: 'new'
                },
                state: states
                // state: {
                    // nooverride: '1',
                    // defaultFieldValues: defaultValues,
                    // recordTypeId: res.recordTypeId
                // }
            });
 
            // this[NavigationMixin.Navigate]({
            //     type: 'standard__objectPage',
            //     attributes: {
            //         objectApiName: 'task__c',
            //         actionName: 'new'
            //     },
            //     state: {
            //         nooverride: '1',
            //         defaultFieldValues: defaultValues,
            //         recordTypeId: res.recordTypeId
            //     }
            // });
            
        }).catch(err => {
            console.log('err======>',err)
        })
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}