//
//  SaveProductListController.m
//  Open
//
//  Created by 雷俊博 on 2020/7/27.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "SaveProductListController.h"
#import "CarouseViewPlus.h"
#import "ScrollVerticalView.h"
#import "ProductListCell.h"
#import "FooterView.h"
#import "ProductDetailController.h"
#import "SaveHomeSectionHeaderView.h"

//银数
#import "SaveProductModel.h"

//比财
#import "SaveBCProductModel.h"
#import "SaveBCProductInfoModel.h"

#import "ProductPurchaseController.h"
#import "OPenAccountController.h"


//test
#import "RechargeProcessingController.h"
#import "HoldingDetailController.h"
#import "SaveWithDrawController.h"
#import "SaveOrderListController.h"
#import "ElectronicAccountController.h"
#import "SMSVerificationController.h"
#import "ElectAccountOPenSuccessController.h"

#import "AiDaAlertView.h"
#import "CTAPIBaseManager.h"

#import "KKSaveActivityPackageView.h"

#import "BannerAdObjectModel.h"

@interface SaveProductListController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>
{
     CarouseViewPlus *carouseViewPlus;
    ScrollVerticalView* radioView;
    
    BOOL postNoti;
}

@property (nonatomic, strong)UITableView* tableView;

@property (nonatomic, strong)UIView* headerView;

@property (nonatomic, strong)FooterView* footerView;

@property (nonatomic, strong)SaveProductModel* currentModel;

@property (nonatomic, strong)NSMutableArray* proList;

@property (nonatomic, assign)BOOL showFuli;

@end

@implementation SaveProductListController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar navBarBackGroundColor:[UIColor colorWithHex:0x137ef6] image:nil isOpaque:YES];//颜色
       
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:0 target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:bar];
    
    if (!postNoti) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KKSBGETBalanceNotificationName object:nil];
        postNoti = YES;
    }
    
    [GTCountSDK trackCountEvent:@"save_homeProductListCount" withArgs:@{}];//个推统计
    
   
    //基金活动
    if (self.showFunActivity) {
        self.showFunActivity = NO;
        [self showBCFundActivity];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.proList = [NSMutableArray array];
    
    [self configNav];
    
    [self.view addSubview:self.tableView];
    
    [self configTabView];
    
     
    [self getProductListRequest];
    
    [self getBCProductListRequest];
   
    //检测到活动通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(detectedActivityNoti:) name:KKSBWDActivityNotificationName object:nil];
     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(detected2ActivityNoti:) name:KKSBWDDetailActivityNotificationName object:nil];
    
    NSString* provinceName = [Tools ValidblankString: [UserDefault objectForKey:@"locationProvince"]];
    NSString* cityName = [Tools ValidblankString: [UserDefault objectForKey:@"locationCity"]];
    NSString* countyName = [Tools ValidblankString: [UserDefault objectForKey:@"locationCounty"]];
    [self getActivityInfoRequestWithProvince:provinceName cityName:cityName countryName:countyName];
    [self getBannersRequestWithProvince:provinceName cityName:cityName countryName:countyName];
   
    
}

- (void)configNav
{
    UIButton* backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(0, 0, 60, 44);
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:8];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem*backItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    
    self.navigationItem.leftBarButtonItem = backItem;
    
    
//    UIButton* bcBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [bcBtn setTitle:@"旧版存钱罐" forState:UIControlStateNormal];
//    bcBtn.titleLabel.font = [UIFont systemFontOfSize:15];
//    [bcBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    bcBtn.frame = CGRectMake(0, 0, 60, 44);
//    [bcBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:8];
//    [bcBtn addTarget:self action:@selector(bcBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//
//    UIBarButtonItem*bcBtnItem = [[UIBarButtonItem alloc]initWithCustomView:bcBtn];
//
//    self.navigationItem.rightBarButtonItem = bcBtnItem;
    
    
}

- (void)configTabView
{
    self.tableView.tableHeaderView = self.headerView;
    
    self.tableView.tableFooterView = self.footerView;
}

#pragma mark - 爱达api请求
- (NSDictionary *)aiDaTokenRequestPara
{
    NSDictionary* params = @{
        @"loginId":[NSNumber numberWithInteger:[getPeopleID PeopleID]].stringValue,
        @"telephone":[getPeopleID PeopleIphoneNmber]
    };
    return params;
}

- (void)aiDaTokenRequest:(void (^)(bool success, NSString*token))response
{
    NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaConfig],AiDaTokenRequest];
    NSLog(@"爱达token的url:%@",url);
    
    NSLog(@"params:%@",[self aiDaTokenRequestPara]);
    
    [NetworkRequest Get3:url Params:[self aiDaTokenRequestPara] Success:^(id _Nonnull responseObject) {
        
        NSLog(@"responseObject:%@",responseObject);
        
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                
                NSString*token = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
                
                response(YES,token);
                return;
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
        [KKLoadingAnimationView dismiss];
    } Failure:^(NSError * _Nonnull error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
}

- (NSDictionary *)aidaUrlRequestPara
{
    NSDictionary* params = @{
        @"deviceid":[[[[UIDevice currentDevice] identifierForVendor] UUIDString]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]],
        @"mobile":[[getPeopleID PeopleIphoneNmber] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]],
        @"uid":[NSNumber numberWithInteger:[getPeopleID PeopleID]].stringValue
    };
  
    return params;
}

- (void)aidaUrlRequestWithToken:(NSString *)token
{
    NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaUrlConfig],AiDaUrlRequest];
    NSLog(@"爱达url的url:%@",url);
    
    NSLog(@"params:%@",[self aidaUrlRequestPara]);
    
    [NetworkRequest Post5:url Params:[self aidaUrlRequestPara] Token:token Success:^(id  _Nonnull responseObject) {
        
         NSLog(@"responseObject:%@",responseObject);
        
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                
                NSString*url = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
                
//                NSMutableCharacterSet *lastSet = [[NSMutableCharacterSet alloc] init];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"-_.!~*;/?:@&=$,#"]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
//
//                url = [url stringByAddingPercentEncodingWithAllowedCharacters:lastSet];
                
                if ([self.navigationController.visibleViewController isKindOfClass:[SaveProductListController class]]) {
                    Web2ViewController * vc = [Web2ViewController new];
                    vc.title= @"智能问诊";
                    vc.skipUrl = [NSURL URLWithString:url];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                
              
                
                
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
        
    } Failure:^(NSError * _Nonnull error) {
        
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
        
    }];
}



#pragma mark - 比财

- (NSDictionary *)getBCRequestParam
{
    NSDictionary *params = @{
        @"phone":[[getPeopleID PeopleIphoneNmber] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]],
        @"id":[NSNumber numberWithInteger:[getPeopleID PeopleID]].stringValue
    };
    return params;
}

- (void)getBCRequest:(NSString *)token
{
   NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaUrlConfig],BCUrlRequest];
    NSLog(@"比财url的url:%@",url);
    
    NSLog(@"params:%@",[self getBCRequestParam]);
    
    [NetworkRequest Get2:url Params:[self getBCRequestParam] Token:token Success:^(id  _Nonnull responseObject) {
        
         NSLog(@"responseObject:%@",responseObject);
                
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                
                NSString*url = [NSString stringWithFormat:@"%@&appBarHide=hide",responseObject[@"result"]];
                
//                NSMutableCharacterSet *lastSet = [[NSMutableCharacterSet alloc] init];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"-_.!~*;/?:@&=$,#"]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
//
//                url = [url stringByAddingPercentEncodingWithAllowedCharacters:lastSet];
                
                if ([self.navigationController.visibleViewController isKindOfClass:[SaveProductListController class]]) {
                    Web2ViewController * vc = [Web2ViewController new];
                    vc.title= @"存钱罐";
                    vc.skipUrl = [NSURL URLWithString:url];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                
              
                
                
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
        
        
    } Failure:^(NSError * _Nonnull error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
}


#pragma mark - 获取产品列表
//银数
- (void)getProductListRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSGetProductListRequest];
    NSLog(@"银数产品列表url:%@",url);
    
    //[KKLoadingAnimationView show];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:nil headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       //[KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString* describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            SaveProductModel*model = [SaveProductModel mj_objectWithKeyValues:dic];
            NSData *archiveCarPriceData = [NSKeyedArchiver archivedDataWithRootObject:model];
            [[NSUserDefaults standardUserDefaults]setObject:archiveCarPriceData forKey:@"productInfo"];
            [[NSUserDefaults standardUserDefaults]synchronize];
            NSLog(@"CURRNO:%@",model.CURRNO);
            self.currentModel = model;
            [self.tableView reloadData];
            
        }else{
            NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
            NSString*code = nil;
            NSString*message = nil;
            if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                code = [NSString stringWithFormat:@"%@",dic[@"code"]];
            }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
            }
            
            if (code) {
                message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                
                if (message) {
                   // [SVProgressHUD showErrorWithStatus:message];
                }else{
                    //[SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
            }else{
                //[SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
            
            
    
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       //[KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];

}

//比财
- (void)getBCProductListRequest {
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCGetProductListRequest];
    NSLog(@"比财产品列表url:%@",url);
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    
    NSLog(@"params:%@",params);
    
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            self.proList = [SaveBCProductModel mj_objectArrayWithKeyValuesArray:objc[@"result"][@"prdList"]];
            
            
            
        }else{
            [self alertShow:describe];
        }
        
        [self.tableView reloadData];
        
    } Failure:^(NSError* error) {
        
        NSLog(@"error:%@",error);
        
    }];
    
}
#pragma mark - 提示
- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" 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:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}

#pragma mark - 比财产品详情
- (void)getBiCaiDetailInfoRequest:(SaveBCProductModel *)model {
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCGetProductInfoRequest];
    NSLog(@"比财产品详情url:%@",url);
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:[NSString stringWithFormat:@"%ld",model.prdId] forKey:@"productId"];
    
    
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            SaveBCProductInfoModel* infoModel = [SaveBCProductInfoModel mj_objectWithKeyValues:objc[@"result"]];

            ProductDetailController*vc = [ProductDetailController new];
            vc.hidesBottomBarWhenPushed = YES;
            vc.title = @"产品详情";
            vc.bcInfoModel = infoModel;
            vc.type = SaveFromTypeBiCai;
            vc.bcModel = model;
            vc.showFuli = self.showFuli;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else{
            [Tools showMessage:describe];
        }

        [self.tableView reloadData];
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 获取比财h5产品详情链接
- (void)getBCProductDetailInfoH5Request:(NSString *)token orgId:(SaveBCProductModel *)model {
    NSString* url = [NSString stringWithFormat:@"%@/20200228/login/bicai/hb/org",[NetworkConfig ipYDConfig]];
    NSLog(@"比财h5产品详情url:%@",url);
    NSDictionary *params = @{
        @"phone":[[getPeopleID PeopleIphoneNmber] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]],
        @"orgId":@(model.orgId),
        @"productId":@(model.prdId)
    };
    
    NSLog(@"params:%@",params);
    
    [NetworkRequest Get2:url Params:params Token:token Success:^(id  _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
         NSLog(@"responseObject:%@",responseObject);
                
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                
                Web2ViewController * vc = [Web2ViewController new];
                vc.title= @"存钱罐";
                vc.skipUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@&appBarHide=hide",responseObject[@"result"]]];
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
              
                
                
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
        
        
    } Failure:^(NSError * _Nonnull error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
}

#pragma mark - 存钱罐banner
- (void)getBannersRequestWithProvince:(NSString *)provinceName cityName:(NSString *)cityName countryName:(NSString *)countryName {
    NSString* address = nil;
    NSString*city = [UserDefault objectForKey:@"locationCity"];
    NSString*county = [UserDefault objectForKey:@"locationCounty"];
    if ((![Tools isBlankString:city]) && !([Tools isBlankString:county])) {
        address = [NSString stringWithFormat:@"%@$%@",city,county];
    }
    NSDictionary *params =@{
                            @"showType":@"701",
                            @"address":address ? address :@"",
                            @"versionId":[NSNumber numberWithInt:1054],
                            @"fromSys":@"2",
                            @"fromApp":@"kklife"
    };

      NSLog(@"params:%@",params);
    
      NSString * url =[IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/getNews"];
    NSLog(@"url:%@",url);
    
    [NetworkRequest SBAuthPost:url Params:params Success:^(id  _Nonnull responseObject) {
        
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject[@"code"] isEqualToNumber:@0]) {
            
            NSArray *results = responseObject[@"result"];
            
            if ([results isKindOfClass:[NSArray class]]) {
               
                NSArray* modelArray = [BannerAdObjectModel mj_objectArrayWithKeyValuesArray:results];
                
                [self->carouseViewPlus setup2SubviewPages:modelArray withCallbackBlock:^(BannerAdObjectModel *model) {
                    if (![Tools isBlankString:model.targetUrl]) {
                        NSString*version = nil;
                        NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
                        NSArray*vArr = [v componentsSeparatedByString:@"."];
                        
                        for (int i = 0; i < vArr.count; i++) {
                            if (version == nil) {
                                version = [NSString stringWithFormat:@"%@",vArr[i]];
                            }else{
                                version = [version stringByAppendingFormat:@"%@",vArr[i]];
                            }
                        }
                        if ([model.title isEqualToString:@"存钱罐拉新"] || [model.title isEqualToString:@"存钱罐活动"]) {
                            
                            NSString* url = [NSString stringWithFormat:@"%@?userId=%@&phone=%@&version=%@&appName=kksh",model.targetUrl,@([getPeopleID PeopleID]),[getPeopleID PeopleIphoneNmber],version];
                            
                            [self jumpToUrl:url andTitle:model.title];
                            
                        }else{
                            [self jumpToUrl:model.targetUrl andTitle:model.title];
                        }
                        
                        
                    }
                    
                }];
                
            }
            
            
        }
        
    } Failure:^(NSError * _Nonnull error) {
        
        NSLog(@"error:%@",error);
        
    }];
    
    
//    [CTAPIBaseManager POST6:url params:params completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
//        if ([responseObject[@"code"] isEqualToNumber:@0]) {
//
//            NSArray *results = responseObject[@"result"];
//
//            if ([results isKindOfClass:[NSArray class]]) {
//
//                NSArray* modelArray = [BannerAdObjectModel mj_objectArrayWithKeyValuesArray:results];
//
//                [self->carouseViewPlus setup2SubviewPages:modelArray withCallbackBlock:^(BannerAdObjectModel *model) {
//                    if (![Tools isBlankString:model.targetUrl]) {
//                        NSString*version = nil;
//                        NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//                        NSArray*vArr = [v componentsSeparatedByString:@"."];
//
//                        for (int i = 0; i < vArr.count; i++) {
//                            if (version == nil) {
//                                version = [NSString stringWithFormat:@"%@",vArr[i]];
//                            }else{
//                                version = [version stringByAppendingFormat:@"%@",vArr[i]];
//                            }
//                        }
//                        if ([model.title isEqualToString:@"存钱罐拉新"] || [model.title isEqualToString:@"存钱罐活动"]) {
//
//                            NSString* url = [NSString stringWithFormat:@"%@?userId=%@&phone=%@&version=%@&appName=kksh",model.targetUrl,@([getPeopleID PeopleID]),[getPeopleID PeopleIphoneNmber],version];
//
//                            [self jumpToUrl:url andTitle:model.title];
//
//                        }else{
//                            [self jumpToUrl:model.targetUrl andTitle:model.title];
//                        }
//
//
//                    }
//
//                }];
//
//            }
//
//
//        }
//
//
//    }];
}

#pragma mark - 请求是否弹框
- (void)getActivityInfoRequestWithProvince:(NSString *)provinceName cityName:(NSString *)cityName countryName:(NSString *)countryName
{
    
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    NSString* url = [NSString stringWithFormat:@"%@active/getActiveInfo",CoinsBaseUrl];
    NSDictionary*params = @{
        @"activeIndex":@"704",
        @"isplayVersionStr":version,
        @"fromSys":@"2",
        @"fromApp":@"kklife",
        @"provinceName":provinceName,
        @"cityName":cityName,
        @"countryName":countryName
    };
    
    NSLog(@"推广存钱罐活动url:%@",url);
    NSLog(@"params:%@",params);
    
    [CTAPIBaseManager GET:url params:params completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        
        if (error) {
            NSLog(@"error:%@",error);
            return;
        }
        NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"responseObject:%@",dic);
        NSString*code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        if ([code isEqualToString:@"0"]) {
            self.showFuli = YES;
            BOOL show = [UserDefault boolForKey:@"bcAcitvityHaveShow"];
            if (show) {
                return;
            }
            
            [UserDefault setBool:YES forKey:@"bcAcitvityHaveShow"];
            NSString* title = [NSString stringWithFormat:@"%@",dic[@"result"][@"activeTypeDes"]];
            NSString* message = [NSString stringWithFormat:@"%@",dic[@"result"][@"activeDes"]];
            NSString* activeUrl = [NSString stringWithFormat:@"%@",dic[@"result"][@"activeUrl"]];
            NSString*version = nil;
            NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
            NSArray*vArr = [v componentsSeparatedByString:@"."];
            
            for (int i = 0; i < vArr.count; i++) {
                if (version == nil) {
                    version = [NSString stringWithFormat:@"%@",vArr[i]];
                }else{
                    version = [version stringByAppendingFormat:@"%@",vArr[i]];
                }
            }
              
                [KKSaveActivityPackageView showViewWithVC:self title:title message:message block:^(BOOL success) {
                    NSLog(@"领取红包");
                    NSString* url = [NSString stringWithFormat:@"%@?userId=%@&phone=%@&version=%@&appName=kksh",activeUrl,@([getPeopleID PeopleID]),[getPeopleID PeopleIphoneNmber],version];
                    
                    [self jumpToUrl:url andTitle:@"存钱罐活动"];
                }];
                return;
            
        }
    }];
    
}

-(void)jumpToUrl:(NSString*)url andTitle:(NSString*)title
{
    
    WebVC *webvc = [[WebVC alloc]init];
    webvc.url = url;
    webvc.title = title;
    webvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webvc animated:YES];
    
}


#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y <= -cl_kNavigationBarHeight) {
        scrollView.contentOffset = CGPointMake(0, -cl_kNavigationBarHeight);
    }
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.currentModel.SUBPACKS.count > 0 ? 1 + self.proList.count  : self.proList.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    NSString*identify = @"cell";
    ProductListCell*cell = [tableView dequeueReusableCellWithIdentifier:identify];
    
    
    if (self.currentModel.SUBPACKS.count > 0) {
        if (indexPath.section == self.proList.count) {
            
            SaveSubProductModel*model = self.currentModel.SUBPACKS[0];
            
            cell.lb_bankName.text = [NSString stringWithFormat:@"定期存款 | 乌当农商银行 |%@",model.NOTE];
            cell.lb_rate.text = [NSString stringWithFormat:@"%.4lf%%",model.RATE.doubleValue];
            cell.lb_date.text = [self getYearAndMonthStrWithStr:model.STERM];
            cell.lb_message.text = [NSString stringWithFormat:@"%@元起购 | %@",model.MIN_AMT,[self getYearAndMonthStrWithStr:model.STERM]];
            
            if ([model.RET_PRD_CODE isEqualToString:@"36"]) {
                cell.lb_mark2.hidden = NO;
                cell.lb_mark2.text = @"按年派息";
            }else if ([model.RET_PRD_CODE isEqualToString:@"35"]){
                cell.lb_mark2.hidden = NO;
                cell.lb_mark2.text = @"按月派息";
            }else{
                cell.lb_mark2.hidden = YES;
            }
            
            if ([model.PRSTATUS isEqualToString:@"0"]) {
                cell.icon.hidden = YES;
            }else if ([model.PRSTATUS isEqualToString:@"1"]){
                cell.icon.hidden = NO;
                cell.icon.image = [UIImage imageNamed:@"save11"];
            }else if ([model.PRSTATUS isEqualToString:@"2"]){
                cell.icon.hidden = NO;
                cell.icon.image = [UIImage imageNamed:@"saveStop"];
            }
            
        }else{
            
            
            
            SaveBCProductModel* model = self.proList[indexPath.section];
            
            NSString*productTypeText = nil;
            
            if ([model.productType isEqualToString:@"1"]) {
                productTypeText = @"货币基金";
            }else if ([model.productType isEqualToString:@"2"]) {
                productTypeText = @"理财产品";
            }else if ([model.productType isEqualToString:@"3"]) {
                productTypeText = @"纯债产品";
            }else if ([model.productType isEqualToString:@"4"]) {
                productTypeText = @"银行存款";
            }else if ([model.productType isEqualToString:@"5"]) {
                productTypeText = @"保险理财";
            }else if ([model.productType isEqualToString:@"6"]) {
                productTypeText = @"投融资产品";
            }else if ([model.productType isEqualToString:@"7"]) {
                productTypeText = @"组合产品";
            }else{
                productTypeText = @"定期存款";
            }
            
            cell.lb_bankName.text = [NSString stringWithFormat:@"%@ | %@ |%@",productTypeText,model.orgName,model.prdName];
            cell.lb_rate.text = [NSString stringWithFormat:@"%.4lf%%",model.rate.doubleValue];
            cell.lb_date.text = [Tools isBlankString:model.periodName] ? model.productTypeDesc :model.periodName;
            cell.lb_message.text = [NSString stringWithFormat:@"%@起购 | %@",model.minAmountDesc,[Tools isBlankString:model.periodName] ? model.productTypeDesc :model.periodName];
           
            if ([Tools isBlankString:model.label]) {
                cell.lb_mark1.hidden = YES;
                cell.lb_mark2.hidden = YES;
            }else{
                NSArray* labels = [model.label componentsSeparatedByString:@","];
                if (labels.count == 0) {
                    cell.lb_mark1.hidden = YES;
                    cell.lb_mark2.hidden = YES;
                }else if (labels.count == 1) {
                    cell.lb_mark1.hidden = NO;
                    cell.lb_mark2.hidden = YES;
                    cell.lb_mark1.text = labels[0];
                }else{
                    cell.lb_mark1.hidden = NO;
                    cell.lb_mark2.hidden = NO;
                    cell.lb_mark1.text = labels[0];
                    cell.lb_mark2.text = labels[1];
                }
            }
            
            
            if ([model.enable isEqualToString:@"1"]) {
                cell.icon.hidden = YES;
            }else if ([model.enable isEqualToString:@"2"]){
                cell.icon.hidden = NO;
                cell.icon.image = [UIImage imageNamed:@"save11"];
            }
            
        }
    }else{
        SaveBCProductModel* model = self.proList[indexPath.section];
        
        NSString*productTypeText = nil;
        
        if ([model.productType isEqualToString:@"1"]) {
            productTypeText = @"货币基金";
        }else if ([model.productType isEqualToString:@"2"]) {
            productTypeText = @"理财产品";
        }else if ([model.productType isEqualToString:@"3"]) {
            productTypeText = @"纯债产品";
        }else if ([model.productType isEqualToString:@"4"]) {
            productTypeText = @"银行存款";
        }else if ([model.productType isEqualToString:@"5"]) {
            productTypeText = @"保险理财";
        }else if ([model.productType isEqualToString:@"6"]) {
            productTypeText = @"投融资产品";
        }else if ([model.productType isEqualToString:@"7"]) {
            productTypeText = @"组合产品";
        }else{
            productTypeText = @"定期存款";
        }
        
        cell.lb_bankName.text = [NSString stringWithFormat:@"%@ | %@ |%@",productTypeText,model.orgName,model.prdName];
        cell.lb_rate.text = [NSString stringWithFormat:@"%.4lf%%",model.rate.doubleValue];
        cell.lb_date.text = [Tools isBlankString:model.periodName] ? model.productTypeDesc :model.periodName;
        cell.lb_message.text = [NSString stringWithFormat:@"%@起购 | %@",model.minAmountDesc,[Tools isBlankString:model.periodName] ? model.productTypeDesc :model.periodName];
        if ([Tools isBlankString:model.label]) {
            cell.lb_mark1.hidden = YES;
            cell.lb_mark2.hidden = YES;
        }else{
            NSArray* labels = [model.label componentsSeparatedByString:@","];
            if (labels.count == 0) {
                cell.lb_mark1.hidden = YES;
                cell.lb_mark2.hidden = YES;
            }else if (labels.count == 1) {
                cell.lb_mark1.hidden = NO;
                cell.lb_mark2.hidden = YES;
                cell.lb_mark1.text = labels[0];
            }else{
                cell.lb_mark1.hidden = NO;
                cell.lb_mark2.hidden = NO;
                cell.lb_mark1.text = labels[0];
                cell.lb_mark2.text = labels[1];
            }
        }
        
        if ([model.enable isEqualToString:@"1"]) {
            cell.icon.hidden = YES;
        }else if ([model.enable isEqualToString:@"2"]){
            cell.icon.hidden = NO;
            cell.icon.image = [UIImage imageNamed:@"save11"];
        }
    }
    
    
    
    
   
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 140;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
//    NSString*version = nil;
//    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//    NSArray*vArr = [v componentsSeparatedByString:@"."];
//    
//    for (int i = 0; i < vArr.count; i++) {
//        if (version == nil) {
//            version = [NSString stringWithFormat:@"%@",vArr[i]];
//        }else{
//            version = [version stringByAppendingFormat:@"%@",vArr[i]];
//        }
//    }
//    
//    NSString* url = [NSString stringWithFormat:@"http://172.16.10.136/projects/html-nginx/html-nginx/appH5/Piggybank/activity/lib/home.html?userId=%@&phone=%@&version=%@&appName=kksh",@([getPeopleID PeopleID]),[getPeopleID PeopleIphoneNmber],version];
//    [self jumpToUrl:url andTitle:@"存钱罐活动"];
//    return;
    
//
//    SMSVerificationController*kvc = [SMSVerificationController new];
//    kvc.title = @"存钱罐";
//    kvc.prePhone = @"13641870495";
//    kvc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:kvc animated:YES];
//
//    return;
    
    if (self.currentModel.SUBPACKS.count > 0) {
        if (indexPath.section == self.proList.count) {
            SaveSubProductModel*model = self.currentModel.SUBPACKS[0];
            if (self.currentModel == nil) {
                [SVProgressHUD showErrorWithStatus:@"网络异常,检查您的网络!"];
                return;
            }
            
            if ([model.PRSTATUS isEqualToString:@"1"]) {
                [self overAlertViewWithMessage:@"该产品已停售!"];
                return;
            }else if ([model.PRSTATUS isEqualToString:@"2"]){
                [self overAlertViewWithMessage:@"该产品已售罄!"];
                return;
            }else if ([model.PRSTATUS isEqualToString:@"0"]){
                SaveSubProductModel*model = self.currentModel.SUBPACKS[0];
                ProductDetailController*vc = [ProductDetailController new];
                vc.hidesBottomBarWhenPushed = YES;
                vc.title = @"产品详情";
                vc.model = model;
                vc.showFuli = self.showFuli;
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                [Tools showMessage:@"未知错误!"];
                return;
            }
        }else{
            
            SaveBCProductModel* model = self.proList[indexPath.section];
            
            
            if ([model.enable isEqualToString:@"2"]) {
                [self overAlertViewWithMessage:@"该产品已停售!"];
                return;
            }else if([model.enable isEqualToString:@"1"]){
                
                if (model.isCurrency) {
                    [KKLoadingAnimationView show];
                    [self aiDaTokenRequest:^(bool success, NSString *token) {
                        [self getBCProductDetailInfoH5Request:token orgId:model];
                    }];
                }else{
                    [self getBiCaiDetailInfoRequest:model];
                }
    //            ProductDetailController*vc = [ProductDetailController new];
    //            vc.hidesBottomBarWhenPushed = YES;
    //            vc.title = @"产品详情";
    //            vc.model = model;
    //            [self.navigationController pushViewController:vc animated:YES];
            }else{
                [Tools showMessage:@"未知错误!"];
                return;
            }
            
            
            
        }
    }else{
        SaveBCProductModel* model = self.proList[indexPath.section];
        
        
        if ([model.enable isEqualToString:@"2"]) {
            [self overAlertViewWithMessage:@"该产品已停售!"];
            return;
        }else if([model.enable isEqualToString:@"1"]){
            
            if (model.isCurrency) {
                [KKLoadingAnimationView show];
                [self aiDaTokenRequest:^(bool success, NSString *token) {
                    [self getBCProductDetailInfoH5Request:token orgId:model];
                }];
            }else{
                [self getBiCaiDetailInfoRequest:model];
            }
            
           
//            ProductDetailController*vc = [ProductDetailController new];
//            vc.hidesBottomBarWhenPushed = YES;
//            vc.title = @"产品详情";
//            vc.model = model;
//            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [Tools showMessage:@"未知错误!"];
            return;
            
        }
    }
    
   
  
    
    
}
#pragma mark - 过期弹框
- (void)overAlertViewWithMessage:(NSString *)message {
    
    UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertV addAction:cancel];
    
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"查看资产" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.navigationController.tabBarController.selectedIndex = 1;
    }];
    
    [alertV addAction:confirm];
    
    [self presentViewController:alertV animated:YES completion:nil];
    
}



#pragma mark - 响应通知的方法
- (void)detectedActivityNoti:(NSNotification *)notifi
{
    
    NSString *code = notifi.object[@"code"];
    NSData*data1 = [UserDefault objectForKey:@"saveProductModel"];
    NSData*data2 = [UserDefault objectForKey:@"saveAccModel"];
    if ([code isEqualToString:@"201"]) {
        OPenAccountController*vc = [OPenAccountController new];
        vc.title = @"存钱罐开户";
        vc.productModel = [NSKeyedUnarchiver unarchiveObjectWithData:data1];
        vc.hidesBottomBarWhenPushed = YES;
        vc.from = @"activity";
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        ProductPurchaseController*purchaseVC = [ProductPurchaseController new];
        purchaseVC.title = @"产品购买";
        purchaseVC.infoModel = [NSKeyedUnarchiver unarchiveObjectWithData:data2];
        purchaseVC.model = [NSKeyedUnarchiver unarchiveObjectWithData:data1];
        purchaseVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:purchaseVC animated:YES];
        return;
    }
   
    
}

- (void)detected2ActivityNoti:(NSNotification *)notifi
{
   NSData*data1 = [UserDefault objectForKey:@"saveProductModel"];
   ProductDetailController*vc = [ProductDetailController new];
   vc.hidesBottomBarWhenPushed = YES;
   vc.title = @"产品详情";
   vc.model = [NSKeyedUnarchiver unarchiveObjectWithData:data1];
   [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 基金活动
- (void)showBCFundActivity
{
    SaveBCProductModel* proModel = [SaveBCProductModel new];
    proModel.orgId = self.orgId.integerValue;
    proModel.prdId = self.prdId.integerValue;
    [KKLoadingAnimationView show];
    [self aiDaTokenRequest:^(bool success, NSString *token) {
        [self getBCProductDetailInfoH5Request:token orgId:proModel];
    }];
    
}

#pragma mark - private methods
- (NSString *)getYearAndMonthStrWithStr:(NSString*)STERM
{
    if ([Tools isBlankString:STERM]) {
        return nil;
    }
    
    int year = STERM.intValue / 12;
    int month = STERM.intValue % 12;
    
    if (year == 0) {
        return [NSString stringWithFormat:@"%d月",month];
    }else{
        if (month == 0) {
            return [NSString stringWithFormat:@"%d年",year];
        }else{
            return [NSString stringWithFormat:@"%d年%d月",year,month];
        }
    }
}


#pragma mark - 轮播图2设置
- (void)setupCarouseViewPlus
{
    // 图片数组，可以是其他的资源，设置到轮播图上就可以
    NSMutableArray *imagerray = [NSMutableArray array];
    NSArray* kvDataArray = @[@"save01", @"save02", @"save03"];
    for (int i = 0; i < kvDataArray.count; i++)
    {
        // 先用空白页测试
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"save0%d", i + 1]];
        [imagerray addObject:image];
    }
    
    [carouseViewPlus setupSubviewPages:imagerray withCallbackBlock:^(NSInteger pageIndex) {
        // 点击页面
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"carouse2 msg"
//                                                            message:kvDataArray[pageIndex]
//                                                           delegate:nil
//                                                  cancelButtonTitle:@"ok"
//                                                  otherButtonTitles:nil, nil];
        //[alertView show];
    }];
}

#pragma mark - event response
- (void)backClick:(UIButton *)sender
{
    [self.tabBarController.navigationController popViewControllerAnimated:YES];
}

- (void)bcBtnClick:(UIButton *)sender
{
    WeakSelf
       if (![[NSUserDefaults standardUserDefaults]boolForKey:@"bicai_allow"]) {
                      
              
           [AiDaAlertView showAlertViewWithTitle:@"比财数据" imageName:@"bicailogo" ViewController:self type:AiDaAlertViewTypeBC block:^(BOOL success) {
               [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"bicai_allow"];
               [[NSUserDefaults standardUserDefaults]synchronize];
               [weakSelf aiDaTokenRequest:^(bool success, NSString *token) {
                   [weakSelf getBCRequest:token];
                  
               }];
           }];
           
            return;
                     
       }
       
        [self aiDaTokenRequest:^(bool success, NSString *token) {
               [weakSelf getBCRequest:token];
        }];
}

#pragma mark - getters
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - cl_kTabBarHeight) style:UITableViewStyleGrouped];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.estimatedSectionFooterHeight = 10;
        _tableView.estimatedSectionHeaderHeight = 10;
        [_tableView registerNib:[UINib nibWithNibName:@"ProductListCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
}

- (UIView *)headerView
{
    if (!_headerView) {
        _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 205 * WIDTHRADIU)];
        _headerView.backgroundColor = [UIColor whiteColor];
        carouseViewPlus = [[CarouseViewPlus alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 115* WIDTHRADIU)];
        
        [self setupCarouseViewPlus];
        [_headerView addSubview:carouseViewPlus];
        radioView = [[ScrollVerticalView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(carouseViewPlus.frame), [UIScreen mainScreen].bounds.size.width,40 * WIDTHRADIU)];
        radioView.backgroundColor = [UIColor whiteColor];
        radioView.infoArray = @[@"收益稳健，灵活申赎",@"安全可靠,放心购买"];
        [_headerView addSubview:radioView];
        
        SaveHomeSectionHeaderView* headerView = [[NSBundle mainBundle]loadNibNamed:@"SaveHomeSectionHeaderView" owner:self options:nil].lastObject;
        headerView.frame = CGRectMake(0, CGRectGetMaxY(radioView.frame), ScreenWidth, 50 * WIDTHRADIU);
        [_headerView addSubview:headerView];
    }
    return _headerView;
}

- (FooterView *)footerView
{
    if (!_footerView) {
        _footerView = [[NSBundle mainBundle]loadNibNamed:@"FooterView" owner:self options:nil].lastObject;
        _footerView.frame = CGRectMake(0, 0, ScreenWidth, 273);
    }
    return _footerView;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KKSBWDActivityNotificationName object:nil];
}
/*
#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
