SignUpVC.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. //
  2. // SignUpVC.m
  3. // LN_School
  4. //
  5. // Created by apple on 2017/4/11.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "SignUpVC.h"
  9. #import "applyCell.h"
  10. #import "PureCamera.h"
  11. #import "PhotosUploadViewController.h"
  12. @interface SignUpVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIActionSheetDelegate,UINavigationControllerDelegate>
  13. {
  14. UITableView *mainTableView;
  15. NSMutableArray *titleArray;
  16. NSArray *dataArray;
  17. NSArray *sheetsArray;
  18. NSString *bustype;
  19. }
  20. @property (nonatomic, strong) NSString *headImgPath;
  21. @property (nonatomic, strong) NSMutableArray *protocolImgArr;
  22. @property (nonatomic, strong) NSMutableArray *protocolImgPathArr;
  23. @end
  24. @implementation SignUpVC
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self myInit];
  28. }
  29. -(void)myInit
  30. {
  31. [self setTitle:@"学员报名"];
  32. self.view.backgroundColor = KBackGroundColor;
  33. [self goBackByNavigation];
  34. //报名类型 默认为 初领
  35. bustype = @"0";
  36. //@RQ-MARK 1.0.2修改:“学员报名”模块新增 协议上传(上传多张)
  37. NSArray *array = @[@[@"培训车型",@"证件类型",@"报名类型",@"获取照片"],@[@"协议上传"],@[@"姓名",@"性别",@"证件号码",@"手机号码",@"地址"],@[@"推荐人"]];
  38. titleArray = [NSMutableArray arrayWithArray:array];
  39. dataArray = @[[NSMutableArray arrayWithArray:@[@"C1-小型汽车 >",@"身份证 >",@"初领 >",@"点击拍照 >"]],[NSMutableArray arrayWithArray:@[@"请上传协议 >"]],[NSMutableArray arrayWithArray:@[@"请输入姓名",@"请输入性别",@"请输入证件号码",@"请输入手机号码",@"请输入地址"]],[NSMutableArray arrayWithArray:@[@"请输入推荐人"]],[NSMutableArray arrayWithArray:@[@"请输入原车型(例如:C1)",@"请输入原驾驶证号",@"请输入初领证日期"]]];
  40. mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped];
  41. mainTableView.height -= kNavOffSet;
  42. mainTableView.estimatedSectionHeaderHeight = 0;
  43. mainTableView.estimatedSectionFooterHeight = 0;
  44. [mainTableView setDelegate:self];
  45. [mainTableView setDataSource:self];
  46. [self.view addSubview:mainTableView];
  47. // UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  48. // mainTableView.tableHeaderView = view;
  49. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 100)];
  50. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, kSize.width - 20, 50)];
  51. btn.backgroundColor = RQMianColor;
  52. [btn borderCornorRadios:5];
  53. [btn setTitle:@"提交" textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal];
  54. [btn target:self Tag:1];
  55. [view addSubview:btn];
  56. mainTableView.tableFooterView = view;
  57. }
  58. - (void)btnClick:(UIButton *)sender
  59. {
  60. if (sender.tag == 1) {
  61. //提交
  62. [self.view endEditing:YES];
  63. // [mainTableView setEditing:YES];
  64. // [sender becomeFirstResponder];
  65. [self addStudent];
  66. }
  67. }
  68. #pragma mark 拍照
  69. - (void)takePhoto { //100*120
  70. [RQ_SHARE_FUNCTION showAlertWithTitle:@"请选择获取图片方式" message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:@[@"拍照", @"本地照片"] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
  71. if (selectedOtherButtonIndex == 0) {
  72. [RQ_SHARE_FUNCTION getPhotosWithGetPhotosWay:GetPhotosWay_Camera size:CGSizeMake(100, 120) maxLength:100 maxImagesCount:1 photosBlock:^(NSArray * _Nonnull imagesArr, NSArray * _Nonnull imagesDataStrArr) {
  73. if (imagesDataStrArr.count > 0) {
  74. [self uploadHeadImg:imagesDataStrArr.firstObject];
  75. }
  76. }];
  77. }else if (selectedOtherButtonIndex == 1) {
  78. [RQ_SHARE_FUNCTION getPhotosWithGetPhotosWay:GetPhotosWay_Album size:CGSizeMake(100, 120) maxLength:100 maxImagesCount:1 photosBlock:^(NSArray * _Nonnull imagesArr, NSArray * _Nonnull imagesDataStrArr) {
  79. [self uploadHeadImg:imagesDataStrArr.firstObject];
  80. }];
  81. }
  82. }];
  83. }
  84. - (void)choosePhotos {
  85. [self navPushHideTabbarToVC:[[PhotosUploadViewController alloc] initWithNibName:@"PhotosUploadViewController" bundle:nil imagesArr:self.protocolImgArr imagesPathArr:self.protocolImgPathArr returnImagesBlock:^(NSMutableArray * _Nonnull imagesArr, NSMutableArray * _Nonnull imagesPathArr) {
  86. _protocolImgArr = imagesArr;
  87. _protocolImgPathArr = imagesPathArr;
  88. NSMutableArray *array = dataArray[1];
  89. [array replaceObjectAtIndex:0 withObject:@"上传协议成功,点击重新上传 >"];
  90. NSIndexPath *indexpath = [NSIndexPath indexPathForRow:0 inSection:1];
  91. [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
  92. }]];
  93. }
  94. #pragma mark - tableview delegate
  95. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  96. {
  97. return titleArray.count;
  98. }
  99. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  100. {
  101. return [titleArray[section] count];
  102. }
  103. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  104. {
  105. applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  106. if (cell == nil)
  107. {
  108. cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  109. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  110. }
  111. [cell.titLabel setText:[titleArray[indexPath.section] objectAtIndex:indexPath.row]];
  112. NSArray *detailArray = dataArray[indexPath.section];
  113. cell.detailField.delegate = self;
  114. cell.detailField.tag = indexPath.section * 10 + indexPath.row;
  115. if (indexPath.section == 0 || indexPath.section == 1)
  116. {
  117. cell.detailField.userInteractionEnabled = NO;
  118. cell.detailField.textColor = RQMianColor;
  119. cell.detailField.text = detailArray[indexPath.row];
  120. }else {
  121. if (indexPath.section == 2 ) {
  122. if(indexPath.row==2 || indexPath.row==3) {
  123. cell.detailField.keyboardType = UIKeyboardTypeNumberPad;
  124. }
  125. }
  126. cell.detailField.userInteractionEnabled = YES;
  127. NSArray *array = @[@"请输入姓名",@"请输入性别",@"请输入证件号码",@"请输入手机号码",@"请输入地址",@"请输入推荐人",@"请输入原车型(例如:C1)",@"请输入原驾驶证号",@"请输入初领证日期"];
  128. if ([array containsObject:detailArray[indexPath.row]]) {
  129. cell.detailField.text = @"";
  130. cell.detailField.placeholder = detailArray[indexPath.row];
  131. }else {
  132. cell.detailField.textColor = KTitleColor;
  133. cell.detailField.text = detailArray[indexPath.row];
  134. }
  135. }
  136. return cell;
  137. }
  138. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  139. {
  140. [self.view endEditing:YES];
  141. if (indexPath.section == 0)
  142. {
  143. if (indexPath.row == 3) {
  144. //拍照
  145. [self takePhoto];
  146. return;
  147. }
  148. UIActionSheet *myActionSheet;
  149. if (indexPath.row == 0) {
  150. sheetsArray = @[@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车"];
  151. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车", nil];
  152. }else if (indexPath.row == 1) {
  153. sheetsArray = @[@"身份证",@"护照",@"军官证",@"其它"];
  154. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"身份证",@"护照",@"军官证",@"其它", nil];
  155. }else if (indexPath.row == 2) {
  156. sheetsArray = @[@"初领-0",@"增驾-1",@"其它-9"];
  157. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"初领",@"增驾",@"其它", nil];
  158. }
  159. myActionSheet.tag = indexPath.row;
  160. [myActionSheet showInView:self.view];
  161. }else if (indexPath.section == 1) {
  162. if (indexPath.row == 0) {
  163. [self choosePhotos];
  164. }
  165. }
  166. }
  167. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  168. {
  169. return .1;
  170. }
  171. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  172. {
  173. return 25;
  174. }
  175. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  176. //NSLog(@"1");
  177. [self.view endEditing:YES];
  178. }
  179. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  180. {
  181. if (buttonIndex == actionSheet.cancelButtonIndex) {
  182. return;
  183. }
  184. NSMutableArray *array = [dataArray firstObject];
  185. NSString *detailString = sheetsArray[buttonIndex];
  186. if (actionSheet.tag == 2) { //报名类型
  187. detailString = [[sheetsArray[buttonIndex] componentsSeparatedByString:@"-"] firstObject];
  188. bustype = [[sheetsArray[buttonIndex] componentsSeparatedByString:@"-"] lastObject];
  189. if ([bustype isEqualToString:@"1"]) { //mainTableView新增一个section
  190. [titleArray addObject:@[@"原车型",@"原驾驶证号",@"初领证日期"]];
  191. [array replaceObjectAtIndex:actionSheet.tag withObject:[NSString stringWithFormat:@"%@ >",detailString]];
  192. [mainTableView reloadData];
  193. return;
  194. }else{
  195. if (titleArray.count > 3) {
  196. [titleArray removeLastObject];
  197. }
  198. }
  199. }
  200. [array replaceObjectAtIndex:actionSheet.tag withObject:[NSString stringWithFormat:@"%@ >",detailString]];
  201. // NSIndexPath *indexpath = [NSIndexPath indexPathForRow:actionSheet.tag inSection:0];
  202. // [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
  203. [mainTableView reloadData];//上面方法二次调用引起崩溃
  204. }
  205. #pragma mark textField
  206. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  207. {
  208. NSIndexPath *indexpath = indexpath= [NSIndexPath indexPathForRow:textField.tag%10 inSection:textField.tag/10];;
  209. //获取当前cell在tableview中的位置
  210. CGRect rectintableview=[mainTableView rectForRowAtIndexPath:indexpath];
  211. [mainTableView setContentOffset:CGPointMake(mainTableView.contentOffset.x,rectintableview.origin.y-25) animated:YES];
  212. return YES;
  213. }
  214. -(BOOL)textFieldShouldEndEditing:(UITextField *)textField
  215. {
  216. NSString *textString = textField.text;
  217. NSMutableArray *array = dataArray[textField.tag/10];
  218. [array replaceObjectAtIndex:textField.tag%10 withObject:textString];
  219. [mainTableView reloadData];
  220. return YES;
  221. }
  222. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  223. {
  224. [textField endEditing:YES];
  225. return YES;
  226. }
  227. #pragma mark 数据请求
  228. - (void)uploadHeadImg:(NSString *)image
  229. {
  230. if (![NetManager connectedToNetWork]) {
  231. showMsgUnconnect();
  232. return;
  233. }
  234. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  235. [dic setObject:image forKey:@"content"];
  236. [dic setObject:@"" forKey:@"keyword"];
  237. [dic setObject:@"2" forKey:@"type"];
  238. NSString *method = @"upload-2";
  239. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  240. if (!root) {
  241. [self showUPloadImgAlertWithImg:image];
  242. return;
  243. }
  244. if ([root[@"code"] isEqualToString:@"1"]) {
  245. [self showUPloadImgAlertWithImg:image];
  246. return;
  247. }
  248. //上传头像成功
  249. _headImgPath = root[@"body"];
  250. NSMutableArray *array = [dataArray firstObject];
  251. [array replaceObjectAtIndex:3 withObject:@"拍照成功,点击重拍 >"];
  252. NSIndexPath *indexpath = [NSIndexPath indexPathForRow:3 inSection:0];
  253. [mainTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexpath,nil] withRowAnimation:UITableViewRowAnimationNone];
  254. }];
  255. }
  256. - (void)showUPloadImgAlertWithImg:(NSString *)image {
  257. [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:@"图片上传失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"再试一次"] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
  258. if (selectedOtherButtonIndex == 0) {
  259. [self uploadHeadImg:image];
  260. }
  261. }];
  262. }
  263. -(void)addStudent
  264. {
  265. if (_headImgPath.length < 1) {
  266. ShowMsg(@"请采集照片");
  267. _headImgPath = @"";
  268. return;
  269. }
  270. if (!_protocolImgPathArr || _protocolImgPathArr.count == 0) {
  271. ShowMsg(@"请上传协议");
  272. _protocolImgPathArr = [NSMutableArray array];
  273. return;
  274. }
  275. NSInteger num = 4;
  276. if ([bustype isEqualToString:@"1"]) {
  277. num = 5;
  278. }
  279. NSString *name, *idcard, *sex, *phone, *source, *cardtype, *traintype, *perdritype, *drilicnum, *fstdrilicdate, *address;
  280. name=idcard=sex=phone=source=cardtype=traintype=perdritype=drilicnum=fstdrilicdate=address = @"";
  281. for (int i = 0; i < num; i ++) {
  282. NSMutableArray *array = dataArray[i];
  283. for (int j = 0; j < array.count; j ++) {
  284. NSString *string = array[j];
  285. if ([string containsString:@"请输入"] || string.length == 0) {
  286. ShowMsg(@"您还有信息未录入");
  287. return;
  288. }
  289. switch (i) {
  290. case 0:
  291. if (j == 0) {
  292. traintype = [[string componentsSeparatedByString:@"-"] firstObject];
  293. }else if (j == 1) {
  294. cardtype = [[string componentsSeparatedByString:@" "] firstObject];
  295. //@[@"身份证",@"护照",@"军官证",@"其他"];
  296. if ([cardtype isEqualToString:@"身份证"]) {
  297. cardtype = @"1";
  298. }
  299. if ([cardtype isEqualToString:@"护照"]) {
  300. cardtype = @"2";
  301. }
  302. if ([cardtype isEqualToString:@"军官证"]) {
  303. cardtype = @"3";
  304. }
  305. if ([cardtype isEqualToString:@"其它"]) {
  306. cardtype = @"4";
  307. }
  308. }
  309. break;
  310. case 2:
  311. if (j == 0) {
  312. name = string;
  313. }
  314. if (j == 1) {
  315. if (![string isEqualToString:@"男"] && ![string isEqualToString:@"女"]) {
  316. ShowMsg(@"性别输入错误");
  317. return;
  318. }
  319. sex = [string isEqualToString:@"男"]?@"1":@"2";
  320. }
  321. if (j == 2) {
  322. idcard = string;
  323. }
  324. if (j == 3) {
  325. if (![Tools isMobileNumber:string]) {
  326. ShowMsg(@"请输入正确的手机号码");
  327. return;
  328. }
  329. phone = string;
  330. }
  331. if (j == 4) {
  332. address = string;
  333. }
  334. break;
  335. case 3:
  336. source = string;
  337. break;
  338. case 4:
  339. if (j == 0) {
  340. perdritype = string;
  341. }
  342. if (j == 1) {
  343. drilicnum = string;
  344. }
  345. if (j == 2) {
  346. fstdrilicdate = string;
  347. }
  348. break;
  349. default:
  350. break;
  351. }
  352. }
  353. }
  354. if (![NetManager connectedToNetWork]) {
  355. showMsgUnconnect();
  356. return;
  357. }
  358. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  359. [dic setObject:defUser.userDict[@"id"] forKey:@"userId"];
  360. [dic setObject:name forKey:@"name"];
  361. [dic setObject:idcard forKey:@"idcard"];
  362. [dic setObject:sex forKey:@"sex"];
  363. [dic setObject:phone forKey:@"phone"];
  364. [dic setObject:source forKey:@"source"];
  365. [dic setObject:bustype forKey:@"bustype"];
  366. [dic setObject:traintype forKey:@"traintype"];
  367. [dic setObject:perdritype forKey:@"perdritype"];
  368. [dic setObject:drilicnum forKey:@"drilicnum"];
  369. [dic setObject:fstdrilicdate forKey:@"fstdrilicdate"];
  370. [dic setObject:address forKey:@"address"];
  371. [dic setObject:_headImgPath forKey:@"photo"];
  372. [dic setObject:cardtype forKey:@"cardtype"];
  373. [dic setObject:[_protocolImgPathArr componentsJoinedByString:@","] forKey:@"pactPath"];
  374. NSString *method = @"addStudent";
  375. [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) {
  376. if (!root) {
  377. ShowMsg(@"提交失败,请重试");
  378. return;
  379. }
  380. if ([root[@"code"] isEqualToString:@"1"]) {
  381. ShowMsg(root[@"msg"]);
  382. return;
  383. }
  384. ShowMsg(@"报名成功!");
  385. [self.navigationController popViewControllerAnimated:YES];
  386. }];
  387. }
  388. #pragma mark - 限制输入字符
  389. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  390. NSCharacterSet *cs;
  391. //invertedSet方法是去反字符,把所有的除了NUMBERS 里的字符都找出来(包含去空格功能)
  392. cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789n"]invertedSet];
  393. // componentsJoinedByString 用于根据一个字符串来将数组连接成一个新的字符串。
  394. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
  395. BOOL canChange = [string isEqualToString:filtered];
  396. if (textField.tag == 12 || textField.tag == 13) {
  397. return canChange;
  398. }
  399. return YES;
  400. //这样写了以后,输入非数字时不能输入
  401. }
  402. - (void)didReceiveMemoryWarning {
  403. [super didReceiveMemoryWarning];
  404. }
  405. @end