//
//  NewsSearchListController.m
//  Open
//
//  Created by qinxuyang on 2021/11/16.
//  Copyright © 2021 QXY. All rights reserved.
//

#import "NewsSearchListController.h"
#import "HotNewsCell.h"
#import "JHNewsModel.h"
#import "NewsListTableViewCell.h"
#import "NewsTextCell.h"
#import "NewsList2Cell.h"
#import "NewsImagesCell.h"
#import <BUAdSDK/BUAdSDK.h>
#import <GDTNativeExpressAdView.h>
//#import "GDTNativeExpressProAdView.h"
#import "NewsWebViewController.h"
@interface NewsSearchListController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,BUNativeExpressAdViewDelegate,NewsWebViewControllerDelegate>{
    NSString* startTimeStr;
    NSString* endTimeStr;
    NSString* currentPageUrl;
    
    NSInteger currentPage;
    int timeLength;
}
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITableView *historyTableView;
@property (nonatomic, strong) UIView *searchView;
@property (nonatomic, strong) UITextField *TextField;
@property (nonatomic, assign) int indexTag;
@property (nonatomic, assign) BOOL chage;
@property (nonatomic, strong) NSArray *allhotArray;
@property (nonatomic, strong) NSArray *allcountArray;
@property (nonatomic, strong) NSArray *hotArray;
@property (nonatomic, strong) NSArray *countArray;
@property (nonatomic, strong) NSMutableArray *mixDataArray;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) NSMutableArray *expressAdViews;
@property (nonatomic, strong) NSMutableArray *tempArray;
@property (nonatomic, strong) BUNativeExpressAdManager *adManager;
@end

@implementation NewsSearchListController
- (NSMutableArray *)tempArray{
    if (_tempArray == nil) {
        _tempArray = [NSMutableArray array];
    }
    return _tempArray;
}
- (NSMutableArray *)expressAdViews{
    if (_expressAdViews == nil) {
        _expressAdViews = [NSMutableArray array];
    }
    return _expressAdViews;
}
- (NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (NSArray *)allhotArray{
    if (_allhotArray == nil) {
        _allhotArray = [NSArray array];
    }
    return _allhotArray;
}
- (NSArray *)allcountArray{
    if (_allcountArray == nil) {
        _allcountArray = [NSArray array];
    }
    return _allcountArray;
}
- (NSArray *)hotArray{
    if (_hotArray == nil) {
        _hotArray = [NSArray array];
    }
    return _hotArray;
}
- (NSArray *)countArray{
    if (_countArray == nil) {
        _countArray = [NSArray array];
    }
    return _countArray;
}
- (NSMutableArray *)mixDataArray{
    if (_mixDataArray == nil) {
        _mixDataArray = [NSMutableArray array];
    }
    return _mixDataArray;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.chage = NO;
    
    [self navConfig];

    currentPage = 1;
    for (int i = 0; i < 10; i++) {
        JHNewsModel *model = [[JHNewsModel alloc]init];
        model.view_type = @"1";
        model.news_pic = @"http://images8.m.china.com.cn/oss/mchina/20210420/11/img_a3b31532f8617f9d9f96a40b4651ed5c_240_176.jpg";
        model.news_from = @"中国网财经";
        model.news_from = @"1小时前";
        [self.mixDataArray addObject:model];
    }

    timeLength = 80;
    BUAdSlot *slot1 = [[BUAdSlot alloc] init];
    slot1.adSize = CGSizeMake(ScreenWidth, 0);
    slot1.ID = @"946265855";
    slot1.AdType = BUAdSlotAdTypeFeed;
    
    BUSize *imgSize = [BUSize sizeBy:BUProposalSize_Feed228_150];
    slot1.imgSize = imgSize;
    slot1.position = BUAdSlotPositionFeed;
    
    
    self.adManager = [[BUNativeExpressAdManager alloc] initWithSlot:slot1 adSize:CGSizeMake(ScreenWidth, 0)];
    self.adManager.delegate = self;
    
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.historyTableView];
    [self loadHotData];
}
- (void)backClick:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)navConfig {
    UIView*navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    navView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:navView];
    
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake( 10, cl_kStatusBarHeight + 9.5, 60, 25);
    backBtn.titleLabel.textAlignment =NSTextAlignmentLeft;
    [backBtn setImage:[UIImage imageNamed:@"blackBack"] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"blackBack"] forState:UIControlStateHighlighted];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setTitle:@"返回" forState:UIControlStateHighlighted];
    [backBtn setTitleColor:[UIColor colorWithHex:0x404040] forState:UIControlStateNormal];
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:2];
    [backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBtn];
    
    [navView addSubview:self.searchView];
  
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - cl_kTabbarSafeBottomMargin) style:UITableViewStylePlain];
        _tableView.hidden = YES;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//推荐该方法
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshHeader)];
        _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreNewsData)];
        [_tableView registerNib:[UINib nibWithNibName:@"NormalTableViewCell" bundle:nil] forCellReuseIdentifier:@"NormalTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsListTableViewCell" bundle:nil] forCellReuseIdentifier:@"NewsListTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsTextCell" bundle:nil] forCellReuseIdentifier:@"NewsTextCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsList2Cell" bundle:nil] forCellReuseIdentifier:@"NewsList2Cell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsImagesCell" bundle:nil] forCellReuseIdentifier:@"NewsImagesCell"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"nativeexpresscell"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"BUDNativeExpressCell"];
        
        _tableView.tabAnimated = [TABTableAnimated animatedWithCellClass:[NewsList2Cell class] cellHeight:111];
        _tableView.tabAnimated.cancelGlobalCornerRadius = YES;
        _tableView.tabAnimated.animatedHeight = 12.f;
        _tableView.tabAnimated.dropAnimationDuration = 3;
        _tableView.tabAnimated.animatedSectionCount = 3;
        _tableView.tabAnimated.superAnimationType = TABViewSuperAnimationTypeShimmer;
        _tableView.tabAnimated.canLoadAgain = YES;
    }
    return _tableView;
}
- (UITableView *)historyTableView {
    if (!_historyTableView) {
        _historyTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - cl_kTabbarSafeBottomMargin) style:UITableViewStyleGrouped];
        _historyTableView.backgroundColor = [UIColor whiteColor];
        _historyTableView.dataSource = self;
        _historyTableView.delegate = self;
        _historyTableView.estimatedSectionHeaderHeight = 0;
        _historyTableView.estimatedSectionFooterHeight = 0;
        _historyTableView.separatorStyle = UITableViewCellSeparatorStyleNone;//推荐该方法
        [_historyTableView registerNib:[UINib nibWithNibName:@"HotNewsCell" bundle:nil] forCellReuseIdentifier:@"HotNewsCell"];
    }
    return _historyTableView;
}
- (UIView *)searchView{
    if (_searchView == nil) {
        _searchView = [[UIView alloc]initWithFrame:CGRectMake(80, cl_kStatusBarHeight, ScreenWidth-80, 44)];
        
        UIView *searchBaseView = [[UIView alloc]initWithFrame:CGRectMake(0, 2, _searchView.width - 60, 40)];
        searchBaseView.backgroundColor = [UIColor colorWithHex:0x000000 alpha:0.1];
        searchBaseView.layer.masksToBounds = YES;
        searchBaseView.layer.cornerRadius = 20.0;
        [_searchView addSubview:searchBaseView];
        
        UIButton *searchBtnImg = [[UIButton alloc]initWithFrame:CGRectMake(10, 11.5, 16, 17)];
        searchBtnImg.enabled = NO;
        [searchBtnImg setImage:[UIImage imageNamed:@"icon_search"] forState:UIControlStateNormal];
        [searchBaseView addSubview:searchBtnImg];
        
        _TextField = [[UITextField alloc]initWithFrame:CGRectMake(30, 0, searchBaseView.width - 40, 40)];
        _TextField.textColor = [UIColor blackColor];
        _TextField.returnKeyType = UIReturnKeySearch;
        _TextField.placeholder = @"搜索关键字";
        _TextField.font = [UIFont systemFontOfSize:16];
        _TextField.clearButtonMode = UITextFieldViewModeAlways;
        _TextField.delegate = self;
        [searchBaseView addSubview:_TextField];
        

        UIButton *searchBtn = [[UIButton alloc]initWithFrame:CGRectMake(_searchView.width - 50, 0, 40, 30)];
        searchBtn.centerY = searchBaseView.centerY;
        searchBtn.titleLabel.font = [UIFont systemFontOfSize:17.0];
        [searchBtn setTitle:@"搜索" forState:UIControlStateNormal];
        [searchBtn setTitleColor:K_MainColor forState:UIControlStateNormal];
        [searchBtn addTarget:self action:@selector(search) forControlEvents:UIControlEventTouchUpInside];
        [_searchView addSubview:searchBtn];
    }
    return _searchView;
}
//搜索虚拟键盘响应
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (textField.text.length != 0) {
        self.indexTag = 1;
        
        self.tableView.hidden = NO;
        self.historyTableView.hidden = YES;
        
        [self.tableView.mj_header beginRefreshing];
        
        [_TextField resignFirstResponder];
    }else{
        self.indexTag = 0;
        
        self.tableView.hidden = YES;
        self.historyTableView.hidden = NO;

        [self.mixDataArray removeAllObjects];
        [self.tableView reloadData];
        [self.historyTableView reloadData];
        [_TextField resignFirstResponder];
    }
    return YES;
}
//搜索
- (void)search{
    if (self.TextField.text.length != 0) {
        self.indexTag = 1;
        
        self.tableView.hidden = NO;
        self.historyTableView.hidden = YES;
        
        [self.tableView.mj_header beginRefreshing];
        
        [_TextField resignFirstResponder];

    }else{
        self.indexTag = 0;
        
        self.tableView.hidden = YES;
        self.historyTableView.hidden = NO;

        [self.mixDataArray removeAllObjects];
        [self.tableView reloadData];
        [self.historyTableView reloadData];
        [_TextField resignFirstResponder];
    }
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
//    self.indexTag = 1;
//
//    [self.tableView reloadData];
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.text.length != 0) {
        self.indexTag = 1;
        
        self.tableView.hidden = NO;
        self.historyTableView.hidden = YES;
        
        [self.tableView.mj_header beginRefreshing];
        
        [_TextField resignFirstResponder];
    }else{
        self.indexTag = 0;
        
        self.tableView.hidden = YES;
        self.historyTableView.hidden = NO;
        
        [self.mixDataArray removeAllObjects];
        [self.tableView reloadData];
        [self.historyTableView reloadData];
        [_TextField resignFirstResponder];
    }
}
#pragma mark  -----  Refresh
- (void)loadMoreNewsData
{
    [self.tempArray removeAllObjects];
    
    BOOL success = [UserDefault boolForKey:@"quickLookNews"];
    
    NSInteger maxCount = success ? 21 : 12;
    
    if (self.dataArray.count >= currentPage * maxCount) {
        
        NSLog(@"currentPage:%ld",currentPage);
        
        for (int i = 0; i < maxCount; i++) {
            [self.tempArray addObject:self.dataArray[(currentPage - 1) * maxCount + i]];
        }
        
        [self.adManager loadAdDataWithCount:3];
    }else{
        NSLog(@"currentPage:%ld",currentPage);
        
        for (int i = 0; i < (self.dataArray.count - (currentPage - 1) * maxCount); i++) {
            [self.tempArray addObject:self.dataArray[(currentPage - 1) * maxCount + i]];
        }
        
        [self.adManager loadAdDataWithCount:3];
        
        _tableView.mj_footer.hidden  =  YES;
        
    }
}
-(void)refreshTableView
{
    [self.tableView.mj_header beginRefreshing];
}
- (void)refreshHeader
{
    [self.tableView tab_startAnimation];
    [self requestList];
}
- (void)upDown
{
    [self requestList];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (self.indexTag == 0) {
        return 1;
    }
    return self.mixDataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (self.indexTag == 0) {
        return self.hotArray.count;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.indexTag == 0) {
        //历史记录
        static NSString *nibString = @"HotNewsCell";
        HotNewsCell *cell = [tableView dequeueReusableCellWithIdentifier:nibString];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:nibString owner:self options:nil] lastObject];
        }
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.titleLabel.text = self.hotArray[indexPath.row];
        cell.countLabel.text = self.countArray[indexPath.row];
        cell.numLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row + 1];
        if (indexPath.row == 0) {
            cell.numLabel.textColor = [UIColor colorWithHex:0xe71f19];
        }else if (indexPath.row == 1){
            cell.numLabel.textColor = [UIColor colorWithHex:0xed7807];
        }else{
            cell.numLabel.textColor = [UIColor colorWithHex:0xe1b727];
        }
        return cell;
    }
    
    id model = self.mixDataArray[indexPath.section];
    if ([model isKindOfClass:[JHNewsModel class]]) {
        JHNewsModel* newsModel = (JHNewsModel *)model;
        
        if ([newsModel.view_type isEqualToString:@"2"]) {
            NewsListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewsListTableViewCell"];
            
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            
            
            [cell refreshUIWithModel:newsModel];
            
            
            return cell;
        }else if ([newsModel.view_type isEqualToString:@"0"]){
            NewsTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewsTextCell"];
            
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            
            
            [cell refreshUIWithModel:newsModel];
            
            
            return cell;
        } else if ([newsModel.view_type isEqualToString:@"1"]) {
            NewsList2Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewsList2Cell"];
            
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            
            
            [cell refreshUIWithModel:newsModel];
            
            
            return cell;
        }else if ([newsModel.view_type isEqualToString:@"3"]) {
            NewsImagesCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewsImagesCell"];
            
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            
            
            [cell refreshUIWithModel:newsModel];
            
            
            return cell;
        }else{
            NewsTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NewsTextCell"];
            
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            
            
            [cell refreshUIWithModel:newsModel];
            
            
            return cell;
        }
        
    }else if ([model isKindOfClass:[BUNativeExpressAdView class]]){
        BUNativeExpressAdView *expressView = (BUNativeExpressAdView *)model;
        UITableViewCell *cell = nil;
        cell = [tableView dequeueReusableCellWithIdentifier:@"BUDNativeExpressCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        //[self addAccessibilityIdentifier:model];
        // 重用BUNativeExpressAdView，先把之前的广告试图取下来，再添加上当前视图
       
        
        for (UIView* view in cell.contentView.subviews) {
            [view removeFromSuperview];
        }
        
        UIView* line = [UIView new];
        line.backgroundColor = [UIColor colorWithHex:0xcccccc];
        line.tag = 100;
        
        UIView *view = model;
        view.tag = indexPath.section;
        //[self addAccessibilityIdentifier:(GDTNativeExpressProAdView *)view];
        [cell.contentView addSubview:view];
        [cell.contentView addSubview:line];
        
        
        [expressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.right.offset(0);
        }];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.offset(0);
            make.left.offset(15);
            make.right.offset(-15);
            make.height.offset(0.5);
        }];
        return cell;
    } else{
        
        BUNativeExpressAdView *expressView = (BUNativeExpressAdView *)model;
        
        UIView* line = [UIView new];
        line.backgroundColor = [UIColor colorWithHex:0xcccccc];
        line.tag = 100;
        
        expressView.tag = 1000;
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"nativeexpresscell" forIndexPath:indexPath];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        for (UIView* view in cell.contentView.subviews) {
            [view removeFromSuperview];
        }
                
        [cell.contentView addSubview:expressView];
        [cell.contentView addSubview:line];
        
        
        [expressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.right.offset(0);
        }];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.offset(0);
            make.left.offset(15);
            make.right.offset(-15);
            make.height.offset(0.5);
        }];
        
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (self.indexTag == 0) {
        return 50;
    }else{
        return 0.01;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (self.indexTag == 0) {
        return 60;
    }
    
    id model = self.mixDataArray[indexPath.section];
    if ([model isKindOfClass:[JHNewsModel class]]) {
        return UITableViewAutomaticDimension;
    }else{
        UIView* view = (UIView *)model;
        
        CGFloat height = view.bounds.size.height + 0.5;
    
        return height;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (self.indexTag == 0) {
        if (self.hotArray.count == 0) {
            return [UIView new];
        }
        UIView *headerView = [UIView new];
        headerView.backgroundColor = [UIColor whiteColor];
        headerView.frame = CGRectMake(0, 0, ScreenWidth, 40);
        
        UILabel *historyTitleLabel = [[UILabel alloc] init];
        [historyTitleLabel setFrame:CGRectMake(15, 10, 250, 30)];
        historyTitleLabel.text= @"猜你想搜";
        historyTitleLabel.font = [UIFont systemFontOfSize:17];
        historyTitleLabel.textColor = [UIColor colorWithHex:0x404040];
        [headerView addSubview:historyTitleLabel];
        
        
        UIButton *changeBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 80, 10, 70, 30)];
        changeBtn.tag = 0;
        [changeBtn setTitle:@"换一换" forState:UIControlStateNormal];
        [changeBtn setImage:[UIImage imageNamed:@"searchChage"] forState:UIControlStateNormal];
        [changeBtn setTitleColor:[UIColor colorWithHex:0x666666] forState:UIControlStateNormal];
        changeBtn.titleLabel.font = [UIFont systemFontOfSize:17.0];
        [changeBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:4];
        [changeBtn addTarget:self action:@selector(changeBtn:) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:changeBtn];
        
        return headerView;
    }
    return [[UIView alloc]init];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    if (self.indexTag == 0) {
        self.TextField.text = self.hotArray[indexPath.row];
    }else{
        id model = self.mixDataArray[indexPath.section];
        if ([model isKindOfClass:[JHNewsModel class]]) {
            JHNewsModel*newsModel = (JHNewsModel *)model;
            
            NewsWebViewController *vc = [[NewsWebViewController alloc]init];
            
            vc.title = @"新闻资讯";
            
            
            NSString* usr_id  = nil;
            
            if ([UserDefault boolForKey:@"firstlog"]) {
                usr_id = [NSString stringWithFormat:@"%@",@([getPeopleID PeopleID])];
            }
            
            if ([Tools isBlankString:usr_id]) {
                vc.url = newsModel.news_url;
            }else{
                vc.url = [newsModel.news_url stringByAppendingFormat:@"&usr_id=%@",usr_id];
            }
            
            vc.model = newsModel;
           
            
            vc.delegate = self;
            
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            currentPageUrl = newsModel.news_url;
        }
        return;
    }
    if (self.TextField.text.length != 0) {
        self.tableView.hidden = NO;
        self.historyTableView.hidden = YES;
        
        [self.tableView.mj_header beginRefreshing];
        
        [_TextField resignFirstResponder];
        
        self.indexTag = 1;
    }else{
        self.tableView.hidden = YES;
        self.historyTableView.hidden = NO;
        
        self.indexTag = 0;
        [self.mixDataArray removeAllObjects];
        [self.tableView reloadData];
        [self.historyTableView reloadData];
        [_TextField resignFirstResponder];
    }
}
#pragma mark - 切换数据
- (void)changeBtn:(UIButton *)button{
    if (self.allhotArray.count > 10) {
        if (self.chage) {
            self.hotArray = [self.allhotArray subarrayWithRange:NSMakeRange(0, 10)];

            self.countArray = [self.allcountArray subarrayWithRange:NSMakeRange(0, 10)];
            
            self.chage = NO;
        }else{
            self.hotArray = [self.allhotArray subarrayWithRange:NSMakeRange(self.allhotArray.count - 10, 10)];

            self.countArray = [self.allcountArray subarrayWithRange:NSMakeRange(self.allcountArray.count - 10, 10)];
            
            self.chage = YES;
        }
        
        [self.historyTableView reloadData];
    }
}
#pragma mark - loadData
- (void)loadHotData{
    WeakSelf
    NSString *url = @"https://kk.weface.com.cn/news/hotwords/";
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [NetworkRequest Get4:url Params:param Success:^(id _Nonnull responseObject) {

        NSLog(@"========responseObject:%@",responseObject);
        if ([responseObject[@"hotwords"] isKindOfClass:[NSArray class]]) {
            NSArray *arr = responseObject[@"hotwords"];
            NSArray *infosArr = responseObject[@"hotwords_infos"];
            weakSelf.allhotArray = arr;
            weakSelf.allcountArray = infosArr;
            if (arr.count > 10) {
                weakSelf.hotArray = [arr subarrayWithRange:NSMakeRange(0, 10)];
                weakSelf.countArray = [infosArr subarrayWithRange:NSMakeRange(0, 10)];
            }else{
                weakSelf.hotArray = responseObject[@"hotwords"];
                weakSelf.countArray = responseObject[@"hotwords_infos"];
            }
            [weakSelf.historyTableView reloadData];
        }
    } Failure:^(NSError * _Nonnull error) {
        NSLog(@"error:%@",error);

    }];
}
- (void)requestList
{
    [self.view endEditing:YES];

    [self.mixDataArray removeAllObjects];
    
    NSString *urlString = JUHEUrlString;
    
    NSString* province = [UserDefault objectForKey:@"locationProvince"];
    
    NSString* provinceValue = [self getLocationAddressKeyWithProvinceName:province];
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:provinceValue forKey:@"address"];
    if (self.TextField.text.length != 0) {
        [param setValue:self.TextField.text forKey:@"keyword"];
    }
    WeakSelf
    [NetworkRequest NewsPost:urlString Params:param Success:^(id _Nonnull objc) {
        [weakSelf.tableView.mj_header endRefreshing];
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *status = [NSString stringWithFormat:@"%@",objc[@"status"]];
            if ([status isEqualToString:@"0"]) {
                NSLog(@"新闻请求成功并渲染时间:%@",[NSDate date]);
                [self.expressAdViews removeAllObjects];
                [self.dataArray removeAllObjects];
                weakSelf.dataArray = [NSMutableArray arrayWithArray:[JHNewsModel mj_objectArrayWithKeyValuesArray:objc[@"news_list"]]];
                NSArray *arr = [JHNewsModel mj_objectArrayWithKeyValuesArray:objc[@"news_list"]];
                for (JHNewsModel *model in arr) {
                    [weakSelf.mixDataArray addObject:model];
                }
                [weakSelf loadNewsData];
            }else{
                [weakSelf.expressAdViews removeAllObjects];
                [weakSelf.dataArray removeAllObjects];
                [weakSelf.mixDataArray removeAllObjects];
            }
        }else{
            [weakSelf.expressAdViews removeAllObjects];
            [weakSelf.dataArray removeAllObjects];
            [weakSelf.mixDataArray removeAllObjects];
        }
        [weakSelf.tableView reloadData];
        [self.tableView tab_endAnimationEaseOut];
    } Failure:^(NSError* error) {
        [weakSelf.tableView.mj_header endRefreshing];
        [self.tableView tab_endAnimationEaseOut];
        [weakSelf.expressAdViews removeAllObjects];
        [weakSelf.dataArray removeAllObjects];
        [weakSelf.mixDataArray removeAllObjects];
        [weakSelf.tableView reloadData];
        NSLog(@"error:%@",error);
    }];
}
- (void)loadNewsData
{
    [self.mixDataArray removeAllObjects];
    currentPage = 1;
    [self.tempArray removeAllObjects];
    
    BOOL success = [UserDefault boolForKey:@"quickLookNews"];
    
    NSInteger maxCount = success ? 21 : 12;
    
    
    if (self.dataArray.count > maxCount) {
        
        for (int i = 0; i < maxCount; i++) {
            [self.tempArray addObject:self.dataArray[i]];
        }
        
        [self.adManager loadAdDataWithCount:3];
        _tableView.mj_footer.hidden  =  NO;
    }else{
        self.tempArray = self.dataArray;
        [self.adManager loadAdDataWithCount:3];
        
        _tableView.mj_footer.hidden  =  YES;
    }
}
#pragma mark - 看新闻得金币
- (NSDictionary *)readNewsGetCoinsRequestPara {
    NSDictionary* params = @{
        @"uid":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
        @"telphone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
        @"watchstarttime":startTimeStr ? startTimeStr :@"",
        @"watchendtime":endTimeStr ? endTimeStr : @"",
        @"currentpagetotalheight":@(0),
        @"currentNewsHeight":@(0),
        @"currentPageUrl":currentPageUrl ,
        @"frommodel":[NSNumber numberWithInt:2],
        @"eventtype":[NSNumber numberWithInt:1001],
        
        @"slidingdistance":@(0),
        @"slidingTime":@(0)
    };
    
    return params;
}
//
//- (void)readNewsGetCoinsRequest {
//    NSString *url = [NSString stringWithFormat:@"%@news/readnews",CoinsBaseUrl];//外网
//
//    [NetworkRequest Get:url Params:[self readNewsGetCoinsRequestPara] Success:^(id _Nonnull objc) {
//
//        NSLog(@"objc:%@",objc);
//
//        if ([objc isKindOfClass:[NSDictionary class]]) {
//            NSString* code = [NSString stringWithFormat:@"%@",objc[@"code"]];
//            if ([code isEqualToString:@"0"]) {
//                if ([objc[@"result"] isKindOfClass:[NSDictionary class]]) {
//                    NSString*score = [NSString stringWithFormat:@"+%@",objc[@"result"][@"score"]];
//                    [CTToast showWithMessage:score image:@"readNews-coins-toastBackView" duration:1];
//                }
//            }
//        }
//
//    } Failure:^(NSError* error) {
//        NSLog(@"error");
//    }];
//
//}



#pragma mark - NewsWebViewControllerDelegate
//第一次加载完成返回总高度和当前时间戳(精确到秒)
- (void)kkNewsDetailViewControllerDidFirstFinishLoad:(NewsWebViewController *)vc withTime:(NSString *)timeStr {
    
    startTimeStr = timeStr;
}

//控制器关闭返回当前时间戳
- (void)kkNewsDetailViewControllerDidClose:(NewsWebViewController *)vc withTime:(NSString *)timeStr {
//    endTimeStr = timeStr;
//
//
//    NSInteger number = endTimeStr.integerValue - startTimeStr.integerValue;
//
//    NSLog(@">>>>%ld",number);
//
//    if (number >= 13000) {
//        [self readNewsGetCoinsRequest];
//    }
    
    
}
//#pragma mark - AccessibilityIdentifier
//- (void)addAccessibilityIdentifier:(GDTNativeExpressProAdView *)adView {
//    adView.accessibilityIdentifier = @"express_draw_view";
//}
//
//- (void)removeAccessibilityIdentifier:(GDTNativeExpressProAdView *)adView {
//    adView.accessibilityIdentifier = nil;
//}






//#pragma mark - BUNativeExpressAdViewDelegate
//- (void)nativeExpressAdSuccessToLoad:(BUNativeExpressAdManager *)nativeExpressAd views:(NSArray<__kindof BUNativeExpressAdView *> *)views {
//    [self.tableView.mj_header endRefreshing];
//    [self.tableView.mj_footer endRefreshing];
//    //【重要】不能保存太多view，需要在合适的时机手动释放不用的，否则内存会过大
//    if (views.count) {
//
//        [self.expressAdViews addObjectsFromArray:views];
////        [self.expressAdViews addObject:views.firstObject];
//        [views enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            BUNativeExpressAdView *expressView = (BUNativeExpressAdView *)obj;
//            expressView.rootViewController = self;
//            // important: 此处会进行WKWebview的渲染，建议一次最多预加载三个广告，如果超过3个会很大概率导致WKWebview渲染失败。
//            [expressView render];
//            if (!(((currentPage - 2)*NewPageSize + (idx + 1) * 6 -1) >= self.dataArray.count)) {
//                [self.dataArray insertObject:expressView atIndex:((currentPage - 2)*NewPageSize + (idx + 1) * 6 -1)];
//            }
////            *stop = YES;
//        }];
//
//
//    }
//    [self.tableView reloadData];
//    [self pbud_logWithSEL:_cmd msg:@""];
//}
//
//- (void)nativeExpressAdFailToLoad:(BUNativeExpressAdManager *)nativeExpressAd error:(NSError *)error {
//    [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"error:%@", error]];
//    [self.tableView.mj_header endRefreshing];
//    [self.tableView.mj_footer endRefreshing];
//}
//
//- (void)nativeExpressAdViewRenderSuccess:(BUNativeExpressAdView *)nativeExpressAdView {
//    [self.tableView reloadData];
//    static dispatch_once_t onceToken;
//    dispatch_once(&onceToken, ^{
//        self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateCurrentPlayedTime) userInfo:nil repeats:YES];
//        [self.timer fire];
//    });
//    [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"nativeExpressAdView.videoDuration:%ld", (long)nativeExpressAdView.videoDuration]];
//}
//
//- (void)updateCurrentPlayedTime {
//    for (BUNativeExpressAdView *nativeExpressAdView in self.expressAdViews) {
//        [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"nativeExpressAdView.currentPlayedTime:%.4f", nativeExpressAdView.currentPlayedTime]];
//    }
//}
//
//- (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView stateDidChanged:(BUPlayerPlayState)playerState {
//    [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"playerState:%ld", (long)playerState]];
//}
//
//- (void)nativeExpressAdViewRenderFail:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *)error {
//    [self pbud_logWithSEL:_cmd msg:[NSString stringWithFormat:@"error:%@", error]];
//}
//
//- (void)nativeExpressAdViewWillShow:(BUNativeExpressAdView *)nativeExpressAdView {
//    [self pbud_logWithSEL:_cmd msg:@""];
//}
//
//- (void)nativeExpressAdViewDidClick:(BUNativeExpressAdView *)nativeExpressAdView {
//    [self pbud_logWithSEL:_cmd msg:@""];
//}
//
//- (void)nativeExpressAdViewPlayerDidPlayFinish:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *)error {
//    [self pbud_logWithSEL:_cmd msg:@""];
//}
//
//- (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView dislikeWithReason:(NSArray<BUDislikeWords *> *)filterWords {//【重要】需要在点击叉以后 在这个回调中移除视图，否则，会出现用户点击叉无效的情况
//    [self.expressAdViews removeObject:nativeExpressAdView];
//    [self.dataArray removeObject:nativeExpressAdView];
//
//    NSUInteger index = [self.dataArray indexOfObject:nativeExpressAdView];
//    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:index inSection:0];
//    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
//    [self pbud_logWithSEL:_cmd msg:@""];
//}
//
//- (void)nativeExpressAdViewDidClosed:(BUNativeExpressAdView *)nativeExpressAdView {
//    [self pbud_logWithSEL:_cmd msg:@""];
//}
//
//- (void)nativeExpressAdViewWillPresentScreen:(BUNativeExpressAdView *)nativeExpressAdView {
//    [self pbud_logWithSEL:_cmd msg:@""];
//}
//
//- (void)nativeExpressAdViewDidCloseOtherController:(BUNativeExpressAdView *)nativeExpressAdView interactionType:(BUInteractionType)interactionType {
//    NSString *str;
//    if (interactionType == BUInteractionTypePage) {
//        str = @"ladingpage";
//    } else if (interactionType == BUInteractionTypeVideoAdDetail) {
//        str = @"videoDetail";
//    } else {
//        str = @"appstoreInApp";
//    }
//    [self pbud_logWithSEL:_cmd msg:str];
//}
//
//
//- (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
//    //BUD_Log(@"SDKDemoDelegate BUNativeExpressFeedAdView In VC (%@) extraMsg:%@", NSStringFromSelector(sel), msg);
//}


#pragma mark - GDTNativeExpressProAdManagerDelegete
/**
 * 拉取广告成功的回调
 */
//- (void)gdt_nativeExpressProAdSuccessToLoad:(GDTNativeExpressProAdManager *)adManager views:(NSArray<__kindof GDTNativeExpressProAdView *> *)views
//{
//    NSLog(@"%s",__FUNCTION__);
//    self.expressAdViews = [NSMutableArray arrayWithArray:views];
//    if (self.expressAdViews.count) {
//        [self.expressAdViews enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            GDTNativeExpressProAdView *adView = (GDTNativeExpressProAdView *)obj;
//            adView.controller = self;
//            adView.delegate = self;
//            [adView render];
//            NSLog(@"eCPM:%ld eCPMLevel:%@", [adView eCPM], [adView eCPMLevel]);
//            NSInteger index = 2 + idx * 6;
//            if (index >= self.tempArray.count) {
//                NSInteger k = index - self.tempArray.count;
//                if (k < 1) {
//                    [self.tempArray addObject:adView];
//                }
//            }else{
//                [self.tempArray insertObject:adView atIndex:index];
//            }
//        }];
//
//        [self.mixDataArray addObjectsFromArray:self.tempArray];
//    }
//    [self.tableView reloadData];
//
//    if (currentPage == 1) {
//        [self.tableView tab_endAnimationEaseOut];
//    }
//    currentPage++;
//    [self.tableView.mj_header endRefreshing];
//    [self.tableView.mj_footer endRefreshing];
//}
/**
 * 拉取广告失败的回调
 */

//- (void)gdt_nativeExpressProAdFailToLoad:(GDTNativeExpressProAdManager *)adManager error:(NSError *)error
//{
//    NSLog(@"%s",__FUNCTION__);
//    NSLog(@"Express Ad Load Fail : %@",error);
//    [self.mixDataArray addObjectsFromArray:self.tempArray];
//    [self.tableView reloadData];
//    if (currentPage == 1) {
//        [self.tableView tab_endAnimationEaseOut];
//    }
//    currentPage++;
//    [self.tableView.mj_header endRefreshing];
//    [self.tableView.mj_footer endRefreshing];
//}

//
//#pragma mark - GDTNativeExpressProAdViewDelegate;
//- (void)gdt_NativeExpressProAdViewRenderSuccess:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//    [self.tableView reloadData];
//}
//- (void)gdt_NativeExpressProAdViewRenderFail:(GDTNativeExpressProAdView *)nativeExpressProAdView
//{
//    UIView *superView = nativeExpressProAdView.superview;
//
//    UITableViewCell* cell = (UITableViewCell *)superView.superview;
//    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
//    [self.dataArray removeObjectAtIndex:indexPath.section];
//    [self.tableView reloadData];
//}
//
//- (void)gdt_NativeExpressProAdViewClicked:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//}
//
//- (void)gdt_NativeExpressProAdViewClosed:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//
//    UIView *superView = nativeExpressAdView.superview;
//
//    UITableViewCell* cell = (UITableViewCell *)superView.superview;
//    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
//    [self.dataArray removeObjectAtIndex:indexPath.section];
//    [self.tableView reloadData];
//
//}
//
//- (void)gdt_NativeExpressProAdViewExposure:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//}
//
//- (void)gdt_NativeExpressProAdViewWillPresentScreen:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//}
//
//- (void)gdt_NativeExpressProAdViewDidPresentScreen:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//}
//
//- (void)gdt_NativeExpressProAdViewWillDissmissScreen:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//}
//
//- (void)gdt_NativeExpressProAdViewDidDissmissScreen:(GDTNativeExpressProAdView *)nativeExpressAdView
//{
//    NSLog(@"%s",__FUNCTION__);
//}
//
//- (void)gdt_NativeExpressProAdView:(GDTNativeExpressProAdView *)nativeExpressProAdView playerStatusChanged:(GDTMediaPlayerStatus)status
//{
//    NSLog(@"%s",__FUNCTION__);
//}

#pragma mark - BUNativeExpressAdViewDelegate
/**
 * Sent when views successfully load ad
 */
- (void)nativeExpressAdSuccessToLoad:(BUNativeExpressAdManager *)nativeExpressAdManager views:(NSArray<__kindof BUNativeExpressAdView *> *)views
{
    NSLog(@"%s",__FUNCTION__);
    self.expressAdViews = [NSMutableArray arrayWithArray:views];
    if (self.expressAdViews.count) {
        [self.expressAdViews enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            BUNativeExpressAdView *adView = (BUNativeExpressAdView *)obj;
            adView.rootViewController = self;
            [adView render];
            BOOL success = [UserDefault boolForKey:@"quickLookNews"];
            
            NSInteger index = success ? (5 + idx * 9) : (2 + idx * 6);
            if (index >= self.tempArray.count) {
                NSInteger k = index - self.tempArray.count;
                if (k < 1) {
                    [self.tempArray addObject:adView];
                }
                //[self.tempArray addObject:adView];
            }else{
                [self.tempArray insertObject:adView atIndex:index];
            }
        }];
        
        [self.mixDataArray addObjectsFromArray:self.tempArray];
    }
    [self.tableView reloadData];
    
    if (currentPage == 1) {
        [self.tableView tab_endAnimationEaseOut];
    }
    currentPage++;
    
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];

    NSLog(@"广告请求成功时间:%@",[NSDate date]);
}

/**
 * Sent when views fail to load ad
 */
- (void)nativeExpressAdFailToLoad:(BUNativeExpressAdManager *)nativeExpressAdManager error:(NSError *_Nullable)error
{
    NSLog(@"%s",__FUNCTION__);
    NSLog(@"Express Ad Load Fail : %@",error);
    [self.mixDataArray addObjectsFromArray:self.tempArray];
    [self.tableView reloadData];
    if (currentPage == 1) {
        [self.tableView tab_endAnimationEaseOut];
    }
    currentPage++;
   
    
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

/**
 * This method is called when rendering a nativeExpressAdView successed, and nativeExpressAdView.size.height has been updated
 */
- (void)nativeExpressAdViewRenderSuccess:(BUNativeExpressAdView *)nativeExpressAdView
{
    NSLog(@"%s",__FUNCTION__);
    [self.tableView reloadData];
}

/**
 * This method is called when a nativeExpressAdView failed to render
 */
- (void)nativeExpressAdViewRenderFail:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *_Nullable)error
{
    UIView *superView = nativeExpressAdView.superview;
    
    UITableViewCell* cell = (UITableViewCell *)superView.superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    
    
    
    
    
    [self.mixDataArray removeObjectAtIndex:indexPath.section];
    //[nativeExpressAdView removeFromSuperview];
    [self.tableView reloadData];
}

/**
 * Sent when an ad view is about to present modal content
 */
- (void)nativeExpressAdViewWillShow:(BUNativeExpressAdView *)nativeExpressAdView
{
    
}

/**
 * Sent when an ad view is clicked
 */
- (void)nativeExpressAdViewDidClick:(BUNativeExpressAdView *)nativeExpressAdView
{
    NSLog(@"%s",__FUNCTION__);
}

/**
Sent when a playerw playback status changed.
@param playerState : player state after changed
*/
- (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView stateDidChanged:(BUPlayerPlayState)playerState
{
    NSLog(@"%s",__FUNCTION__);
}

/**
 * Sent when a player finished
 * @param error : error of player
 */
- (void)nativeExpressAdViewPlayerDidPlayFinish:(BUNativeExpressAdView *)nativeExpressAdView error:(NSError *)error
{
    NSLog(@"%s",__FUNCTION__);
}

/**
 * Sent when a user clicked dislike reasons.
 * @param filterWords : the array of reasons why the user dislikes the ad
 */
- (void)nativeExpressAdView:(BUNativeExpressAdView *)nativeExpressAdView dislikeWithReason:(NSArray<BUDislikeWords *> *)filterWords
{
    NSLog(@"%s",__FUNCTION__);
    
    UIView *superView = nativeExpressAdView.superview;
    
    UITableViewCell* cell = (UITableViewCell *)superView.superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    
    
    
    
    
    [self.mixDataArray removeObjectAtIndex:indexPath.section];
    //[nativeExpressAdView removeFromSuperview];
    [self.tableView reloadData];
}

/**
 * Sent after an ad view is clicked, a ad landscape view will present modal content
 */
- (void)nativeExpressAdViewWillPresentScreen:(BUNativeExpressAdView *)nativeExpressAdView
{
    
}

/**
 This method is called when another controller has been closed.
 @param interactionType : open appstore in app or open the webpage or view video ad details page.
 */
- (void)nativeExpressAdViewDidCloseOtherController:(BUNativeExpressAdView *)nativeExpressAdView interactionType:(BUInteractionType)interactionType
{
    
}


/**
 This method is called when the Ad view container is forced to be removed.
 @param nativeExpressAdView : Ad view container
 */
- (void)nativeExpressAdViewDidRemoved:(BUNativeExpressAdView *)nativeExpressAdView
{
    NSLog(@"%s",__FUNCTION__);
    
    UIView *superView = nativeExpressAdView.superview;
    
    UITableViewCell* cell = (UITableViewCell *)superView.superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    
    
    
    
    
    [self.mixDataArray removeObjectAtIndex:indexPath.section];
    //[nativeExpressAdView removeFromSuperview];
    [self.tableView reloadData];
}


#pragma mark - 获取定位省份的key
- (NSString *)getLocationAddressKeyWithProvinceName:(NSString *)province
{
    NSString* str = @"bj";
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"newProvince" ofType:@"plist"];
    //其次通过这个文件路径获得字典文件(因为Info.plist内容本身就是个字典集)
    NSArray *provinceArr = [NSArray arrayWithContentsOfFile:filePath];
    
    for (NSDictionary* dic in provinceArr) {
        if ([dic[@"provinceName"] isEqualToString:province]) {
            str = dic[@"provinceValue"];
            break;
        }
    }
    
    
    return str;
}
//- (NSMutableDictionary *)dispatchTable
//{
//    if (_dispatchTable == nil) {
//        _dispatchTable = [[NSMutableDictionary alloc]init];
//    }
//    return _dispatchTable;
//}
/*
#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
