沙世明
2022-03-12 0593d044698afa73e7e58022dab190ead1925f3a
force-app/main/default/aura/WeeklyReport/WeeklyReportHelper.js
@@ -1,7 +1,6 @@
({
    doinit : function(component, event, helper) {
        this.report_date_list(component, event, helper, 5);
        component.set('v.login',true);
        var action = component.get('c.getalldata');
        action.setCallback(this,function(response){
@@ -12,7 +11,10 @@
                component.set('v.fieldsmap',res.fieldsMap);
                component.set('v.allselectlist',res.allselectlist);
                component.set('v.doclist',res.doclist);
                component.find('select_agency_person').set('v.options', this.conv_selected(res.allselectlist.AgencyPerson__c));
                // PIPL update Yin Mingjie 21/02/2022 start
                // component.find('select_agency_person').set('v.options', this.conv_selected(res.allselectlist.AgencyPerson__c));
                this.search_contact(component, event, helper,res.allselectlist.AgencyPerson__c);
                // PIPL update Yin Mingjie 21/02/2022 end
                component.find('select_department').set('v.options', this.conv_selected(res.allselectlist.Department_Cateogy__c));
                component.find('select_purpose_type').set('v.options', this.conv_selected(res.allselectlist.Purpose_Type__c));
                component.find('select_result').set('v.options', this.conv_selected(res.allselectlist.Result__c));
@@ -23,6 +25,7 @@
                component.set('v.selected_agency_person', res.allselectlist.AgencyPerson__c[0].label);
                component.set('v.dialog_type', '新建');
                component.set('v.awsurl', res.awsurl);// 20220222 PI改造 by Bright
                component.set('v.contactawsurl', res.contactawsurl);// 20220222 PI改造 by Bright
                
                this.get_reports(component, event, helper, component.find('select_date').get('v.value'), component.find('select_agency_person').get('v.value'));
            
@@ -35,6 +38,76 @@
        });
        $A.enqueueAction(action);
    },
    // PIPL update Yin Mingjie 21/02/2022 start
    search_contact : function(component, event, helper, resobj) {
        let contactData = Object.create(null);
        var dataArr = new Array();
        for (let i = 0; i < resobj.length; i++) {
            if (resobj[i].awsid != null && resobj[i].awsid != ''){
                contactData[resobj[i].awsid] = resobj[i];
                dataArr.push(resobj[i].awsid);
            }
        }
        let obj= Object.create(null);
        obj['dataIds'] = dataArr;
        var payload = JSON.stringify(obj);
        this.search_contact_url(component, 'Contact', (result)=>{
            var token = result.token;
            var searchUrl = result.searchUrl;
            this.search_core(token,searchUrl,payload,(result)=>{
                if(result.status == '0'){
                    this.to_contact_list(result,contactData,component);
                }else{
                    this.error('AWS search status : ' + result.status);
                    component.set('v.login',false);
                }
            },component);
        });
    },
    to_contact_list : function(result,retMap,component) {
        var resls = result.object;
        var res = [];
        var space = {};
        space['label'] = '';
        space['selected'] = true;
        space['value'] = '';
        res.push(space);
        for (var i = 0; i < resls.length; i++) {
            var t = {};
            t['label'] = resls[i].lastName;
            t['selected'] = false;
            t['Doctor_Division1__c'] = resls[i].doctorDivision1;
            t['value'] = retMap[resls[i].dataId].value;
            res.push(t);
        }
        component.find('select_agency_person').set('v.options',res);
        component.set('v.allselectlistAgencyPerson',res);
        component.set('v.login',false);
    },
    search_contact_url : function(component, sobject, callback) {
        var action = component.get('c.getAwsurl');
        action.setParams({
            "sobj" : sobject,
        });
        action.setCallback(this,function(response){
            var state = response.getState();
            if(state == 'SUCCESS'){
                var result = response.getReturnValue();
                if(callback)callback(result);
            }
            else{
                this.error('AWS url/token error.');
                component.set('v.login',false);
            }
        });
        $A.enqueueAction(action);
    },
    // PIPL update Yin Mingjie 21/02/2022 end
    select_department : function(component, event, helper) {
        var dc = component.find("select_department").get("v.value");
@@ -99,32 +172,78 @@
                
                // 20220222 PI改造 by Bright--start
                let dataIds = [];
                let dataIds1 = [];
                let mm = {};
                let b = false;
                let b1 = false;
                for (const rep of res.reports) {
                    if (rep.doctor2__r && rep.doctor2__r.AWS_Data_Id__c) {
                        dataIds.push(rep.doctor2__r.AWS_Data_Id__c);
                    }
                    if (rep.Person_In_Charge2__r && rep.Person_In_Charge2__r.AWS_Data_Id__c) {
                        dataIds1.push(rep.Person_In_Charge2__r.AWS_Data_Id__c);
                    }
                }
                let Foo = null;
                Foo = function(){
                    if(b && b1){
                        for (const rep of res.reports) {
                            if (rep.doctor2__r && rep.doctor2__r.AWS_Data_Id__c && mm.hasOwnProperty(rep.doctor2__r.AWS_Data_Id__c)) {
                                rep.doctor2__r.awsdata = mm[rep.doctor2__r.AWS_Data_Id__c];
                            }
                            if (rep.Person_In_Charge2__r && rep.Person_In_Charge2__r.AWS_Data_Id__c && mm.hasOwnProperty(rep.Person_In_Charge2__r.AWS_Data_Id__c)) {
                                rep.Person_In_Charge2__r.awsdata = mm[rep.Person_In_Charge2__r.AWS_Data_Id__c];
                            }
                        }
                        $A.getCallback(()=>component.set('v.reports', res.reports))();
                    }else{
                        console.log('b='+b + ',b1='+b1+',continue');
                        setTimeout(Foo,100);
                    }
                }
                
                if(dataIds.length > 0){
                    let awsurl = component.get('v.awsurl');
                    helper.search_agency_contact_core(awsurl.token,awsurl.searchUrl,JSON.stringify({
                    helper.search_core(awsurl.token,awsurl.searchUrl,JSON.stringify({
                        "dataIds":dataIds
                    }),(result)=>{
                        if(result.status == '0'){
                            let mm = {};
                            for (const m of result.object) {
                                mm[m.dataId] = m;
                            }
                            for (const rep of res.reports) {
                                if (rep.doctor2__r && rep.doctor2__r.AWS_Data_Id__c && mm.hasOwnProperty(rep.doctor2__r.AWS_Data_Id__c)) {
                                    rep.doctor2__r.awsdata = mm[rep.doctor2__r.AWS_Data_Id__c];
                                }
                            }
                            component.set('v.reports', res.reports);
                            b = true;
                            Foo();
                        }else{
                            this.error('AWS search status : ' + result.status);
                        }
                    },component);
                }else{
                    b = true;
                }
                if(dataIds1.length > 0){
                    let contactawsurl = component.get('v.contactawsurl');
                    helper.search_core(contactawsurl.token,contactawsurl.searchUrl,JSON.stringify({
                        "dataIds":dataIds1
                    }),(result)=>{
                        if(result.status == '0'){
                            for (const m of result.object) {
                                mm[m.dataId] = m;
                            }
                            b1 = true;
                            Foo();
                        }else{
                            this.error('AWS search status : ' + result.status);
                        }
                    },component);
                }else{
                    b1 = true;
                }
                // 20220222 PI改造 by Bright--end
@@ -179,7 +298,10 @@
    },
    
    get_agency_person_name : function(component, agency_person_value) {
        var allselectlist = component.get('v.allselectlist.AgencyPerson__c');
        // PIPL update Yin Mingjie 21/02/2022 start
        // var allselectlist = component.get('v.allselectlist.AgencyPerson__c');
        var allselectlist = component.get('v.allselectlistAgencyPerson');
        // PIPL update Yin Mingjie 21/02/2022 end
        var new_label = '';
        for (var i = 0; i < allselectlist.length; i++) {
            if (agency_person_value == allselectlist[i].value) {
@@ -456,7 +578,7 @@
        var name = component.get('v.selected_agency_person');
        var ret = this.create_report_header(component, name, select_agency, select_date);
        // PIPL update Yin Mingjie 21/02/2022 start
        this.set_aws_url(component)
        this.set_aws_url(component,'Agency_Contact__c')
        // PIPL update Yin Mingjie 21/02/2022 end
    },
    
@@ -1066,10 +1188,10 @@
        }
    },
    // PIPL update Yin Mingjie 21/02/2022 start
    set_aws_url : function(component) {
    set_aws_url : function(component,sobject) {
        var action = component.get('c.getAwsurl');
        action.setParams({
            "sobj" : "Agency_Contact__c",
            "sobj" : sobject,
        });
        action.setCallback(this,function(response){
            var state = response.getState();
@@ -1077,6 +1199,7 @@
                var awsmap = this.conv_selected(response.getReturnValue());
                component.set('v.AWStoken',awsmap.token);
                component.set('v.AWSinsert',awsmap.newUrl);
                component.set('v.AWSsearch',awsmap.searchUrl);
                component.set('v.AWStransactionURL',awsmap.transactionURL);
            }
            else{
@@ -1256,7 +1379,7 @@
    },
    search_agency_contact : function(token,searchUrl,payload,retMap,component) {
        this.search_agency_contact_core(token,searchUrl,payload,(result)=>{
        this.search_core(token,searchUrl,payload,(result)=>{
            if(result.status == '0'){
                this.to_doctor_list(result,retMap,component);
            }else{
@@ -1280,7 +1403,7 @@
        //     component.set('v.login',false);
        // });
    },
    search_agency_contact_core : function(token,searchUrl,payload,callback,component) {
    search_core : function(token,searchUrl,payload,callback,component) {
        fetch(searchUrl, {
            method: 'POST',
            body: payload,