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
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;
 
 
    connectedCallback(){ 
        console.log(this.recordId); 
        console.log(JSON.parse(this.urlStr)); 
        console.log(333);  
    }
    //获取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;
            this.defaultValue['Delivered_Product'] = '02i10000004tNXIAA2';
            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)) {
                        console.log('fieldsif => ',field);
                        // field.value= this.defaultValue[fieldName];
                    }
                   });
               }
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        }).finally(() => {
            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();
           });
       }
    }
 
}