//
//  InsuredMemberAddViewController.m
//  Open
//
//  Created by 雷俊博 on 2019/8/5.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "InsuredMemberAddViewController.h"

#import <IQKeyboardManager.h>


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

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

#import "InsuredMemberAddTableViewCell.h"

#import "InsuredInfoController.h"


@interface InsuredMemberAddViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UITextViewDelegate,SCNavigationControllerDelegate>
{
    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;
    
    BOOL  _keyboardIsVisible;
    
}

@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;//记录将要编辑的输入框



@end

@implementation InsuredMemberAddViewController
#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    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);
    

    
    if (self.type == CTUPLoadInfoTypeModify) {
        tf_name.text = self.model.user_name;
        tf_nation.text = self.model.nation;
        tf_idNumber.text = self.model.id_card;
        tf_phone.text = self.model.phone;
        tv_address.text = self.model.hk_address;
        [tv_address.delegate textViewShouldBeginEditing:tv_address];
        [tv_address.delegate textViewDidChange:tv_address];
        tf_name.textColor = [UIColor colorWithHex:0x808080];
        tf_nation.textColor = [UIColor colorWithHex:0x808080];
        tf_idNumber.textColor = [UIColor colorWithHex:0x808080];
        tf_phone.textColor = [UIColor colorWithHex:0x808080];
        tv_address.textColor = [UIColor colorWithHex:0x808080];
        
        tf_name.userInteractionEnabled = NO;
         tf_nation.userInteractionEnabled = NO;
         tf_idNumber.userInteractionEnabled = NO;
         tf_phone.userInteractionEnabled = NO;
         tv_address.userInteractionEnabled = NO;
    
//            [self.scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
    }
    
    _keyboardIsVisible = NO;
    

}


- (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;
    if ([self.title isEqualToString:@"参保人信息"]) {
        [GTCountSDK trackCountEvent:@"home_shebaojiafei_addPeople" withArgs:@{}];
    }else if ([self.title isEqualToString:@"信息修改"]) {
        [GTCountSDK trackCountEvent:@"home_shebaojiaofei_infoModify" withArgs:@{}];
    }
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    
}

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


#pragma mark : UIKeyboardWillShowNotification/UIKeyboardWillHideNotification
- (void)keyboardWillShow:(NSNotification *)notification
{
    _keyboardIsVisible = YES;
    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{
    _keyboardIsVisible = NO;
    
    [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);
    }];
    
    if (self.type == CTUPLoadInfoTypeModify) {
        [self.img_message mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lb_title);
            make.top.equalTo(self.lb_title.mas_bottom).offset(10 * WIDTHRADIU);
            make.width.height.offset(12 * WIDTHRADIU);
        }];
        
        [self.lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.img_message.mas_top).offset(-3);
            make.left.equalTo(self.img_message.mas_right).offset(3);
            make.right.offset(-10 * 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;
    
    if (self.type == CTUPLoadInfoTypeModify) {
        
            [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(leftMargin);
                make.top.offset(60 * WIDTHRADIU);
                make.width.offset(width);
                make.height.offset(height);
            }];

        
    }else{
        [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];
    }
    
   
    
    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 *)upLoadCardImageRequestPara:(BOOL)isLeft
{
    NSDictionary *para = @{
        @"key":[PayUserInfoManager sharedManager].model.key,
        @"id_card":tf_idNumber.text,
        @"pos":isLeft ? @(0) :@(1)
    };
    return para;
}

- (void)upLoadCardImageRequest:(BOOL)isLeft resultBlock:(void (^)(bool success,NSString* imageName))result
{
    WeakSelf
    NSString *urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipMySocialInsuranceConfig],UpLoadCardImageRequest];
    NSLog(@"上传身份证图片url:%@",urlString);
    NSLog(@"params:%@",[self upLoadCardImageRequestPara:isLeft]);
    NSData* imageData = nil;
    if (isLeft) {
        imageData = UIImageJPEGRepresentation(cardFrontImg, 1);
    }else{
        imageData = UIImageJPEGRepresentation(cardBackImg, 1);
    }
    NSString* imageFormat = @"jpg";
    NSString* imageName = @"file1";
    
    NSLog(@"图片大小:%lukb",imageData.length/1024);
    
   
    
    [NetworkRequest uploadImage:urlString Params:[self upLoadCardImageRequestPara:isLeft] Image:imageData ImageName:[NSString stringWithFormat:@"%@.%@",imageName,imageFormat] ImageParam:imageName Success:^(id _Nonnull responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString *code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            if ([code isEqualToString:@"200"]) {
                NSString*data = responseObject[@"data"];
                if ([data isKindOfClass:[NSString class]] && ![NSString blankString:data]) {
                     result(YES,data);
                }else{
                     result(NO,nil);
                }
               
            }else if ([code isEqualToString:@"601"] || [code isEqualToString:@"10004"]){
                
                [NetworkTokenRequest getTokenSuccess:^(BOOL success) {
                    if (success) {
                        [weakSelf upLoadCardImageRequest:isLeft resultBlock:result];
                    }else{
                        result(NO,nil);
                    }
                }];
                
                
            }else{
                result(NO,nil);
            }
        }else{
            result(NO,nil);
        }
        
    } Failure:^(NSError* error) {
        NSLog(@"error:%@",error);
        result(NO,nil);
    }];
}

- (NSDictionary *)uploadInsuredMemberInfoRequestParam:(NSString *)imageName1 image2:(NSString *)imageName2
{
    NSDictionary *para = @{
        @"key":[PayUserInfoManager sharedManager].model.key ?[PayUserInfoManager sharedManager].model.key:@"" ,
        @"id_card":tf_idNumber.text ? tf_idNumber.text :@"",
        @"user_name":tf_name.text ? tf_name.text :@"",
        @"nation":tf_nation.text? tf_nation.text :@"",
        @"gender":@([Tools genderOfIDNumber:tf_idNumber.text]),
        @"phone":tf_phone.text? tf_phone.text :@"",
        @"id_card_img":imageName1,
        @"id_card_img1":imageName2
    };
    
    return para;
}

- (void)uploadInsuredMemberInfoRequest:(NSString *)imageName1 image2:(NSString *)imageName2 resultBlock:(void (^)(bool success,NSDictionary* data))result
{
    
    WeakSelf
    NSString* urlString = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipMySocialInsuranceConfig],UpLoadOrModifyInsuredMemberInfoRequest];
    NSLog(@"上传或修改参保信息url:%@",urlString);
    NSLog(@"para:%@",[self uploadInsuredMemberInfoRequestParam:imageName1 image2:imageName2]);

                       
    [NetworkRequest Post:urlString Params:[self uploadInsuredMemberInfoRequestParam:imageName1 image2:imageName2] Success:^(id _Nonnull reponseObject) {
        
        NSLog(@"reponseObject:%@",reponseObject);
        if ([reponseObject isKindOfClass:[NSDictionary class]]) {
            NSString* code = [NSString stringWithFormat:@"%@",reponseObject[@"code"]];
            if ([code isEqualToString:@"200"]) {
                result(YES,reponseObject[@"data"]);
            }else if ([code isEqualToString:@"601"] || [code isEqualToString:@"10004"]){
                
                [NetworkTokenRequest getTokenSuccess:^(BOOL success) {
                    if (success) {
                        [weakSelf uploadInsuredMemberInfoRequest:imageName1 image2:imageName2 resultBlock:result];
                    }else{
                        result(NO,nil);
                    }
                }];
                
                
            }else{
                 result(NO,nil);
            }
        }else{
            result(NO,nil);
        }
                           
        } Failure:^(NSError* error) {
          
        NSLog(@"error:%@",error);
            result(NO,nil);
            
    }];
    
    
    

    
}

- (void)uploadAllInfo:(void (^)(bool success,NSDictionary* data))result
{
        WeakSelf
        [self upLoadCardImageRequest:YES resultBlock:^(bool success, NSString *imageName) {
            if (success) {
                
                
                
                [weakSelf upLoadCardImageRequest:NO resultBlock:^(bool success, NSString *imageName2) {
                    if (success) {
                        
                        
    
                        [weakSelf uploadInsuredMemberInfoRequest:imageName image2:imageName2 resultBlock:^(bool success, NSDictionary *data) {
                            result(success,data);
                            
                        }];
    
    
    
    
                    }else{
                      result(NO,nil);
                    }
                }];
            }else{
              result(NO,nil);
            }
        }];
}




#pragma mark - SCNavigationControllerDelegate
- (void)sendIDCValue:(NSString *)name SEX:(NSString *)sex FOLK:(NSString *)folk BIRTHDAY:(NSString *)birthday ADDRESS:(NSString *) address NUM:(NSString *)num
{
    if (self.type == CTUPLoadInfoTypeNew) {
        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
{
          [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 = 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 (self.scrollview.contentOffset.y != self.topView.maxY && _keyboardIsVisible) {
        [self.scrollview setContentOffset:CGPointMake(0, self.topView.maxY) animated:YES];
    }
    
    return YES;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
            
    
    return YES;
}
- (void)textViewDidChange:(UITextView *)textView
{
    
    [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 = 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 (self.scrollview.contentOffset.y != self.topView.maxY && _keyboardIsVisible) {
           [self.scrollview setContentOffset:CGPointMake(0, self.topView.maxY) animated:YES];
       }
    
    if (!textView.text.length){
        lb_address.alpha = 1;
    }else{
        lb_address.alpha = 0;
    }
}

- (void)textChangedExt:(NSNotification *)notification
{
               [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 - 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 (self.type == CTUPLoadInfoTypeNew) {
        if (![Tools isChinese:tf_name.text] || 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 uploadAllInfo:^(bool success, NSDictionary *data) {
        [SVProgressHUD dismiss];
        
        
        if (self.type == CTUPLoadInfoTypeModify) {
            [self.navigationController popViewControllerAnimated:YES];
        }else if (self.type == CTUPLoadInfoTypeNew){
            SocialInsurancePayUserListModel*model = [SocialInsurancePayUserListModel new];
            model.Id = [NSString stringWithFormat:@"%@",data[@"id"]].integerValue;
            model.user_name = self->tf_name.text;
            model.id_card = self->tf_idNumber.text;
           
            
            InsuredInfoController* vc = [[InsuredInfoController alloc]init];
            vc.title = @"参保信息";
            vc.model = self.sbmodel;
            vc.selectCity_code = self.selectCity_code;
            vc.selectCityName = self.selectCityName;
            vc.hukou_type = self.hukou_type;
            vc.hukou = self.hukou;
            vc.payUserModel = model;
            vc.citys = self.citys;
            vc.wModel = self.wModel;
            
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }];
    
}


#pragma mark - private methods
#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, 0, SCREEN_WIDTH, ScreenHeight - cl_kNavigationBarHeight - 60)];
        _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-cl_kNavigationBarHeight - 60, ScreenWidth, 60)];
        
        UILabel *lb_message = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 12)];
        lb_message.textColor = [UIColor colorWithHex:0xc0c0c0];
        lb_message.font = [UIFont systemFontOfSize:12];
        lb_message.textAlignment= NSTextAlignmentCenter;
        lb_message.numberOfLines = 0;
        lb_message.text = @"请确认身份信息，如有误请重拍或手动修改";
        [_bottomView addSubview:lb_message];
        
        UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        if (self.type == CTUPLoadInfoTypeModify) {
            [nextBtn setTitle:@"保存修改" forState:UIControlStateNormal];
        }else{
            [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        }
        [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        nextBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        nextBtn.frame =CGRectMake(0, 15, 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;
        if (self.type == CTUPLoadInfoTypeModify){
            
                _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64 *WIDTHRADIU + height)];
           
        }else{
            _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];
        if (self.type == CTUPLoadInfoTypeModify) {
            [_topBackView addSubview:self.img_message];
            [_topBackView addSubview:self.lb_message];
        }
        [_topView addSubview:self.leftView];
        [_topView addSubview:self.rightView];
        
        
    }
    return _topView;
}

- (UIView *)topBackView
{
    if (!_topBackView) {
        if (self.type == CTUPLoadInfoTypeModify) {
            
                 _topBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 162 * WIDTHRADIU)];
         
        }else{
            _topBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 135 * WIDTHRADIU)];
        }
        
        _topBackView.backgroundColor = K_MainColor;
       
    }
    return _topBackView;
}

- (UILabel *)lb_title
{
    if (!_lb_title) {
        _lb_title = [[UILabel alloc]init];
        _lb_title.text = @"拍摄身份证";
        _lb_title.textColor = [UIColor whiteColor];
        _lb_title.font = [UIFont systemFontOfSize: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
