//
//  GovInfoViewController.m
//  Open
//
//  Created by 雷俊博 on 2020/5/13.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "GovInfoViewController.h"
#import "ZWCollectionViewCell.h"
#import "ZWHeaderViewCell.h"

#import "GovBtnTableViewCell.h"
#import "GovNewsHeaderView.h"

#import "WeiJianQueryViewController.h"
#import "LoginVC.h"

#import "HeathOrganViewController.h"
#import "ApplyStateQueryViewController.h"

#import "KKRedPackageClickEventModel.h"
#import <objc/runtime.h>
#import "WXApi.h"

#import "PreDeceptionAlertView.h"



//新闻
#import "JHNewsModel.h"
#import "NewsViewController.h"
#import "HeadLineViewController.h"
#import "NewsListTableViewCell.h"
#import "NewsList2Cell.h"
#import "NewsTextCell.h"
#import "NewsImagesCell.h"
#import "NewsWebViewController.h"

//天气
#import "GovWeatherModel.h"

#import "CTAPIBaseManager.h"

#import "CoinsCenterViewController.h"
#import <KSAdSDK/KSCUFeedPage.h>
#import "UIViewController+KSCUFeedPageExtend.h"
#import "TimerProxy.h"


@interface GovInfoViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,GovBtnTableViewCellDelegate,GovNewsHeaderViewDelegate,UIGestureRecognizerDelegate>
{
    UIButton* btn1;
    UIButton* btn2;
    UIButton* btn3;
}

@property (nonatomic, strong)UIScrollView* scrollView;

@property (nonatomic, strong)UICollectionView*collectionView;

@property (nonatomic, strong)UIImageView* topImg;

@property (nonatomic, strong)NSArray* bgArray;


@property (nonatomic, strong)NSArray* titleArray;

@property (nonatomic, strong)NSArray* redPackageClickEventsArray;
@property (nonatomic, strong)NSArray* bottomEssArray;
@property (nonatomic, strong)UIImageView* bottomEssImage;

@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)NSArray *newsArray;

//@property (nonatomic, strong)GovWeatherModel *weatherModel;
@property (nonatomic, strong)NSDictionary *weatherDic;

@property (nonatomic, strong)GovNewsHeaderView *newsHeaderView;

@property (nonatomic, strong)NSTimer *timer;

@property (nonatomic, assign)BOOL showWeather;

@property (nonatomic, assign)BOOL coinSigned;

@end

@implementation GovInfoViewController

- (void)dealloc
{
    if (self.timer && [self.timer isValid]) {
        [self.timer invalidate];
    }
    self.timer = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [self.navigationController.navigationBar navBarBackGroundColor:K_MainColor image:nil isOpaque:YES];//颜色
         
    [self.navigationController.navigationBar navBarBottomLineHidden:YES];
    
    [GTCountSDK trackCountEvent:@"home_zhengwu_listPage" withArgs:@{}];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //self.view.backgroundColor = K_MainColor;
    
    
    [self creatNav];
    
    [self requestZWBMIconsAndTargetEvent];
    
    [self.view addSubview:self.tableView];
    
//    NSDate *oldDate = [UserDefault objectForKey:@"FangPianJianCeshowLastTime"];

//    if (oldDate == nil || ![Tools isSameDay:oldDate date2:[NSDate date]]) {
//        [self requestFPCheckRequest];
//    }
    
    
    [self loadNewsData];
    
    [self requestWeatherData];
    
    [self judgeSignOrNorSignRequest];
   
    [self bottomView];
}

- (void) bottomView{
//    KSCUFeedPage *feedPage = [[KSCUFeedPage alloc] initWithPosId:@"6030000009"];
//    feedPage.videoStateDelegate = self;
//    feedPage.stateDelegate = self;
//    feedPage.callBackDelegate = self;
//    feedPage.hidesBottomBarWhenPushed = YES;
//    UIViewController *vc1 = feedPage.feedViewController;
//    [vc1 setKscu_feedPageDelegate:self];
//    [self addChildViewController:vc1];
//    UIView *ksview=vc1.view;
//    ksview.frame=CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight + 52);
//    [self.view addSubview:ksview];
//    [vc1.view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.tableView.mas_bottom).offset(20);
//        //make.top.right.bottom.left.offset(0);
//    }];
    _bottomEssImage=[UIImageView new];
    _bottomEssImage.image  = [UIImage imageNamed:@"gov_bottom_ess"];
    _bottomEssImage.userInteractionEnabled=YES;
    UITapGestureRecognizer *essImageClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(essClick:)];
    [_bottomEssImage addGestureRecognizer:essImageClick];
    [self.view addSubview:_bottomEssImage];
    [_bottomEssImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tableView.mas_bottom).offset(10);
        make.centerX.equalTo(self.view);
        make.width.offset(ScreenWidth-30);
        make.height.offset(WIDTHRADIU*220);
    }];
    
    [self getEssImage];
}

-(void)essClick:(UITapGestureRecognizer *)tap{
    NSLog(@"%@",@"!!!!!!!!!!!!");
    if(self.bottomEssArray!=nil&&self.bottomEssArray.count>0){
        KKRedPackageClickEventModel *model= self.bottomEssArray[0];
        [[clickEvent instance] clickEventRooterVC:self.navigationController model:model];
    }else{
        [[clickEvent instance] clickEventRooterVC:self Content:@"homeOne1" menuName:@"homeOne1"];
    }
}

-(void) getEssImage{
    self.bottomEssArray=nil;
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    NSString *url = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    NSDictionary *params = @{
        @"configName":@"GovBottomEss",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS"
    };
    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                    self.bottomEssArray = [KKRedPackageClickEventModel mj_objectArrayWithKeyValuesArray:objc[@"result"]];
                    KKRedPackageClickEventModel *model=self.bottomEssArray[0];
                    [self.bottomEssImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon]]];
                }
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}

- (void)creatNav
{
    UIView*nav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    nav.backgroundColor = K_MainColor;
    [self.view addSubview:nav];
    
    UIButton*backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [nav addSubview:backBtn];
    
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.offset(cl_kStatusBarHeight);
        make.width.offset(80);
        make.height.offset(cl_kNavBarHeight);
    }];
    
    UILabel*titleLabel = [[UILabel alloc]init];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = self.title;
    titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [nav addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(cl_kStatusBarHeight);
        make.width.offset(80);
        make.height.offset(cl_kNavBarHeight);
    }];
    
    
    
}

#pragma mark - 后台获取的icon和点击事件关键字
- (void)requestZWBMIconsAndTargetEvent
{
    
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    
    NSString *url = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    //NSString *url = @"http://172.16.10.18:8017/dynamic/menu/get";
    
    NSDictionary *params = @{
        @"configName":@"ZhengWuBianMin",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS"
    };
    WeakSelf
    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            
            if ([state isEqualToString:@"200"]) {
                if ([objc[@"result"] isKindOfClass:[NSArray class]]) {
                    //weakSelf.redPackageClickEventsArray = [KKRedPackageClickEventModel mj_objectArrayWithKeyValuesArray:objc[@"result"]];
                    
                  
                    //[weakSelf.tableView reloadData];
                }
            }
            
           
        }
      
        
        
        
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
        
        
    }];
    
}

#pragma mark - 获取天气
- (void)requestWeatherData
{
    WeakSelf
    NSString *url = WeatherUrl;
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [NetworkRequest Get4:url Params:param Success:^(id _Nonnull responseObject) {

        NSLog(@"responseObject:%@",responseObject);
        NSDictionary *dic = responseObject;
        if (dic.count > 0) {
            weakSelf.weatherDic  = dic;
            
            if (weakSelf.weatherDic) {
                [weakSelf creatTimer];
            }
            
            [weakSelf timerMethod1];
        }

    } Failure:^(NSError * _Nonnull error) {
        NSLog(@"error:%@",error);

    }];
    
    
//    WeakSelf
//    NSString *url = WeatherUrl;
//    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]init];
//    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
//    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
//    //默认:application/x-www-form-urlencoded
//    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
//
//    manager.requestSerializer.timeoutInterval = 20;
//    [manager POST:url parameters:nil headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//
//        if (responseObject) {
//
//
//            NSLog(@"%@",responseObject);
//
//            NSNumber *ret = responseObject[@"ret"];
//            if ([ret isKindOfClass:[NSNumber class]]) {
//                if (ret.integerValue == 200) {
//                    NSDictionary *dic = responseObject;
//
//
//                    weakSelf.weatherModel = [GovWeatherModel mj_objectWithKeyValues:dic[@"data"]];
//
//
//                    if (weakSelf.weatherModel) {
//                        [weakSelf creatTimer];
//                    }
//
//                    [weakSelf timerMethod1];
//
//                }
//
//            }
//
//
//
//        }
//
//
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
//    }];
}

#pragma mark - 获取是否已签到
- (void)judgeSignOrNorSignRequest
{
    
    WeakSelf
    NSString *url = [NSString stringWithFormat:@"%@score/getuserTaskStatus",[NetworkConfig ipCoinsConfig]];
    
    NSDictionary *dic = @{
                             @"userId":[NSNumber numberWithInteger:[getPeopleID PeopleID]],
                             @"telephone":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY],
                             @"fromModel":@"2"
                             };
    
    
    NSArray *result = [dic.allKeys sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        
        NSLog(@"%@~%@",obj1,obj2); //3~4 2~1 3~1 3~2
        
        return [obj1 compare:obj2]; //升序
        
    }];
    NSString *sign = nil;
    for (int i = 0; i < result.count; i++) {
        NSString *key = result[i];
        if (i==0) {
            sign = [NSString stringWithFormat:@"%@=%@",key,dic[key]];
        }else{
            
            sign = [NSString stringWithFormat:@"%@&%@=%@",sign,key,dic[key]];
        }
    }
    
    sign = [NSString stringWithFormat:@"%@&Kanwf574",sign];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:dic];
    
    NSString *signString = [[MyMD5 md5:sign] lowercaseString];
    [params setObject:signString forKey:@"sign"];
   
    [params setObject:[NSNumber numberWithInt:172] forKey:@"verflag"];
    
    [CTAPIBaseManager POST:url params:params completionHandler:^(id  _Nonnull responseObject, NSError * _Nonnull error) {

        if (responseObject) {
            NSNumber *code = responseObject[@"code"];
            if (code.integerValue == 0) {
                
                
               
                NSArray* dateArray = [[NSMutableArray alloc]initWithArray:responseObject[@"result"][@"dateTaskStatus"]];
                //self.dataArray = [KKTaskModel mj_objectArrayWithKeyValuesArray:responseObject[@"result"][@"taskstatus"]];
                
                //获取今天是周几
                
                NSNumber *index = responseObject[@"result"][@"currentDayofWeek"];
                NSInteger weekIndex = index.integerValue - 1;
                
                NSDictionary *dic = dateArray[weekIndex];
                NSNumber *status = dic[@"status"];
                if (status.integerValue == 302) {
                    weakSelf.coinSigned = YES;
                    
                    [weakSelf timerMethod1];
                }
                
              
            }
        }
    
       
    }];
}



#pragma mark - 获取新闻数据

- (NSDictionary *)requestParams
{
    
    NSString* province = [UserDefault objectForKey:@"locationProvince"];
    
    NSString* provinceValue = [self getLocationAddressKeyWithProvinceName:province];
    
    NSDictionary *param = @{
        @"news_type":@"china",
        @"address":provinceValue,
        @"start":@(0),
        @"end":@(10)
    };
    
    return param;
}

- (void)loadNewsData
{
    NSString *urlString = JUHEUrlString;
    NSLog(@"新闻列表:url:%@",urlString);
    NSLog(@"params:%@",[self requestParams]);
    WeakSelf
    
    NSLog(@"请求前时间:%@",[NSDate date]);
    [NetworkRequest NewsPost:urlString Params:[self requestParams] Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *status = [NSString stringWithFormat:@"%@",objc[@"status"]];
            if ([status isEqualToString:@"0"]) {
                NSLog(@"新闻请求成功并渲染时间:%@",[NSDate date]);

                weakSelf.newsArray = [NSMutableArray arrayWithArray:[JHNewsModel mj_objectArrayWithKeyValuesArray:objc[@"news_list"]]];
                [weakSelf.tableView reloadData];
            }
        }
        
        
        
    } Failure:^(NSError* error) {
        
        NSLog(@"error:%@",error);
    }];
}


#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;
}



#pragma mark - 获取防骗检测链接
- (void)requestFPCheckRequest
{
    
    NSString*version = nil;
    NSString*v = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSArray*vArr = [v componentsSeparatedByString:@"."];
    
    for (int i = 0; i < vArr.count; i++) {
        if (version == nil) {
            version = [NSString stringWithFormat:@"%@",vArr[i]];
        }else{
            version = [version stringByAppendingFormat:@"%@",vArr[i]];
        }
    }
    
    NSString *url = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    //NSString *url = @"http://172.16.10.18:8017/dynamic/menu/get";
    
    NSDictionary *params = @{
        @"configName":@"FangPianJianCe",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS"
    };
    
    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
        
        NSLog(@"objc:%@",objc);
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            
            if ([state isEqualToString:@"200"]) {
                
                NSArray *array = [KKRedPackageClickEventModel mj_objectArrayWithKeyValuesArray:objc[@"result"]];
                
                if (array.count == 1) {
                    NSDate *oldDate = [NSDate date];
                    [UserDefault setObject:oldDate forKey:@"FangPianJianCeshowLastTime"];
                    [UserDefault synchronize];
                    KKRedPackageClickEventModel *model = array[0];
                    
                    [PreDeceptionAlertView showWithBlock:^(NSInteger code) {
                        if (code == 200) {
                            [self goToPreventionVCWithModel:model];
                            
                            [self addFPCheckClickCountWithType:@"100401"];
                        }else if (code == 201){
                            [self addFPCheckClickCountWithType:@"100402"];
                        }
                    }];
                }
                
                
            }
            
           
        }
      
        
        
        
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
        
        
    }];
    
}



#pragma mark - 统计防骗检测
- (void)addFPCheckClickCountWithType:(NSString *)type
{
    NSString *url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],KKFPCheckRequest];
    //NSString *url = [NSString stringWithFormat:@"%@%@",@"http://172.16.10.18:8017/",KKFPCheckRequest] ;
    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:[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY] forKey:@"tel"];
    [params setObject:@([getPeopleID PeopleID]) forKey:@"uid"];
    [params setObject:province forKey:@"province"];
    [params setObject:city forKey:@"city"];
    [params setObject:county forKey:@"county"];
    [params setObject:@"kksh" forKey:@"fromApp"];
    [params setObject:type forKey:@"type"];
   
   
    NSLog(@"params:%@",params);
    
    
    [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
    
        NSLog(@"objc:%@",objc);
        

    } Failure:^(NSError* error) {
       
        NSLog(@"error:%@",error);
        
       
        
    }];
}





#pragma mark - 康爱多
- (void)getKangAiDuoUrlRequest {
    
    
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    
    NSString*url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipAdDaUrlConfig],KADURLRequest];
    
    NSDictionary* params = @{
        @"mobile": [getPeopleID PeopleIphoneNmber]
    };
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post:url Params:params Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            NSString*describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
            if ([state isEqualToString:@"200"]) {
                
                NSString*url = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
                
//                NSMutableCharacterSet *lastSet = [[NSMutableCharacterSet alloc] init];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"-_.!~*;/?:@&=$,#"]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];
//                   [lastSet formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
//
//                url = [url stringByAddingPercentEncodingWithAllowedCharacters:lastSet];
                
                if ([self.navigationController.visibleViewController isKindOfClass:[GovInfoViewController class]]) {
                    Web2ViewController * vc = [Web2ViewController new];
                    vc.title= @"便民药房";
                    vc.skipUrl = [NSURL URLWithString:url];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                
              
                
                
            }else{
                [SVProgressHUD showErrorWithStatus:describe];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器异常"];
        }
        
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
    }];
    
}



#pragma mark - 获取联合登录链接
- (void)getFederatedLoginRequestWithModel:(KKRedPackageClickEventModel *)model
{
    NSString *url = [NSString stringWithFormat:@"%@",model.content];
    
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
    
    NSDictionary *params = @{
        @"uid":@([getPeopleID PeopleID]),
        @"tel":[getPeopleID PeopleIphoneNmber]
    };
    
    NSLog(@"联合登录url:%@",url);
    NSLog(@"params:%@",params);
    [KKLoadingAnimationView show];
    [NetworkRequest Get: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"]) {
            NSString *url = [NSString stringWithFormat:@"%@",objc[@"result"]];
            
            url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
           
            [self jumpToHTML5:url andJAnalytics:model.menuName];
            
            
        }else{
            [self alertShow:describe];
        }
        
        
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络异常"];
    }];
    
}


#pragma mark - 提示
- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }else{
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}

#pragma mark - 创建定时器
- (void)creatTimer {
    
    TimerProxy *proxy = [[TimerProxy alloc]initWithTarget:self];
    
    self.timer = [NSTimer timerWithTimeInterval:4.0 target:proxy selector:@selector(timerMethod1) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
    
    [self timerMethod1];
}

#pragma mark - 定时器绑定方法
- (void)timerMethod1
{
    self.showWeather = !self.showWeather;
    
    if (self.showWeather && self.weatherDic) {
        
        self.newsHeaderView.lb_lunDate.text = [Tools getLunarDate];
        NSString *low_temp = self.weatherDic[@"today"][@"low_temp"];
        NSString *high_temp = self.weatherDic[@"today"][@"high_temp"];
        if (low_temp.length > 3 && high_temp.length > 3) {
            self.newsHeaderView.lb_dateAndWeather.text = [NSString stringWithFormat:@"%@ %@~%@ %@",[Tools getInternationDate],[low_temp substringFromIndex:2],[high_temp substringFromIndex:2],self.weatherDic[@"today"][@"weather"]];
        }
        
        [self.newsHeaderView.signBtn  setTitle:@"今日运势" forState:UIControlStateNormal];
        
    }else{
        
        if (self.coinSigned) {
            self.newsHeaderView.lb_lunDate.text = @"今日签到";
            self.newsHeaderView.lb_dateAndWeather.text = @"连续签到拿更多金币奖励";
            
            [self.newsHeaderView.signBtn  setTitle:@"已签到" forState:UIControlStateNormal];
        }else{
            self.newsHeaderView.lb_lunDate.text = @"今日签到";
            self.newsHeaderView.lb_dateAndWeather.text = @"连续签到拿更多金币奖励";
            
            [self.newsHeaderView.signBtn  setTitle:@"领取金币" forState:UIControlStateNormal];
        }
        
       
    }
}


#pragma mark - GovBtnTableViewCellDelegate
//默认情况下的回调方法
- (void)GovBtnClickWithIndex:(NSInteger)index
{
    switch (index) {
        case 0:
        {
            [self goToAuthQueryVC];//认证查询
        }
            break;
        case 1:
        {
            [self goToMarkProgressQueryVC];//登记进度查询
        }
            break;
        case 2:
        {
            [self goToBuTieMarkVC];//补贴登记
        }
            break;
        case 3:
        {
            [self goToSheBaoOrgsVC];//社保机构
        }
            break;
        case 4:
        {
            //[self jumpToHTML5:@"https://m.tianxiaxinyong.com/cooperation/crp-v2/index.html?txxychannel=bmhsNmsyMTJKSmFpTjVDTm5YY3R2Zz09&txxysp=1" andJAnalytics:@"防骗检测"];
            [[clickEvent instance] clickEventRooterVC:self Content:@"miniPaySocial" menuName:@"缴社保"];
        }
            break;
        case 5:
        {
            [self jumpToHTML5:@"http://hotline.treeyee.com" andJAnalytics:@"救助热线"];
        }
            break;
        case 6:
        {
            [self goToHospitalVC];//医院
        }
            break;
        case 7:
        {
            [self goToBeadHouseVC];//养老院
        }
            break;
            
        default:
            break;
    }
}

//根据后台返回的数据的回调方法
- (void)GovBtnClickWithServerModel:(KKRedPackageClickEventModel *)model
{
    [self goToClickServeReturnRedPackageVCWithModel:model];
}

#pragma mark - GovNewsHeaderViewDelegate
- (void)GovNewsHeaderViewClickBtnWithIndex:(NSInteger)index
{
    switch (index) {
        case 200:
        case 201:
        {
            if (self.showWeather && self.weatherDic){
//                [self jumpToHTML5:@"https://mobile.51wnl.com/web/#/index"andJAnalytics:@"万年历"];
                [self jumpToHTML5:@"http://nginx.weface.com.cn/appH5/calendar/#/"andJAnalytics:@"万年历"];
            }else{
                CoinsCenterViewController *vc = [[CoinsCenterViewController alloc]init];
                vc.title = @"金币中心";
                vc.signBlock = ^(BOOL show) {
                    if (show) {
                        [self judgeSignOrNorSignRequest];
                    }
                };
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        }
            break;
        
        
        case 202:
        {
            
            HeadLineViewController*newsVC = [HeadLineViewController new];
            newsVC.title = @"新闻";
            newsVC.from = @"home";
            newsVC.currentIndex = 4;
            newsVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:newsVC animated:YES];
            
//            NewsViewController*newsVC = [NewsViewController new];
//            newsVC.title = @"新闻";
//            newsVC.from = @"home";
//            newsVC.currentIndex = 4;
//            newsVC.hidesBottomBarWhenPushed = YES;
//            [self.navigationController pushViewController:newsVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    return self.newsArray.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        GovBtnTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GovBtnTableViewCell"];
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        cell.delegate = self;
        
        [cell reloadDataWithArray:self.redPackageClickEventsArray];
        
        return cell;
    }
    
    JHNewsModel* newsModel = self.newsArray[indexPath.row];
    
    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;
    }
    
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        GovNewsHeaderView * headerView = [[GovNewsHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 91 * WIDTHRADIU)];
        headerView.delegate = self;
        headerView.Gov=self;
        self.newsHeaderView = headerView;
        return headerView;
    }
    return nil;
}


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

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

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return 210 * WIDTHRADIU;
    }
    return UITableViewAutomaticDimension;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 1) {
        
        
        JHNewsModel* newsModel = self.newsArray[indexPath.row];
        
        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;
       
        
        [self.navigationController pushViewController:vc animated:YES];
        
    }
   
    
    
}







#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
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)btnClick:(UIButton *)sender
{
    
    NSString*city = [[NSUserDefaults standardUserDefaults]objectForKey:@"locationCity"];
    if ([NSString blankString:city]) {
               city = @"北京市";
    }
    if (sender == btn3) {
        WKSuperViewController *tc=[[WKSuperViewController alloc]init];
        tc.titleStr=@"政务信息";
        tc.pathStr=@"http://www.mohrss.gov.cn/wap/xw/";
        [self.navigationController pushViewController:tc animated:YES];
    }else if (sender == btn1){
       
        WebViewController *tc=[WebViewController new];
        
        NSString*url = [NSString stringWithFormat:@"http://nginx.weface.com.cn/appH5/government/lib/ssi.html?city=%@",city];
        url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        tc.URL =[NSURL URLWithString:url];
                tc.hidesBottomBarWhenPushed =YES;
        tc.janalytics = @"社保机构";
        [self.navigationController pushViewController:tc animated:YES];
    }else if (sender == btn2){
        WebViewController *tc=[WebViewController new];
        NSString*url = [NSString stringWithFormat:@"http://nginx.weface.com.cn/appH5/government/lib/oldPeople.html?city=%@",city];
        url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
       tc.URL =[NSURL URLWithString:url];
              tc.hidesBottomBarWhenPushed =YES;
       tc.janalytics = @"养老院";
       [self.navigationController pushViewController:tc animated:YES];
    }
    
}

#pragma mark - 未登录跳转

- (void)unLoginTap {
    [[NSNotificationCenter defaultCenter]postNotificationName:KKSBJumpLoginVCNotificationName object:nil];
}



#pragma mark - 后台控制的点击事件
- (void)goToClickServeReturnRedPackageVCWithModel:(KKRedPackageClickEventModel *)model
{
    
    
    if (model.whetherLogin.boolValue && ![[NSUserDefaults standardUserDefaults]boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    
    switch (model.type.integerValue) {
        case 1001:
            //原生
        {
            if ([model.menuTag isEqualToString:@"govPMYF"]) {
                [self getKangAiDuoUrlRequest];//便民药房
            }else if ([model.menuTag isEqualToString:@"govYY"]){
                [self goToHospitalVC];//医院
            }else if ([model.menuTag isEqualToString:@"govYLY"]){
                [self goToBeadHouseVC];//养老院
            }else if ([model.menuTag isEqualToString:@"govSBJG"]){
                [self goToSheBaoOrgsVC];//社保机构
            }else if ([model.menuTag isEqualToString:@"govSBCX"]){
                [self goToMarkProgressQueryVC];//申报查询
            }
           
        }
            break;
        case 1002:
            //h5
        {
            if ([model.menuName isEqualToString:@"救助热线"]) {
                [self jumpToHTML5:@"http://hotline.treeyee.com" andJAnalytics:@"救助热线"];
                return;
            }
            
            WebVC *vc = [[WebVC alloc]init];
            vc.title = model.menuName;
            vc.url = model.content;
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
           
        }
            break;
        case 1003:
            //小程序
        {
            if (![WXApi isWXAppInstalled]){
                [Tools showMessage:@"请安装微信APP后重试"];
                return;
            }
            
            WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
            launchMiniProgramReq.userName = @"gh_f8a0e531525d";  //拉起的小程序的username
            launchMiniProgramReq.path = @"pages/base/redirect/index?routeKey=PH04_PRODUCT_TRANSFER_CY&wtagid=118.4.2";    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
            launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
            [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                
            }];
           
        }
            break;
        case 1004:
            //其他
        {
            NSDictionary *dic = [self dictionaryWithJsonString:model.content];
            if (dic) {
                [self push:dic model:model];
            }
            
        }
            break;
        case 1005:
        {
            [self getFederatedLoginRequestWithModel:model];
        }
            break;
            
        default:
            break;
    }
    
    
   
    
    
}

#pragma mark - 发射跳转
- (void)push:(NSDictionary *)params model:(KKRedPackageClickEventModel *)model
{
    // 类名
    NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]];
    const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding];
    
    // 从一个字串返回一个类
    Class newClass = objc_getClass(className);
    if (!newClass)
    {
        // 创建一个类
        Class superClass = [NSObject class];
        newClass = objc_allocateClassPair(superClass, className, 0);
        // 注册你创建的这个类
        objc_registerClassPair(newClass);
    }
    // 创建对象
    
    UIViewController* instance = nil;
    
    NSString *classType =[NSString stringWithFormat:@"%@", params[@"classType"]];
    if ([classType isEqualToString:@"storyboard"]) {
        instance = [Storyboard instantiateViewControllerWithIdentifier:class];
    }else if ([classType isEqualToString:@"class"]){
        instance = [[newClass alloc] init];
    }
    
     
    
    // 对该对象赋值属性
    NSDictionary * propertys = params[@"property"];
    [propertys enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        // 检测这个对象是否存在该属性
        if ([self checkIsExistPropertyWithInstance:instance verifyPropertyName:key]) {
            // 利用kvc赋值
            [instance setValue:obj forKey:key];
        }
    }];
    
    instance.title = model.menuName;
    
    instance.hidesBottomBarWhenPushed = YES;
    // 跳转到对应的控制器
    [self.navigationController pushViewController:instance animated:YES];
}


- (BOOL)checkIsExistPropertyWithInstance:(id)instance verifyPropertyName:(NSString *)verifyPropertyName
{
    unsigned int outCount, i;
    
    // 获取对象里的属性列表
    objc_property_t * properties = class_copyPropertyList([instance
                                                           class], &outCount);
    
    for (i = 0; i < outCount; i++) {
        objc_property_t property =properties[i];
        //  属性名转成字符串
        NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
        // 判断该属性是否存在
        if ([propertyName isEqualToString:verifyPropertyName]) {
            free(properties);
            return YES;
        }
    }
    free(properties);
    
    return NO;
}

#pragma mark - 认证查询
- (void)goToAuthQueryVC
{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    
    WeiJianQueryViewController* vc = [WeiJianQueryViewController new];
    vc.title = @"认证查询";
    [self.navigationController pushViewController:vc animated:YES];
    return;
}

#pragma mark - 补贴登记
- (void)goToBuTieMarkVC
{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    HeathOrganViewController* hoVC =  [Storyboard instantiateViewControllerWithIdentifier:@"HeathOrganViewController"];;
    hoVC.title = @"补贴办理";
    [self.navigationController pushViewController:hoVC animated:YES];
}

#pragma mark - 申报查询
- (void)goToMarkProgressQueryVC
{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstlog"]) {
        [self unLoginTap];
        return;
    }
    ApplyStateQueryViewController* vc = [ApplyStateQueryViewController new];
    vc.title = @"申报查询";
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 医院
- (void)goToHospitalVC
{
    NSString*city = [[NSUserDefaults standardUserDefaults]objectForKey:@"locationCity"];
    NSString*county = [[NSUserDefaults standardUserDefaults]objectForKey:@"locationCounty"];
     if ([NSString blankString:city]) {
        city = @"北京市";
        county = @"朝阳区";
     }
    NSString *adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
    NSString*s = [NSString stringWithFormat:@"uid=%ld&deviceid=%@&mobile=%@",[getPeopleID PeopleID],adId,[getPeopleID PeopleIphoneNmber]];
    NSString*url = [NSString stringWithFormat:@"http://nginx.weface.com.cn/appH5/government/lib/hospital.html?city=%@&county=%@&%@",city,county,s];
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    WebViewController *tc=[WebViewController new];
    tc.URL =[NSURL URLWithString:url];
    tc.janalytics = @"医院";
    [self.navigationController pushViewController:tc animated:YES];
    
}

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

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

#pragma mark - 防骗检测
- (void)goToPreventionVCWithModel:(KKRedPackageClickEventModel *)model
{
    [self jumpToHTML5:[model.content stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]] andJAnalytics:model.menuName];
}


#pragma mark - h5页面跳转
-(void)jumpToHTML5:(NSString*)url andJAnalytics:(NSString*)janalytics
{
    Web2ViewController*tc = [Web2ViewController new];
    tc.skipUrl =[NSURL URLWithString:url];
    tc.title = janalytics;
    [self.navigationController pushViewController:tc animated:YES];
}

#pragma mark - json 转字典
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }

    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}




#pragma mark - getters and setters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, SCREEN_WIDTH, ScreenHeight)];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, ScreenHeight);
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.delegate = self;
         _scrollView.contentOffset = CGPointMake(ScreenWidth, 475 * WIDTHRADIU);
        _scrollView.contentOffset = CGPointMake(0, 0);
        _scrollView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        
        
        //顶部背景图
        UIImageView* topBackImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * 111 /375.0)];
        topBackImg.image = [UIImage imageNamed:@"zhengwu_banner"];
        [_scrollView addSubview:topBackImg];
        
        
        //UICollectionView
        UICollectionViewFlowLayout *fl = [[UICollectionViewFlowLayout alloc]init];
        //布局
        fl.minimumLineSpacing = 1.0;
        fl.minimumInteritemSpacing = 1.0;
               
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(topBackImg.frame), ScreenWidth, 210 * WIDTHRADIU) collectionViewLayout:fl];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.scrollEnabled = NO;
       
        // _collectionView.backgroundColor = K_GrayColor;
       
        _collectionView.backgroundColor = [UIColor whiteColor];
        
       
        //cell注册
        [_collectionView registerNib:[UINib nibWithNibName:@"ZWCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
        //[_collectionView registerNib:[UINib nibWithNibName:@"ZWHeaderViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell2"];
        
        [_scrollView addSubview:_collectionView];
        
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(_collectionView.frame), ScreenWidth, ScreenHeight - cl_kNavigationBarHeight  - 41) style:UITableViewStyleGrouped];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
        _tableView.scrollEnabled = NO;
        
        _tableView.estimatedSectionFooterHeight = 10;
        _tableView.estimatedSectionHeaderHeight = 10;
        _tableView.estimatedRowHeight = 50;
        [_tableView registerNib:[UINib nibWithNibName:@"NewsListTableViewCell" bundle:nil] forCellReuseIdentifier:@"NewsListTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsList2Cell" bundle:nil] forCellReuseIdentifier:@"NewsList2Cell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsTextCell" bundle:nil] forCellReuseIdentifier:@"NewsTextCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsImagesCell" bundle:nil] forCellReuseIdentifier:@"NewsImagesCell"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"nativeexpresscell"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"BUDNativeExpressCell"];
        
        [_scrollView addSubview:_tableView];
        

        
        
        
//        HomeVideoContentCell *videoCell = [[HomeVideoContentCell alloc]init];
//        videoCell.frame = CGRectMake(0, CGRectGetMaxY(_tableView.frame), ScreenWidth, ScreenHeight);
//        [_scrollView addSubview:videoCell];
//        [videoCell setupVideoVCWithSelf:self];
        
//        KSCUFeedPage *feedPage = [[KSCUFeedPage alloc] initWithPosId:@"6030000009"];
//        feedPage.videoStateDelegate = self;
//        feedPage.stateDelegate = self;
//        feedPage.callBackDelegate = self;
//        feedPage.hidesBottomBarWhenPushed = YES;
//        UIViewController *vc1 = feedPage.feedViewController;
//        [vc1 setKscu_feedPageDelegate:self];
//        [self addChildViewController:vc1];
//        UIView *ksview=vc1.view;
//        ksview.frame=CGRectMake(0, CGRectGetMaxY(_collectionView.frame), ScreenWidth, ScreenHeight + 52);
//        [_scrollView addSubview:ksview];
//        [vc1.view mas_makeConstraints:^(MASConstraintMaker *make) {
//            //make.top.equalTo(self.newsHeaderView.mas_bottom).offset(20);
//            make.top.right.bottom.left.offset(0);
//        }];
//       
        
    }
    return _scrollView;
}


- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,cl_kNavigationBarHeight, ScreenWidth, WIDTHRADIU*370) 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:[GovBtnTableViewCell class] forCellReuseIdentifier:@"GovBtnTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsListTableViewCell" bundle:nil] forCellReuseIdentifier:@"NewsListTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsList2Cell" bundle:nil] forCellReuseIdentifier:@"NewsList2Cell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsTextCell" bundle:nil] forCellReuseIdentifier:@"NewsTextCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"NewsImagesCell" bundle:nil] forCellReuseIdentifier:@"NewsImagesCell"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"nativeexpresscell"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"BUDNativeExpressCell"];
        _tableView.tableHeaderView = self.topImg;
        
    }
    
    return _tableView;
}




- (UIImageView *)topImg
{
    if (!_topImg) {
        _topImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * 110/375.0) ];
        _topImg.image = [UIImage imageNamed:@"zhengwu_banner"];
        //_topImg.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _topImg;
}

- (NSArray *)bgArray
{
    if (!_bgArray) {
//        if (self.btnHidden){
//            _bgArray = @[@"zw_renzhengchaxun",@"zw_butie",@"zw_jindu",@"zw_zhengwuxinxi",@"zw_shebaojigou",@"zw_minzheng",@"zw_helptel",@"zw_yanglaoyuan"];
//        }else{
//            _bgArray = @[@"zw_renzhengchaxun",@"zw_butie",@"zw_bmyf",@"zw_zhengwuxinxi",@"zw_shebaojigou",@"zw_hosptial",@"zw_minzheng",@"zw_helptel",@"zw_yanglaoyuan"];
//        }
        
    
        _bgArray = @[@"zw_renzhengchaxun",@"zw_jindu",@"zw_butie",@"zw_shebaojigou",@"zw_fp",@"zw_helptel",@"zw_hosptial",@"zw_yanglaoyuan"];
        
    }
    return _bgArray;
}


- (NSArray *)titleArray
{
    if (!_titleArray) {
//        if (self.btnHidden) {
//            _titleArray = @[@"认证查询",@"补贴登记",@"申报查询",@"国家人社部",@"社保机构",@"民政部",@"救助热线",@"养老院"];
//        }else{
//            _titleArray = @[@"认证查询",@"补贴登记",@"便民药房",@"国家人社部",@"社保机构",@"医院",@"民政部",@"救助热线",@"养老院"];
//        }
        
        _titleArray = @[@"认证查询",@"申报查询",@"补贴登记",@"社保机构",@"缴社保",@"救助热线",@"医院",@"养老院"];
        
    }
    return _titleArray;
}

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