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

#import "MiniPaySocial.h"

@interface MiniPaySocial()
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, assign) UIView *navBar;
@property (nonatomic, assign) UIView *centerGroup;
@property (nonatomic, assign) UILabel *more;
@property (nonatomic, strong) NSMutableArray *DataArr;
@end

@implementation MiniPaySocial
- (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.title = @"社保缴纳";
    [self center];
    [self navConfig];
    [self bottom];
}
-(void)bottom{
    UILabel *more=[UILabel new];
    more.text=@"更多服务";
    self.more=more;
    [self.view addSubview:more];
    [more mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.centerGroup.mas_bottom).offset(15*WIDTHRADIU);
        make.left.offset(20*WIDTHRADIU);
    }];
    NSString *url1 = [NSString stringWithFormat:@"%@dynamic/menu/get",[NetworkConfig ipYinShuConfig]];
    NSString *version=[Tools getVersionCode];
    NSDictionary *params1 = @{
        @"configName":@"SocialPayBottom",
        @"appName":@"kksh",
        @"version":version,
        @"systemType":@"iOS"
    };
    [NetworkRequest Post15:url1 Params:params1 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.DataArr = [NSMutableArray array];
                    for (NSDictionary *dic in objc[@"result"]) {
                        KKRedPackageClickEventModel *model = [KKRedPackageClickEventModel mj_objectWithKeyValues:dic];
                        [self.DataArr addObject:model];
                    }
                    [self bottomList:self.DataArr];
                }
            }
        }

    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
    
}
-(void) bottomList:(NSMutableArray *)list{
    KKRedPackageClickEventModel *model_01=list[0];
    UIView*bottomGroup = [[UIView alloc]init];
    bottomGroup.backgroundColor=[UIColor whiteColor];
    bottomGroup.layer.cornerRadius = 10 * WIDTHRADIU;
    bottomGroup.layer.masksToBounds = YES;
    [self.view addSubview:bottomGroup];
    [bottomGroup mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.more.mas_bottom).offset(8*WIDTHRADIU);
        make.width.offset(SCREEN_WIDTH-40*WIDTHRADIU);
        make.height.offset(70*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    UIImageView *image=[UIImageView new];
    image.backgroundColor=K_MainColor;
    [bottomGroup addSubview:image];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(5*WIDTHRADIU);
        make.left.offset(2*WIDTHRADIU);
        make.height.offset(67*WIDTHRADIU);
    }];
    UILabel *title=[UILabel new];
    title.text=model_01.menuName;
    title.textColor=[UIColor blackColor];
    title.font=[UIFont boldSystemFontOfSize:18];
    [bottomGroup addSubview:title];
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(image.mas_right).offset(15*WIDTHRADIU);
        make.top.offset(10*WIDTHRADIU);
    }];
    NSString *tag=model_01.menuTag;
    NSDictionary *dic_01=[Tools dictionaryWithJsonString:tag];
    UILabel *des=[UILabel new];
    des.text=dic_01[@"des"];
    des.textColor=[UIColor grayColor];
    des.font=[UIFont systemFontOfSize:15];
    [bottomGroup addSubview:des];
    [des mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(image.mas_right).offset(15*WIDTHRADIU);
        make.top.equalTo(title.mas_bottom).offset(8*WIDTHRADIU);
    }];
    UIButton *button=[UIButton new];
    [button setTitle:dic_01[@"click"] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    button.backgroundColor=K_MainColor;
    button.layer.cornerRadius = 5 * WIDTHRADIU;
    button.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(button01:) forControlEvents:UIControlEventTouchUpInside];
    [bottomGroup addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bottomGroup);
        make.width.offset(80*WIDTHRADIU);
        make.height.offset(30*WIDTHRADIU);
        make.left.offset(SCREEN_WIDTH-130*WIDTHRADIU);
    }];
    
    KKRedPackageClickEventModel *model_02=list[1];
    UIView*bottomGroup2 = [[UIView alloc]init];
    bottomGroup2.backgroundColor=[UIColor whiteColor];
    bottomGroup2.layer.cornerRadius = 10 * WIDTHRADIU;
    bottomGroup2.layer.masksToBounds = YES;
    [self.view addSubview:bottomGroup2];
    [bottomGroup2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomGroup.mas_bottom).offset(8*WIDTHRADIU);
        make.width.offset(SCREEN_WIDTH-40*WIDTHRADIU);
        make.height.offset(70*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    UIImageView *image2=[UIImageView new];
    image2.backgroundColor=K_MainColor;
    [bottomGroup2 addSubview:image2];
    [image2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(5*WIDTHRADIU);
        make.left.offset(2*WIDTHRADIU);
        make.height.offset(67*WIDTHRADIU);
    }];
    UILabel *title2=[UILabel new];
    title2.text=model_02.menuName;
    title2.textColor=[UIColor blackColor];
    title2.font=[UIFont boldSystemFontOfSize:18];
    [bottomGroup2 addSubview:title2];
    [title2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(image2.mas_right).offset(15*WIDTHRADIU);
        make.top.offset(10*WIDTHRADIU);
    }];
    NSString *tag2=model_02.menuTag;
    NSDictionary *dic_02=[Tools dictionaryWithJsonString:tag2];
    UILabel *des2=[UILabel new];
    des2.text=dic_02[@"des"];
    des2.textColor=[UIColor grayColor];
    des2.font=[UIFont systemFontOfSize:15];
    [bottomGroup2 addSubview:des2];
    [des2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(image2.mas_right).offset(15*WIDTHRADIU);
        make.top.equalTo(title2.mas_bottom).offset(8*WIDTHRADIU);
    }];
    UIButton *button2=[UIButton new];
    [button2 setTitle:dic_01[@"click"] forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize:16];
    button2.backgroundColor=K_MainColor;
    button2.layer.cornerRadius = 5 * WIDTHRADIU;
    button2.layer.masksToBounds = YES;
    [button2 addTarget:self action:@selector(button02:) forControlEvents:UIControlEventTouchUpInside];
    [bottomGroup2 addSubview:button2];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bottomGroup2);
        make.width.offset(80*WIDTHRADIU);
        make.height.offset(30*WIDTHRADIU);
        make.left.offset(SCREEN_WIDTH-130*WIDTHRADIU);
    }];
    
    KKRedPackageClickEventModel *model_03=list[2];
    UIView*bottomGroup3 = [[UIView alloc]init];
    bottomGroup3.backgroundColor=[UIColor whiteColor];
    bottomGroup3.layer.cornerRadius = 10 * WIDTHRADIU;
    bottomGroup3.layer.masksToBounds = YES;
    [self.view addSubview:bottomGroup3];
    [bottomGroup3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomGroup2.mas_bottom).offset(8*WIDTHRADIU);
        make.width.offset(SCREEN_WIDTH-40*WIDTHRADIU);
        make.height.offset(70*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    UIImageView *image3=[UIImageView new];
    image3.backgroundColor=K_MainColor;
    [bottomGroup3 addSubview:image3];
    [image3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(5*WIDTHRADIU);
        make.left.offset(2*WIDTHRADIU);
        make.height.offset(67*WIDTHRADIU);
    }];
    UILabel *title3=[UILabel new];
    title3.text=model_03.menuName;
    title3.textColor=[UIColor blackColor];
    title3.font=[UIFont boldSystemFontOfSize:18];
    [bottomGroup3 addSubview:title3];
    [title3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(image3.mas_right).offset(15*WIDTHRADIU);
        make.top.offset(10*WIDTHRADIU);
    }];
    NSString *tag3=model_03.menuTag;
    NSDictionary *dic_03=[Tools dictionaryWithJsonString:tag3];
    UILabel *des3=[UILabel new];
    des3.text=dic_03[@"des"];
    des3.textColor=[UIColor grayColor];
    des3.font=[UIFont systemFontOfSize:15];
    [bottomGroup3 addSubview:des3];
    [des3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(image3.mas_right).offset(15*WIDTHRADIU);
        make.top.equalTo(title3.mas_bottom).offset(8*WIDTHRADIU);
    }];
    UIButton *button3=[UIButton new];
    [button3 setTitle:dic_03[@"click"] forState:UIControlStateNormal];
    button3.titleLabel.font = [UIFont systemFontOfSize:16];
    button3.backgroundColor=K_MainColor;
    button3.layer.cornerRadius = 5 * WIDTHRADIU;
    button3.layer.masksToBounds = YES;
    [button3 addTarget:self action:@selector(button03:) forControlEvents:UIControlEventTouchUpInside];
    [bottomGroup3 addSubview:button3];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bottomGroup3);
        make.width.offset(80*WIDTHRADIU);
        make.height.offset(30*WIDTHRADIU);
        make.left.offset(SCREEN_WIDTH-130*WIDTHRADIU);
    }];
    
    
    UIView*bottomGroup4 = [[UIView alloc]init];
    bottomGroup4.backgroundColor=[UIColor whiteColor];
    bottomGroup4.layer.cornerRadius = 10 * WIDTHRADIU;
    bottomGroup4.layer.masksToBounds = YES;
    [self.view addSubview:bottomGroup4];
    [bottomGroup4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomGroup3.mas_bottom).offset(15*WIDTHRADIU);
        make.width.offset(SCREEN_WIDTH-60*WIDTHRADIU);
        make.height.offset(50*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    
    UIImageView *leftImage=[UIImageView new];
    leftImage.image=[UIImage imageNamed:@"minipay_01"];
    [bottomGroup4 addSubview:leftImage];
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bottomGroup4);
        make.left.offset(35*WIDTHRADIU);
    }];
    
    UILabel *leftText=[UILabel new];
    leftText.text=@"缴纳流程";
    leftText.textColor=K_MainColor;
    leftText.font=[UIFont systemFontOfSize:17];
    leftText.userInteractionEnabled=YES;
    UITapGestureRecognizer *leftClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftClick:)];
    [leftText addGestureRecognizer:leftClick];
    [bottomGroup4 addSubview:leftText];
    [leftText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftImage.mas_right).offset(5*WIDTHRADIU);
        make.centerY.equalTo(bottomGroup4);
    }];
    
    UILabel *rightText=[UILabel new];
    rightText.text=@"分享好友";
    rightText.textColor=K_MainColor;
    rightText.font=[UIFont systemFontOfSize:17];
    rightText.userInteractionEnabled=YES;
    UITapGestureRecognizer *rightClick = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightClick:)];
    [rightText addGestureRecognizer:rightClick];
    [bottomGroup4 addSubview:rightText];
    [rightText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomGroup4.mas_right).offset(-35*WIDTHRADIU);
        //make.left.equalTo(rightImage.mas_right).offset(1);
        make.centerY.equalTo(bottomGroup4);
    }];
    
    UIImageView *rightImage=[UIImageView new];
    rightImage.image=[UIImage imageNamed:@"minipay_02"];
    [bottomGroup4 addSubview:rightImage];
    [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bottomGroup4);
        make.right.equalTo(rightText.mas_left).offset(-5*WIDTHRADIU);
    }];
    
}

-(void)leftClick:(UITapGestureRecognizer *)tap{
    NSLog(@"%@",@"!!!!!!!!!!!!");
    WebVC *webvc = [[WebVC alloc]init];
    webvc.url=@"https://nginx.weface.com.cn/appH5/openDy/course.html";
    webvc.title=@"缴纳流程";
    [self.navigationController pushViewController:webvc animated:YES];
}

-(void)rightClick:(UITapGestureRecognizer *)tap{
    NSLog(@"%@",@"!!!!!!!!!!!!");
    UMSocialMessageObject *messageObject=[UMSocialMessageObject messageObject];
    UIImage *rightImage=[UIImage imageNamed:@"logo"];
    UMShareWebpageObject *shareObject=[UMShareWebpageObject shareObjectWithTitle:@"新农合、社保、医保在线缴纳" descr:@"看看生活-让缴费更简单（足不出户缴纳新农合、社保、医保)" thumImage:rightImage];
    shareObject.webpageUrl=@"https://nginx.weface.com.cn/appH5/openDy/index.html";
    messageObject.shareObject=shareObject;
    [[UMSocialManager defaultManager]shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            [Tools showMessage:@"分享失败了！"];
        }else{
            //[Tools showMessage:@"分享！"];
        }
    }];
}

#pragma mark - event response
- (void)button01:(UIButton *)sender{
    if (self.DataArr) {
        KKRedPackageClickEventModel *model=self.DataArr[0];
        [[clickEvent instance] clickEventNative:self model:model];
    }else{
        WebVC *webvc = [[WebVC alloc]init];
        webvc.url =[NSString stringWithFormat:@"https://nginx.weface.com.cn/appH5/kk_wallet/#/?userId=%ld&phone=%@", (long)[getPeopleID PeopleID],[getPeopleID PeopleIphoneNmber]];;
        webvc.title = @"养老钱包";
        webvc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:webvc animated:YES];
    }
}

#pragma mark - event response
- (void)button02:(UIButton *)sender{
    if (self.DataArr) {
        KKRedPackageClickEventModel *model=self.DataArr[1];
        [[clickEvent instance] clickEventNative:self model:model];
    }else{
        WebVC *webvc = [[WebVC alloc]init];
        webvc.url =[NSString stringWithFormat:@"https://nginx.weface.com.cn/appH5/kk_wallet/#/?userId=%ld&phone=%@", (long)[getPeopleID PeopleID],[getPeopleID PeopleIphoneNmber]];;
        webvc.title = @"养老钱包";
        webvc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:webvc animated:YES];
    }
}

#pragma mark - event response
- (void)button03:(UIButton *)sender{
    if (self.DataArr) {
        KKRedPackageClickEventModel *model=self.DataArr[2];
        [[clickEvent instance] clickEventNative:self model:model];
    }else{
        WebVC *webvc = [[WebVC alloc]init];
        webvc.url =[NSString stringWithFormat:@"http://www.wodeshebao.com/calc/index.html"];;
        webvc.title = @"社保计算器";
        //webvc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:webvc animated:YES];
    }
}

-(void)center{
    UIImageView* topImage = [UIImageView new];
    topImage.image=[UIImage imageNamed:@"pay_image_01"];
    topImage.contentMode = UIViewContentModeScaleToFill;
    //topImage.backgroundColor = [UIColor clearColor];
    [self.view addSubview:topImage];
    [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.offset(SCREEN_WIDTH);
        make.height.offset(250*WIDTHRADIU);
    }];
    
    UIView*centerGroup = [[UIView alloc]init];
    centerGroup.backgroundColor=[UIColor whiteColor];
    centerGroup.layer.cornerRadius = 10 * WIDTHRADIU;
    centerGroup.layer.masksToBounds = YES;
    [self.view addSubview:centerGroup];
    [centerGroup mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topImage.mas_bottom).offset(-50*WIDTHRADIU);
        make.width.offset(SCREEN_WIDTH-40*WIDTHRADIU);
        make.height.offset(180*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    self.centerGroup=centerGroup;
    
    UILabel *city=[UILabel new];
    city.text=@"上海";
    city.font=[UIFont systemFontOfSize:18];
    city.textColor=[UIColor blackColor];
    [self.centerGroup addSubview:city];
    [city mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(15*WIDTHRADIU);
        make.left.offset(15*WIDTHRADIU);
    }];
    
    UILabel *tips01=[UILabel new];
    tips01.text=@"新农合、社保、医保缴纳";
    tips01.textColor=[UIColor blackColor];
    tips01.font=[UIFont boldSystemFontOfSize:25];
    [self.centerGroup addSubview:tips01];
    [tips01 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(city.mas_bottom).offset(15*WIDTHRADIU);
        make.left.offset(15*WIDTHRADIU);
    }];
    
    UILabel *tips02=[UILabel new];
    tips02.text=@"足不出户也能缴纳新农合、社保、医保";
    tips02.font=[UIFont systemFontOfSize:14];
    tips02.textColor=[UIColor colorWithHex:0x9c9c9c];
    [self.centerGroup addSubview:tips02];
    [tips02 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tips01.mas_bottom).offset(10*WIDTHRADIU);
        make.left.offset(15*WIDTHRADIU);
    }];
    
    UIButton *button=[UIButton new];
    [button setTitle:@"我要缴纳" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:18];
    button.backgroundColor=K_MainColor;
    button.layer.cornerRadius = 10 * WIDTHRADIU;
    button.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(payClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.centerGroup addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tips02.mas_bottom).offset(10*WIDTHRADIU);
        make.centerX.equalTo(self.centerGroup);
        make.width.offset(SCREEN_WIDTH-100*WIDTHRADIU);
        make.height.offset(45*WIDTHRADIU);
    }];
   
}

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


#pragma mark - event response
- (void)payClick:(UIButton *)sender{
    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
    launchMiniProgramReq.userName =@"gh_dca9a59780cf";  //拉起的小程序的username
    launchMiniProgramReq.path = nil;    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
    [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
        
    }];
}

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



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