buli
2023-05-23 89c6a02c36153a85b15e016650526fa795a551bf
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
import {
    LightningElement,
    wire,
    api
} from 'lwc';
import {
    CurrentPageReference
} from "lightning/navigation";
import {
    CloseActionScreenEvent
} from 'lightning/actions';
import init from '@salesforce/apex/buttonAssetCtl.init';
import initUserName from '@salesforce/apex/buttonAssetCtl.initUserName';
import selecctAccountByAccountId from '@salesforce/apex/buttonAssetCtl.selecctAccountByAccountId';
import selecctProduct2ById from '@salesforce/apex/buttonAssetCtl.selecctProduct2ById';
import selecctRepairByFomatToday from '@salesforce/apex/buttonAssetCtl.selecctRepairByFomatToday';
import selecctQISReportByFomatToday from '@salesforce/apex/buttonAssetCtl.selecctQISReportByFomatToday';
 
export default class LexCreateRepairFromAsset extends LightningElement {
    @api recordId;
    str;
    IsLoading = true;
    Id;
    userID;
    EmployeeNoC;
    day;
    day1;
    day2;
    Name;
    NoPartRiskDateFC;
    ProductIDC;
    AccountId;
    HPIdC;
    HospitalC;
    DepartmentClassC;
    HospitalId;
    DepartmentClassId;
    RepairSalesPointProvinceChinaC;
 
    @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 => {
            console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.userID = result.userID;
                this.day = result.day;
                this.day1 = result.day1;
                this.day2 = result.day2;
                this.Name = result.Name;
                this.NoPartRiskDateFC = result.NoPartRiskDateFC;
                this.ProductIDC = result.ProductIDC;
                this.AccountId = result.AccountId;
                this.HPIdC = result.HPIdC;
                this.HospitalC = result.HospitalC;
                this.DepartmentClassC = result.DepartmentClassC;
                this.HospitalId = result.HospitalId;
                this.DepartmentClassId = result.DepartmentClassId;
 
                initUserName({
                    userId: this.userID
                }).then(result => {
                    console.log(result);
                    if (result != null) {
                        this.EmployeeNoC = result.Employee_No__c;
                        this.RepairSalesPointProvinceChinaC = result.RepairSalesPoint_Province_China__c;
                    }
                })
 
                this.CreateRepairFromAsset();
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        }).catch(error => {
            console.log(error);
        })
    }
 
    // 新建修理    
    CreateRepairFromAsset() {
        var nCRepairFromAssetBSting = "{!$Label.notCreateRepairFromAssetButton}";
        var nCRepairFromAssetB02Sting = "{!$Label.notCreateRepairFromAssetButton02}";
        nCRepairFromAssetBSting = nCRepairFromAssetBSting + nCRepairFromAssetB02Sting;
        var nCRepairFromAssetBList = nCRepairFromAssetBSting.split(',');
        var EmployeeNo = this.EmployeeNoC;
        if (nCRepairFromAssetBList.indexOf(EmployeeNo) != -1) {
            alert("对不起,您无权使用此按钮创建修理!");
            return;
        }
        var today = this.day1;
        todays = today.split("/");
        fomatToday = todays[0] + '-' + todays[1] + '-' + todays[2];
 
        var QIS_Name = '';
        var QIS_Id = '';
        var url1 = "";
        var FSE_GI_Main_Leader__id = '';
        var FSE_GI_Main_Leader__name = '';
        var FSE_SP_Main_Leader__id = '';
        var FSE_SP_Main_Leader__name = '';
        var Incharge_Staff = '';
        var Incharge_Staff_id = '';
 
        selecctQISReportByFomatToday({
            AssetId: this.Id,
            fomatToday: fomatToday
        }).then(records => {
            console.log(records);
                if (records.length >= 1) {
                    var boolday = confirm('请确认此件是否属于10天内重复报告,如果是,请使用原QIS信息填写。');
                    if (!boolday) {
                        return;
                    }
                }
 
                if (records.length >= 1) {
                    QIS_Name = records[0].Name;
                    QIS_Id = records[0].Id;
            }
        })
 
        selecctRepairByFomatToday({
            AssetId: this.Id,
            fomatToday: fomatToday
        }).then(records2 => {
            console.log(records2);
                if (records2.length >= 1) {
                    var boolday = confirm('此件设备如为10天内重复报告,建议回到原修理单使用复制功能提交。请确认是否继续新建修理? ');
                    if (!boolday) {
                        return;
                    }
                }
                var Old_Repair_Name = '';
                if (records2.length >= 1) {
                    Old_Repair_Name = records2[0].Name;
            }
        })
 
        selecctProduct2ById({
            Id: this.ProductIDC
        }).then(recordP => {
            console.log(recordP);
 
                if (recordP != null && recordP.length > 0) {
                    var canRepair = recordP[0].Can_Repair__c;
                    if (canRepair == '第三方') {
                        alert('非我司修理对象,无法新建修理,如有不明请咨询CIC');
                        return;
                    }
                    if (canRepair == '不' || canRepair == null) {
                        alert('本设备无法新建修理');
                        return;
                    }
                    if (canRepair == 'RC送修') {
                        url1 = "&00N10000009HAJl=TRUE"
                    }
 
            }
        })
 
        selecctAccountByAccountId({
            AccountId: this.AccountId
        }).then(List => {
            console.log(List);
            if (List != null) {
 
                var RecordTypeId = List['records']['Parent']['RecordTypeId'].substring(0, 15);
                
                if (RecordTypeId != '01210000000Qem1') {
                    if (List['records']['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
                        FSE_GI_Main_Leader__id = List['records']['Parent']['Parent']['FSE_GI_Main_Leader__c'].substring(0, 15);
                        FSE_GI_Main_Leader__name = List['records']['Parent']['Parent']['FSE_GI_Main_Leader__r']['Name'];
                    }
                    if (List['records']['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) {
                        FSE_SP_Main_Leader__id = List['records']['Parent']['Parent']['FSE_SP_Main_Leader__c'].substring(0, 15);
                        FSE_SP_Main_Leader__name = List['records']['Parent']['Parent']['FSE_SP_Main_Leader__r']['Name'];
                    }
                    var Work_Location = '';
                    if (List['records']['Parent']['RecordTypeId'] != null || List['records']['Parent']['RecordTypeId'] != '') {
                        var recordId = List['records']['Parent']['RecordTypeId'].substring(0, 15);
                        if (recordId == '01210000000QemL' || recordId == '01210000000QezZ' || recordId == '01210000000QemQ') {
                            if (List['records']['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
                                Work_Location = List['records']['Parent']['Parent']['FSE_GI_Main_Leader__r']['Work_Location__c'];
                            }
 
                        } else if (recordId == '01210000000Qeze' || recordId == '01210000000Qezj' || recordId == '01210000000Qezt' || recordId == '01210000000Qezo' || recordId == '01210000000Qezy') {
                            if (List['records']['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) {
                                Work_Location = List['records']['Parent']['Parent']['FSE_SP_Main_Leader__r']['Work_Location__c'];
                            }
 
                        }
                    }
                    if (RecordTypeId == '01210000000QemL') {
                        Incharge_Staff = FSE_GI_Main_Leader__name;
                        Incharge_Staff_id = FSE_GI_Main_Leader__id;
                    }
                    if (RecordTypeId == '01210000000QezZ') {
                        Incharge_Staff = FSE_GI_Main_Leader__name;
                        Incharge_Staff_id = FSE_GI_Main_Leader__id;
                    }
                    if (RecordTypeId == '01210000000QemQ') {
                        Incharge_Staff = FSE_GI_Main_Leader__name;
                        Incharge_Staff_id = FSE_GI_Main_Leader__id;
                    }
                    if (RecordTypeId == '01210000000Qeze') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == '01210000000Qezj') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == '01210000000Qezt') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == '01210000000Qezo') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == '01210000000Qezy') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                }
 
 
            }
        })
        var partSupplyFinishDate = this.NoPartRiskDateFC;
        if (this.day < this.NoPartRiskDateFC && this.NoPartRiskDateFC <= this.day2) {
            alert('预计' + partSupplyFinishDate + '零件即将停产,请送修前与工厂及RC联络');
        }
        if (this.NoPartRiskDateFC != null && this.NoPartRiskDateFC != undefined && this.NoPartRiskDateFC <= this.day) {
            alert('该型号零件已经停产,有特殊需求,请送修前与工厂RC联络');
        }
 
        var url = "/a0J/e?CF00N10000002Dx66_lkid=" + this.HospitalId + "&CF00N10000002Dx66=" + this.HospitalC + "&CF00N10000002Dx5t_lkid=" + this.DepartmentClassId + "&CF00N10000002Dx5t=" + this.DepartmentClassC + "&CF00N10000002Dx5n_lkid=" + this.Id + "&CF00N10000002Dx5n=" + this.Name + "&CF00N10000002Dx1X_lkid=" + this.Id + "&CF00N10000002Dx1X=" + this.Name + "&CF00N10000002EMHw_lkid=" + Incharge_Staff_id + "&CF00N10000002EMHw=" + Incharge_Staff + "&00N10000002FH86=%e5%8f%aa%e4%bf%ae%e7%90%86&00N10000006P6Rn=" + this.RepairSalesPointProvinceChinaC + "&00N10000006P6SM=" + encodeURI(Work_Location) + "&CF00N10000009H7yM=" + QIS_Name + "&CF00N10000009H7yM_lkid=" + QIS_Id + "&00N10000009H2fa=" + Old_Repair_Name + "&retURL=%2F" + this.Id;
        if (url1 != "") {
            url = url + url1;
        }
        window.open(url);
    }
}