//
//  SSPaymenyViewController.m
//  Open
//
//  Created by 雷俊博 on 2019/7/29.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "SSPaymenyViewController.h"
#import "PaymentDetailViewController.h"
#import "InsuredMemberAddViewController.h"


#import "SocialSecurityPaymentTableViewCell.h"
#import "SSPayment2TableViewCell.h"

#import "CYCitySelectedView.h"
#import "CityTypeSelectView.h"


#import "Constants.h"

#import "UIView+frameAdjust.h"



#import "SelectLocationView.h"
#import "PayCityModel.h"
#import "SheBaoDataModel.h"


#import "InsuredMemberAddViewController.h"
#import "InsuredMemberSelectViewController.h"
#import "UINavigationBar+handle.h"
#import "PayHistoryController.h"

@interface SSPaymenyViewController ()<UITableViewDelegate, UITableViewDataSource,UIGestureRecognizerDelegate>
{
    NSInteger _selectIndex;
    NSInteger _selectCity_code;
    
    wxyjModel* WXYModel;
    
    NSArray* titleArray;
    NSArray* contentArray;
}
@property (nonatomic, strong)UIScrollView *scrollView;


@property (nonatomic, strong)UIView *topView;
@property (nonatomic, strong)UIView *topbackView;
@property (nonatomic, strong)UILabel *lb_title;
@property (nonatomic, strong)UILabel *lb_subTitle;

@property (nonatomic, strong)UIView *cardView;
@property (nonatomic, strong)UILabel *lb_cityTitle;
@property (nonatomic, strong)UILabel *lb_city;
@property (nonatomic,strong)UIImageView *img_arrow;
@property (nonatomic, strong)UIButton *btn_city;


@property (nonatomic, strong)UIView *lineView1;


@property (nonatomic, strong)UIView *planView;

@property (nonatomic, strong)UILabel *lb_ssPlanTitle;
@property (nonatomic, strong)UILabel *lb_ssPlan;
@property (nonatomic,strong)UIImageView *img_arrow4;
@property (nonatomic, strong)UIButton *btn_ssPlan;

@property (nonatomic, strong)UIView *lineView4;


@property (nonatomic, strong)UILabel *lb_cityTypeTitle;
@property (nonatomic, strong)UILabel *lb_cityType;
@property (nonatomic,strong)UIImageView *img_arrow2;
@property (nonatomic, strong)UIButton *btn_cityType;

@property (nonatomic, strong)UIImageView *img_message;
@property (nonatomic, strong)UILabel *lb_message;


//户口
@property (nonatomic, strong)UIView *residenceView;

@property (nonatomic, strong)NSMutableArray *btnArray;

@property (nonatomic, strong)UILabel *lb_TotalSocialSecurityExpenseTitle;
@property (nonatomic, strong)UILabel *lb_TotalSocialSecurityExpense;

@property(nonatomic,strong)UIView *backView_TotalSocialSecurityExpense;

@property (nonatomic, strong)UIView *lineView2;

@property (nonatomic, strong)UITableView *tableView;


@property (nonatomic, strong)NSArray *dataArray;

@property (nonatomic, strong)UIView *footerView;

@property (nonatomic, strong)UIView *lineView3;

@property (nonatomic, strong)UILabel *lb_check;

@property (nonatomic, strong)UIImageView *img_arrow3;

@property (nonatomic, strong)UIView *bottomView;

@property (nonatomic, strong)UIButton *btn_kefu;
@property (nonatomic, strong)UIButton *btn_phone;


@property (nonatomic, strong)UIView *bottomBtnBackView;
@property (nonatomic, strong)UIButton *btn_left;
@property (nonatomic, strong)UIButton *btn_right;

@property (nonatomic, strong)NSArray* citysArray;
@property (nonatomic, strong)SelectLocationView*locationView;

@property (nonatomic, strong)SheBaoDataModel* dataModel;








@end

@implementation SSPaymenyViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [GTCountSDK trackCountEvent:@"home_shebaojiaofei_mainPage" withArgs:@{}];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self getOCR];
    self.view.backgroundColor = [UIColor colorWithHex:0xf5f5f5];
    _selectIndex = 0;
    _selectCity_code = 1201;
    
    titleArray = @[@"重要说明：",@"社保减员注意事项：",@"温馨提示："];
    contentArray = @[@"• 以前曾在单位参保过得，第一次下单购买前，请先确认前单位是否已经减员，若因前单位没有减员，导致购买不成功，平台不负责！\n• 平台仅支持代缴服务，不支持生育津贴，住房补贴等申领，且不出具任何相关证明。",@"• 若您停止购买后，平台通常会于次月截至时间后的一周操作减员(部分地区可能会有延迟)，需提前减员的用户，请提前 3~7 个工作日联系客服。\n• 如果您当月申请减员后，又想重新购买当月的社保，请务必先联系客服撤销减员，避免漏缴。",@"• 避免因错过截止时间忘记下单，造成社保断缴的，建议一次性购买多个月份，若有新的工作单位，未缴费的月份可申请退款。\n• 凡带有“代缴”标识的，首月会一次性收取一年的费用，年费会因地区和缴费月份不同稍有变化。\n• 带有“预收费用”的城市，因社保局已确定调费，但上调金额未定，固将预收一定的费用。待社保局确定上调金额后，平台会统一清算，多退少补（如：杭州市一般于6月份公布，但须从当年1月份开始执行）。\n• 每年政府会调整社保缴费基数，平台会在第一时间通知您。若因政府调整通知滞后导致划扣金额不准确的，承诺多退少补，童叟无欺。\n• 本套餐适合于18岁至法定退休年龄之间的用户购买。\n• 社保缴费功能与“我的社保”合作，用户在此功能内所有行为与“看看生活APP”无关。"];
    
    //起点发生变化
    //self.edgesForExtendedLayout=UIRectEdgeBottom;
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self.tableView layoutIfNeeded];

    
    [self loadAllApis];
    
    self.tableView.hidden = YES;
    self.bottomView.hidden = YES;
    
    
    [self.navigationController.navigationBar navBarBackGroundColor:K_MainColor image:nil isOpaque:YES];//颜色
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
    
//    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [rightBtn setTitle:@"购买记录" forState:UIControlStateNormal];
//    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
//    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//
//    UIBarButtonItem* rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
//
//    self.navigationItem.rightBarButtonItem = rightItem;
    

    [self navConfig];
    
    
    //返回guide弹框
    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"shebaoPayShowLastTime"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
}

- (void)navConfig
{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = K_MainColor;
    [self.view addSubview:navView];
    
    
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake( 10 * WIDTHRADIU, cl_kStatusBarHeight , 50, 44);
    backBtn.titleLabel.textAlignment =NSTextAlignmentLeft;
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    //    [button_2 setBackgroundColor:[UIColor redColor]];
    //    [button_2 setTitleColor:[UIColor colorWithRed:12.0 green:12.0 blue:12.0 alpha:1] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:3];
    
    
    
    
    //title
    UILabel* lb_title = [[UILabel alloc]init];
    lb_title.textColor = [UIColor whiteColor];
    lb_title.font = [UIFont boldSystemFontOfSize:17 * WIDTHRADIU];
    lb_title.textAlignment = NSTextAlignmentCenter;
    [navView addSubview:lb_title];
    
    lb_title.text = self.title;
    
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(navView);
        make.height.offset(25);
        make.top.offset(cl_kStatusBarHeight + 9.5);
    }];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake( ScreenWidth - 80, cl_kStatusBarHeight , 80, 44);
    [rightBtn setTitle:@"购买记录" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:rightBtn];
    
}


#pragma mark - reload data
- (void)reloadUI:(BOOL)changeUI
{
    if (self.dataModel) {
        wxyjModel* wModel = WXYModel;
         self.lb_subTitle.text = [NSString stringWithFormat:@"服务费: 每月%d元(通道服务费+增值税费)",(int)wModel.shebao_charge];
         NSString*month = [NSString stringWithFormat:@"%d",wModel.month];
        NSString* newmonth = [NSString stringWithFormat:@"%@年%@月",[month substringToIndex:4],[month substringFromIndex:5]];
         self.lb_message.text = [NSString stringWithFormat:@"目前可购买%@及之后月份，截止日期为%@月%d日",newmonth,[month substringFromIndex:5],wModel.inc_date];
         ShebaoCityDataItem* item = wModel.shebaos[_selectIndex];
        __block double num = 0.0;
         [item.Data enumerateObjectsUsingBlock:^(ShebaoNamePrice * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
             num = num + obj.p;
         }];
         
         self.lb_TotalSocialSecurityExpense.text = [NSString stringWithFormat:@"%.2lf元/月",num];
         CGFloat height = [NSString getSpaceLabelHeightwithSpeace:2 withFont:[UIFont systemFontOfSize:12] withWidth:(ScreenWidth - 73) text:self.lb_message.text];
         
         CGRect frame = self.topView.frame;
         
         NSLog(@"改变前%@",NSStringFromCGRect(frame));
        CGFloat maxY;
         self.lb_ssPlan.text = wModel.shebao_type;
        if (changeUI) {
             maxY = height> 12 ?((296 + 45)  - 12 + height) : (296 + 45) ;
            
            
            [self.planView mas_updateConstraints:^(MASConstraintMaker *make) {
                   make.height.offset(45);
               }];
               for (UIView* view in self.planView.subviews) {
                   view.hidden = NO;
               }
               
               
               CGFloat height = [self.planView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
               CGRect frame = self.planView.frame;
               frame.size.height = height;
               self.planView.frame = frame;
               
               
               [self.cardView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.height.offset(90 + 45);
                }];
               
               CGRect frame2 = self.topView.frame;
               frame2.size.height = 296 + 45;
               self.topView.frame = frame2;
           
           
            
        }else{
             maxY = height> 12 ?(296   - 12 + height) : 296 ;
            
            [self.planView mas_updateConstraints:^(MASConstraintMaker *make) {
                   make.height.offset(0);
               }];
               for (UIView* view in self.planView.subviews) {
                   view.hidden = YES;
               }
               
               
               CGFloat height = [self.planView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
               CGRect frame = self.planView.frame;
               frame.size.height = height;
               self.planView.frame = frame;
               
               
               [self.cardView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.height.offset(90);
                }];
               
               CGRect frame2 = self.topView.frame;
               frame2.size.height = 296;
               self.topView.frame = frame2;
            
        }
        
         
         frame.size.height = maxY;
         
         self.topView.frame = frame;
         
          NSLog(@"改变后%@",NSStringFromCGRect(self.topView.frame));
          [self.tableView reloadData];
    }
    
    
}
#pragma mark - load api
- (void)getSocialInsuranceCitysRequest
{
    WeakSelf
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipMySocialInsuranceConfig],GetSocialInsuranceCitysRequest];
              urlString = [urlString stringByAppendingFormat:@"?pid=0"];
    NSLog(@"获取城市url:%@",urlString);
    [SVProgressHUD show];
    [NetworkRequest Get:urlString Params:nil Success:^(id _Nonnull responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        [SVProgressHUD dismiss];
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            if ([code isEqualToString:@"200"]) {
                NSArray *dataArray = [PayCityModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
                weakSelf.citysArray = dataArray;
                [weakSelf btnClick:self->_btn_city];
            }else{
                [SVProgressHUD showInfoWithStatus:@"请求失败"];
            }
        }else{
            [SVProgressHUD showInfoWithStatus:@"服务器异常"];
        }
        
        
    } Failure:^(NSError* error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}

- (NSDictionary *)getSheBaoDataRequestPara
{
    NSDictionary *parma =@{
        @"city_code":@(_selectCity_code),
        @"type":@(_selectIndex + 1)
    };
    return parma;
}

- (void)getSheBaoDataRequest
{
    WeakSelf
    [SVProgressHUD show];
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipMySocialInsuranceConfig],GetSheBaoDataRequest];
    NSLog(@"获取社保数据url:%@",urlString);
    NSLog(@"params:%@",[self getSheBaoDataRequestPara]);
    [NetworkRequest Get:urlString Params:[self getSheBaoDataRequestPara] Success:^(id _Nonnull responseObject) {
        [SVProgressHUD dismiss];
                     NSLog(@"responseObject:%@",responseObject);
                     
                     if ([responseObject isKindOfClass:[NSDictionary class]]) {
                           NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
                           if ([code isEqualToString:@"200"]) {
                               SheBaoDataModel *model = [SheBaoDataModel mj_objectWithKeyValues:responseObject[@"data"]];
                               weakSelf.dataModel = model;
                               self->WXYModel = model.wxyj.count > 0 ? model.wxyj[0] :nil;
                               if (model.wxyj.count >1) {
                                   [weakSelf reloadUI:YES];
                               }else{
                                   [weakSelf reloadUI:NO];
                               }
                               
                               
                                    
                                    
                                }
                     }
                     
                     
                 } Failure:^(NSError* error) {
                     NSLog(@"error:%@",error);
                     [SVProgressHUD dismiss];
                     
                 }];
}




- (void)loadAllApis
{
    WeakSelf
    [SVProgressHUD show];
    dispatch_group_t group = dispatch_group_create();
       
       dispatch_queue_t searialQueue = dispatch_queue_create("com.shebaoPay.www", DISPATCH_QUEUE_SERIAL);
       
       dispatch_group_enter(group);
       dispatch_group_async(group, searialQueue, ^{
           //网络请求1
           
           NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipMySocialInsuranceConfig],GetSocialInsuranceCitysRequest];
           urlString = [urlString stringByAppendingFormat:@"?pid=0"];
           NSLog(@"获取城市url:%@",urlString);
           [NetworkRequest Get:urlString Params:nil Success:^(id _Nonnull responseObject) {
               NSLog(@"responseObject:%@",responseObject);
               if ([responseObject isKindOfClass:[NSDictionary class]]) {
                   NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
                   if ([code isEqualToString:@"200"]) {
                       NSArray *dataArray = [PayCityModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
                       weakSelf.citysArray = dataArray;
                       
                       
                   }
               }
               dispatch_group_leave(group);
               
           } Failure:^(NSError* error) {
               NSLog(@"error:%@",error);
                dispatch_group_leave(group);
           }];
           
           
           
       });
       dispatch_group_enter(group);
       dispatch_group_async(group, searialQueue, ^{
           //网络请求2
              NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipMySocialInsuranceConfig],GetSheBaoDataRequest];
              NSLog(@"获取社保数据url:%@",urlString);
              NSLog(@"params:%@",[self getSheBaoDataRequestPara]);
              [NetworkRequest Get:urlString Params:[self getSheBaoDataRequestPara] Success:^(id _Nonnull responseObject) {
                  NSLog(@"responseObject:%@",responseObject);
                  
                  if ([responseObject isKindOfClass:[NSDictionary class]]) {
                        NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
                        if ([code isEqualToString:@"200"]) {
                              SheBaoDataModel *model = [SheBaoDataModel mj_objectWithKeyValues:responseObject[@"data"]];
                            weakSelf.dataModel = model;
                            if (model.wxyj.count > 0) {
                                self->WXYModel = model.wxyj[0];
                            }
                            
                                 
                                 
                             }
                  }
                  dispatch_group_leave(group);
                  
              } Failure:^(NSError* error) {
                  NSLog(@"error:%@",error);
                  dispatch_group_leave(group);
                  
              }];
        
       });
    
    dispatch_group_enter(group);
    dispatch_group_async(group, searialQueue, ^{
        [NetworkTokenRequest getTokenSuccess:^(BOOL success) {
            dispatch_group_leave(group);
        }];
    });
    
       //2个网络请求结束后,刷新UI
       dispatch_group_notify(group, searialQueue, ^{
           dispatch_async(dispatch_get_global_queue(0, 0), ^{
               dispatch_async(dispatch_get_main_queue(), ^{
                   
                   [SVProgressHUD dismiss];
                   
                   if (self.dataModel) {
                       self.tableView.hidden = NO;
                       self.bottomView.hidden = NO;
                       [weakSelf reloadUI:self.dataModel.wxyj.count > 1 ? YES : NO];
                   }
                   
                
                   
               });
           });
       });
}


- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
    WeakSelf
   
    
    
   
   
    
    

    [self.backView_TotalSocialSecurityExpense mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.residenceView.mas_bottom).offset(1);
        make.left.right.offset(0);
        make.height.offset(47 );
    }];

    [self.lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(10 );
        make.right.offset(-10);
        make.height.offset(0.5);
    }];

    [self.lb_check mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.footerView).offset(-8);
        make.top.equalTo(weakSelf.lineView3.mas_bottom).offset(15);
        make.height.offset(15);
    }];

    [self.img_arrow3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.lb_check);
        make.left.equalTo(weakSelf.lb_check.mas_right).offset(4);
    }];

    [self.btn_kefu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.left.offset(25);
        make.width.offset(50);
    }];
    
    [self.btn_kefu layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];

    
    [self.btn_phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.left.equalTo(weakSelf.btn_kefu.mas_right).offset(25);
        make.width.offset(50);
    }];
    
    [self.btn_phone layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleTop imageTitleSpace:4];
    
    [self.bottomBtnBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.bottomView);
        
        make.right.offset(-10);
        make.height.offset(35);
        make.width.offset(200);
    }];
    
//    [self.btn_left mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.bottom.offset(0);
//        make.width.equalTo(weakSelf.bottomBtnBackView).multipliedBy(0.5);
//    }];
    
    [self.btn_right mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.offset(0);
        make.width.equalTo(weakSelf.bottomBtnBackView).multipliedBy(1);
    }];
    
}

#pragma mark - OCR
-(void)getOCR
{
#if TARGET_IPHONE_SIMULATOR
    
#else
    // 打开引擎
    Gint ret = 0;
    Gint vaule = 1;
    ret = TREC_StartUP(TREC_GetEngineTimeKEY());
    if (ret == 100) {
        return;
    }
    if (ret == 100) {
        return;
    }if (ret == 101) {
        return;
    }
    
    ret = TREC_SetParam(T_SET_HEADIMG, &vaule);
    ret = TREC_SetSupportEngine(TIDCARD2);// 演示使用身份证，其他证件以此类推
    
    UIImage *sdfasf;
    sdfasf=   TREC_GetHeadImage();// 获取人头像图片流
    
    if (ret != 1) {
        
        TREC_ClearUP();
        return;
    }
    
    
    ret = TREC_ClearUP();
#endif

    


}


#pragma mark - UITableViewDelegate & UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1 + titleArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        wxyjModel *wModel = WXYModel;
           ShebaoCityDataItem *item = wModel.shebaos[_selectIndex];
           return item.Data.count;
    }
   
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        SocialSecurityPaymentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        wxyjModel *wModel = WXYModel;
        ShebaoCityDataItem *item = wModel.shebaos[_selectIndex];
        
        [cell refreshUIWithData:item.Data[indexPath.row] Array:item.Data index:indexPath.row];
        
        return cell;
    }
    
    SSPayment2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SSPayment2TableViewCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.lb_title.text = titleArray[indexPath.section - 1];
   
    
    NSString* str = [contentArray objectAtIndex:(indexPath.section - 1)];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
     paraStyle.firstLineHeadIndent = [UIFont systemFontOfSize:14].pointSize * 2;
    /** 行高 */
    paraStyle.lineSpacing = 8;
    // NSKernAttributeName字体间距
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.5f
                          };
    
      
    [attributedString addAttributes:dic range:NSMakeRange(0, str.length)];

    [cell.lb_content sizeToFit];
    
     cell.lb_content.attributedText = attributedString;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
               return 40 * WIDTHRADIU;
           }else if (indexPath.row == (self.dataArray.count - 1)){
               return 45 * WIDTHRADIU;
           }
           return 35 * WIDTHRADIU;
    }
    
    NSString* str = [contentArray objectAtIndex:(indexPath.section - 1)];
    CGFloat height =  [NSString getSpaceLabelHeightwithSpeace:8 withFont:[UIFont systemFontOfSize:14] withWidth:(ScreenWidth - 50) text:str];
    return   height > 14 ?  75 + height + 0.5 : 75 + 14 + 0.5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section != 0) {
        return 10;
    }
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return  self.footerView;
    }
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
    view.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (section == 1) {
        return 10;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
        view.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        return view;
    }
    return nil;
}

#pragma mark - event response
- (void)backBtnClick
{
    
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"shebaoDepartmentShowLastTime"];

    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        
        [self.navigationController popViewControllerAnimated:YES];
        
        return;
    }
    
    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"shebaoDepartmentShowLastTime"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    WeakSelf
    [GuideAlertView showWithImageName:@"guide_shebaoDepartment" VC:self Block:^(BOOL success) {
        [weakSelf goToSheBaoOrgsVC];
    }];
    return;
    
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)chatClick:(UIButton *)sender
{
    
    NSString *url = [NSString stringWithFormat:@"https://www.sobot.com/chat/pc/index.html?sysNum=a73ea222d7284f7c8801e60e6054e985&partnerId=%@&tel=%@&uname=%@&face=%@&remark=KANKANSHEBAO",[PayUserInfoManager sharedManager].model.uid,[getPeopleID PeopleIphoneNmber],[self URLEncodedString:[getPeopleID Peopletitle]],[self URLEncodedString:[getPeopleID PeoplePhoto].absoluteString]];
         Web2ViewController*webvc = [[Web2ViewController alloc]init];
                 
        webvc.title = @"智能客服";
                 
        webvc.skipUrl = [NSURL URLWithString:url];
                 
        [self.navigationController pushViewController:webvc animated:YES];
}

- (NSString *)URLEncodedString:(NSString *)string
{
    // CharactersToBeEscaped = @":/?&=;+!@#$()~',*";
    // CharactersToLeaveUnescaped = @"[].";

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

    return encodedString;
}
- (void)phoneClick:(UIButton *)sender
{
    NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://4008819211"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
}
- (void)btnClick:(UIButton *)sender
{
    
    if (_selectIndex == sender.tag - 200) {
        return;
    }
    
    _selectIndex = sender.tag - 200;
    NSArray *itemsArray = @[@"本地城镇",@"本地农村",@"外地城镇",@"外地农村"];
    self.lb_cityType.text = itemsArray[_selectIndex];
    CGFloat leftORRightDistance = 25 * WIDTHRADIU;
    CGFloat middleDistance = 25 * WIDTHRADIU;
    CGFloat btnWidth = (ScreenWidth - leftORRightDistance * 2 - (itemsArray.count - 1)*middleDistance)/itemsArray.count;
    UIView *view = [self.residenceView viewWithTag:2000];
    for (UIButton *btn in self.btnArray) {
        if (btn == sender) {
           
            [btn setTitleColor:K_MainColor forState:UIControlStateNormal];
            [UIView animateWithDuration:0.2 animations:^{
                
                
                view.frame = CGRectMake(25*WIDTHRADIU + self->_selectIndex * (btnWidth + middleDistance), 38*WIDTHRADIU, btnWidth, 2*WIDTHRADIU);
            }];
            
            
            [self reloadUI:self.dataModel.wxyj.count > 1 ? YES : NO];
        } else {
            [btn setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
            
        }
    }
    
    
    
}

- (void)selectBtnClick:(UIButton *)sender
{
    
//    InsuredMemberAddViewController *InsuredMemberVC = [[InsuredMemberAddViewController alloc]init];
//    InsuredMemberVC.title = @"新增参保人";
//    [self.navigationController pushViewController:InsuredMemberVC animated:YES];
//
//    return;
    
    if (sender == _btn_city) {
        if (self.citysArray.count == 0) {
            
            [self getSocialInsuranceCitysRequest];
            return;
        }
        
        [self.locationView showWithAnimation:YES];
        WeakSelf
        self.locationView.chooseFinish = ^(PayCityModel * _Nonnull model) {
            weakSelf.lb_city.text = model.name;
            if (self->_selectCity_code != model.Id) {
                self->_selectCity_code = model.Id;
                [weakSelf getSheBaoDataRequest];
            }
            
        };
//        [CYCitySelectedView showCityViewWithResultBlock:^(NSString * _Nonnull selectCity) {
//            if (selectCity) {
//                self.lb_city.text = selectCity;
//            }
//        }];
       
    }else if (sender == _btn_cityType){
        [CityTypeSelectView showCityTypeViewWithResultBlock:^(NSString * _Nonnull selectCityType) {
            if (selectCityType) {
                self.lb_cityType.text = selectCityType;
                for (UIButton *btn in self.btnArray) {
                    if ([btn.titleLabel.text isEqualToString:selectCityType]) {
                        [self btnClick:btn];
                    }
                }
            }
        }];
    }else if (sender == _btn_ssPlan){
        [CityTypeSelectView show4WithArray:self.dataModel.wxyj block:^(wxyjModel * _Nonnull model) {
            if (model) {
                self.lb_ssPlan.text = model.shebao_type;
                
                self->WXYModel = model;
                [self reloadUI:self.dataModel.wxyj.count > 1 ? YES:NO];
                
            }
        }];
    }
}

- (void)quickClick:(UIButton *)sender
{
   
    
  
    WeakSelf
    if ([PayUserInfoManager sharedManager].model) {
         
        if ([PayUserInfoManager sharedManager].model.userList.count == 0) {
            
            InsuredMemberAddViewController *vc = [[InsuredMemberAddViewController alloc]init];
            vc.title = @"增加参保人";
            vc.sbmodel = self.dataModel;
            vc.selectCity_code = _selectCity_code;
            vc.selectCityName = self.lb_city.text;
            vc.hukou_type = [NSString stringWithFormat:@"%d",_selectIndex+1];
            vc.hukou = self.lb_cityType.text;
            vc.citys = self.citysArray;
            vc.wModel = WXYModel;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
             
            InsuredMemberSelectViewController *vc = [[InsuredMemberSelectViewController alloc]init];
            vc.title = @"选择人员";
            vc.model = self.dataModel;
            vc.selectCity_code = _selectCity_code;
            vc.selectCityName = self.lb_city.text;
            vc.hukou_type = [NSString stringWithFormat:@"%d",_selectIndex+1];
            vc.hukou = self.lb_cityType.text;
            vc.citys = self.citysArray;
            vc.wModel = WXYModel;
            [self.navigationController pushViewController:vc animated:NO];
        }
    }else{
        [NetworkTokenRequest getTokenSuccess:^(BOOL success) {
            if (success) {
                [weakSelf quickClick:sender];
            }else{
                [SVProgressHUD showErrorWithStatus:@"请求失败"];
            }
        }];
    }
    
}

- (void)checkDetailInfoClick:(UITapGestureRecognizer *)tap
{
    
    Web2ViewController * vc = [Web2ViewController new];
    vc.title= @"社保计算器";
    vc.skipUrl = [NSURL URLWithString:@"http://www.wodeshebao.com/calc/index.html"];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)rightBtnClick:(UIButton *)sender {
    
    WeakSelf
    if ([PayUserInfoManager sharedManager].model) {
        PayHistoryController* vc = [PayHistoryController new];
        vc.title = @"缴费记录";
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        return;
       
    }else{
        [NetworkTokenRequest getTokenSuccess:^(BOOL success) {
            if (success) {
                [weakSelf rightBtnClick:sender];
            }else{
                [SVProgressHUD showErrorWithStatus:@"请求失败"];
            }
        }];
    }
    
    
}

#pragma mark - 社保机构
- (void)goToSheBaoOrgsVC
{
    NSString*city = [[NSUserDefaults standardUserDefaults]objectForKey:@"locationCity"];
    NSString*county = [[NSUserDefaults standardUserDefaults]objectForKey:@"locationCounty"];
     if ([NSString blankString:city]) {
         city = @"北京市";
         county = @"朝阳区";
     }
    NSString*url = [NSString stringWithFormat:@"http://nginx.weface.com.cn/appH5/government/lib/ssi.html?city=%@",city];
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    WebViewController *tc=[WebViewController new];
    tc.URL =[NSURL URLWithString:url];
    tc.janalytics = @"社保机构";
    [self.navigationController pushViewController:tc animated:YES];
}


#pragma mark -  判断是否是同一天
- (BOOL)isSameDay:(NSDate*)date1 date2:(NSDate*)date2
{
    NSCalendar* calendar = [NSCalendar currentCalendar];
    unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
    NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
    return [comp1 day] == [comp2 day] &&
    [comp1 month] == [comp2 month] &&
    [comp1 year] == [comp2 year];
}

#pragma mark - getters and setters
- (SelectLocationView *)locationView
{
    if (!_locationView) {
        _locationView = [[SelectLocationView alloc]initWithProvinceArray:self.citysArray];
    }
    return _locationView;
}
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 45 * WIDTHRADIU)];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight+20* WIDTHRADIU);
        _scrollView.showsHorizontalScrollIndicator = NO;
        [self.view addSubview:self.topView];
    }
    return _scrollView;
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, SCREEN_HEIGHT - cl_kNavigationBarHeight - 51 * WIDTHRADIU) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableHeaderView = self.topView;
        self.topView.autoresizingMask = UIViewAutoresizingNone;
        
        [_tableView registerClass:[SocialSecurityPaymentTableViewCell class] forCellReuseIdentifier:@"cell"];
        [_tableView registerNib:[UINib nibWithNibName:@"SSPayment2TableViewCell" bundle:nil] forCellReuseIdentifier:@"SSPayment2TableViewCell"];
        _tableView.tableFooterView = [UIView new];
        _tableView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    }
    return _tableView;
}

- (UIView *)topView
{
    if (!_topView) {
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 296 + 45)];
       
        _topView.backgroundColor = [UIColor colorWithHex:0xf5f5f5];
        [_topView addSubview:self.topbackView];
        [_topView addSubview:self.lb_title];
        [_topView addSubview:self.lb_subTitle];
        [_topView addSubview:self.cardView];
        [_topView addSubview:self.img_message];
        [_topView addSubview:self.lb_message];
        [_topView addSubview:self.residenceView];
        [_topView addSubview:self.backView_TotalSocialSecurityExpense];
        [_topView addSubview:self.lb_TotalSocialSecurityExpenseTitle];
        [_topView addSubview:self.lb_TotalSocialSecurityExpense];
        [_topView addSubview:self.lineView2];
        
        [self.topbackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.offset(0);
            make.height.offset(117);
        }];
        
        [self.lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.offset(15 );
               make.left.offset(20 );
               make.height.offset(17);
        }];
           
        [self.lb_subTitle mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.lb_title.mas_bottom).offset(8);
               make.left.equalTo(self.lb_title);
               make.height.offset(12);
        }];
        
        [self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.lb_subTitle.mas_bottom).offset(20);
            make.left.offset(15);
            make.right.offset(-15);
            make.height.offset(135);
        }];
        
        
           [self.img_message mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.lb_message.mas_top).offset(2);
               make.left.offset(35);
               make.width.height.offset(11);
           }];
           
           [self.lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
              make.top.equalTo(self.cardView.mas_bottom).offset(10);
               make.left.equalTo(self.img_message.mas_right).offset(2);
               make.right.offset(-35);
               make.height.mas_greaterThanOrEqualTo(12);
           }];
           
           [self.residenceView mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.lb_message.mas_bottom).offset(15);
               make.left.right.offset(0);
               make.height.offset(50);
           }];
         [self.lb_TotalSocialSecurityExpenseTitle mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.residenceView.mas_bottom).offset(17);
                make.left.offset(23);
                make.height.offset(15);
            }];
            
            [self.lb_TotalSocialSecurityExpense mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.lb_TotalSocialSecurityExpenseTitle);
                make.right.offset(-25);
            }];
            
            [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.offset(0);
                make.left.offset(10);
                make.right.offset(-10);
                make.height.offset(0.5);
            }];
            
        
        
        
    }
    return _topView;
}

- (UIView *)topbackView
{
    if (!_topbackView) {
        _topbackView = [[UIView alloc]init];
        _topbackView.backgroundColor = K_MainColor;
    }
    return _topbackView;
}

- (UILabel *)lb_title
{
    if (!_lb_title) {
        _lb_title = [[UILabel alloc]init];
        _lb_title.text = @"自助缴纳社保 | 按当地最低标准缴纳";
        _lb_title.textColor = [UIColor whiteColor];
        _lb_title.font = [UIFont systemFontOfSize:17];
    }
    return _lb_title;
}

- (UILabel *)lb_subTitle
{
    if (!_lb_subTitle) {
        _lb_subTitle = [[UILabel alloc]init];
        _lb_subTitle.text = @"服务费: 每月-元(通道服务费+增值税费)";
        _lb_subTitle.textColor = [UIColor whiteColor];
        _lb_subTitle.font = [UIFont systemFontOfSize:12];
    }
    return _lb_subTitle;
}

- (UIView *)cardView
{
    if (!_cardView) {
        _cardView = [[UIView alloc]init];
        _cardView.backgroundColor = [UIColor whiteColor];
        _cardView.layer.cornerRadius = 10;
        //_cardView.layer.masksToBounds = YES;
        [_cardView addSubview:self.lb_cityTitle];
        [_cardView addSubview:self.lb_city];
        [_cardView addSubview:self.img_arrow];
        [_cardView addSubview:self.btn_city];
        
        [_cardView addSubview:self.lineView1];
        
        [_cardView addSubview:self.planView];
        
        [_cardView addSubview:self.lb_cityTypeTitle];
        [_cardView addSubview:self.lb_cityType];
        [_cardView addSubview:self.img_arrow2];
        [_cardView addSubview:self.btn_cityType];
        
        
        
           [self.lb_cityTitle mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.offset(15);
               make.left.offset(20);
               make.height.offset(15);
           }];
           [self.lb_city mas_makeConstraints:^(MASConstraintMaker *make) {
               make.centerY.equalTo(self.lb_cityTitle);
               make.left.equalTo(self.lb_cityTitle.mas_right).offset(10);
               make.height.offset(15);
           }];
           [self.img_arrow mas_makeConstraints:^(MASConstraintMaker *make) {
               make.centerY.equalTo(self.lb_city);
               make.right.offset(-20);
           }];
           
           [self.btn_city mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self->_cardView);
               make.left.offset(90);
               make.right.equalTo(self.img_arrow);
               make.height.offset(45);
           }];
           
           
           [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.lb_cityTitle.mas_bottom).offset(15);
               make.left.offset(10);
               make.right.offset(-10);
               make.height.offset(0.5);
           }];
           
           
           
           [self.planView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.lineView1.mas_bottom);
                make.left.right.offset(0);
                make.height.offset(45);
           }];
           
           
           [self.lb_cityTypeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.planView.mas_bottom).offset(15);
               make.left.offset(20);
               make.height.offset(15);
           }];
           [self.lb_cityType mas_makeConstraints:^(MASConstraintMaker *make) {
               make.centerY.equalTo(self.lb_cityTypeTitle);
               make.left.equalTo(self.lb_cityTypeTitle.mas_right).offset(10);
               make.height.offset(15);
           }];
           [self.img_arrow2 mas_makeConstraints:^(MASConstraintMaker *make) {
               make.centerY.equalTo(self.lb_cityTypeTitle);
               make.right.offset(-20);
           }];
           
           [self.btn_cityType mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.planView.mas_bottom);
               make.left.offset(90);
               make.right.equalTo(self.img_arrow2);
               make.height.offset(45);
           }];
        
        
       
    }
    return _cardView;
}


- (UILabel *)lb_cityTitle
{
    if (!_lb_cityTitle) {
        _lb_cityTitle = [[UILabel alloc]init];
        _lb_cityTitle.textColor = [UIColor colorWithHex:0x808080];
        _lb_cityTitle.text = @"参保城市:";
        _lb_cityTitle.font = [UIFont systemFontOfSize:15];
    }
    return _lb_cityTitle;
}

- (UILabel *)lb_city
{
    if (!_lb_city) {
        _lb_city = [[UILabel alloc]init];
        _lb_city.textColor = [UIColor colorWithHex:0x4d4d4d];
        _lb_city.text = @"上海";
        _lb_city.font = [UIFont systemFontOfSize:15];
    }
    return _lb_city;
}

- (UIImageView *)img_arrow
{
    if (!_img_arrow) {
        _img_arrow = [[UIImageView alloc]init];
        _img_arrow.image = [UIImage imageNamed:@"my_wallet_Withdrawaloffunds_Binding_arrow_normal"];
    }
    return _img_arrow;
}

- (UIButton *)btn_city
{
    if (!_btn_city) {
        _btn_city = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_btn_city addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _btn_city;
}


- (UIView *)lineView1
{
    if (!_lineView1) {
        _lineView1 = [[UIView alloc]init];
        _lineView1.backgroundColor = [UIColor colorWithHex:0xcccccc];
    }
    return _lineView1;
}




- (UIView *)planView
{
    if (!_planView) {
        _planView = [[UIView alloc]init];
        _planView.backgroundColor = [UIColor whiteColor];
        [_planView addSubview:self.lb_ssPlanTitle];
        [_planView addSubview:self.lb_ssPlan];
        [_planView addSubview:self.img_arrow4];
        [_planView addSubview:self.lineView4];
        [_planView addSubview:self.btn_ssPlan];
        
        [self.lb_ssPlanTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(15);
            make.left.offset(20);
            make.height.offset(15);
        }];
        [self.lb_ssPlan mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.lb_ssPlanTitle);
            make.left.equalTo(self.lb_ssPlanTitle.mas_right).offset(10);
            make.height.offset(15);
        }];
        [self.img_arrow4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.lb_ssPlan);
            make.right.offset(-20);
        }];

        [self.btn_ssPlan mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self->_planView);
            make.left.offset(90);
            make.right.equalTo(self.img_arrow4);
            make.height.offset(45);
        }];


        [self.lineView4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.lb_ssPlanTitle.mas_bottom).offset(15);
            make.left.offset(10);
            make.right.offset(-10);
            make.height.offset(0.5);
        }];
    }
    return _planView;
}


- (UILabel *)lb_ssPlanTitle
{
    if (!_lb_ssPlanTitle) {
        _lb_ssPlanTitle = [[UILabel alloc]init];
        _lb_ssPlanTitle.textColor = [UIColor colorWithHex:0x808080];
        _lb_ssPlanTitle.text = @"参保方案:";
        _lb_ssPlanTitle.font = [UIFont systemFontOfSize:15];
    }
    return _lb_ssPlanTitle;
}

- (UILabel *)lb_ssPlan
{
    if (!_lb_ssPlan) {
        _lb_ssPlan = [[UILabel alloc]init];
        _lb_ssPlan.textColor = [UIColor colorWithHex:0x4d4d4d];
        _lb_ssPlan.text = @"";
        _lb_ssPlan.font = [UIFont systemFontOfSize:15];
    }
    return _lb_ssPlan;
}

- (UIImageView *)img_arrow4
{
    if (!_img_arrow4) {
        _img_arrow4 = [[UIImageView alloc]init];
        _img_arrow4.image = [UIImage imageNamed:@"my_wallet_Withdrawaloffunds_Binding_arrow_normal"];
    }
    return _img_arrow4;
}

- (UIButton *)btn_ssPlan
{
    if (!_btn_ssPlan) {
        _btn_ssPlan = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_btn_ssPlan addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _btn_ssPlan;
}


- (UIView *)lineView4
{
    if (!_lineView4) {
        _lineView4 = [[UIView alloc]init];
        _lineView4.backgroundColor = [UIColor colorWithHex:0xcccccc];
    }
    return _lineView4;
}




- (UILabel *)lb_cityTypeTitle
{
    if (!_lb_cityTypeTitle) {
        _lb_cityTypeTitle = [[UILabel alloc]init];
        _lb_cityTypeTitle.textColor = [UIColor colorWithHex:0x808080];
        _lb_cityTypeTitle.text = @"参保性质:";
        _lb_cityTypeTitle.font = [UIFont systemFontOfSize:15];
    }
    return _lb_cityTypeTitle;
}

- (UILabel *)lb_cityType
{
    if (!_lb_cityType) {
        _lb_cityType = [[UILabel alloc]init];
        _lb_cityType.textColor = [UIColor colorWithHex:0x4d4d4d];
        _lb_cityType.text = @"本地城镇";
        _lb_cityType.font = [UIFont systemFontOfSize:15];
        
    }
    return _lb_cityType;
}
- (UIImageView *)img_arrow2
{
    if (!_img_arrow2) {
        _img_arrow2 = [[UIImageView alloc]init];
        _img_arrow2.image = [UIImage imageNamed:@"my_wallet_Withdrawaloffunds_Binding_arrow_normal"];
    }
    return _img_arrow2;
}

- (UIButton *)btn_cityType
{
    if (!_btn_cityType) {
        _btn_cityType = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_cityType addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _btn_cityType;
}

- (UIImageView *)img_message
{
    if (!_img_message) {
        _img_message = [[UIImageView alloc]init];
        _img_message.image = [UIImage imageNamed:@"Socialsecuritypayment_Monthprompt_normal"];
    }
    return _img_message;
}

- (UILabel *)lb_message
{
    if (!_lb_message) {
        _lb_message = [[UILabel alloc]init];
        _lb_message.text = @"目前可购买2019年8月及之后月份,截止时间为8月9号";
        _lb_message.textColor = [UIColor colorWithHex:0xb3b3b3];
        _lb_message.font = [UIFont systemFontOfSize:12];
        _lb_message.numberOfLines = 0;
    }
    return _lb_message;
}

- (UIView *)residenceView
{
    if (!_residenceView) {
        _residenceView = [[UIView alloc]init];
        _residenceView.backgroundColor = [UIColor whiteColor];
        
        NSArray *itemsArray = @[@"本地城镇",@"本地农村",@"外地城镇",@"外地农村"];
        CGFloat leftORRightDistance = 25;
        CGFloat middleDistance = 25;
        CGFloat btnWidth = (ScreenWidth - leftORRightDistance * 2 - (itemsArray.count - 1)*middleDistance)/itemsArray.count;
        for (int i = 0; i < itemsArray.count; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(25 + (btnWidth + middleDistance) * i, 0, btnWidth, 50);
            [button setTitle:itemsArray[i] forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
            [button setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = 200 + i;
            [_residenceView addSubview:button];
            [self.btnArray addObject:button];
        }
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(25, 38, btnWidth, 2)];
        lineView.backgroundColor = K_MainColor;
        lineView.tag = 2000;
        [_residenceView addSubview:lineView];
        
        //阴影
        _residenceView.layer.shadowColor = K_MainColor.CGColor;
        _residenceView.layer.shadowOffset = CGSizeMake(0, 1);
        _residenceView.layer.shadowOpacity = 0.2;
        _residenceView.layer.shadowRadius = 1 ;
    }
    return _residenceView;
}

- (NSMutableArray *)btnArray
{
    if (!_btnArray) {
        _btnArray = [[NSMutableArray alloc]init];
    }
    return _btnArray;
}

- (UILabel *)lb_TotalSocialSecurityExpenseTitle
{
    if (!_lb_TotalSocialSecurityExpenseTitle) {
        _lb_TotalSocialSecurityExpenseTitle = [[UILabel alloc]init];
        _lb_TotalSocialSecurityExpenseTitle.text = @"社保总费用";
        _lb_TotalSocialSecurityExpenseTitle.textColor = [UIColor colorWithHex:0x4d4d4d];
        _lb_TotalSocialSecurityExpenseTitle.font = [UIFont systemFontOfSize:15 ];
    }
    return _lb_TotalSocialSecurityExpenseTitle;
}

- (UILabel *)lb_TotalSocialSecurityExpense
{
    if (!_lb_TotalSocialSecurityExpense) {
        _lb_TotalSocialSecurityExpense = [[UILabel alloc]init];
        _lb_TotalSocialSecurityExpense.text = @"元/月";
        _lb_TotalSocialSecurityExpense.textColor = [UIColor colorWithHex:0xf85531];
        _lb_TotalSocialSecurityExpense.font = [UIFont systemFontOfSize:15];
    }
    return _lb_TotalSocialSecurityExpense;
}

- (UIView *)backView_TotalSocialSecurityExpense
{
    if (!_backView_TotalSocialSecurityExpense) {
        _backView_TotalSocialSecurityExpense = [[UIView alloc]init];
        _backView_TotalSocialSecurityExpense.backgroundColor = [UIColor whiteColor];
    }
    return _backView_TotalSocialSecurityExpense;
}

- (UIView *)lineView2
{
    if (!_lineView2) {
        _lineView2 = [[UIView alloc]init];
        _lineView2.backgroundColor = [UIColor colorWithHex:0xcccccc];
    }
    return _lineView2;
}



- (UIView *)footerView
{
    if (!_footerView) {
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
        _footerView.backgroundColor = [UIColor whiteColor];
        
        [_footerView addSubview:self.lineView3];
        [_footerView addSubview:self.lb_check];
        [_footerView addSubview:self.img_arrow3];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(checkDetailInfoClick:)];
        [_footerView addGestureRecognizer:tap];
        
        
    }
    return _footerView;
}

- (UIView *)lineView3
{
    if (!_lineView3) {
        _lineView3 = [[UIView alloc]init];
        _lineView3.backgroundColor = [UIColor colorWithHex:0xcccccc];
    }
    return _lineView3;
}

- (UILabel *)lb_check
{
    if (!_lb_check) {
        _lb_check = [[UILabel alloc]init];
        _lb_check.text = @"查看详情";
        _lb_check.textColor = [UIColor colorWithHex:0x808080];
    }
    return _lb_check;
}

- (UIImageView *)img_arrow3
{
    if (!_img_arrow3) {
        _img_arrow3 = [[UIImageView alloc]init];
        _img_arrow3.image = [UIImage imageNamed:@"my_wallet_Withdrawaloffunds_Binding_arrow_normal"];
    }
    return _img_arrow3;
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT - 50  , ScreenWidth,  50 )];
        _bottomView.backgroundColor = [UIColor whiteColor];
        _bottomView.layer.shadowColor = K_MainColor.CGColor;
        _bottomView.layer.shadowOffset = CGSizeMake(0, -1);
        _bottomView.layer.shadowOpacity = 0.2;
        _bottomView.layer.shadowRadius = 1;
        [_bottomView addSubview:self.btn_kefu];
        [_bottomView addSubview:self.btn_phone];
        [_bottomView addSubview:self.bottomBtnBackView];
    }
    return _bottomView;
}


- (UIButton *)btn_kefu
{
    if (!_btn_kefu) {
        _btn_kefu = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_kefu setTitle:@"联系客服" forState:UIControlStateNormal];
        [_btn_kefu setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
        [_btn_kefu setImage:[UIImage imageNamed:@"Socialsecuritypayment_customerservice_normal"] forState:UIControlStateNormal];
        _btn_kefu.titleLabel.font = [UIFont systemFontOfSize:11 ];
        _btn_kefu.backgroundColor = [UIColor clearColor];
        [_btn_kefu addTarget:self action:@selector(chatClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_kefu;
}

- (UIButton *)btn_phone
{
    if (!_btn_phone) {
        _btn_phone = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_phone setTitle:@"拨打热线" forState:UIControlStateNormal];
        [_btn_phone setTitleColor:[UIColor colorWithHex:0x808080] forState:UIControlStateNormal];
        [_btn_phone setImage:[UIImage imageNamed:@"Socialsecuritypayment_Call_normal"] forState:UIControlStateNormal];
        [_btn_phone addTarget:self action:@selector(phoneClick:) forControlEvents:UIControlEventTouchUpInside];
        _btn_phone.titleLabel.font = [UIFont systemFontOfSize:11];
        _btn_phone.backgroundColor = [UIColor clearColor];
    }
    return _btn_phone;
}

- (UIView *)bottomBtnBackView
{
    if (!_bottomBtnBackView) {
        _bottomBtnBackView = [[UIView alloc]init];
        _bottomBtnBackView.backgroundColor = [UIColor redColor];
        _bottomBtnBackView.layer.cornerRadius = 18;
        _bottomBtnBackView.layer.masksToBounds = YES;
        [_bottomBtnBackView addSubview:self.btn_left];
        [_bottomBtnBackView addSubview:self.btn_right];
    }
    return _bottomBtnBackView;
}

- (UIButton *)btn_left
{
    if (!_btn_left) {
        _btn_left = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_left.backgroundColor = [UIColor colorWithHex:0x1db46e];
        [_btn_left setTitle:@"一键续保" forState:UIControlStateNormal];
        [_btn_left setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_left.titleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _btn_left;
}

- (UIButton *)btn_right
{
    if (!_btn_right) {
        _btn_right = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_right.backgroundColor = K_MainColor;
        [_btn_right setTitle:@"立即参保" forState:UIControlStateNormal];
        [_btn_right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_right.titleLabel.font = [UIFont systemFontOfSize:14];
        [_btn_right addTarget:self action:@selector(quickClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_right;
}


/*
#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
