binxie
2023-06-20 f62ffbeb0ce6d67b56c0d409d7b93574a0070452
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
({
    doInit: function (component, event, helper) {
        helper.doinit(component, event, helper);
    },
 
    createAopp: function (component, event, helper) {
        var addRecordEvent = $A.get('e.force:createRecord');
        addRecordEvent.setParams({
            entityApiName: 'Agency_Opportunity__c',
            recordTypeId: '012100000006KW7'
        });
        addRecordEvent.fire();
    },
 
    new_report: function (component, event, helper) {
        component.find('save_button').set('v.label', '保存并新建');
        helper.new_report(component, event, helper);
    },
 
    copy_button: function (component, event, helper) {
        component.find('save_button').set('v.label', '保存并新建');
        helper.copy_button(component, event, helper);
    },
    delete_button: function (component, event, helper) {
        helper.delete_button(component, event, helper);
    },
    change_report_radio: function (component, event, helper) {
        helper.change_report_radio(component, event, helper);
    },
 
    edit_button: function (component, event, helper) {
        component.find('save_button').set('v.label', '保存');
        helper.edit_button(component, event, helper);
    },
 
    createCon: function (component, event, helper) {
        helper.createCon(component, event, helper);
    },
 
    showRequiredFields: function (component, event, helper) {
        $A.util.removeClass(component.find("newOpportunityField"), "none");
        $A.util.removeClass(component.find("newOpportunityField"), "none");
    },
 
    handleSuccess: function (component, event, helper) {
        helper.handleSuccess(component, event, helper);
    },
 
    handleSubmit: function (component, event, helper) {
        event.preventDefault(); // stop form submission
        var showValidationError = false;
        var fields = component.find("newOpportunityField");
        var vaildationFailReason = '';
        let agencyReport = Object.create(null);
        fields.forEach(function (field) {
            if (field.get("v.fieldName") === 'Type__c' && $A.util.isEmpty(field.get("v.value"))) {
                showValidationError = true;
                vaildationFailReason = "分类不能为空!";
            } else if (field.get("v.fieldName") === 'Doctor_Division1__c' && $A.util.isEmpty(field.get("v.value"))) {
                showValidationError = true;
                if (vaildationFailReason != '') {
                    vaildationFailReason += "医生区分(职务)不能为空!";
                } else {
                    vaildationFailReason = "医生区分(职务)不能为空!";
                }
 
            }
            //SWAG-CF58C3 fy start 
            if (field.get("v.fieldName") === 'Name') {
                agencyReport['name'] = field.get("v.value");
            } else if (field.get("v.fieldName") === 'Type__c') {
                agencyReport['type'] = field.get("v.value");
            } else if (field.get("v.fieldName") === 'Doctor_Division1__c') {
                agencyReport['doctorDivision1'] = field.get("v.value");
            }
            //SWAG-CF58C3 fy end 
        });
        if (!showValidationError) {
            //SWAG-CF58C3 fy start 
            var agencyHospitalid = component.get('v.hospitalLinkId');
            //zhj MEBG新方案改造 2022-11-29 start
            debugger
            let hospitalName = '';
            //调用后端searchAgencyDataId方法查询出医院下面所有客户人员dataid
            helper.CallBackAction(component, 'searchAgencyDataId', {
                hospitalId: agencyHospitalid
            }, function (data) {
                if (data.getState() == "SUCCESS") {
                    var data = data.getReturnValue();
                    if (data.IsSuccess == true) {
                        let agencyContactIds = ''
                        if (data.Message == '' && data.Data && data.Data.length > 0) {
                            hospitalName = data.Data[0].Agency_Hospital__r.Name;
                            for (var i = 0; i < data.Data.length; i++) {
                                if (data.Data[i].AWS_Data_Id__c)
                                    agencyContactIds += ',' + data.Data[i].AWS_Data_Id__c;
                            }
                            agencyContactIds = agencyContactIds.substring(1);
                            agencyReport['agencyContactIds'] = agencyContactIds;
                        } else {
                            agencyReport['agencyContactIds'] = agencyContactIds;
                        }
                        var arr = new Array();
                        arr.push(agencyReport);
                        var requestData = JSON.stringify(arr);
                        // helper.set_aws_url(component,data,agencyHospitalid);
 
                        var token = component.get('v.AWStoken');
                        var newUrl = component.get('v.AWSinsert') + 'V2';
 
                        component.set('v.login', true);
                        helper.insert_agencycontact(component, token, newUrl, requestData, agencyHospitalid, helper, hospitalName);
                    } else {
                        helper.ShowToast({
                            "message": data.message,
                            "type": "error"
                        });
                    }
                } else {
                    helper.ShowToast({
                        "message": 'searchAgency失败',
                        "type": "error"
                    });
                }
            })
            //zhj MEBG新方案改造 2022-11-29 end
            // var arr = new Array();
            // arr.push(agencyReport);
            // var data = JSON.stringify(arr);
            // var token = component.get('v.AWStoken');
            // var newUrl = component.get('v.AWSinsert');
            // component.set('v.login',true);
            // helper.insert_agencycontact(component,token,newUrl,data,agencyHospitalid,helper);
            //SWAG-CF58C3 fy end 
            // helper.newlyBuild(component, event, helper);
        } else {
            component.find('OppMessage').setError(vaildationFailReason);
        }
    },
 
    createCancel: function (component, event, helper) {
        helper.createCancel(component, event, helper);
    },
 
    yes_button: function (component, event, helper) {
        component.set('v.confirm_status', 1);
        helper.close_confirm(component, component.get('v.modal_confirm_title'), component.get('v.modal_confirm_text'));
    },
 
    no_button: function (component, event, helper) {
        component.set('v.confirm_status', 2);
        helper.close_confirm(component, component.get('v.modal_confirm_title'), component.get('v.modal_confirm_text'));
    },
 
    toggle_report: function (component, event, helper) {
        helper.toggle_report(component, event, helper);
    },
 
    save_report: function (component, event, helper) {
        helper.save_report(component, event, helper);
    },
 
    select_date_change: function (component, event, helper) {
        helper.select_date_change(component, event, helper);
    },
 
    select_agency_change: function (component, event, helper) {
        debugger
        helper.select_agency_change(component, event, helper);
    },
 
    hosChange: function (component, event, helper) {
        var hospital_name = event.getParam("value");
        var hospital_nameld = component.get("v.UseProduct1s");
        if (hospital_name.match(/(\S+\s)+/)) {
            if (hospital_nameld != hospital_name) {
                helper.searchHos(component, event, helper);
            }
        } else {
            if (hospital_name == '') {
                helper.hideSearchs(component, event, helper);
            } else {
                helper.hideSearch(component, event, helper);
            }
        }
    },
    selectHos: function (component, event, helper) {
        helper.selectHos(component, event, helper);
        helper.setOpportunity_cfilter(component);
    },
    //使用产品1
    UseProduct1Change: function (component, event, helper) {
        var UseProduct1Name = event.getParam("value");
        var UseProduct1Nameold = component.get("v.UseProduct1s");
        debugger
        if (UseProduct1Name.match(/(\S+\s)+/)) {
            if (UseProduct1Name != UseProduct1Nameold) {
                helper.searchUseProduct1(component, event, helper);
            }
        } else {
            if (UseProduct1Name == '') {
                helper.hideSearchUseProduct1s(component, event, helper);
            } else {
                helper.hideSearchUseProduct1(component, event, helper);
            }
        }
    },
    seletUseProduct1Change: function (component, event, helper) {
        helper.seletUseProduct1Change(component, event, helper);
    },
    //使用产品2
    UseProduct2Change: function (component, event, helper) {
        var UseProduct2Name = event.getParam("value");
        var UseProduct2Nameold = component.get("v.UseProduct2s");
        if (UseProduct2Name.match(/(\S+\s)+/)) {
            if (UseProduct2Name != UseProduct2Nameold) {
                helper.searchUseProduct2(component, event, helper);
            }
        } else {
            if (UseProduct2Name == '') {
                helper.hideSearchUseProduct2s(component, event, helper);
            } else {
                helper.hideSearchUseProduct2(component, event, helper);
            }
        }
    },
    seletUseProduct2Change: function (component, event, helper) {
        helper.seletUseProduct2Change(component, event, helper);
    },
    productcategoryChange2: function (component, event, helper) {
        helper.productcategoryChange2(component, event, helper);
    },
    //使用产品3
    UseProduct3Change: function (component, event, helper) {
        var UseProduct3Name = event.getParam("value");
        var UseProduct3Nameold = component.get("v.UseProduct3s");
        if (UseProduct3Name.match(/(\S+\s)+/)) {
            if (UseProduct3Name != UseProduct3Nameold) {
                helper.searchUseProduct3(component, event, helper);
            }
        } else {
            if (UseProduct3Name == '') {
                helper.hideSearchUseProduct3s(component, event, helper);
            } else {
                helper.hideSearchUseProduct3(component, event, helper);
            }
        }
    },
    seletUseProduct3Change: function (component, event, helper) {
        helper.seletUseProduct3Change(component, event, helper);
    },
 
 
    select_department: function (component, event, helper) {
        helper.setOpportunity_cfilter(component);
    },
    doctor_change: function (component, event, helper) {
        helper.doctor_change(component, event, helper);
    },
    stageNameChange: function (component, event, helper) {
        helper.stageNameChange(component, event, helper);
    },
    onDragOver: function (component, event, helper) {
        event.preventDefault();
    },
 
    onDrop: function (component, event, helper) {
        event.stopPropagation();
        event.preventDefault();
        event.dataTransfer.dropEffect = 'copy';
        var files = event.dataTransfer.files;
        helper.readFile(component, helper, files[0]);
    },
    CreateRecord: function (component, event, helper) {
        var files = event.getSource().get("v.files");
        helper.readFile(component, helper, files[0]);
        component.set("v.showErrorInfo", false);
    },
 
    processFileContent: function (component, event, helper) {
        helper.saveRecords(component, event, helper);
        component.set("v.showErrorInfo", false);
    },
 
    cancel: function (component, event, helper) {
        component.set("v.showMain", true);
    },
 
    import: function (component, event, helper) {
        helper.showImport(component);
    },
    exportDate: function (component, event, helper) {
        var stockData = component.get("v.reports_date");
        console.log('导出数据' + stockData);
        var csv = helper.convertArrayOfObjectsToCSV(component, stockData);
        if (csv == null) { return; }
 
        var universalBOM = "\uFEFF";
        var hiddenElement = document.createElement('a');
        hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(universalBOM + csv);
        hiddenElement.target = '_self'; // 
        hiddenElement.download = 'ExportData.csv';  // CSV file Name* you can change it.[only name not .csv] 
        document.body.appendChild(hiddenElement); // Required for FireFox browser
        hiddenElement.click(); // using click() js function to download csv file
 
    },
    export_condition: function (component, event, helper) {
        helper.showExport(component);
    },
 
    select_repores_date: function (component, event, helper) {
        helper.select_repores_date(component, event, helper);
    },
    export: function (component, event, helper) {
        console.log('进入export');
        var stockData = component.get("v.reports_date");
        console.log('查出的数据' + stockData);
    },
    close_import: function (component, event, helper) {
        component.set("v.showMain", true);
        helper.close_import(component);
    },
    close_export: function (component, event, helper) {
        component.set("v.showMain", true);
        helper.close_export(component);
    },
    select_ConsumptionOfConsumables: function (component, event, helper) {
        helper.select_ConsumptionOfConsumables(component, event, helper);
    },
    select_purpose_type: function (component, event, helper) {
        helper.selectPurposeType(component, event, helper);
    },
    select_warlocksNumber: function (component, event, helper) {
        helper.select_warlocksNumber(component, event, helper);
    },
    selectProductClassification: function (component, event, helper) {
        helper.selectProductClassification(component, event, helper);
    },
    selectpurposetype: function (component, event, helper) {
        helper.selectpurposetype(component, event, helper);
    },
    return_main_page: function (component, event, helper) {
        window.open('/customer/', '_self');
    },
    exportErrorInfo: function (component, event, helper) {
        helper.exportErrorInfoHelper(component);
    },
    closeErrorDiv: function (component, event, helper) {
        var errorDiv01 = component.find('errorDiv01');
        $A.util.addClass(errorDiv01, 'slds-hide');
    }
})