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

#import "JoinPartnerViewController.h"

#import <IQKeyboardManager.h>

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

#import "Constants.h"
#import "Tools.h"

#import "InsuredMemberAddTableViewCell.h"

#import "JoinPartnerResultViewController.h"
#import "PartnerCenterViewController.h"
#import "FaceImageModel.h"

@interface JoinPartnerViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UITextViewDelegate,SCNavigationControllerDelegate,passImagesDelegate>
{
    CGPoint _editOffset;
    
    CGFloat _editHeight;
    
    //记录位置
    CGFloat currentMaxY;
    
    //记录户籍textview的placeholder
    UILabel* lb_address;
    
    UITextField* tf_name;
    UITextField* tf_nation;
    UITextField* tf_idNumber;
    UITextView * tv_address;
    UITextField* tf_phone;
    
    UIImage* cardFrontImg;
    UIImage* cardBackImg;
}

@property (nonatomic, strong)UIView *topView;
@property (nonatomic, strong)UIView *topBackView;
@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)UILabel *lb_title;

@property (nonatomic, strong)UIImageView* img_message;

@property (nonatomic, strong)UILabel *lb_message;



@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)UIScrollView *scrollview;

@property (nonatomic, strong)UIView *bottomView;
@property (nonatomic, strong)NSArray *titleArray;

@property (nonatomic, assign)CGPoint lastContentOffset;

@property(nonatomic ,strong) UITextField * firstResponderTextF;//记录将要编辑的输入框

@property(nonatomic, strong)NSMutableArray* imageManyImage;

@end

@implementation JoinPartnerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"加入合伙人";
    self.view.backgroundColor = [UIColor colorWithHex:0xf5f5f5];
       [self.view addSubview:self.scrollview];
       [self.view addSubview:self.bottomView];
       
       currentMaxY = self.topView.maxY;
       
       NSArray *titles = @[@"姓       名",@"民       族",@"身份证号",@"户籍住址",@"手机号码"];
       NSArray *placeholders = @[@"请输入姓名",@"请输入民族",@"请输入身份证号码",@"请输入户籍住址",@"请输入联系方式"];
       for (int i = 0; i < 5; i++) {
         currentMaxY =  [self creatLineWithLeftStr:titles[i] right:placeholders[i] height:45*WIDTHRADIU index:i];
       }
       
       self.scrollview.contentSize = CGSizeMake(ScreenWidth, currentMaxY + 50);
       //[self.view addSubview:self.tableView];
       //起点发生变化
       //self.edgesForExtendedLayout=UIRectEdgeBottom;
       
       //创建观察者，监听键盘的弹出
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
       //收起键盘的通知
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
       
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChangedExt:) name:UITextViewTextDidChangeNotification object:nil];
       
       NSLog(@"scrollview.offset.y:%f",self.scrollview.contentOffset.y);
       

    [self configNav];
       
}

- (void)configNav
{
    UIBarButtonItem * backButtonItem = [[UIBarButtonItem alloc] init];
    backButtonItem.title = @"返回";
    self.navigationItem.backBarButtonItem = backButtonItem;
    
    self.imageManyImage = [NSMutableArray array];
}
- (void)dealloc
{
    NSLog(@"InsuredMemberAddViewController销毁了");
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UITextViewTextDidChangeNotification object:nil];
}


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

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


#pragma mark : UIKeyboardWillShowNotification/UIKeyboardWillHideNotification
- (void)keyboardWillShow:(NSNotification *)notification
{
    
    NSDictionary *userInfo = [notification userInfo];
    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];//获取弹出键盘的fame的value值
    CGRect keyboardRect = [aValue CGRectValue];
    keyboardRect = [self.view convertRect:keyboardRect fromView:self.view];//获取键盘相对于self.view的frame ，传window和传nil是一样的
    NSLog(@"键盘相对于屏幕的位置%@",NSStringFromCGRect(keyboardRect));
//    CGFloat keyboardTop = keyboardRect.origin.y;
    NSNumber * animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];//获取键盘弹出动画时间值
    NSTimeInterval animationDuration = [animationDurationValue doubleValue];
    
    
    NSLog(@"self.topView.maxY:%f",self.topView.maxY);
        [UIView animateWithDuration:animationDuration animations:^{
            [self.scrollview setContentOffset:CGPointMake(0, self.topView.maxY) animated:NO];
        }];
        
}

-(void)keyboardWillHide:(NSNotification *)note{
         [self.scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
    [self.lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(11 * WIDTHRADIU);
        make.left.offset(20 * WIDTHRADIU);
        make.height.offset(16 * WIDTHRADIU);
    }];
    
    
    
    
    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(leftMargin);
        make.top.offset(36 * 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);
        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.top.left.offset(10);
        make.right.bottom.offset(-10);
    }];
    
    
    [self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10 * WIDTHRADIU);
        make.top.equalTo(self.leftView);
        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.top.left.offset(10);
          make.right.bottom.offset(-10);
      }];
     
}

- (CGFloat)creatLineWithLeftStr:(NSString *)leftName right:(NSString *)rightName height:(CGFloat)height index:(NSInteger)index
{
    
   
    InsuredMemberAddTableViewCell *view = [[InsuredMemberAddTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    
    view.frame = CGRectMake(0, currentMaxY, ScreenWidth, height);
    
    [self.scrollview addSubview:view];
    
    view.lb_title.text = leftName;
    
    if (index == 3) {
        view.tv_value.delegate = self;
        view.tv_value.tag = 200 + index;
        view.tf_value.hidden = YES;
        view.tv_value.hidden = NO;
        view.tv_value.textColor = [UIColor grayColor];
        lb_address = view.placeHolder;
        tv_address = view.tv_value;
        return view.maxY + 10;
    }else{
        view.tf_value.placeholder = rightName;
        view.tf_value.delegate = self;
           
           
        view.tf_value.tag = 200 + index;
    }
    
    if (index == 0) {
        tf_name =  view.tf_value;
        tf_name.inputAccessoryView = [self addToolbar:tf_name];
    }else if (index == 1){
        tf_nation = view.tf_value;
        tf_nation.inputAccessoryView = [self addToolbar:tf_nation];
    }else if (index == 2){
        tf_idNumber = view.tf_value;
        tf_idNumber.inputAccessoryView = [self addToolbar:tf_idNumber];
    }else if (index == 4){
        tf_phone = view.tf_value;
        tf_phone.keyboardType = UIKeyboardTypeNumberPad;
        tf_phone.inputAccessoryView = [self addToolbar:tf_phone];
        view.hidden = YES;
    }
    
   
    
    return view.maxY;

}


- (UIToolbar *)addToolbar:(UITextField *)tf
{
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 35)];
    toolbar.tintColor = K_MainColor;
    toolbar.backgroundColor = [UIColor grayColor];
//    UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(nextTextField)];
//    UIBarButtonItem *prevButton = [[UIBarButtonItem alloc] initWithTitle:@"上一步" style:UIBarButtonItemStylePlain target:self action:@selector(prevTextField)];
    
    UILabel *lb_title = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 15)];
    lb_title.textColor = [UIColor colorWithHex:0xc0c0c0];
    lb_title.text = tf.placeholder;
    
    UIBarButtonItem *placeholderItem = [[UIBarButtonItem alloc]initWithCustomView:lb_title];
    
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(textFieldDone)];
//    if (tf == self.tf_UserName) {
//        toolbar.items = @[nextButton, space, bar];
//    }else if (tf == self.tf_Password)
//    {
//        toolbar.items = @[prevButton, space, bar];
//    }
    toolbar.items = @[placeholderItem,space,bar];
    
    return toolbar;
}
//-(void)nextTextField{
//
//    if (self.tf_UserName.isFirstResponder) {
//        [self.tf_Password becomeFirstResponder];
//    }
//}
//- (void)prevTextField {
//
//    if (self.tf_Password.isFirstResponder) {
//        [self.tf_UserName becomeFirstResponder];
//    }
//
//}
- (void)textFieldDone {
    [self.view endEditing:YES];
}



#pragma mark - loadApi
- (NSDictionary *)upLoadCardImageRequestParaWithImageBaseStr:(NSString *)imageStr
{
//    NSData* imageData = nil;
//    if (isLeft) {
//        imageData = UIImageJPEGRepresentation(cardFrontImg, 1);
//    }else{
//        imageData = UIImageJPEGRepresentation(cardBackImg, 1);
//    }
    //[imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]
    NSDictionary* params = @{
        @"base64Image":imageStr
    };
    return params;
}
- (void)upLoadCardImageRequestWithImageBaseStr:(NSString *)imageStr resultBlock:(void (^)(bool success,NSString* imageName))result
{
//    WeakSelf
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipSwitchConfig],PartnerUpLoadCardImageRequest];
    NSLog(@"合伙人上传身份证图片url:%@",urlString);
    
    [NetworkRequest uploadImage:urlString Params:[self upLoadCardImageRequestParaWithImageBaseStr:imageStr] Image:nil ImageName:nil ImageParam:nil Success:^(id _Nonnull responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            if ([code isEqualToString:@"200"]) {
                NSString*data = responseObject[@"result"];
                if ([data isKindOfClass:[NSString class]] && ![NSString blankString:data]) {
                     result(YES,data);
                }else{
                     result(NO,nil);
                }
               
            }else{
                result(NO,nil);
            }
        }else{
            result(NO,nil);
        }
        
    } Failure:^(NSError* error) {
        NSLog(@"error:%@",error);
        result(NO,nil);
    }];
}

//上传脸部图片
- (NSDictionary *)upLoad2CardImageRequestParaWithImageBaseStr:(NSString *)imageStr
{
//    NSData* imageData = nil;
//    if (isLeft) {
//        imageData = UIImageJPEGRepresentation(cardFrontImg, 1);
//    }else{
//        imageData = UIImageJPEGRepresentation(cardBackImg, 1);
//    }
    //[imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]
    NSDictionary* params = @{
        @"base64Images":imageStr
    };
    return params;
}
- (void)upLoad2CardImageRequestWithImageBaseStr:(NSString *)imageStr resultBlock:(void (^)(bool success,NSString* imageName))result
{
//    WeakSelf
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipSwitchConfig],PartnerFaceUpLoadCardImageRequest];
    NSLog(@"合伙人上传脸部图片url:%@",urlString);
    
    [NetworkRequest uploadImage:urlString Params:[self upLoad2CardImageRequestParaWithImageBaseStr:imageStr] Image:nil ImageName:nil ImageParam:nil Success:^(id _Nonnull responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            if ([code isEqualToString:@"200"]) {
                NSString*data = responseObject[@"result"];
                if ([data isKindOfClass:[NSString class]] && ![NSString blankString:data]) {
                     result(YES,data);
                }else{
                     result(NO,nil);
                }
               
            }else{
                result(NO,nil);
            }
        }else{
            result(NO,nil);
        }
        
    } Failure:^(NSError* error) {
        NSLog(@"error:%@",error);
        result(NO,nil);
    }];
}

#pragma mark - 上传所有信息
- (void)upLoadAllInfoWithImages:(NSArray *)imagesArray
{
    NSString*bas64Str = nil;
    for (UIImage* image in imagesArray) {
        if (bas64Str) {
            bas64Str = [bas64Str stringByAppendingFormat:@",%@",[self getCompressImagebase64StrWithOriginalImage:image]];
        }else{
            bas64Str = [self getCompressImagebase64StrWithOriginalImage:image];
        }
    }
    
    NSString*cardFrontStr = [UIImageJPEGRepresentation(cardFrontImg, 1.0) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    NSString*cardBackStr = [UIImageJPEGRepresentation(cardBackImg, 1.0) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [KKLoadingAnimationView show];
    [self upLoadCardImageRequestWithImageBaseStr:cardFrontStr resultBlock:^(bool success, NSString *frontName) {
        
        if (success) {
            [self upLoadCardImageRequestWithImageBaseStr:cardBackStr resultBlock:^(bool success, NSString *backName) {
                if (success) {
                    [self upLoad2CardImageRequestWithImageBaseStr:bas64Str resultBlock:^(bool success, NSString *faceName) {
                        if (success) {
                            [self upLoadAllInfoRequestWithFaceName:faceName front:frontName back:backName];
                        }else{
                            [KKLoadingAnimationView dismiss];
                            [SVProgressHUD showInfoWithStatus:@"提交失败"];
                        }
                    }];
                }else{
                    [KKLoadingAnimationView dismiss];
                    [SVProgressHUD showInfoWithStatus:@"提交失败"];
                }
            }];
        }else
        {
            [KKLoadingAnimationView dismiss];
            [SVProgressHUD showInfoWithStatus:@"提交失败"];
        }
    }];
    
    
}
- (NSDictionary *)upLoadAllInfoRequestParamsWithFaceName:(NSString *)faceName front:(NSString *)frontName back:(NSString *)backName
{
    NSDictionary*params = @{
        @"name":[EnercryTool A:tf_name.text],
        @"column10":tf_nation.text,
        @"address":tv_address.text,
        @"top":frontName? frontName :@"",
        @"back":backName? backName:@"",
        @"face":faceName?faceName:@"",
        @"carNum":[EnercryTool A:tf_idNumber.text],
        @"tel":[EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY]
    };
    return params;
}

- (void)upLoadAllInfoRequestWithFaceName:(NSString *)faceName front:(NSString *)frontName back:(NSString *)backName
{
//    WeakSelf
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipPartnerConfig],PartnetUPloadAllInfoRequest];
    NSLog(@"合伙人上传所有信息url:%@",urlString);
    NSLog(@"params:%@",[self upLoadAllInfoRequestParamsWithFaceName:faceName front:frontName back:backName]);
    
    [NetworkRequest Post2:urlString Params:[self upLoadAllInfoRequestParamsWithFaceName:faceName front:frontName back:backName] Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
            if ([code isEqualToString:@"200"]) {
                JoinPartnerResultViewController* vc = [JoinPartnerResultViewController new];
                vc.type = @"success";
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                [SVProgressHUD showInfoWithStatus:@"提交失败"];
            }
        }else{
            [SVProgressHUD showInfoWithStatus:@"提交失败"];
        }
        
    } Failure:^(NSError* error) {
        NSLog(@"error:%@",error);
        [KKLoadingAnimationView dismiss];
        [SVProgressHUD showInfoWithStatus:@"提交失败"];
    }];
    
}


#pragma mark - SCNavigationControllerDelegate
- (void)sendIDCValue:(NSString *)name SEX:(NSString *)sex FOLK:(NSString *)folk BIRTHDAY:(NSString *)birthday ADDRESS:(NSString *) address NUM:(NSString *)num
{
    
        tf_name.text =name;
        tf_idNumber.text =  num;
        tf_nation.text = folk;
        tv_address.text = address;
        
        [tv_address.delegate textViewDidChange:tv_address];
    
    
    
}

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

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

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

}
- (void)sendTakeImage:(TCARD_TYPE) iCardType image:(UIImage *)cardImage
{
    NSLog(@"sendTakeImage = %d %@\n",iCardType,cardImage);

    if (iCardType == TIDCARDBACK) {
        [self.rightBtn setBackgroundImage:cardImage forState:UIControlStateNormal];
        cardBackImg = [UIImage imageWithImage:cardImage scale:0.125];
    }else if (iCardType == TIDCARD2){
        [self.leftBtn setBackgroundImage:cardImage forState:UIControlStateNormal];
        cardFrontImg = [UIImage imageWithImage:cardImage scale:0.125];
    }
    
    NSLog(@"imageWidth:%f,imageHeight:%f",cardFrontImg.size.width,cardFrontImg.size.height);
    
    

}
- (void)sendIDCARDBackAction
{
    
}



#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    self.firstResponderTextF = textField;
    
    return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
   
//    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
//    CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:indexPath];
//    CGRect rectInSuperview = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];
//
//     [self.tableView setContentOffset:rectInTableView.origin animated:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)sender {
    
    // 执行动画(恢复到原始位置)
    //[self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
    
    // 交出第一响应者
    [sender resignFirstResponder];
    
    return YES;
}

#pragma mark - UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    //NSInteger height = [NSString getSpaceLabelHeightwithSpeace:4 withFont:[UIFont systemFontOfSize:15 * WIDTHRADIU] withWidth:(ScreenWidth- 115 * WIDTHRADIU) text:textView.text];
    
      [textView sizeToFit];
    
      CGRect rect = textView.frame;
      //TEXTVIEW_WIDTH为UITextView的固定宽度值
      rect.size.width = ScreenWidth - 125 * WIDTHRADIU;
      textView.frame = rect;
    
       CGRect frame = textView.superview.frame;
//       frame.size.height = height > (30 * WIDTHRADIU - 10) ? (height + 15 * WIDTHRADIU + 10) : 45 * WIDTHRADIU;
       frame.size.height = textView.bounds.size.height + 15 * WIDTHRADIU;
       textView.superview.frame = frame;
       
       CGRect frame2 = tf_phone.superview.frame;
       frame2.origin.y = textView.superview.maxY+10;
       tf_phone.superview.frame = frame2;
       
       [textView.superview layoutIfNeeded];
       [tf_phone.superview layoutIfNeeded];
    
    self.scrollview.contentSize = CGSizeMake(ScreenWidth, tf_phone.superview.maxY + 50);
     [self.scrollview setContentOffset:CGPointMake(0, self.topView.maxY) animated:NO];
    
    return YES;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
//    NSInteger height = [NSString getSpaceLabelHeightwithSpeace:4 withFont:[UIFont systemFontOfSize:15 * WIDTHRADIU] withWidth:(ScreenWidth- 115 * WIDTHRADIU) text:textView.text];
//       CGRect frame = textView.superview.frame;
//       frame.size.height = height > (30 * WIDTHRADIU - 10) ? (height + 15 * WIDTHRADIU + 10) : 45 * WIDTHRADIU;
//       textView.superview.frame = frame;
//       
//       CGRect frame2 = tf_phone.superview.frame;
//       frame2.origin.y = textView.superview.maxY+10;
//       tf_phone.superview.frame = frame2;
//       
//       [textView.superview layoutIfNeeded];
//       [tf_phone.superview layoutIfNeeded];
//    
//    self.scrollview.contentSize = CGSizeMake(ScreenWidth, tf_phone.superview.maxY + 50);
    
    return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
          [textView sizeToFit];
        
          CGRect rect = textView.frame;
          //TEXTVIEW_WIDTH为UITextView的固定宽度值
          rect.size.width = ScreenWidth - 125 * WIDTHRADIU;
          textView.frame = rect;
        
           CGRect frame = textView.superview.frame;
    //       frame.size.height = height > (30 * WIDTHRADIU - 10) ? (height + 15 * WIDTHRADIU + 10) : 45 * WIDTHRADIU;
           frame.size.height = textView.bounds.size.height + 15 * WIDTHRADIU;
           textView.superview.frame = frame;
       
       CGRect frame2 = tf_phone.superview.frame;
       frame2.origin.y = textView.superview.maxY+10;
       tf_phone.superview.frame = frame2;
       
       [textView.superview layoutIfNeeded];
       [tf_phone.superview layoutIfNeeded];
    
    self.scrollview.contentSize = CGSizeMake(ScreenWidth, tf_phone.superview.maxY + 50);
    
     
    if (textView.isFirstResponder) {
        [self.scrollview setContentOffset:CGPointMake(0, self.topView.maxY) animated:NO];
    }
    
    
    
    if (!textView.text.length){
        lb_address.alpha = 1;
    }else{
        lb_address.alpha = 0;
    }
}

- (void)textChangedExt:(NSNotification *)notification
{
//    CGFloat height = [NSString getSpaceLabelHeightwithSpeace:4 withFont:[UIFont systemFontOfSize:15 * WIDTHRADIU] withWidth:(ScreenWidth- 115 * WIDTHRADIU) text:tv_address.text];
//
//       CGRect frame = tv_address.superview.frame;
//       frame.size.height = height > (30 * WIDTHRADIU - 10) ? (height + 15 * WIDTHRADIU + 12) : 45 * WIDTHRADIU;
//       tv_address.superview.frame = frame;
    
    
           [tv_address sizeToFit];
          
            CGRect rect = tv_address.frame;
            //TEXTVIEW_WIDTH为UITextView的固定宽度值
            rect.size.width = ScreenWidth - 125 * WIDTHRADIU;
            tv_address.frame = rect;
          
             CGRect frame = tv_address.superview.frame;
      //       frame.size.height = height > (30 * WIDTHRADIU - 10) ? (height + 15 * WIDTHRADIU + 10) : 45 * WIDTHRADIU;
             frame.size.height = tv_address.bounds.size.height + 15 * WIDTHRADIU;
             tv_address.superview.frame = frame;
    
       
       CGRect frame2 = tf_phone.superview.frame;
       frame2.origin.y = tv_address.superview.maxY+10;
       tf_phone.superview.frame = frame2;
       
       [tv_address.superview layoutIfNeeded];
       [tf_phone.superview layoutIfNeeded];
    
    self.scrollview.contentSize = CGSizeMake(ScreenWidth, tf_phone.superview.maxY + 50);
    
    
    if (self.scrollview.contentOffset.y != self.topView.maxY) {
        [self.scrollview setContentOffset:CGPointMake(0, self.topView.maxY) animated:YES];
    }
     
    
    if (!tv_address.text.length){
        lb_address.alpha = 1;
    }else{
        lb_address.alpha = 0;
    }
}


#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 4;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    InsuredMemberAddTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.tf_value.delegate = self;
    cell.tv_value.delegate = self;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        NSArray * array = self.titleArray[0];
        [cell refreshUIWithTitle:array[indexPath.row]];
    }else{
         [cell refreshUIWithTitle:self.titleArray[1]];
        cell.tf_value.hidden = YES;
        cell.tv_value.hidden = NO;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
       return  _editHeight > 45 * WIDTHRADIU ? _editHeight + 10 * WIDTHRADIU : 45 * WIDTHRADIU;
    }
    return 45 * WIDTHRADIU;
}

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

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



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

     }
    
    
    [self.imageManyImage removeAllObjects];

    [self.imageManyImage addObject:originImage[0]];
    [self.imageManyImage addObject:originImage[originImage.count-3]];
    [self.imageManyImage addObject:originImage[originImage.count-2]];
    [self.imageManyImage addObject:originImage[originImage.count-1]];

//
    [self upLoadAllInfoWithImages:self.imageManyImage];
}

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


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

- (void)IdClick:(UIButton *)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];
}

- (void)commitPayUserInfoClick:(UIButton *)sender
{
    

    
    
    if (!(cardBackImg && cardFrontImg)) {
        [SVProgressHUD showInfoWithStatus:@"请拍摄身份证正反面"];
        return;
    }
    
    if (tf_name.text.length < 2) {
        [SVProgressHUD showInfoWithStatus:@"请正确输入姓名"];
        return;
    }

    if (![Tools isChinese:tf_nation.text] || tf_nation.text.length < 1) {
        [SVProgressHUD showInfoWithStatus:@"请正确输入民族"];
        return;
    }

    if (![IDCardNumber_Validate isValidateIDCardString:tf_idNumber.text] || tf_idNumber.text.length == 0) {
        [SVProgressHUD showInfoWithStatus:@"请正确的身份证号码"];
        return;
    }

    if (tv_address.text.length < 1) {
        [SVProgressHUD showInfoWithStatus:@"请正确的户籍地址"];
        return;
    }
//
//    if (![Tools isMobileNumber:tf_phone.text]) {
//        [SVProgressHUD showInfoWithStatus:@"请正确的手机号码"];
//        return;
//    }
    
//    NSLog(@"%@",[self getIdentityCardAge:tf_idNumber.text]);
//    NSString* sex = [self getIdentityCardAge:tf_idNumber.text];
//    NSString* age = [self getIdentityCardAge:tf_idNumber.text];
//
//    if ([sex isEqualToString:@"男"]) {
//        if (age < 18 || age > 58) {
//            [SVProgressHUD showErrorWithStatus:@"参保人年龄不符合参保要求"];
//            return;
//        }
//    }else if ([sex isEqualToString:@"女"]){
//       if (age < 18 || age > 48) {
//            [SVProgressHUD showErrorWithStatus:@"参保人年龄不符合参保要求"];
//            return;
//        }
//    }
    
    //[SVProgressHUD show];
    
    [self goToAuthVC];
   
}


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

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


            [weakSelf.imageManyImage removeAllObjects];

            if (originImage.count == 0) {


            }else{
                
                [weakSelf.imageManyImage addObject:originImage[0]];
                [weakSelf.imageManyImage addObject:originImage[originImage.count-3]];
                [weakSelf.imageManyImage addObject:originImage[originImage.count-2]];
                [weakSelf.imageManyImage addObject:originImage[originImage.count-1]];

//
                [weakSelf upLoadAllInfoWithImages:weakSelf.imageManyImage];

            }


            //finish

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


#pragma mark - private methods

#pragma mark - 压缩image并转成base64str
- (NSString *)getCompressImagebase64StrWithOriginalImage:(UIImage *)image
{
    UIImage* newImage = [UIImage imageWithImage:image scale:0.125];
    NSData*ImageData = UIImageJPEGRepresentation(newImage, 1.0);
    
    NSString*base64Str = [ImageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    
    return base64Str;
}

#pragma mark - 根据身份证获取年龄
-(NSString *)getIdentityCardAge:(NSString *)numberStr
{

NSDateFormatter *formatterTow = [[NSDateFormatter alloc]init];
[formatterTow setDateFormat:@"yyyy-mm-dd"];
NSDate *bsyDate = [formatterTow dateFromString:[self birthdayStrFromIdentityCard:numberStr]];

NSTimeInterval dateDiff = [bsyDate timeIntervalSinceNow];

int age = trunc(dateDiff/(60*60*24))/365;

return [NSString stringWithFormat:@"%d",-age];
}

#pragma mark - 根据身份证获取性别
/**

 *  从身份证上获取性别

 */

+ (NSString *)genderOfIDNumber:(NSString *)IDNumber
{
      //  记录校验结果：0未知，1男，2女
    NSInteger result = 0;
    NSString *sex = @"未知";
    NSString *fontNumer = nil;
    
    if (IDNumber.length == 15)
    { // 15位身份证号码：第15位代表性别，奇数为男，偶数为女。
        fontNumer = [IDNumber substringWithRange:NSMakeRange(14, 1)];
 
    }else if (IDNumber.length == 18)
    { // 18位身份证号码：第17位代表性别，奇数为男，偶数为女。
        fontNumer = [IDNumber substringWithRange:NSMakeRange(16, 1)];
    }else
    { //  不是15位也不是18位，则不是正常的身份证号码，直接返回
        return sex;
    }
    
    NSInteger genderNumber = [fontNumer integerValue];
    
    if(genderNumber % 2 == 1){
        result = 1;
           sex = @"男";
    }
    else if (genderNumber % 2 == 0){
        result = 2;
        sex = @"男";
    }
        
    return sex;
}
-(NSString *)birthdayStrFromIdentityCard:(NSString *)numberStr
{
    NSMutableString *result = [NSMutableString stringWithCapacity:0];
    NSString *year = nil;
    NSString *month = nil;
    
    BOOL isAllNumber = YES;
    
    NSString *day = nil;
    if([numberStr length]<14)
        return result;
    
    
    if (numberStr.length == 18) {
            //**截取前14位
            NSString *fontNumer = [numberStr substringWithRange:NSMakeRange(0, 13)];

            //**检测前14位否全都是数字;
            const char *str = [fontNumer UTF8String];
            const char *p = str;
            while (*p!='\0') {
                if(!(*p>='0'&&*p<='9'))
                    isAllNumber = NO;
                p++;
            }
            if(!isAllNumber)
                return result;

            year = [numberStr substringWithRange:NSMakeRange(6, 4)];
            month = [numberStr substringWithRange:NSMakeRange(10, 2)];
            day = [numberStr substringWithRange:NSMakeRange(12,2)];

            [result appendString:year];
            [result appendString:@"-"];
            [result appendString:month];
            [result appendString:@"-"];
            [result appendString:day];
            return result;
    }

    
    //**截取前12位
    NSString *fontNumer = [numberStr substringWithRange:NSMakeRange(0, 11)];
    
    //**检测前12位否全都是数字;
    const char *str = [fontNumer UTF8String];
    const char *p = str;
    while (*p!='\0') {
        if(!(*p>='0'&&*p<='9'))
            isAllNumber = NO;
        p++;
    }
    if(!isAllNumber)
        return result;
    
    
    year = [NSString stringWithFormat:@"19%@",[numberStr substringWithRange:NSMakeRange(6, 2)]];
    month = [numberStr substringWithRange:NSMakeRange(8, 2)];
    day = [numberStr substringWithRange:NSMakeRange(10,2)];
    
    
    [result appendString:year];
    [result appendString:@"-"];
    [result appendString:month];
    [result appendString:@"-"];
    [result appendString:day];
    return result;
    
}



#pragma mark - getters and setters
- (NSArray *)titleArray
{
    if (!_titleArray) {
        _titleArray = @[@[@"姓        名",@"民        族",@"身份证号",@"户籍地址"],@"手机号码"];
    }
    return _titleArray;
}
- (UIScrollView *)scrollview
{
    if (!_scrollview) {
        _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, SCREEN_WIDTH, ScreenHeight - cl_kNavigationBarHeight - 90)];
        _scrollview.contentSize = CGSizeMake(ScreenWidth, ScreenHeight+20* WIDTHRADIU);
        _scrollview.showsHorizontalScrollIndicator = NO;
        _scrollview.showsVerticalScrollIndicator = NO;
        [_scrollview addSubview:self.topView];
    }
    return _scrollview;
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - 90, ScreenWidth, 90)];
        
        UILabel *lb_message = [[UILabel alloc]init];
        lb_message.textColor = [UIColor colorWithHex:0xc0c0c0];
        lb_message.font = [UIFont systemFontOfSize:12];
        lb_message.textAlignment= NSTextAlignmentCenter;
        lb_message.text = @"请确认身份信息，如有误请重拍或手动修改\n您的信息仅供申请合伙人实名认证用";
        lb_message.numberOfLines = 0;
        
          //富文本设置文字行间距
            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
            paragraphStyle.lineSpacing = 4;
            paragraphStyle.alignment = NSTextAlignmentCenter;
            
            NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName: [UIColor colorWithHex:0xc0c0c0], NSParagraphStyleAttributeName:paragraphStyle};
            lb_message.attributedText = [[NSAttributedString alloc]initWithString:lb_message.text attributes:attributes];
            
       
        
        
        
        
        
        [_bottomView addSubview:lb_message];
        
        
        [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(0);
            make.centerX.width.equalTo(self->_bottomView);
        }];
        
        UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        nextBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        nextBtn.frame =CGRectMake(0, 45, ScreenWidth, 45);
        nextBtn.backgroundColor = K_MainColor;
        [nextBtn addTarget:self action:@selector(commitPayUserInfoClick:) forControlEvents:UIControlEventTouchUpInside];
        [_bottomView addSubview:nextBtn];
    }
    return _bottomView;
}

- (UITableView *)tableView
{
    if (!_tableView ) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight - 45 * WIDTHRADIU) style:UITableViewStyleGrouped];
        _tableView.showsHorizontalScrollIndicator = YES;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.tableHeaderView = self.topView;
        _tableView.backgroundColor = [UIColor colorWithHex:0xf5f5f5];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[InsuredMemberAddTableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
}

- (UIView *)topView
{
    if (!_topView) {
        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;
         _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 37 *WIDTHRADIU + height)];
        
        _topView.backgroundColor = [UIColor whiteColor];
        [_topView addSubview:self.topBackView];
        [_topBackView addSubview:self.lb_title];
        [_topView addSubview:self.leftView];
        [_topView addSubview:self.rightView];
        
        
    }
    return _topView;
}

- (UIView *)topBackView
{
    if (!_topBackView) {
        
        _topBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 135 * WIDTHRADIU)];

        
        _topBackView.backgroundColor = K_MainColor;
        
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)[UIColor whiteColor].CGColor, (__bridge id)[UIColor colorWithHex:0xe8f3fb].CGColor];
        gradientLayer.locations = @[@0.0, @1.0];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(0, 1);
        gradientLayer.frame = _topBackView.bounds;
        [_topBackView.layer addSublayer:gradientLayer];
       
    }
    return _topBackView;
}

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

- (UIImageView *)img_message
{
    if (!_img_message) {
        _img_message = [[UIImageView alloc]init];
        _img_message.image = [UIImage imageNamed:@"insuredInfoModify_messageIcon"];
    }
    return _img_message;
}

- (UILabel *)lb_message
{
    if (!_lb_message) {
        _lb_message = [[UILabel alloc]init];
        _lb_message.text = @"仅支持修改身份证照,修改个人信息请联系客服";
        _lb_message.textColor = [UIColor whiteColor];
        _lb_message.font = [UIFont systemFontOfSize:13];
        _lb_message.numberOfLines = 0;
    }
    return _lb_message;
}

- (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.lb_uploadTitle];
        [_leftView addSubview:self.btn_left];
        [_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];
        [_leftBtn addTarget:self action:@selector(IdClick:) 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];
        [_rightBtn addTarget:self action:@selector(IdClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}
/*
#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
