//
//  OPenAccountController.m
//  Open
//
//  Created by 雷俊博 on 2020/7/29.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "OPenAccountController.h"
#import "UIView+frameAdjust.h"
#import "UIImage+Custom.h"

#import "OPenAccountCardView.h"
#import "OPenAccountTopView.h"
#import "OPenAccountBottomView.h"

#import "ElectronicAccountController.h"


#import "BCRealNameInfoIdentifyController.h"



@interface OPenAccountController ()<UIScrollViewDelegate,SCNavigationControllerDelegate>
{
    UIButton* currentBtn;
    NSString* backImg;
    NSString* frontImg;
    NSString* cardName;
    NSString* cardNo;
}

@property (nonatomic, strong)UIScrollView* scrollView;

@property (nonatomic, strong)UIButton* nextBtn;

@property (nonatomic, strong)UIButton* frontBtn;

@property (nonatomic, strong)UIButton* backBtn;

@property (nonatomic, strong)UIView*bottomView;

@end

@implementation OPenAccountController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:0 target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:bar];
    [GTCountSDK trackCountEvent:@"save_accountOpenInfoCount" withArgs:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.bottomView];
    [self.view addSubview:self.nextBtn];
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomView.mas_bottom).offset(0);
        make.left.right.offset(0);
        make.height.offset(45);
    }];
    
    [self addShadowToView:self.bottomView withColor:[UIColor colorWithHex:0x137ef6 alpha:0.3]];
    
}


#pragma mark - 上传用户协议
- (void)uploadPDFRequest
{
    
    NSString*path =  [[NSBundle mainBundle] pathForResource:@"kkV11" ofType:@"pdf"];
    NSData* data = [NSData dataWithContentsOfFile:path];
    
   NSString *base64String = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    
    //当数据结构为数组时
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSPDFUploadRequest];
    NSDictionary*params = @{
        @"base64":base64String,
        @"name":@"个人信息使用授权书V1.1",
        @"loginId":[NSString stringWithFormat:@"%@",@([getPeopleID PeopleID])]
    };
    
    NSLog(@"银数pdf上传url:%@",url);
    NSLog(@"params:%@",params);
    
    
    [KKLoadingAnimationView show];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil  progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString* describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
//            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            [self uploadOCRImageRequest];
            return;
        }
         [KKLoadingAnimationView dismiss];
                NSDictionary*dic = [Tools dencode:describe];
                NSLog(@"describe:%@",[Tools dencode:describe]);
                NSString*code = nil;
                NSString*message = nil;
                if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                    code = [NSString stringWithFormat:@"%@",dic[@"code"]];
                }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                    code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
                }
                
                if (code) {
                    message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                    
                    if (message) {
                        [SVProgressHUD showErrorWithStatus:message];
                    }else{
                        [SVProgressHUD showErrorWithStatus:@"系统错误"];
                    }
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
                
                
        
    
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
    
    
}

#pragma mark - ocr证件照上传
- (void)uploadOCRImageRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],YSOCRImageUploadRequest];
    
    NSDictionary*params = @{
        @"backImg":backImg,
        @"frontImg":frontImg,
        @"userId":@([getPeopleID PeopleID])
    };
    
    NSLog(@"银数ocr证件照上传url:%@",url);
    NSLog(@"params:%@",params);
    
    //[KKLoadingAnimationView show];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString* describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            SaveOcrInfoModel*model = [SaveOcrInfoModel mj_objectWithKeyValues:dic];
            [GTCountSDK trackCountEvent:@"save_accountOpenElectCount" withArgs:nil];
           ElectronicAccountController* vc = [ElectronicAccountController new];
           vc.title = @"电子账户";
            vc.productModel = self.productModel;
            vc.ocrModel = model;
            vc.from = self.from;
           [self.navigationController pushViewController:vc animated:YES];
            
        }else{
                NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
                NSLog(@"describe:%@",dic);
                NSString*code = nil;
                NSString*message = nil;
                if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                    code = [NSString stringWithFormat:@"%@",dic[@"code"]];
                }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                    code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
                }
                
                if (code) {
                    message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                    
                    if (message) {
                        [SVProgressHUD showErrorWithStatus:message];
                    }else{
                        [SVProgressHUD showErrorWithStatus:@"系统错误"];
                    }
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
                
                
        
            }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
        [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}

#pragma mark - 比财 身份证更新
- (void)bcUploadOCRImageRequest{
    
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCUPDateOCRImageRequest];
    NSLog(@"比财更新身份证url:%@",url);
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:frontImg forKey:@"idcardFrontPhoto"];
    [params setObject:backImg forKey:@"idcardBackPhoto"];
    [params setObject:@"2" forKey:@"transcoding"];
    
    
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6: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"]) {
            [SVProgressHUD showSuccessWithStatus:@"更新成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [Tools showMessage:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
}






#pragma mark - SCNavigationControllerDelegate
- (void)sendIDCValue:(NSString *)name SEX:(NSString *)sex FOLK:(NSString *)folk BIRTHDAY:(NSString *)birthday ADDRESS:(NSString *) address NUM:(NSString *)num
{
   
    cardName = name;
    
    cardNo = num;
    
    cardName = [cardName stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    cardNo =   [cardNo stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    
}

- (void)sendAllValue:(NSString *)text
{
    NSLog(@"all  = %@",text);
    
}
- (void)sendIDCBackValue:(NSString *)issue PERIOD:(NSString *) period
{
    NSLog(@"idcback  = %@\n%@\n",issue,period);
}
- (void)sendCardFaceImage:(UIImage *)image
{
    if (image != NULL) {

//        NSData *small = UIImagePNGRepresentation(image);
        
       
    }

}
- (void)sendFieldImage:(TFIELDID) filed  image:(UIImage *)fieldimage
{
    
    NSLog(@"sendFieldImage = %d %@\n",filed,fieldimage);
    
    
    [self.backBtn setBackgroundImage:fieldimage forState:UIControlStateNormal];

}
- (void)sendTakeImage:(TCARD_TYPE) iCardType image:(UIImage *)cardImage
{
    NSLog(@"sendTakeImage = %d %@\n",iCardType,cardImage);
    NSLog(@"cardImage.size:%@",NSStringFromCGSize(cardImage.size));
    
    UIImage*newImage = [UIImage imageWithImage:cardImage scale:0.4];
    
     NSLog(@"newImage.size:%@",NSStringFromCGSize(newImage.size));
    
    NSData*data = UIImageJPEGRepresentation(newImage, 0.20);
    NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    NSLog(@"newImage.datalength =%ld",data.length);
    NSLog(@"encodedImageStr.length = %ld",encodedImageStr.length);
    
    if (iCardType == TIDCARDBACK) {
        if (currentBtn == self.frontBtn) {
            [SVProgressHUD showErrorWithStatus:@"请拍摄身份证正面"];
            return;
        }
        backImg = encodedImageStr;
        [self.backBtn setBackgroundImage:[UIImage imageWithData:data] forState:UIControlStateNormal];
//        cardBackImg = [UIImage imageWithImage:cardImage scale:0.125];
    }else if (iCardType == TIDCARD2){
        if (currentBtn == self.backBtn) {
            [SVProgressHUD showErrorWithStatus:@"请拍摄身份证背面"];
            return;
        }
        frontImg = encodedImageStr;
        [self.frontBtn setBackgroundImage:[UIImage imageWithData:data]  forState:UIControlStateNormal];
        //cardFrontImg = [UIImage imageWithImage:cardImage scale:0.125];
    }
    
    //NSLog(@"imageWidth:%f,imageHeight:%f",cardFrontImg.size.width,cardFrontImg.size.height);
    
    

}
- (void)sendIDCARDBackAction
{
    
}




#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"y:%lf",scrollView.contentOffset.y);
    if (scrollView.contentOffset.y <= 0) {
        scrollView.contentOffset = CGPointMake(0, 0);
    }
}

#pragma mark - public methods
-(id)getXiblWithClassName:(NSString *)className
{
    return [[NSBundle mainBundle]loadNibNamed:className owner:self options:nil].lastObject;
}
- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {
    
    theView.layer.shadowColor = theColor.CGColor;
    theView.layer.shadowOffset = CGSizeMake(0,0);
    theView.layer.shadowOpacity = 0.5;
    theView.layer.shadowRadius = 5;
    // 单边阴影 顶边
    float shadowPathWidth = theView.layer.shadowRadius;
    CGRect shadowRect = CGRectMake(0, 0-shadowPathWidth/2.0, theView.bounds.size.width, shadowPathWidth);
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:shadowRect];
    theView.layer.shadowPath = path.CGPath;
    
}

/*!
 *  @brief 使图片压缩后刚好小于指定大小
 *
 *  @param image 当前要压缩的图 maxLength 压缩后的大小
 *
 *  @return 图片对象
 */
//图片质量压缩到某一范围内，如果后面用到多，可以抽成分类或者工具类,这里压缩递减比二分的运行时间长，二分可以限制下限。
- (UIImage *)compressImageSize:(UIImage *)image toByte:(NSUInteger)maxLength{
    //首先判断原图大小是否在要求内，如果满足要求则不进行压缩，over
    CGFloat compression = 1;
    NSData *data = UIImageJPEGRepresentation(image, compression);
    if (data.length < maxLength) return image;
    //原图大小超过范围，先进行“压处理”，这里 压缩比 采用二分法进行处理，6次二分后的最小压缩比是0.015625，已经够小了
    CGFloat max = 1;
    CGFloat min = 0;
    for (int i = 0; i < 6; ++i) {
        compression = (max + min) / 2;
        data = UIImageJPEGRepresentation(image, compression);
        if (data.length < maxLength * 0.9) {
            min = compression;
        } else if (data.length > maxLength) {
            max = compression;
        } else {
            break;
        }
    }
    //判断“压处理”的结果是否符合要求，符合要求就over
    UIImage *resultImage = [UIImage imageWithData:data];
    if (data.length < maxLength) return resultImage;
    
    //缩处理，直接用大小的比例作为缩处理的比例进行处理，因为有取整处理，所以一般是需要两次处理
    NSUInteger lastDataLength = 0;
    while (data.length > maxLength && data.length != lastDataLength) {
        lastDataLength = data.length;
        //获取处理后的尺寸
        CGFloat ratio = (CGFloat)maxLength / data.length;
        CGSize size = CGSizeMake((NSUInteger)(resultImage.size.width * sqrtf(ratio)),
                                 (NSUInteger)(resultImage.size.height * sqrtf(ratio)));
        //通过图片上下文进行处理图片
        //UIGraphicsBeginImageContext(size);
        UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:size];
        [resultImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
        resultImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        //获取处理后图片的大小
        data = UIImageJPEGRepresentation(resultImage, compression);
    }
    
    return resultImage;
}

#pragma mark - event response
- (void)IdClick:(UIButton *)sender
{
    currentBtn = sender;
    
    SCCaptureCameraController *con = [[SCCaptureCameraController alloc] init];
    con.scNaigationDelegate = self;
    con.iCardType = TIDCARD2;
    con.isDisPlayTxt = NO;
    //con.TimeKey = TimeKeyS;
    con.ScanMode = TIDC_NORMAL_MODE;
    
       
    [self presentViewController:con animated:YES completion:NULL];
}

- (void)nextBtnClick:(UIButton *)sender
{
    
    if (frontImg == nil) {
        [Tools showMessage:@"请先拍摄身份证正面"];
        return;
    }
    
    if (backImg == nil) {
        [Tools showMessage:@"请先拍摄身份证反面"];
        return;
    }
    
    if (self.type == SaveFromTypeYinShu) {
        [self uploadPDFRequest];
    }else if (self.type == SaveFromTypeBiCai) {
        
        if (self.functionType == BiCaiOFunctionTypeUpdateIdInfo) {
            [self bcUploadOCRImageRequest];
        }else{
            [self alertShow:[NSString stringWithFormat:@"检测姓名:%@,如错误,请在输入框内修改",cardName]];
        }
        
       

    }
    
    
    return;
    
    
    [self uploadOCRImageRequest];
}

#pragma mark - 姓名身份证号码提示
- (void)alertShow:(NSString *)message
{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"取消按钮被点击了");
    }];
    
    UIAlertAction * actionDel = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
       UITextField*textField = alert.textFields[0];
        self->cardName = [textField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
        NSLog(@"%@",self->cardName);
        
        BCRealNameInfoIdentifyController* vc = [BCRealNameInfoIdentifyController new];
        vc.title = @"实名认证";
        vc.idcardFrontPhoto = self->frontImg;
        vc.idcardBackPhoto = self->backImg;
        vc.idCardName = self->cardName;
        vc.idcardNo = self->cardNo;
        vc.bcInfoModel = self.bcInfoModel;
        [self.navigationController pushViewController:vc animated:YES];
        
    }];

    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        NSLog(@"这是要删除一条信息");
    }];

    //添加行为按钮
    [alert addAction:action];
    [alert addAction:actionDel];
    
    UITextField*textField = alert.textFields[0];
    
    textField.text = cardName;
    

    //模态展示方式
    [self presentViewController:alert animated:YES completion:nil];
  
}



#pragma mark - getters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - cl_kTabBarHeight - 112 * WIDTHRADIU)];
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(ScreenWidth, 0);
        
        //顶部view
        OPenAccountTopView* topView = [self getXiblWithClassName:@"OPenAccountTopView"];
        [_scrollView addSubview:topView];
        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.mas_greaterThanOrEqualTo(50);
        }];
        
       //身份证正面View
        OPenAccountCardView* frontView =  [self getXiblWithClassName:@"OPenAccountCardView"];
        frontView.lb_message.text= @"点击拍照身份证正面";
        //frontView.frame = CGRectMake((ScreenWidth - 300)/2, 50, 300, 208);
        self.frontBtn = frontView.btn;
        [self.frontBtn addTarget:self action:@selector(IdClick:) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:frontView];
        
        [frontView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(topView.mas_bottom).offset(0);
            make.left.offset((ScreenWidth - 248)/2);
            make.width.offset(245);
            make.height.offset(155);
        }];
        
        //身份证背面View
      OPenAccountCardView* backView =  [self getXiblWithClassName:@"OPenAccountCardView"];
      //backView.frame = CGRectMake((ScreenWidth - 300)/2, frontView.maxY + 50, 300, 208);
      backView.imgCard.image = [UIImage  imageNamed:@"Socialsecuritycontributions_IDUpload_ReversesideofIDcard_normal"];
        backView.lb_message.text= @"点击拍照身份证后面";
        self.backBtn = backView.btn;
        [self.backBtn addTarget:self action:@selector(IdClick:) forControlEvents:UIControlEventTouchUpInside];
        //self.backBtn.layer.cornerRadius = 10;
        //self.backBtn.layer.masksToBounds = YES;
      [_scrollView addSubview:backView];
        
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(frontView.mas_bottom).offset(20);
            make.left.offset((ScreenWidth - 248)/2);
            make.width.offset(248);
            make.height.offset(155);
        }];
        OPenAccountBottomView* bottomView = [self getXiblWithClassName:@"OPenAccountBottomView"];
        [_scrollView addSubview:bottomView];
        [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(backView.mas_bottom).offset(0);
            make.left.offset((ScreenWidth - 320)/2);
            make.width.offset(320);
            make.height.mas_greaterThanOrEqualTo(50);
            make.bottom.offset(0);
        }];
        
       // _scrollView.contentSize = CGSizeMake(ScreenWidth, backView.maxY + 10);
    }
    return _scrollView;
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - cl_kNavigationBarHeight - 112 * WIDTHRADIU, ScreenWidth, 112 * WIDTHRADIU)];
        _bottomView.backgroundColor = [UIColor whiteColor];
        
        //拍摄时需注意
        UILabel*lb_title = [UILabel new];
        lb_title.text = @"拍摄时需注意";
        lb_title.textColor = [UIColor colorWithHex:0x4d4d4d];
        lb_title.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        [_bottomView addSubview:lb_title];
        [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10 * WIDTHRADIU);
            make.left.offset(15);
        }];
        
        [_bottomView layoutIfNeeded];
        
        CGFloat left = 15;
        CGFloat width = 72 * WIDTHRADIU;
        CGFloat height = 46.5 * WIDTHRADIU;
        CGFloat lineWidth = (ScreenWidth - 30 - width * 4)/3;
        NSArray* titleArray = @[@"标准",@"边框缺失",@"照片模糊",@"闪光强烈"];
        NSArray* imageArray = @[@"right",@"wrong",@"wrong",@"wrong"];
        for (int i = 0 ; i < 4; i++) {
            CGFloat X = left +(width + lineWidth) * i;
            
            UIImageView* imageView = [[UIImageView alloc]init];
            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"card_0%d",i + 1]];
            imageView.frame = CGRectMake(X, lb_title.maxY + 10 * WIDTHRADIU, width, height);
            [_bottomView addSubview:imageView];
            
            UIButton*btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            [btn setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
            btn.frame = CGRectMake(X, imageView.maxY, width, 30 * WIDTHRADIU);
            [btn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:3];
            [_bottomView addSubview:btn];
            
        }
        
    }
    return _bottomView;
}

- (UIButton *)nextBtn
{
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nextBtn setTitle:@"身份核验" forState:UIControlStateNormal];
        _nextBtn.backgroundColor = [UIColor colorWithHex:0x137ef6];
        [_nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _nextBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_nextBtn addTarget:self action:@selector(nextBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;
}

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