public with sharing class loanerArrangedEmailController {

	

    public loanerArrangedEmailController() {
    }

    @AuraEnabled
    public static InitData init(String recordId) {
    	String statusSting = Label.StatusProcessState;
		List<String> status = statusSting.split(',');
    	InitData res = new InitData();
    	try {
    	    Rental_Apply__c rac = [SELECT Id, Status__c, Campaign__c, RC_return_to_office__c, Repair_Final_Inspection_Date_F__c, Repair__c, Assigned_Not_Shipment__c, Demo_purpose1__c, Contract_pdf_updated__c, Wei_Assigned_Cnt__c from Rental_Apply__c where Id = :recordId];

    	    if( rac.Campaign__c != null ){
    	    	//获取学会对象
    	    	Campaign camp = [select Id, Status, Rental_Apply_Flag__c,IF_Approved__c,Approved_Status__c, Meeting_Approved_No__c from Campaign where id = :rac.Campaign__c];
    	    	res.CampaignId = camp.Id;
    	    	res.CampaignStatus = camp.Status;
    	    	res.IFApproved = camp.IF_Approved__c;
	    	    res.MeetingApprovedNo = camp.Meeting_Approved_No__c;
	    	    res.ApprovedStatus = camp.Approved_Status__c;
    	    }   
    	    res.Id = recordId;   
    	    res.RaStatus = rac.Status__c;
    	    res.WeiAssignedCnt = Integer.valueOf(rac.Wei_Assigned_Cnt__c);
    	    res.AssignedNotShipment = Integer.valueOf(rac.Assigned_Not_Shipment__c);
    	    res.DemoPurpose1 = rac.Demo_purpose1__c;
    	    res.ContractPdfUpdated = rac.Contract_pdf_updated__c;
    	    res.RepairId = rac.Repair__c;
    	    res.RepairFinalInspectionDateF = rac.Repair_Final_Inspection_Date_F__c;
    	    res.RCReturnToOffice = rac.RC_return_to_office__c;
    	    res.StatusList = status;
    	}
    	catch (Exception e) {
    	    System.debug(LoggingLevel.INFO, '****e:' + e);
    	}
    	system.debug('res======'+res);
    	return res;
    }

    
    //获取备品借出一栏
    @AuraEnabled
    public static Integer getRentalApplyEquipmentSet(String recordId) {
    	Rental_Apply__c tempRa = [SELECT Id, Bollow_Date__c from Rental_Apply__c where Id = :recordId];
    	List<Rental_Apply_Equipment_Set__c> tempRaEquipSetList = new List<Rental_Apply_Equipment_Set__c>();
    	Integer pageLength ;
    	if(tempRa.Bollow_Date__c != null) {
    		tempRaEquipSetList = [SELECT Id from Rental_Apply_Equipment_Set__c where Rental_Apply__c = :recordId AND Shippment_loaner_time__c != null and RAES_Status__c != '已分配' and RAES_Status__c != '取消分配'];
    	}else {
    		tempRaEquipSetList = [SELECT Id from Rental_Apply_Equipment_Set__c where Rental_Apply__c = :recordId AND RAES_Status__c != '已分配' and RAES_Status__c != '取消分配'];
    	}
    	//
    	if(tempRaEquipSetList.size()>0) {
			Integer setLength = tempRaEquipSetList.size();
			pageLength = Math.mod(setLength,10) == 0 ? setLength/10 : Math.round(setLength) + 1;
    	}
    	return pageLength;
    }

    public class InitData{
		@AuraEnabled
		public String Id;
		@AuraEnabled
		public String CampaignStatus;	//学会状态
		@AuraEnabled
		public String CampaignId;	//学会Id
		@AuraEnabled
		public String RaStatus;		//备品借出申请状态
		@AuraEnabled
		public Integer WeiAssignedCnt;		//未分配件数  Wei_Assigned_Cnt__c
		@AuraEnabled
		public Integer AssignedNotShipment;	//已分配未出库指示  Assigned_Not_Shipment__c
		@AuraEnabled
		public String DemoPurpose1;			//使用目的1	 Demo_purpose1__c
		@AuraEnabled
		public Boolean ContractPdfUpdated;	//合同书已上传	Contract_pdf_updated__c
		@AuraEnabled
		public String RepairId;				//学会.修理Id
		@AuraEnabled
		public Date RepairFinalInspectionDateF;		//修理最终检测日F  	Repair_Final_Inspection_Date_F__c
		@AuraEnabled
		public Date RCReturnToOffice;		//RC修理品返送日		RC_return_to_office__c
		@AuraEnabled
		public Boolean IFApproved;			//学会.是否需要申请决裁
		@AuraEnabled
		public String MeetingApprovedNo;	//学会.会议决裁编码
		@AuraEnabled
		public String ApprovedStatus;		//学会.决裁状态	Approved_Status__c
		@AuraEnabled
		public List<String> StatusList;
	}
}