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

#import "SocialSecurityVerificationFailureViewController.h"
#import "successViewController.h"
#import "SelectedImg.h"
#import "Constants.h"
#import "VerificationFailureAlertView.h"
#import "KKUserIdentifyViewController.h"
#import "FaceImageModel.h"

@interface SocialSecurityVerificationFailureViewController ()<SelectedImgClickDelegate,passImagesDelegate>{
    SelectedImg* currentImg;
}

@property (nonatomic, strong)UIScrollView* scrollView;

@property (nonatomic, strong)SelectedImg* topleftImg;

@property (nonatomic, strong)SelectedImg* topRightImg;

@property (nonatomic, strong)SelectedImg* bottomLeftImg;

@property (nonatomic, strong)SelectedImg* bottomRightImg;

@property (nonatomic, strong)UILabel* lb_middleMessage;

@property (nonatomic, strong)UIButton* btn_RECollect;

@property (nonatomic, strong)UIButton* btn_commit;

@property (nonatomic, strong)NSMutableArray* tmpArray;




@end

@implementation SocialSecurityVerificationFailureViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [GTCountSDK trackCountEvent:@"home_SBAuth_failurePage" withArgs:@{}];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tmpArray = [NSMutableArray array];
    
    [self configUI];
}


- (void)configUI
{
    [self.view addSubview:self.scrollView];
    
   
    
    
    if (self.arrayImages.count == 4) {
        self.topleftImg.image = self.arrayImages[0];
        self.topRightImg.image = self.arrayImages[1];
        self.bottomLeftImg.image = self.arrayImages[2];
        self.bottomRightImg.image = self.arrayImages[3];
         [self.tmpArray addObjectsFromArray:self.arrayImages];
    }
    
    //默认选中第一张图片比对
    [self.topleftImg tapClick:nil];
    
    
}

#pragma mark - 获取scrollview的contentHeight
- (CGFloat)getScrollViewContentHeight
{
    //顶部图片距离顶部距离
    CGFloat topImgTopPadding = 10 * WIDTHRADIU;
    
    //图片高度
    CGFloat imgHeight = 1.25 *(ScreenWidth - 51* WIDTHRADIU)/2;
    
    //图片行间隔
    CGFloat imgLineSpace = 17 * WIDTHRADIU;
    
    //中部contentheight
    CGFloat middleContentHeight = 33* WIDTHRADIU;
    
    //按钮高度
    CGFloat btnHeight = 45 * WIDTHRADIU;
    
    //总高度
    CGFloat totalHeight = topImgTopPadding + imgHeight * 2 + imgLineSpace + middleContentHeight + btnHeight;
    
    
    return totalHeight;
}



#pragma mark - 上传图片api
- (NSDictionary *)uploadImagesRequestParam:(UIImage *)selfImage
{
    
//    NSDictionary *dictNew =@{
//                                 @"flag":@2,
//                                 @"id":ID,
//                                 @"name":[EnercryTool A:name],
//                                 @"identityNumber":[EnercryTool A:identityNumber],
//                                 @"image":[EnercryTool encryptBase64:imageData],
//                                 @"sign":str1,
//                                 @"versionflag":@1,
//    //                             @"phoneNumber":telPhone,
//                                 @"photoLstr":senderPic//1周 照片一逗号的形式隔开
//                                 };
    NSString *sign = [NSString stringWithFormat:@"identityNumber=%@&name=%@&KkweInfo",[EnercryTool A:[NSString validBlankStr:self.ValidationIdNumber]],[EnercryTool A:[NSString validBlankStr:self.ValidationName]]];
       sign =  [MyMD5 md5:sign];
     selfImage=  [JobUtil imagehuangzhuan:selfImage rotation:UIImageOrientationLeft];
    
    
    NSArray *dataArray = nil;
    
    if (currentImg == self.topleftImg) {
        dataArray =@[ [self imageChangeType:selfImage],
        [self imageChangeType:self.tmpArray[1]],
        [self imageChangeType:self.tmpArray[2]],
        [self imageChangeType:self.tmpArray[3]]];
    }else if (currentImg == self.topRightImg){
        dataArray =@[ [self imageChangeType:selfImage],
        [self imageChangeType:self.tmpArray[0]],
        [self imageChangeType:self.tmpArray[2]],
        [self imageChangeType:self.tmpArray[3]]];
    }else if (currentImg == self.bottomLeftImg){
        dataArray =@[ [self imageChangeType:selfImage],
        [self imageChangeType:self.tmpArray[0]],
        [self imageChangeType:self.tmpArray[1]],
        [self imageChangeType:self.tmpArray[3]]];
    }else if (currentImg == self.bottomRightImg)
    {
        dataArray =@[ [self imageChangeType:selfImage],
        [self imageChangeType:self.tmpArray[0]],
        [self imageChangeType:self.tmpArray[1]],
        [self imageChangeType:self.tmpArray[2]]];
    }
    
    NSMutableArray*baocun = [NSMutableArray array];
    for (NSString *str in dataArray) {
        if (![baocun containsObject:str]) {
            [baocun addObject:str];
        }else{
            if ([baocun containsObject:str]) {
                [baocun removeObject:str];
                continue;
            }
        }
    }
    
    NSString *senderPic =@"";
    if (baocun.count <1) {
          [SVProgressHUD doneShow];
        senderPic = @"";
    }else{
        senderPic =[baocun componentsJoinedByString:@","];
    }
    
    NSDictionary *params = @{
        @"flag":@2,
        @"id":[NSString validBlankStr:self.bak],
        @"name":[EnercryTool A:[NSString validBlankStr:self.ValidationName]],
        @"identityNumber":[EnercryTool A:[NSString validBlankStr:self.ValidationIdNumber]],
        @"image":[self imageChangeType:selfImage],
        @"sign":sign,
        @"versionflag":@1,
        @"photoLstr":senderPic
    };
    return params;
}
- (void)uploadImagesRequest:(UIImage *)selfImage
{
    WeakSelf
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipKKSBConfig],verifyPhotoRequest];
    if (@available(iOS 9,*)) {
        url =  [url  stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }else{
        url =  [url  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    
    NSLog(@"活体检测上传图片url:%@",url);
    NSLog(@"params:%@",[self uploadImagesRequestParam:selfImage]);
    [KKLoadingAnimationView show];
    [NetworkRequest SBAuthPost:url Params:[self uploadImagesRequestParam:selfImage] Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString* code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            if ([code isEqualToString:@"0"]) {
                UIImage*image2 = nil;
                if ([responseObject[@"result"] isKindOfClass:[NSString class]]) {
                    if (![NSString blankString:responseObject[@"result"]]) {
                        NSData *dataBase64 =[[NSData alloc]initWithBase64EncodedString:responseObject[@"result"] options:0];
                        UIImage *image = [UIImage imageWithData:dataBase64];
                        image2 = image;
                    }
                }
                
                
                [weakSelf JumpToRZSuccessVCWithImage1:selfImage image2:image2];
                
                if (weakSelf.ValidationName) {
                    NSDictionary *ValidationDic = @{@"ValidationName":weakSelf.ValidationName};
                    [[NSUserDefaults standardUserDefaults]setObject:ValidationDic forKey:@"ValidationDic"];
                    [[NSUserDefaults standardUserDefaults]synchronize];
                    [getPeopleID getprovinceNightSix:weakSelf.province];
                }
            }else if ([code isEqualToString:@"28"]){
                
                UIAlertController *alertCon =[UIAlertController alertControllerWithTitle:@"信息正在审核中,请耐心等待!" message:nil preferredStyle:UIAlertControllerStyleAlert];
                [alertCon addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSLog(@"%@",@"确定了!!!!!");
                    for (UIViewController*vc in self.navigationController.viewControllers) {
                        if ([vc isKindOfClass:[KKUserIdentifyViewController class]]) {
                            KKUserIdentifyViewController*currentVC  = (KKUserIdentifyViewController *)vc;
                            [currentVC clearText];
                            [self.navigationController popToViewController:currentVC animated:YES];
                            break;
                        }
                    }
                 self.navigationController.navigationBar.translucent = YES;
                        [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:27/255.0 green:132/255.0 blue:208/255.0 alpha:1.0]];
                    if ([UIScreen mainScreen].bounds.size.height == 480) {
                        [self.navigationController setNavigationBarHidden:NO animated:YES];
                    }
                }]];
                [self presentViewController:alertCon animated:YES completion:nil];
                
                //[self performSegueWithIdentifier:@"unwindB" sender:self];
                
            }else if ([code isEqualToString:@"42"]){
                
                [weakSelf alertMessage:@"请使用绿色通道方式认证！"];
                
            }else if ([code isEqualToString:@"4"] || [code isEqualToString:@"1012"]){
                [weakSelf alertShow];
            } else{
                
                
                codeSelected *code1 = [codeSelected MustTakeReturn:code.integerValue];
                
                [code1 returnCodeMethod];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器繁忙,请稍后重试!"];
        }
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常,请稍后重试!"];
    }];
}


#pragma mark - SelectedImgClickDelegate
- (void)clickImg:(SelectedImg *)img
{
    if (currentImg == img) {
        return;
    }
    if (currentImg) {
        [currentImg configData];
    }
    currentImg = img;
}

#pragma mark - passImagesDelegate
- (void)passImages:(NSArray *)imagesArray
{
    NSLog(@"%@",[NSThread currentThread]);
    //[SVProgressHUD showSuccessWithStatus:@"人脸识别成功"];
    
    
   
//   NSArray*newImageArray = [imagesArray sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
//       FaceImageModel *model1 = (FaceImageModel *)obj1;
//       FaceImageModel *model2 = (FaceImageModel *)obj2;
//        // 因为不满足sortedArrayUsingComparator方法的默认排序顺序，则需要交换
//        if (model1.score < model2.score) return NSOrderedDescending;
//        return NSOrderedAscending;
//    }];

    NSMutableArray *originImage = [[NSMutableArray alloc]init];
    //NSMutableArray *scoreArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < imagesArray.count; i++) {



        FaceImageModel*imageModel = imagesArray[i];
        //UIImage* image = [UIImage imageWithImage:imageModel.image scale:0.5];
        [originImage addObject:imageModel.image];
//        [scoreArray addObject:[NSString stringWithFormat:@"%.4f",imageModel.score]];

    }

   


    [self.tmpArray removeAllObjects];
    [self.tmpArray addObject:originImage[0]];
    [self.tmpArray addObject:originImage[1]];
    [self.tmpArray addObject:originImage[2]];
    [self.tmpArray addObject:originImage[3]];
    
    self.topleftImg.image = originImage[0];
    self.topRightImg.image = originImage[1];
    self.bottomLeftImg.image = originImage[2];
    self.bottomRightImg.image = originImage[3];
    
    
    [self->currentImg configData];
    self->currentImg = nil;
    
    [self.topleftImg tapClick:nil];
    
    

    [NSThread sleepForTimeInterval:1.0f];
//
    [self uploadImagesRequest:self->currentImg.image];

//    return;
//    TestViewController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"TestViewController"];
//    vc.title = @"查看图片";
//    vc.imageArray = imagesArray;
//
//    [self.navigationController pushViewController:vc animated:YES];

  
}

- (void)passFail
{
    NSLog(@"传值失败");
    [SVProgressHUD showErrorWithStatus:@"人脸识别失败"];
}


#pragma mark - event response
- (void)btnClick:(UIButton *)sender
{
    
    timeForButtonCount *time=[[timeForButtonCount alloc]initMustTakeReturn:nil];
    
    [time methodWithTimeCount:sender];
    
    if (sender == self.btn_commit) {
        [self uploadImagesRequest:currentImg.image];
    }else if (sender == self.btn_RECollect){
        [self goToAuthVC];
    }
    return;
   
}

#pragma mark - 跳转页面
- (void)JumpToRZSuccessVCWithImage1:(UIImage *)image1 image2:(UIImage *)image2
{
    [getPeopleID socialSate:1];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ZLAuthenticationAssistant" object:nil userInfo:nil];
   
    successViewController *blueVC = [MainBoard instantiateViewControllerWithIdentifier:@"successViewController"];
    blueVC.imageView1 = image1;
    blueVC.imageView2 = image2;
    blueVC.province =self.province;
    blueVC.city =self.city;
    blueVC.county =self.county;
    blueVC.name = self.ValidationName;
    blueVC.idNumber = self.ValidationIdNumber;
    blueVC.bak = self.bak;
    
    [self.navigationController pushViewController:blueVC animated:YES];
}

#pragma mark - 活体检测
- (void)goToAuthVC
{
     
    LivenessViewController* dvc = [[LivenessViewController alloc] init];
    dvc.delegate = self;
    NSArray *array_ =nil;
//    NSInteger kankanZhang =   [[NSUserDefaults standardUserDefaults]integerForKey:@"huoti_kankan_int"];
                            
    array_ =[[NSArray alloc]initWithObjects:@1, nil];
  

    [dvc livenesswithList:array_ order:YES numberOfLiveness:0];
//    __weak typeof(self) weakSelf = self;
    /*dvc.completion = ^(NSDictionary *images, NSMutableArray *originImage) {


            

            if (originImage.count == 0) {


            }else{
                [weakSelf.tmpArray removeAllObjects];
                [weakSelf.tmpArray addObject:originImage[0]];
                [weakSelf.tmpArray addObject:originImage[1]];
                [weakSelf.tmpArray addObject:originImage[2]];
                [weakSelf.tmpArray addObject:originImage[3]];
                
                self.topleftImg.image = originImage[0];
                self.topRightImg.image = originImage[1];
                self.bottomLeftImg.image = originImage[2];
                self.bottomRightImg.image = originImage[3];
                
                
                [self->currentImg configData];
                self->currentImg = nil;
                
                [self.topleftImg tapClick:nil];
                
                

                [NSThread sleepForTimeInterval:1.0f]; 
//
                [weakSelf uploadImagesRequest:self->currentImg.image];

            }


            //finish

    };*/
    
    [self presentViewController:dvc animated:YES completion:nil];
}

#pragma mark - alert message
- (void)alertMessage:(NSString *)message
{
    WeakSelf
    UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if ([message isEqualToString:@"请使用绿色通道方式认证"]) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }else if ([message isEqualToString:@"信息正在审核中,请耐心等待"]){
            for (UIViewController* vc in weakSelf.navigationController.viewControllers) {
                if ([vc isKindOfClass:[PhotoViewController class]]) {
                    [weakSelf.navigationController popToViewController:vc animated:YES];
                    break;
                }
            }
        }
        
    }];
    
    [alertV addAction:confirm];
    
    [self presentViewController:alertV animated:YES completion:nil];
}

- (void)alertShow
{
    WeakSelf
    [VerificationFailureAlertView showWithViewController:self Callback:^(NSInteger index) {
        if (index == 200) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }else if (index == 201){
            UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
               artificalViewController *artVC=[sb instantiateViewControllerWithIdentifier:@"artificalViewController"];
               artVC.failurePic =   [JobUtil imagehuangzhuan:self->currentImg.image rotation:UIImageOrientationLeft];
               artVC.telPhone =self.telPhone;
               [weakSelf.navigationController pushViewController:artVC animated:YES];
        }
    }];
}


#pragma mark - 图片处理

-(NSString*)imageChangeType:(UIImage*)selfImage{
    UIImage *  flippedImage= selfImage;
    //这里做了修改2017年6月27日
    //先获取图片的镜面图像
    flippedImage  = [UIImage imageWithCGImage:flippedImage.CGImage
                                        scale:1.0 orientation: UIImageOrientationUpMirrored];
    //2017年6月27日
    //2017年7月17日 (483,664)  -->  (360,270)
    //压缩到某一尺寸
    flippedImage=  [self imageByScalingAndCroppingForSize:CGSizeMake(360, 270) and:flippedImage];
    //压缩
    NSData  *dateImage1 =UIImageJPEGRepresentation( flippedImage,0.86);
    //编码
    NSString *str3=[EnercryTool encryptBase64:dateImage1];
    return str3;
    
}

#pragma mark - 图片压缩到某一尺寸
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize and:(UIImage*)imageKs
{
    UIImage *sourceImage = imageKs;
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth= width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    
    //UIGraphicsBeginImageContext(targetSize); // this will crop
    UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:targetSize];
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width= scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil)
        NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
}



#pragma mark - getters and setters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        
      
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
       
         _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
       // _scrollView.delegate = self;
        

       
        
        _scrollView.contentSize = CGSizeMake(ScreenWidth, [self getScrollViewContentHeight]);
         UIView*leftLine = [[UIView alloc]init];
        leftLine.backgroundColor = [UIColor colorWithHex:0xcccccc];
        UIView*rightLine = [[UIView alloc]init];
        rightLine.backgroundColor = [UIColor colorWithHex:0xcccccc];
        
        [_scrollView addSubview:self.topleftImg];
        [_scrollView addSubview:self.topRightImg];
        [_scrollView addSubview:self.bottomLeftImg];
        [_scrollView addSubview:self.bottomRightImg];
        
        [_scrollView addSubview:self.lb_middleMessage];
        [_scrollView addSubview:leftLine];
        [_scrollView addSubview:rightLine];
        [_scrollView addSubview:self.btn_RECollect];
        [_scrollView addSubview:self.btn_commit];
        
        
       
        
        
        [self.topleftImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(17 * WIDTHRADIU);
            make.top.offset(10 * WIDTHRADIU);
        make.height.mas_equalTo(self.topleftImg.mas_width).multipliedBy(5/4.0);
            make.width.offset((ScreenWidth - 51* WIDTHRADIU)/2);
        }];
        
        [self.topRightImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.topleftImg.mas_right).offset(17 * WIDTHRADIU);
            make.top.width.height.equalTo(self.topleftImg);
        }];
        
        [self.bottomLeftImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topleftImg.mas_bottom).offset(17 * WIDTHRADIU);
            make.left.width.height.equalTo(self.topleftImg);
        }];
        
        [self.bottomRightImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topRightImg.mas_bottom).offset(17 * WIDTHRADIU);
            make.right.width.height.equalTo(self.topRightImg);
        }];
        [self.lb_middleMessage setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [self.lb_middleMessage setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [self.lb_middleMessage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bottomRightImg.mas_bottom).offset(10 * WIDTHRADIU);
            make.centerX.equalTo(self->_scrollView);
        }];
        
        
        [leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomLeftImg);
            make.centerY.equalTo(self.lb_middleMessage);
            make.right.equalTo(self.lb_middleMessage.mas_left).offset(-5 * WIDTHRADIU);
                make.height.offset(0.5);
        }];
        [rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bottomRightImg);
            make.centerY.equalTo(self.lb_middleMessage);
            make.left.equalTo(self.lb_middleMessage.mas_right).offset(5 * WIDTHRADIU);
                make.height.offset(0.5);
        }];
        
        [self.btn_RECollect mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(leftLine);
            make.top.equalTo(self.lb_middleMessage.mas_bottom).offset(10 * WIDTHRADIU);
            make.width.offset((ScreenWidth - 58* WIDTHRADIU)/2);
            make.height.offset(45 * WIDTHRADIU);
            
        }];
        
        [self.btn_commit mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.btn_RECollect.mas_right).offset(24 * WIDTHRADIU);
            make.top.width.height.equalTo(self.btn_RECollect);
        }];
        
        
    }
    return _scrollView;
}

- (SelectedImg*)topleftImg
{
    if (!_topleftImg) {
        _topleftImg = [[SelectedImg alloc]initCustomUI];
        _topleftImg.delegate = self;
        _topleftImg.contentMode = UIViewContentModeScaleAspectFill;
        _topleftImg.clipsToBounds = YES;
    }
    return _topleftImg;
}
- (SelectedImg*)topRightImg
{
    if (!_topRightImg) {
        _topRightImg = [[SelectedImg alloc]initCustomUI];
        _topRightImg.delegate = self;
        _topRightImg.contentMode = UIViewContentModeScaleAspectFill;
        _topRightImg.clipsToBounds = YES;
    }
    return _topRightImg;
}
- (SelectedImg*)bottomLeftImg
{
    if (!_bottomLeftImg) {
        _bottomLeftImg = [[SelectedImg alloc]initCustomUI];
        _bottomLeftImg.delegate = self;
        _bottomLeftImg.contentMode = UIViewContentModeScaleAspectFill;
        _bottomLeftImg.clipsToBounds = YES;
    }
    return _bottomLeftImg;
}
- (SelectedImg*)bottomRightImg
{
    if (!_bottomRightImg) {
        _bottomRightImg = [[SelectedImg alloc]initCustomUI];
        _bottomRightImg.delegate = self;
        _bottomRightImg.contentMode = UIViewContentModeScaleAspectFill;
        _bottomRightImg.clipsToBounds = YES;
    }
    return _bottomRightImg;
}

- (UILabel *)lb_middleMessage
{
    if (!_lb_middleMessage) {
        _lb_middleMessage = [[UILabel alloc]init];
        _lb_middleMessage.text = @"选择照片开始认证";
        _lb_middleMessage.textColor = [UIColor colorWithHex:0x808080];
        _lb_middleMessage.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
        _lb_middleMessage.textAlignment = NSTextAlignmentCenter;
    }
    return _lb_middleMessage;
}

- (UIButton *)btn_RECollect
{
    if (!_btn_RECollect) {
        _btn_RECollect = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_RECollect.backgroundColor = [UIColor colorWithHex:0x13a480];
        _btn_RECollect.layer.cornerRadius = 5 * WIDTHRADIU;
        [_btn_RECollect setTitle:@"重新识别" forState:UIControlStateNormal];
        [_btn_RECollect setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_RECollect.titleLabel.font = [UIFont systemFontOfSize:19 * WIDTHRADIU];
        [_btn_RECollect addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _btn_RECollect;
}

- (UIButton *)btn_commit
{
    if (!_btn_commit) {
        _btn_commit = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_commit.backgroundColor = [UIColor colorWithHex:0x13a480];
        _btn_commit.layer.cornerRadius = 5 * WIDTHRADIU;
        [_btn_commit setTitle:@"身份认证" forState:UIControlStateNormal];
        [_btn_commit setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_commit.titleLabel.font = [UIFont systemFontOfSize:19 * WIDTHRADIU];
        [_btn_commit addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_commit;
}

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