//
//  InsuredInfoViewController.m
//  Open
//
//  Created by 雷俊博 on 2020/3/19.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "InsuredInfoViewController.h"
#import <IQKeyboardManager.h>
#import "AuthenticationGuideView.h"
#import "GreenChannelAlertView.h"

#import "GreenChannelVC.h"
#import "successViewController.h"
#import "MyPickerViewController.h"
#import "SocialSecurityVerificationFailureViewController.h"
#import "UIView+frameAdjust.h"

#import "KKSocialAuthSuccessController.h"

#import "FaceImageModel.h"
#import "TestViewController.h"


@interface InsuredInfoViewController ()<UITextFieldDelegate,UIScrollViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,passImagesDelegate>
{
    BOOL isLocationing;
}

@property (nonatomic, strong)UIScrollView* scrollView;

@property (nonatomic, strong)UIImageView *img_back;//背景

@property (nonatomic, strong)UIView* contentView;
@property (nonatomic, strong)UIView* contentView2;

@property (nonatomic, strong)UIView* leftLine;//左划线

@property (nonatomic, strong)UIView* rightLine;//右划线

@property (nonatomic, strong)UILabel* lb_middleMessage;//中间message

@property (nonatomic, strong)UIButton* btn_green;//绿色通道按钮

@property (nonatomic, strong)UIButton* btn_next;//下一步按钮

@property (nonatomic, strong)UILabel* lb_locationState;//定位状态判断

@property (nonatomic, strong)UIImageView* img_location;

@property (nonatomic, strong)UILabel* lb_location;//定位地址

@property (nonatomic, strong)UILabel* lb_insureTitle;//参保title

@property (nonatomic, strong)UIView* sepLine;//分割线

@property (nonatomic, strong)UILabel* lb_insuredType;//参保类型

@property (nonatomic, strong)UILabel* lb_insuredTypeContent;


@property (nonatomic, strong)UILabel* lb_insuredAddress;//参保地址

@property (nonatomic, strong)UILabel* lb_insuredAddressContent;

@property (nonatomic, strong)UILabel* lb_phoneTitle;//联系电话

@property (nonatomic, strong)UITextField* tf_phone;

@property (nonatomic, strong)UIButton* Btn_edit;


@property(nonatomic,strong)NSMutableArray *imageManyImage;

@property(nonatomic,strong)     NSString *city;
@property(nonatomic,strong)     NSString *province;
@property(nonatomic,strong)     NSString *county;


@property (nonatomic, assign)BOOL hiddenGreenBtn;//

@end

@implementation InsuredInfoViewController
#pragma mark - life cycle
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    //TODO: 页面appear 禁用
   [[IQKeyboardManager sharedManager] setEnable:NO];
    //禁止手势返回
    id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
    [self.view addGestureRecognizer:pan];
    
    [GTCountSDK trackCountEvent:@"home_SBAuth_insuranceInfoPage" withArgs:@{}];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    //TODO: 页面Disappear 启用
   [[IQKeyboardManager sharedManager] setEnable:YES];
    
    // 开启返回手势
   if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
       self.navigationController.interactivePopGestureRecognizer.enabled = YES;
   }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =   [UIColor whiteColor];
    
    [self.view addSubview:self.scrollView];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    [self configUI];
    [self configUIData];
    [self configBackBtn];
    
    self.province = [NSString validBlankStr:self.paramSModel.provinceName];
    self.city = [NSString validBlankStr:self.paramSModel.cityName];
    self.county = [NSString validBlankStr:self.paramSModel.countryName];
    
    
    
    [self hiddenGreenBtnRequest];
    
}

- (void)configUI
{
    
    
    if (![self CanShowOnOneScreen]) {
        [self.view  addSubview:self.contentView2];
        [self.view addSubview:self.contentView];
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.top.equalTo(self.scrollView.mas_bottom).offset(10 * WIDTHRADIU);
           make.width.equalTo(self.scrollView);
           make.height.offset(17 * WIDTHRADIU);
        }];
        [self.contentView2 mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.contentView.mas_bottom).offset(10 * WIDTHRADIU);
               make.width.equalTo(self.scrollView);
               make.height.offset(45 * WIDTHRADIU);
           }];
    }
    
        
    
    
   
    
    
    UITapGestureRecognizer*tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClcik:)];
    [self.img_location addGestureRecognizer:tap];
    UITapGestureRecognizer*tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClcik:)];
    [self.lb_location addGestureRecognizer:tap1];
}
- (void)configUIData
{
    //参保类型
    NSInteger cityType =(NSInteger)self.paramSModel.verify_type;
           if (cityType) {
               switch (cityType) {
                   case 1:
                       self.lb_insuredTypeContent.text =@"机关事业";
                       break;
                   case 2:
                       self.lb_insuredTypeContent.text =@"企业员工";
                       break;
                   default:
                       self.lb_insuredTypeContent.text =@"城镇居民";
                       break;
               }
           }
    //参保地址
    self.lb_insuredAddressContent.text = [NSString stringWithFormat:@"%@%@%@%@%@%@",[NSString validBlankStr:self.paramSModel.provinceName],[NSString validBlankStr:self.paramSModel.cityName],[NSString validBlankStr:self.paramSModel.countryName],[NSString validBlankStr:self.paramSModel.townName],[NSString validBlankStr:self.paramSModel.villageName],[NSString validBlankStr:self.paramSModel.companyName]];
    
    
    //参保人电话
    if (![NSString blankString:self.paramSModel.telphoneValue] ) {
        self.tf_phone.text =  [EnercryTool decryptUseDES:self.paramSModel.telphoneValue key:DESKEY];
        self.tf_phone.userInteractionEnabled = NO;
        [self.tf_phone resignFirstResponder];
        [self.Btn_edit setTitle:@"修改" forState:UIControlStateNormal];
        self.Btn_edit.selected = YES;
        
       }else{
           self.tf_phone.text =@"";
           [self.tf_phone becomeFirstResponder];
           [self.Btn_edit setTitle:@"保存" forState:UIControlStateNormal];
           self.tf_phone.userInteractionEnabled = YES;
           self.Btn_edit.selected = NO;
    }
    
    //定位地址
    
    [self locationAddress];
    
    
    
    
    
}

#pragma mark - 导航栏返回按钮及点击事件
- (void)configBackBtn
{
    UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backbtn.frame = CGRectMake(-50, 0, 40, 40);
    [backbtn setTitle:@"返回" forState:UIControlStateNormal];
    [backbtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backbtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    [backbtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:6];

    

    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:backbtn];

    self.navigationItem.leftBarButtonItem = backItem;
    
 
}




#pragma mark - 定位
- (void)locationAddress
{
    
    if (isLocationing) {
        return;
    }
    
     isLocationing = YES;
    //定位地址
       [[XWLocationManager sharedXWLocationManager] getCurrentLocation:^(CLLocation *location, CLPlacemark *placeMark, NSString *error) {
           if (error) {
               self->isLocationing =NO;
               self.lb_locationState.text = @"本地-国内";
                self.lb_location.text = [NSString stringWithFormat:@"%@%@%@",[NSString validBlankStr:self.paramSModel.provinceName],[NSString validBlankStr:self.paramSModel.cityName],[NSString validBlankStr:self.paramSModel.countryName]];
               NSLog(@"定位出错,错误信息:%@",error);
           }else{
               self->isLocationing =NO;
               NSLog(@"定位成功:经度:%f 纬度:%lf 当前地址:%@  \n location详细信息:%@ \n ",location.coordinate.latitude, location.coordinate.longitude, placeMark.name, location);

               
               NSDictionary *addressDic = placeMark.addressDictionary;
               NSString *state=[addressDic objectForKey:@"State"];
               NSString *city=[addressDic objectForKey:@"City"];
               NSString *subLocality=[addressDic objectForKey:@"SubLocality"];
               NSString *street=[addressDic objectForKey:@"Street"];
               self.lb_location.text = [NSString stringWithFormat:@"%@%@%@%@",[NSString validBlankStr:state],[NSString validBlankStr:city],[NSString validBlankStr:subLocality],[NSString validBlankStr:street]];
               
               
               NSString *strNew =@"";
              if([self.paramSModel.provinceName isEqualToString:@"上海市"] || [self.paramSModel.provinceName  isEqualToString:@"北京市"] || [self.paramSModel.provinceName  isEqualToString:@"天津市"] || [self.paramSModel.provinceName  isEqualToString:@"重庆市"]){
                         strNew = self.paramSModel.provinceName;
                    }else{
                         strNew = self.paramSModel.cityName;
               }
               
               if ([city isEqualToString:strNew]) {
                   self.lb_locationState.text = @"本地-国内";
               }else{
                   self.lb_locationState.text = @"异地-国内";
               }
               
          
               

           }
       } onViewController:self];
}

#pragma mark - 关闭键盘补偿视图
/** 关闭键盘补偿视图 */
- (void)closeKeyboardOffsetView
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

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

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"偏移量y:%f",scrollView.contentOffset.y);
}


#pragma mark - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   
    //完成选择
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"]) {
        __block UIImage *flippedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        if (flippedImage == nil) {
            [SVProgressHUD showErrorWithStatus:@"请在设置中打开照片访问权限"];
            return;
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [picker dismissViewControllerAnimated:YES completion:^{
                
                //雷俊博
                GreenChannelVC *vc = [[GreenChannelVC alloc]init];
                vc.title = @"绿色通道";
                vc.lastVCImage = flippedImage;
                vc.state = GreenRenZheng;
                vc.ValidationName = self.ValidationName;
                vc.ValidationIdNumber = self.ValidationIdNumber;
                vc.bak = self.bak;
                vc.province =self.province;
                vc.city =self.city;
                vc.county =self.county;

                [self.navigationController pushViewController:vc animated:YES];
            }];
        });
    }
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
     [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - passImagesDelegate
- (void)passImages:(NSArray *)imagesArray {
    
    //[SVProgressHUD showSuccessWithStatus:@"人脸识别成功"];
    NSLog(@"回调一次");
    
//    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];
        

     }
    
//    TestViewController *testVC = [TestViewController new];
//    testVC.title = @"查看图片";
//    testVC.originImage = originImage;
//
//    [self.navigationController pushViewController:testVC animated:YES];
    
    
    [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 uploadImagesRequest:originImage[0]];
        

}

- (void)passFail {
    
}


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

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

#pragma mark - 隐藏绿色通道按钮
- (void)hiddenGreenBtnRequest
{
    NSString *url = [NSString stringWithFormat:@"%@socialsecurity/display/isCerGreenChannelShow",[NetworkConfig ipKKSBConfig]];
    
    NSString *provinceName = [Tools isBlankString:self.paramSModel.provinceName] ? @"" :  self.paramSModel.provinceName;
    NSString *cityName = [Tools isBlankString:self.paramSModel.cityName] ? @"" : self.paramSModel.cityName;
    NSString *countyName = [Tools isBlankString:self.paramSModel.countryName] ? @"" : self.paramSModel.countryName;
    
    NSDictionary *params = @{
        @"provinceName": provinceName,
        @"cityName": cityName,
        @"countryName": countyName,
        @"verifyType": @(self.paramSModel.verify_type),
        @"fromApp": @"kksh"
    };
    
    [NetworkRequest SBAuthPost:url Params:params Success:^(id _Nonnull objectC) {
        
        NSLog(@"objectC:%@",objectC);
        if ([objectC isKindOfClass:[NSDictionary class]]) {
            NSString *code = [NSString stringWithFormat:@"%@",objectC[@"code"]];
            if ([code isEqualToString:@"1202"]) {
                self.hiddenGreenBtn = YES;
                [self refreshBtnsLayout];
            }else{
                
            }
        }
        
        
    } Failure:^(NSError* error) {
        
        NSLog(@"error:%@",error);
        
    }];
}



#pragma mark - 更新认证状态API

- (NSDictionary *)updateAuthStateRequestPara
{

    if ([self.lb_location.text isEqualToString:@"请定位您的地址"]) {
         self.lb_location.text = [NSString stringWithFormat:@"%@%@%@",[NSString validBlankStr:self.paramSModel.provinceName],[NSString validBlankStr:self.paramSModel.cityName],[NSString validBlankStr:self.paramSModel.countryName]];
    }
    
    NSString *sign = [NSString stringWithFormat:@"identityNumber=%@&name=%@&KkweInfo",[EnercryTool A:[NSString validBlankStr:self.ValidationIdNumber]],[EnercryTool A:[NSString validBlankStr:self.ValidationName]]];
    sign =  [MyMD5 md5:sign];
    
    NSDictionary *params = @{
       @"flag":@2,
       @"id":[NSString validBlankStr:self.bak],
       @"name":[EnercryTool A:[NSString validBlankStr:self.ValidationName]],
       @"identityNumber":[EnercryTool A:[NSString validBlankStr:self.ValidationIdNumber]],
       @"address_relation":[self.lb_locationState.text isEqualToString:@"本地-国内"] ?@0 :@1,
       @"now_address":[EnercryTool encryptUseDES:self.lb_location.text key:DESKEY],
       @"phone_number":[EnercryTool encryptUseDES:self.tf_phone.text key:DESKEY],
       @"sign":sign
    };
    return params;
}
- (void)updateAuthStateRequest:(NSInteger)index
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipKKSBConfig],upDateRZStateRequest];
    if (@available(iOS 9,*)) {
        url =  [url  stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }else{
        url =  [url  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    
    NSLog(@"更新认证状态url:%@",url);
    NSLog(@"params:%@",[self updateAuthStateRequestPara]);
    
    WeakSelf
    
    [[NSUserDefaults standardUserDefaults]setValue:self.lb_location.text forKey:@"gdfdsgdfght"];
    
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post2:url Params:[self updateAuthStateRequestPara] Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString* code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            if ([code isEqualToString:@"0"]) {
                if (index == 200) {
                    [weakSelf showGreenChannel];
                }else if (index == 201){
                    [weakSelf goToAuthVC];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"服务器繁忙,请稍后重试!"];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器繁忙,请稍后重试!"];
        }
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常,请稍后重试!"];
    }];
    
    
    
    
}

- (void)update2AuthStateRequest:(NSInteger)index {
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipKKSBConfig],upDateRZStateRequest];
    if (@available(iOS 9,*)) {
        url =  [url  stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }else{
        url =  [url  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    
    NSLog(@"更新认证状态url:%@",url);
    NSLog(@"params:%@",[self updateAuthStateRequestPara]);
    
    WeakSelf
    
    [[NSUserDefaults standardUserDefaults]setValue:self.lb_location.text forKey:@"gdfdsgdfght"];
    
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    [KKLoadingAnimationView show];
    [NetworkRequest SBAuthPost:url Params:[self updateAuthStateRequestPara] Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString* code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            if ([code isEqualToString:@"0"]) {
                if (index == 200) {
                    [weakSelf showGreenChannel];
                }else if (index == 201){
                    [weakSelf goToAuthVC];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"服务器繁忙,请稍后重试!"];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器繁忙,请稍后重试!"];
        }
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常,请稍后重试!"];
    }];
}


#pragma mark - 上传图片api
- (NSDictionary *)uploadImagesRequestParam:(UIImage *)selfImage
{
    
//    NSDictionary *dictNew =@{
//                                 @"flag":@2,
//                                 @"id":ID,
//                                 @"name":[EnercryTool A:name],
//                                 @"identityNumber":[EnercryTool A:identityNumber],
//                                 @"image":[EnercryTool encryptBase64:imageData],
//                                 @"sign":str1,
//                                 @"versionflag":@1,
//    //                             @"phoneNumber":telPhone,
//                                 @"photoLstr":senderPic//1周 照片一逗号的形式隔开
//                                 };
    NSString *sign = [NSString stringWithFormat:@"identityNumber=%@&name=%@&KkweInfo",[EnercryTool A:[NSString validBlankStr:self.ValidationIdNumber]],[EnercryTool A:[NSString validBlankStr:self.ValidationName]]];
       sign =  [MyMD5 md5:sign];
     selfImage=  [JobUtil imagehuangzhuan:selfImage rotation:UIImageOrientationLeft];
    
    NSArray *dataArray =@[ [self imageChangeType:selfImage],
                           [self imageChangeType:self.imageManyImage[1]],
                           [self imageChangeType:self.imageManyImage[2]],
                           [self imageChangeType:self.imageManyImage[3]]];
    //        self.baocun removeObject: = [self.baocun valueForKeyPath:@"@distinctUnionOfObjects.self"];
    
    NSMutableArray*baocun = [NSMutableArray array];
    for (NSString *str in dataArray) {
        if (![baocun containsObject:str]) {
            [baocun addObject:str];
        }else{
            if ([baocun containsObject:str]) {
                [baocun removeObject:str];
                continue;
            }
        }
    }
    
    NSString *senderPic =@"";
    if (baocun.count <1) {
        senderPic =[NSNull null];
    }else{
        senderPic =[baocun componentsJoinedByString:@","];
    }
    
    NSDictionary *params = @{
        @"flag":@2,
        @"id":[NSString validBlankStr:self.bak],
        @"name":[EnercryTool A:[NSString validBlankStr:self.ValidationName]],
        @"identityNumber":[EnercryTool A:[NSString validBlankStr:self.ValidationIdNumber]],
        @"image":[self imageChangeType:selfImage],
        @"sign":sign,
        @"versionflag":@1,
        @"photoLstr":senderPic
    };
    return params;
}
- (void)uploadImagesRequest:(UIImage *)selfImage
{
    WeakSelf
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipKKSBConfig],verifyPhotoRequest];
    if (@available(iOS 9,*)) {
        url =  [url  stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    }else{
        url =  [url  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    
    NSLog(@"活体检测上传图片url:%@",url);
    NSLog(@"params:%@",[self uploadImagesRequestParam:selfImage]);
    [KKLoadingAnimationView show];
    [NetworkRequest SBAuthPost:url Params:[self uploadImagesRequestParam:selfImage] Success:^(id _Nonnull responseObject) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"responseObject:%@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSString* code = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
            if ([code isEqualToString:@"0"]) {
                UIImage*image2 = nil;
                if ([responseObject[@"result"] isKindOfClass:[NSString class]]) {
                    if (![NSString blankString:responseObject[@"result"]]) {
                        NSData *dataBase64 =[[NSData alloc]initWithBase64EncodedString:responseObject[@"result"] options:0];
                        UIImage *image = [UIImage imageWithData:dataBase64];
                        image2 = image;
                    }
                }
                
                
                [weakSelf JumpToRZSuccessVCWithImage1:selfImage image2:image2];
                
                if (weakSelf.ValidationName) {
                    NSDictionary *ValidationDic = @{@"ValidationName":weakSelf.ValidationName};
                    [[NSUserDefaults standardUserDefaults]setObject:ValidationDic forKey:@"ValidationDic"];
                    [[NSUserDefaults standardUserDefaults]synchronize];
                    [getPeopleID getprovinceNightSix:weakSelf.province];
                }
            }else{
                [weakSelf JumpToRZFailVCWithCode:code.integerValue];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"服务器繁忙,请稍后重试!"];
        }
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [SVProgressHUD showErrorWithStatus:@"网络异常,请稍后重试!"];
    }];
}

#pragma mark - 跳转到successView
- (void)JumpToRZSuccessVCWithImage1:(UIImage *)image1 image2:(UIImage *)image2
{
    [getPeopleID socialSate:1];
    //[[NSNotificationCenter defaultCenter] postNotificationName:@"ZLAuthenticationAssistant" object:nil userInfo:nil];
    
        KKSocialAuthSuccessController *blueVC = [KKSocialAuthSuccessController new];
        blueVC.imageView1 = image1;
        blueVC.imageView2 = image2;
        blueVC.province =self.province;
        blueVC.city =self.city;
        blueVC.county =self.county;
        blueVC.name = self.ValidationName;
        blueVC.idNumber = self.ValidationIdNumber;
        blueVC.bak = self.bak;
    
        [self.navigationController pushViewController:blueVC animated:YES];
   
//    successViewController *blueVC = [MainBoard instantiateViewControllerWithIdentifier:@"successViewController"];
//    blueVC.imageView1 = image1;
//    blueVC.imageView2 = image2;
//    blueVC.province =self.province;
//    blueVC.city =self.city;
//    blueVC.county =self.county;
//    blueVC.name = self.ValidationName;
//    blueVC.idNumber = self.ValidationIdNumber;
//    blueVC.bak = self.bak;
//
//    [self.navigationController pushViewController:blueVC animated:YES];
}

- (void)JumpToRZFailVCWithCode:(NSInteger)code
{
    
    SocialSecurityVerificationFailureViewController*vc = [[SocialSecurityVerificationFailureViewController alloc]init];
    vc.title =@"照片选取";
    vc.arrayImages = self.imageManyImage;
    vc.province =self.province;
    vc.city =self.city;
    vc.county =self.county;
    vc.telPhone =self.tf_phone.text;
    vc.modelCode = code;
    vc.ValidationName = self.ValidationName;
    vc.ValidationIdNumber = self.ValidationIdNumber;
    vc.bak = self.bak;
   

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

    return;
    
    UIStoryboard *sb  =[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    MyPickerViewController *picker =[sb instantiateViewControllerWithIdentifier:@"MyPickerViewController"];
    picker.arrayImages =self.imageManyImage;
    picker.province =self.province;
    picker.city =self.city;
    picker.county =self.county;
    picker.telPhone =self.tf_phone.text;
    picker.modelCode = code;
    //self.modelCode =model.code;
   
    picker.greenValues =@"";
    
   
   [self.navigationController pushViewController:picker animated:YES];
}


#pragma mark - event response
- (void)tapClcik:(UITapGestureRecognizer *)tap
{
    [self locationAddress];
}
- (void)goToGreenChannelVC:(UIButton *)sender
{
//     WeakSelf
    
    if (self.tf_phone.text.length == 0) {
        [SVProgressHUD showErrorWithStatus:@"请填写手机号"];
        
        return;
    }
    
    if (![Tools isMobileNumber:self.tf_phone.text]) {
        return [SVProgressHUD showErrorWithStatus:@"手机号码错误"];
        
    }
    
    if (self.Btn_edit.selected == NO) {
        [SVProgressHUD showInfoWithStatus:@"请保存修改信息"];
        return;
    }
    
    [self update2AuthStateRequest:200];
    
    return;

}

- (void)goToNextVC:(UIButton *)sender
{
    
   if (self.tf_phone.text.length == 0) {
          [SVProgressHUD showErrorWithStatus:@"请填写手机号"];
       return;
      }
      
      if (![Tools isMobileNumber:self.tf_phone.text]) {
          return [SVProgressHUD showErrorWithStatus:@"手机号码错误"];
          
      }
    
    if (self.Btn_edit.selected == NO) {
        [SVProgressHUD showInfoWithStatus:@"请保存修改信息"];
        return;
    }
    
    [self update2AuthStateRequest:201];
}

- (void)editClick:(UIButton *)sender
{
    sender.selected = !sender.selected;
    
    if (!sender.selected) {
        [self.Btn_edit setTitle:@"保存" forState:UIControlStateNormal];
        self.tf_phone.userInteractionEnabled = YES;
        [self.tf_phone becomeFirstResponder];
    }else{
        
        if (self.tf_phone.text.length == 0) {
               [SVProgressHUD showErrorWithStatus:@"请填写手机号"];
           }
           
           if (![Tools isMobileNumber:self.tf_phone.text]) {
               return [SVProgressHUD showErrorWithStatus:@"手机号码错误"];
               
           }
        
        [self.Btn_edit setTitle:@"修改" forState:UIControlStateNormal];
        [self.tf_phone resignFirstResponder];
        self.tf_phone.userInteractionEnabled = NO;
    }
    
}

- (void)backBtnClick:(UIButton *)btn
{
    [self.view endEditing:YES];
//    BOOL show = [[NSUserDefaults standardUserDefaults]boolForKey:@"SocialSecurityAuthentication"];
//    if (!show) {
        [AuthenticationGuideView showGuideViewWithimgHidden:YES Block:^(BOOL isBack) {
           // [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"SocialSecurityAuthentication"];
           // [[NSUserDefaults standardUserDefaults]synchronize];
            if (isBack) {
                
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        }];
   // }else {
//         [self.navigationController popViewControllerAnimated:YES];
//    }
    
    
    
}

#pragma mark - 绿色通道
- (void)showGreenChannel
{
    WeakSelf
    [GreenChannelAlertView  showWithViewController:self Callback:^(NSInteger index) {
        
        if (index == 201) {
            
             
            [weakSelf startCamera];
            
        }
        
    }];
}

- (void)startCamera
{
    UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
    ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
    ipc.cameraDevice=UIImagePickerControllerCameraDeviceFront;
    ipc.delegate = self;
    ipc.allowsEditing = NO;
    ipc.navigationBar.barTintColor =[UIColor whiteColor];
    ipc.navigationBar.tintColor = [UIColor whiteColor];
    ipc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    ipc.videoQuality = UIImagePickerControllerQualityType640x480;
    
   [self presentViewController:ipc animated:YES completion:^{
        
    }];
}


#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 uploadImagesRequest:originImage[0]];

            }


            //finish

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


#pragma mark - 刷新绿色通道和活体检测按钮的UI布局
- (void)refreshBtnsLayout
{
    if (self.hiddenGreenBtn) {
        
        self.btn_green.hidden = self.hiddenGreenBtn;
        
        [self.btn_green mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView2);
            make.left.offset(20 * WIDTHRADIU);
            make.width.offset(0);
            make.height.offset(45 * WIDTHRADIU);
        }];
        
        [self.btn_next mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-30 * WIDTHRADIU);
            make.left.offset(30 * WIDTHRADIU);
            make.centerY.equalTo(self.contentView2);
            make.height.offset(45 * WIDTHRADIU);
        }];
//        [self.btn_green mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerY.equalTo(self.contentView2);
//            make.left.offset(20 * WIDTHRADIU);
//            make.right.equalTo(self.btn_next.mas_left).offset(-10 * WIDTHRADIU);
//            make.height.offset(45 * WIDTHRADIU);
//        }];
//        [self.btn_next mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.offset(-20 * WIDTHRADIU);
//            make.left.equalTo(self.btn_green.mas_right).offset(10 * WIDTHRADIU);
//            make.width.equalTo(self.btn_green.mas_width).multipliedBy(1.7);
//            make.centerY.height.equalTo(self.btn_green);
//        }];
    }
}


#pragma mark - 图片压缩到某一尺寸
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize and:(UIImage*)imageKs
{
    UIImage *sourceImage = imageKs;
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth= width * scaleFactor;
        scaledHeight = height * scaleFactor;
        
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    
    //UIGraphicsBeginImageContext(targetSize); // this will crop
    UIGraphicsImageRenderer*re=[[UIGraphicsImageRenderer alloc] initWithSize:targetSize];
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width= scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil)
        NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
}

#pragma mark - 图片处理

-(NSString*)imageChangeType:(UIImage*)selfImage{
    UIImage *  flippedImage= selfImage;
    //这里做了修改2017年6月27日
    //先获取图片的镜面图像
    flippedImage  = [UIImage imageWithCGImage:flippedImage.CGImage
                                        scale:1.0 orientation: UIImageOrientationUpMirrored];
    //2017年6月27日
    //2017年7月17日 (483,664)  -->  (360,270)
    //压缩到某一尺寸
    flippedImage=  [self imageByScalingAndCroppingForSize:CGSizeMake(360, 270) and:flippedImage];
    //压缩
    NSData  *dateImage1 =UIImageJPEGRepresentation( flippedImage,0.86);
    //编码
    NSString *str3=[EnercryTool encryptBase64:dateImage1];
    return str3;
    
}


/**
 *  计算富文本字体高度
 *
 *  @param lineSpeace 行高
 *  @param font       字体
 *  @param width      字体所占宽度
 *
 *  @return 富文本高度
 */
-(CGFloat)getSpaceLabelHeightwithSpeace:(CGFloat)lineSpeace withFont:(UIFont*)font withWidth:(CGFloat)width string:(NSString *)str {
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    //    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    /** 行高 */
    paraStyle.lineSpacing = lineSpeace;
    // NSKernAttributeName字体间距
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.5f
                          };
    CGSize size = [str boundingRectWithSize:CGSizeMake(width,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:dic context:nil].size;
    return ceilf(size.height);
}

#pragma mark - 显示一行地址的高度
-(CGFloat)getOneLineHeight
{
    NSString* str = @"河";
     
    CGFloat height = [self getSpaceLabelHeightwithSpeace:4 withFont:[UIFont systemFontOfSize:15 * WIDTHRADIU] withWidth:(ScreenWidth - 70 * WIDTHRADIU - 10 - 88) string:str];
    return height;
}
#pragma mark - 显示地址的高度
- (CGFloat)getAddressHeight
{
   NSString* address =  [NSString stringWithFormat:@"%@%@%@%@%@%@",[NSString validBlankStr:self.paramSModel.provinceName],[NSString validBlankStr:self.paramSModel.cityName],[NSString validBlankStr:self.paramSModel.countryName],[NSString validBlankStr:self.paramSModel.townName],[NSString validBlankStr:self.paramSModel.villageName],[NSString validBlankStr:self.paramSModel.companyName]];
    CGFloat height = [self getSpaceLabelHeightwithSpeace:4 withFont:[UIFont systemFontOfSize:15 * WIDTHRADIU] withWidth:(ScreenWidth - 70 * WIDTHRADIU - 10 - 88) string:address];
    return height;
}

#pragma mark - contentviw距离背景图距离
- (CGFloat)getcontentdistanceFromBackImg
{
    CGFloat distance = 50 * WIDTHRADIU;
    
    
    if ([self CanShowOnOneScreen2]) {
        if ([self getRemainHeight] > 0) {
            distance = distance + 0.6 * [self getRemainHeight];
        }
    }
    
    
    return distance;
}

#pragma mark - 判断是否能够在一个屏幕显示
- (BOOL)CanShowOnOneScreen
{
    //背景图高度
    CGFloat height = 0.0;
    //背景图顶部距离
    CGFloat topPadding = 10 * WIDTHRADIU;
    //contentviw距离背景图距离
    CGFloat distance = [self getcontentdistanceFromBackImg];
    
    //分割线和按钮整体高度
    CGFloat bottomContent = 72 * WIDTHRADIU;
    
    //底部留白距离
    CGFloat bottomPadding = 30 * WIDTHRADIU;
    
    //整个内容高度
    CGFloat totalHeight = 0.0;
    
    if ([self getAddressHeight] <= [self getOneLineHeight]) {
        height = 428 * WIDTHRADIU;
    }else{
        height = 428 * WIDTHRADIU + ([self getAddressHeight] - [self getOneLineHeight]);
    }
    
    totalHeight = topPadding + height + distance + bottomContent + bottomPadding;
    
    if (totalHeight <= (ScreenHeight - cl_kNavigationBarHeight) ) {
        return YES;
    }
    
    return NO;
}

- (BOOL)CanShowOnOneScreen2
{
    //背景图高度
    CGFloat height = 0.0;
    //背景图顶部距离
    CGFloat topPadding = 10 * WIDTHRADIU;
    //contentviw距离背景图距离
    CGFloat distance = 50 * WIDTHRADIU;
    
    //分割线和按钮整体高度
    CGFloat bottomContent = 72 * WIDTHRADIU;
    
    //底部留白距离
    CGFloat bottomPadding = 30 * WIDTHRADIU;
    
    //整个内容高度
    CGFloat totalHeight = 0.0;
    
    if ([self getAddressHeight] <= [self getOneLineHeight]) {
        height = 495 * WIDTHRADIU;
    }else{
        height = 495 * WIDTHRADIU + ([self getAddressHeight] - [self getOneLineHeight]);
    }
    
    totalHeight = topPadding + height + distance + bottomContent + bottomPadding;
    
    if (totalHeight <= (ScreenHeight - cl_kNavigationBarHeight) ) {
        return YES;
    }
    
    return NO;
}

#pragma mark - 获取剩余高度

- (CGFloat)getRemainHeight
{
    //背景图高度
   CGFloat height = 0.0;
   //背景图顶部距离
   CGFloat topPadding = 10 * WIDTHRADIU;
   //contentviw距离背景图距离
   CGFloat distance = 50 * WIDTHRADIU;
   
   //分割线和按钮整体高度
   CGFloat bottomContent = 72 * WIDTHRADIU;
   
   //底部留白距离
   CGFloat bottomPadding = 30 * WIDTHRADIU;
   
   //整个内容高度
   CGFloat totalHeight = 0.0;
   
   if ([self getAddressHeight] <= [self getOneLineHeight]) {
       height = 495 * WIDTHRADIU;
   }else{
       height = 495 * WIDTHRADIU + ([self getAddressHeight] - [self getOneLineHeight]);
   }
    
    totalHeight = topPadding + height + distance + bottomContent + bottomPadding;
    
    
    return (ScreenHeight - cl_kNavigationBarHeight)-totalHeight;
       
}

#pragma mark - 获取背景图片的高度
- (CGFloat)getbackImgHeight
{
    //背景图高度
    CGFloat height = 0.0;
    if ([self getAddressHeight] <= [self getOneLineHeight]) {
        height = 428 * WIDTHRADIU;
    }else{
        height = 428 * WIDTHRADIU + ([self getAddressHeight] - [self getOneLineHeight]);
    }
    return height;
}

# pragma mark - scrollView所需要的contentHeight
- (CGFloat)getScrollViewContenHeight
{
    //背景图高度
    CGFloat height = 0.0;
    //背景图顶部距离
    CGFloat topPadding = 10 * WIDTHRADIU;
    //contentviw距离背景图距离
    CGFloat distance = [self getcontentdistanceFromBackImg];
    
    //分割线和按钮整体高度
    CGFloat bottomContent = 72 * WIDTHRADIU;
    
    //底部留白距离
    CGFloat bottomPadding = 30 * WIDTHRADIU;
    
    //整个内容高度
    CGFloat totalHeight = 0.0;
    
    if ([self getAddressHeight] <= [self getOneLineHeight]) {
        height = 428 * WIDTHRADIU;
    }else{
        height = 428 * WIDTHRADIU + ([self getAddressHeight] - [self getOneLineHeight]);
    }
    
    if ([self CanShowOnOneScreen]) {
        totalHeight = topPadding + height + distance + bottomContent + bottomPadding;
    }else{
        totalHeight = height + topPadding;
    }
    
    
    
    return totalHeight;
}


#pragma mark - getters and setters
-(NSMutableArray *)imageManyImage
{
    if (!_imageManyImage) {
        _imageManyImage =[NSMutableArray array];
    }
    return _imageManyImage;

}

- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        
        if ([self CanShowOnOneScreen]) {
            _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        }else{
            _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight  - 92 * WIDTHRADIU)];
        }
         _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.delegate = self;
        

        //scrollview的contentheight
        CGFloat contentHeight = 0.0;
        contentHeight = [self getScrollViewContenHeight] + 10 * WIDTHRADIU ;//在计算高度的情况下加10个尺寸
       
        
        _scrollView.contentSize = CGSizeMake(ScreenWidth, contentHeight);
        
        if ([self getAddressHeight] <= [self getOneLineHeight]) {
            self.img_back.image = [UIImage imageNamed:@"insuredInfo_bg"];
        }else{
            UIImage*image = [UIImage imageNamed:@"insuredInfo_bg"];
            image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(200 * WIDTHRADIU, 10 * WIDTHRADIU, 10 * WIDTHRADIU, 10 * WIDTHRADIU) resizingMode:UIImageResizingModeStretch];
            
            self.img_back.image = image;
        }
        
        [_scrollView addSubview:self.img_back];
        
        [self.img_back mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(12* WIDTHRADIU);
            make.centerX.equalTo(self->_scrollView);
            make.width.offset(359 * WIDTHRADIU);
            make.height.offset([self getbackImgHeight]);
        }];
        
        if ([self CanShowOnOneScreen]) {
            [_scrollView  addSubview:self.contentView2];
            [_scrollView addSubview:self.contentView];
            [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.img_back.mas_bottom).offset([self getcontentdistanceFromBackImg]);
                make.width.equalTo(self->_scrollView);
               make.height.offset(17 * WIDTHRADIU);
            }];
            [self.contentView2 mas_makeConstraints:^(MASConstraintMaker *make) {
                   make.top.equalTo(self.contentView.mas_bottom).offset(10 * WIDTHRADIU);
                make.width.equalTo(self->_scrollView);
                   make.height.offset(45 * WIDTHRADIU);
            }];
        }
        
        
    }
    return _scrollView;
}

- (UIImageView *)img_back
{
    if (!_img_back) {
        _img_back = [[UIImageView alloc]init];
        
        _img_back.userInteractionEnabled = YES;
        
        [_img_back addSubview:self.lb_locationState];
        [_img_back addSubview:self.lb_location];
        [_img_back addSubview:self.img_location];
        [_img_back addSubview:self.lb_insureTitle];
        [_img_back addSubview:self.sepLine];
        [_img_back addSubview:self.lb_insuredType];
        [_img_back addSubview:self.lb_insuredTypeContent];
        [_img_back addSubview:self.lb_insuredAddress];
        [_img_back addSubview:self.lb_insuredAddressContent];
        [_img_back addSubview:self.lb_phoneTitle];
        [_img_back addSubview:self.tf_phone];
        [_img_back addSubview:self.Btn_edit];
        
        
        
        [self.lb_locationState mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.top.offset(30 * WIDTHRADIU);
        }];
               
        [self.img_location mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(self.lb_locationState);
               make.top.equalTo(self.lb_locationState.mas_bottom).offset(13 * WIDTHRADIU);
               make.width.offset(9 * WIDTHRADIU);
               make.height.offset(12 * WIDTHRADIU);
        }];
           
        [self.lb_location mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(self->_img_location.mas_right).offset(3);
               make.top.equalTo(self->_img_location).offset(-2);
               make.right.offset(-30 * WIDTHRADIU);
        }];
           
        [self.lb_insureTitle mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.img_location.mas_bottom).offset(87 * WIDTHRADIU);
               make.leading.equalTo(self->_lb_locationState);
        }];
        [self.sepLine mas_makeConstraints:^(MASConstraintMaker *make) {
               make.top.equalTo(self.lb_insureTitle.mas_bottom).offset(15 * WIDTHRADIU);
               make.left.offset(20 * WIDTHRADIU);
               make.right.offset(-20 * WIDTHRADIU);
               make.height.offset(0.5);
        }];
        
    
         [self.lb_insuredType setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
         [self.lb_insuredType setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        //[self.lb_insuredTypeContent setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
         //[self.lb_insuredTypeContent setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
        [self.lb_insuredType mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(self.lb_locationState);
               make.top.equalTo(self.sepLine.mas_bottom).offset(35 * WIDTHRADIU);
               make.right.equalTo(self.lb_insuredTypeContent.mas_left).offset(-10);
        }];
           
        [self.lb_insuredTypeContent mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(self.lb_insuredType.mas_right).offset(10);
               make.right.offset(-40 * WIDTHRADIU);
               make.centerY.equalTo(self.lb_insuredType);
        }];
        
        
        [self.lb_insuredAddress setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [self.lb_insuredAddress setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        
        [self.lb_insuredAddress mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(self.lb_locationState);
               make.top.equalTo(self.lb_insuredType.mas_bottom).offset(45 * WIDTHRADIU);
               make.right.equalTo(self.lb_insuredAddressContent.mas_left).offset(-10);
        }];
       
        
        if ([self getAddressHeight] > [self getOneLineHeight]) {
            [self.lb_insuredAddressContent mas_makeConstraints:^(MASConstraintMaker *make) {
              make.left.equalTo(self.lb_insuredTypeContent);
              make.right.offset(-40 * WIDTHRADIU);
              make.top.equalTo(self.lb_insuredAddress.mas_top);
                  
            }];
        }else{
            [self.lb_insuredAddressContent mas_makeConstraints:^(MASConstraintMaker *make) {
                  make.left.equalTo(self.lb_insuredTypeContent);
                  make.right.offset(-40 * WIDTHRADIU);
                  make.centerY.equalTo(self.lb_insuredAddress);
                  
             }];
        }
           
       
           
        [self.lb_phoneTitle mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.equalTo(self.lb_locationState);
               make.bottom.offset(-45 * WIDTHRADIU);
        }];
        
         [self.tf_phone setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
           
        [self.tf_phone mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.lb_insuredTypeContent);
               make.right.equalTo(self.Btn_edit.mas_left);
               make.centerY.equalTo(self.lb_phoneTitle);
               make.height.offset(40 * WIDTHRADIU);
               
        }];
        
        [self.Btn_edit setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [self.Btn_edit setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        
        [self.Btn_edit mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.tf_phone);
            make.left.equalTo(self.tf_phone.mas_right);
            make.right.offset(-30 * WIDTHRADIU);
            make.height.offset(40 * WIDTHRADIU);
        }];
    }
    return _img_back;
}


- (UIView *)contentView
{
    if (!_contentView) {
        _contentView = [[UIView alloc]init];
        [_contentView addSubview:self.lb_middleMessage];
        [_contentView addSubview:self.leftLine];
        [_contentView addSubview:self.rightLine];
        
        [self.lb_middleMessage setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [self.lb_middleMessage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self.contentView);
        }];
        
        [self.leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
               make.centerY.equalTo(self.lb_middleMessage);
               make.left.offset(20 * WIDTHRADIU);
               make.right.equalTo(self.lb_middleMessage.mas_left).offset(-28 * WIDTHRADIU);
               make.height.offset(0.5);
        }];
        
        [self.rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.lb_middleMessage);
            make.left.equalTo(self.lb_middleMessage.mas_right).offset(28 * WIDTHRADIU);
            make.right.offset(-20 * WIDTHRADIU);
            make.height.offset(0.5);
        }];
        
    }
    return _contentView;
}

- (UIView *)contentView2
{
    if (!_contentView2) {
        _contentView2 = [[UIView alloc]init];
        [_contentView2 addSubview:self.btn_green];
        [_contentView2 addSubview:self.btn_next];
        
        [self.btn_green mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self->_contentView2);
            make.left.offset(20 * WIDTHRADIU);
            make.right.equalTo(self.btn_next.mas_left).offset(-10 * WIDTHRADIU);
            make.height.offset(45 * WIDTHRADIU);
        }];
        
        
        [self.btn_next mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-20 * WIDTHRADIU);
            make.left.equalTo(self.btn_green.mas_right).offset(10 * WIDTHRADIU);
            make.width.equalTo(self.btn_green.mas_width).multipliedBy(1.7);
            make.centerY.height.equalTo(self.btn_green);
        }];
        
    }
    return _contentView2;
}


- (UIButton *)btn_green
{
    if (!_btn_green) {
        _btn_green = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_green setTitle:@"绿色通道" forState:UIControlStateNormal];
        [_btn_green setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_green.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_btn_green setBackgroundColor:[UIColor colorWithHex:0x19956D]];
        _btn_green.layer.cornerRadius = 5 * WIDTHRADIU;
        [_btn_green addTarget:self action:@selector(goToGreenChannelVC:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_green;
}

- (UIButton *)btn_next
{
    if (!_btn_next) {
        _btn_next = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn_next setTitle:@"下一步" forState:UIControlStateNormal];
        [_btn_next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _btn_next.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_btn_next setBackgroundColor:[UIColor colorWithHex:0x1980D1]];
        _btn_next.layer.cornerRadius = 5 * WIDTHRADIU;
        [_btn_next addTarget:self action:@selector(goToNextVC:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn_next;
}

- (UIView *)leftLine
{
    if (!_leftLine) {
        _leftLine = [[UIView alloc]init];
        _leftLine.backgroundColor = [UIColor colorWithHex:0xcccccc];
    }
    return _leftLine;
}

- (UILabel *)lb_middleMessage
{
    if (!_lb_middleMessage) {
           _lb_middleMessage = [[UILabel alloc]init];
           _lb_middleMessage.text = @"人工智能认证";
           _lb_middleMessage.textColor = [UIColor colorWithHex:0x808080];
           _lb_middleMessage.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
       }
       return _lb_middleMessage;
}

- (UIView *)rightLine
{
    if (!_rightLine) {
        _rightLine = [[UIView alloc]init];
        _rightLine.backgroundColor = [UIColor colorWithHex:0xcccccc];
    }
    return _rightLine;
}


- (UILabel*)lb_locationState
{
    if (!_lb_locationState) {
        _lb_locationState = [[UILabel alloc]init];
        _lb_locationState.text = @"本地-国内";
        _lb_locationState.textColor = [UIColor whiteColor];
        _lb_locationState.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:19.0*WIDTHRADIU];
    }
    return _lb_locationState;
}

- (UIImageView *)img_location
{
    if (!_img_location) {
        _img_location = [[UIImageView alloc]init];
        _img_location.image = [UIImage imageNamed:@"location_insuredInfo"];
        _img_location.userInteractionEnabled = YES;
    }
    return _img_location;
}

- (UILabel*)lb_location
{
    if (!_lb_location) {
        _lb_location = [[UILabel alloc]init];
        _lb_location.textColor = [UIColor whiteColor];
        _lb_location.text = @"请定位您的地址";
        _lb_location.font = [UIFont systemFontOfSize:14 * WIDTHRADIU];
        _lb_location.numberOfLines = 0;
        _lb_location.userInteractionEnabled = YES;
    }
    return _lb_location;
}
- (UILabel*)lb_insureTitle
{
    if (!_lb_insureTitle) {
        _lb_insureTitle = [[UILabel alloc]init];
        _lb_insureTitle.textColor = [UIColor colorWithHex:0x1980D1];
        _lb_insureTitle.text = @"参保信息";
        _lb_insureTitle.font = [UIFont fontWithName:@"System Heavy" size:17.0*WIDTHRADIU];
    }
    return _lb_insureTitle;
}

- (UIView *)sepLine
{
    if (!_sepLine) {
        _sepLine = [[UIView alloc]init];
        _sepLine.backgroundColor = [UIColor colorWithHex:0xcccccc alpha:0.5];
    }
    return _sepLine;
}

- (UILabel*)lb_insuredType
{
    if (!_lb_insuredType) {
        _lb_insuredType = [[UILabel alloc]init];
        _lb_insuredType.textColor = [UIColor colorWithHex:0x1980D1];
        _lb_insuredType.text = @"参保类型   |";
        _lb_insuredType.font = [UIFont fontWithName:@"System Heavy" size:16.0*WIDTHRADIU];
    }
    return _lb_insuredType;
}

- (UILabel*)lb_insuredTypeContent
{
    if (!_lb_insuredTypeContent) {
        _lb_insuredTypeContent = [[UILabel alloc]init];
        _lb_insuredTypeContent.textColor = [UIColor colorWithHex:0x404040];
        _lb_insuredTypeContent.text = @"城镇居民";
        _lb_insuredTypeContent.textAlignment = NSTextAlignmentLeft;
        //河北省邯郸市肥乡区人力资源和社会保障局
        _lb_insuredTypeContent.font = [UIFont systemFontOfSize:15*WIDTHRADIU];
    }
    return _lb_insuredTypeContent;
}

- (UILabel*)lb_insuredAddress
{
    if (!_lb_insuredAddress) {
        _lb_insuredAddress = [[UILabel alloc]init];
        _lb_insuredAddress.textColor = [UIColor colorWithHex:0x1980D1];
        _lb_insuredAddress.text = @"参保地址   |";
        _lb_insuredAddress.font = [UIFont fontWithName:@"System Heavy" size:16.0*WIDTHRADIU];
        [_lb_insuredAddress sizeToFit];
        if ([self getAddressHeight] > [self getOneLineHeight]) {
             _lb_insuredAddress.contentMode = UIViewContentModeTop;
        }else{
            _lb_insuredAddress.contentMode = UIViewContentModeCenter;
        }
       
    }
    return _lb_insuredAddress;
}

- (UILabel*)lb_insuredAddressContent
{
    if (!_lb_insuredAddressContent) {
        _lb_insuredAddressContent = [[UILabel alloc]init];
        _lb_insuredAddressContent.textColor = [UIColor colorWithHex:0x404040];
        //_lb_insuredAddressContent.text = @"河北省邯郸市肥乡区人力资源和社会保障局";
        [_lb_insuredAddressContent sizeToFit];
        _lb_insuredAddressContent.textAlignment = NSTextAlignmentJustified;
        if ([self getAddressHeight] > [self getOneLineHeight]) {
            _lb_insuredAddressContent.contentMode = UIViewContentModeTop;
        }else{
            _lb_insuredAddressContent.contentMode = UIViewContentModeCenter;
        }
        
        
        
        _lb_insuredAddressContent.attributedText = [NSString getAttributedWithString:@"河北省邯郸市肥乡区人力资源和社会保障局" WithLineSpace:4 kern:0.5 font:[UIFont systemFontOfSize:15*WIDTHRADIU]];
        
        _lb_insuredAddressContent.numberOfLines = 0;
        //河北省邯郸市肥乡区人力资源和社会保障局
        _lb_insuredAddressContent.font = [UIFont systemFontOfSize:15*WIDTHRADIU];
    }
    return _lb_insuredAddressContent;
}


- (UILabel*)lb_phoneTitle
{
    if (!_lb_phoneTitle) {
        _lb_phoneTitle = [[UILabel alloc]init];
        _lb_phoneTitle.textColor = [UIColor colorWithHex:0x1980D1];
        _lb_phoneTitle.text = @"联系电话   |";
        _lb_phoneTitle.font = [UIFont fontWithName:@"System Heavy" size:16.0*WIDTHRADIU];
    }
    return _lb_phoneTitle;
}

- (UITextField *)tf_phone
{
    if (!_tf_phone) {
        _tf_phone = [[UITextField alloc]init];
        _tf_phone.textColor = [UIColor colorWithHex:0x404040];
        _tf_phone.borderStyle =  UITextBorderStyleNone;
        _tf_phone.placeholder = @"请输入手机号";
        _tf_phone.font = [UIFont systemFontOfSize:15*WIDTHRADIU];
        _tf_phone.delegate = self;
    }
    return _tf_phone;
}

- (UIButton *)Btn_edit
{
    if (!_Btn_edit) {
        _Btn_edit = [UIButton buttonWithType:UIButtonTypeCustom];
        [_Btn_edit setTitle:@"修改" forState:UIControlStateNormal];
        [_Btn_edit setTitleColor:K_MainColor forState:UIControlStateNormal];
        _Btn_edit.titleLabel.font = [UIFont systemFontOfSize:15 * WIDTHRADIU];
        [_Btn_edit addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _Btn_edit;
}

- (void)dealloc{
    
    [self closeKeyboardOffsetView];
    NSLog(@"参保信息页面销毁了");
}



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