//
//  ElectronicAccountController.m
//  Open
//
//  Created by 雷俊博 on 2020/7/29.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "ElectronicAccountController.h"
#import "ElectronicAccountTopView.h"
#import "ElectronicAccountCardView.h"
#import "ProductElectronicAccountInfoCell.h"
#import "ElectAccoutBankSelectCell.h"
#import "ElectAccountBankCodeView.h"
#import "ElectAccountFaceVerityView.h"
#import "SMSVerificationController.h"
#import "BankPresentView.h"
#import "SaveBankModel.h"
#import "SaveJobModel.h"
#import "CityTypeSelectView.h"
#import "KBankListModel.h"

#import "BCOPAccAgreementModel.h"

#import "AgreementPresentView.h"


#import <MediaPlayer/MediaPlayer.h>
#import "OPenAccountController.h"

@interface ElectronicAccountController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>

{
    NSString*videoStr;
    
    SaveJobModel* selectJobModel;
    
    BOOL selectAgreement;
    
    BOOL isOK;
}
@property (nonatomic, strong)UIScrollView* scrollView;

@property (nonatomic, strong)ElectAccoutBankSelectCell* bankCell;

@property (nonatomic, strong)ElectAccountBankCodeView* bankCodeView;

@property (nonatomic, strong)ElectAccountBankCodeView* phoneView;

@property (nonatomic, strong)ElectAccoutBankSelectCell* jobCell;

@property (nonatomic, strong)ElectAccoutBankSelectCell* industryCell;

@property (nonatomic, strong)ElectAccountFaceVerityView* verityView;

@property (nonatomic, strong)BCOPAccAgreementModel* agreementModel;

@property (nonatomic, strong)BCDutyModel* dutyModel;

@property (nonatomic, strong)BCIndustryModel* industryModel;

@property (nonatomic, strong)MPMoviePlayerController* player;

@end

@implementation ElectronicAccountController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:0 target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:bar];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.scrollView];
    
    [self selectAgreementClick:self.verityView.selectBtn];
    
    [self getAllOPENAccountAgreementRequest];
    
    
    if (self.type == SaveFromTypeBiCai) {
        self.bankCodeView.tf_content.text = self.bankNo;
        self.phoneView.tf_content.text = self.bcPrePhone;
    }
    
    
   
    

}


#pragma mark - 上传人脸活体检测video
- (void)uploadVideoRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],FaceVideoUploadRequest];
    
    NSDictionary*params = @{
        @"idNo":self.ocrModel.idno,
        @"name":self.ocrModel.name,
        @"userId":@([getPeopleID PeopleID]),
        @"videoStr":videoStr
    };
    
    NSLog(@"银数上传活体认证视频url:%@",url);
    NSLog(@"params:%@",params);
    
    [KKLoadingAnimationView show];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *strHeader = [NSString stringWithFormat:@"IOS#%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSLog(@"strHeader:%@",strHeader);
    [manager.requestSerializer setValue:strHeader forHTTPHeaderField:@"User-Agent"];
       
    [manager POST:url parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
       
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"responseObject:%@",responseObject);
        NSString*state = [NSString stringWithFormat:@"%@",responseObject[@"state"]];
        NSString* result = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
        NSString* describe = [NSString stringWithFormat:@"%@",responseObject[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSDictionary*dic = [Tools dencode:result];
            NSLog(@"result:%@",[Tools dencode:result]);
            [GTCountSDK trackCountEvent:@"save_accountOpenSMSCount" withArgs:nil];
            SMSVerificationController*vc = [SMSVerificationController new];
            vc.title = @"短信验证";
            vc.productModel = self.productModel;
            vc.ocrModel = self.ocrModel;
            vc.jobModel = self->selectJobModel;
            vc.seqNo = dic[@"seqNo"];
            vc.prePhone = self.phoneView.tf_content.text;
            vc.cardNo = self.bankCodeView.tf_content.text;
            vc.type = SMSSendTypeOpenAccount;
            [self.navigationController pushViewController:vc animated:YES];
            vc.from = self.from;
                return;
        }else{
            NSDictionary*dic = [Tools dictionaryWithJsonString:describe];
            NSLog(@"describe:%@",dic);
            NSString*code = nil;
            NSString*message = nil;
            if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"code"]]]) {
                code = [NSString stringWithFormat:@"%@",dic[@"code"]];
            }else if (![Tools isBlankString:[NSString stringWithFormat:@"%@",dic[@"RETCODE"]]]){
                code = [NSString stringWithFormat:@"%@",dic[@"RETCODE"]];
            }
            
            if (code) {
                message = [KBankErrorCode showErrorMessageWithErrorCode:code];
                
                if (message) {
                    [SVProgressHUD showErrorWithStatus:message];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"系统错误"];
                }
            }else{
                [SVProgressHUD showErrorWithStatus:@"系统错误"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       [KKLoadingAnimationView dismiss];
       NSLog(@"error:%@",error);
         [SVProgressHUD showInfoWithStatus:@"网络异常"];
    }];
}


#pragma mark - 比财机构支持的银行卡列表
- (void)querySupportCardsWithOrgId:(NSString *)orgId
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCQuerySupportCardsRequest];
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    
    NSLog(@"比财机构支持的银行卡列表url:%@",url);
    NSLog(@"params:%@",params);
    
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSArray* bankListArray = [SaveBCBankModel mj_objectArrayWithKeyValuesArray:objc[@"result"][@"supportBankList"]];
            WeakSelf
            [BankPresentView showBankListWithVC:self type:BankPresentViewTypeBiCai bankArray:bankListArray block:^(SaveBCBankModel* model) {
                weakSelf.bankCell.lb_content.text = model.bankName;
                self->isOK = YES;
            }];
            
        }else{
            //[Tools showMessage:describe];
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        //[Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
    
  
}


#pragma mark - 比财获取开户协议
- (void)getAllOPENAccountAgreementRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCQueryOpenAccountAgreementsRequest];
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    
    NSLog(@"比财开户协议url:%@",url);
    NSLog(@"params:%@",params);
    
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:params Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            self.agreementModel =  [BCOPAccAgreementModel mj_objectWithKeyValues:objc[@"result"]];
            
        }else{
            //[Tools showMessage:describe];
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
        //[Tools showMessage:@"网络出小差了,请稍后重试"];
        
    }];
}

#pragma mark - 比财开户活体检测
- (NSDictionary *)bcUploadVideoRequestPara
{
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    
    NSString* fileName = [NSString stringWithFormat:@"%@.mp4",self.registerModel.realName];
    
    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:videoStr forKey:@"uploadFile"];
    [params setObject:fileName forKey:@"fileName"];
    [params setObject:@(YES) forKey:@"flag"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    [params setObject:self.registerModel.realName forKey:@"realName"];
    [params setObject:self.registerModel.userCardId forKey:@"userCardId"];
//    [params setObject:@"雷俊博" forKey:@"realName"];
//    [params setObject:@"411522199109276910" forKey:@"userCardId"];
//    [params setObject:@"340" forKey:@"orgId"];
    
    
    return params;
}
- (void)bcUploadVideoRequest
{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCOPENAccountDetectionLivingRequest];
    
    NSLog(@"比财开户活体检测url:%@",url);
    NSLog(@"params:%@",[self bcUploadVideoRequestPara]);
    
    
    [KKLoadingAnimationView show];
    [NetworkRequest Post6:url Params:[self bcUploadVideoRequestPara] Success:^(id _Nonnull objc) {
       
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            NSString *verification = [NSString stringWithFormat:@"%@",objc[@"result"][@"verification"]];
            if ([verification isEqualToString:@"20"]) {
                
                [self bcCommitOpenAccountInfoRequest];
                return;
                
            }else if ([verification isEqualToString:@"30"]) {
               // [Tools showMessage:@"验证不匹配"];
                [self alertShow:@"验证不匹配"];
            }
            
        }else{
            [self alertShow:describe];
        }

        [KKLoadingAnimationView dismiss];
    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}

- (void)testRequest:(NSData *)data {
    NSString* url = [NSString stringWithFormat:@"http://172.16.10.18:8017/%@",BCTestRequest];
    
    NSLog(@"测试url:%@",url);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    manager.requestSerializer = [AFJSONRequestSerializer serializer];
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    [manager POST:url parameters:nil headers:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        [formData appendPartWithFormData:data name:@"file"];
        [formData appendPartWithFileData:data name:@"file" fileName:@"leijunbo" mimeType:@"application/octet-stream"];
        } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSLog(@"responseObject:%@",responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"error:%@",error);
        }];
}


#pragma mark - 开户提交(验证码)
- (NSDictionary *)bcCommitOpenAccountInfoRequestParams{
    NSMutableDictionary *params = [NetworkPublicParams getBCPublicParams];
    
    
    NSString* bankCardNum = [self.bankCodeView.tf_content.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString* bankCardPhone = [self.phoneView.tf_content.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString* bankName = [self.bankCell.lb_content.text stringByReplacingOccurrencesOfString:@" " withString:@""];

    [params setObject:[getPeopleID PeopleIphoneNmber] forKey:@"loginPhoneNum"];
    [params setObject:self.bcInfoModel.orgId forKey:@"orgId"];
    [params setObject:self.registerModel.address forKey:@"residentAddress"];
    if (self.registerModel.industryList.count > 0) {
        [params setObject:self.industryModel.industryCode forKey:@"industry"];
    }
    
    if (self.registerModel.dutyList.count > 0) {
        [params setObject:self.dutyModel.dutyCode forKey:@"userDuty"];
    }
    
    
    [params setObject:bankCardNum forKey:@"bankCardNum"];
    [params setObject:bankCardPhone forKey:@"bankCardPhone"];
    [params setObject:bankName forKey:@"bankName"];
    
    return params;
}
- (void)bcCommitOpenAccountInfoRequest{
    NSString* url = [NSString stringWithFormat:@"%@%@",[NetworkConfig ipYinShuConfig],BCCommitOpenAccountInfoRequest];
    
    NSLog(@"比财开户提交url:%@",url);
    NSLog(@"params:%@",[self bcCommitOpenAccountInfoRequestParams]);
    

    [NetworkRequest Post6:url Params:[self bcCommitOpenAccountInfoRequestParams] Success:^(id _Nonnull objc) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"objc:%@",objc);
        NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        NSString *describe = [NSString stringWithFormat:@"%@",objc[@"describe"]];
        if ([state isEqualToString:@"200"]) {
            
            NSString* bankCardNum = [self.bankCodeView.tf_content.text stringByReplacingOccurrencesOfString:@" " withString:@""];
            NSString* bankCardPhone = [self.phoneView.tf_content.text stringByReplacingOccurrencesOfString:@" " withString:@""];
            NSString* bankName = [self.bankCell.lb_content.text stringByReplacingOccurrencesOfString:@" " withString:@""];
            
            NSString* apiPackSeq = objc[@"result"][@"apiPackSeq"];
            NSString* validateCodeSerialNum = objc[@"result"][@"validateCodeSerialNum"];
            
            SMSVerificationController*vc = [SMSVerificationController new];
            vc.title = @"短信验证";
            vc.type = SMSSendTypeBCOpenAccount;
            vc.bcInfoModel = self.bcInfoModel;
            vc.registerModel = self.registerModel;
            vc.dutyModel = self.dutyModel;
            vc.industryModel = self.industryModel;
            vc.bankName = bankName;
            vc.bankNo = bankCardNum;
            vc.prePhone = bankCardPhone;
            vc.apiPackSeq = apiPackSeq;
            vc.validateCodeSerialNum = validateCodeSerialNum;
            
            [self.navigationController pushViewController:vc animated:YES];
            
            
        }else if ([state isEqualToString:@"204"]){
            NSString* code = [NSString stringWithFormat:@"%@",objc[@"result"][@"code"]];
            if ([code isEqualToString:@"Y10009"]) {
                OPenAccountController* vc = [OPenAccountController new];
                vc.title = @"更新身份证";
                vc.type = SaveFromTypeBiCai;
                vc.functionType = BiCaiOFunctionTypeUpdateIdInfo;
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                [self alertShow:describe];
            }
        } else{
            [self alertShow:describe];
        }

    } Failure:^(NSError* error) {
        [KKLoadingAnimationView dismiss];
        NSLog(@"error:%@",error);
        
        [self alertShow:@"网络出小差了,请稍后重试"];
        
    }];
}


#pragma mark - public methods
-(id)getXiblWithClassName:(NSString *)className
{
    return [[NSBundle mainBundle]loadNibNamed:className owner:self options:nil].lastObject;
}


#pragma mark - UIImagePickerControllerDelegate
/**
   UIImagePickerController代理 获取到媒体资源
 */
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
     NSString *mediaType = info[UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
        // 视频处理
        NSURL *videoUrl = info[UIImagePickerControllerMediaURL];//视频路径
        
        NSData*data = [NSData dataWithContentsOfURL:videoUrl];
        
        NSString *encodedImageStr = nil;
        if (self.type == SaveFromTypeYinShu) {
            encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
        }else if (self.type == SaveFromTypeBiCai) {
            //encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
            encodedImageStr =  [GTMBase64 stringByEncodingData:data];
//            NSString *path = [[NSBundle mainBundle] pathForResource:@"2.视频base64进行URLEncoder后" ofType:@"txt"];
//            encodedImageStr = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
        }
        
        NSLog(@"encodedImageStr.length:%ld",encodedImageStr.length);
        
       
        
        
        
        
        
        
//        UIImage *image = [self get_videoThumbImage:videoUrl];
        
        
        NSString * size = [NSString stringWithFormat:@"%ld kb", (long)[self getFileSize:[[videoUrl absoluteString] substringFromIndex:16]]];
        NSString *length = [NSString stringWithFormat:@"%.2f s", [self getVideoLength:videoUrl]];
           
           NSLog(@"-------------%@%@",size,length);
        //self.videoImageView.image = image;
        
        if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
            
            if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([videoUrl path])) {
                UISaveVideoAtPathToSavedPhotosAlbum([videoUrl path], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);//保存视频到相簿
            }
            
            
            
            
            if (self.type == SaveFromTypeYinShu) {
                videoStr = encodedImageStr;
                [self uploadVideoRequest];
            }else if (self.type == SaveFromTypeBiCai) {
                //videoStr = encodedImageStr;
                //videoStr =  [self encodeBase64:data];
                videoStr =  [encodedImageStr stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "] invertedSet]];
                
                //videoStr =  [videoStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
                
                    
//                    NSString* str = nil;
//
//                     str = [videoStr stringByRemovingPercentEncoding];
//
//
//                    NSData*tempData = [GTMBase64 decodeString:str];
//
//                    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//                        NSString *documentsDirectory = [paths objectAtIndex:0];
//
//                    NSString *path2 = [documentsDirectory stringByAppendingPathComponent:@"myMove2.mp4"];
//
//                    [tempData writeToFile:path2 atomically:YES];
//                    NSURL *moveUrl = [NSURL fileURLWithPath:path2];
//
//                        self.player = [[MPMoviePlayerController alloc]init];
//                        [self.player setContentURL:moveUrl];
//                        self.player.view.frame = self.view.bounds;
//                        [self.view addSubview:self.player.view];
//                        [self.player play];
//
//                return;
//
                //[self testRequest:data];
                [self bcUploadVideoRequest];
            }
            
        }
        
//       NSURL *newVideoUrl ; //一般.mp4
//          NSDateFormatter *formater = [[NSDateFormatter alloc] init];//用时间给文件全名，以免重复，在测试的时候其实可以判断文件是否存在若存在，则删除，重新生成文件即可
//          [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];
//          newVideoUrl = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]]] ;//这个是保存在app自己的沙盒路径里，后面可以选择是否在上传后删除掉。我建议删除掉，免得占空间。
//          [picker dismissViewControllerAnimated:YES completion:nil];
//          [self convertVideoQuailtyWithInputURL:videoUrl outputURL:newVideoUrl completeHandler:nil];

        
        
    }
    // 选择图片后手动销毁界面
    [picker dismissViewControllerAnimated:YES completion:nil];
}


- (NSString *)encodeBase64:(NSData *)data {
    if (nil == data) {
        return @"";
    }
    NSData *base64Data = [data base64EncodedDataWithOptions:0];
    if (nil == base64Data) {
        return @"";
    }
    NSString *result = [[NSString alloc] initWithData:base64Data encoding:NSUTF8StringEncoding];
    if (nil == result) {
        return @"";
    }
    return result;
}

/**
  用户取消操作
 */
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
//    手动销毁界面
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//视频保存到相册之后的回调
- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error) {
        // 保存失败
    }else {
        // 处理视频
        
    }
}


- (void) convertVideoQuailtyWithInputURL:(NSURL*)inputURL
                               outputURL:(NSURL*)outputURL
                         completeHandler:(void (^)(AVAssetExportSession*))handler
{
    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
        //  NSLog(resultPath);
        exportSession.outputURL = outputURL;
        exportSession.outputFileType = AVFileTypeMPEG4;
        exportSession.shouldOptimizeForNetworkUse= YES;
        [exportSession exportAsynchronouslyWithCompletionHandler:^(void)
         {
             switch (exportSession.status) {
                 case AVAssetExportSessionStatusCancelled:
                     NSLog(@"AVAssetExportSessionStatusCancelled");
                     break;
                 case AVAssetExportSessionStatusUnknown:
                     NSLog(@"AVAssetExportSessionStatusUnknown");
                     break;
                 case AVAssetExportSessionStatusWaiting:
                     NSLog(@"AVAssetExportSessionStatusWaiting");
                     break;
                 case AVAssetExportSessionStatusExporting:
                     NSLog(@"AVAssetExportSessionStatusExporting");
                     break;
                 case AVAssetExportSessionStatusCompleted:
                 {   NSLog(@"AVAssetExportSessionStatusCompleted");
                     NSLog(@"%@",[NSString stringWithFormat:@"%f s", [self getVideoLength:outputURL]]);
                     NSLog(@"%@", [NSString stringWithFormat:@"%.2f kb", [self getFileSize:[outputURL path]]]);
                     NSData*data = [NSData dataWithContentsOfURL:outputURL];
                    NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
                    NSLog(@"encodedImageStr.length:%ld",encodedImageStr.length);
                 }
                     //UISaveVideoAtPathToSavedPhotosAlbum([outputURL path], self, nil, NULL);//这个是保存到手机相册
                     
                     //[self alertUploadVideo:outputURL];
                     break;
                 case AVAssetExportSessionStatusFailed:
                     NSLog(@"AVAssetExportSessionStatusFailed");
                     break;
             }
             
         }];
    
}

#pragma mark --UITextFieldDelegate
//输入时一直监听,返回YES表示修改生效,返回NO表示不修改
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField.tag == 1) {
        return YES;
    }
    NSString *text = [self.bankCodeView.tf_content text];
    //返回一个字符集,指定字符串中包含的字符
    NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789\b"];
    //string = [string stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    //invertedSet  除了characterSet中包含的字符都找出来
    if ([string rangeOfCharacterFromSet:[characterSet invertedSet]].location != NSNotFound) {
        return NO;
    }
    
    text = [text stringByReplacingCharactersInRange:range withString:string];
    text = [text stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    //不能写nil
    NSString *newString = @"";
    while (text.length > 0) {
        //每4位截取/不够4位有多少截取多少
        NSString *subString = [text substringToIndex:MIN(text.length, 4)];
        newString = [newString stringByAppendingString:subString];
        //加空格
        if (subString.length == 4) {
            newString = [newString stringByAppendingString:@" "];
        }
        text = [text substringFromIndex:MIN(text.length, 4)];
    }
    newString = [newString stringByTrimmingCharactersInSet:[characterSet invertedSet]];
    //限制长度
    if (newString.length >= 24) {
        return NO;
    }
    
    [self.bankCodeView.tf_content setText:newString];
    
    if (self.type != SaveFromTypeBiCai) {
        NSString *originalStr = [newString stringByReplacingOccurrencesOfString:@" " withString:@""];
        //判断实哪家银行,并赋值
        if (originalStr.length == 16 || originalStr.length == 17 || originalStr.length == 19) {
            if ([self returnBankName:originalStr].length > 0) {
                NSString*bankName = [self returnBankName:originalStr];
                NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"BankList"ofType:@"plist"];
                NSArray*array = [NSArray arrayWithContentsOfFile:plistPath];
                
                BOOL success = NO;
                for (NSDictionary*dic in array) {
                    NSString*name =  dic[@"bankName"];
                    if ([name isEqualToString:bankName]) {
                        success = YES;
                        break;
                    }
                }
                isOK = success;
                if (success) {
                    self.bankCell.lb_content.text = [self returnBankName:originalStr];
                }
                
            }
        }
    }
   
    
    
    return NO;
}
//编辑结束
- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (self.bankCodeView.tf_content.text.length <= 0 || self.bankCodeView.tf_content.text.length > 24) {
        //提示错误信息
        self.bankCell.lb_content.text = @"选择支持的银行";
    }
}

//根据卡号判断银行
- (NSString *)returnBankName:(NSString *)cardName {
    
    
    if (cardName.length < 6) {
        return @"";
    }
    NSString*bankName = [KBankListModel getBankNameWithStr:cardName];
    
    return bankName;
    
}

#pragma mark - 跳转web页面
- (void)jumpToWebVCWithUrl:(NSString *)url title:(NSString *)title
{
    
    if (self.type == SaveFromTypeYinShu) {
        
        url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        
    }else if (self.type == SaveFromTypeBiCai) {
        
        NSArray* urlArray = [url componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"?"]];
        url = nil;
        
        for (int i = 0; i < urlArray.count; i++) {
            if (i == 0) {
                url = urlArray[0];
            }else{
                if (i == (urlArray.count - 1)) {
                    url = [url stringByAppendingFormat:@"?%@",[urlArray[i] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
                }else{
                    url = [NSString stringWithFormat:@"%@?%@",url,urlArray[i]];
                }
            }
        }
        
    }
    
    
    
    WebVC * vc = [WebVC new];
    vc.title= title;
    vc.url = url;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

#pragma mark - 当前日期
- (NSString *)getCurrentDate
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    formatter.dateFormat = @"yyyy年MM月dd日";
    
    NSTimeZone* zone = [NSTimeZone timeZoneWithName:@"Asia/beijing"];
    
    [formatter setTimeZone:zone];

    NSString *time = [formatter stringFromDate:[NSDate date]];


    return time;
}

#pragma mark - 提示
- (void)alertShow:(NSString *)msg
{
    if (@available(iOS 9.0,*)) {
        
        UIAlertController * alertV = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertV addAction:confirm];
        
        [self presentViewController:alertV animated:YES completion:nil];
        
    }else{
        UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertV show];
    }
}


#pragma mark - event response
- (void)checkAgreementClick:(UIButton *)sender
{
    
    
    if (self.type == SaveFromTypeYinShu) {
        NSArray*array = @[
            @{
                @"name":[NSString stringWithFormat:@"贵州乌当农商银行\"%@\"存款产品协议",self.productModel.NOTE],
                @"url":[NSString stringWithFormat:@"http://nginx.weface.com.cn/agreement/ckxy.html?cp=%@&jf=%@",self.productModel.NOTE,self.ocrModel.name]
            },@{
                @"name":@"贵州乌当农商银行电子账户协议",
                @"url":[NSString stringWithFormat:@"http://nginx.weface.com.cn/agreement/dzzh.html?jf=%@",self.ocrModel.name]
            },@{
                @"name":@"贵州乌当农商银行账户委托扣款授权书",
                @"url":[NSString stringWithFormat:@"http://nginx.weface.com.cn/agreement/zhkk.html?name=%@&idcard=%@&time=%@",self.ocrModel.name,self.ocrModel.idno,[self getCurrentDate]]
            },@{
                @"name":@"贵州乌当农商银行平台服务协议",
                @"url":@"http://nginx.weface.com.cn/agreement/kkshbank.html"
            },
        ];
        
        [AgreementPresentView showBankListWithVC:self type:AgreementPresentViewTypeWuDang bankArray:array block:^(id  _Nonnull model) {
            NSString* name = model[@"name"];
            NSString* url = model[@"url"];
            [self jumpToWebVCWithUrl:url title:name];
        }];
    }else if (self.type == SaveFromTypeBiCai) {
        [AgreementPresentView showBankListWithVC:self type:AgreementPresentViewTypeBiCai bankArray:self.agreementModel.agreementList block:^(BCSubModel*  _Nonnull model) {
            NSString* name = model.agreementTitle;
            NSString* url = model.agreementUrl;
            [self jumpToWebVCWithUrl:url title:name];
        }];
    }
    
}
- (void)selectAgreementClick:(UIButton *)sender
{
    selectAgreement = !selectAgreement;
    if (selectAgreement) {
        self.verityView.selectIcon.image = [UIImage imageNamed:@"xieyi_selected"];
    }else{
        self.verityView.selectIcon.image = [UIImage imageNamed:@"xieyi_unselected"];
    }
}
- (void)nextBtnClick:(UIButton *)sender
{
    
    if (![Tools IsBankCard:self.bankCodeView.tf_content.text]) {
        [Tools showMessage:@"请输入正确的银行卡号"];
        return;
    }
    
    if (!isOK) {
        [Tools showMessage:@"请选择支持的发卡行"];
        return;
    }
    
    if (![Tools isMobileNumber:self.phoneView.tf_content.text]) {
        [Tools showMessage:@"请输入正确的手机号码"];
        return;
    }
    
    if (self.type == SaveFromTypeYinShu) {
        if (selectJobModel == nil) {
            [Tools showMessage:@"请选择您的职业"];
            return;
        }
    }else if (self.type == SaveFromTypeBiCai) {
        if (self.industryModel == nil && self.registerModel.industryList.count > 0) {
            [Tools showMessage:@"请选择您的行业"];
            return;
        }
        
        if (self.dutyModel == nil && self.registerModel.dutyList.count > 0) {
            [Tools showMessage:@"请选择您的职业"];
            return;
        }
    }
    
    
    
    if (!selectAgreement) {
        [Tools showMessage:@"请选择同意协议"];
        return;
    }
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"人脸认证提示" message:@"录制时请保持正脸对框且眨眼!" preferredStyle:UIAlertControllerStyleAlert];
       //默认只有标题 没有操作的按钮:添加操作的按钮 UIAlertAction
       
       UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
           NSLog(@"取消");
       }];
       //添加确定
       UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"确认认证" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull   action) {
           NSLog(@"确定");
           [self openCameraForVideo];
       }];
       //设置`确定`按钮的颜色
       [sureBtn setValue:[UIColor redColor] forKey:@"titleTextColor"];
       //将action添加到控制器
       [alertVc addAction:cancelBtn];
       [alertVc addAction :sureBtn];
       //展示
       [self presentViewController:alertVc animated:YES completion:nil];
    

    
}

- (void)selectBankClick:(UIButton *)sender
{
    [self.view endEditing:YES];
    
    if (self.type == SaveFromTypeYinShu) {
    
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"BankList" ofType:@"plist"];
        NSArray*array = [NSArray arrayWithContentsOfFile:plistPath];
        NSMutableArray*bankArray = [NSMutableArray array];
        for (NSDictionary*dic in array) {
           SaveBankModel*model = [SaveBankModel new];
           model.bankName = dic[@"bankName"];
           model.bankImage = dic[@"bankImage"];
           model.orderMin = dic[@"orderMin"];
           model.dMin = dic[@"dMin"];
           [bankArray addObject:model];
        }
        WeakSelf
        [BankPresentView showBankListWithVC:self type:BankPresentViewTypeWuDang bankArray:bankArray block:^(SaveBankModel* model) {
             __strong __typeof(weakSelf)strongSelf = weakSelf;
            strongSelf.bankCell.lb_content.text = model.bankName;
        }];
        
    }else if (self.type == SaveFromTypeBiCai) {
        
        [self querySupportCardsWithOrgId:self.bcInfoModel.orgId];
        
    }
    
    
}

- (void)jobSelectClick:(UIButton *)sender
{
    [self.view endEditing:YES];
    if (self.type == SaveFromTypeYinShu) {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"job"ofType:@"plist"];
        NSArray*array = [NSArray arrayWithContentsOfFile:plistPath];
        NSMutableArray*jobArray = [NSMutableArray array];
        for (NSDictionary*dic in array) {
           SaveJobModel*model = [SaveJobModel new];
           model.jobName = dic[@"jobName"];
           model.jobCode = dic[@"jobCode"];
           [jobArray addObject:model];
        }
        WeakSelf
        
        [CityTypeSelectView show5WithArray:jobArray type:SelectTypesJob block:^(SaveJobModel* model) {
            if (model) {
                __strong __typeof(weakSelf)strongSelf = weakSelf;
                strongSelf.jobCell.lb_content.text = model.jobName;
                self->selectJobModel = model;
            }
        }];
    }else if (self.type == SaveFromTypeBiCai) {
        
        if (self.registerModel.dutyList.count == 0) {
            [Tools showMessage:@"该银行不需选择职业"];
            return;
        }
        
        WeakSelf
        [CityTypeSelectView show5WithArray:self.registerModel.dutyList type:SelectTypesBCJob block:^(BCDutyModel* model) {
            weakSelf.jobCell.lb_content.text = model.dutyName;
            weakSelf.dutyModel = model;
        }];
    }
    
    
    
}

- (void)industrySelectBtnClick:(UIButton *)sender{
    
    if (self.registerModel.industryList.count == 0) {
        [Tools showMessage:@"该银行不需选择行业"];
        return;
    }
    
    WeakSelf
    [CityTypeSelectView show5WithArray:self.registerModel.industryList type:SelectTypesBCIndustry block:^(BCIndustryModel* model) {
        weakSelf.industryCell.lb_content.text = model.industryName;
        weakSelf.industryModel = model;
    }];
}

#pragma mark - 私有方法
/**
  录制
 */
- (void)openCameraForVideo
{
    // 一般情况下用这个判断
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        // 该设备不支持拍照
        
        [Tools showMessage:@"该设备不支持录像"];
        return;
    }
    
    if (self.type == SaveFromTypeYinShu) {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.mediaTypes =  [[NSArray alloc] initWithObjects:(NSString*)kUTTypeMovie,nil];
        picker.videoMaximumDuration = 3.0; // 视频的最大录制时长
        picker.videoQuality = UIImagePickerControllerQualityTypeMedium;
        //picker.showsCameraControls = NO;
        picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo; //相机的模式 拍照/摄像
        picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        picker.delegate = self;
        [self presentViewController:picker animated:YES completion:nil];
    }else if (self.type == SaveFromTypeBiCai) {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.mediaTypes =  [[NSArray alloc] initWithObjects:(NSString*)kUTTypeMovie,nil];
        picker.videoMaximumDuration = 4.0; // 视频的最大录制时长
        picker.videoQuality = UIImagePickerControllerQualityTypeMedium;
        //picker.showsCameraControls = NO;
        picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo; //相机的模式 拍照/摄像
        picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        picker.delegate = self;
        [self presentViewController:picker animated:YES completion:nil];
    }
    
    
    
    
}


/**
 获取视频缩略图
 */

- (UIImage *)get_videoThumbImage:(NSURL *)videoURL
{
    NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:videoURL options:opts];
    AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
    generator.appliesPreferredTrackTransform = YES;
    CMTime actualTime;
    NSError *error = nil;
    CGImageRef img = [generator copyCGImageAtTime:CMTimeMake(0, 600) actualTime:&actualTime error:&error];
    if (error) {
        return nil;
    }
    return [UIImage imageWithCGImage:img];
}

- (CGFloat) getFileSize:(NSString *)path
{
    NSLog(@"%@",path);
    NSFileManager *fileManager = [NSFileManager defaultManager];
    float filesize = -1.0;
    if ([fileManager fileExistsAtPath:path]) {
        NSDictionary *fileDic = [fileManager attributesOfItemAtPath:path error:nil];//获取文件的属性
        unsigned long long size = [[fileDic objectForKey:NSFileSize] longLongValue];
        filesize = 1.0*size/1024;
    }else{
        NSLog(@"找不到文件");
    }
    return filesize;
}//此方法可以获取文件的大小，返回的是单位是KB。
- (CGFloat) getVideoLength:(NSURL *)URL
{
    
    AVURLAsset *avUrl = [AVURLAsset assetWithURL:URL];
    CMTime time = [avUrl duration];
    int second = ceil(time.value/time.timescale);
    return second;
}

- (NSString *)getCurrentTimeStamp
{
   NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    // 设置想要的格式，hh与HH的区别:分别表示12小时制,24小时制

    [formatter setDateFormat:@"yyyyMMdd"];

    NSDate *dateNow = [NSDate date];

    //把NSDate按formatter格式转成NSString

    NSString *currentTime = [formatter stringFromDate:dateNow];

    return currentTime;
}



#pragma mark - getters
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, cl_kNavigationBarHeight, ScreenWidth, ScreenHeight - cl_kNavigationBarHeight)];
        _scrollView.showsVerticalScrollIndicator = NO;
        //_scrollView.delegate = self;
        _scrollView.contentSize = CGSizeMake(ScreenWidth, 0);
        
        //顶部view
        ElectronicAccountTopView* topView = [self getXiblWithClassName:@"ElectronicAccountTopView"];
        [_scrollView addSubview:topView];
        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.mas_greaterThanOrEqualTo(50);
        }];
        //cardView
        ElectronicAccountCardView* cardView = [[ElectronicAccountCardView alloc]init];
        [_scrollView addSubview:cardView];
        [cardView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(topView.mas_bottom).offset(0);
           make.left.mas_equalTo(0);
           make.width.mas_equalTo(ScreenWidth);
           make.height.mas_greaterThanOrEqualTo(50);
       }];

        
        [_scrollView layoutIfNeeded];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cardView.cardView.bounds
                                                             byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                                   cornerRadii:CGSizeMake(12, 12)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = cardView.cardView.bounds;
        maskLayer.path = maskPath.CGPath;
        cardView.cardView.layer.mask = maskLayer;
        
        
        ProductElectronicAccountInfoCell* nameView = [self getXiblWithClassName:@"ProductElectronicAccountInfoCell"];
        nameView.lb_title.text = @"姓名";
        [_scrollView addSubview:nameView];
        [nameView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(cardView.mas_bottom).offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.offset(50);
        }];
        
        ProductElectronicAccountInfoCell* idView = [self getXiblWithClassName:@"ProductElectronicAccountInfoCell"];
        idView.lb_title.text = @"身份证号";
        
       
        [_scrollView addSubview:idView];
        [idView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(nameView.mas_bottom).offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.offset(50);
        }];
        
        
        if (self.type == SaveFromTypeYinShu) {
            //姓名
            NSString* subNameStr = [self.ocrModel.name substringFromIndex:1];
            NSString*hiddenNameStr = @"";
            for (int i = 0; i < subNameStr.length; i++) {
                hiddenNameStr = [hiddenNameStr stringByAppendingString:@"*"];
            }
            
            NSString*nameStr = [NSString stringWithFormat:@"%@%@",[self.ocrModel.name substringToIndex:1],hiddenNameStr];
            
            nameView.lb_content.text = nameStr;
            
            
            //身份证号
            NSString* subIdStr = [self.ocrModel.idno substringFromIndex:3];
            NSString*hiddenIdStr = @"";
            for (int i = 0; i < subIdStr.length; i++) {
                if (i < (subIdStr.length - 4)) {
                    hiddenIdStr = [hiddenIdStr stringByAppendingString:@"*"];
                }else{
                    hiddenIdStr = [hiddenIdStr stringByAppendingFormat:@"%@",[subIdStr substringWithRange:NSMakeRange(i, 1)]];
                }
                
            }
            
            NSString*IdStr = [NSString stringWithFormat:@"%@%@",[self.ocrModel.idno substringToIndex:3],hiddenIdStr];
            
            idView.lb_content.text = IdStr;
            
        }else if (self.type == SaveFromTypeBiCai) {
            
            cardView.lb_mark.text = [NSString stringWithFormat:@"%@",[self.bcInfoModel.orgName substringToIndex:1]];
            cardView.lb_bankName.text = self.bcInfoModel.orgName;
            
            //姓名
            NSString* subNameStr = [self.registerModel.realName substringFromIndex:1];
            NSString*hiddenNameStr = @"";
            for (int i = 0; i < subNameStr.length; i++) {
                hiddenNameStr = [hiddenNameStr stringByAppendingString:@"*"];
            }
            
            NSString*nameStr = [NSString stringWithFormat:@"%@%@",[self.registerModel.realName substringToIndex:1],hiddenNameStr];
            
            nameView.lb_content.text = nameStr;
            
            
            //身份证号
            NSString* subIdStr = [self.registerModel.userCardId substringFromIndex:3];
            NSString*hiddenIdStr = @"";
            for (int i = 0; i < subIdStr.length; i++) {
                if (i < (subIdStr.length - 4)) {
                    hiddenIdStr = [hiddenIdStr stringByAppendingString:@"*"];
                }else{
                    hiddenIdStr = [hiddenIdStr stringByAppendingFormat:@"%@",[subIdStr substringWithRange:NSMakeRange(i, 1)]];
                }
                
            }
            
            NSString*IdStr = [NSString stringWithFormat:@"%@%@",[self.registerModel.userCardId  substringToIndex:3],hiddenIdStr];
            
            idView.lb_content.text = IdStr;
        }
       
        
        //发卡行
        ElectAccoutBankSelectCell*bankCell = [self getXiblWithClassName:@"ElectAccoutBankSelectCell"];
        bankCell.lb_title.text = @"发卡行";
        bankCell.lb_content.text = @"选择支持的银行";
        [bankCell.btn addTarget:self action:@selector(selectBankClick:) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:bankCell];
        self.bankCell = bankCell;
        [bankCell mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(idView.mas_bottom).offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.offset(50);
        }];
        //银行卡号
        ElectAccountBankCodeView* bankCodeView = [self getXiblWithClassName:@"ElectAccountBankCodeView"];
        bankCodeView.lb_title.text = @"银行卡号";
        bankCodeView.tf_content.placeholder = @"请输入银行卡号";
        bankCodeView.tf_content.delegate = self;
        self.bankCodeView = bankCodeView;
        [_scrollView addSubview:bankCodeView];
        [bankCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bankCell.mas_bottom).offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.offset(50);
        }];
        //预留手机号
        ElectAccountBankCodeView* phoneView = [self getXiblWithClassName:@"ElectAccountBankCodeView"];
        phoneView.lb_title.text = @"预留手机号";
        phoneView.tf_content.placeholder = @"请输入预留手机号";
        self.phoneView = phoneView;
        [_scrollView addSubview:phoneView];
        [phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(bankCodeView.mas_bottom).offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.offset(50);
        }];
        
        if (self.type == SaveFromTypeBiCai) {
            ElectAccoutBankSelectCell*industryCell = [self getXiblWithClassName:@"ElectAccoutBankSelectCell"];
            industryCell.lb_title.text = @"行业";
            industryCell.lb_content.text = @"请选择您的行业";
            [industryCell.btn addTarget:self action:@selector(industrySelectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            self.industryCell = industryCell;
            [_scrollView addSubview:industryCell];
            [industryCell mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(phoneView.mas_bottom).offset(0);
                make.left.mas_equalTo(0);
                make.width.mas_equalTo(ScreenWidth);
                make.height.offset(50);
            }];
            
            //职业
            ElectAccoutBankSelectCell*jobCell = [self getXiblWithClassName:@"ElectAccoutBankSelectCell"];
            jobCell.lb_title.text = @"职业";
            jobCell.lb_content.text = @"请选择您的职业";
            [jobCell.btn addTarget:self action:@selector(jobSelectClick:) forControlEvents:UIControlEventTouchUpInside];
            self.jobCell = jobCell;
            [_scrollView addSubview:jobCell];
            [jobCell mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(industryCell.mas_bottom).offset(0);
                make.left.mas_equalTo(0);
                make.width.mas_equalTo(ScreenWidth);
                make.height.offset(50);
            }];
            
        }else if (self.type == SaveFromTypeYinShu){
            //职业
            ElectAccoutBankSelectCell*jobCell = [self getXiblWithClassName:@"ElectAccoutBankSelectCell"];
            jobCell.lb_title.text = @"职业";
            jobCell.lb_content.text = @"请选择您的职业";
            [jobCell.btn addTarget:self action:@selector(jobSelectClick:) forControlEvents:UIControlEventTouchUpInside];
            self.jobCell = jobCell;
            [_scrollView addSubview:jobCell];
            [jobCell mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(phoneView.mas_bottom).offset(0);
                make.left.mas_equalTo(0);
                make.width.mas_equalTo(ScreenWidth);
                make.height.offset(50);
            }];
        }
        
    
        
        
        
        //确认按钮
        ElectAccountFaceVerityView*verityView = [self getXiblWithClassName:@"ElectAccountFaceVerityView"];
        [verityView.btn_xieyi addTarget:self action:@selector(checkAgreementClick:) forControlEvents:UIControlEventTouchUpInside];
        [verityView.selectBtn addTarget:self action:@selector(selectAgreementClick:) forControlEvents:UIControlEventTouchUpInside];
        [verityView.nextBtn addTarget:self action:@selector(nextBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_scrollView addSubview:verityView];
        self.verityView = verityView;
        [verityView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.jobCell.mas_bottom).offset(0);
            make.left.mas_equalTo(0);
            make.width.mas_equalTo(ScreenWidth);
            make.height.offset(95);
            make.bottom.mas_equalTo(0);
        }];
        
        
       
        
        
       // _scrollView.contentSize = CGSizeMake(ScreenWidth, backView.maxY + 10);
    }
    return _scrollView;
}
/*
#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
