binxie
2024-01-20 e0de9222da210f9c8eb1a9f5400f936a14923e11
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// import { api, wire,LightningElement } from 'lwc';
// import { CurrentPageReference } from "lightning/navigation";
// import { CloseActionScreenEvent } from 'lightning/actions';
// import { updateRecord } from 'lightning/uiRecordApi';
// import { ShowToastEvent } from 'lightning/platformShowToastEvent';
// import { NavigationMixin } from 'lightning/navigation';
// import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
// import init from '@salesforce/apex/lexNewOnLineSurvey2Controller.init';
 
// export default class lexNewOnLineSurvey2 extends NavigationMixin(LightningElement) {
//     @api recordId;
//     id;
//     reportId;
//     CreatedById;
//     CreatedBy_Name__c;
//     Name
//     @wire(CurrentPageReference)
//     getStateParameters(currentPageReference) {
//         if (currentPageReference) {
//           const urlValue = currentPageReference.state.recordId;
//           if (urlValue) {
//             let str = `${urlValue}`;
//             this.recordId = str;
//           }
//         }
//     }
//     connectedCallback(){
//         init({
//             recordId: this.recordId
//         }).then(result=>{
//             this.Name = result.Id;
//             this.CreatedBy_Name__c=result.CreatedByNameC;
//             this.CreatedById=result.CreatedById
//             this.createOPDFromRentalApply();
//         });
//     }
//     createOPDFromRentalApply(){
//         var today = new Date();
//         var year = today.getFullYear();
//         var month = today.getMonth() + 1;
//         var day = today.getDate();
//         var hours = today.getHours();
//         var minutes = today.getMinutes();
//         var seconds = today.getSeconds();
//         let time=year + '%2F' + month + '%2F' + day;
  //       let url='/setup/ui/recordtypeselect.jsp?ent=01I10000000u0VA&retURL=%2F'+this.recordId+
  //       '&save_new_url=%2Fa1E%2Fe%3FretURL%3D%252F'+this.recordId+
        // '%26Report_day__c%3D'+time+
        // '%26Medical_staff__c%3D'+this.name+
        // '%26Medical_staff__c_lkid%3D'+this.recordId+
        // '%26Reporter__c%3D'+this.CreatedBy_Name__c+
        // '%26Reporter__c_lkid%3D'+this.CreatedById;
//         // let url='/setup/ui/recordtypeselect.jsp?ent=On_Line_Survey';
//         this[NavigationMixin.Navigate]({
//             type: 'standard__webPage',
//             attributes: {
//                 url:url
//             }
//         });
//         // let url = '/setup/ui/recordtypeselect.jsp';
//         // let params = new URLSearchParams();
//         // params.append('ent', '%2F'+this.recordId);
//         // params.append('save_new_url', '%2Fa1E%2Fe%3FretURL%3D%252F'+this.recordId+
//         // '%26Report_day__c%3D'+time+
//         // '%26Medical_staff__c%3D'+this.name+
//         // '%26Medical_staff__c_lkid%3D'+this.recordId+
//         // '%26Reporter__c%3D'+this.CreatedBy_Name__c+
//         // '%26Reporter__c_lkid%3D'+this.CreatedById);
//         // console.log(url + '?' + params.toString());
//         // url=url + '?' + params.toString()
//         // this[NavigationMixin.Navigate]({
//         //     type: 'tandard__webPage',
//         //     attributes: {
//         //         url: url
//         //     }
//         // });
//         // window.open();
//         this.dispatchEvent(new CloseActionScreenEvent());
//     }
// }
 
import { api, wire,LightningElement, track } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import init from '@salesforce/apex/lexNewOnLineSurvey2Controller.init';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class LexNewOnLineSurvey2 extends NavigationMixin(LightningElement) {
    @api recordId;
    date;
    practitioner1;
    ownerId;
    selectedRecordTypeId;
    IsLoading = true;
    @track recordTypeOptions;
    @wire(getObjectInfo, { objectApiName: 'On_Line_Survey__c' })
    objectInfo({ error, data }) {
      if (data) {
        this.recordTypeOptions = Object.values(data.recordTypeInfos).map((rt) => ({
          label: rt.name,
          value: rt.recordTypeId
        }));
      } else if (error) {
        // 处理操作失败的错误
      }
    }
    @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;
          }
        }
    }
    connectedCallback(){
        
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        init({
            recordId: this.recordId
        }).then(result=>{
            console.log("res:"+result);
            this.ownerId = result.CreatedById;
 
            this.IsLoading = false;
        });
    }
    handleRecordTypeChange(event) {
        this.selectedRecordTypeId = event.target.value;
 
        var today = new Date();
        var year = today.getFullYear();
        var month = today.getMonth() + 1;
        var day = today.getDate();
        var hours = today.getHours();
        var minutes = today.getMinutes();
        var seconds = today.getSeconds();
        let time=year + '-' + month + '-' + day;
        const defaultValues = encodeDefaultFieldValues({
            // OPD_number__c: this.recordId,
            Report_day__c: time,
            Medical_staff__c: this.recordId,
            Reporter__c: this.ownerId
        });
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'On_Line_Survey__c',
                actionName: 'new'
            },
            state: {
                nooverride: '1',
                defaultFieldValues: defaultValues,
                recordTypeId: this.selectedRecordTypeId
            }
        });
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    
}