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

#import "LoginOff.h"
#import "WebVC.h"
@interface LoginOff ()<UINavigationControllerDelegate,UIGestureRecognizerDelegate>
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, assign) UIView *navBar;
@property (nonatomic, assign) UIView *centerGroup;
@property (nonatomic, strong)NSArray* bottomArray;
@end

@implementation LoginOff
- (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 centerText];
}

-(void) centerText{
    UIImageView *image=[UIImageView new];
    image.image=[UIImage imageNamed:@"login_off"];
    [self.view addSubview:image];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navBar.mas_bottom).offset(20*WIDTHRADIU);
        make.height.offset(80*WIDTHRADIU);
        make.width.offset(80*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    UILabel *tel=[UILabel new];
    NSString *number = [getPeopleID PeopleIphoneNmber];
    tel.text=[NSString stringWithFormat:@"注销%@****%@绑定的账号",[number substringToIndex:2],[number substringFromIndex:8]] ;
    tel.font=[UIFont boldSystemFontOfSize:20*WIDTHRADIU];
    [self.view addSubview:tel];
    [tel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(image.mas_bottom).offset(20*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    
    UILabel *des=[UILabel new];
    des.text=@"注销账号后您的账号下相关信息将被清空且无法找回,包括但不限于:";
    des.font=[UIFont systemFontOfSize:16*WIDTHRADIU];
    des.lineBreakMode = UILineBreakModeWordWrap;
    des.numberOfLines = 0;
    des.textColor=[UIColor colorWithHex:0x8d8d8d];
    [self.view addSubview:des];
    [des mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tel.mas_bottom).offset(20*WIDTHRADIU);
        make.width.offset(SCREEN_WIDTH-30*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    
    UILabel *detail1=[UILabel new];
    detail1.text=@"1,认证的记录";
    detail1.textColor=[UIColor colorWithHex:0x4d4d4d];
    [self.view addSubview:detail1];
    [detail1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(des.mas_bottom).offset(25*WIDTHRADIU);
        make.left.offset(15*WIDTHRADIU);
    }];
    
    UILabel *detail2=[UILabel new];
    detail2.text=@"2,获得的金币";
    detail2.textColor=[UIColor colorWithHex:0x4d4d4d];
    [self.view addSubview:detail2];
    [detail2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(detail1.mas_bottom).offset(15*WIDTHRADIU);
        make.left.offset(15*WIDTHRADIU);
    }];
    
    UILabel *detail3=[UILabel new];
    detail3.text=@"3,获得的奖品";
    detail3.textColor=[UIColor colorWithHex:0x4d4d4d];
    [self.view addSubview:detail3];
    [detail3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(detail2.mas_bottom).offset(15*WIDTHRADIU);
        make.left.offset(15*WIDTHRADIU);
    }];
    
    UIButton* pri = [UIButton buttonWithType:UIButtonTypeCustom];
    [pri setTitle:@"点击【确认注销】即代表您已同意《用户注销协议》" forState:UIControlStateNormal];
    [pri setTitleColor:K_MainColor forState:UIControlStateNormal];
    pri.titleLabel.font = [UIFont systemFontOfSize:15];
    [pri addTarget:self action:@selector(priClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pri];
    [pri mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view.mas_bottom).mas_equalTo(-45);
        make.centerX.equalTo(self.view);
    }];
    
    UIButton *loginoff = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginoff setTitle:@"确认注销" forState:UIControlStateNormal];
    [loginoff setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    loginoff.titleLabel.font = [UIFont systemFontOfSize:18*WIDTHRADIU];
    loginoff.backgroundColor = K_MainColor;
    loginoff.layer.cornerRadius=10*WIDTHRADIU;
    //loginoff.layer.maskedCorners=YES;
    [self.view addSubview:loginoff];
    [loginoff addTarget:self action:@selector(logOffClick:) forControlEvents:UIControlEventTouchUpInside];
    [loginoff mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(pri.mas_top).mas_equalTo(-25);
        make.width.offset(ScreenWidth-50*WIDTHRADIU);
        make.height.offset(40*WIDTHRADIU);
        make.centerX.equalTo(self.view);
    }];
    
}
- (void)logOffClick:(UIButton *)sender{
    NSLog(@"logOffClick");
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"账号注销" message:@"确认注销当前账号?" preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击取消");
    }]];
    
    [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击确认");
        
        NSString *url = [NSString stringWithFormat:@"https://socialsecurity.weface.com.cn:8066/socialsecurity/kankan/closeAccount?Id=%ld&telphone=%@&targetflag=%@",(long)[getPeopleID PeopleID],[getPeopleID PeopleUnPhoneNmber],@"2"];
        NSDictionary *params = @{
           
        };
        [NetworkRequest Post15:url Params:params Success:^(id _Nonnull objc) {
            NSLog(@"objc:%@",objc);
            if ([objc isKindOfClass:[NSDictionary class]]) {
                NSString *state = [NSString stringWithFormat:@"%@",objc[@"code"]];
                if ([state isEqualToString:@"0"]) {
                    [self.delegate loginOffResult];
                }else{
                    [XYProgressHUD showMessage:@"注销错误"];
                }
            }
        } Failure:^(NSError *error) {
            NSLog(@"error:%@",error);
        }];
    }]];
    
     [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)priClick{
    WebVC * vc = [WebVC new];
    vc.title= @"注销协议";
    vc.url = @"http://kefu.weface.com.cn/ys/kksh_login_off.html";
    [self.navigationController pushViewController:vc animated:YES];
}

- (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:@"blackBack"] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor colorWithHex:0x4d4d4d] 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 colorWithHex:0x4d4d4d];
    [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)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
