buli
2023-07-11 80a3f59e2d3df07805bc67e329300b8de90a5b3a
force-app/main/default/aura/WeeklyReport/WeeklyReportController.js
@@ -1,11 +1,12 @@
({
    doInit : function(component, event, helper) {
        console.log('zhj 新方案');
        if (window.location.href.endsWith("weekly-report")) {
        console.log('zhj 新方案weeklyReport');
        if (window.location.href.endsWith('weekly-report')) {
            helper.doinit(component, event, helper);
        } else {
            helper.hideCmp(component, event, helper);
        }
        component.set('v.showErrorInfo', false);
    },
    createAopp : function(component, event, helper) {
@@ -15,10 +16,12 @@
            recordTypeId: '012100000006KW7'
        });
        addRecordEvent.fire();
        component.set('v.showErrorInfo', false);
    },
    
    new_report : function(component, event, helper) {
        component.find('save_button').set('v.label', '保存并新建');
        component.set('v.data.Report_Date__c', '');
        helper.new_report(component, event, helper);
    },
    
@@ -41,8 +44,8 @@
    },
    showRequiredFields: function(component, event, helper){
        $A.util.removeClass(component.find("newOpportunityField"), "none");
        $A.util.removeClass(component.find("newOpportunityField"), "none");
        $A.util.removeClass(component.find('newOpportunityField'), 'none');
        $A.util.removeClass(component.find('newOpportunityField'), 'none');
    },
    
    handleSuccess : function(component, event, helper) {
@@ -60,7 +63,7 @@
        // vivek 添加验证 start
        // helper.handleFormSubmit(component);
        var showValidationError = false;
        var fields = component.find("newOpportunityField");
        var fields = component.find('newOpportunityField');
        var vaildationFailReason = '';
        // var vaildationFailReason2 = '';
        // var currentDate = new Date().toJSON().slice(0,10);
@@ -70,25 +73,30 @@
        // PIPL update Yin Mingjie 21/02/2022 end
        fields.forEach(function (field) {
            if(field.get("v.fieldName") === 'Type__c' && $A.util.isEmpty(field.get("v.value"))){
            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"))){
                vaildationFailReason = '分类不能为空!';
            } else if (
                field.get('v.fieldName') === 'Doctor_Division1__c' &&
                $A.util.isEmpty(field.get('v.value'))
            ) {
                showValidationError = true;
                if(vaildationFailReason != ''){
                    vaildationFailReason += "医生区分(职务)不能为空!";
                    vaildationFailReason += '医生区分(职务)不能为空!';
                }else{
                    vaildationFailReason = "医生区分(职务)不能为空!";
                    vaildationFailReason = '医生区分(职务)不能为空!';
                }
            }
            // PIPL update Yin Mingjie 21/02/2022 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");
            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');
            }
            // PIPL update Yin Mingjie 21/02/2022 end
        });
@@ -103,26 +111,39 @@
            var agencyHospitalid = component.get('v.hospitalLinkId');
            //zhj MEBG新方案改造 2022-11-29 start
            debugger
            debugger;
            let hospitalName = '';
            //调用后端searchAgencyDataId方法查询出医院下面所有客户人员dataid
            helper.CallBackAction(component,'searchAgencyDataId',{
            helper.CallBackAction(
                component,
                'searchAgencyDataId',
                {
                hospitalId : agencyHospitalid
            },function(data){
                if(data.getState() == "SUCCESS"){
                },
                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;
                            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 +=
                                            ',' + data.Data[i].AWS_Data_Id__c;
                            }
                            agencyContactIds = agencyContactIds.substring(1);
                            agencyReport['agencyContactIds'] = agencyContactIds;
                                agencyContactIds =
                                    agencyContactIds.substring(1);
                                agencyReport['agencyContactIds'] =
                                    agencyContactIds;
                        }else{
                            agencyReport['agencyContactIds'] = agencyContactIds;
                                agencyReport['agencyContactIds'] =
                                    agencyContactIds;
                        }
                        var arr = new Array();
                        arr.push(agencyReport);
@@ -132,21 +153,30 @@
                        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);
                            component.set('v.loginEdit', true);
                            helper.insert_agencycontact(
                                component,
                                token,
                                newUrl,
                                requestData,
                                agencyHospitalid,
                                helper,
                                hospitalName
                            );
                    }else{
                        helper.ShowToast({
                            "message" : data.message,
                            "type" : "error"
                                message: data.message,
                                type: 'error'
                        });
                    }
                }else{
                    helper.ShowToast({
                        "message" : 'searchAgency失败',
                        "type" : "error"
                            message: 'searchAgency失败',
                            type: 'error'
                    });
                }
            })
                }
            );
            //zhj MEBG新方案改造 2022-11-29 end
            // var arr = new Array();
            // arr.push(agencyReport);
@@ -175,12 +205,20 @@
    
    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'));
        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'));
        helper.close_confirm(
            component,
            component.get('v.modal_confirm_title'),
            component.get('v.modal_confirm_text')
        );
    },
    
    toggle_report : function(component, event, helper) {
@@ -200,7 +238,7 @@
    },
    
    hosChange : function(component, event, helper) {
      var hospital_name = event.getParam("value");
        var hospital_name = event.getParam('value');
      if (hospital_name.match(/(\S+\s)+/)) {
         helper.searchHos(component, event, helper);
      } else {
@@ -252,18 +290,20 @@
        helper.readFile(component,helper,files[0]);
    },
    CreateRecord : function(component, event, helper){
        var files = event.getSource().get("v.files");
        var files = event.getSource().get('v.files');
        // var fileInput = component.find("file").getElement();
        // var file = fileInput.files[0];
        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);
        component.set('v.showMain', true);
    },
    import : function(component,event,helper){
@@ -272,21 +312,23 @@
        helper.showImport(component);
    },
    exportDate : function(component,event,helper){
        var stockData = component.get("v.reports_date");
        var stockData = component.get('v.reports_date');
        console.log('导出数据'+stockData); 
        var csv = helper.convertArrayOfObjectsToCSV(component,stockData);
        if (csv == null){return;}
        if (csv == null) {
            return;
        }
        // ####--code for create a temp. <a> html tag [link tag] for download the CSV file--####     
        var universalBOM = "\uFEFF";
        var universalBOM = '\uFEFF';
        var hiddenElement = document.createElement('a');
        hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(universalBOM+csv);
        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
        // helper.showExport(component);
    },
    export_condition : function(component,event,helper){
@@ -302,17 +344,20 @@
    },
    export : function(component,event,helper){
        console.log('进入export');
        var stockData = component.get("v.reports_date");
        var stockData = component.get('v.reports_date');
        console.log('查出的数据'+stockData);
        // helper.showExportDate(component,stockData);
        // helper.showExport(component);
    },
    close_import : function(component,event,helper){
        component.set("v.showMain",true);
        component.set('v.showMain', true);
        helper.close_import(component);
    },
    close_export : function(component,event,helper){
        component.set("v.showMain",true);
        component.set('v.showMain', true);
        helper.close_export(component);
    },
    exportErrorInfo: function (component, event, helper) {
        helper.exportErrorInfoHelper(component);
    }
})
});