//
//  InsuredInfoController.m
//  Open
//
//  Created by 雷俊博 on 2019/12/18.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "InsuredInfoController.h"
#import "Constants.h"
#import "UIView+frameAdjust.h"
#import "InsuredInfoController.h"
#import "InsuredInfoTopCell.h"
#import "InsuredItemCell.h"
#import "InsuredItem2Cell.h"
#import "InsuredItem3Cell.h"
#import "InsuredItem4Cell.h"
#import "InsuredItem5Cell.h"
#import "InsuredItem6Cell.h"
#import "SelectMonthViewController.h"
#import "CZQAddressPicker.h"
#import "CityTypeSelectView.h"
#import "Tools.h"

@interface InsuredInfoController ()<InsuredInfoTopCellDelegate,MySwitchDelegate,UIScrollViewDelegate,UITextFieldDelegate,UIScrollViewDelegate>
{
    BOOL BuyInsurance;
    BOOL BuyFund;
    
    UILabel* lb_startDate;
    UILabel* lb_endDate;
    UILabel* lb_city;
    UILabel* lb_cityType;
    UILabel* lb_num;
    UILabel*lb_cardType;
    UITextField* tf_wage;
    UILabel *lb_wage;
    UILabel *lb_fund;
    UILabel *lb_sb;
    UILabel *lb_p;
    UILabel *lb_e;
    UILabel *lb_serviceCharge;
    UILabel *lb_total;
    
    //单月社保费用
    double shebao_fee;//社保费用
    //单月公积金费用
    double fund_fee;//公积金费用
    
    //总计社保费用
    double allshebao_fee;
    //总计公积金费用
    double allfund_fee;
    //总的服务费用
    NSString* allservice_fee;
    
    
    //开始月份
    NSInteger startMonth;
    int mNums;//月份数
    
    NSString*startDateStr;
    NSString*endDateStr;
    NSString*mNum;
    NSString* city;
    NSString* Mhukou;
    
    //是否办卡
    BOOL haveCard;
    NSString*sb_cardType;
    
    //是否第一次购买社保
    BOOL first_sb;
    //是否第一次购买公积金
    BOOL first_fund;
    
    wxyjModel* WWModel;
    FundCityDataItem* fundItem;
    
    //记录同时购买公积金,服务费可省多少
    double save_sbfund;
    
    
    
    CGFloat currentMaxY;
    CGFloat current2MaxY;
    
    
    UIView* chargeCardView;
    UIView* section2View;
    InsuredItemCell*fundTopView;
    InsuredItemCell*fund2View;
    InsuredItem5Cell*fund3View;
    InsuredItem6Cell*fund4View;
    InsuredItem2Cell*fund5View;
    
    
}


@property (nonatomic, strong)UIScrollView *scrollView;

@property (nonatomic, strong)UIView* serviceMoneyView;


@end

@implementation InsuredInfoController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [GTCountSDK trackCountEvent:@"home_shebaojiaofei_canbaoxinxi" withArgs:@{}];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
     BuyFund = NO;
    
    
    wxyjModel* wModel = self.wModel;
       
       for (ShebaoCityDataItem* item in wModel.shebaos) {
           if (item.hukou_type == self.hukou_type.intValue) {
               
               for (ShebaoNamePrice* price in item.Data) {
                   shebao_fee = shebao_fee + price.p;
               }
               break;
           }
       }
      
      
    
    
    for (FundCityDataItem* item in wModel.funds) {
        if (item.hukou_type == self.hukou_type.intValue) {
            fundItem = item;
            break;
        }
    }
    
    
    WWModel = wModel;
    haveCard = NO;
    sb_cardType = @"不办卡";

    save_sbfund = wModel.fund_charge + wModel.shebao_charge - wModel.package_charge;
    
    
    NSLog(@"社保费用%.2f",shebao_fee * WWModel.nums);
       
    allshebao_fee = [NSString stringWithFormat:@"%.2f",shebao_fee * WWModel.nums].doubleValue;
   
   
   
    startMonth = WWModel.month;
    NSString*months = [NSString stringWithFormat:@"%d",wModel.month];
    
    int year = [months substringToIndex:4].intValue;
    int month = [months substringFromIndex:5].intValue;
    int nums = wModel.nums;
    int monthTotal =  month + nums - 1;
    int remainder = monthTotal % 12;
    int q = monthTotal/12;
    startDateStr = [NSString stringWithFormat:@"%d年%d月",year,month];
    endDateStr = [NSString stringWithFormat:@"%d年%d月",year + q,remainder];
   
    mNum = [NSString stringWithFormat:@"%d个月",nums];
    mNums = nums;
    
    city = self.selectCityName;
    Mhukou = self.hukou;
    
    
    
    [self.view addSubview:self.scrollView];
    [self creatServiceView];
     currentMaxY = [self creatTopView:164.5];
    currentMaxY = [self creatInsuredItemCell:45];
    currentMaxY = [self creatInsuredItem2Cell:45];
    currentMaxY = [self creatInsuredItem3Cell:45];
    currentMaxY = [self creatInsuredItem4Cell:0];
    [self creatSection2View];
    current2MaxY = [self creatInsuredItem5Cell:38];
    current2MaxY = [self creatInsuredItem6Cell:45];
    current2MaxY = [self creatInsuredItem7Cell:45];
    current2MaxY = [self creatInsuredItem8Cell:45];
    current2MaxY = [self creatInsuredItem9Cell:98];
    current2MaxY = [self creatInsuredItem10Cell:45];
    [self hiddenFundView];
}

- (void)dealloc
{
    NSLog(@"InsuredInfoController销毁了");

}

//topView
- (CGFloat)creatTopView:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"InsuredInfoTopCell" owner:self options:nil];
    InsuredInfoTopCell* cell = [Bundle objectAtIndex:0];
    
    
    cell.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    
    cell.delegate = self;
    
    [self.scrollView addSubview:cell];
    
    lb_startDate = cell.lb_startDate;
    lb_endDate = cell.lb_endDate;
    lb_city = cell.lb_city;
    lb_cityType = cell.lb_type;
    lb_num = cell.lb_monthNum;
    
    cell.lb_startDate.text = startDateStr;
    cell.lb_endDate.text = endDateStr;
    cell.lb_monthNum.text = mNum;
    lb_city.text = city;
    lb_cityType.text = Mhukou;
    
    return cell.maxY;
}

//InsuredItemCell
- (CGFloat)creatInsuredItemCell:(CGFloat)height
{
    
    InsuredItemCell* cell = [[InsuredItemCell alloc]init];
    cell.backgroundColor = [UIColor whiteColor];
    
    cell.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    
    [self.scrollView addSubview:cell];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb_title.text = @"本城市首次参保";
    cell.cuSwitch.tag = 200;
    cell.cuSwitch.delegate = self;
    cell.line.hidden = NO;
    return cell.maxY;
}

- (CGFloat)creatInsuredItem2Cell:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"InsuredItem2Cell" owner:self options:nil];
    InsuredItem2Cell* cell = [Bundle objectAtIndex:0];
    cell.backgroundColor = [UIColor whiteColor];
    cell.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    [self.scrollView addSubview:cell];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb_title.text = @"社保费用";
    
    if (WWModel.nums == 1) {
        cell.lb_content.text = [NSString stringWithFormat:@"¥%.2f/月",shebao_fee * WWModel.nums];
    }else{
        cell.lb_content.text = [NSString stringWithFormat:@"¥%.2f(共%d月)",shebao_fee * WWModel.nums, WWModel.nums];
    }
    
    
    
    lb_sb = cell.lb_content;
    
    return cell.maxY;
}

- (CGFloat)creatInsuredItem3Cell:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"InsuredItem3Cell" owner:self options:nil];
    InsuredItem3Cell* cell = [Bundle objectAtIndex:0];
    cell.backgroundColor = [UIColor whiteColor];
    cell.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    
     [self.scrollView addSubview:cell];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb_content.text = sb_cardType;
    
    lb_cardType = cell.lb_content;
    
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selctCardClick:)];
    
    [cell addGestureRecognizer:tap];
    
    return cell.maxY;
}
- (CGFloat)creatInsuredItem4Cell:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"InsuredItem4Cell" owner:self options:nil];
    InsuredItem4Cell* cell = [Bundle objectAtIndex:0];
    cell.backgroundColor = [UIColor whiteColor];
    cell.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    [self.scrollView addSubview:cell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
               
    NSDecimalNumber *decNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",WWModel.shebao_card_charge]];
    cell.lb_money.text = [NSString stringWithFormat:@"¥%@",decNumber.stringValue];
    
    chargeCardView = cell;
    
    return cell.maxY;
}

- (void)creatSection2View
{
    section2View = [[UIView alloc]initWithFrame:CGRectMake(0, currentMaxY, ScreenWidth, 315)];
    section2View.backgroundColor = [UIColor redColor];
    [self.scrollView addSubview:section2View];
}

- (CGFloat)creatInsuredItem5Cell:(CGFloat)height
{
    UIView* headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, height)];
    [section2View addSubview:headerView];
    headerView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    UILabel* lb_title = [[UILabel alloc]init];
     NSDecimalNumber *decNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",save_sbfund]];
    lb_title.text = [NSString stringWithFormat:@"同时购买公积金，公积金服务费立减%@元/月",decNumber.stringValue];
    lb_title.textColor = [UIColor colorWithHex:0x808080];
    lb_title.font = [UIFont systemFontOfSize:13];
    [headerView addSubview:lb_title];
    
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(15);
        make.left.offset(20);
        make.height.offset(13);
    }];
    
    return headerView.maxY;
}

- (CGFloat)creatInsuredItem6Cell:(CGFloat)height
{
    InsuredItemCell* cell = [[InsuredItemCell alloc]init];
    cell.backgroundColor = [UIColor whiteColor];
    cell.frame = CGRectMake(0, current2MaxY, ScreenWidth, height);
    [section2View addSubview:cell];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb_title.text = @"是否购买公积金";
    cell.cuSwitch.tag = 201;
    cell.cuSwitch.delegate = self;
               
    cell.line.hidden = BuyFund != YES;
    
    fundTopView = cell;
               
    return cell.maxY;
}
- (CGFloat)creatInsuredItem7Cell:(CGFloat)height
{
    InsuredItemCell* cell = [[InsuredItemCell alloc]init];
    fund2View = cell;
    cell.backgroundColor = [UIColor whiteColor];
    cell.frame = CGRectMake(0, current2MaxY, ScreenWidth, height);
    [section2View addSubview:cell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb_title.text = @"本城市首次缴纳公积金";
    cell.cuSwitch.delegate = self;
    cell.cuSwitch.tag = 202;
    cell.line.hidden = NO;
    
    
    return cell.maxY;
}
- (CGFloat)creatInsuredItem8Cell:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"InsuredItem5Cell" owner:self options:nil];
    InsuredItem5Cell* cell = [Bundle objectAtIndex:0];
    cell.backgroundColor = [UIColor whiteColor];
    cell.frame = CGRectMake(0, current2MaxY, ScreenWidth, height);
    [section2View addSubview:cell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
     NSDecimalNumber *minNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",fundItem.min]];
     NSDecimalNumber *maxNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",fundItem.max]];
    cell.tf_fundMoney.placeholder = [NSString stringWithFormat:@"%@元~%@元",minNumber.stringValue,maxNumber.stringValue];
    tf_wage = cell.tf_fundMoney;
    tf_wage.delegate = self;
    [tf_wage addTarget:self action:@selector(textFieldTextChange:) forControlEvents:UIControlEventEditingChanged];
    fund3View = cell;
    return cell.maxY;
}

- (CGFloat)creatInsuredItem9Cell:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"InsuredItem6Cell" owner:self options:nil];
    InsuredItem6Cell* cell = [Bundle objectAtIndex:0];
   cell.backgroundColor = [UIColor whiteColor];
   cell.frame = CGRectMake(0, current2MaxY, ScreenWidth, height);
    [section2View addSubview:cell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    lb_wage = cell.lb_wages;
    NSDecimalNumber *pNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",fundItem.p]];
    NSDecimalNumber *eNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",fundItem.e]];
    cell.lb_person.text = [NSString stringWithFormat:@"%@%%",pNumber.stringValue];
    cell.lb_company.text = [NSString stringWithFormat:@"%@%%",eNumber.stringValue];
    lb_p = cell.lb_person;
    lb_e = cell.lb_company;
    
    fund4View = cell;
                
    return cell.maxY;
}
- (CGFloat)creatInsuredItem10Cell:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"InsuredItem2Cell" owner:self options:nil];
    InsuredItem2Cell* cell = [Bundle objectAtIndex:0];
    cell.backgroundColor = [UIColor whiteColor];
    cell.frame = CGRectMake(0, current2MaxY, ScreenWidth, height);
    [section2View addSubview:cell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.lb_title.text = @"公积金费用";
    lb_fund = cell.lb_content;
    fund5View = cell;
    return cell.maxY;
}



#pragma mark - load apis
- (NSDictionary *)BuyShebaoRequestPara
{
    wxyjModel* wModel = self.wModel;
    NSDictionary *para = nil;
    if (BuyFund) {
        para = @{
            @"sbuId":@(self.payUserModel.Id),
            @"cid":@(wModel.Id),
            @"hukou_type":@(self.hukou_type.integerValue),
            @"month":@(startMonth),
            @"nums":@(mNums),
            @"shebao_card":haveCard ? @(1) :@(0),
            @"first_sb": @(first_sb),
            //@"sb_wage":@(allshebao_fee),
            @"buyFund":[NSNumber numberWithBool:BuyFund],
            @"fund":@(tf_wage.text.integerValue),
            @"first_fund": @(first_fund),
            @"added":@(0),
            @"city":self.selectCityName,
            @"id_card":self.payUserModel.id_card,
            @"user_name":self.payUserModel.user_name,
        };
    }else{
        para = @{
            @"sbuId":@(self.payUserModel.Id),
            @"cid":@(wModel.Id),
            @"hukou_type":@(self.hukou_type.integerValue),
            @"month":@(startMonth),
            @"nums":@(mNums),
            @"shebao_card":haveCard ? @(1) :@(0),
            @"first_sb": @(first_sb),
            //@"sb_wage":@(allshebao_fee),
            @"buyFund":[NSNumber numberWithBool:BuyFund],
            @"fund":@(0.0),
            @"first_fund": @(first_fund),
            @"added":@(0),
            @"city":self.selectCityName,
            @"id_card":self.payUserModel.id_card,
            @"user_name":self.payUserModel.user_name,
            
        };
    }
    
    return para;
}

- (void)checkAccord
{
    if (BuyFund) {
        if (tf_wage.text.length == 0) {
               [self alertShow:@"请填写缴费范围内的公积金金额"];
               return ;
           }else{
               if (tf_wage.text.integerValue < fundItem.min || tf_wage.text.integerValue > fundItem.max) {
                   [self alertShow:@"请填写缴费范围内的公积金金额"];
                   return ;
               }
           }
        
        [self buyedFundMoneyRequestResponse:^(bool large,NSString* data) {
            if (large) {
                [self BuySheBaoRequest];
            }else{
               [self alertShow:[NSString stringWithFormat:@"您当前填写的金额少于%@元",data]];
            }
        }];
    }else{
         [self BuySheBaoRequest];
    }
}

- (void)BuySheBaoRequest
{
    
    
   
   
    
    NSString *phone = [getPeopleID PeopleIphoneNmber];
       //先拼接
       NSString *sign = [NSString stringWithFormat:@"%@%@",SocialInsurancePayLoginKey,phone];
       sign = [MyMD5 md5:sign];
    
    NSDictionary *params = [self BuyShebaoRequestPara];
    NSMutableString *redirectUrl = [[NSMutableString alloc]initWithString:@""];
    for (NSString* key in params.allKeys) {
        if (redirectUrl.length == 0) {
             redirectUrl = (NSMutableString *)[redirectUrl stringByAppendingString:[NSString stringWithFormat:@"/s/shebao/direct_buy?%@=%@",key,params[key]]];
        }else{
             redirectUrl = (NSMutableString *)[redirectUrl stringByAppendingString:[NSString stringWithFormat:@"&%@=%@",key,params[key]]];
        }
       
    }
    
    redirectUrl = [self URLEncodedString:redirectUrl];
    
    
   
    
    
    
    [self getBackUrlRequestResponse:^(NSString *backurl) {
        if (backurl) {
            //NSString *url = [NSString stringWithFormat:@"%@reg_login?phone=%@&sign=%@&redirectUrl=%@&backUrl=%@",[NetworkConfig ipSheBaoPay],phone,sign,redirectUrl,[self URLEncodedString:backurl]];
            NSString *url = [NSString stringWithFormat:@"%@reg_login?phone=%@&sign=%@&channel=%@&redirectUrl=%@&backUrl=%@",[NetworkConfig ipSheBaoPay],phone,sign,SocialInsurancePayChannel,redirectUrl,[self URLEncodedString:backurl]];
            Web2ViewController *webvc = [[Web2ViewController alloc]init];
              
              webvc.title = @"订单支付";
              
              webvc.skipUrl = [NSURL URLWithString:url];
              
              [self.navigationController pushViewController:webvc animated:YES];
        }
    }];
    return;
    
    
    
  
    
    
    
}


- (void)getBackUrlRequestResponse:( void (^)(NSString* backurl))success
{
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:[self BuyShebaoRequestPara]];
    
    NSString *phone = [getPeopleID PeopleIphoneNmber];
    
    [params setObject:phone forKey:@"phone"];
    
    
    for (NSString* key in params.allKeys) {
        if ([key containsString:@"_"]) {
            id str = [params valueForKey:key];
            [params removeObjectForKey:key];
            NSRange redirectRange = [key rangeOfString:@"_"];
            NSString* prefixStr =  [key substringToIndex:redirectRange.location+redirectRange.length-1];
            NSString* suffixStr = [[key substringFromIndex:redirectRange.location+redirectRange.length] capitalizedString];
            NSString *newKey = [NSString stringWithFormat:@"%@%@",prefixStr,suffixStr];
            
            [params setObject:str forKey:newKey];
            
        }else{
            if ([key isEqualToString:@"fund"]) {
                NSNumber* fund = [params valueForKey:key];
                NSString*moneyStr = [NSString stringWithFormat:@"%.2f,%@,%ld",allshebao_fee,allservice_fee,fund.integerValue*mNums];
                [params setObject:moneyStr forKey:key];
            }
        }
    }
    
    NSString *url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipBackUrlConfig],BackUrlRquest];
    NSLog(@"请求backurl:%@",url);
    NSLog(@"param:%@",params);
    [NetworkRequest Get3:url Params:params Success:^(id _Nonnull response) {
        NSLog(@"response:%@",response);
        if ([response isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",response[@"state"]];
            NSString *describe = [NSString stringWithFormat:@"%@",response[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                NSString*backurl = response[@"result"];
                
                success(backurl);
                
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
    } Failure:^(NSError * _Nonnull error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"无网络"];
    }];
}
- (NSString *)URLEncodedString:(NSString *)string
{
    // CharactersToBeEscaped = @":/?&=;+!@#$()~',*";
    // CharactersToLeaveUnescaped = @"[].";

    NSString *unencodedString = string;
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)unencodedString,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));

    return encodedString;
}

- (NSDictionary *)BuyedFundMoneyRequestPara
{
    NSDictionary *param = @{
        @"key": [PayUserInfoManager sharedManager].model.key,
        @"sbuId":@(self.payUserModel.Id),
        @"city_code":@(self.selectCity_code)
    };
    return param;
}

- (void)buyedFundMoneyRequestResponse:( void (^)(bool large,NSString* data))success
{
    NSString *url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipMySocialInsuranceConfig],BuyedFundMoneyRequest];
    NSLog(@"获取以往公积金金额url:%@",url);
    NSLog(@"param:%@",[self BuyedFundMoneyRequestPara]);
    
    [NetworkRequest Post:url Params:[self BuyedFundMoneyRequestPara] Success:^(id _Nonnull reponseObject) {
        NSLog(@"reponseObject:%@",reponseObject);
        if ([reponseObject isKindOfClass:[NSDictionary class]]) {
            NSString* data = [NSString stringWithFormat:@"%@",reponseObject[@"data"]];
            if (self->tf_wage.text.doubleValue >= data.doubleValue) {
                success(YES,data);
            }else{
                success(NO,data);
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
    
    } Failure:^(NSError* error) {
        NSLog(@"error:%@",error);
    }];
    
}


#pragma mark - UITextFieldDelegate
-(void)textFieldTextChange:(UITextField *)textField
{
    if (textField.text.length > 0) {
        NSDecimalNumber *num1 = [NSDecimalNumber decimalNumberWithString:textField.text];
        NSDecimalNumber *num2 = [NSDecimalNumber decimalNumberWithString:@"100"];
        NSDecimalNumber *num3 = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",fundItem.p]];
        NSDecimalNumber *num4 = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",fundItem.e]];
        NSDecimalNumber *num5 = [num1 decimalNumberByMultiplyingBy:num2];
        NSDecimalNumber *num6 = [num3 decimalNumberByAdding:num4];
        NSDecimalNumber *aNum = [num5 decimalNumberByDividingBy:num6];
        
        
        lb_wage.text = [NSString stringWithFormat:@"%.0f元",aNum.doubleValue];
        if (mNums == 1) {
            lb_fund.text = [NSString stringWithFormat:@"¥%@/月",textField.text];
        }else{
            lb_fund.text = [NSString stringWithFormat:@"¥%ld(共%d月)",textField.text.integerValue * mNums,mNums];
        }
    }else{
        lb_wage.text = @"0元";
        if (mNums == 1) {
            lb_fund.text = [NSString stringWithFormat:@"¥0/月"];
        }else{
            lb_fund.text = [NSString stringWithFormat:@"¥0(共%d月)",mNums];
        }
        
    }
    
    
    
    [self CalculateTotalCharge];
    
              
    
    
}




#pragma mark - MySwitchDelegate
- (BOOL)allowClick:(MySwitch *)Switch
{
    if (Switch.tag == 201) {
        
        if (!WWModel.pack) {
            [self alertShow:@"该城市不支持打包购买"];
        }
        return WWModel.pack;
    }
    return YES;
}
- (void)onStatusDelegate:(MySwitch *)Switch
{
    if (Switch.tag == 200) {
        first_sb = Switch.OnStatus;
    }else if (Switch.tag == 201){
        BuyFund = Switch.OnStatus;
        [self.scrollView.delegate scrollViewDidScroll:self.scrollView];
        if (Switch.OnStatus) {
            [self showFundView];
        }else{
            [self hiddenFundView];
            
           
        }
        
        
        [self CalculateTotalCharge];
        
        
    }else if (Switch.tag == 202){
        first_fund = Switch.OnStatus;
    }
    
}


#pragma mark - InsuredInfoTopCellDelegate
- (void)Btnclick:(UILabel *)label index:(NSInteger)index
{
    [self.view endEditing:YES];
    
    NSLog(@"label:%@,index:%ld",label,index);
    
    if (index == 202) {
        
         [Tools showMessage:@"城市不可选"];
         return;
        CZQAddressPicker *picker = [[CZQAddressPicker alloc]initWithCitys:self.citys];
           picker.block = ^(PayCityModel * _Nonnull province, PayCityModel * _Nonnull city) {
               self->lb_city.text = city.name;
           };
           
           [picker showWithAnimation:YES];
        return;
    }else if (index == 203){
        [CityTypeSelectView showCityTypeViewWithResultBlock:^(NSString * _Nonnull selectCityType) {
                   if (selectCityType) {
                       self->lb_cityType.text = selectCityType;
                       
                       if ([selectCityType isEqualToString:@"本地城镇"]) {
                           self.hukou_type = @"1";
                       }else if ([selectCityType isEqualToString:@"本地农村"]){
                           self.hukou_type = @"2";
                       }else if ([selectCityType isEqualToString:@"外地城镇"]){
                           self.hukou_type = @"3";
                       }else if ([selectCityType isEqualToString:@"外地农村"]){
                           self.hukou_type = @"4";
                       }
                       
                       wxyjModel* wModel = self.model.wxyj.firstObject;
                       self->shebao_fee = 0.0;
                             for (ShebaoCityDataItem* item in wModel.shebaos) {
                                 if (item.hukou_type == self.hukou_type.intValue) {
                                     
                                     for (ShebaoNamePrice* price in item.Data) {
                                         self->shebao_fee = self->shebao_fee + price.p;
                                     }
                                     break;
                                 }
                             }
                            
                       NSLog(@"社保费用%.2f",self->shebao_fee);
                       
                       for (FundCityDataItem* item in wModel.funds) {
                           if (item.hukou_type == self.hukou_type.intValue) {
                               self->fundItem = item;
                               break;
                           }
                       }
                       
                       self->allshebao_fee = [NSString stringWithFormat:@"%.2f",self->shebao_fee * self->WWModel.nums].doubleValue;
                       
                       NSDecimalNumber *minNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->fundItem.min]];
                       NSDecimalNumber *maxNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->fundItem.max]];
                       self->tf_wage.placeholder = [NSString stringWithFormat:@"%@元~%@元",minNumber.stringValue,maxNumber.stringValue];
                       
                       
                       NSDecimalNumber *pNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->fundItem.p]];
                       NSDecimalNumber *eNumber = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->fundItem.e]];
                       self->lb_p.text = [NSString stringWithFormat:@"%%%@",pNumber.stringValue];
                       self->lb_e.text = [NSString stringWithFormat:@"%%%@",eNumber.stringValue];
                       
                       
                       if (self->mNums == 1) {
                           self->lb_sb.text = [NSString stringWithFormat:@"¥%.2f/月",self->shebao_fee * self->mNums];
                       }else{
                           self->lb_sb.text = [NSString stringWithFormat:@"¥%.2f(共%d月)",self->shebao_fee * self->mNums, self->mNums];
                       }
                       
                       
                   }
             [self CalculateTotalCharge];
               }];
        return;
    }
    
    SelectMonthViewController* vc =[[SelectMonthViewController alloc]init];
    vc.title = @"选择月份";
    vc.startDate = [NSString stringWithFormat:@"%d",WWModel.month];
    vc.block = ^(BOOL flag, NSString * _Nonnull startDate, NSString * _Nonnull endDate, NSInteger month, NSInteger num) {
      if (flag) {
            self->lb_startDate.text = startDate;
            self->lb_endDate.text = endDate;
            self->lb_num.text = [NSString stringWithFormat:@"%ld个月",num];
          
          NSDecimalNumber *package_charge = nil;
          if (self->BuyFund) {
              package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.package_charge]];
          }else{
               package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.shebao_charge]];
          }
          
            NSDecimalNumber *package_charge_t = [package_charge decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%ld",(long)num]]];
            
            if (num == 1) {
                self->lb_sb.text = [NSString stringWithFormat:@"¥%.2f/月",self->shebao_fee * num];
                
                self->lb_serviceCharge.text = [NSString stringWithFormat:@"¥%@/月",package_charge_t.stringValue];
                self->lb_fund.text = [NSString stringWithFormat:@"¥%@/月",self->tf_wage.text];
            }else{
                self->lb_sb.text = [NSString stringWithFormat:@"¥%.2f(共%ld月)",self->shebao_fee * num, (long)num];
                self->lb_serviceCharge.text = [NSString stringWithFormat:@"¥%@(共%ld月)",package_charge_t.stringValue,num];
                self->lb_fund.text = [NSString stringWithFormat:@"¥%ld(共%ld月)",self->tf_wage.text.integerValue * num,(long)num];
            }
          
          self->allservice_fee = [NSString stringWithFormat:@"%@",package_charge_t.stringValue];
            
            
            
            self->mNums = (int)num;
            self->startMonth = month;
            
            [self CalculateTotalCharge];
            
            
        }
    };
    [self.navigationController pushViewController:vc animated:YES];
}




#pragma mark - UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    NSLog(@"%f",scrollView.contentOffset.y);

//    if (BuyFund) {
//        _scrollView.contentSize = CGSizeMake(ScreenWidth, self.scrollView.bounds.size.height + 90);
//    }else{
//        _scrollView.contentSize = CGSizeMake(ScreenWidth, self.scrollView.bounds.size.height + 0.5);
//    }
    
    if (scrollView.contentOffset.y <=0) {
        scrollView.contentOffset = CGPointMake(0, 0 );
        
    }
    
   
    
    
    
  

}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    CGRect rect = self.serviceMoneyView.frame;
    
    if (rect.origin.y == ScreenHeight - 95) {
        rect.origin.y = ScreenHeight - 50;
        [UIView animateWithDuration:0.2 animations:^{
            self.serviceMoneyView.frame = rect;
        }];
    }
    
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    NSLog(@"123445345345");
    if (decelerate == NO) {
        CGRect rect = self.serviceMoneyView.frame;
        
        if (rect.origin.y == ScreenHeight - 50) {
            rect.origin.y = ScreenHeight - 95;
            [UIView animateWithDuration:0.2 animations:^{
                self.serviceMoneyView.frame = rect;
            }];
        }
    }
   
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGRect rect = self.serviceMoneyView.frame;
    
    if (rect.origin.y == ScreenHeight - 50) {
        rect.origin.y = ScreenHeight - 95;
        [UIView animateWithDuration:0.2 animations:^{
            self.serviceMoneyView.frame = rect;
        }];
    }
}


#pragma mark - event response
- (void)selctCardClick:(UITapGestureRecognizer *)tap
{
     [self.view endEditing:YES];
    [CityTypeSelectView show3CityTypeViewWithResultBlock:^(NSString * _Nonnull selectCityType) {
        if (selectCityType) {
            
            if ([selectCityType containsString:@"新办卡"]) {
                self->sb_cardType = @"新办卡";
                self->haveCard = YES;
                [self showCardChargeView];
            }else{
                self->sb_cardType = selectCityType;
                self->haveCard = NO;
                [self hiddenCardChargeView];
            }
            
            self->lb_cardType.text = self->sb_cardType;
            

            
             NSDecimalNumber *package_charge = nil;
            if (self->BuyFund) {
                package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.package_charge]];
            }else{
                package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.shebao_charge]];
            }
            NSDecimalNumber *package_charge_t = [package_charge decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%d",self->mNums]]];
            
            NSString *totalStr = nil;
                      
                      if (self->BuyFund) {
                          if (self->haveCard) {
                              if (self->tf_wage.text.length == 0) {
                                   totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue +self->WWModel.shebao_card_charge];
                              }else{
                                   totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue +self->WWModel.shebao_card_charge + self->tf_wage.text.integerValue * self->mNums];
                              }
                             
                          }else{
                              
                              if (self->tf_wage.text.length == 0) {
                                   totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue ];
                              }else{
                                  totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue  + self->tf_wage.text.integerValue * self->mNums];
                              }
                              
                             
                          }
                      }else{
                          
                          if (self->haveCard) {
                              totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue +self->WWModel.shebao_card_charge];
                          }else{
                              totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue ];
                          }
                      }
                      
                      NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:totalStr];
                      [content addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0xf6562f] range:NSMakeRange(3, totalStr.length-3)];
                      [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(3, totalStr.length - 4)];
                      [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(totalStr.length - 1, 1)];
                      self->lb_total.attributedText = content;
            
        }
    }];
}

- (void)payClick:(UIButton *)sender
{
    [self checkAccord];
}


//显示办理社保卡费用show
- (void)showCardChargeView
{
    CGRect frame = chargeCardView.frame;
    frame.size.height = 64;
    
    chargeCardView.frame = frame;
    
    CGRect frame2 = section2View.frame;
    frame2.origin.y = chargeCardView.maxY;
    
    section2View.frame = frame2;
    if (self.scrollView.height >= (section2View.maxY + 45)) {
              _scrollView.contentSize = CGSizeMake(ScreenWidth, self.scrollView.bounds.size.height + 0.5);
          }else{
             _scrollView.contentSize = CGSizeMake(ScreenWidth, section2View.maxY + 90);
          }
       
       
}


//隐藏社保卡费用Hedden
- (void)hiddenCardChargeView
{
    CGRect frame = chargeCardView.frame;
    frame.size.height = 0;
       
    chargeCardView.frame = frame;
    CGRect frame2 = section2View.frame;
    frame2.origin.y = chargeCardView.maxY;
    
    section2View.frame = frame2;
    if (self.scrollView.height >= (section2View.maxY + 45)) {
              _scrollView.contentSize = CGSizeMake(ScreenWidth, self.scrollView.bounds.size.height + 0.5);
          }else{
             _scrollView.contentSize = CGSizeMake(ScreenWidth, section2View.maxY + 90);
          }
       
}


//显示公积金View
- (void)showFundView
{
    CGRect frame = section2View.frame;
    frame.size.height = 300;
    section2View.frame = frame;
    fundTopView.line.hidden = NO;
    fund2View.hidden = NO;
    fund3View.hidden = NO;
    fund4View.hidden = NO;
    fund5View.hidden = NO;
    
    if (self.scrollView.height >= (section2View.maxY + 45)) {
           _scrollView.contentSize = CGSizeMake(ScreenWidth, self.scrollView.bounds.size.height + 0.5);
       }else{
          _scrollView.contentSize = CGSizeMake(ScreenWidth, section2View.maxY + 90);
       }
}

- (void)hiddenFundView
{
   CGRect frame = section2View.frame;
    frame.size.height = 83;
    section2View.frame = frame;
    fundTopView.line.hidden = YES;
    fund2View.hidden = YES;
    fund3View.hidden = YES;
    fund4View.hidden = YES;
    fund5View.hidden = YES;
    
    if (self.scrollView.height >= (section2View.maxY + 45)) {
           _scrollView.contentSize = CGSizeMake(ScreenWidth, self.scrollView.bounds.size.height + 0.5);
       }else{
          _scrollView.contentSize = CGSizeMake(ScreenWidth, section2View.maxY + 90);
       }
    
    [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

#pragma mark - 计算总的费用
- (void)CalculateTotalCharge
{
    

   NSDecimalNumber *package_charge = nil;
    if (self->BuyFund) {
        package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.package_charge]];
    }else{
         package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.shebao_charge]];
    }
    NSDecimalNumber *package_charge_t = [package_charge decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%d",self->mNums]]];
    







    NSString *totalStr = nil;
              
              if (self->BuyFund) {
                  if (self->haveCard) {
                      if (self->tf_wage.text.length == 0) {
                           totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue +self->WWModel.shebao_card_charge];
                      }else{
                           totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue +self->WWModel.shebao_card_charge + self->tf_wage.text.integerValue * self->mNums];
                      }
                     
                  }else{
                      
                      if (self->tf_wage.text.length == 0) {
                           totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue ];
                      }else{
                          totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue  + self->tf_wage.text.integerValue * self->mNums];
                      }
                      
                     
                  }
              }else{
                  
                  if (self->haveCard) {
                      totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue +self->WWModel.shebao_card_charge];
                  }else{
                      totalStr = [NSString stringWithFormat:@"合计: %.2f元",self->shebao_fee * self->mNums +package_charge_t.doubleValue ];
                  }
              }
              
              NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:totalStr];
              [content addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0xf6562f] range:NSMakeRange(3, totalStr.length-3)];
              [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(3, totalStr.length - 4)];
              [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(totalStr.length - 1, 1)];
              self->lb_total.attributedText = content;
    
    if (mNums == 1) {
         self->lb_serviceCharge.text = [NSString stringWithFormat:@"¥%@/月",package_charge_t.stringValue];
    }else{
        
          self->lb_serviceCharge.text = [NSString stringWithFormat:@"¥%@(共%d月)",package_charge_t.stringValue,mNums];
    }
    
    allshebao_fee = self->shebao_fee * self->mNums;
     self->allservice_fee = [NSString stringWithFormat:@"%@",package_charge_t.stringValue];
    
}

+(NSString*)encodeString:(NSString*)unencodedString{

    if([[[UIDevice currentDevice]systemVersion]floatValue] >=9.0) {

            return[unencodedString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];

}

NSString*encodedString = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)unencodedString,NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8));

return encodedString;
}



- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:nil message:msg preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }else{
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}

#pragma mark - getters and setters

- (void)creatServiceView
{
    InsuredItem2Cell* view = [[NSBundle mainBundle]loadNibNamed:@"InsuredItem2Cell" owner:self options:nil].lastObject;
    view.backgroundColor = [UIColor whiteColor];
    view.lb_title.text = @"服务费";
    NSDecimalNumber *package_charge = nil;
    if (self->BuyFund) {
        package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.package_charge]];
    }else{
         package_charge = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%lf",self->WWModel.shebao_charge]];
    }
   NSDecimalNumber *package_charge_t = [package_charge decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%d",mNums]]];
    if (mNums == 1) {
        view.lb_content.text = [NSString stringWithFormat:@"¥%@/月",package_charge_t.stringValue];
    }else{
        view.lb_content.text = [NSString stringWithFormat:@"¥%@(共%d月)",package_charge_t.stringValue,mNums];
    }
    
    allservice_fee = [NSString stringWithFormat:@"%@",package_charge_t.stringValue];
    
    
    view.frame = CGRectMake(0, ScreenHeight - 95, ScreenWidth, 50);
    
    lb_serviceCharge = view.lb_content;
    
    self.serviceMoneyView = view;
    [self.view addSubview:view];
    
    
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - 50, ScreenWidth, 50)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    
    
    
    UILabel *lb = [[UILabel alloc]init];
    lb_total = lb;
    lb.text = [NSString stringWithFormat:@"合计: %.2f元",shebao_fee * mNums +package_charge_t.doubleValue ];
    lb.textColor = [UIColor colorWithHex:0x4d4d4d];
    lb.font = [UIFont systemFontOfSize:15];
    [bottomView addSubview:lb];
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:lb.text];
    [content addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0xf6562f] range:NSMakeRange(3, lb.text.length-3)];
    [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(3, lb.text.length - 4)];
    [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(lb.text.length - 1, 1)];
    lb.attributedText = content;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = K_MainColor;
    [btn setTitle:@"确认参保" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [bottomView addSubview:btn];
    
    [btn addTarget:self action:@selector(payClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [lb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.centerY.equalTo(bottomView);
        make.width.offset(ScreenWidth/2 - 20);
    }];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.offset(0);
        make.width.offset(ScreenWidth/2);
    }];
}


- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 50)];
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.backgroundColor = [UIColor clearColor];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 50+0.5);
        _scrollView.delegate = self;
        _scrollView.bounces = YES;
    }
    return _scrollView;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
