//
//  MyWalletViewController.m
//  Open
//
//  Created by 雷俊博 on 2021/7/21.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "MyWalletViewController.h"
#import "MyWalletTopCardTableCell.h"
#import "MyWalletMiddleCell.h"
#import "MyWalletRankHeaderView.h"
#import "MyWalletRankTableCell.h"
#import "UserRankModel.h"

#import "LSLDecimalNumberTool.h"

#import "CoinsDetailListVC.h"
#import "WithDrawViewController.h"
#import "KKSVideoViewController.h"

//小满
#import <BXMediaSDK/BXMediaMaterialManager.h>
#import "KKActivityViewController.h"
#import "GuideONLineFindJobAlertView.h"


#import "GuideMyWalletAlertView.h"

@interface MyWalletViewController ()<UITableViewDelegate,UITableViewDataSource,MyWalletTopCardTableCellDelegate>

@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)NSArray *dataArray;

@property (nonatomic, strong)UserRankModel *rankModel;


@end

@implementation MyWalletViewController
- (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];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    
    [self.view addSubview:self.tableView];
    
    [self creatBottomView];
    
    [self navConfig];
    
    [self loadRankListRequest];
    
    [self showGuideView];
}
- (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.titleLabel.font = [UIFont systemFontOfSize:15];
    [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:18];
    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);
    }];
    
    
    UIButton* checkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [checkBtn setTitle:@"收益记录" forState:UIControlStateNormal];
    checkBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [checkBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    checkBtn.frame = CGRectMake(ScreenWidth - 80, cl_kStatusBarHeight, 70, 44);
    [checkBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [checkBtn addTarget:self action:@selector(checkClick:) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:checkBtn];
    
    [self.view addSubview:navView];
}

- (void)creatBottomView
{
    
    CGFloat bottomViewHeight = cl_kNavigationBarHeight > 64 ? 55 * WIDTHRADIU  : 44 * WIDTHRADIU;
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - bottomViewHeight, ScreenWidth, bottomViewHeight)];
    [self.view addSubview:bottomView];
    
    UIButton *earnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    earnBtn.frame = CGRectMake(0, 0, ScreenWidth/2, bottomViewHeight);
    [earnBtn setTitle:@"去赚钱" forState:UIControlStateNormal];
    [earnBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    earnBtn.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
    earnBtn.backgroundColor = [UIColor colorWithHex:0xf98505];
    [earnBtn addTarget:self action:@selector(earnBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:earnBtn];
    
    UIButton *txBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    txBtn.frame = CGRectMake(ScreenWidth/2, 0, ScreenWidth/2, bottomViewHeight);
    [txBtn setTitle:@"提现" forState:UIControlStateNormal];
    [txBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    txBtn.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
    txBtn.backgroundColor = [UIColor colorWithHex:0xf35511];
    [txBtn addTarget:self action:@selector(txBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:txBtn];
}

- (void)showGuideView
{
    
    
    
    
    NSInteger x = (arc4random() % 3) + 1;
    
//    switch (x) {
//        case 1:
//        {
//            //[self showOnLineJob];
//        }
//            break;
//        case 2:
//        {
//            [self showTTLingXianjin];
//        }
//            break;
//        case 3:
//        {
//            [self showJianYangMaoAlert];
//        }
//            break;
//
//        default:
//            break;
//    }
    
    
    

    
    
//    WeakSelf
//    [GuideONLineFindJobAlertView showWithVC:self Block:^(BOOL success) {
//
//        [weakSelf goToOnlineJobVC];
//
//    }];
//    return;
}

#pragma mark - 在线兼职弹框
- (void)showOnLineJob
{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"GuideONLineFindJobAlertView"];

    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }

    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"GuideONLineFindJobAlertView"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    WeakSelf
    [GuideMyWalletAlertView showWithImageName:@"mywallet_zxjz" VC:self Block:^(BOOL success) {
        [NetworkRequest statisticsWithEventName:@"mywallet_zxjz"];
        [weakSelf goToOnlineJobVC];
    }];
}

#pragma mark - 天天领现金弹框
- (void)showTTLingXianjin
{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"GuideTTLingXianjin"];

    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }

    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"GuideTTLingXianjin"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    WeakSelf
    [GuideAlertView showWithImageName:@"mywallet_ttlxj" VC:self Block:^(BOOL success) {
        [NetworkRequest statisticsWithEventName:@"mywallet_ttlxj"];
        [weakSelf addRedPackage];
    }];
}

#pragma mark - 剪羊毛弹框
- (void)showJianYangMaoAlert
{
    NSDate *oldTime = [[NSUserDefaults standardUserDefaults]objectForKey:@"GuideJianYangMao"];

    if (oldTime && [self isSameDay:[NSDate date] date2:oldTime]) {
        return;
    }

    NSDate *oldDate = [NSDate date];
    [[NSUserDefaults standardUserDefaults]setObject:oldDate forKey:@"GuideJianYangMao"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    WeakSelf
    [GuideAlertView showWithImageName:@"mywallet_jym" VC:self Block:^(BOOL success) {
        [NetworkRequest statisticsWithEventName:@"mywallet_jym"];
        [weakSelf loadXMImageData];
    }];
}


#pragma mark - 刷新金币和金额数量
- (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 (error) {
                [SVProgressHUD showInfoWithStatus:@"无网络"];
                return ;
            }
            if (responseObj) {
                NSString *code = [responseObj[@"code"] stringValue];
                if ([code isEqualToString:@"0"]) {
                    [getPeopleID getTotalCoins:responseObj[@"result"]];
                   
                   
                    [self.tableView reloadData];
                    
                    return ;
                }
            }
        }];
    }
}


#pragma mark - 获取排名列表数据接口

- (void)loadRankListRequest
{
    if ([getPeopleID PeopleID] && [getPeopleID PeopleIphoneNmber])
    {
        NSDictionary *params = @{
                                 @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                                 @"telephone": [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
                                 };
        NSString *url =[NSString stringWithFormat:@"%@userservice/getRanking",CoinsBaseUrl];
//        WeakSelf
        [BaseNetManager POST2:url parameters:params completionHandler:^(id responseObj, NSError *error) {
            
           
            if (responseObj) {
                
                
                NSString *code = [NSString stringWithFormat:@"%@",responseObj[@"code"]];
                
                
                if ([code isEqualToString:@"0"]) {
                    self.rankModel = [UserRankModel mj_objectWithKeyValues:responseObj[@"result"]];
                    [self.tableView reloadData];
                }
            }
            
        }];
    }
}


#pragma mark - MyWalletTopCardTableCellDelegate
- (void)MyWalletTopCardBtnClickWithIndex:(NSInteger)index
{
    [self goToWithDrawVC];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0 || section == 1) {
        return 1;
    }
    if (self.rankModel) {
        return self.rankModel.rankList.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        MyWalletTopCardTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyWalletTopCardTableCell"];
        
        cell.delegate = self;
        
        NSDictionary *dic = [getPeopleID totalCoins];
        
        [cell reloadDataWithData:dic];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }else if (indexPath.section == 1){
        MyWalletMiddleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyWalletMiddleCell"];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        NSURL *url = [getPeopleID PeoplePhoto];
        if (url) {
            [cell.userIcon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"my_information_headportrait_default"]];
        }else{
            cell.userIcon.image = [UIImage imageNamed:@"my_information_headportrait_default"];
        }
        if (self.rankModel) {
            if (![Tools isBlankString:self.rankModel.rankNo]) {
                cell.lb_rank.text = self.rankModel.rankNo;
            }
            
            if (![Tools isBlankString:self.rankModel.percentage]) {
                
                cell.lb_percent.attributedText = [self setupAttributeString:[NSString stringWithFormat:@"超越了%@的人",self.rankModel.percentage] rangeText:self.rankModel.percentage color:[UIColor colorWithHex:0xf98505] font:[UIFont boldSystemFontOfSize:14 * WIDTHRADIU]];
            }
            NSDictionary *dic = [getPeopleID totalCoins];
            if (dic) {
                NSString *sumProfit = [NSString stringWithFormat:@"%@",dic[@"userCurrentAccrue"]];
                if (![Tools isBlankString:sumProfit]) {
                    cell.lb_sumProfit.text = [NSString stringWithFormat:@"%@元",sumProfit];
                }
            }
            
        }
        
        return cell;
    }
    
    MyWalletRankTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyWalletRankTableCell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row == 0) {
        cell.rankIcon.image = [UIImage imageNamed:@"coin_rank1"];
        cell.lb_rank.text = @"";
        cell.userIcon.layer.borderColor = [UIColor colorWithHex:0xffdf53].CGColor;
        cell.userIcon.layer.borderWidth = 2 * WIDTHRADIU;
    }else if (indexPath.row == 1){
        cell.rankIcon.image = [UIImage imageNamed:@"coin_rank2"];
        cell.lb_rank.text = @"";
        cell.userIcon.layer.borderWidth = 0;
    }else if (indexPath.row == 2){
        cell.rankIcon.image = [UIImage imageNamed:@"coin_rank3"];
        cell.lb_rank.text = @"";
        cell.userIcon.layer.borderWidth = 0;
    }else{
        cell.rankIcon.image = [UIImage imageNamed:@""];
        cell.lb_rank.text = [NSString stringWithFormat:@"%ld",indexPath.row];
        cell.userIcon.layer.borderWidth = 0;
    }
    
    cell.top1Icon.hidden = !(indexPath.row == 0);
    cell.fireworksImg.hidden = !(indexPath.row == 0);
    
    RankUserModel *userModel = self.rankModel.rankList[indexPath.row];
    
    [cell.userIcon sd_setImageWithURL:[NSURL URLWithString:userModel.accountphoto]];
    if (![Tools isBlankString:userModel.cusname]) {
        cell.lb_nickName.text = userModel.cusname;
    }
    
    if (![Tools isBlankString:userModel.accumulatedmoney]) {
        cell.lb_profitSum.text =  [NSString stringWithFormat:@"%@元",[LSLDecimalNumberTool stringWithDecimalNumber:userModel.accumulatedmoney.doubleValue]];
    }
    
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return 143 * WIDTHRADIU;
    }else if (indexPath.section == 1){
        return 133 * WIDTHRADIU;
    }
    return 66 * WIDTHRADIU;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        MyWalletRankHeaderView * headerView = [[MyWalletRankHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 37 * WIDTHRADIU)];

        return headerView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return 46 * WIDTHRADIU;
    }
    return 0.0;
}

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

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

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

- (void)checkClick:(UIButton *)sender
{
    CoinsDetailListVC *vc = [[CoinsDetailListVC alloc]init];
    vc.title = @"我的钱包";
    vc.type = ListVCTypeMyWallet;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)earnBtnClick:(UIButton *)sender
{
    NSInteger i = [UserDefault integerForKey:@"profitRankListEarnClickNum"];
    
    if (i == 0) {
        [self goToTVVC:NO];
    }else if (i == 1){
        [self loadXMImageData];
    }else if (i == 2){
        [self addRedPackage];
    }
    
    i++;
    if (i >= 3) {
        i = 0;
    }
    
    [UserDefault setInteger:i forKey:@"profitRankListEarnClickNum"];
    [UserDefault synchronize];
}

- (void)txBtnClick:(UIButton *)sender
{
    [self goToWithDrawVC];
}

#pragma mark - 去提现
- (void)goToWithDrawVC
{
    WeakSelf
    WithDrawViewController *vc =[[WithDrawViewController alloc]init];
    vc.title = @"提现中心";
    vc.block = ^(BOOL success) {
      
        if (success) {
            [weakSelf refreshCoins];
        }
        
    };
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 跳转到小视频
- (void)goToTVVC:(BOOL)fromHome {
    
    WeakSelf
    KKSVideoViewController *oneVC = [[KKSVideoViewController alloc]initWithType:fromHome];
    oneVC.title = fromHome ?@"看视频" :@"红包视频";
    oneVC.view.backgroundColor = [UIColor whiteColor];
    oneVC.block = ^(BOOL success) {
      
        if (success) {
            [weakSelf refreshCoins];
        }
    };
    
    [self.navigationController pushViewController:oneVC animated:YES];
    
    
//    KKTabBarViewController *tabBarVC = [[KKTabBarViewController alloc]initWithType:fromHome];
    
    
//    LittleVideoViewController *twoVC = [[LittleVideoViewController alloc] init];
//    twoVC.title = fromHome ?@"看视频" :@"红包视频";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.tabBarItem = [self getCustomItemWithTitle:@"更多" image:@"" selectedImage:@""];
//    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav1];
    
    
   
    
    
//    KKVideoViewController *oneVC = [[KKVideoViewController alloc] init];
//    oneVC.title = fromHome ?@"看视频" :@"红包视频";
//    oneVC.view.backgroundColor = [UIColor whiteColor];
//    oneVC.tabBarItem = [self getCustomItemWithTitle:@"小视频" image:@"" selectedImage:@""];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:oneVC];
//    [tabBarVC addChildViewController:nav2];
//    KKSVideoViewController *oneVC = [[KKSVideoViewController alloc] init];
//    oneVC.title = fromHome ?@"看视频" :@"红包视频";
//    oneVC.view.backgroundColor = [UIColor whiteColor];
//    oneVC.tabBarItem = [self getCustom3ItemWithTitle:@"小视频" image:@"" selectedImage:@""];
//    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:oneVC];
//    [tabBarVC addChildViewController:nav2];
//
//
//    KKSFeedPageViewController *twoVC = [[KKSFeedPageViewController alloc] init];
//    twoVC.title = fromHome ?@"更多" :@"更多";
//    twoVC.view.backgroundColor = [UIColor whiteColor];
//    twoVC.tabBarItem = [self getCustom3ItemWithTitle:@"更多" image:@"" selectedImage:@""];
//    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:twoVC];
//    [tabBarVC addChildViewController:nav1];
    
    
    
    //tabBarVC.fromHome = fromHome;
    
    
    //修改主题的颜色
    //tabBarVC.tabBar.tintColor = [UIColor colorWithHex:0x137ef6];
    
    
    
//    [tabBarVC.navigationController setNavigationBarHidden:YES];
//    tabBarVC.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:tabBarVC animated:YES];
    
}

#pragma mark - 剪羊毛
- (void)loadXMImageData
{
//  __block NSString*adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    
    __weak typeof(self) weakSelf = self;
    [BXMediaMaterialManager getEntranceMaterialsWithAppkey:@"kksh-IOS-hdgj_xsekjn" placId:@"6668" thirdUserId:@"" success:^(BXMMaterialModel *model) {
        
        
        [BXMediaMaterialManager entranceShowEventTrackingWithPlaceId:@"6668" userId:@"" materialModel:model];
        
       
        [BXMediaMaterialManager entranceClickEventTrackingWithPlaceId:@"6668" userId:@"" materialModel:model];
        
        KKActivityViewController *vc = [KKActivityViewController new];
        vc.title = @"剪羊毛";
        vc.placeId = @"6668";
        vc.buId = @"946405771";
        vc.gdtAdId = @"2082218177897738";
        [weakSelf.navigationController pushViewController:vc animated:YES];
       
        
    } fail:^(NSString *error) {
    
        
    }];
}

#pragma mark - 天天领现金
- (void)addRedPackage
{
    //素材使用代码
   //素材曝光,一般在素材加载完成的时候调用.如果不知道素材加载好的时机,可以在素材所在页面加载完成的时候调用
//  __block NSString*adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
   
   
   //加载素材
   //__weak typeof(self) weakSelf = self;
   [BXMediaMaterialManager getEntranceMaterialsWithAppkey:@"kksh-IOS-hdgj_xsekjn" placId:@"6667" thirdUserId:@"" success:^(BXMMaterialModel *model) {
       //weakSelf.model = model;
       if (model) {
           
           [BXMediaMaterialManager entranceShowEventTrackingWithPlaceId:@"6667" userId:@"" materialModel:model];
           
        
           [BXMediaMaterialManager entranceClickEventTrackingWithPlaceId:@"6667" userId:@"" materialModel:model];
           
           KKActivityViewController *vc = [KKActivityViewController new];
           vc.title = @"天天赚钱";
           vc.placeId = @"6667";
           vc.buId = @"946405763";
           vc.gdtAdId = @"9002117197798706";
           vc.hidesBottomBarWhenPushed = YES;
           [self.navigationController pushViewController:vc animated:YES];
           
           
           
       }
   } fail:^(NSString *error) {
       
   }];
}


#pragma mark - 在线兼职
- (void)goToOnlineJobVC
{
    WebVC *webvc = [[WebVC alloc]init];
    webvc.url = [NSString stringWithFormat:@"https://squirrel.kxbwmedia.com/ditch/task?union_id=10222&phoneNum=%@&uuid=%@",[getPeopleID PeopleIphoneNmber],@([getPeopleID PeopleID])];
    webvc.title = @"在线兼职";
    [self.navigationController pushViewController:webvc animated:YES];
}


#pragma mark - 自定义富文本
- (NSMutableAttributedString *)setupAttributeString:(NSString *)text rangeText:(NSString *)rangeText color:(UIColor *)color font:(UIFont *)font  {
    NSRange hightlightTextRange = [text rangeOfString:rangeText];
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:text];
    if (hightlightTextRange.length > 0) {
        [attributeStr addAttribute:NSForegroundColorAttributeName
                                     value:color
                                     range:hightlightTextRange];
        [attributeStr addAttribute:NSFontAttributeName value:font range:hightlightTextRange];
        return attributeStr;
    }else {
        return [rangeText copy];
    }
}

#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
- (UITableView *)tableView
{
    if (!_tableView) {
        CGFloat bottomViewHeight = cl_kNavigationBarHeight > 64 ? 55 * WIDTHRADIU  : 44 * WIDTHRADIU;
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - bottomViewHeight) style:UITableViewStyleGrouped];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        
        _tableView.estimatedSectionFooterHeight = 10;
        _tableView.estimatedSectionHeaderHeight = 10;
        _tableView.estimatedRowHeight = 50;
        
        [_tableView registerClass:[MyWalletTopCardTableCell class] forCellReuseIdentifier:@"MyWalletTopCardTableCell"];
        [_tableView registerClass:[MyWalletMiddleCell class] forCellReuseIdentifier:@"MyWalletMiddleCell"];
        [_tableView registerClass:[MyWalletRankTableCell class] forCellReuseIdentifier:@"MyWalletRankTableCell"];
    }
    
    return _tableView;
}

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