//
//  SSCardAdultInfoCollectViewController.m
//  Open
//
//  Created by 雷俊博 on 2019/10/12.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "SSCardAdultInfoCollectViewController.h"
#import "UIImage+Custom.h"
#import "UIButton+CQBlockSupport.h"
#import "Constants.h"

#import "SSCardInfoCollectCell.h"
#import "SSCardNationInfoCollectCell.h"
#import "SSCardInfoCollectAddressCell.h"
#import "SSCardDateSelectedTableViewCell.h"
#import "IQKeyboardManager.h"
#import "CYAddressSelectedView.h"
#import "CYYearMonthDaySelectedView.h"
#import "UIView+frameAdjust.h"

#import "SCCaptureCameraController.h"
#import "IOSOCRAPI.h"

#import "CTImageCompression.h"

#import "SSCardCollectImageModel.h"
#import "SSCardCollectImagesController.h"

#import "SSCardCollectBasicInfoController.h"

@interface SSCardAdultInfoCollectViewController ()<UITextFieldDelegate,UIScrollViewDelegate,UITextViewDelegate,SCNavigationControllerDelegate>
{
    //记录位置
    CGFloat currentMaxY;
    
    //记录当前选中输入框
    NSInteger selectedTag;
    
    //iOS,地址框高度
    CGFloat addressContentOffsetY;
    
    
    UIView *addressView;
    UIView * departmentView;
    UIView *dateView;
    
    UIButton *startBtn;
    UIButton *endBtn;
    
    NSString *startDate;
    NSString *endDate;
    
    
    UITextField *tf_name;
    UITextField *tf_idCard;
    UITextField *tf_birth;
    UITextView *tv_address;
    UITextField *tf_deparment;
    
    UIButton *btn_mz;
    UIButton *btn_sex;
    
    
    UIButton *btn_tmp;
    
    NSString *base64Str_frontImg;
    NSString *base64Str_backImg;
    
    
}

@property (nonatomic, strong)UIScrollView *scrollView;

@property (nonatomic, strong)UIView *backView;

@property (nonatomic, strong)UIView *topView;
@property (nonatomic, strong)UIView *gradualView;
@property (nonatomic, strong)UILabel *lb_title;
@property (nonatomic, strong)UIButton *btn_shootRequirement;

@property (nonatomic, strong)UIView *leftView;
@property (nonatomic, strong)UIImageView *img_leftTop;
@property (nonatomic, strong)UIImageView *img_leftBottom;
@property (nonatomic,strong)UIImageView *img_rightBottom;
@property (nonatomic, strong)UIImageView *img_rightTop;
@property (nonatomic, strong)UIImageView *img_Front;
@property (nonatomic, strong)UILabel *lb_uploadTitle;
@property (nonatomic, strong)UIButton *btn_left;

@property (nonatomic, strong)UIButton *leftBtn;

@property (nonatomic, strong)UIView *rightView;
@property (nonatomic, strong)UIImageView *img2_leftTop;
@property (nonatomic, strong)UIImageView *img2_leftBottom;
@property (nonatomic,strong)UIImageView *img2_rightBottom;
@property (nonatomic, strong)UIImageView *img2_rightTop;
@property (nonatomic, strong)UIImageView *img_Back;
@property (nonatomic, strong)UILabel *lb2_uploadTitle;
@property (nonatomic, strong)UIButton *btn_right;
@property (nonatomic, strong)UIButton *rightBtn;

@property (nonatomic, strong)UIView *bottomView;




@end

@implementation SSCardAdultInfoCollectViewController

- (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 setupUI];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    addressContentOffsetY = 58;
    
    [self getOCR];
    
    self.navigationController.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
}




- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    [self.lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.top.offset(10);
        make.height.offset(17);
    }];
    [self.btn_shootRequirement mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-20);
        make.centerY.equalTo(self.lb_title);
        make.height.offset(20);
        make.width.offset(65);
    }];
    
    CGFloat leftMargin = 10 * WIDTHRADIU;
       CGFloat middleMargin = 11 * WIDTHRADIU;
       CGFloat rightMargin = 10 * WIDTHRADIU;
       CGFloat width = (SCREEN_WIDTH - leftMargin - middleMargin - rightMargin)/2;
       CGFloat scale = 230/344.0;
       CGFloat height = width * scale;
       
       [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.left.offset(10 * WIDTHRADIU);
           make.top.equalTo(self.lb_title.mas_bottom).offset(9 * WIDTHRADIU);
           make.width.offset(width);
           make.height.offset(height);
       }];
       
       [self.img_leftTop mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.offset(10 * WIDTHRADIU);
           make.left.offset(15 * WIDTHRADIU);
       }];
       [self.img_leftBottom mas_makeConstraints:^(MASConstraintMaker *make) {
           make.bottom.offset(-10 * WIDTHRADIU);
           make.left.offset(15 * WIDTHRADIU);
       }];
       [self.img_rightBottom mas_makeConstraints:^(MASConstraintMaker *make) {
           make.bottom.offset(-10 * WIDTHRADIU);
           make.right.offset(-15 * WIDTHRADIU);
       }];
       [self.img_rightTop mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.offset(10 * WIDTHRADIU);
           make.right.offset(-15 * WIDTHRADIU);
       }];

       [self.lb_uploadTitle mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(self.img_Front.mas_bottom).offset(4 * WIDTHRADIU);
           make.centerX.equalTo(self.leftView);
           make.height.offset(12 * WIDTHRADIU);
       }];

       CGFloat imgWidth = 84 * WIDTHRADIU;
       CGFloat imgSizeScale = 104 / 168.0;
       CGFloat imgHeight = imgWidth * imgSizeScale;

       [self.img_Front mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerX.equalTo(self.leftView);
           make.top.equalTo(self.img_leftTop.mas_bottom).offset(4);
           make.width.offset(imgWidth);
           make.height.offset(imgHeight);
       }];

       [self.btn_left mas_makeConstraints:^(MASConstraintMaker *make) {
           make.center.equalTo(self.img_Front);
           make.width.height.offset(25 * WIDTHRADIU);
       }];
      [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
          make.center.equalTo(self.leftView);
          make.size.equalTo(self.leftView);
      }];
    
    
    [self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.right.offset(-10 * WIDTHRADIU);
           make.top.equalTo(self.lb_title.mas_bottom).offset(9 * WIDTHRADIU);
           make.width.offset(width);
           make.height.offset(height);
       }];
       
       
       [self.img2_leftTop mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.offset(10 * WIDTHRADIU);
           make.left.offset(15 * WIDTHRADIU);
       }];
       [self.img2_leftBottom mas_makeConstraints:^(MASConstraintMaker *make) {
           make.bottom.offset(-10 * WIDTHRADIU);
           make.left.offset(15 * WIDTHRADIU);
       }];
       [self.img2_rightBottom mas_makeConstraints:^(MASConstraintMaker *make) {
           make.bottom.offset(-10 * WIDTHRADIU);
           make.right.offset(-15 * WIDTHRADIU);
       }];
       [self.img2_rightTop mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.offset(10 * WIDTHRADIU);
           make.right.offset(-15 * WIDTHRADIU);
       }];
       
       [self.img_Back mas_makeConstraints:^(MASConstraintMaker *make) {
           make.centerX.equalTo(self.rightView);
           make.top.equalTo(self.img2_leftTop.mas_bottom);
           make.width.offset(imgWidth);
           make.height.offset(imgHeight);
       }];
       
       [self.lb2_uploadTitle mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(self.img_Back.mas_bottom).offset(4 * WIDTHRADIU);
           make.centerX.equalTo(self.rightView);
           make.height.offset(12 * WIDTHRADIU);
       }];
       
       [self.btn_right mas_makeConstraints:^(MASConstraintMaker *make) {
           make.center.equalTo(self.img_Back);
           make.width.height.offset(25 * WIDTHRADIU);
       }];
    
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.rightView);
        make.size.equalTo(self.rightView);
    }];
       
}

- (void)setupUI
{
    UIButton *btn_back = [UIButton buttonWithType:UIButtonTypeCustom];
    btn_back.frame = CGRectMake(0, 0, 60, 40);
    
    [btn_back setTitle:@"返回" forState:UIControlStateNormal];
    [btn_back setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
    btn_back.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn_back setImage:[[UIImage imageNamed:@"back"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    [btn_back addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [btn_back layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btn_back];
    if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]>=7) {
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        negativeSpacer.width = -15;
        self.navigationItem.leftBarButtonItems = @[negativeSpacer, backItem];
    }else{
        self.navigationItem.leftBarButtonItem = backItem;
    }
}


- (CGFloat)creatLineWithLeftStr:(NSString *)leftName height:(CGFloat)height index:(NSInteger)index
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"SSCardInfoCollectCell" owner:self options:nil];
    SSCardInfoCollectCell *view = [Bundle objectAtIndex:0];
    
    view.tf_right.delegate = self;
    
    view.tf_right.tag = 200 + index;
    
    
    
    view.leftLabel.text = leftName;
    
    [self.topView addSubview:view];
    
    if (index == 5) {
        view.frame = CGRectMake(0, addressView.maxY, ScreenWidth, height);
        departmentView = view;
        tf_deparment = view.tf_right;
    }else if (index == 6){
        view.frame = CGRectMake(0, departmentView.maxY, ScreenWidth, height);
        dateView = view;
    }else{
        if (index == 0){
            tf_name  = view.tf_right;
        }else if (index == 2){
            tf_idCard = view.tf_right;
        }else if (index == 3){
            tf_birth = view.tf_right;
        }
        view.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    }
    
    return view.frame.origin.y + height;
}


- (CGFloat)creatLine2WithHeight:(CGFloat)height index:(NSInteger)index
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"SSCardNationInfoCollectCell" owner:self options:nil];
    SSCardNationInfoCollectCell *view = [Bundle objectAtIndex:0];
    
    
    view.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    
    [self.topView addSubview:view];
    
    [view.btn_national cq_addAction:^(UIButton *button) {
        
        
         //获取plist文件
           NSURL *URL=[[NSBundle mainBundle]URLForResource:@"nation" withExtension:@"plist"];
           //plist 文件为字典类型
           NSArray *nations= [NSArray arrayWithContentsOfURL:URL];
          
          
        

        [CYAddressSelectedView show2AddressPickerWithTitle:@"请选择您的民族" data:nations addressType:AddressTypeNational resultBlock2:^(NSString * _Nonnull selectValue) {
            [button setTitle:selectValue forState:UIControlStateNormal];
        }];
        
    } forControlEvents:UIControlEventTouchUpInside];
    
    
    NSURL *URL2=[[NSBundle mainBundle]URLForResource:@"sex" withExtension:@"plist"];
             
    NSArray *sexs= [NSArray arrayWithContentsOfURL:URL2];
    
    [view.btn_sex cq_addAction:^(UIButton *button) {
        
        [CYAddressSelectedView showAddressPickerWithTitle:@"请选择您的性别" data:sexs addressType:AddressTypeSex resultBlock:^(NSDictionary * _Nonnull selectValue) {
            NSString *title = selectValue[@"name"];
            [button setTitle:title forState:UIControlStateNormal];
        }];
        
    } forControlEvents:UIControlEventTouchUpInside];
    
    btn_mz = view.btn_national;
    btn_sex = view.btn_sex;
    return view.frame.origin.y + height;
}

- (CGFloat)creatAddressViewWithHeight:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"SSCardInfoCollectAddressCell" owner:self options:nil];
       SSCardInfoCollectAddressCell *view = [Bundle objectAtIndex:0];
       view.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
       
       [self.topView addSubview:view];
    
    view.tv_address.delegate = self;
    
    view.tv_address.tag = 204;
    
    addressView = view;
    tv_address = view.tv_address;
    
    return view.frame.origin.y + height;
}

- (CGFloat)creatDateViewWithHeight:(CGFloat)height
{
    NSArray *Bundle = [[NSBundle mainBundle]loadNibNamed:@"SSCardDateSelectedTableViewCell" owner:self options:nil];
    SSCardDateSelectedTableViewCell *view = [Bundle objectAtIndex:0];
    view.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    [self.topView addSubview:view];
    dateView = view;
    
    [view.btn_startDate addTarget:self action:@selector(selectDateClick:) forControlEvents:UIControlEventTouchUpInside];
     [view.btn_endDate addTarget:self action:@selector(selectDateClick:) forControlEvents:UIControlEventTouchUpInside];
    
    startBtn = view.btn_startDate;
    endBtn = view.btn_endDate;
    
    return view.maxY;
}


#pragma mark - load Data
//上传身份证正反面照片
- (void)upLoadIdCardImg
{
    
   
    
    
     NSString *url = [NSString stringWithFormat:@"%@login/image",SSCardCollectBaseUrl];
    
     //对输入框的身份证去空格
    NSString *IdCardNum = [tf_idCard.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
    //身份证号AES加密
    NSString *IdentiftyEnerypt = [EnercryTool A:IdCardNum];
    
       NSDictionary *params = @{
                                @"idcard":IdentiftyEnerypt,
                                @"type":@"ID_CARD",
                                @"photo":base64Str_frontImg,
                                @"photo02":base64Str_backImg,
                                @"bak_01":[NSNumber numberWithInteger:[getPeopleID PeopleID]]
                                };
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
       
    
      [manager.requestSerializer setValue:self.accessToken forHTTPHeaderField:@"accessToken"];
       
    [manager POST:url parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"JSON:%@",responseObject);
                  
                  NSString *state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
                  if ([state isEqualToString:@"200"]) {
                      
                  }else{
                      [SVProgressHUD showInfoWithStatus:@"请检查您的网络"];
                  }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"Error: %@",error);
    }];
       
       
    
}


- (void)checkAllInfo
{
    if ([NSString blankString:base64Str_frontImg]) {
           [SVProgressHUD showInfoWithStatus:@"请拍摄身份证正面照"];
           return;
       }
       
       if ([NSString blankString:base64Str_backImg]) {
           [SVProgressHUD showInfoWithStatus:@"请拍摄身份证背面照"];
           return;
       }
       
       if (tf_name.text.length == 0) {
           [SVProgressHUD showInfoWithStatus:@"请填写姓名"];
           return;
       }
       
       if ([NSString blankString:btn_mz.titleLabel.text]) {
           [SVProgressHUD showInfoWithStatus:@"请选择民族"];
           return;
       }
       
       if ([NSString blankString:btn_sex.titleLabel.text]) {
           [SVProgressHUD showInfoWithStatus:@"请选择性别"];
           return;
       }
       
       if (tf_idCard.text.length == 0) {
           [SVProgressHUD showInfoWithStatus:@"请拍摄身份证"];
           return;
       }
       
       if (tf_birth.text.length == 0) {
           [SVProgressHUD showInfoWithStatus:@"请输入出生日期"];
           return;
       }
       
       if (tv_address.text.length == 0) {
              [SVProgressHUD showInfoWithStatus:@"请输入家庭住址"];
              return;
          }
       
       if (tf_deparment.text.length == 0) {
                 [SVProgressHUD showInfoWithStatus:@"请输入签发机关"];
                 return;
             }
       
       if (startDate == nil) {
                 [SVProgressHUD showInfoWithStatus:@"请选择起始时间"];
                 return;
             }
       
       if (endDate == nil) {
           [SVProgressHUD showInfoWithStatus:@"请选择截止时间"];
           return;
       }
    
    
     NSString *url = [NSString stringWithFormat:@"%@login/allInfo",SSCardCollectBaseUrl];
    
     //对输入框的身份证去空格
    NSString *IdCardNum = [tf_idCard.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
    //身份证号AES加密
    NSString *IdentiftyEnerypt = [EnercryTool A:IdCardNum];
    
       NSDictionary *params = @{
                                @"idcard":IdentiftyEnerypt,
                                @"operateid":[NSNumber numberWithInteger:[getPeopleID PeopleID]]
                                };
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
       
       [manager.requestSerializer setValue:self.accessToken forHTTPHeaderField:@"accessToken"];
       WeakSelf
    [manager POST:url parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"JSON:%@",responseObject);
        
        NSString *state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        if ([state isEqualToString:@"200"]) {
            
        }else if ([state isEqualToString:@"300"]){
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"该用户已采集,是否继续?" message:nil preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *checkAction= [UIAlertAction actionWithTitle:@"查看图片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [weakSelf queryImages];
            }];
            
            UIAlertAction *collectAction= [UIAlertAction actionWithTitle:@"继续采集" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                              
                
                [weakSelf goToCollectOtherInfo];
                          }];
            
            [alertVC addAction:checkAction];
            [alertVC addAction:collectAction];
            
            
            
            [self presentViewController:alertVC animated:YES completion:nil];
        }else if ([state isEqualToString:@"444"]){
             [SVProgressHUD showInfoWithStatus:@"访问过于频繁"];
        } else{
            [SVProgressHUD showInfoWithStatus:@"请检查您的网络"];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"Error: %@",error);
    }];
       
}


- (void)queryImages
{
     NSString *url = [NSString stringWithFormat:@"%@login/queryImages",SSCardCollectBaseUrl];
    
     //对输入框的身份证去空格
       NSString *IdCardNum = [tf_idCard.text  stringByReplacingOccurrencesOfString:@" " withString:@""];
       //身份证号AES加密
       NSString *IdentiftyEnerypt = [EnercryTool A:IdCardNum];
       
          NSDictionary *params = @{
                                   @"idcard":IdentiftyEnerypt,
                                   };
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager.requestSerializer setValue:self.accessToken forHTTPHeaderField:@"accessToken"];
    [manager POST:url parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"JSON:%@",responseObject);
               NSString *state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
               if ([state isEqualToString:@"200"]){
                   
                   
                   if ([responseObject[@"result"] isKindOfClass:[NSArray class]]) {
                       
                       
                       NSArray *result = responseObject[@"result"];
                       NSMutableArray *imageArray = [[NSMutableArray alloc]init];
                       imageArray = [SSCardCollectImageModel mj_objectArrayWithKeyValuesArray:result];
                       
                       SSCardCollectImagesController *vc = [[SSCardCollectImagesController alloc]init];
                       vc.title = @"采集图片";
                       vc.dataArray = imageArray;
                       [self.navigationController pushViewController:vc animated:YES];
                   }
               }else if ([state isEqualToString:@"444"]){
                   [SVProgressHUD showInfoWithStatus:@"访问过于频繁"];
               }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
    
}

- (void)goToCollectOtherInfo
{
    SSCardCollectBasicInfoController *vc = [[SSCardCollectBasicInfoController alloc]init];
    vc.title = @"基本信息";
    
    [self.navigationController pushViewController:vc animated:YES];
}



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

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    NSLog(@"%s",__func__);
    
    selectedTag = textField.tag;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField.tag == 202) {
        
        if (textField.text.length == 0) {
            [SVProgressHUD showInfoWithStatus:@"请拍摄身份证"];
        }
        
        return NO;
    }
    return YES;
}

#pragma mark - UITextViewDelegate

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    NSLog(@"%s",__func__);
    selectedTag = textView.tag;
}
- (void)textViewDidChange:(UITextView *)textView
{
    UIView *view  = textView.superview.superview;
        CGRect frame = view.frame;
        float height = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, MAXFLOAT)].height;
        
        frame.size.height = height > 33 ? (height + 25) + 0.5 : 58;
        height = frame.size.height;
        view.frame = frame;
        addressContentOffsetY = 58 + height ;
        
       
    
    NSLog(@"addressContentOffsetY:%f",addressContentOffsetY);
        
        departmentView.minY = view.maxY;
        dateView.minY = departmentView.maxY;
        self.topView.height = dateView.maxY + 50;
        self.backView.height = dateView.maxY + 50;
       self.scrollView.contentSize = CGSizeMake(ScreenWidth, self.backView.height);
       [self.scrollView setContentOffset:CGPointMake(0, 95 + 58+ self->addressContentOffsetY ) animated:NO];
}
//- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
//{
//    UIView *view  = textView.superview.superview;
//    CGRect frame = view.frame;
//    float height = [self heightForTextView:textView WithText:[NSString stringWithFormat:@"%@%@",textView.text,text]];
//    frame.size.height = height > 58 ? height : 58;
//    [UIView animateWithDuration:0.5 animations:^{
//
//            view.frame = frame;
//
//        } completion:nil];
//    addressContentOffsetY = 58 + height;
//
//   [self.scrollView setContentOffset:CGPointMake(0, 95 + 58+ self->addressContentOffsetY ) animated:YES];
//
//    departmentView.minY = view.maxY;
//    dateView.minY = departmentView.maxY;
//    self.topView.height = dateView.maxY + 50;
//
//    return YES;
//}





- (float) heightForTextView: (UITextView *)textView WithText: (NSString *) strText{
    CGSize constraint = CGSizeMake(textView.contentSize.width , CGFLOAT_MAX);
    CGRect size = [strText boundingRectWithSize:constraint
                                             options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                          attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]}
                                             context:nil];
    float textHeight = size.size.height + 25.0;
    return textHeight;
}

#pragma mark - SCNavigationControllerDelegate
- (void)sendIDCValue:(NSString *)name SEX:(NSString *)sex FOLK:(NSString *)folk BIRTHDAY:(NSString *)birthday ADDRESS:(NSString *) address NUM:(NSString *)num
{
    if (![NSString blankString:name] && btn_tmp == self.rightBtn) {
           [SVProgressHUD showInfoWithStatus:@"请重新拍摄身份证背面照"];
           return;
       }
   
    if (![IDCardNumber_Validate isValidateIDCardString:num]) {
        [SVProgressHUD showInfoWithStatus:@"身份证识别错误,请重新拍摄"];
        return;
    }
    
    tf_name.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];
    tf_idCard.text =  [NSString stringWithFormat:@"%@ %@ %@ %@",st1,st2,st3,st4];
    
    [btn_mz setTitle:folk forState:UIControlStateNormal];
    [btn_sex setTitle:sex forState:UIControlStateNormal];
    tf_birth.text = birthday;
    tv_address.text = address;
    
    
           UIView *view  = tv_address.superview.superview;
           CGRect frame = view.frame;
           float height = [tv_address sizeThatFits:CGSizeMake(tv_address.frame.size.width, MAXFLOAT)].height;
           
           frame.size.height = height > 33 ? (height + 25) + 0.5 : 58;
           height = frame.size.height;
           view.frame = frame;
          
           
          
       
       NSLog(@"addressContentOffsetY:%f",addressContentOffsetY);
           
           departmentView.minY = view.maxY;
           dateView.minY = departmentView.maxY;
           self.topView.height = dateView.maxY + 50;
           self.backView.height = dateView.maxY + 50;
          self.scrollView.contentSize = CGSizeMake(ScreenWidth, self.backView.height);
}


- (void)sendAllValue:(NSString *)text
{
    NSLog(@"all  = %@",text);
    
}
- (void)sendIDCBackValue:(NSString *)issue PERIOD:(NSString *) period
{
    NSLog(@"idcback  = %@\n%@\n",issue,period);
    
    if (![NSString blankString:issue] && btn_tmp == self.leftBtn) {
        [SVProgressHUD showInfoWithStatus:@"请重新拍摄身份证正面照"];
        return;
    }
    
    NSArray *array = [period componentsSeparatedByString:@"-"];
    
    [startBtn setTitle:array[0] forState:UIControlStateNormal];
    [endBtn setTitle:array[1] forState:UIControlStateNormal];
    
    
    [startBtn setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
    [endBtn setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
    
    startDate = array[0];
    endDate = array[1];
    
    tf_deparment.text = issue;
}
- (void)sendCardFaceImage:(UIImage *)image
{
    if (image != NULL) {

      // [self.leftBtn setBackgroundImage:image forState:UIControlStateNormal];

    }

}
- (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);
    UIImage *image = [CTImageCompression imageWithOriginalImage:cardImage];
    if (iCardType == TIDCARD2) {
        if (btn_tmp == self.leftBtn) {
            [self.leftBtn setBackgroundImage:cardImage forState:UIControlStateNormal];
            NSLog(@"1232:%@",[NSDate date]);
            
            base64Str_frontImg =   [CTImageCompression encodedImageToBase64StrWithImage:image];
            NSLog(@"456:%@",[NSDate date]);
            
        }else{
            [SVProgressHUD showInfoWithStatus:@"请重新拍摄身份证正面照"];
        }
        
    }else if (iCardType == TIDCARDBACK){
        if (btn_tmp == self.rightBtn) {
                   [self.rightBtn setBackgroundImage:cardImage forState:UIControlStateNormal];
            base64Str_backImg =  [CTImageCompression encodedImageToBase64StrWithImage:image];
               }else{
                   [SVProgressHUD showInfoWithStatus:@"请重新拍摄身份证背面照"];
               }
    }
    
    


//            NSData *small =UIImageJPEGRepresentation([self imageByScalingAndCroppingForSize:CGSizeMake(667, 375) and:cardImage], 1.0);
//  self.ocrBase64 = [small base64EncodedStringWithOptions:0];

}
- (void)sendIDCARDBackAction
{
    
}

#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];
    
    if (selectedTag < 203) {
        [UIView animateWithDuration:duration animations:^{
            [self.scrollView setContentOffset:CGPointMake(0, 95 + (self->selectedTag - 200)*58 ) animated:YES];
           }];
    } else{
        [UIView animateWithDuration:duration animations:^{
            [self.scrollView setContentOffset:CGPointMake(0, 95 + 58+ self->addressContentOffsetY ) animated:YES];
        }];
    }
   
}

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

-(void)getOCR
{
#if TARGET_IPHONE_SIMULATOR
    
#else
    // 打开引擎
    Gint ret = 0;
    Gint vaule = 1;
    ret = TREC_StartUP(TREC_GetEngineTimeKEY());
    if (ret == 100) {
        return;
    }
    if (ret == 100) {
        return;
    }if (ret == 101) {
        return;
    }
    
    ret = TREC_SetParam(T_SET_HEADIMG, &vaule);
    ret = TREC_SetSupportEngine(TIDCARD2);// 演示使用身份证，其他证件以此类推
    
    UIImage *sdfasf;
    sdfasf=   TREC_GetHeadImage();// 获取人头像图片流
    
    if (ret != 1) {
        
        TREC_ClearUP();
        return;
    }
    
    
    ret = TREC_ClearUP();
#endif

    


}



#pragma mark - event response
- (void)backClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)selectDateClick:(UIButton *)sender
{
    NSString *title = nil;
    if (sender == self->startBtn ) {
        title = @"请选择起始日期";
    }else{
        title = @"请选择截止日期";
    }
    WeakSelf
    [CYYearMonthDaySelectedView showDatePickerWithTitle:title minDateStr:@"" resultBlock:^(NSString * _Nonnull selectValue) {
        
        if (sender == self->startBtn) {
            
            if (self->endDate) {
                if (![self compareWithStartDate:self->endDate endDate:selectValue]) {
                     [sender setTitle:selectValue forState:UIControlStateNormal];
                                   self->startDate = selectValue;
                      [sender setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
                }else{
                    [SVProgressHUD showInfoWithStatus:@"起始日期不能大于等于截止日期"];
                }
            }else{
                [sender setTitle:selectValue forState:UIControlStateNormal];
                self->startDate = selectValue;
                [weakSelf selectDateClick:self->endBtn];
                 [sender setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
            }
        }else if (sender == self->endBtn){
            if ([self compareWithStartDate:self->startDate endDate:selectValue]) {
                [sender setTitle:selectValue forState:UIControlStateNormal];
                self->endDate = selectValue;
                 [sender setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
            }else{
                [SVProgressHUD showInfoWithStatus:@"截止日期不能小于等于起始日期"];
            }
        }
        
    }];
    
    
    
}

- (BOOL)compareWithStartDate:(NSString *)startDate endDate:(NSString *)endDate
{
    // 2.将时间转换为date
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy.MM.dd";
    NSDate *date1 = [formatter dateFromString:startDate];
    NSDate *date2 = [formatter dateFromString:endDate];
    NSComparisonResult result = [date1 compare:date2];
    
    if (result == NSOrderedDescending)
    {
        return NO;
    }else if (result == NSOrderedAscending){
        return YES;
    }else{
        return NO;
    }
}

- (void)scanClick:(UIButton *)sender
{
    
    btn_tmp = sender;
    
    SCCaptureCameraController *con = [[SCCaptureCameraController alloc] init];
    con.scNaigationDelegate = self;
    con.iCardType = TIDCARD2;
    con.isDisPlayTxt = NO;
    //con.TimeKey = TimeKeyS;
    con.ScanMode = TIDC_SCAN_MODE;
    [self presentViewController:con animated:YES completion:NULL];
}


#pragma mark - getters and setters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 100)];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.contentSize = CGSizeMake(ScreenWidth, self.backView.maxY + 20);
        
        
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        
        
        _scrollView.delegate = self;
        
        [_scrollView addSubview:self.backView];
    }
    return _scrollView;
}

- (UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 600)];
        _backView.backgroundColor = [UIColor whiteColor];
        
        [_backView addSubview:self.topView];
//        [_backView addSubview:self.whiteView];
//        [_backView addSubview:self.img_success];
//        [_backView addSubview:self.lb_success];
//        [_backView addSubview:self.btn_approve];
//        [_backView addSubview:self.btn_back];
         
    }
    return _backView;
}

- (UIView *)topView
{
    if (!_topView) {
        _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 600)];
        _topView.backgroundColor = [UIColor whiteColor];
        [_topView addSubview:self.gradualView];
        [_topView addSubview:self.lb_title];
        [_topView addSubview:self.btn_shootRequirement];
        
        [_topView addSubview:self.leftView];
        [_topView addSubview:self.rightView];
        
           CGFloat leftMargin = 10 * WIDTHRADIU;
           CGFloat middleMargin = 11 * WIDTHRADIU;
           CGFloat rightMargin = 10 * WIDTHRADIU;
           CGFloat width = (SCREEN_WIDTH - leftMargin - middleMargin - rightMargin)/2;
           CGFloat scale = 230/344.0;
           CGFloat height = width * scale;
           currentMaxY = 10 * WIDTHRADIU + height + 28.5;
        NSArray *titleArray = @[@"*姓        名",@"*民        族",@"*身份证号",@"*出生日期",@"*家庭住址",@"*签发机关",@"*有效日期"];
        
        for (int i = 0; i < titleArray.count; i++) {
            
            if (i == 1) {
                currentMaxY = [self creatLine2WithHeight:58 index:i];
            }else if (i == 4){
                currentMaxY = [self creatAddressViewWithHeight:58];
            }else if (i == 6){
                currentMaxY = [self creatDateViewWithHeight:58];
            }else{
                currentMaxY = [self creatLineWithLeftStr:titleArray[i] height:58 index:i];
            }
            
            
        }
        
        self.backView.maxY = currentMaxY + 50;
       
        
    }
    return _topView;
}

- (UIView *)gradualView
{
    if (!_gradualView) {
        _gradualView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 135)];
        
        CAGradientLayer * gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = _gradualView.bounds;
        gradientLayer.colors = @[(__bridge id)[UIColor whiteColor].CGColor,(__bridge id)[UIColor colorWithHex:0xe3effb].CGColor];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(0, 1);
        gradientLayer.locations = @[@0.3,@1];
        [_gradualView.layer addSublayer:gradientLayer];
    }
    return _gradualView;
}

- (UILabel *)lb_title
{
    if (!_lb_title) {
        _lb_title = [[UILabel alloc]init];
        _lb_title.text = @"拍摄身份证";
        _lb_title.font = [UIFont systemFontOfSize:17];
        _lb_title.textColor = [UIColor colorWithHex:0x333333];
    }
    return _lb_title;
}

- (UIButton *)btn_shootRequirement
{
    if (!_btn_shootRequirement) {
        _btn_shootRequirement = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_shootRequirement setTitle:@"拍摄要求" forState:UIControlStateNormal];
        [_btn_shootRequirement setTitleColor:K_MainColor forState:UIControlStateNormal];
        _btn_shootRequirement.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return _btn_shootRequirement;
}


- (UIView *)leftView
{
    if (!_leftView) {
        _leftView = [[UIView alloc]init];
        
        _leftView.backgroundColor = [UIColor whiteColor];
        _leftView.layer.cornerRadius = 5 * WIDTHRADIU;
        [_leftView addSubview:self.img_leftTop];
        [_leftView addSubview:self.img_leftBottom];
        [_leftView addSubview:self.img_rightBottom];
        [_leftView addSubview:self.img_rightTop];
        [_leftView addSubview:self.img_Front];
        [_leftView addSubview:self.btn_left];
        [_leftView addSubview:self.lb_uploadTitle];
        [_leftView addSubview:self.leftBtn];
        
        _leftView.layer.shadowColor = K_MainColor.CGColor;
        _leftView.layer.shadowOffset = CGSizeMake(0, 1);
        _leftView.layer.shadowOpacity = 0.2;
        _leftView.layer.shadowRadius = 1 * WIDTHRADIU;
        
        
        
    }
    return _leftView;
}

- (UIImageView *)img_leftTop
{
    if (!_img_leftTop) {
        _img_leftTop = [[UIImageView alloc]init];
        _img_leftTop.image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
    }
    return _img_leftTop;
}
- (UIImageView *)img_leftBottom
{
    if (!_img_leftBottom) {
        _img_leftBottom = [[UIImageView alloc]init];
        UIImage *image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
        _img_leftBottom.image = [UIImage lj_imageRotatedByDegrees:-90 image:image];
    }
    return _img_leftBottom;
}
- (UIImageView *)img_rightBottom
{
    if (!_img_rightBottom) {
        _img_rightBottom = [[UIImageView alloc]init];
        UIImage *image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
        _img_rightBottom.image = [UIImage lj_imageRotatedByDegrees:-180 image:image];
    }
    return _img_rightBottom;
}

- (UIImageView *)img_rightTop
{
    if (!_img_rightTop) {
        _img_rightTop = [[UIImageView alloc]init];
        UIImage *image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
        _img_rightTop.image = [UIImage lj_imageRotatedByDegrees:-270 image:image];
    }
    return _img_rightTop;
}

- (UIImageView *)img_Front
{
    if (!_img_Front) {
        _img_Front = [[UIImageView alloc]init];
        _img_Front.image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_IDcardfront_normal"];
    }
    return _img_Front;
}

- (UILabel *)lb_uploadTitle
{
    if (!_lb_uploadTitle) {
        _lb_uploadTitle = [[UILabel alloc]init];
        _lb_uploadTitle.text = @"上传证件人像面";
        _lb_uploadTitle.textColor = [UIColor colorWithHex:0x808080];
        _lb_uploadTitle.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
    }
    return _lb_uploadTitle;
}

- (UIButton *)btn_left
{
    if (!_btn_left) {
        _btn_left = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_left.backgroundColor = K_MainColor;
        [_btn_left setImage:[UIImage imageNamed:@"Socialsecuritycontributions_camera_normal"] forState:UIControlStateNormal];
        _btn_left.layer.cornerRadius = 12.5 * WIDTHRADIU;
        
    }
    return _btn_left;
}
- (UIButton *)leftBtn
{
    if (!_leftBtn) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        WeakSelf
        [_leftBtn cq_addAction:^(UIButton *button) {
               
             [weakSelf scanClick:button];
               
           } forControlEvents:UIControlEventTouchUpInside];
        
        
        
        
    }
    return _leftBtn;
}

- (UIView *)rightView
{
    if (!_rightView) {
        _rightView  = [[UIView alloc]init];
        _rightView.backgroundColor = [UIColor whiteColor];
        _rightView.layer.cornerRadius = 5 * WIDTHRADIU;
        [_rightView addSubview:self.img2_leftTop];
        [_rightView addSubview:self.img2_leftBottom];
        [_rightView addSubview:self.img2_rightBottom];
        [_rightView addSubview:self.img2_rightTop];
        [_rightView addSubview:self.img_Back];
        [_rightView addSubview:self.lb2_uploadTitle];
        [_rightView addSubview:self.btn_right];
        [_rightView addSubview:self.rightBtn];
        _rightView.layer.shadowColor = K_MainColor.CGColor;
        _rightView.layer.shadowOffset = CGSizeMake(0, 1);
        _rightView.layer.shadowOpacity = 0.2;
        _rightView.layer.shadowRadius = 1 * WIDTHRADIU;
    }
    return _rightView;
}

- (UIImageView *)img2_leftTop
{
    if (!_img2_leftTop) {
        _img2_leftTop = [[UIImageView alloc]init];
        _img2_leftTop.image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
    }
    return _img2_leftTop;
}
- (UIImageView *)img2_leftBottom
{
    if (!_img2_leftBottom) {
        _img2_leftBottom = [[UIImageView alloc]init];
        UIImage *image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
        _img2_leftBottom.image = [UIImage lj_imageRotatedByDegrees:-90 image:image];
    }
    return _img2_leftBottom;
}
- (UIImageView *)img2_rightBottom
{
    if (!_img2_rightBottom) {
        _img2_rightBottom = [[UIImageView alloc]init];
        UIImage *image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
        _img2_rightBottom.image = [UIImage lj_imageRotatedByDegrees:-180 image:image];
    }
    return _img2_rightBottom;
}

- (UIImageView *)img2_rightTop
{
    if (!_img2_rightTop) {
        _img2_rightTop = [[UIImageView alloc]init];
        UIImage *image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_Squarecorner_normal"];
        _img2_rightTop.image = [UIImage lj_imageRotatedByDegrees:-270 image:image];
    }
    return _img2_rightTop;
}

- (UIImageView *)img_Back
{
    if (!_img_Back) {
        _img_Back = [[UIImageView alloc]init];
        _img_Back.image = [UIImage imageNamed:@"Socialsecuritycontributions_IDUpload_ReversesideofIDcard_normal"];
    }
    return _img_Back;
}

- (UILabel *)lb2_uploadTitle
{
    if (!_lb2_uploadTitle) {
        _lb2_uploadTitle = [[UILabel alloc]init];
        _lb2_uploadTitle.text = @"上传国徽面";
        _lb2_uploadTitle.textColor = [UIColor colorWithHex:0x808080];
        _lb2_uploadTitle.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
    }
    return _lb2_uploadTitle;
}

- (UIButton *)btn_right
{
    if (!_btn_right) {
        _btn_right = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn_right.backgroundColor = K_MainColor;
        [_btn_right setImage:[UIImage imageNamed:@"Socialsecuritycontributions_camera_normal"] forState:UIControlStateNormal];
        _btn_right.layer.cornerRadius = 12.5 * WIDTHRADIU;
            
    }
    return _btn_right;
}

- (UIButton *)rightBtn
{
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        WeakSelf
        [_rightBtn cq_addAction:^(UIButton *button) {
               
            [weakSelf scanClick:button];
               
           } forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _rightBtn;
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 100, ScreenWidth, 100)];
        _bottomView.backgroundColor = [UIColor whiteColor];
        UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        nextBtn.backgroundColor = K_MainColor;
        [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        nextBtn.layer.cornerRadius = 5;
        [nextBtn addTarget:self action:@selector(checkAllInfo) forControlEvents:UIControlEventTouchUpInside];
        [_bottomView addSubview:nextBtn];
        
        
       UILabel *lb_message = [[UILabel alloc]init];
        lb_message.text = @"请确认身份信息，如有误请重拍或手动修改";
        lb_message.font = [UIFont systemFontOfSize:14];
        lb_message.textColor = [UIColor colorWithHex:0xcccccc];
        lb_message.textAlignment = NSTextAlignmentCenter;
        [_bottomView addSubview:lb_message];
        
        
        
        [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
          make.centerX.equalTo(self->_bottomView);
            make.height.offset(14);
            make.width.offset(ScreenWidth);
            make.top.offset(15);
        }];
         [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
             make.centerX.equalTo(self->_bottomView);
               make.height.offset(45);
               make.width.offset(ScreenWidth);
             make.bottom.offset(-10);
           }];
    }
    return _bottomView;
}




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