123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- //
- // ClubApplicationViewController.m
- // DSH
- //
- // Created by 张毅成 on 2018/12/28.
- // Copyright © 2018 WZX. All rights reserved.
- //
- #import "ClubApplicationViewController.h"
- #import "ClubApplicationTableViewCell.h"
- #import "ClubApplicationModel.h"
- #import "MOFSPickerManager.h"
- #import "H5ViewController.h"
- #import "NSString+RegexCategory.h"
- @interface ClubApplicationViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextViewDelegate>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- /**
- 是否勾选同意
- */
- @property (assign, nonatomic) BOOL isAgree;
- /**
-
- */
- @property (strong, nonatomic) ClubApplicationModel *model;
- /**
-
- */
- @property (strong, nonatomic) UIButton *buttonVerification;
- /**
-
- */
- @property (strong, nonatomic) NSMutableArray *arrayImage;
- @property (assign, nonatomic) NSInteger photoType;
- @end
- @implementation ClubApplicationViewController
- - (NSMutableArray *)arrayImage {
- if (!_arrayImage) {
- _arrayImage = @[].mutableCopy;
- }
- return _arrayImage;
- }
- - (ClubApplicationModel *)model {
- if (!_model) {
- _model = [ClubApplicationModel new];
- }
- return _model;
- }
- - (void)NetworkOfGetCode {
- NSString *URL = @"memberUserInfo/sendMessage";
- NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
- parameters[@"phone"] = self.model.姓名;
- parameters[@"type"] = @"1";
- [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
- NSLog(@"%@",responseObject);
- [self Verification];
- } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
-
- }];
- }
- - (void)NetworkOfUploadIconWithImage:(UIImage *)image {
- // SHOWLOADING
- // NSString *URL = @"my/iconUpload";
- // [NetWorkRequest PostImages:URL post:nil dicImages:@[image].mutableCopy amrFilePath:nil name:@"file" success:^(id result) {
- // NSLog(@"%@",result);
- // REMOVESHOW
- // if ([result[@"code"] integerValue] == 0) {
- // self.model.imageIconURL = result[@"data"][@"imgurl"];
- // [self Network];
- // }
- // } fail:^(id error) {
- // REMOVESHOW
- // }];
- }
- - (void)Network {
- // NSString *URL = [NSString stringWithFormat:@"/my/readClubApply"];
- // NSDictionary *parameters = [NSDictionary dictionary];
- // parameters = @{@"clubName":self.model.readingName,
- // @"dscr":self.model.摘要,
- // @"ownUserName":self.model.originatorName,
- // @"ownUserDscr":@"",
- // @"city":self.model.city,
- // @"detailAddress":self.model.address,
- // @"phone":self.model.originatorPhoneNumber,
- // @"checkCode":self.model.originatorCode,
- // @"readClubLogo":self.model.imageIconURL,
- // @"idCard": self.model.originatorID
- // };
- // [NetWorkRequest postJSONWithUrl:URL parameters:parameters.mutableCopy success:^(id result) {
- // NSLog(@"%@",result);
- // if ([result[@"code"] integerValue] == 0) {
- // NSLog(@"Success");
- // SHOWSUCCESS(@"提交成功")
- // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToSubmitSuccessViewController" object:nil];
- // [self.navigationController popToRootViewControllerAnimated:false];
- // });
- // }else
- // SHOWERROR(result[@"msg"]);
- // } fail:^(NSError *error) {
- //
- // }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"投稿";
- self.view.backgroundColor = kBackgroundColor;
- [self createTableView];
- }
- - (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.separatorStyle = 0;
- self.tableView.backgroundColor = kBackgroundColor;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.model.arrayTitle.count + 1;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *view = [UIView new];
- [view setBackgroundColor:kBackgroundColor];
- return view;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- UIView *view = [UIView new];
- [view setBackgroundColor:kBackgroundColor];
- return view;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 0.01;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 10;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- ClubApplicationTableViewCell *cell0 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:0];
- ClubApplicationTableViewCell *cell1 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:1];
- ClubApplicationTableViewCell *cell2 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:2];
- ClubApplicationTableViewCell *cell6 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:6];
- if (indexPath.row == [tableView numberOfRowsInSection:0] - 1) {
- NSArray *array = @[cell6.button0, cell6.button1, cell6.button2];
- [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- UIButton *button = obj;
- button.layer.borderColor = [UIColor hexStringToColor:@"d8d8d8"].CGColor;
- button.layer.borderWidth = 1.0f;
- button.tag = idx;
- [button addEventHandler:^(id sender) {
- UIButton *button = (UIButton *)sender;
- self.photoType = button.tag;
- } forControlEvents:(UIControlEventTouchUpInside)];
- }];
- [cell6.button3 setCorner];
- return cell6;
- }
- cell0.textField.userInteractionEnabled = true;
- [cell0.textField addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
- cell0.textField.tag = indexPath.row;
- cell0.textField.keyboardType = UIKeyboardTypeDefault;
- cell0.label0.text = self.model.arrayTitle[indexPath.row];
- [cell0.textField setPlaceholder:self.model.arrayPlaceHolder[indexPath.row]];
- if (indexPath.row == 1) {
- cell1.label0.text = self.model.arrayTitle[indexPath.row];
- cell1.textView.text = self.model.摘要;
- cell1.textView.delegate = self;
- return cell1;
- }else if (indexPath.row == 5) {
- cell2.label0.text = self.model.arrayTitle[indexPath.row];
- cell0.textField.keyboardType = UIKeyboardTypeNumberPad;
- self.buttonVerification = cell2.button0;
- cell2.blockDidTouchButton = ^(UIButton * _Nonnull button) {
- [self NetworkOfGetCode];
- };
- cell2.textField.text = self.model.联系方式;
- [cell2.textField addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
- cell2.textField.tag = 13;
- return cell2;
- }
- return cell0;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 2) {
- if (indexPath.row == 0) {
- [[MOFSPickerManager shareManger] showMOFSAddressPickerWithDefaultZipcode:@"450000-450900-450921" title:@"选择地区" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString * _Nullable address, NSString * _Nullable zipcode) {
- self.model.验证码 = address;
- [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:(UITableViewRowAnimationNone)];
- } cancelBlock:^{
-
- }];
- }
- }
- }
- - (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)getPhoto {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
- picker.delegate = self;
- picker.allowsEditing = YES;//取消白框
- UIAlertAction *camera = [UIAlertAction actionWithTitle:@"相册上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [ZYCTool controller:self AlbumIsAvailable:^{
- picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- [self presentViewController:picker animated:YES completion:^{}];
- } OrNotAvailable:^{}];
- }];
- UIAlertAction *photo = [UIAlertAction actionWithTitle:@"拍照上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [ZYCTool controller:self CameraIsAvailable:^{
- picker.sourceType = UIImagePickerControllerSourceTypeCamera;
- [self presentViewController:picker animated:YES completion:^{}];
- } OrNotAvailable:^{}];
- }];
- UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"点击了取消按钮");
- }];
- [cancel setValue:[UIColor redColor] forKey:@"titleTextColor"];
- [alert addAction:cancel];
- [alert addAction:camera];
- [alert addAction:photo];
- [self presentViewController:alert animated:YES completion:nil];
- }
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
- UIImage *selectIma = [info objectForKey:UIImagePickerControllerEditedImage];
- // selectIma = [selectIma fixOrientation];
- NSData *Data= UIImageJPEGRepresentation(selectIma, 0.3);
- UIImage *new = [UIImage imageWithData:Data];
- [self.arrayImage replaceObjectAtIndex:self.photoType withObject:new];
- [self.navigationController dismissViewControllerAnimated:YES completion:^{}];
- [self.tableView reloadData];
- }
- /**
- 验证码倒计时
- */
- - (void)Verification {
- __weak __typeof__(self) weakSelf = self;
- [self.buttonVerification addEventHandler:^(id sender) {
- if (self.model.姓名.length == 11) {
- __block NSInteger time = 59; //倒计时时间
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
- dispatch_source_set_timer(timer,DISPATCH_TIME_NOW,1.0*NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(timer, ^{
- if(time <= 0){ //倒计时结束,关闭
- dispatch_source_cancel(timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置按钮的样式
- [weakSelf.buttonVerification setTitle:@"重新获取验证码" forState:UIControlStateNormal];
- weakSelf.buttonVerification.userInteractionEnabled = YES;
- });
- }else{
- int seconds = time % 60;
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置label读秒效果
- [weakSelf.buttonVerification setTitle:[NSString stringWithFormat:@"重新获取(%.2d)",seconds] forState:UIControlStateNormal];
- weakSelf.buttonVerification.userInteractionEnabled = NO;
- });
- time--;
- }
- });
- dispatch_resume(timer);
- // [self NetworkOfGetCode];
- }else{
- SHOWERROR(@"请输入手机号")
- }
- } forControlEvents:(UIControlEventTouchUpInside)];
- }
- - (void)change:(UITextField *)textField {
- switch (textField.tag) {
- case 0://关键词
- self.model.标题 = textField.text;
- break;
- case 2://关键词
- self.model.关键词 = textField.text;
- break;
- case 3://研究领域
- self.model.研究领域 = textField.text;
- break;
- case 4://姓名
- self.model.姓名 = textField.text;
- break;
- case 5://联系方式
- self.model.联系方式 = textField.text;
- break;
- case 6://验证码
- self.model.验证码 = textField.text;
- break;
- case 7://邮箱
- self.model.邮箱 = textField.text;
- break;
- case 8://邮编
- self.model.邮编= textField.text;
- break;
- case 9://联系地址
- self.model.联系地址 = textField.text;
- break;
- case 10://详细地址
- self.model.详细地址 = textField.text;
- break;
- case 11://推荐人姓名
- self.model.推荐人姓名 = textField.text;
- break;
- case 12://推荐人电话
- self.model.推荐人电话 = textField.text;
- break;
-
- default:
- break;
- }
- }
- - (void)textViewDidChange:(UITextView *)textView {
- self.model.摘要 = textView.text;
- }
- - (void)check {
- __block BOOL isDone = true;
- [self.model.arrayData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- NSArray *arrayTmp = obj;
- [arrayTmp enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- NSString *string = obj;
- if (string.length == 0) {
- SHOWERROR(@"请填写相关信息")
- isDone = false;
- *stop = true;
- }
- }];
- }];
- // if (!self.isAgree) {
- // SHOWERROR(@"请阅读并同意相关章程")
- // return;
- // }
- // if (![NSString accurateVerifyIDCardNumber:self.model.研究领域]) {
- // SHOWERROR(@"请输入正确的身份证号")
- // return;
- // }
- // if (self.isAgree && isDone) {
- // [self NetworkOfUploadIconWithImage:self.imageIcon];
- // }
- }
- @end
|