zhangchunxu
2023-07-21 14e3923804ac265cb8bf6e571232131b662fd204
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
/*
 * @Description: 备品检测分析报告
 * @Author: [lijinhuan]
 * @Date: 2023-06-25 17:32:18
 * @LastEditors: [lijinhuan]
 * @LastEditTime: 2023-07-06 16:04:00
 */
import { LightningElement, track, wire, api } from 'lwc';
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { updateRecord } from 'lightning/uiRecordApi';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import { CloseActionScreenEvent } from 'lightning/actions';
 
import init from '@salesforce/apex/lexRentalApplyFaultReportController.init';
 
const columns = [
    { label: 'No.', fieldName: 'Name',type: 'text'},
    { label: '备品配套明细型号', fieldName: 'Fixture_Model_No__c',type: 'text' },
    { label: '固定资产号码', fieldName: 'Loaner_asset_no__c',type: 'text' },
    { label: '机身编码', fieldName: 'SerialNumber_F__c',type: 'text'},
    { label: '战略科室分类', fieldName: 'OCMdeptCategory',type: 'text' },
    { label: '医院', fieldName: 'Hospital',type: 'text' },
    { label: '检测结果', fieldName: 'Inspection_result_after__c',type: 'text'},
    { label: '检测NG区分', fieldName: 'Inspection_result_after_NG__c',type: 'text'},
    {
        type: "button", label: '故障报告', initialWidth: 130, typeAttributes: {
            label: '故障报告',
            name: 'View',
            title: '故障报告',
            disabled: false,
            value: 'RentalApplyFault',
            iconPosition: 'left',
            iconName:'utility:preview',
            variant:'Brand'
        }
    },
    
];
export default class LexRentalApplyFaultReport extends NavigationMixin(LightningElement) {
    @api recordId;
    IsLoading = true;
    datas = [];
    columns = columns;
    selectedRas = [];
    RentalApplyName;
    PersonInCharge;
    WorkPlace;
    DemoPurpose2;
    @track error;
    @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=>{
            if(JSON.stringify(result)!= '' && result.length>0){
                this.IsLoading = false;
                this.records = result;
                let resultList = [];
                let objectTemp;
 
                result.forEach(item => {
                    this.RentalApplyName = item.rae.Rental_Apply__r.Name;
                    this.PersonInCharge = item.rae.Rental_Apply__r.Person_In_Charge__r.Name;
                    this.WorkPlace = item.rae.Rental_Apply__r.WorkPlace__c;
                    this.DemoPurpose2 = item.rae.Rental_Apply__r.demo_purpose2__c;
                    // console.log(item);
                    objectTemp = item.rae;
                    objectTemp.OCMdeptCategory = item.rae.Rental_Apply__r.OCM_dept_category__c;
                    objectTemp.Hospital = item.rae.Rental_Apply__r.Hospital__r.Name;
                    // objectTemp.RentalApplyFault = '<a href="/'+item.faultId+'" >点击查看</a>';
                    objectTemp.RentalApplyFault = item.faultId;
                    //console.log(JSON.stringify(objectTemp));
                    resultList.push(objectTemp);
                });
                this.datas = resultList;
            }else{
                // this.dispatchEvent(new CloseActionScreenEvent());
                this.showToast('没有回收检测NG的一览','warning');
                this.updateRecordView(this.recordId);
                return;
            }
        }).catch(err=>{
            console.log("error:");
            console.log(err);
            this.error = err;
        }).finally(()=>{
 
        });
    }
 
 
    callRowAction(event) {
        const rec = event.detail.row;
        const actionName = event.detail.action.name;
        // console.log(actionName);
        if (actionName === 'View') {
            console.log(rec.RentalApplyFault);
            const recordId = rec.RentalApplyFault;
            // this.handleAction(rec, 'view');
            if(recordId != null && recordId !=''){
                this[NavigationMixin.Navigate]({
                    type: 'standard__recordPage',
                    attributes: {
                        recordId: recordId,
                        objectApiName: 'Rental_Apply_Fault__c',
                        actionName: 'view'
                    }
                })
                // window.open("/"+faultId);
            }else{
                console.log('zheli00');
                console.log('C:',rec);
                // 新建跳转
                // window.open("/a5C/e?
                // Name=*" 
                // + "&CF00N10000009I5UX_lKid=" + radetailId 
                // + "&CF00N10000009I5UX=" + radetailName 
                // + "&CF00N10000009I5UV_lKid=" + personId 
                // + "&CF00N10000009I5UV=" + personName 
                // + "&00N10000009I5Uh=" + purpose2 
                // + "&00N10000009I5UW=" + name 
                // + "&00N10000009I6jv=" + hospitalName 
                // + "&00N10000009I5Ua=" + serialNumber 
                // + "&00N10000009I5UP=" + fixtureNo 
                // + "&00N10000009I5Uf=" + workPlace 
                // + "&00N10000009I5UU=" + deptCategory);
                let defaultFieldValues = {};
                // console.log('zheli01');
                defaultFieldValues['Name'] = '*';
                defaultFieldValues['Rental_Apply_Equipment_Set_Detail__c'] = rec.Id;
                defaultFieldValues['Person_In_Charge_User__c']= rec.Rental_Apply__r.Person_In_Charge__c;
                defaultFieldValues['demo_purpose2__c']= rec.Rental_Apply__r.demo_purpose2__c;
                defaultFieldValues['RentalApplyNo__c']= rec.Rental_Apply__r.Name;
                defaultFieldValues['HospitalText__c']= rec.Hospital;
                defaultFieldValues['Repair_product_body_number__c']= rec.SerialNumber_F__c;
                defaultFieldValues['Fixture_Model_No__c']= rec.Fixture_Model_No__c;
                defaultFieldValues['WorkPlace__c']= rec.Rental_Apply__r.WorkPlace__c;
                defaultFieldValues['OCM_dept_category__c']= rec.OCMdeptCategory;
                this[NavigationMixin.Navigate]({
                    type: 'standard__objectPage',
                    attributes: {
                        objectApiName: 'Rental_Apply_Fault__c',
                        actionName: 'new'
                    },
                    state: {
                        nooverride: '1',
                        defaultFieldValues: encodeDefaultFieldValues(defaultFieldValues)
                    }
                });       
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        }
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            message: msg,
            variant: type
        });
        if(type == 'success'){
            this.updateRecordView(this.recordId);
        }
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
 
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
}