buli
2023-06-05 e9b970ea36eea5dcf93fd5b965bf13d7010ce0ad
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
102
103
104
105
106
107
108
109
110
111
112
import { LightningElement, api, track, wire } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import initData from '@salesforce/apex/LeadDemoPIPLController.initData';
 
export default class LeadDemoPIPL extends LightningElement {
    sobjectType = 'Lead';
 
    @api recordId;
    @track title;
    @track recordTypeId;
    @track isClone = false;
    @track isShowSpinner = true;
    @wire(CurrentPageReference) pageRef;
    @track layout;
    @track fields;
    @track staticResource;
    @track section_names;
    @track piFieldsMap;
 
    connectedCallback() {
        if(!this.recordId || this.isClone){
            this.title = '新建意向';
        }
        if(this.pageRef && this.pageRef.state) {
            this.recordTypeId = this.pageRef.state.recordTypeId;
        }
        console.log('recordId = ' + this.recordId + ' pid = ' + this.pid + ' recordTypeId = ' + this.recordTypeId + ' sobjectType = ' + this.sobjectType);
        initData({
            rid : this.recordId,
            recordTypeId : this.recordTypeId,
            sobjectType : this.sobjectType
        }).then((r) =>{
            r = JSON.parse(JSON.stringify(r));
            if(r.status == 'Success'){
                console.log('r.status ==  Success');
                console.log('r.entity.layout start = ' + r.entity.layout);
                let layout = JSON.parse(r.entity.layout);
                for(var s of layout){
                    for(var c of s.layoutColumns){
                        for(var item of c.layoutItems){
                            console.log('item.behavior = ' + JSON.stringify(item.behavior));
                            item['disabled'] = item.behavior == 'Readonly' ? true : false;
                            item['required'] = item.behavior == 'Required' ? true : false;
                        }
                    }
                }
                this.layout = layout;
                this.fields = r.entity.fields;
                this.staticResource = JSON.parse(r.entity.staticResource)
                this.section_names = this.layout.map(s=>s.label);
                let m = {};
                for(let f of this.staticResource.PIDetails){
                    m[f.SF_Field_API_Name__c] = f;
                }
                this.piFieldsMap = m;
                console.log('this.piFieldsMap = ' + JSON.stringify(this.piFieldsMap));
            }else{
                this.showToast('Error',r.Msg);
            }
            this.isShowSpinner = false;
        })
    }
 
    showToast(type,msg){
        const event = new ShowToastEvent({
            title : type,
            variant : type,
            message : msg
        });
        this.dispatchEvent(event);
    }
 
    CaseInfoChange(){
        console.log('hello');
    }
 
    save(){
        console.log('enter save button');
        for(let s of this.layout){
            for(let c of s.layoutColumns){                
                for(let item of c.layoutItems){
                    // if(item.field && item.behavior != "Readonly"){
                    //     if(pi_fields_map.hasOwnProperty(item.field)){
                    //         data[item.field] = obj[pi_fields_map[item.field].AWS_Field_API__c];
                    //         //data[pi_fields_map[item.field].SF_Field_Encrypted_API__c] = obj[pi_fields_map[item.field].AWS_Encrypted_Field_API__c];
                    //     }else{
                    //         data[item.field] = item.value;
                    //     }
                    // }
                    console.log('item.field = ' + item.field + ' value = ' + item.value);
                }
            }
        }
    }
 
    cancel(){
        
    }
 
    change(event){
        console.log(event.target.value);
        // console.log(event.target);
        // for(let s of this.layout){
        //     for(let c of s.layoutColumns){                
        //         for(let item of c.layoutItems){
        //             if(item.field == 'Email')
        //                 console.log('item.field = ' + item.field + ' value = ' + item.value);
        //         }
        //     }
        // }
    }
}