黄千龙
2023-08-08 1363fbac72b3c291821917fc883587c1928f1651
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import { LightningElement, track, wire ,api} from 'lwc';
import LightningConfirm from 'lightning/confirm';
import jquery183minjs from '@salesforce/resourceUrl/jquery183minjs';
import PleaseWaitDialog from '@salesforce/resourceUrl/PleaseWaitDialog';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import Selected from '@salesforce/label/c.Selected';
import Set_Search from '@salesforce/label/c.Set_Search';
import Search_Condition from '@salesforce/label/c.Search_Condition';
import Search  from '@salesforce/label/c.Search';
import Search_Result  from '@salesforce/label/c.Search_Result';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import { CurrentPageReference } from 'lightning/navigation';
    
import getNeedParm1  from "@salesforce/apex/LexChoiceAssetController.getNeedParm1";
import init  from "@salesforce/apex/LexChoiceAssetController.init";
import searchAss  from "@salesforce/apex/LexChoiceAssetController.searchAss";
import getData  from "@salesforce/apex/LexChoiceAssetController.getData";
 
 
 
const columns = [
    { label: '选择', fieldName: 'Selected' , minWidth: 20, maxWidth: 20  },
    { label: '保有设备名称', fieldName: 'Name' },
    { label: '机身编码', fieldName: 'SerialNumber' },
    { label: '医院', fieldName: 'HP_Name' },
    { label: '科室', fieldName: 'Department_Name' },
    { label: '发货日', fieldName: 'Posting_Date' },
    { label: '多年保修期至', fieldName: 'Extend_Gurantee_DateTo'},
    { label: '最近一期维修合同结束日', fieldName: 'CurrentContract_End_Date'},
    ];
export default class lexChoiceAsset  extends NavigationMixin(LightningElement) {
 
    Label = {
        Set_Search,
        Search_Condition,
        Search,
        Search_Result,
        Selected
    }
 
 
 
    @api recordId;
    IsLoading=true;
    data = [];
    columns = columns;
    SSPLine;
    Delivered_Product;
    Department_Name;
    HospitalId;
    WorkLocation;
    //搜索需要的数据
    @track inputData1;
    @track inputData2;
    @track inputData3;
    Id;
    StatusC;
    Incharge_Staff;
    Repair_Detail;
    FaultTime;
    RepairApplicantName;
    HPname;
    DepName;
    PlannedVisitDay;
    ActualVisitDateFirst;
    RepairsReportDate;
    ReceiverTime;
    ActualVisitDateSecon;
    ActualVisitDateThird;
    ApplicationTime;
    canRepair;
    //搜索出的数据 report onclick拼接需要的参数     
    needParm2;
 
 
    @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;
           }
         }
     }
       handleRowAction(event) {
        const action = event.detail.action;
        const row = event.detail.row;
        switch (action.name) {
            case '点击添加':
                this.handleAdd(row);
                break;
            default:
                break;
        }
    }
 
    handleAdd(row) {
        // Implement edit logic here
        console.log('Editing row' + JSON.stringify(row));
        this.SetProductId(row.setProductidFull);
    }
 
 
   
 
    getInput1(event){
        this.inputData1=event.detail.value;
 
    }
 
    getInput2(event){
        this.inputData2=event.detail.value;
 
    }
    getInput3(event){
        this.inputData3=event.detail.value;
 
    }
 
 
 
    connectedCallback(){
        init({
            recordId: this.recordId
        }).then(result => {
            // console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.StatusC = result.StatusC;
                this.Incharge_Staff = result.OwnerId;
                this.Repair_Detail = result.Repair_Detail;
                this.FaultTime = result.FaultTime;
                this.RepairApplicantName = result.RepairApplicantName;
                this.HPname = result.HPname;
                this.DepName = result.DepName;
                this.RepairsReportDate = result.RepairsReportDate;
                this.ReceiverTime = result.ReceiverTime;
                this.PlannedVisitDay = result.PlannedVisitDay;
                this.ActualVisitDateFirst = result.ActualVisitDateFirst;
                this.ActualVisitDateSecon = result.ActualVisitDateSecon;
                this.ActualVisitDateThird = result.ActualVisitDateThird;
                this.ApplicationTime = result.ApplicationTime;
                this.ApplyForRepair();
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        }).catch(error => {
            console.log(error);
        })
        this.serContact();
      
    }
     async SelectNone(){
        const inputSearchNo = this.template.querySelector('lightning-input[data-target="SearchNo"]');
            if (inputSearchNo) {
              inputSearchNo.value = '';
            }
 
        const inputSearchName = this.template.querySelector('lightning-input[data-target="SearchName"]');
        if (inputSearchName) {
          inputSearchName.value = '';
        }
        const inputSearchSN = this.template.querySelector('lightning-input[data-target="SearchSN"]');
       console.log('inputSearchSN=='+inputSearchSN);
        if (inputSearchSN) {
          inputSearchSN.value = '';
        }
 
        this.inputData1='';
        this.inputData2='';
        this.inputData3='';
        var SearchNo = this.inputData1;
        var SearchName = this.inputData2;
        var SearchSN = this.inputData3;
        await getData({SearchName : SearchName , SearchNo : SearchNo , SearchSN : SearchSN}).then(res=>{
         if(res!=null){
                this.IsLoading=false;
                this.data=res;
                console.log(res);
                console.log(this.data[0]); 
                }
            }).catch(error=>{
                console.log(error);
            })
 
     }
 
 
 
 
    async SelectDone(){
        var selectedRecords =  this.template.querySelector("lightning-datatable").getSelectedRows();     
            console.log('selectedRecords.length=='+selectedRecords.length);
            if(selectedRecords.length>0){
                if (selectedRecords.length>1) {
                    const evt = new ShowToastEvent({
                        title : '只能选择一个保有设备',
                        message: '',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
                searchAss({
                    recordId: selectedRecords[0].Assetid
                }).then(result => {
                    // console.log(result);
                    if (result != null) {
                        console.log('result.canRepair=='+result.canRepair);
                        this.IsLoading = false;
                        this.canRepair = result.canRepair;
                    }
                    console.log('this.canRepair=='+this.canRepair);
                    if (this.canRepair == '第三方') {
                        const evt = new ShowToastEvent({
                                title : '非我司修理对象,无法新建修理,如有不明请咨询CIC',
                                message: '',
                                variant: 'error'
                            });
                            this.dispatchEvent(evt);
                            this.dispatchEvent(new CloseActionScreenEvent());
                            return;
                    }
                     if (this.canRepair == '不'||this.canRepair == null) {
                            const evt = new ShowToastEvent({
                                    title : '本设备无法新建修理',
                                    message: '',
                                    variant: 'error'
                                });
                                this.dispatchEvent(evt);
                                this.dispatchEvent(new CloseActionScreenEvent());
                            return;
                    }
                    var status = this.StatusC;
                    if (status != '待处理') {
                        const evt = new ShowToastEvent({
                                title : '报修子单的状态不是 待处理 无法申请修理',
                                message: '',
                                variant: 'error'
                            });
                            this.dispatchEvent(evt);
                            this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }
                    if (this.Id == null || this.Id == '') {
                        const evt = new ShowToastEvent({
                                title : '报修子单Id 不能为空',
                                message: '',
                                variant: 'error'
                            });
                            this.dispatchEvent(evt);
                            this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }
                         this.Delivered_Product =  selectedRecords[0].Assetid;
                         this.Department_Name = selectedRecords[0].Accountid;
                         this.HospitalId = selectedRecords[0].Hospital;
                         this.WorkLocation = selectedRecords[0].WorkLocation;
                        this.navigateToNewObjectPage();
                }).catch(error => {
                    console.log(error);
                })
            
            }
            else{
                console.log('else');
                const evt = new ShowToastEvent({
                        title : '请选择一个保有设备',
                        message: '',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
            }
    }
 
    async serContact(){
    console.log('into serContact')
    var SearchNo = this.inputData1;
    var SearchName = this.inputData2;
    var SearchSN = this.inputData3;
 
        if(SearchSN == undefined){
            SearchSN='';
        }
        if(SearchName == undefined){
            SearchName='';
        }
        if(SearchNo == undefined){
            SearchNo = '';
        }
    console.log('SearchName='+SearchName);
    console.log('SearchNo='+SearchNo);
    console.log('SearchSN='+SearchSN);
        await getData({SearchName : SearchName , SearchNo : SearchNo , SearchSN : SearchSN}).then(res=>{
         if(res!=null){
                this.IsLoading=false;
                this.data=res;
                console.log(res);
                console.log(this.data[0]); 
                }
            }).catch(error=>{
                console.log(error);
            })
 
    }
    navigateToNewObjectPage() {
        // console.log('RepairApplicantName=='+this.RepairApplicantName);
        // console.log('this.id=='+this.id);
        const defaultFieldValues =encodeDefaultFieldValues({
          Delivered_Product__c: this.Delivered_Product,
          Account__c: this.Department_Name,
          Hospital__c: this.HospitalId,
          SalesOfficeCode_selection__c: this.WorkLocation,
          Incharge_Staff__c:this.Incharge_Staff,
          Repair_Detail__c:this.Repair_Detail,
          Failure_Occurrence_Date__c:this.FaultTime,
          Repair_Source__c:'从报修子单',
          RepairApplicant__c:this.RepairApplicantName,
          RepairApplicantHospital__c:this.HPname,
          RepairApplicantDepartment__c:this.DepName,
          RepairTime__c:this.RepairsReportDate,
          ReceiverTime__c:this.ReceiverTime,
          PlannedVisitDay__c:this.PlannedVisitDay,
          ActualVisitDateFirst__c:this.ActualVisitDateFirst,
          ActualVisitDateSecond__c:this.ActualVisitDateSecon,
          ActualVisitDateThird__c:this.ActualVisitDateThird,
          SubOrderCreatedDate__c:this.ApplicationTime,
          Exc_work_location__c:true,
          RepairSubOrder__c:this.recordId
        });
 
            this[NavigationMixin.Navigate]({
              type: 'standard__objectPage',
              attributes: {
                objectApiName: 'Repair__c',
                actionName: 'new'
              },
              state: {
                nooverride: '1',
                defaultFieldValues: defaultFieldValues
              }
            });
        this.dispatchEvent(new CloseActionScreenEvent());
      }
 
}