FUYU
2023-12-13 4488f711dbc01a8db6753907cae2ef4021dede68
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { NavigationMixin } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
 
// import { getRecordUi } from 'lightning/uiRecordApi';
 
// import NAME_FIELD from '@salesforce/schema/Repair__c.Incharge_Staff__c';
import MY_CUSTOM_OBJECT from '@salesforce/schema/Repair__c';
 
import init from '@salesforce/apex/NewRepairAuraController.init';
 
export default class newRepairLWC extends LightningElement {
    // Expose a field to make it available in the template
    // nameField = NAME_FIELD;
 
    // Flexipage provides recordId and objectApiName
    // @api recordId = 'a0J0l00000EouAT';
    @api recordId;
    @api urlStr;
    @api objectApiName;
 
    /* @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
             console.log(111);
             console.log(currentPageReference);
 
         if (currentPageReference) {
           const urlValue = currentPageReference.state.recordId;
           if (urlValue) {
             let str = `${urlValue}`;
             console.log("str");
             console.log(str);
             this.recordId = str;
           }
         }
     }*/
 
    objectName = 'Repair__c';
    uiPageLayoutView;
    isNewMode;
    //默认值赋值标记
    // defaultFlag = true;
    defaultValue;
    isLoading = true;
    activeSections;
 
    connectedCallback(){ 
        console.log(this.recordId); 
        console.log(JSON.parse(this.urlStr)); 
    }
    //获取Layout字段
    handleRecordEditFormLoad(event) {
        console.log('Layout => ', JSON.stringify(event.detail.layout));
        this.uiPageLayoutView = event.detail.layout;
        console.log('Layout1 => ',this.uiPageLayoutView);
        // urlStr 传参处理
       init({
            recordId : this.recordId,urlStr : this.urlStr
        }).then(result => {
            console.log("result");
            console.log(result);
            this.defaultValue = result;
            //to del !
            this.defaultValue['Delivered_Product'] = '02i10000004tNXIAA2';
            this.defaultValue['Account'] = '0011000001g11rDAAQ';
            this.defaultValue['SalesOfficeCode_selection'] = '北京';
            this.defaultValue['On_site_repair'] = 'RC修理';
            this.defaultValue['Repair_Detail'] = 'testLwc';
            this.defaultValue['Hospital'] = '0011000001g11rDAAQ';
            this.defaultValue['work_location_select'] = '北京办事处';
 
 
 
            if (!result.status) {
                const inputFields = this.template.querySelectorAll(
               'lightning-input-field'
                );
                if (inputFields) {
                   inputFields.forEach(field => {
                    /*console.log('fieldsif => ',field);
                    console.log('fieldsif => ',field.name);
                    console.log('fieldsif => ',field.name.replace("__c",""));*/
                    let fieldName = field.name.replace("__c","");
                    if (this.defaultValue.hasOwnProperty(fieldName)) {
                        field.value= this.defaultValue[fieldName];
                    }
                   });
               }
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        }).finally(() => {
            let checkedSections = new Set();
            if (this.uiPageLayoutView.sections.length > 0) {
              // console.log("id");
              checkedSections.add(this.uiPageLayoutView.sections[0].id);
              //todo del  or 显示所有
              checkedSections.add(this.uiPageLayoutView.sections[1].id);
              // console.log(this.uiPageLayoutView.sections[0].id);
              //默认打开第一个accordion
              this.activeSections =  Array.from(checkedSections);
            }
            
            this.isLoading = false;
        });  
        
    }
    //
 
    handleSubmit(event){
       console.log("handleSubmit");
       event.preventDefault();       // stop the form from submitting
       const fields = event.detail.fields;
       console.log("fields");
       console.log(fields);
       console.log(event.detail);
       // this.template.querySelector('lightning-record-edit-form').submit(fields);
    }
    //成功后跳转
    handleSucess(event){
       const updatedRecord = event.detail.id;
       console.log('onsuccess: ', updatedRecord);
    }
    handleReset(event) {
        const fields = event.detail.fields;
        console.log('fields => ',fields);
       const inputFields = this.template.querySelectorAll(
           'lightning-input-field'
       );
       if (inputFields) {
           inputFields.forEach(field => {
 
                console.log('fieldsif => ',field);
                console.log('fieldsif => ',field.name);
               // field.reset();
           });
       }
    }
    handleSectionToggle(event) {
        const openSections = event.detail.openSections;
 
        /*if (openSections.length === 0) {
            this.activeSectionsMessage = 'All sections are closed';
        } else {
            this.activeSectionsMessage =
                'Open sections: ' + openSections.join(', ');
        }*/
    }
 
}