//
//  socialOnceViewController.m
//  socialSecurity
//
//  Created by 看看智能 on 2017/7/27.
//  Copyright © 2017年 黄江涛 . All rights reserved.
//

#import "socialOnceViewController.h"

@interface socialOnceViewController ()<UITextFieldDelegate>
//文本框textfield_name
@property (weak, nonatomic) IBOutlet UITextField *nameText;
//文本框textfield_身份证
@property (weak, nonatomic) IBOutlet UITextField *IDText;
//ocr保存的身份证照片
@property(nonatomic,strong)NSString *ocrBase64;
//ocr保存的头像照片
@property(nonatomic,strong)NSString *ocrBase64_;
//发送数据
@property (weak, nonatomic) IBOutlet UIButton *buttonForSender;
//手机号码
@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;
//获取状态1为 直接进去 2位弹窗进去
@property(nonatomic,strong)NSString *str1111;
//判断状态是否可以进行下一步
@property(nonatomic)BOOL isEnter;
//判断社保局的个人信息不对的变量
@property(nonatomic,strong)NSString *resultMessage;
//判断图片
@property (weak, nonatomic) IBOutlet UIImageView *cococoImage;

@property(nonatomic,strong)verifyAdressModel *verifyModel;


@end

@implementation socialOnceViewController
//JAnalytics
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [JANALYTICSService startLogPageView:@"社保采集-基础信息认证"];
    [MobClick beginLogPageView:@"社保采集-基础信息认证"];

}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [JANALYTICSService stopLogPageView:@"社保采集-基础信息认证"];
      [MobClick endLogPageView:@"社保采集-基础信息认证"];
    
}



WEBS
-(void)buttonClick_1{
    ZHINENGKEFU
}
//-(void)buttonClick_{
//    [self.navigationController popViewControllerAnimated:YES];
//}



- (void)viewDidLoad {
    [super viewDidLoad];
 
    if ([self.CAOCAOCAO isEqualToString:@"我是皮卡丘"]) {
      self.navigationItem.hidesBackButton = NO;
    }else{
        self.navigationItem.hidesBackButton = NO;
    }
    
    if ([self.CAOCAOCAO isEqualToString:@"caocaocao"]) {
        self.cococoImage.image =[UIImage imageNamed:@"就业采集地址"];
        self.phoneNumber.placeholder =@"请输入地址";
    }
    self.nameText.text =self.name_xin;
    self.IDText.text =self.id_xin;
    
    
//    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];        button.frame = CGRectMake(0, 0, 80, 49);     button.titleLabel.textAlignment =NSTextAlignmentLeft;   [button setTitle:@"返回     " forState:UIControlStateNormal];        [button addTarget:self action:@selector(buttonClick_) forControlEvents:UIControlEventTouchUpInside];        UIBarButtonItem * backButtonItem_ = [[UIBarButtonItem alloc] initWithCustomView:button];        self.navigationItem.leftBarButtonItem = backButtonItem_;
    
//    UIButton * button_2 = [UIButton buttonWithType:UIButtonTypeCustom];        button_2.frame = CGRectMake(0, 0, 0, 49);     button_2.titleLabel.textAlignment =NSTextAlignmentRight;   [button_2 setTitle:@"     帮助" forState:UIControlStateNormal];        [button_2 addTarget:self action:@selector(buttonClick_1) forControlEvents:UIControlEventTouchUpInside];        UIBarButtonItem * backButtonItem_2 = [[UIBarButtonItem alloc] initWithCustomView:button_2];        self.navigationItem.rightBarButtonItem = backButtonItem_2;
    
    
    self.title =@"信息采集";
//    self.leftNameTRanslet.constant =97 * (UIScreen.mainScreen.bounds.size.width ) /375 ;
    
    self.leftNameTRanslet.constant = [UIScreen mainScreen].bounds.size.width *90 /375;
    if ([UIScreen mainScreen].bounds.size.width == 375 ) {
        self.leftNameTRanslet.constant  = 73;
    }else if ([UIScreen mainScreen].bounds.size.width == 320){
        self.leftNameTRanslet.constant  = 63;
    }else if ([UIScreen mainScreen].bounds.size.width == 414){
        self.leftNameTRanslet.constant  = 83;
    }
    
    if (self.personPrivate == 1)
        //特权
        [self getForPrivate];
    else
        [self geta];
    
    
    [self textFieldAddTwoBlackPlaceinTextFiled:self.phoneNumber];
    self.phoneNumber.delegate =self;
    self.nameText.delegate =self;
    self.IDText.delegate =self;
    self.isEnter = NO;
    
    
    
    
    
    //内部版使用
//    self.nameText.text=@"黄江涛";
//    self.IDText.text =@"42112619940907171X";
//    self.buttonForSender.userInteractionEnabled =YES;
    //内部版使用
    
    
    
    
}
- (IBAction)didend:(UITextField *)sender {
    [self.view endEditing:YES];
  
    
    if (self.personPrivate == 1)
          [self getForPrivate];
    else
      [self geta];
}


#pragma mark - 验证证件OCR
- (IBAction)explainIdentifly:(id)sender {
    
    [self userOCR];
    
}

-(void)userOCR{

    SCCaptureCameraController *scocr = [[SCCaptureCameraController alloc] init];
    scocr.scNaigationDelegate = self;
    scocr.iCardType = TIDCARD2;
    scocr.isDisPlayTxt = YES;
    //con.TimeKey = TimeKeyS;
    scocr.ScanMode = TIDC_SCAN_MODE;
    
    [self presentViewController:scocr animated:YES completion:NULL];

}


-(void)getOCR
{
#if TARGET_IPHONE_SIMULATOR
    
#else
    // Do any additional setup after loading the view, typically from a nib.
    // 如果是客户使用自己的界面，调用识别引擎参考代码如下
    
    // 打开引擎
    Gint ret = 0;
    Gint vaule = 1;
    ret = TREC_StartUP(TREC_GetEngineTimeKEY());
    if (ret == 100) {
        NSLog(@"引擎过期\n");
        return;
    }
    if (ret == 100) {
        NSLog(@"引擎过期\n");
        return;
    }if (ret == 101) {
        NSLog(@"引擎绑定失败\n");
        return;
    }
    //获取引擎信息，可以不用操作，可有可无
    //  self.nameText.text=  [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@\n%@\n",TREC_GetCopyrightInfoArray(),TREC_GetVersionArray(),TREC_GetTimeStatus()]];
    // 设置引擎参数
    ret = TREC_SetParam(T_SET_HEADIMG, &vaule);
    // 设置引擎类型
    ret = TREC_SetSupportEngine(TIDCARD2);// 演示使用身份证，其他证件以此类推
    if (ret != 1) {
        NSLog(@"引擎不支持\n");
        TREC_ClearUP();
        return;
    }
    
    
    // 引擎内存释放
    ret = TREC_ClearUP();
    
#endif
    
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField == self.IDText) {
        // 四位加一个空格
        if ([string isEqualToString:@""]) { // 删除字符
            return YES;
        } else {
            
            
            if (textField.text.length   == 6 || textField.text.length   == 11 || textField.text.length   == 16 ) {
                textField.text = [NSString stringWithFormat:@"%@ ", textField.text];
    
            }
      
        }
        return YES;
    }
    return YES;
}

- (void)sendIDCValue:(NSString *)name SEX:(NSString *)sex FOLK:(NSString *)folk BIRTHDAY:(NSString *)birthday ADDRESS:(NSString *) address NUM:(NSString *)num
{
    NSLog(@"idc  = %@\n%@\n%@\n%@\n%@\n%@\n",name,sex,folk,birthday,address,num);
   
    if ([self.CAOCAOCAO isEqualToString:@"caocaocao"]) {
        self.phoneNumber.text =address;
    }
    
    
    
    
    if (![name isEqualToString:@""]) {
        self.nameText.text =name;
        //这里把身份证改一下
        NSString *st1 =[num substringWithRange:NSMakeRange(0, 6)];
        NSString *st2 =[num substringWithRange:NSMakeRange(6, 4)];
        NSString *st3 =[num substringWithRange:NSMakeRange(10, 4)];
        NSString *st4 =[num substringFromIndex:14];
        self.IDText.text =  [NSString stringWithFormat:@"%@ %@ %@ %@",st1,st2,st3,st4];
        self.IDText.enabled = NO;//大众用户在扫描完身份证之后身份证号码不让修改!!!(2019年5月16日改..)
        self.isEnter = YES;
        
        if (self.personPrivate == 1)
            [self getForPrivate];
        else
            [self geta];
        
        
    }
    
    

    
   
    
}

- (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) {
        NSLog(@"headiamge = %@\n",image);
        //        NSData *smallImgData = UIImageJPEGRepresentation(image, 0.2);
        NSData *smallImgData =UIImagePNGRepresentation(image);
        self.ocrBase64_ = [smallImgData base64EncodedStringWithOptions:0];
    }
    
}
- (void)sendFieldImage:(TFIELDID) filed  image:(UIImage *)fieldimage
{
    
    NSLog(@"sendFieldImage = %d %@\n",filed,fieldimage);
}
- (void)sendTakeImage:(TCARD_TYPE) iCardType image:(UIImage *)cardImage
{
    NSLog(@"sendTakeImage = %d %@\n",iCardType,cardImage);
    //    NSData *smallImgData =UIImageJPEGRepresentation(cardImage, 0.2);
    NSData *smallImgData =UIImageJPEGRepresentation([self imageByScalingAndCroppingForSize:CGSizeMake(667, 375) and:cardImage], 1.0);
    self.ocrBase64 = [smallImgData base64EncodedStringWithOptions:0];
}
- (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
    
    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 - 跳转到第二个界面
- (IBAction)buttonSender:(id)sender {
    if ([self.CAOCAOCAO isEqualToString:@"caocaocao"]) {
        [SVProgressHUD showErrorWithStatus:@"功能正在开发中"];
        return;
    }


    if (self.personPrivate == 1) {
        //私人使用
        [self privateNoUseTel];
    }else
    {
    //大众使用
            [self publicUseTel];
    }
    
    
}
//私人使用逻辑
-(void)privateNoUseTel{
     NSString *newStr = [self.IDText.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
    //没访问前先做一下判断
    

    
       //2017年3月7日星期三改的内容 老左要求修改注释了前面代码写了下面的代码
       if(  [IDCardNumber_Validate isValidateIDCardString:newStr] == NO   )return    [SVProgressHUD showErrorWithStatus:@"身份证不正确请检查"];
    
    //判断二 : 身份证号码是否输错
//    if(  [IDCardNumber_Validate isValidateIDCardString:newStr] == NO   ){
//        if ( ![newStr isEqualToString:@""]) {
//            [SVProgressHUD showErrorWithStatus:@"身份证不正确请检查"];
//            return;
//        }
//}
    
    
    
    
    //判断三 :姓名是否为空
if(self.nameText.text.length <=0)   return   [SVProgressHUD showErrorWithStatus:@"请输入姓名"];

    
    
    //判断四:手机号码要做加密
    NSString *tel =nil;
    if ([self.phoneNumber.text  isEqualToString:@""]) {
        tel =[NSNull null];
    }else{
        
        tel = [EnercryTool encryptUseDES:self.phoneNumber.text key:DESKEY];
        
    }
    
    
    
    
    //判读五:离线采集直接
    if ([self.offLineGather isEqualToString:@"离线采集"]) {
        [SVProgressHUD dismiss];
        [self senderTwoVc:1];
        return;
    }
    
    //最后最一个提醒

    //    判读一: 填了的手机号码
    
    
    
    
    if (self.phoneNumber.text.length > 0) {
        if ((self.phoneNumber.text.length  != 11 && self.phoneNumber.text.length  != 0) || [self isPureInt:self.phoneNumber.text]  == NO)  return  [SVProgressHUD showErrorWithStatus:@"手机号码格式不正确"];
        
        
        
        [SVProgressHUD doneShow];
        [SVProgressHUD shows];
    
        [CityNetManager OnceSocialMessage:[EnercryTool A:self.nameText.text] andIdentityName:[EnercryTool A:newStr]  andUserId:[getPeopleID PeopleID] andPhone_number:tel completionHandle:^(verifyAdressModel *model, NSError *error) {
            [SVProgressHUD doneShow];
            [SVProgressHUD dismiss];
            //状态为0跳转到第二个界面
            if(error){
                [SVProgressHUD showErrorWithStatus:@"网络状态不佳"];

            }
             self.verifyModel =model;
            
            
            if (model.code == 0 || model.code == 1000 || model.code == 2002  ) {
                if (model.code == 1000) {
                    [SVProgressHUD showErrorWithStatus:@"参数为空1000"];
                }
                if (model.code == 2002) {
                  
                    [SVProgressHUD showErrorWithStatus:@"参数为空2002"];
                }

                [SVProgressHUD dismiss];
                [self senderTwoVc:1];
            }else{
                //状态为别的在显示出来
                [SVProgressHUD dismiss];
                 
                switch (model.code) {

                    case 24:
                        
                        //                        分隔字符串
                        if ([model.RESULT isEqualToString:@""]) {
                            
                            break;
                        }
                        
                        //从字符A中分隔成2个元素的数组
                        NSLog(@"array:%@",[model.RESULT componentsSeparatedByString:@";"][0]);
                        NSLog(@"array:%@",[model.RESULT componentsSeparatedByString:@";"][1]);
                        [self  alertS:[EnercryTool desA:[model.RESULT componentsSeparatedByString:@";"][0]] andTable:[model.RESULT componentsSeparatedByString:@";"][1]];
                        
                        break;

                    case 23:
                        [self alertSHOW:@"不在认证期间"];
                        
                        break;

                    case 27:
                        [self alertSHOW:@"社保采集次数用完"];

                        break;

                    case 2:
                        [self alertSHOW:[NSString stringWithFormat:@"姓名:%@\n身份证:%@\n请确认是否输入正确! ! !",self.nameText.text,self.IDText.text]];
                        self.str1111 =@"123";
                        break;
                    default:
                        [[codeSelected MustTakeReturn:model.code]returnCodeMethod];

                        break;

                }

                // [[codeSelected MustTakeReturn:model.code]returnCodeMethod];

                return;
            }
        }];
        //2017年3月7日星期三改的内容 老左要求修改注释了前面代码写了下面的代码
       //  [self senderTwoVc:1];

        return;
    }
    
    
    
    
    
    
    
    
    
    
        NSString *alertTitle  = @"手机号码为空,请确定是否要填写";
        
        
        UIAlertController *alertC =[UIAlertController alertControllerWithTitle:alertTitle message:nil preferredStyle:UIAlertControllerStyleAlert];
    //提醒一:确定
        [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
                 return;
        }]];
    //提醒二:取消(包含所有逻辑)
        [alertC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
               [SVProgressHUD doneShow];


            [SVProgressHUD shows];
            [CityNetManager OnceSocialMessage:[EnercryTool A:self.nameText.text] andIdentityName:[EnercryTool A:newStr]  andUserId:[getPeopleID PeopleID] andPhone_number:tel completionHandle:^(verifyAdressModel *model, NSError *error) {
                [SVProgressHUD doneShow];
                  self.verifyModel =model;
                //状态为0跳转到第二个界面
                if(error){
                    [SVProgressHUD showErrorWithStatus:@"网络状态不佳"];

                }
              
                if (model.code == 0) {
                    [SVProgressHUD dismiss];
                    [self senderTwoVc:1];
                }else{
                    //状态为别的在显示出来
                    [SVProgressHUD dismiss];
                    
                    switch (model.code) {
                        case 23:
                            
                            [self alertSHOW:@"不在认证期间"];
                            
                            break;

                        case 24:
                            
                       
//                            self.resultMessage =  [self convertToJsonData:(NSDictionary*)model.RESULT];
                            
                            
                            
                            //                        分隔字符串
                            if ([model.RESULT isEqualToString:@""]) {

                                break;
                            }

                            //从字符A中分隔成2个元素的数组
                            NSLog(@"array:%@",[model.RESULT componentsSeparatedByString:@";"][0]);
                            NSLog(@"array:%@",[model.RESULT componentsSeparatedByString:@";"][1]);
                            [self  alertS:[EnercryTool desA:[model.RESULT componentsSeparatedByString:@";"][0]] andTable:[model.RESULT componentsSeparatedByString:@";"][1]];

                            break;

                      
                        case 27:
                            [self alertSHOW:@"社保采集次数用完"];

                            break;

                        case 2:
                            [self alertSHOW:[NSString stringWithFormat:@"姓名:%@\n身份证:%@\n请确认是否输入正确! ! !",self.nameText.text,self.IDText.text]];
                            self.str1111 =@"123";
                            break;
                        default:
                            [[codeSelected MustTakeReturn:model.code]returnCodeMethod];

                            break;

                    }

                    // [[codeSelected MustTakeReturn:model.code]returnCodeMethod];

                    return;
                }
            }];
            //2017年3月7日星期三改的内容 老左要求修改注释了前面代码写了下面的代码
            //   [self senderTwoVc:1];
            
        }]];

        
        [self presentViewController:alertC animated:YES completion:nil];
    
    
   

}

// 字典转json字符串方法

-(NSString *)convertToJsonData:(NSDictionary *)dict

{
    
    NSError *error;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    
    NSString *jsonString;
    
    if (!jsonData) {
        
        NSLog(@"%@",error);
        
    }else{
        
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        
    }
    
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    
    NSRange range = {0,jsonString.length};
    
    //去掉字符串中的空格
    
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    
    NSRange range2 = {0,mutStr.length};
    
    //去掉字符串中的换行符
    
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    
    return mutStr;
    
}



//大众使用逻辑
-(void)publicUseTel{
    NSString *newStr = [self.IDText.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
    if (self.phoneNumber.text.length  != 11 || [self isPureInt:self.phoneNumber.text]  == NO)  return   [SVProgressHUD showErrorWithStatus:@"手机号码不正确"];
    
    if(  [IDCardNumber_Validate isValidateIDCardString:newStr] == NO)   return   [SVProgressHUD showErrorWithStatus:@"身份证不正确请检查"];
    if(self.nameText.text.length <=0)    return   [SVProgressHUD showErrorWithStatus:@"请输入姓名"];
    
    if(!self.ocrBase64)    return   [SVProgressHUD showErrorWithStatus:@"请拍身份证正面"];
    
    
    
    if ((self.phoneNumber.text.length  == 11 && [self isPureInt:self.phoneNumber.text]  == YES )) {
        [SVProgressHUD shows];
        [CityNetManager OnceSocialMessage:[EnercryTool A:self.nameText.text] andIdentityName:[EnercryTool A:newStr]  andUserId:[getPeopleID PeopleID] andPhone_number:[EnercryTool encryptUseDES:self.phoneNumber.text key:DESKEY] completionHandle:^(verifyAdressModel *model, NSError *error) {
            self.verifyModel =model;
             [SVProgressHUD doneShow];
            
            if(error){
                [SVProgressHUD showErrorWithStatus:@"网络状态不佳"];
            
            }
            
//            NSDictionary *dictNew =@{
//                                     @"identityNumber":identityName,
//                                     @"name":name,
//                                     @"userId":@(userid),
//                                     @"phone_number":iphonenNumber
//                                     };
//            NSLog(@"dictNew:%@",dictNew);
            
            
            
            //状态为0跳转到第二个界面
            
        
            
            
            if (model.code == 0  ) {
                [SVProgressHUD dismiss];
                [self senderTwoVc:1];
            }else{
                //状态为别的在显示出来
                [SVProgressHUD dismiss];
                switch (model.code) {
                    case 27:
                        [self alertSHOW:@"社保采集次数用完"];
                        
                        break;
                    case 23:
                        [self alertSHOW:@"不在认证期间"];
                        
                        break;
                    case 1029:
                        [self alertSHOW:@"已采集过，不能重复采集！"];
                        
                        break;
                        
                    case 2:
                         [SVProgressHUD showErrorWithStatus:@"您不在本次采集范围内，请咨询当地社保局"];
//                        [self alertSHOW:[NSString stringWithFormat:@"姓名:%@\n身份证:%@\n请确认是否输入正确! ! !",self.nameText.text,self.IDText.text]];
//                        self.str1111 =@"123";
                        break;
                    case 1009 :
                        //手机号码不匹配
                       [self alertSHOW:@"手机号码不匹配"];
                        break;
                    default:
                        [[codeSelected MustTakeReturn:model.code]returnCodeMethod];
                        
                        break;
                        
                }
                
                // [[codeSelected MustTakeReturn:model.code]returnCodeMethod];
                
                return;
            }
        }];
    }
}



-(void)alertS:(NSString *)name andTable:(NSString*)tableID{

    NSString *alertTitle  = [NSString stringWithFormat:@"该身份证号码在社保局系统中的名字为:%@\n请确认是否替换为%@?",name,self.nameText.text];

    
    UIAlertController *alertCon =[UIAlertController alertControllerWithTitle:alertTitle message:nil preferredStyle:UIAlertControllerStyleAlert];

    [alertCon addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  [self senderTwoVc:1];
 
    }]];
    [alertCon addAction:[UIAlertAction actionWithTitle:@"确定替换" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
   
        [self NEXT:tableID andImportantMessage:name];
}]];

    [self presentViewController:alertCon animated:YES completion:nil];
    
}
//bushi
-(void)NEXT:(NSString*)table andImportantMessage:(NSString*)strs{
    [SVProgressHUD shows];
         NSString *newStr = [self.IDText.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
        __weak __typeof(self)weakSelf = self;
    
    
    

    [CityNetManager newIDAndNAme:[EnercryTool A:newStr] andName:[EnercryTool A:weakSelf.nameText.text] andResult:table completionHandle:^(verifyAdressModel *model, NSError *error) {
        [SVProgressHUD doneShow];//状态为0跳转到第二个界面
        if(error){
            [SVProgressHUD showErrorWithStatus:@"网络状态不佳"];
        }
        self.verifyModel =model;
        if (model.code == 0) {
            [SVProgressHUD dismiss];
            [self senderTwoVc:1];
        }else{
            [SVProgressHUD dismiss];
            switch (model.code) {
                case 27:
                [self alertSHOW:@"社保采集次数用完"];
                break;
                    
                case 2:
                    [self alertSHOW:[NSString stringWithFormat:@"姓名:%@\n身份证:%@\n请确认是否输入正确! ! !",weakSelf.nameText.text,weakSelf.IDText.text]];
                    self.str1111 =@"123";
                    break;
                    
                default:
                    [[codeSelected MustTakeReturn:model.code]returnCodeMethod];
                    break;
            }
        }
    }];
    
    
}

-(void)alertSHOW:(NSString*)str{

    UIAlertController *alertCon =[UIAlertController alertControllerWithTitle:str message:nil preferredStyle:UIAlertControllerStyleAlert];
    __weak __typeof(self)weakSelf = self;
    [alertCon addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }]];
    [alertCon addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

       
        if ([str isEqualToString:@"请拍身份证正面"] ) {
      
            dispatch_async(dispatch_get_main_queue(), ^{
                 [weakSelf userOCR];
            });
            
        }else
        if ([self.str1111 isEqualToString:@"123"]) {
            
            

                [weakSelf senderTwoVc:2];

            
        }else if([self.offLineGather isEqualToString:@"离线采集"]){
            [self senderTwoVc:2];
            
            
        }
        
//        if ([str isEqualToString:@"手机号码不匹配，是否修改？"]) {
//
//
//
//
//
//             if(!self.ocrBase64)    return   [SVProgressHUD showErrorWithStatus:@"请拍身份证正面"];
//            NSString *IdcardName = [self.nameText.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
//            NSString *IdcardIDNumber = [self.IDText.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
//            NSString *IdcardPhoneNumber = self.phoneNumber.text;
//
//            [CityNetManager replaceTelphone:IdcardPhoneNumber andName:IdcardName andIdNumber:IdcardIDNumber completionHandle:^(verifyAdressModel *model, NSError *error) {
//                NSLog(@"error:%@",error);
//
//                if (model.code==0) {
//
//                  [self senderTwoVc:2];
//                }
//
//            }];
//
//
//        }
    }]];


    [self presentViewController:alertCon animated:YES completion:nil];

}


//推送到第二个界面
-(void)senderTwoVc:(NSInteger )ins{

    NSString *newStr = [self.IDText.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
    socialSecurityViewController *vc =[socialSecurityViewController sharedInstance];
    vc.ins = ins;
    vc.nText =self.nameText.text;
    vc.idText =newStr;
    vc.telText = self.phoneNumber.text;
    vc.ocrBase64 =self.ocrBase64;
    vc.ocrBase64_ =self.ocrBase64_;
    if (self.ocrBase64 && self.ocrBase64_) {
        vc.isPhoto = YES;
    }else {
        vc.isPhoto = NO;
    }
    vc.goGreenTongDao =NO;
    paramWithResult *models = [paramWithResult mj_objectWithKeyValues:self.verifyModel.RESULT];
//    models.countryName
    if (models.countryName.length >0) {
    vc.paraModel =models;
        vc.paraModelStr = @"asdasd";
    }else{
       vc.paraModelStr = @"asf";
    }

    if ([self.offLineGather isEqualToString:@"离线采集"]) {vc.offLineGather =@"离线采集"; }else{ vc.offLineGather =@"";}
    if(![self.navigationController.topViewController isKindOfClass:[vc class]]) {
        [self.navigationController pushViewController:vc animated:YES];
    }


}

#pragma mark - 判断按钮的点击事件
-(void)geta{
    if((self.nameText.text.length > 0) && (self.IDText.text.length > 0) &&self.phoneNumber.text.length >0)
    {
        
        [self.view reloadInputViews];
        self.buttonForSender .backgroundColor =[UIColor colorWithRed:25/255.0 green:149/255.0 blue:109/255.0 alpha:1.0];
        self.buttonForSender.userInteractionEnabled =YES;
    }else
    {
        [self.view reloadInputViews];
        self.buttonForSender.backgroundColor =[UIColor colorWithRed:191/255.0 green:191/255.0 blue:191/255.0 alpha:1.0];
        self.buttonForSender.userInteractionEnabled =NO;
    }
}

-(void)getForPrivate{
    //2017年3月7日星期三改的内容  (self.IDText.text.length > 0) 删了
    if(self.nameText.text.length > 0 && (self.IDText.text.length > 0)) //姓名身份证号不为空
    {
        
        [self.view reloadInputViews];
        self.buttonForSender .backgroundColor =[UIColor colorWithRed:25/255.0 green:149/255.0 blue:109/255.0 alpha:1.0];
        self.buttonForSender.userInteractionEnabled =YES;
    }else
    {
        [self.view reloadInputViews];
        self.buttonForSender.backgroundColor =[UIColor colorWithRed:191/255.0 green:191/255.0 blue:191/255.0 alpha:1.0];
        self.buttonForSender.userInteractionEnabled =NO;
    }



}




-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

#pragma mark - 封装好的用来在textField前面加两个空格
-(void)textFieldAddTwoBlackPlaceinTextFiled:(UITextField *)textField
{
    UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(textField.frame.origin.x,textField.frame.origin.y,5.0, textField.frame.size.height)];
    textField.leftView = blankView;
    textField.leftViewMode =UITextFieldViewModeAlways;
}
#pragma mark - 设置代理
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

//-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
//{
//
//}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//2017年3月7日星期三改的内容  注释的是以前的内容
//    if (_isEnter == NO   ) {
//
//        [self alertSHOW:@"请拍身份证正面"];
//    }
    
 

   if(self.personPrivate == 1){
        _isEnter =YES;
        
    }else{
        if (_isEnter == NO   ) {
            
            [self alertSHOW:@"请拍身份证正面"];
        }
    }
    
    
    

    return YES;


}




#pragma mark - 是否是数字类型
- (BOOL)isPureInt:(NSString *)string{
    
    
    
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}
@end
