ClubApplicationViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. //
  2. // ClubApplicationViewController.m
  3. // DSH
  4. //
  5. // Created by 张毅成 on 2018/12/28.
  6. // Copyright © 2018 WZX. All rights reserved.
  7. //
  8. #import "ClubApplicationViewController.h"
  9. #import "ClubApplicationTableViewCell.h"
  10. #import "ClubApplicationModel.h"
  11. #import "MOFSPickerManager.h"
  12. #import "H5ViewController.h"
  13. #import "NSString+RegexCategory.h"
  14. @interface ClubApplicationViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextViewDelegate>
  15. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  16. /**
  17. 是否勾选同意
  18. */
  19. @property (assign, nonatomic) BOOL isAgree;
  20. /**
  21. */
  22. @property (strong, nonatomic) ClubApplicationModel *model;
  23. /**
  24. */
  25. @property (strong, nonatomic) UIButton *buttonVerification;
  26. /**
  27. */
  28. @property (strong, nonatomic) NSMutableArray *arrayImage;
  29. @property (assign, nonatomic) NSInteger photoType;
  30. @end
  31. @implementation ClubApplicationViewController
  32. - (NSMutableArray *)arrayImage {
  33. if (!_arrayImage) {
  34. _arrayImage = @[].mutableCopy;
  35. }
  36. return _arrayImage;
  37. }
  38. - (ClubApplicationModel *)model {
  39. if (!_model) {
  40. _model = [ClubApplicationModel new];
  41. }
  42. return _model;
  43. }
  44. - (void)NetworkOfGetCode {
  45. NSString *URL = @"memberUserInfo/sendMessage";
  46. NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
  47. parameters[@"phone"] = self.model.姓名;
  48. parameters[@"type"] = @"1";
  49. [[HttpManager sharedHttpManager] POST:URL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  50. NSLog(@"%@",responseObject);
  51. [self Verification];
  52. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  53. }];
  54. }
  55. - (void)NetworkOfUploadIconWithImage:(UIImage *)image {
  56. // SHOWLOADING
  57. // NSString *URL = @"my/iconUpload";
  58. // [NetWorkRequest PostImages:URL post:nil dicImages:@[image].mutableCopy amrFilePath:nil name:@"file" success:^(id result) {
  59. // NSLog(@"%@",result);
  60. // REMOVESHOW
  61. // if ([result[@"code"] integerValue] == 0) {
  62. // self.model.imageIconURL = result[@"data"][@"imgurl"];
  63. // [self Network];
  64. // }
  65. // } fail:^(id error) {
  66. // REMOVESHOW
  67. // }];
  68. }
  69. - (void)Network {
  70. // NSString *URL = [NSString stringWithFormat:@"/my/readClubApply"];
  71. // NSDictionary *parameters = [NSDictionary dictionary];
  72. // parameters = @{@"clubName":self.model.readingName,
  73. // @"dscr":self.model.摘要,
  74. // @"ownUserName":self.model.originatorName,
  75. // @"ownUserDscr":@"",
  76. // @"city":self.model.city,
  77. // @"detailAddress":self.model.address,
  78. // @"phone":self.model.originatorPhoneNumber,
  79. // @"checkCode":self.model.originatorCode,
  80. // @"readClubLogo":self.model.imageIconURL,
  81. // @"idCard": self.model.originatorID
  82. // };
  83. // [NetWorkRequest postJSONWithUrl:URL parameters:parameters.mutableCopy success:^(id result) {
  84. // NSLog(@"%@",result);
  85. // if ([result[@"code"] integerValue] == 0) {
  86. // NSLog(@"Success");
  87. // SHOWSUCCESS(@"提交成功")
  88. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  89. // [[NSNotificationCenter defaultCenter] postNotificationName:@"pushToSubmitSuccessViewController" object:nil];
  90. // [self.navigationController popToRootViewControllerAnimated:false];
  91. // });
  92. // }else
  93. // SHOWERROR(result[@"msg"]);
  94. // } fail:^(NSError *error) {
  95. //
  96. // }];
  97. }
  98. - (void)viewDidLoad {
  99. [super viewDidLoad];
  100. self.title = @"投稿";
  101. self.view.backgroundColor = kBackgroundColor;
  102. [self createTableView];
  103. }
  104. - (void)createTableView {
  105. self.tableView.delegate = self;
  106. self.tableView.dataSource = self;
  107. self.tableView.tableFooterView = [UIView new];
  108. self.tableView.rowHeight = UITableViewAutomaticDimension;
  109. self.tableView.estimatedRowHeight = 60;
  110. self.tableView.separatorStyle = 0;
  111. self.tableView.backgroundColor = kBackgroundColor;
  112. }
  113. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  114. return 1;
  115. }
  116. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  117. return self.model.arrayTitle.count + 1;
  118. }
  119. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  120. UIView *view = [UIView new];
  121. [view setBackgroundColor:kBackgroundColor];
  122. return view;
  123. }
  124. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  125. UIView *view = [UIView new];
  126. [view setBackgroundColor:kBackgroundColor];
  127. return view;
  128. }
  129. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  130. return 0.01;
  131. }
  132. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  133. return 10;
  134. }
  135. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  136. ClubApplicationTableViewCell *cell0 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:0];
  137. ClubApplicationTableViewCell *cell1 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:1];
  138. ClubApplicationTableViewCell *cell2 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:2];
  139. ClubApplicationTableViewCell *cell6 = [ClubApplicationTableViewCell cellWithTableView:tableView AndIndex:6];
  140. if (indexPath.row == [tableView numberOfRowsInSection:0] - 1) {
  141. NSArray *array = @[cell6.button0, cell6.button1, cell6.button2];
  142. [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  143. UIButton *button = obj;
  144. button.layer.borderColor = [UIColor hexStringToColor:@"d8d8d8"].CGColor;
  145. button.layer.borderWidth = 1.0f;
  146. button.tag = idx;
  147. [button addEventHandler:^(id sender) {
  148. UIButton *button = (UIButton *)sender;
  149. self.photoType = button.tag;
  150. } forControlEvents:(UIControlEventTouchUpInside)];
  151. }];
  152. [cell6.button3 setCorner];
  153. return cell6;
  154. }
  155. cell0.textField.userInteractionEnabled = true;
  156. [cell0.textField addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
  157. cell0.textField.tag = indexPath.row;
  158. cell0.textField.keyboardType = UIKeyboardTypeDefault;
  159. cell0.label0.text = self.model.arrayTitle[indexPath.row];
  160. [cell0.textField setPlaceholder:self.model.arrayPlaceHolder[indexPath.row]];
  161. if (indexPath.row == 1) {
  162. cell1.label0.text = self.model.arrayTitle[indexPath.row];
  163. cell1.textView.text = self.model.摘要;
  164. cell1.textView.delegate = self;
  165. return cell1;
  166. }else if (indexPath.row == 5) {
  167. cell2.label0.text = self.model.arrayTitle[indexPath.row];
  168. cell0.textField.keyboardType = UIKeyboardTypeNumberPad;
  169. self.buttonVerification = cell2.button0;
  170. cell2.blockDidTouchButton = ^(UIButton * _Nonnull button) {
  171. [self NetworkOfGetCode];
  172. };
  173. cell2.textField.text = self.model.联系方式;
  174. [cell2.textField addTarget:self action:@selector(change:) forControlEvents:(UIControlEventEditingChanged)];
  175. cell2.textField.tag = 13;
  176. return cell2;
  177. }
  178. return cell0;
  179. }
  180. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  181. if (indexPath.section == 2) {
  182. if (indexPath.row == 0) {
  183. [[MOFSPickerManager shareManger] showMOFSAddressPickerWithDefaultZipcode:@"450000-450900-450921" title:@"选择地区" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString * _Nullable address, NSString * _Nullable zipcode) {
  184. self.model.验证码 = address;
  185. [self.tableView reloadRowAtIndexPath:indexPath withRowAnimation:(UITableViewRowAnimationNone)];
  186. } cancelBlock:^{
  187. }];
  188. }
  189. }
  190. }
  191. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  192. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  193. [cell setSeparatorInset:UIEdgeInsetsZero];
  194. }
  195. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  196. [cell setLayoutMargins:UIEdgeInsetsZero];
  197. }
  198. if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
  199. [cell setPreservesSuperviewLayoutMargins:NO];
  200. }
  201. }
  202. - (void)getPhoto {
  203. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  204. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  205. picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
  206. picker.delegate = self;
  207. picker.allowsEditing = YES;//取消白框
  208. UIAlertAction *camera = [UIAlertAction actionWithTitle:@"相册上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  209. [ZYCTool controller:self AlbumIsAvailable:^{
  210. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  211. [self presentViewController:picker animated:YES completion:^{}];
  212. } OrNotAvailable:^{}];
  213. }];
  214. UIAlertAction *photo = [UIAlertAction actionWithTitle:@"拍照上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  215. [ZYCTool controller:self CameraIsAvailable:^{
  216. picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  217. [self presentViewController:picker animated:YES completion:^{}];
  218. } OrNotAvailable:^{}];
  219. }];
  220. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  221. NSLog(@"点击了取消按钮");
  222. }];
  223. [cancel setValue:[UIColor redColor] forKey:@"titleTextColor"];
  224. [alert addAction:cancel];
  225. [alert addAction:camera];
  226. [alert addAction:photo];
  227. [self presentViewController:alert animated:YES completion:nil];
  228. }
  229. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  230. UIImage *selectIma = [info objectForKey:UIImagePickerControllerEditedImage];
  231. // selectIma = [selectIma fixOrientation];
  232. NSData *Data= UIImageJPEGRepresentation(selectIma, 0.3);
  233. UIImage *new = [UIImage imageWithData:Data];
  234. [self.arrayImage replaceObjectAtIndex:self.photoType withObject:new];
  235. [self.navigationController dismissViewControllerAnimated:YES completion:^{}];
  236. [self.tableView reloadData];
  237. }
  238. /**
  239. 验证码倒计时
  240. */
  241. - (void)Verification {
  242. __weak __typeof__(self) weakSelf = self;
  243. [self.buttonVerification addEventHandler:^(id sender) {
  244. if (self.model.姓名.length == 11) {
  245. __block NSInteger time = 59; //倒计时时间
  246. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  247. dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
  248. dispatch_source_set_timer(timer,DISPATCH_TIME_NOW,1.0*NSEC_PER_SEC, 0); //每秒执行
  249. dispatch_source_set_event_handler(timer, ^{
  250. if(time <= 0){ //倒计时结束,关闭
  251. dispatch_source_cancel(timer);
  252. dispatch_async(dispatch_get_main_queue(), ^{
  253. //设置按钮的样式
  254. [weakSelf.buttonVerification setTitle:@"重新获取验证码" forState:UIControlStateNormal];
  255. weakSelf.buttonVerification.userInteractionEnabled = YES;
  256. });
  257. }else{
  258. int seconds = time % 60;
  259. dispatch_async(dispatch_get_main_queue(), ^{
  260. //设置label读秒效果
  261. [weakSelf.buttonVerification setTitle:[NSString stringWithFormat:@"重新获取(%.2d)",seconds] forState:UIControlStateNormal];
  262. weakSelf.buttonVerification.userInteractionEnabled = NO;
  263. });
  264. time--;
  265. }
  266. });
  267. dispatch_resume(timer);
  268. // [self NetworkOfGetCode];
  269. }else{
  270. SHOWERROR(@"请输入手机号")
  271. }
  272. } forControlEvents:(UIControlEventTouchUpInside)];
  273. }
  274. - (void)change:(UITextField *)textField {
  275. switch (textField.tag) {
  276. case 0://关键词
  277. self.model.标题 = textField.text;
  278. break;
  279. case 2://关键词
  280. self.model.关键词 = textField.text;
  281. break;
  282. case 3://研究领域
  283. self.model.研究领域 = textField.text;
  284. break;
  285. case 4://姓名
  286. self.model.姓名 = textField.text;
  287. break;
  288. case 5://联系方式
  289. self.model.联系方式 = textField.text;
  290. break;
  291. case 6://验证码
  292. self.model.验证码 = textField.text;
  293. break;
  294. case 7://邮箱
  295. self.model.邮箱 = textField.text;
  296. break;
  297. case 8://邮编
  298. self.model.邮编= textField.text;
  299. break;
  300. case 9://联系地址
  301. self.model.联系地址 = textField.text;
  302. break;
  303. case 10://详细地址
  304. self.model.详细地址 = textField.text;
  305. break;
  306. case 11://推荐人姓名
  307. self.model.推荐人姓名 = textField.text;
  308. break;
  309. case 12://推荐人电话
  310. self.model.推荐人电话 = textField.text;
  311. break;
  312. default:
  313. break;
  314. }
  315. }
  316. - (void)textViewDidChange:(UITextView *)textView {
  317. self.model.摘要 = textView.text;
  318. }
  319. - (void)check {
  320. __block BOOL isDone = true;
  321. [self.model.arrayData enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  322. NSArray *arrayTmp = obj;
  323. [arrayTmp enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  324. NSString *string = obj;
  325. if (string.length == 0) {
  326. SHOWERROR(@"请填写相关信息")
  327. isDone = false;
  328. *stop = true;
  329. }
  330. }];
  331. }];
  332. // if (!self.isAgree) {
  333. // SHOWERROR(@"请阅读并同意相关章程")
  334. // return;
  335. // }
  336. // if (![NSString accurateVerifyIDCardNumber:self.model.研究领域]) {
  337. // SHOWERROR(@"请输入正确的身份证号")
  338. // return;
  339. // }
  340. // if (self.isAgree && isDone) {
  341. // [self NetworkOfUploadIconWithImage:self.imageIcon];
  342. // }
  343. }
  344. @end