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

#import "CoinsDetailListVC.h"
#import "CoinsDetailListVC2.h"

#import "Constants.h"

#import "CoinsListItemTableViewCell.h"
#import "CoinsDetailHeaderView.h"

#import "CoinsExchangeVC.h"
#import "WithDrawViewController.h"
#import "OrderProgressViewController.h"

#import "CoinDetailModel.h"
#import "MyWalletListModel.h"

#import "CoinsDetailFooterView.h"

#import "CTAPIBaseManager.h"


//极光小视频
#import "KKTabBarViewController.h"
#import "KKTVViewController.h"
#import "LittleVideoViewController.h"
#import "KKVideoViewController.h"
#import "KKSVideoViewController.h"

#import "LittleGoldHouseWebVC.h"

//存钱罐
#import "StatisticsViewController.h"
#import "SaveTabBarController.h"
#import "SaveProductListController.h"
#import "MyAssetsController.h"
#import "LittleGoldHouseWebVC.h"
#import "ProductDetailController.h"
#import "KKActivityRedPackageBaseView.h"
#import "KKCLFundViewController.h"


@interface CoinsDetailListVC ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,CoinsDetailHeaderViewDelegate>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIButton *btn_gold;
@property (nonatomic, strong)UIButton *btn_Exchange;
@property (nonatomic, strong)CoinsDetailHeaderView *headerView;

@property (nonatomic, strong)NSMutableArray *dataArray;

@property (nonatomic, strong)CoinsDetailFooterView *footerView;

@end

@implementation CoinsDetailListVC
#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self navConfig];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
    
    if (self.type == ListVCTypeMyWallet) {
        [self.view addSubview:self.btn_gold];
    }
    
    [self.view addSubview:self.btn_Exchange];
    self.tableView.tableFooterView = self.footerView;
    
    [self.headerView refreshData];
    [self refreshCoins];
    if (@available(iOS 11.0, *)) {
           self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
       }else{
            self.automaticallyAdjustsScrollViewInsets = NO;
       }
   
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [self.navigationController.navigationBar navBarBackGroundColor:[UIColor colorWithHex:0xf98505] image:nil isOpaque:YES];//颜色
         
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0xf98505];
//
//    [self.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//        self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0xf98505];
//    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
//    }];
//    self.navigationController.navigationBar.translucent = NO;
    
    if (self.type == ListVCTypeCoinsDetail) {
        [GTCountSDK trackCountEvent:@"life_coinList" withArgs:@{}];//个推统计
        
        [self loadMoreApi];
    }else if (self.type == ListVCTypeCoinsCost){
        [self loadData];
    }else if (self.type == ListVCTypeMyWallet){
        [GTCountSDK trackCountEvent:@"home_myWallet_mainPage" withArgs:@{}];//个推统计
        
        [self loadWalletApi];
    }
    
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = YES;
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if ([self.title isEqualToString:@"金币明细"]) {
        [JANALYTICSService startLogPageView:@"金币明细"];
        [MobClick beginLogPageView:@"金币明细"];
    }else if ([self.title isEqualToString:@"金币消费"]){
        [JANALYTICSService startLogPageView:@"金币消费"];
        [MobClick beginLogPageView:@"金币消费"];
    }
    
}
-(void)viewDidDisappear:(BOOL)animated{
    
    [super viewDidDisappear:animated];
    if ([self.title isEqualToString:@"金币明细"]) {
        [JANALYTICSService stopLogPageView:@"金币明细"];
        [MobClick endLogPageView:@"金币明细"];
    }else if ([self.title isEqualToString:@"金币消费"]){
        [JANALYTICSService stopLogPageView:@"金币消费"];
        [MobClick endLogPageView:@"金币消费"];
    }
    
    
}
- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
    CGFloat bottomViewHeight = cl_kNavigationBarHeight > 64 ? 55 * WIDTHRADIU  : 44 * WIDTHRADIU;
    
    
    
    if (self.type == ListVCTypeMyWallet) {
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.offset(0);
            make.top.offset(cl_kNavigationBarHeight);
            make.bottom.offset(-bottomViewHeight);
        }];
        
        [self.btn_gold mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(0);
            make.height.offset(bottomViewHeight);
            make.width.offset(0.3 * ScreenWidth);
            make.top.equalTo(self.tableView.mas_bottom);
        }];
        
        [self.btn_Exchange mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(0);
            make.height.offset(bottomViewHeight);
            make.width.offset(0.7 * ScreenWidth);
            make.top.equalTo(self.tableView.mas_bottom);
        }];
        
    }else if (self.type == ListVCTypeCoinsDetail){
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.offset(0);
            make.top.offset(cl_kNavigationBarHeight);
            make.bottom.offset(0);
        }];
        
        [self.btn_Exchange mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.offset(0);
            make.height.offset(bottomViewHeight);
            make.top.equalTo(self.tableView.mas_bottom);
        }];
        
    }
    
    [self.view layoutIfNeeded];
    
   
}

- (void)navConfig
{
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor colorWithHex:0xf98505];
    //返回按钮
    UIButton* backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    backBtn.frame = CGRectMake(10, cl_kStatusBarHeight, 60, 44);
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel* lb_title = [UILabel new];
    lb_title.text = self.title;
    lb_title.font = [UIFont boldSystemFontOfSize:17];
    lb_title.textAlignment = NSTextAlignmentCenter;
    lb_title.textColor = [UIColor whiteColor];
    [navView addSubview:backBtn];
    [navView addSubview:lb_title];
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(cl_kStatusBarHeight);
        make.centerX.equalTo(navView);
        make.height.offset(44);
    }];
    [self.view addSubview:navView];
}



- (void)configNavBar
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 60, 40);
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn setTitle:@"金币消费" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(goTocoinCostListVC:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    self.navigationItem.rightBarButtonItem = item;
    
}

#pragma mark - call api
- (void)refreshCoins
{
    
    if ([getPeopleID PeopleID] && [getPeopleID PeopleIphoneNmber])
    {
        NSDictionary *params = @{
                                 @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                 @"telephone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
                                 };
        NSString *url =[NSString stringWithFormat:@"%@score/getpersonintegrals",CoinsBaseUrl];
        [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
            
            if (responseObj) {
                NSString *code = [responseObj[@"code"] stringValue];
                if ([code isEqualToString:@"0"]) {
                    [getPeopleID getTotalCoins:responseObj[@"result"]];
                   
                    [self.headerView refreshData];
                    
                    return ;
                }
            }
            
        
        }];
    }
}


#pragma mark - call api
//金币明细接口
- (void)loadData{
    if ([getPeopleID PeopleID])
    {
        NSDictionary *params = @{
                                 @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                 };
        NSString *url =[NSString stringWithFormat:@"%@score/getAllScoreDetail",CoinsBaseUrl];
        [SVProgressHUD show];
        [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
            [SVProgressHUD dismiss];
            if (responseObj) {
                NSString *code = [responseObj[@"code"] stringValue];
                if ([code isEqualToString:@"0"]) {
                    
                    NSArray *array = nil;
                    if (self.type == ListVCTypeCoinsDetail) {
                        if ([responseObj[@"result"][@"detailInfo"] isKindOfClass:[NSArray class]]) {
                            array = responseObj[@"result"][@"detailInfo"];
                        }
                        
                    }else if (self.type == ListVCTypeCoinsCost){
                        array = responseObj[@"result"][@"expendList"];
                    }
                    
                   
                    self.dataArray = [CoinDetailModel mj_objectArrayWithKeyValuesArray:array];
                    [self.tableView reloadData];
                }else{
                    [SVProgressHUD showInfoWithStatus:responseObj[@"des"]];
                }
            }
        }];
    }
}


//签到请求
- (void)loadMoreApi
{
    
    [SVProgressHUD show];
    WeakSelf
    dispatch_group_t group = dispatch_group_create();
    
    dispatch_queue_t searialQueue = dispatch_queue_create("com.hmc.www", DISPATCH_QUEUE_SERIAL);
    
    dispatch_group_enter(group);
    dispatch_group_async(group, searialQueue, ^{
        //网络请求1
        if ([getPeopleID PeopleID])
        {
            NSDictionary *params = @{
                                     @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                     };
            NSString *url =[NSString stringWithFormat:@"%@score/getAllScoreDetail",CoinsBaseUrl];
            [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
                dispatch_group_leave(group);
                if (responseObj) {
                    NSString *code = [responseObj[@"code"] stringValue];
                    if ([code isEqualToString:@"0"]) {
                        
                        NSArray *array = nil;
                        if (weakSelf.type == ListVCTypeCoinsDetail) {
                            if ([responseObj[@"result"][@"detailInfo"] isKindOfClass:[NSArray class]]) {
                                array = responseObj[@"result"][@"detailInfo"];
                            }
                            
                        }else if (weakSelf.type == ListVCTypeCoinsCost){
                            array = responseObj[@"result"][@"expendList"];
                        }
                        
                        
                        weakSelf.dataArray = [CoinDetailModel mj_objectArrayWithKeyValuesArray:array];
                        
                    }
                }
            }];
        }
    });
    dispatch_group_enter(group);
    dispatch_group_async(group, searialQueue, ^{
        
        //网络请求2
        if ([getPeopleID PeopleID] && [getPeopleID PeopleIphoneNmber])
        {
            NSDictionary *params = @{
                                     @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                     @"telephone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
                                     };
            NSString *url =[NSString stringWithFormat:@"%@score/getpersonintegrals",CoinsBaseUrl];
            [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
                if (responseObj) {
                    NSString *code = [responseObj[@"code"] stringValue];
                    if ([code isEqualToString:@"0"]) {
                        [getPeopleID getTotalCoins:responseObj[@"result"]];
                    }
                }
                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];
                
                
                
                [weakSelf.tableView reloadData];
                
              [weakSelf.headerView refreshData];
            
                
                
                
              
                
            });
        });
    });
    
}


//查询钱包记录
- (void)loadWalletApi
{
    [SVProgressHUD show];
     WeakSelf
     dispatch_group_t group = dispatch_group_create();
     
     dispatch_queue_t searialQueue = dispatch_queue_create("com.walletlistqueue.www", DISPATCH_QUEUE_SERIAL);
     
     dispatch_group_enter(group);
     dispatch_group_async(group, searialQueue, ^{
         //网络请求1
         if ([getPeopleID PeopleID])
         {
             NSDictionary *params = @{
                                      @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                      };
             NSString *url =[NSString stringWithFormat:@"%@score/gettransaction",CoinsBaseUrl];
             
            
             
             [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
                 
                 NSLog(@"钱包记录:responseObj:%@",responseObj);
                 NSLog(@"钱包记录:error:%@",error);
                 if (responseObj) {
                     
                     if ([responseObj[@"code"] isKindOfClass:[NSNumber class]]) {
                         NSNumber *code = (NSNumber *)responseObj[@"code"];
                         if (code.integerValue == 0) {
                             NSArray *array = nil;
                            if (weakSelf.type == ListVCTypeMyWallet)
                            {
                                        if ([responseObj[@"result"] isKindOfClass:[NSArray class]])
                                        {
                                                array = responseObj[@"result"];
                                                        
                                        }

                            }
                             
                              

                            weakSelf.dataArray = [MyWalletListModel mj_objectArrayWithKeyValuesArray:array];
                         }
                     }
                     
                 }
                 
                 dispatch_group_leave(group);
             }];
         }
     });
     dispatch_group_enter(group);
     dispatch_group_async(group, searialQueue, ^{
         
         //网络请求2
         if ([getPeopleID PeopleID] && [getPeopleID PeopleIphoneNmber])
         {
             NSDictionary *params = @{
                                      @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                      @"telephone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
                                      };
             NSString *url =[NSString stringWithFormat:@"%@score/getpersonintegrals",CoinsBaseUrl];
             [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
                 NSLog(@"金币刷新接口:responseObj:%@",responseObj);
                 NSLog(@"金币刷新接口:error:%@",error);
                 if (responseObj) {

                     if ([responseObj[@"code"] isKindOfClass:[NSNumber class]]) {
                         NSNumber *code = (NSNumber *)responseObj[@"code"];
                         if (code.integerValue == 0) {
                             [getPeopleID getTotalCoins:responseObj[@"result"]];
                             
                             
                             NSLog(@"取数据:%@",[getPeopleID totalCoins]);
                             
                         }
                     }
                     
                 }
                 
                 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];
                 
                 
                 
                 [weakSelf.tableView reloadData];
                 
               [weakSelf.headerView refreshData];
             
                 
                 
                 
               
                 
             });
         });
     });
}




#pragma mark -  UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.tableView) {
        CGFloat offsetY = scrollView.contentOffset.y;
        NSLog(@"%f",offsetY);
        
        if (offsetY <=0) {
            scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
        }
    }
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CoinsListItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.type = self.type;
    
    if (self.type == ListVCTypeCoinsDetail) {
        [cell refreshUIWithData:self.dataArray[indexPath.row]];
    }else if (self.type == ListVCTypeCoinsCost){
        [cell refreshUIWithData:self.dataArray[indexPath.row]];
    }else if (self.type == ListVCTypeMyWallet){
        [cell refreshUIWithData:self.dataArray[indexPath.row]];
    }
    
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 62*WIDTHRADIU;
}

#pragma mark - CoinsDetailHeaderViewDelegate
- (void)clickBtn
{
    if (self.type == ListVCTypeCoinsDetail) {
        
        
        
        WebVC *webVC = [[WebVC alloc]init];
        webVC.title = @"金币抽奖";
//        外网http://nginx.weface.com.cn/lesson/award/src/award.html
//        内网@"http://172.16.10.121/projects/html-nginx/html-nginx/lesson/award/src/award.html"
        //webVC.url = @"http://nginx.weface.com.cn/lesson/award/src/award.html";
         webVC.url = CoinsRewardedUrl;
        [self.navigationController pushViewController:webVC animated:YES];
        
    }else if (self.type == ListVCTypeMyWallet){
        [self goToTVVC:NO];
    }
    
    
    
}

#pragma mark - event responses
- (void)backClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)btnClick:(UIButton *)sender
{
//    CoinsDetailListVC2 *vc = [[CoinsDetailListVC2 alloc]init];
//    vc.title = @"金币明细";
//    [self.navigationController pushViewController:vc animated:YES];
//    return;
    
    
    if (self.type == ListVCTypeCoinsDetail) {
        CoinsExchangeVC *vc = [[CoinsExchangeVC alloc]init];
        vc.title = @"金币兑换";
        
        [self.navigationController pushViewController:vc animated:YES];
    }else if (self.type == ListVCTypeMyWallet){
    
                WithDrawViewController *vc =[[WithDrawViewController alloc]init];
                vc.title = @"提现中心";
              [self.navigationController pushViewController:vc animated:YES];
        

    }
   
}

- (void)goldBtnClick:(UIButton *)sender
{
//    [self judgeSaveAmountRequest];
    [[clickEvent instance] clickEventRooterVC:self Content:@"homeThree4" menuName:@"存钱罐"];
}

- (void)goTocoinCostListVC:(UIButton *)btn
{
    CoinsDetailListVC *vc = [[CoinsDetailListVC alloc]init];
    vc.title = @"金币消费";
    vc.type = ListVCTypeCoinsCost;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
//#pragma mark - 判断是否有存款
//- (void)judgeSaveAmountRequest
//{
//    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCGetSaveAmountRequest];
//    NSLog(@"获取乌当和比财账户存款金额总数量url:%@",url);
//
////    NSString *province = [Tools isBlankString:[UserDefault objectForKey:@"locationProvince"]] ? @"" : [UserDefault objectForKey:@"locationProvince"];
////    NSString *city = [Tools isBlankString:[UserDefault objectForKey:@"locationCity"]] ? @"" : [UserDefault objectForKey:@"locationCity"];
////    NSString *county = [Tools isBlankString:[UserDefault objectForKey:@"locationCounty"]] ? @"" : [UserDefault objectForKey:@"locationCounty"];
//
//    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
//    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
//
//
////    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"tel"];
////    [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
////    [params setObject:province forKey:@"province"];
////    [params setObject:city forKey:@"city"];
////    [params setObject:county forKey:@"county"];
//
//
//
//    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"]) {
//            NSDictionary *result = objc[@"result"];
//            if ([result isKindOfClass:[NSDictionary class]]) {
//                NSString *sumAmount = [NSString stringWithFormat:@"%@",result[@"sumAmount"]];
//
//
//                if (sumAmount.doubleValue > 0) {
//
//                    SaveTabBarController*tabVC = (SaveTabBarController*)[self getTabVC:YES];
//
//                    [tabVC.navigationController setNavigationBarHidden:YES];
//                    tabVC.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:tabVC animated:YES];
//                }else{
//
////                    LittleGoldHouseWebVC *oneVC = [[LittleGoldHouseWebVC alloc] init];
////                    oneVC.title = @"小金库";
////                    oneVC.view.backgroundColor = [UIColor whiteColor];
////                    oneVC.fromHome = YES;
////                    oneVC.hidesBottomBarWhenPushed = YES;
////                    [self.navigationController pushViewController:oneVC animated:YES];
//
//                    SaveTabBarController*tabVC = (SaveTabBarController*)[self getTabVC2];
//
//                    [tabVC.navigationController setNavigationBarHidden:YES];
//                    tabVC.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:tabVC animated:YES];
//
//
//                }
//
//
//
//
//            }
//
//        }else{
//            [Tools showMessage:describe];
//        }
//
//    } Failure:^(NSError* error) {
//        [KKLoadingAnimationView dismiss];
//        NSLog(@"error:%@",error);
//
//        [Tools showMessage:@"网络出小差了,请稍后重试"];
//
//    }];
//}



//#pragma mark - 跳转到子视图tabcontroller
//- (UITabBarController *)getTabVC:(BOOL)showBC
//{
//    //2.设置窗口的根控制器
//      SaveTabBarController *tabBarVC = [[SaveTabBarController alloc] init];
//      tabBarVC.showBC = showBC;
//      //添加子控制器
//      //默认显示的第一个添加的子控制器的View
//      //tabBarVC里面有多少个子控制器,tabBar当中就有多少个平分的按钮
//
//      //UITabBarController中的tabBar的内容是有对应按钮的控制器来决定的.
//      //tabBar的内容是有对应按钮的控制器的tabBarItem来决定
//
////    if (showBC) {
////
////        SaveProductListController *oneVC = [[SaveProductListController alloc] init];
////        oneVC.title = @"产品列表";
////        oneVC.view.backgroundColor = [UIColor whiteColor];
////        oneVC.tabBarItem = [self getCustomItemWithTitle:@"产品列表" image:@"product_unselected" selectedImage:@"product_selected"];
////        UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:oneVC];
////        [tabBarVC addChildViewController:nav1];
////
////    }else{
////        LittleGoldHouseWebVC *oneVC = [[LittleGoldHouseWebVC alloc] init];
////        oneVC.title = @"小金库";
////        oneVC.view.backgroundColor = [UIColor whiteColor];
////        oneVC.url = @"https://lc.jr.jd.com/ck/xjkHold/index/?channel=a00308";
////        oneVC.tabBarItem = [self getCustomItemWithTitle:@"小金库" image:@"product_unselected" selectedImage:@"product_selected"];
////        UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:oneVC];
////        [tabBarVC addChildViewController:nav1];
////    }
//
//
//    KKCLFundViewController *oneVC = [[KKCLFundViewController alloc]init];
//    oneVC.title = @"存钱罐";
//    oneVC.view.backgroundColor = [UIColor whiteColor];
//    oneVC.tabBarItem = [self getCustomItemWithTitle:@"存钱罐" image:@"product_unselected" selectedImage:@"product_selected"];
//    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:oneVC];
//    [tabBarVC addChildViewController:nav1];
//
//
//
//    LittleGoldHouseWebVC *twoVC = [[LittleGoldHouseWebVC alloc] init];
//    twoVC.title = @"小金库";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.url = @"https://lc.jr.jd.com/ck/xjkHold/index/?channel=a00308";
//    twoVC.tabBarItem = [self getCustomItemWithTitle:@"小金库" image:@"xiaojinku_unselected" selectedImage:@"xiaojinku_selected"];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav2];
//
//
//      MyAssetsController *threeVC = [[MyAssetsController alloc] init];
//    threeVC.title = @"其他资产";
//    threeVC.view.backgroundColor = [UIColor whiteColor];
//    threeVC.tabBarItem = [self getCustomItemWithTitle:@"其他资产" image:@"myAssets_unselected" selectedImage:@"myAssets_selected"];
//      UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:threeVC];
//      [tabBarVC addChildViewController:nav3];
//
//
//
//
//      //修改主题的颜色
//      tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
//
//
//
//    return tabBarVC;
//}
//
//- (UITabBarController *)getTabVC2
//{
//    SaveTabBarController *tabBarVC = [[SaveTabBarController alloc] init];
//
//    KKCLFundViewController *oneVC = [[KKCLFundViewController alloc]init];
//    oneVC.title = @"存钱罐";
//    oneVC.view.backgroundColor = [UIColor whiteColor];
//    oneVC.tabBarItem = [self getCustomItemWithTitle:@"存钱罐" image:@"product_unselected" selectedImage:@"product_selected"];
//    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:oneVC];
//    [tabBarVC addChildViewController:nav1];
//
//
//
//    LittleGoldHouseWebVC *twoVC = [[LittleGoldHouseWebVC alloc] init];
//    twoVC.title = @"小金库";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.url = @"https://lc.jr.jd.com/ck/xjkHold/index/?channel=a00308";
//    twoVC.tabBarItem = [self getCustomItemWithTitle:@"小金库" image:@"xiaojinku_unselected" selectedImage:@"xiaojinku_selected"];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav2];
//
//    //修改主题的颜色
//    tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
//
//
//
//
//    return tabBarVC;
//
//}
//
#pragma mark - 跳转到小视频
- (void)goToTVVC:(BOOL)fromHome {

    KKSVideoViewController *oneVC = [[KKSVideoViewController alloc]initWithType:fromHome];
    oneVC.title = fromHome ?@"看视频" :@"红包视频";
    oneVC.view.backgroundColor = [UIColor whiteColor];
    oneVC.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:oneVC animated:YES];
}

//- (UITabBarItem *)getCustomItemWithTitle:(NSString *)title image:(NSString *)imageName selectedImage:(NSString *)selectedImageName
//{
//    UIImage *image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    UIImage* selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//     UITabBarItem *tabbarItem = [[UITabBarItem alloc] initWithTitle:title image:image selectedImage:selectedImage];
//    [tabbarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHex:0x137ef6], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
//    [tabbarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHex:0x7a7a7a], NSForegroundColorAttributeName,[UIFont systemFontOfSize:15],NSFontAttributeName, nil] forState:UIControlStateNormal];
//
//    return tabbarItem;
//}


-(void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {

    theView.layer.shadowColor = theColor.CGColor;
    theView.layer.shadowOffset = CGSizeMake(-1,-1);
    theView.layer.shadowOpacity = 0.5;
    theView.layer.shadowRadius = 5;
    // 单边阴影 顶边
    float shadowPathWidth = theView.layer.shadowRadius;
    CGRect shadowRect = CGRectMake(0, 0-shadowPathWidth/2.0, theView.bounds.size.width, shadowPathWidth);
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
    theView.layer.shadowPath = path.CGPath;
}

-(void)addShadow2ToView:(UIView *)theView withColor:(UIColor *)theColor {

    theView.layer.shadowColor = theColor.CGColor;
    theView.layer.shadowOffset = CGSizeMake(1,-1);
    theView.layer.shadowOpacity = 0.5;
    theView.layer.shadowRadius = 5;
    // 单边阴影 顶边
    float shadowPathWidth = theView.layer.shadowRadius;
    CGRect shadowRect = CGRectMake(0, 0-shadowPathWidth/2.0, theView.bounds.size.width, shadowPathWidth);
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
    theView.layer.shadowPath = path.CGPath;
}



#pragma mark getters and setters
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[CoinsListItemTableViewCell class] forCellReuseIdentifier:@"cell"];
        
        _tableView.tableHeaderView = self.headerView;
    }
    return _tableView;
}

- (UIButton *)btn_gold
{
    if (!_btn_gold) {
        _btn_gold =[UIButton buttonWithType:UIButtonTypeCustom];
        _btn_gold.backgroundColor = [UIColor whiteColor];
        _btn_gold.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_btn_gold setTitle:@"灵活理财" forState:UIControlStateNormal];
        [_btn_gold addTarget:self action:@selector(goldBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_btn_gold setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
        _btn_gold.layer.shadowOffset =  CGSizeMake(-2, -1);
        _btn_gold.layer.shadowOpacity = 0.2;
        _btn_gold.layer.shadowColor =  [UIColor blackColor].CGColor;
        
    }
    return _btn_gold;
}

- (UIButton *)btn_Exchange
{
    if (!_btn_Exchange) {
        _btn_Exchange =[UIButton buttonWithType:UIButtonTypeCustom];
        _btn_Exchange.backgroundColor = [UIColor colorWithHex:0xf98505];
        _btn_Exchange.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_btn_Exchange setTitle:@"金币兑换" forState:UIControlStateNormal];
        [_btn_Exchange addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btn_Exchange.layer.shadowOffset =  CGSizeMake(2, -1);
        _btn_Exchange.layer.shadowOpacity = 0.2;
        _btn_Exchange.layer.shadowColor =  [UIColor blackColor].CGColor;
        _btn_Exchange.hidden = YES;
    }
    return _btn_Exchange;
}

- (CoinsDetailHeaderView *)headerView
{
    if (!_headerView) {
        _headerView = [[CoinsDetailHeaderView alloc]init];
        
        NSDictionary *dic = [getPeopleID totalCoins];
        
        NSNumber *amountMoney = dic[@"amountMoney"];
        
        if (amountMoney.doubleValue > 0) {
            _headerView.frame = CGRectMake(0, 0, ScreenWidth, 125 * WIDTHRADIU);
        }else{
            _headerView.frame = CGRectMake(0, 0, ScreenWidth, 95 * WIDTHRADIU);
        }
               
        
        _headerView.delegate = self;
        _headerView.type = self.type;
    }
    return _headerView;
}

- (CoinsDetailFooterView *)footerView
{
    if (!_footerView) {
        _footerView = [[CoinsDetailFooterView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 42 * WIDTHRADIU)];
    }
    return _footerView;
}

- (void)setType:(ListVCType)type
{
    _type = type;
    if (type == ListVCTypeMyWallet) {
        self.headerView.type = type;
        [self.btn_Exchange setTitle:@"立即提现" forState:UIControlStateNormal];
         _btn_Exchange.hidden = NO;
    }
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
/*
#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
