public without sharing class StatusPageController {
    public StatusPageController() {
        Inquiryform = new Inquiry_form__c();
    }
    public Inquiry_form__c Inquiryform{get; set;}

    public void init(){

        String infId = ApexPages.currentPage().getParameters().get('id');
        //2022-5-6 yjk SWAG-CBUB2W 增加查询项
      List<Inquiry_form__c> infList = [SELECT id,Reasons_options__c,Opp_Name_Search__c,Opp_Name__c,Hospital__c,Hospital_Name__c,Hospital_ID__c,Follow_Content__c,Follow_Content_Other__c,Status__c,Service_Follow_Content__c,Service_Follow_Content_Other__c,Service_Status__c,Redistribution__c,GotoDepartment__c,Product_Owner__c,Transfer_Service_Follow_Content__c,Transfer_Service_Follow_Date__c FROM Inquiry_form__c WHERE id =  :infId];
      if (infList.size() == 0) {
        
      }else{
            Inquiryform = infList[0];
      }
    }
    //不需要
    public void save(){

        try{
            
            if (String.isBlank(Inquiryform.Reasons_options__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '不需要理由不能为空'));
                return;
            }
            //2022-5-5 yjk SWAG-CBUB2W start
            /*if (Inquiryform.Reasons_options__c == '已经有询价' && String.isBlank(Inquiryform.Opp_Name__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '已有询价名称不能为空'));
                return;
            }
            if(!String.isBlank(Inquiryform.Opp_Name__c)){
                List<Opportunity> OPPList = [select id from Opportunity where name = :Inquiryform.Opp_Name__c and Hospital__c = :Inquiryform.Hospital__c];
                if(OPPList == NULL || OPPList.size() == 0){
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '请选择正确的询价信息'));
                    return;
                }else{
                    Inquiryform.Opp_Name_Search__c = OPPList.get(0).id;
                }
            }*/
            
            if (Inquiryform.Reasons_options__c == '已经有询价' && String.isBlank(Inquiryform.Opp_Name_Search__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '已有询价名称不能为空'));
                return;
            }


            //2022-5-5 yjk SWAG-CBUB2W end
            Inquiryform.Status__c = '02.不需要';

            update Inquiryform;

        }catch (Exception ex){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()));
        }
    }
    //营业跟进
    public void savefo(){
        try {
            //20220606 LLIU-CEGCRB you start
            /**
            if (String.isBlank(Inquiryform.Follow_Content__c) && String.isBlank(Inquiryform.Follow_Content_Other__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '跟进内容不能为空'));
            }
            if (String.isBlank(Inquiryform.Follow_Content__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '跟进内容不能为空'));
            }
            **/
            /**20220703 you DB202306544691 start 
            if(false != Inquiryform.Redistribution__c && String.isBlank(Inquiryform.GotoDepartment__c)){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '勾选时必须填写转至科室'));
            }
            if(false == Inquiryform.Redistribution__c && String.isNotBlank(Inquiryform.GotoDepartment__c)){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '未勾选时不能填写转至科室'));
            } 
            20220703 you DB202306544691 end
            **/
            //20220606 LLIU-CEGCRB you end
            if ('其他'.equals(Inquiryform.Follow_Content__c) && String.isBlank(Inquiryform.Follow_Content_Other__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '跟进内容（其他）不能为空'));
            }
            // Date nowDT = Date.now();
            /**20220703 you DB202306544691 start 
            //20220418 you SWAG-CBUB2W start LLIU-CGK3D2
            if(String.isNotBlank(Inquiryform.Follow_Content__c) && (Inquiryform.Follow_Content__c.indexOf('仅需服务对应')!=-1 || Inquiryform.Follow_Content__c.indexOf('营业服务共同对应')!=-1)){
               Inquiryform.ServiceCorrespond__c = true;
               //Inquiryform.Service_Status__c = '01.未跟进'; 放到trigger中处理，因为原本要是已跟进得话就不动

            }else{
                Inquiryform.ServiceCorrespond__c = false;
                //Inquiryform.Service_Status__c = '';
            }
            20220703 you DB202306544691 end 
            **/
            if(String.isNotBlank(Inquiryform.Follow_Content__c) ){
               /** 20220703 you DB202306544691 start 
                if(Inquiryform.Follow_Content__c =='仅需服务对应'){
                  Inquiryform.Status__c = '02.不需要';               
                }else{
                **/
                  Inquiryform.Follow_Date__c = Date.toDay();
                  Inquiryform.Status__c = '03.已跟进'; 
                /**}20220703 you DB202306544691 end **/
            }
            //20220418 you SWAG-CBUB2W end
            update Inquiryform;
        }
        catch (Exception ex) {
            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()));
        }
    }
    //20220418 you SWAG-CBUB2W start 服务跟进
    public void servicesavefo(){
        try {
            if (String.isBlank(Inquiryform.Service_Follow_Content__c) && String.isBlank(Inquiryform.Service_Follow_Content_Other__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '服务跟进内容不能为空'));
            }
            if (String.isBlank(Inquiryform.Service_Follow_Content__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '服务跟进内容不能为空'));
            }
            if ('其他'.equals(Inquiryform.Service_Follow_Content__c) && String.isBlank(Inquiryform.Service_Follow_Content_Other__c)) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '服务跟进内容（其他）不能为空'));
            }
            // Date nowDT = Date.now();
            Inquiryform.Service_Follow_Date__c = Date.toDay();
            Inquiryform.Service_Status__c = '03.已跟进';
            update Inquiryform;
        }
        catch (Exception ex) {
            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()));
        }
    }
    //20220418 you SWAG-CBUB2W end
    
    //20220703 you DB202306544691 start 
    //转服务
    public void TransferServicesavefo(){
        try {
            if(String.isNotBlank(Inquiryform.Transfer_Service_Follow_Content__c) && (Inquiryform.Transfer_Service_Follow_Content__c.indexOf('仅需服务对应')!=-1 || Inquiryform.Transfer_Service_Follow_Content__c.indexOf('营业服务共同对应')!=-1)){
               Inquiryform.ServiceCorrespond__c = true;
               //Inquiryform.Service_Status__c = '01.未跟进'; 放到trigger中处理，因为原本要是已跟进得话就不动

            }else{
                Inquiryform.ServiceCorrespond__c = false;
                //Inquiryform.Service_Status__c = '';
            }
            
            if(String.isNotBlank(Inquiryform.Transfer_Service_Follow_Content__c) ){
                if(Inquiryform.Transfer_Service_Follow_Content__c =='仅需服务对应'){
                  Inquiryform.Status__c = '02.不需要';               
                }else{
                  Inquiryform.Transfer_Service_Follow_Date__c = Date.toDay();
                  Inquiryform.Status__c = '03.已跟进'; 
                }
            }
            //20220418 you SWAG-CBUB2W end
            update Inquiryform;
        }
        catch (Exception ex) {
            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()));
        }
    }
    //转科室
     public void TransferDepartmentsavefo(){
        try {

            if(false != Inquiryform.Redistribution__c && String.isBlank(Inquiryform.GotoDepartment__c)){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '勾选时必须填写转至科室'));
            }
            if(false == Inquiryform.Redistribution__c && String.isNotBlank(Inquiryform.GotoDepartment__c)){
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '未勾选时不能填写转至科室'));
            } 
           
            update Inquiryform;
        }
        catch (Exception ex) {
            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ex.getMessage()));
        }
    }
    //20220703 you DB202306544691 end 
}