Ei kuvausta

KXNextStepViewController.m 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // KXNextStepViewController.m
  3. // QBCS
  4. //
  5. // Created by kuxuan on 2017/7/27.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXNextStepViewController.h"
  9. #import "QBImagePickerController.h"
  10. #import "KXLogginViewController.h"
  11. @interface KXNextStepViewController ()<QBImagePickerControllerDelegate>
  12. @property (nonatomic,assign)BOOL upOrDown;
  13. @end
  14. @implementation KXNextStepViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // Do any additional setup after loading the view.
  18. [self createNavBar];
  19. [self createView];
  20. }
  21. -(void)createNavBar
  22. {
  23. self.name=@"身份证";
  24. [self addLeftBarButtonItemWithImageName:@"main_back" title:nil target:self selector:@selector(backAction)];
  25. }
  26. -(void)backAction
  27. {
  28. [self.navigationController popViewControllerAnimated:YES];
  29. }
  30. -(void)createView
  31. {
  32. NSArray *imageArray=@[@"main_ID_up",@"main_ID_down"];
  33. for (int i=0; i<2; i++) {
  34. UIImageView *IDButton=[[UIImageView alloc]init];
  35. IDButton.frame=CGRectMake((SCREEN_WIDTH-160)/2, 100+150*i, 160, 100);
  36. IDButton.image=[UIImage imageNamed:imageArray[i]];
  37. IDButton.userInteractionEnabled=YES;
  38. UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imagePickAction:)];
  39. [IDButton addGestureRecognizer:tap];
  40. IDButton.tag=99+i;
  41. [self.view addSubview:IDButton];
  42. }
  43. UIButton *next=[UIButton buttonWithType:UIButtonTypeCustom];
  44. next.frame=CGRectMake(14,400, SCREEN_WIDTH-28, 45);
  45. next.layer.cornerRadius=6;
  46. next.tag=999;
  47. next.layer.masksToBounds=YES;
  48. next.backgroundColor=[UIColor baseColor];
  49. next.titleLabel.font=FONT_SYS(16);
  50. [next setTitle:@"立即申请" forState:UIControlStateNormal];
  51. [next setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  52. [next addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
  53. [self.view addSubview:next];
  54. }
  55. -(void)nextAction
  56. {
  57. UIButton *nextButton=(UIButton *)[self.view viewWithTag:999];
  58. NSString *urlString=[NSString stringWithFormat:@"%@/user/personalCenter",URL];
  59. [KXHTTP post:urlString params:nil success:^(id json) {
  60. NSString *username= [[NSUserDefaults standardUserDefaults]valueForKey:USER_NAME];
  61. if (!username) {
  62. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请登录" preferredStyle:UIAlertControllerStyleAlert];
  63. [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  64. KXLogginViewController *loggin=[[KXLogginViewController alloc]init];
  65. [self.navigationController pushViewController:loggin animated:YES];
  66. [[NSUserDefaults standardUserDefaults]setObject:nil forKey:@"ISPOP"];
  67. [[NSUserDefaults standardUserDefaults]synchronize];
  68. }]];
  69. [self presentViewController:alertController animated:YES completion:nil];
  70. }else{
  71. NSString *urlS=[NSString stringWithFormat:@"%@/user/iosApply",URL];
  72. 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};
  73. [KXHTTP post:urlS params:paraDict success:^(id json) {
  74. [nextButton setTitle:@"审核中..." forState:UIControlStateNormal];
  75. [self.navigationController popViewControllerAnimated:YES];
  76. } failure:^(NSError *error) {
  77. }];
  78. }
  79. } failure:^(NSError *error) {
  80. }];
  81. }
  82. -(void)imagePickAction:(UITapGestureRecognizer *)tap
  83. {
  84. if (tap.view.tag==99) {
  85. self.upOrDown=YES;
  86. }else{
  87. self.upOrDown=NO;
  88. }
  89. QBImagePickerController *imagePicker=[[QBImagePickerController alloc]init];
  90. imagePicker.delegate = self;
  91. imagePicker.allowsMultipleSelection = YES;
  92. imagePicker.showsNumberOfSelectedAssets = YES;
  93. imagePicker.maximumNumberOfSelection=1;
  94. [self presentViewController:imagePicker animated:YES completion:nil];
  95. }
  96. #pragma mark - QBImagePickerControllerDelegate
  97. - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(PHAsset *)asset;
  98. {
  99. if (self.upOrDown==YES) {
  100. PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
  101. // 同步获得图片, 只会返回1张图片
  102. options.synchronous = YES;
  103. [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(160, 100) contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
  104. UIImageView *button=[self.view viewWithTag:99];
  105. button.image=result;
  106. }];
  107. }else{
  108. PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
  109. // 同步获得图片, 只会返回1张图片
  110. options.synchronous = YES;
  111. options.resizeMode=PHImageRequestOptionsResizeModeExact;
  112. [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(160, 100) contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
  113. UIImageView *button=[self.view viewWithTag:100];
  114. button.image=result;
  115. }];
  116. }
  117. [self dismissViewControllerAnimated:YES completion:nil];
  118. }
  119. -(void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
  120. {
  121. [self dismissViewControllerAnimated:YES completion:nil];
  122. }
  123. - (void)didReceiveMemoryWarning {
  124. [super didReceiveMemoryWarning];
  125. // Dispose of any resources that can be recreated.
  126. }
  127. -(void)nextStepButtonClickso
  128. {
  129. }
  130. /*
  131. #pragma mark - Navigation
  132. // In a storyboard-based application, you will often want to do a little preparation before navigation
  133. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  134. // Get the new view controller using [segue destinationViewController].
  135. // Pass the selected object to the new view controller.
  136. }
  137. */
  138. @end