//
//  DistrictAuthenticationInfoController.m
//  KKCivilAd
//
//  Created by 雷俊博 on 2019/11/25.
//  Copyright © 2019 雷俊博. All rights reserved.
//

#import "DistrictAuthenticationInfoController.h"
//百度
#import <BMKLocationKit/BMKLocationComponent.h>
#import "UIView+frameAdjust.h"


#import "LivenessViewController.h"
#import "TestViewController.h"
#import "AuthenticationFinishController.h"
#import "AuthenticationFailedController.h"
#import "YFGreenChannelVC.h"
#import "CommitIDInfoController.h"
#import "AuthenticationReviewController.h"
#import "FaceImageModel.h"
#import "AuthenticationButieFinishVC.h"
@interface DistrictAuthenticationInfoController ()<UITextFieldDelegate,passImagesDelegate,BMKLocationManagerDelegate>
{
    NSString *addressRelation;
    NSString *nowAddress;
    NSString *aLocation;
    NSArray *kImages;
    NSString *verifytype;
}

//百度
@property (nonatomic, strong)BMKLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet UILabel *lb_title;

@end

@implementation DistrictAuthenticationInfoController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
    if ([self.type isEqualToString:@"butie"]) {
        [GTCountSDK trackCountEvent:@"home_BTAuth_btInfoPage" withArgs:@{}];
    }else{
        [GTCountSDK trackCountEvent:@"home_YFAuth_yfInfoPage" withArgs:@{}];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithHex:0xf4f4f4];
    
    
    if ([self.type isEqualToString:@"butie"]) {
        self.lb_title.text = @"补贴信息";
    }
    
    [self configNav];
    
     [self locationDisplay];
    
    self.lb_locationAddress.text = @"正在定位";
    self.lb_Locationtype.text = @"本地";
    
   __block NSString *authType = nil;
    [self.model.types enumerateObjectsUsingBlock:^(TypesModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == 0) {
            authType =  obj.verifytypeText;
        }else{
            authType =  [NSString stringWithFormat:@"%@,%@",authType,obj.verifytypeText];
        }
       
    }];
    
    self.lb_DistrictAuthType.text = authType;
    
    if (self.model.types.count > 0)
    {
        TypesModel *model = self.model.types[0];
        self.lb_shequ.text = [NSString stringWithFormat:@"%@%@%@%@%@",EmptyString(model.provinceName),EmptyString(model.cityName),EmptyString(model.countryName),EmptyString(model.townName),EmptyString(model.villageName)];
                                        
    }
    
    
    
    self.tf_mobile.text = [EnercryTool AES256Decrypt:self.model.telphone key:MZAESKEY];
    
    NSLog(@"tel:%@",self.model.telphone);
    
    
    self.cardView.height =  self.tf_mobile.maxY + 50;
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    tap.cancelsTouchesInView =NO;
    [_tableView addGestureRecognizer:tap];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
         [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    addressRelation = @"本地";
    
    if (self.model.types.count > 0)
    {
        TypesModel *model = self.model.types[0];
         nowAddress = [NSString stringWithFormat:@"%@%@%@",model.provinceName,model.cityName,model.countryName];
                          
    }
    
    [self.model.types enumerateObjectsUsingBlock:^(TypesModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (idx == 0) {
            verifytype = [NSString stringWithFormat:@"%ld",obj.verifytype];
        }else{
            verifytype = [NSString stringWithFormat:@"%@,%ld",verifytype,obj.verifytype];
        }
        
    }];
}

- (void)configNav
{
    UIBarButtonItem * backButtonItem = [[UIBarButtonItem alloc] init];
    backButtonItem.title = @"返回";
    self.navigationItem.backBarButtonItem = backButtonItem;
}

#pragma mark - load api
- (NSDictionary *)requestParams
{
    NSDictionary *params = nil;
    if ([[EnercryTool AES256Decrypt:self.model.telphone key:MZAESKEY] isEqualToString:self.tf_mobile.text]) {
        params = @{
            @"addressRelation":addressRelation,
            @"nowAddress":nowAddress ? nowAddress :@"",
            @"fromModel":@2,
            @"identityNumber":self.model.identityNumber ? self.model.identityNumber :@"",
            @"indentityFacePhoto":@"",
            @"lal":aLocation ? aLocation :@"",
            @"libid":[NSNumber numberWithInteger:self.model.libid],
            @"recordPhotos":kImages,
            @"verifytype":verifytype ? verifytype : @""
        };
    }else{
        params = @{
        @"addressRelation":addressRelation,
        @"nowAddress":nowAddress ? nowAddress :@"",
        @"fromModel":@2,
        @"identityNumber":self.model.identityNumber ? self.model.identityNumber :@"",
        @"indentityFacePhoto":@"",
        @"lal":aLocation ? aLocation :@"",
        @"libid":[NSNumber numberWithInteger:self.model.libid],
        @"recordPhotos":kImages,
        @"verifytype":verifytype ? verifytype : @"",
        @"telphone":[EnercryTool AES256Encrypt:self.tf_mobile.text key:MZAESKEY] ? [EnercryTool AES256Encrypt:self.tf_mobile.text key:MZAESKEY] : @""
        };
    }
    return params;
}

- (void)uploadDataRequest
{
    if ([self.type isEqualToString:@"butie"]) {
        [self butieUploadDataRequest];
    }else{
        [self youfuUploadDataRequest];
    }
}


- (void)youfuUploadDataRequest
{
    WeakSelf
       NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYouFuVerityConfig],DistrictAuthenticationUploadImageRequest];
       NSLog(@"民政认证url%@",urlString);
       NSLog(@"prams:%@",[self requestParams]);
       NSString *token = [UserDefault objectForKey:@"token"];
       
       [SVProgressHUD show];
       [NetworkRequest Post3:urlString Params:[self requestParams] Token:token Success:^(id  _Nonnull responseObject) {
           [SVProgressHUD dismiss];
           NSLog(@"responseObject:%@",responseObject);
           if ([responseObject isKindOfClass:[NSDictionary class]]) {
               NSString *state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
               if ([state isEqualToString:@"200"]) {
                   if ([responseObject[@"result"] isKindOfClass:[NSDictionary class]]) {
                       NSString *code =  [NSString stringWithFormat:@"%@",responseObject[@"result"][@"code"]];
                       if ([code isEqualToString:@"200100"]) {
                           
                           AuthenticationFinishController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"AuthenticationFinishController"];
                           vc.title = @"认证完成";
                           vc.imagesArray = self->kImages;
                           if ([responseObject[@"result"][@"data"] isKindOfClass:[NSDictionary class]]){
                               vc.defaultPhoto = responseObject[@"result"][@"data"][@"defaultPhoto"];
                           }
                           vc.model = self.model;
                           vc.phone = self.tf_mobile.text;
                           vc.location = self->nowAddress;
                           vc.recordId = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"data"][@"recordId"]];
                           vc.type = self.type;

                           [weakSelf.navigationController pushViewController:vc animated:YES];
                           return ;
                           
                       }else if ([code isEqualToString:@"200001"]){
                           [self alertShow:@"照片不合格"];
                       }else if ([code isEqualToString:@"200002"]){
                           [self alertShow:@"身份证号或id错误"];
                       }else if ([code isEqualToString:@"200200"]){
                           AuthenticationFailedController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"AuthenticationFailedController"];
                                                  vc.title = @"认证完成";
                           [weakSelf.navigationController pushViewController:vc animated:YES];
                       }else if ([code isEqualToString:@"200300"]){
                           NSDictionary *data = responseObject[@"result"][@"data"];
                           if ([data isKindOfClass:[NSDictionary class]]) {
                               if ([data[@"idcardPic"] isKindOfClass:[NSNumber class]]) {
                                   NSNumber *idcardPic = (NSNumber *)data[@"idcardPic"];
                                   NSString *recordId = [NSString stringWithFormat:@"%@",data[@"recordId"]];
                                   
                                   if (idcardPic.boolValue) {
                                       if (![Tools isBlankString:recordId]) {
                                           [Tools showMessage:@"信息审核中,请补交证件信息"];
                                           [NSThread sleepForTimeInterval:3.0f];
                                            CommitIDInfoController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"CommitIDInfoController"];
                                            vc.title = @"证件信息";
                                            vc.hidesBottomBarWhenPushed = YES;
                                           vc.recordId = recordId;
                                           vc.type = self.type;
                                           [self.navigationController pushViewController:vc animated:YES];
                                       }
                                   }else{
                                       [self alertShow:@"认证审核中,请耐心等待审核结果"];
                                       AuthenticationReviewController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"AuthenticationReviewController"];
                                       vc.title = @"认证完成";
                                       [self.navigationController pushViewController:vc animated:YES];
                                       
                                   }
                                   
                               }
                           }
                           
                           
                       }else if ([code isEqualToString:@"400001"]){
                           [self alertShow:@"终端参数异常"];
                       }else if ([code isEqualToString:@"400003"]){
                           [self alertShow:@"正常至少需要4张图片"];
                       }else if ([code isEqualToString:@"400004"]){
                           [self alertShow:@"参数不是base64照片"];
                       }else{
                           [self alertShow:@"认证失败"];
                       }
                   
                       
                   }else{
                       [self alertShow:@"服务器异常"];
                   }
               }else if ([state isEqualToString:@"700"]){
                   [weakSelf reloadData];
               }else{
                   [self alertShow:@"请求失败"];
               }
               
           }else{
               [self alertShow:@"服务器异常"];
           }
           
           
       } Failure:^(NSError * _Nonnull error) {
           [SVProgressHUD dismiss];
           NSLog(@"error:%@",error);
           [self alertShow:@"网络异常"];
       }];
}


- (void)butieUploadDataRequest
{
    WeakSelf
       NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYouFuVerityConfig],DistrictAuthenticationUploadImageRequest];
       NSLog(@"民政认证url%@",urlString);
       NSLog(@"prams:%@",[self requestParams]);
       NSString *token = [UserDefault objectForKey:@"token"];
       
       [SVProgressHUD show];
       [NetworkRequest Post7:urlString Params:[self requestParams] Token:token Success:^(id  _Nonnull responseObject) {
           [SVProgressHUD dismiss];
           NSLog(@"responseObject:%@",responseObject);
           if ([responseObject isKindOfClass:[NSDictionary class]]) {
               NSString *state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
               if ([state isEqualToString:@"200"]) {
                   if ([responseObject[@"result"] isKindOfClass:[NSDictionary class]]) {
                       NSString *code =  [NSString stringWithFormat:@"%@",responseObject[@"result"][@"code"]];
                       if ([code isEqualToString:@"200100"]) {
                           
//                           AuthenticationFinishController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"AuthenticationFinishController"];
                           AuthenticationButieFinishVC *vc = [[AuthenticationButieFinishVC alloc]init];
                           vc.title = @"认证完成";
                           vc.imagesArray = self->kImages;
                           if ([responseObject[@"result"][@"data"] isKindOfClass:[NSDictionary class]]){
                               vc.defaultPhoto = responseObject[@"result"][@"data"][@"defaultPhoto"];
                           }
                           vc.model = self.model;
                           vc.phone = self.tf_mobile.text;
                           vc.location = self->nowAddress;
                           vc.recordId = [NSString stringWithFormat:@"%@",responseObject[@"result"][@"data"][@"recordId"]];
                           vc.type = self.type;

                           [weakSelf.navigationController pushViewController:vc animated:YES];
                           return ;
                           
                       }else if ([code isEqualToString:@"200001"]){
                           [self alertShow:@"照片不合格"];
                       }else if ([code isEqualToString:@"200002"]){
                           [self alertShow:@"身份证号或id错误"];
                       }else if ([code isEqualToString:@"200200"]){
                           AuthenticationFailedController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"AuthenticationFailedController"];
                                                  vc.title = @"认证完成";
                           [weakSelf.navigationController pushViewController:vc animated:YES];
                       }else if ([code isEqualToString:@"200300"]){
                           NSDictionary *data = responseObject[@"result"][@"data"];
                           if ([data isKindOfClass:[NSDictionary class]]) {
                               if ([data[@"idcardPic"] isKindOfClass:[NSNumber class]]) {
                                   NSNumber *idcardPic = (NSNumber *)data[@"idcardPic"];
                                   NSString *recordId = [NSString stringWithFormat:@"%@",data[@"recordId"]];
                                   
                                   if (idcardPic.boolValue) {
                                       if (![Tools isBlankString:recordId]) {
                                           [Tools showMessage:@"信息审核中,请补交证件信息"];
                                           [NSThread sleepForTimeInterval:3.0f];
                                            CommitIDInfoController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"CommitIDInfoController"];
                                            vc.title = @"证件信息";
                                            vc.hidesBottomBarWhenPushed = YES;
                                           vc.recordId = recordId;
                                           vc.type = self.type;
                                           [self.navigationController pushViewController:vc animated:YES];
                                       }
                                   }else{
                                       [self alertShow:@"认证审核中,请耐心等待审核结果"];
                                       AuthenticationReviewController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"AuthenticationReviewController"];
                                       vc.title = @"认证完成";
                                       [self.navigationController pushViewController:vc animated:YES];
                                       
                                   }
                                   
                               }
                           }
                           
                           
                       }else if ([code isEqualToString:@"400001"]){
                           [self alertShow:@"终端参数异常"];
                       }else if ([code isEqualToString:@"400003"]){
                           [self alertShow:@"正常至少需要4张图片"];
                       }else if ([code isEqualToString:@"400004"]){
                           [self alertShow:@"参数不是base64照片"];
                       }else{
                           [self alertShow:@"认证失败"];
                       }
                   
                       
                   }else{
                       [self alertShow:@"服务器异常"];
                   }
               }else if ([state isEqualToString:@"700"]){
                   [weakSelf reloadData];
               }else{
                   [self alertShow:@"请求失败"];
               }
               
           }else{
               [self alertShow:@"服务器异常"];
           }
           
           
       } Failure:^(NSError * _Nonnull error) {
           [SVProgressHUD dismiss];
           NSLog(@"error:%@",error);
           [self alertShow:@"网络异常"];
       }];
}

- (void)reloadData
{
    WeakSelf
    [NetworkTokenRequest getTokenSuccess:^(BOOL success) {
        if (success) {
            [weakSelf uploadDataRequest];
        }else{
            [self alertShow:@"请求失败"];
        }
    }];
}

#pragma mark - location


- (void)locationDisplay
{
    //初始化实例
       _locationManager = [[BMKLocationManager alloc] init];
       //设置delegate
      // _locationManager.delegate = self;
       //设置返回位置的坐标系类型
       _locationManager.coordinateType = BMKLocationCoordinateTypeBMK09LL;
       //设置距离过滤参数
       _locationManager.distanceFilter = kCLDistanceFilterNone;
       //设置预期精度参数
       _locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
       //设置应用位置类型
       _locationManager.activityType = CLActivityTypeAutomotiveNavigation;
       //设置是否自动停止位置更新
       _locationManager.pausesLocationUpdatesAutomatically = NO;
       //设置是否允许后台定位
       //_locationManager.allowsBackgroundLocationUpdates = YES;
       //设置位置获取超时时间
       _locationManager.locationTimeout = 10;
       //设置获取地址信息超时时间
       _locationManager.reGeocodeTimeout = 10;
       
       [_locationManager requestLocationWithReGeocode:YES withNetworkState:YES completionBlock:^(BMKLocation * _Nullable location, BMKLocationNetworkState state, NSError * _Nullable error) {
           if (error)
           {
               NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
               
               
               if (self.model.types.count > 0)
               {
                   TypesModel *model = self.model.types[0];
                   
                    self.lb_Locationtype.text = @"本地";
                    self.lb_locationAddress.text = [NSString stringWithFormat:@"%@%@%@",model.provinceName,model.cityName,model.countryName];
                                     
               }
               
               
           }
           
           if (location) { //得到定位信息，添加annotation
               if (location.location) {
                   NSLog(@"LOC = %@",location.location);
               }
               if (location.rgcData) {
                   NSLog(@"rgc = %@",[location.rgcData description]);
               }
               
               if (location.rgcData.poiList) {
                   for (BMKLocationPoi * poi in location.rgcData.poiList) {
                       NSLog(@"poi = %@", poi.name);
                   }
               }
               
               self->aLocation = [NSString stringWithFormat:@"%f,%f",location.location.coordinate.latitude,location.location.coordinate.longitude];
               
               
               if (location.rgcData) {
                   NSString *address = [NSString stringWithFormat:@"%@%@%@%@%@%@(%@)",[NSString validBlankStr:location.rgcData.province],[NSString validBlankStr:location.rgcData.city],[NSString validBlankStr:location.rgcData.district],[NSString validBlankStr:location.rgcData.town],[NSString validBlankStr:location.rgcData.street],[NSString validBlankStr:location.rgcData.streetNumber],[NSString validBlankStr:location.rgcData.locationDescribe]]; NSLog(@"%@%@%@%@%@%@(%@)",location.rgcData.province,location.rgcData.city,location.rgcData.district,location.rgcData.town,location.rgcData.street,location.rgcData.streetNumber,location.rgcData.locationDescribe);
                   
                   
                   
                   
                   self.lb_locationAddress.text = address;
                   self->nowAddress = address;
                   
                   
                   
                   if (self.model.types.count > 0) {
                       TypesModel *model = self.model.types[0];
                       
                       if ([model.provinceName isEqualToString:@"北京市"] || [model.provinceName isEqualToString:@"天津市"] || [model.provinceName isEqualToString:@"上海市"] || [model.provinceName isEqualToString:@"重庆市"]) {
                           if ([model.provinceName isEqualToString:location.rgcData.city]) {
                                                    self.lb_Locationtype.text = @"本地";
                                                    self->addressRelation = @"本地";
                                                }else{
                                                    self.lb_Locationtype.text = @"异地";
                                                    self->addressRelation = @"异地";
                                                }
                       }else{
                           if ([model.cityName isEqualToString:location.rgcData.city]) {
                                                    self.lb_Locationtype.text = @"本地";
                                                    self->addressRelation = @"本地";
                                                }else{
                                                    self.lb_Locationtype.text = @"异地";
                                                    self->addressRelation = @"异地";
                                                }
                       }
                       
                     
                   }
                   
                    self.cardView.height =  self.tf_mobile.maxY + 50;
               }
               
             
               
               
           }
           
       }];
}
/**
 *  @brief 为了适配app store关于新的后台定位的审核机制（app store要求如果开发者只配置了使用期间定位，则代码中不能出现申请后台定位的逻辑），当开发者在plist配置NSLocationAlwaysUsageDescription或者NSLocationAlwaysAndWhenInUseUsageDescription时，需要在该delegate中调用后台定位api：[locationManager requestAlwaysAuthorization]。开发者如果只配置了NSLocationWhenInUseUsageDescription，且只有使用期间的定位需求，则无需在delegate中实现逻辑。
 *  @param manager 定位 BMKLocationManager 类。
 *  @param locationManager 系统 CLLocationManager 类 。
 *  @since 1.6.0
 */
- (void)BMKLocationManager:(BMKLocationManager * _Nonnull)manager doRequestAlwaysAuthorization:(CLLocationManager * _Nonnull)locationManager
{
    
    [locationManager requestAlwaysAuthorization];
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - passImagesDelegate 下一步 人脸识别成功
- (void)passImages:(NSArray *)imagesArray
{
    NSLog(@"%@",[NSThread currentThread]);
    //[SVProgressHUD showSuccessWithStatus:@"人脸识别成功"];
    
    
    

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



         FaceImageModel*imageModel = imagesArray[i];
         [originImage addObject:imageModel.image];
        

     }
    
   
    [array removeAllObjects];
    for (int i = 0; i < originImage.count; i++) {
        NSData *data = UIImageJPEGRepresentation(originImage[i], 0.85);
        NSString *imageStr = [EnercryTool encryptBase64:data];
        [array addObject:imageStr];
    }

    kImages = array;


    [self uploadDataRequest];

    return;
//    TestViewController *vc = [Storyboard instantiateViewControllerWithIdentifier:@"TestViewController"];
//       vc.title = @"查看图片";
//       vc.bestImage = imagesArray[0];
//       vc.liveMouth = imagesArray[1];
//       vc.liveMouth2 = imagesArray[2];
//       vc.liveMouth3 = imagesArray[3];
//       
//    [self.navigationController pushViewController:vc animated:YES];

  
}

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


#pragma mark - 通知
-(void)keyboardWillShow:(NSNotification *)notification
{
    NSLog(@"%s",__func__);
    
//    NSDictionary *userInfo = [notification userInfo];
//    CGFloat duration = [[userInfo objectForKey:@"UIKeyboardAnimationDurationUserInfoKey"] doubleValue];
//    CGRect rect = [[userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];
//
//
//    WeakSelf
//    [UIView animateWithDuration:duration animations:^{
//     [weakSelf.tableView setContentOffset:CGPointMake(0, 58) animated:NO];
//    }];
   
}

-(void)keyboardWillHide:(NSNotification *)notification
{
    //NSLog(@"keyboardWillHide:%@",notification);
    
//    NSDictionary *userInfo = [notification userInfo];
//    CGFloat duration = [[userInfo objectForKey:@"UIKeyboardAnimationDurationUserInfoKey"] doubleValue];
//    WeakSelf
//    [UIView animateWithDuration:duration animations:^{
//        [weakSelf.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
//    }];
}


- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }else{
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}

#pragma mark - 绿色通道/下一步
- (IBAction)btnClick:(UIButton *)sender {
    
    if (![Tools isMobileNumber:self.tf_mobile.text]) {
        [self alertShow:@"请输入规范的手机号"];
        return;
    }
    
    if (sender.tag == 201) {
        LivenessViewController* lvc = [[LivenessViewController alloc] init];
        lvc.delegate = self;
//        WeakSelf
       /* lvc.completion = ^(NSDictionary *images, NSMutableArray *originImage) {
            __strong typeof(weakSelf) strongSelf = weakSelf;
            NSMutableArray *array = [[NSMutableArray alloc]init];
            for (int i = 0; i < originImage.count; i++) {
                NSData *data = UIImageJPEGRepresentation(originImage[i], 0.85);
                NSString *imageStr = [EnercryTool encryptBase64:data];
                [array addObject:imageStr];
            }

            self->kImages = array;


            [strongSelf uploadDataRequest];
        };*/
           
           //lvc.delegate = self;
           
          NSArray * array_ =[[NSArray alloc]initWithObjects:@1, nil];
          [lvc livenesswithList:array_ order:YES numberOfLiveness:0];
          
        
           UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:lvc];
           navi.navigationBarHidden = true;
           navi.modalPresentationStyle = UIModalPresentationFullScreen;
           [self presentViewController:navi animated:YES completion:nil];
    }else{
        YFGreenChannelVC *vc = [[YFGreenChannelVC alloc]init];
        vc.title = @"绿色通道";
        vc.addressRelation = addressRelation;
        vc.aLocation = aLocation ? aLocation :@"";
        vc.identityNumber = self.model.identityNumber ? self.model.identityNumber :@"";
        vc.nowAddress = nowAddress ? nowAddress :@"";
        vc.libid = [NSNumber numberWithInteger:self.model.libid];
        vc.verifytype = verifytype ? verifytype : @"";
        if ([[EnercryTool AES256Decrypt:self.model.telphone key:MZAESKEY] isEqualToString:self.tf_mobile.text])
        {
            vc.telphone = nil;
        }else{
            vc.telphone = [EnercryTool AES256Encrypt:self.tf_mobile.text key:MZAESKEY];
        }
        vc.tf_telphone = self.tf_mobile.text;
        vc.type = self.type;






        [self.navigationController pushViewController:vc animated:YES];
    }
    

}

- (void)tap:(UITapGestureRecognizer*)tap
{
    [_tf_mobile resignFirstResponder];
}

#pragma mark - getters and setters


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