//
//  KKDealIdPhotoVC.m
//  Open
//
//  Created by qxy on 2021/10/13.
//  Copyright © 2021 QXY . All rights reserved.
//

#import "GovNewVc.h"
#import "KKPictureEditVC.h"
#import "KKCarPictureEditVC.h"
#import "IdPhotoBottom.h"
#import "WebVC.h"
#import "GovTopGride.h"
#import "GovBottomGride.h"
@interface GovNewVc ()<UIGestureRecognizerDelegate,GovTopGrideDelegate,GovBottomGrideDelegate>

@property (nonatomic, assign) UIView *navBar;
@property (nonatomic, assign) UIView *topGroup;
@property (nonatomic, assign) UIImageView *centerImage;
@property (nonatomic, strong)NSArray* bottomArray;
@property (nonatomic, strong)NSArray* floatArray;
@end

@implementation GovNewVc
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithHex:0xF5F5F5];
    [self navConfig];
    [self topView];
    [self topGridView];
    [self bottomView];
}
-(void)bottomView{
    UILabel* bottomText = [UILabel new];
    bottomText.text=@"热门服务";
    bottomText.font = [UIFont systemFontOfSize:17 * WIDTHRADIU];
    bottomText.textColor=[UIColor colorWithHex:0x4c4c4c];
    [self.view addSubview:bottomText];
    [bottomText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.centerImage.mas_bottom).offset(15*WIDTHRADIU);
        make.left.offset(10*WIDTHRADIU);
    }];
    
    UIView *gridView = [[UIView alloc]init];

    [self.view addSubview:gridView];
    [gridView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomText.mas_bottom);
        make.width.offset(ScreenWidth);
        make.height.offset(180*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    
    GovBottomGride *vc=[[GovBottomGride alloc]initWithFrame:CGRectMake(10*WIDTHRADIU, 10*WIDTHRADIU, ScreenWidth, 180*WIDTHRADIU)];
    vc.delegate=self;
    vc.reloadData;
    [gridView addSubview:vc];
    
    UIImageView *floatView=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-90*WIDTHRADIU, ScreenHeight-100*WIDTHRADIU, 60*WIDTHRADIU, 70*WIDTHRADIU)];
    floatView.image=[UIImage imageNamed:@"gov_float_image"];
    floatView.userInteractionEnabled=YES;
    UITapGestureRecognizer *floatClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(govFloatView:)];
    [floatView addGestureRecognizer:floatClick];
    [self.view addSubview:floatView];
    
    NSString *url = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    NSDictionary *params = @{
        @"configName":@"GovNewFloatView",
        @"appName":@"kksh",
        @"version":[Tools getVersionCode],
        @"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.floatArray = [KKRedPackageClickEventModel mj_objectArrayWithKeyValuesArray:objc[@"result"]];
                    KKRedPackageClickEventModel *model=self.floatArray[0];
                    [floatView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KKFindPackageIP,model.menuIcon]]];
                   
                }
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}


-(void)topGridView{
    UIView *gridView = [[UIView alloc]init];
    gridView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:gridView];
    [gridView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topGroup.mas_bottom);
        make.width.offset(ScreenWidth);
        make.height.offset(180*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    GovTopGride *vc=[[GovTopGride alloc]initWithFrame:CGRectMake(0, 15*WIDTHRADIU, ScreenWidth, 160*WIDTHRADIU)];
    vc.delegate=self;
    vc.reloadData;
    [gridView addSubview:vc];
    
    UIImageView* topImage = [UIImageView new];
    topImage.image=[UIImage imageNamed:@"gov_center_new_01"];
    topImage.userInteractionEnabled=YES;
    UITapGestureRecognizer *center = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(centerPagerClick:)];
    [topImage addGestureRecognizer:center];
    self.centerImage=topImage;
    [self.view addSubview:topImage];
    [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(vc.mas_bottom).offset(10*WIDTHRADIU);
        make.width.offset(ScreenWidth-20*WIDTHRADIU);
        make.height.offset(95*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    
}
-(void)GovBottomGrideItemClick:(NSInteger)item :(KKRedPackageClickEventModel *)model{
    if(model==nil){
        switch (item) {
            case 0://有所扶
                [Tools smallProgram:@"gh_0e163ff2ba74" :@"gss-canlian/pages/weakhelp/index/index.html"];
                break;
            case 1://社会救助
                [Tools smallProgram:@"gh_dc5faf6be488" :@"publicService/pages/hotline/hotline.html?footer=本服务由中国政府网和民政部社会救助司联合提供&id=106&title=各地社会救助服务热线"];
                break;
            case 2:////老年人服务
                [Tools smallProgram:@"gh_0e163ff2ba74" :@"chunyun/pages/oldPeople/index/index.html"];
                break;
            case 3://一网通办
                [Tools smallProgram:@"gh_0e163ff2ba74" :@"personalCenter/pages/netHalf/index/index.html"];
                break;
            case 4://医保机构
                [Tools smallProgram:@"gh_0e163ff2ba74" :@"yibaofuwu/pages/medPotIns/index.html"];
                break;
            case 5://医保服务
                [Tools smallProgram:@"gh_0e163ff2ba74" :@"yibaofuwu/pages/preFecture/index.html"];
                break;
            default:
                break;
        }
    }else{
        [[clickEvent instance] clickEventNative:self model:model];
    }
}

- (void)GovTopGrideItemClick:(NSInteger)item:(KKRedPackageClickEventModel*)model{
    if(model==nil){
        BOOL alipay=[Tools isInstallAlipay];
        switch (item) {
            case 0://认证记录
                [[clickEvent instance] clickEventRooterVC:self Content:@"homeNewAuthRecord" menuName:@"homeNewAuthRecord"];
                break;
            case 1://政务
                if(alipay){
                    [Tools openUri:@"alipays://platformapi/startapp?appId=2021002178691136"];
                }else{
                    [Tools smallProgram:@"gh_dc5faf6be488" :@""];
                }
                break;
            case 2://民政
                if(alipay){
                    [Tools openUri:@"alipays://platformapi/startapp?appId=2021001123608001"];
                }else{
                    [Tools smallProgram:@"gh_2e039694bf46" :@""];
                }
                break;
            case 3://人社
                if(alipay){
                    [Tools openUri:@"alipays://platformapi/startapp?appId=2021001152625231"];
                }else{
                    [Tools smallProgram:@"gh_ea87a49ea2ec" :@""];
                }
                break;
            case 4://养老
                if(alipay){
                    [Tools openUri:@"alipays://platformapi/startapp?appId=2021002151675549"];
                }else{
                    [Tools smallProgram:@"gh_1221cf5490f9" :@""];
                }
                break;
            case 5://医保服务
                //[[clickEvent instance] clickEventRooterVC:self Content:@"SbDoSth" menuName:@"SbDoSth"];
                [Tools smallProgram:@"gh_0e163ff2ba74" :@"yibaofuwu/pages/preFecture/index.html"];
                break;
            case 6://公积金
                if(alipay){
                    [Tools openUri:@"alipays://platformapi/startapp?appId=2019060365493242"];
                }else{
                    [Tools smallProgram:@"gh_95fd1700c01e" :@""];
                }
                break;
            case 7://异地就医
                if(alipay){
                    [Tools openUri:@"alipays://platformapi/startapp?appId=2021002190631903"];
                }else{
                    [Tools smallProgram:@"gh_95fd1700c01e" :@""];
                }
                break;
            default:
                break;
        }
    }else{
        [[clickEvent instance] clickEventNative:self model:model];
    }
}

-(void)topView{
    UIView*topView = [[UIView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, 80*WIDTHRADIU)];
    [self.view addSubview:topView];
    self.topGroup=topView;
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navBar.mas_bottom);
        make.width.offset(ScreenWidth);
        make.height.offset(80*WIDTHRADIU);
    }];
    //topView.backgroundColor=K_MainColor;
    UIImageView* topImage = [UIImageView new];
    topImage.backgroundColor=K_MainColor;
    [topView addSubview:topImage];
    [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(ScreenWidth);
        make.height.offset(80*WIDTHRADIU);
    }];
    
    UIView* essGroup = [UIView new];
    essGroup.backgroundColor=[UIColor colorWithHex:0x31C1F3];
    //设置所需的圆角位置以及大小
    essGroup.frame = CGRectMake(0, 0, ScreenWidth-20*WIDTHRADIU, 60*WIDTHRADIU);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:essGroup.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = essGroup.bounds;
    maskLayer.path = maskPath.CGPath;
    essGroup.layer.mask = maskLayer;
    [topView addSubview:essGroup];
    
    [essGroup mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20*WIDTHRADIU);
        make.centerX.equalTo(topView);
        make.width.offset(ScreenWidth-20*WIDTHRADIU);
        make.height.offset(60*WIDTHRADIU);
    }];

    UIImageView* ess = [UIImageView new];
    ess.image  = [UIImage imageNamed:@"gov_ess_new_icon"];
    
    [essGroup addSubview:ess];
    [ess mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(essGroup);
        make.left.offset(20*WIDTHRADIU);
        make.width.height.offset(40*WIDTHRADIU);
    }];

    UILabel* essText = [UILabel new];
    essText.text=@"帮家人领取电子社保卡";
    essText.font = [UIFont systemFontOfSize:16*WIDTHRADIU];
    essText.textColor=[UIColor colorWithHex:0xFFFFFF];
    [essGroup addSubview:essText];
    [essText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(essGroup);
        make.centerY.equalTo(essGroup);
    }];
    UIButton *button=[UIButton new];
    [button setTitle:@"     去领取    " forState:UIControlStateNormal];
    [button setTitleColor:K_MainColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14*WIDTHRADIU];
    button.layer.cornerRadius = 10 * WIDTHRADIU;
    button.layer.masksToBounds = YES;
    button.backgroundColor=[UIColor whiteColor];
    [button addTarget:self action:@selector(goToEss) forControlEvents:UIControlEventTouchUpInside];
    [essGroup addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(essGroup);
        make.left.equalTo(essText.mas_right).offset(10*WIDTHRADIU);
    }];
}

- (void)navConfig{
    UIView*nav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    nav.backgroundColor = K_MainColor;
    [self.view addSubview:nav];
    self.navBar=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*WIDTHRADIU];
    [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);
    }];
}

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

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

- (void)goToEss{
    NSLog(@"社保卡");
    [[clickEvent instance] clickEventRooterVC:self Content:@"homeOne1" menuName:@"homeOne1"];
}

//中部图片
-(void)centerPagerClick:(UITapGestureRecognizer *)tap{
    NSLog(@"个人信息....");
    [[clickEvent instance] clickEventRooterVC:self Content:@"homeNewAuthRecord" menuName:@"homeNewAuthRecord"];
}

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