123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- //
- // PersonalCertificationViewController.m
- // ChinaTheoryNetwork
- //
- // Created by 张毅成 on 2019/1/29.
- // Copyright © 2019 张毅成. All rights reserved.
- //
- #import "PersonalCertificationViewController.h"
- #import "PersonalCertificationTableViewCell.h"
- #import "PersonalCertificationModel.h"
- #import "PersonalCertificationHeaderView.h"
- @interface PersonalCertificationViewController ()<UITableViewDataSource, UITableViewDelegate>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (weak, nonatomic) IBOutlet UIButton *buttonFinish;
- @property (strong, nonatomic) NSMutableArray *arrayData;
- @property (strong, nonatomic) PersonalCertificationModel *model;
- @property (strong, nonatomic) PersonalCertificationHeaderView *headerView;
- @end
- @implementation PersonalCertificationViewController
- - (PersonalCertificationHeaderView *)headerView {
- if (!_headerView) {
- _headerView = [[NSBundle mainBundle] loadNibNamed:@"PersonalCertificationHeaderView" owner:self options:nil].lastObject;
- }
- return _headerView;
- }
- - (PersonalCertificationModel *)model {
- if (!_model) {
- _model = [PersonalCertificationModel new];
- }
- return _model;
- }
- - (NSMutableArray *)arrayData {
- if (!_arrayData) {
- _arrayData = @[].mutableCopy;
- }
- return _arrayData;
- }
- - (void)Network {
- NSString *URL = @"my/isApprove";
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- parameters[@"map"] = [self.model modelToJSONString];
-
- [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSLog(@"%@",responseObject);
- if ([responseObject[@"code"] integerValue] == 0) {
- SHOWSUCCESS(@"提交成功!")
- USERDEFAULTSSET(@"2", @"kisApprove");
- [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadMydetail" object:nil];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.navigationController popViewControllerAnimated:true];
- });
- }
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-
- }];
- }
- - (void)NetworkOfGet {
- NSString *URL = @"my/getMeberUserInfo";
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- [[HttpManager sharedHttpManager] GET:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSLog(@"%@",responseObject);
- if ([responseObject[@"code"] integerValue] == 0) {
- self.model = [PersonalCertificationModel modelWithJSON:responseObject[@"data"][@"userId"]];
- [self.tableView reloadData];
- }
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"个人认证";
- [self.buttonFinish setCorner];
- [self createTableView];
- if (self.isNeedRightButton) {
- [self setupRightButton];
- }
- if (self.controllerType == ControllerTypeSuccessed) {
- [self.buttonFinish setTitle:@"重新认证" forState:(UIControlStateNormal)];
- }
- [self NetworkOfGet];
- }
- - (void)viewDidLayoutSubviews {
- if (self.controllerType == ControllerTypeSuccessed) {
- self.tableView.tableHeaderView = self.headerView;
- }
- }
- - (void)createTableView {
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.tableView.tableFooterView = [UIView new];
- self.tableView.rowHeight = UITableViewAutomaticDimension;
- self.tableView.estimatedRowHeight = 60;
- self.tableView.scrollEnabled = false;
- }
- - (void)setupRightButton {
- UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
- rightButton.frame = CGRectMake(0, 0, 40, 40);
- [rightButton setTitleColor:kMainColor forState:(UIControlStateNormal)];
- [rightButton setTitle:@"跳过" forState:(UIControlStateNormal)];
- UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFixedSpace) target:nil action:nil];
- item.width = -7;
- self.navigationItem.rightBarButtonItems = @[item,rightItem];
- [rightButton addTarget:self action:@selector(didTouchRightButton) forControlEvents:UIControlEventTouchUpInside];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return PersonalCertificationModel.arrayTitle.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- PersonalCertificationTableViewCell *cell = [PersonalCertificationTableViewCell cellWithTableView:tableView];
- cell.labelTitle.text = PersonalCertificationModel.arrayTitle[indexPath.row];
- [cell.textField addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
- cell.textField.placeholder = [NSString stringWithFormat:@"请输入%@",cell.labelTitle.text];
- cell.textField.tag = indexPath.row;
- cell.textField.keyboardType = UIKeyboardTypeDefault;
- if (self.controllerType == ControllerTypeSuccessed) {
- cell.textField.userInteractionEnabled = false;
- }
- switch (indexPath.row) {
- case 0:
- cell.textField.text = self.model.realName;
- break;
- case 1:
- cell.textField.text = self.model.idCard;
- cell.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
- break;
- case 2:
- cell.textField.text = self.model.email;
- cell.textField.keyboardType = UIKeyboardTypeEmailAddress;
- break;
- case 3:
- cell.textField.text = self.model.workSpace;
- break;
- case 4:
- cell.textField.text = self.model.workName;
- break;
- default:
- break;
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
- if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
- [cell setPreservesSuperviewLayoutMargins:NO];
- }
- }
- - (void)change:(UITextField *)textField {
- switch (textField.tag) {
- case 0://姓名
- self.model.realName = textField.text;
- break;
- case 1://身份证号
- self.model.idCard = textField.text;
- break;
- case 2://邮箱
- self.model.email = textField.text;
- break;
- case 3://工作单位
- self.model.workSpace = textField.text;
- break;
- case 4://职称
- self.model.workName = textField.text;
- break;
- default:
- break;
- }
- }
- - (void)didTouchRightButton {
-
- }
- - (IBAction)didTouchButtonFinish:(UIButton *)sender {
- if (self.controllerType == ControllerTypeSuccessed) {
- PersonalCertificationViewController *controller = [PersonalCertificationViewController new];
- controller.controllerType = ControllerTypeUnauthorized;
- [self.navigationController pushViewController:controller animated:true];
- }else if (self.controllerType == ControllerTypeUnauthorized) {
- if (!self.model.realName.length) {
- SHOWERROR(@"请输入姓名")
- return;
- }else if (![NSString accurateVerifyIDCardNumber:self.model.idCard]) {
- SHOWERROR(@"请输入正确的身份证号")
- return;
- }else if (![self.model.email isEmailAddress]) {
- SHOWERROR(@"请输入正确的邮箱地址")
- return;
- }else if (!self.model.workSpace.length) {
- SHOWERROR(@"请输入工作单位")
- return;
- }else if (!self.model.workName.length) {
- SHOWERROR(@"请输入职称")
- return;
- }
- [self Network];
- }
- }
- @end
|