PersonalCertificationViewController.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // PersonalCertificationViewController.m
  3. // ChinaTheoryNetwork
  4. //
  5. // Created by 张毅成 on 2019/1/29.
  6. // Copyright © 2019 张毅成. All rights reserved.
  7. //
  8. #import "PersonalCertificationViewController.h"
  9. #import "PersonalCertificationTableViewCell.h"
  10. #import "PersonalCertificationModel.h"
  11. #import "PersonalCertificationHeaderView.h"
  12. @interface PersonalCertificationViewController ()<UITableViewDataSource, UITableViewDelegate>
  13. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  14. @property (weak, nonatomic) IBOutlet UIButton *buttonFinish;
  15. @property (strong, nonatomic) NSMutableArray *arrayData;
  16. @property (strong, nonatomic) PersonalCertificationModel *model;
  17. @property (strong, nonatomic) PersonalCertificationHeaderView *headerView;
  18. @end
  19. @implementation PersonalCertificationViewController
  20. - (PersonalCertificationHeaderView *)headerView {
  21. if (!_headerView) {
  22. _headerView = [[NSBundle mainBundle] loadNibNamed:@"PersonalCertificationHeaderView" owner:self options:nil].lastObject;
  23. }
  24. return _headerView;
  25. }
  26. - (PersonalCertificationModel *)model {
  27. if (!_model) {
  28. _model = [PersonalCertificationModel new];
  29. }
  30. return _model;
  31. }
  32. - (NSMutableArray *)arrayData {
  33. if (!_arrayData) {
  34. _arrayData = @[].mutableCopy;
  35. }
  36. return _arrayData;
  37. }
  38. - (void)Network {
  39. NSString *URL = @"my/isApprove";
  40. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  41. parameters[@"map"] = [self.model modelToJSONString];
  42. [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  43. NSLog(@"%@",responseObject);
  44. if ([responseObject[@"code"] integerValue] == 0) {
  45. SHOWSUCCESS(@"提交成功!")
  46. USERDEFAULTSSET(@"2", @"kisApprove");
  47. [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadMydetail" object:nil];
  48. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  49. [self.navigationController popViewControllerAnimated:true];
  50. });
  51. }
  52. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  53. }];
  54. }
  55. - (void)NetworkOfGet {
  56. NSString *URL = @"my/getMeberUserInfo";
  57. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  58. [[HttpManager sharedHttpManager] GET:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  59. NSLog(@"%@",responseObject);
  60. if ([responseObject[@"code"] integerValue] == 0) {
  61. self.model = [PersonalCertificationModel modelWithJSON:responseObject[@"data"][@"userId"]];
  62. [self.tableView reloadData];
  63. }
  64. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  65. }];
  66. }
  67. - (void)viewDidLoad {
  68. [super viewDidLoad];
  69. self.title = @"个人认证";
  70. [self.buttonFinish setCorner];
  71. [self createTableView];
  72. if (self.isNeedRightButton) {
  73. [self setupRightButton];
  74. }
  75. if (self.controllerType == ControllerTypeSuccessed) {
  76. [self.buttonFinish setTitle:@"重新认证" forState:(UIControlStateNormal)];
  77. }
  78. [self NetworkOfGet];
  79. }
  80. - (void)viewDidLayoutSubviews {
  81. if (self.controllerType == ControllerTypeSuccessed) {
  82. self.tableView.tableHeaderView = self.headerView;
  83. }
  84. }
  85. - (void)createTableView {
  86. self.tableView.delegate = self;
  87. self.tableView.dataSource = self;
  88. self.tableView.tableFooterView = [UIView new];
  89. self.tableView.rowHeight = UITableViewAutomaticDimension;
  90. self.tableView.estimatedRowHeight = 60;
  91. self.tableView.scrollEnabled = false;
  92. }
  93. - (void)setupRightButton {
  94. UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  95. rightButton.frame = CGRectMake(0, 0, 40, 40);
  96. [rightButton setTitleColor:kMainColor forState:(UIControlStateNormal)];
  97. [rightButton setTitle:@"跳过" forState:(UIControlStateNormal)];
  98. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
  99. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFixedSpace) target:nil action:nil];
  100. item.width = -7;
  101. self.navigationItem.rightBarButtonItems = @[item,rightItem];
  102. [rightButton addTarget:self action:@selector(didTouchRightButton) forControlEvents:UIControlEventTouchUpInside];
  103. }
  104. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  105. return 1;
  106. }
  107. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  108. return PersonalCertificationModel.arrayTitle.count;
  109. }
  110. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  111. PersonalCertificationTableViewCell *cell = [PersonalCertificationTableViewCell cellWithTableView:tableView];
  112. cell.labelTitle.text = PersonalCertificationModel.arrayTitle[indexPath.row];
  113. [cell.textField addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
  114. cell.textField.placeholder = [NSString stringWithFormat:@"请输入%@",cell.labelTitle.text];
  115. cell.textField.tag = indexPath.row;
  116. cell.textField.keyboardType = UIKeyboardTypeDefault;
  117. if (self.controllerType == ControllerTypeSuccessed) {
  118. cell.textField.userInteractionEnabled = false;
  119. }
  120. switch (indexPath.row) {
  121. case 0:
  122. cell.textField.text = self.model.realName;
  123. break;
  124. case 1:
  125. cell.textField.text = self.model.idCard;
  126. cell.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  127. break;
  128. case 2:
  129. cell.textField.text = self.model.email;
  130. cell.textField.keyboardType = UIKeyboardTypeEmailAddress;
  131. break;
  132. case 3:
  133. cell.textField.text = self.model.workSpace;
  134. break;
  135. case 4:
  136. cell.textField.text = self.model.workName;
  137. break;
  138. default:
  139. break;
  140. }
  141. return cell;
  142. }
  143. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  144. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  145. [cell setSeparatorInset:UIEdgeInsetsZero];
  146. }
  147. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  148. [cell setLayoutMargins:UIEdgeInsetsZero];
  149. }
  150. if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  151. [cell setPreservesSuperviewLayoutMargins:NO];
  152. }
  153. }
  154. - (void)change:(UITextField *)textField {
  155. switch (textField.tag) {
  156. case 0://姓名
  157. self.model.realName = textField.text;
  158. break;
  159. case 1://身份证号
  160. self.model.idCard = textField.text;
  161. break;
  162. case 2://邮箱
  163. self.model.email = textField.text;
  164. break;
  165. case 3://工作单位
  166. self.model.workSpace = textField.text;
  167. break;
  168. case 4://职称
  169. self.model.workName = textField.text;
  170. break;
  171. default:
  172. break;
  173. }
  174. }
  175. - (void)didTouchRightButton {
  176. }
  177. - (IBAction)didTouchButtonFinish:(UIButton *)sender {
  178. if (self.controllerType == ControllerTypeSuccessed) {
  179. PersonalCertificationViewController *controller = [PersonalCertificationViewController new];
  180. controller.controllerType = ControllerTypeUnauthorized;
  181. [self.navigationController pushViewController:controller animated:true];
  182. }else if (self.controllerType == ControllerTypeUnauthorized) {
  183. if (!self.model.realName.length) {
  184. SHOWERROR(@"请输入姓名")
  185. return;
  186. }else if (![NSString accurateVerifyIDCardNumber:self.model.idCard]) {
  187. SHOWERROR(@"请输入正确的身份证号")
  188. return;
  189. }else if (![self.model.email isEmailAddress]) {
  190. SHOWERROR(@"请输入正确的邮箱地址")
  191. return;
  192. }else if (!self.model.workSpace.length) {
  193. SHOWERROR(@"请输入工作单位")
  194. return;
  195. }else if (!self.model.workName.length) {
  196. SHOWERROR(@"请输入职称")
  197. return;
  198. }
  199. [self Network];
  200. }
  201. }
  202. @end