// // KXNextStepViewController.m // QBCS // // Created by kuxuan on 2017/7/27. // Copyright © 2017年 kuxuan. All rights reserved. // #import "KXNextStepViewController.h" #import "QBImagePickerController.h" #import "KXLogginViewController.h" @interface KXNextStepViewController () @property (nonatomic,assign)BOOL upOrDown; @end @implementation KXNextStepViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self createNavBar]; [self createView]; } -(void)createNavBar { self.name=@"身份证"; [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)]; } -(void)backAction { [self.navigationController popViewControllerAnimated:YES]; } -(void)createView { NSArray *imageArray=@[@"main_ID_up",@"main_ID_down"]; for (int i=0; i<2; i++) { UIImageView *IDButton=[[UIImageView alloc]init]; IDButton.frame=CGRectMake((SCREEN_WIDTH-160)/2, 100+150*i, 160, 100); IDButton.image=[UIImage imageNamed:imageArray[i]]; IDButton.userInteractionEnabled=YES; UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imagePickAction:)]; [IDButton addGestureRecognizer:tap]; IDButton.tag=99+i; [self.view addSubview:IDButton]; } UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom]; next.frame=CGRectMake(14,400, SCREEN_WIDTH-28, 45); next.layer.cornerRadius=6; next.tag=999; next.layer.masksToBounds=YES; next.backgroundColor=[UIColor baseColor]; next.titleLabel.font=FONT_SYS(16); [next setTitle:@"立即申请" forState:UIControlStateNormal]; [next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [next addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:next]; } -(void)nextAction { UIButton *nextButton=(UIButton *)[self.view viewWithTag:999]; NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL]; [KXHTTP post:urlString params:nil success:^(id json) { NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME]; if (!username) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请登录" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { KXLogginViewController *loggin=[[KXLogginViewController alloc]init]; [self.navigationController pushViewController:loggin animated:YES]; [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ISPOP"]; [[NSUserDefaults standardUserDefaults]synchronize]; }]]; [self presentViewController:alertController animated:YES completion:nil]; }else{ NSString *urlS=[NSString stringWithFormat:@"%@/user/iosApply",URL]; NSDictionary *paraDict=@{@"name":self.name,@"age":self.age,@"cell_num":self.cell,@"occupation":self.occupation,@"monthly_income":self.income,@"id":[json[@"user"] valueForKey:@"id"],@"term":self.term,@"amount":self.amount}; [KXHTTP post:urlS params:paraDict success:^(id json) { [nextButton setTitle:@"审核中..." forState:UIControlStateNormal]; [self.navigationController popViewControllerAnimated:YES]; } failure:^(NSError *error) { }]; } } failure:^(NSError *error) { }]; } -(void)imagePickAction:(UITapGestureRecognizer *)tap { if (tap.view.tag==99) { self.upOrDown=YES; }else{ self.upOrDown=NO; } QBImagePickerController *imagePicker=[[QBImagePickerController alloc]init]; imagePicker.delegate = self; imagePicker.allowsMultipleSelection = YES; imagePicker.showsNumberOfSelectedAssets = YES; imagePicker.maximumNumberOfSelection=1; [self presentViewController:imagePicker animated:YES completion:nil]; } #pragma mark - QBImagePickerControllerDelegate - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(PHAsset *)asset; { if (self.upOrDown==YES) { PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; // 同步获得图片, 只会返回1张图片 options.synchronous = YES; [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(160, 100) contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { UIImageView *button=[self.view viewWithTag:99]; button.image=result; }]; }else{ PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; // 同步获得图片, 只会返回1张图片 options.synchronous = YES; options.resizeMode=PHImageRequestOptionsResizeModeExact; [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(160, 100) contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { UIImageView *button=[self.view viewWithTag:100]; button.image=result; }]; } [self dismissViewControllerAnimated:YES completion:nil]; } -(void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)nextStepButtonClickso { } /* #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