public class AgencyConfirmPageController {
    public  eSignForm__c eSignForm { get; set; }
    public boolean disableInput{get;set;}

    public AgencyConfirmPageController(ApexPages.StandardController controller) {
    }
    public AgencyConfirmPageController(){
        
    }
    public void init(){
        String paramId = ApexPages.currentPage().getParameters().get('id');
        list<eSignForm__c> ESignFormList = [Select id,agencyAutoSignUpStatus__c, 
                                            AccessoriesQualified__c ,handleOpinionAgency__c, 
                                            agencySignUpDate__c, denyReason__c ,
                                            HPSignUpStatus__c,
                                            agencyAcceptResult__c
                                            from eSignForm__c
                                            where Id = :paramId];
        if( ESignFormList.size() == 0){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '找不到对应的签收单！'));
            return;
        }
        eSignForm = ESignFormList[0];
        if(eSignForm.agencyAutoSignUpStatus__c!= null && eSignForm.agencyAutoSignUpStatus__c.equals('申请中')){
           disableInput = false; 
        }else{
            disableInput = true;
        }
        return;
    }
    public PageReference confirm() {
        if(eSignForm.AccessoriesQualified__c){
            if(eSignForm.agencyAcceptResult__c.equals('全部验收')
              || string.isNotBlank(eSignForm.handleOpinionAgency__c)){
            eSignForm.agencyAutoSignUpStatus__c = '已批准';
            }else{
                 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '在验收结果不是全部验收时，请您先填写处理意见！'));
                return null;
            }
        }else if(string.isBlank(eSignForm.denyReason__c)){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '经销商验收附件不合格，请您填写驳回理由！'));
            return null;
        }else{
            eSignForm.agencyAutoSignUpStatus__c = '不批准';
        }
        try{
            update eSignForm;
            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM, '确认完毕！'));
            disableInput = true;
        }catch(exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));

        }
        return null;
    }

}