ApplyVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. //
  2. #import "ApplyVC.h"
  3. #import "STButton.h"
  4. #import "applyCell.h"
  5. //#import <SMS_SDK/SMSSDK.h>
  6. @interface ApplyVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIActionSheetDelegate>
  7. {
  8. NSArray* titles;
  9. NSArray *sheetsArray;
  10. NSInteger sheetNow;
  11. UITextField *tfNow;
  12. UITextField *carField;
  13. UITextField *identField;
  14. UITextField *nameField;
  15. UITextField *identHMField;
  16. UITextField *dhField;
  17. UITextField *iponeField;
  18. UITextField *addressField;
  19. UITextField *submitField;
  20. }
  21. @end
  22. @implementation ApplyVC
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self myInit];
  26. }
  27. - (void)didReceiveMemoryWarning {
  28. [super didReceiveMemoryWarning];
  29. // Dispose of any resources that can be recreated.
  30. }
  31. #pragma mark -
  32. -(void)myInit
  33. {
  34. [self configNavigationBar];
  35. [self.view setBackgroundColor:[UIColor whiteColor]];
  36. [self setTitle:@"报名"];
  37. self.navigationController.navigationBar.translucent = NO;
  38. CGFloat x,y,w,h;
  39. UITableView* tv = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStyleGrouped];
  40. [tv setContentInset:UIEdgeInsetsMake(0, 0, kSize.height/2, 0)];
  41. tv.height -= kNavOffSet;
  42. [self.view addSubview:tv];
  43. [tv setDelegate:self];
  44. [tv setDataSource:self];
  45. tv.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  46. titles = @[@[@"车型",@"证件类型"],@[@"姓名",@"证件号码",@"电话",@"手机",@"地址"],/*@[@"验证码"]*/];
  47. x = 0;
  48. h = 60;
  49. w = kSize.width;
  50. y = kSize.height - h - kNavOffSet - kSafeAreaBottomHeight;
  51. UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  52. [vi setBackgroundColor:backGroundColor];
  53. vi.layer.borderWidth = .5;
  54. vi.layer.borderColor = KlineColor.CGColor;
  55. [self.view addSubview:vi];
  56. STButton* stBtn = [[STButton alloc] initWithFrame:CGRectMake((kSize.width - 100)/2.0, 0, 100, h)];
  57. [stBtn setImage:[UIImage imageNamed:@"question_correct"] withTitle:@"提交" Font:SmallFont forState:UIControlStateNormal];
  58. [stBtn addTarget:self action:@selector(clickToSubmit) forControlEvents:UIControlEventTouchUpInside];
  59. [stBtn setStyle:1];
  60. [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  61. [vi addSubview:stBtn];
  62. }
  63. -(void)clickToSubmitNumber
  64. {
  65. // if ([iponeField.text isEqualToString:@""] || [identHMField.text isEqualToString:@""])
  66. // {
  67. // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"手机号码或者证件号码为空!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  68. // [alert show];
  69. // return;
  70. // }
  71. //
  72. // if (![Util connectedToNetWork]) {
  73. // showMsgUnconnect();
  74. // return;
  75. // }
  76. //
  77. // //获取验证码
  78. // [MBProgressHUD showLoadToView:self.view];
  79. // [RQ_SHARE_FUNCTION checkMobPolicyOnResult:^(BOOL success) {
  80. // //获取验证码
  81. // [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:iponeField.text zone:@"86" template:nil result:^(NSError *error) {
  82. // [MBProgressHUD hideHUDForView:self.view];
  83. // if (error) {
  84. // if (error.code == 477) {
  85. // ShowMsg(@"当天验证次数已超上限");
  86. // }else{
  87. // ShowMsg(@"请检查手机号码是否正确");
  88. // }
  89. // return;
  90. // }
  91. // [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"验证码已发送" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil];
  92. // }];
  93. // }];
  94. }
  95. -(void)clickToSubmit
  96. {
  97. if ([nameField.text isEqualToString:@""] || [identHMField.text isEqualToString:@""] || [addressField.text isEqualToString:@""] || [iponeField.text isEqualToString:@""] || [submitField.text isEqualToString:@""])
  98. {
  99. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"信息不完整,请您完善信息" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  100. [alert show];
  101. return;
  102. }
  103. if ([identField.text containsString:@"身份证"]) {
  104. //身份证验证
  105. NSString *regex2 = @"^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$";
  106. NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex2];
  107. if (![regextestmobile evaluateWithObject:identHMField.text]) {
  108. ShowMsg(@"请输入正确的身份证号码");
  109. return;
  110. }
  111. }
  112. NSString * mobil = @"^1(3[0-9]|4[579]|5[0-35-9]|7[01356]|8[0-9])\\d{8}$";
  113. NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mobil];
  114. if (![regextestmobile evaluateWithObject:iponeField.text]) {
  115. ShowMsg(@"请输入正确的手机号");
  116. return;
  117. }
  118. if ([carField.text isEqualToString:@"C1-小型汽车 >"])
  119. {
  120. carField.text = @"C1-小型汽车";
  121. }
  122. if ([identField.text isEqualToString:@"身份证 >"])
  123. {
  124. identField.text = @"身份证";
  125. }
  126. [self submit];
  127. // //验证验证码是否过期
  128. // if (![Util connectedToNetWork]) {
  129. // showMsgUnconnect();
  130. // return;
  131. // }
  132. //
  133. // //验证验证码
  134. // [MBProgressHUD showLoadToView:self.view];
  135. // [SMSSDK commitVerificationCode:submitField.text phoneNumber:iponeField.text zone:@"86" result:^(NSError *error) {
  136. //
  137. // [MBProgressHUD hideHUDForView:self.view];
  138. // if (error) {
  139. // //NSLog(@"验证码有误");
  140. // ShowMsg(@"请输入正确验证码");
  141. // } else {
  142. // //NSLog(@"验证成功");
  143. // [self submit];
  144. // }
  145. // }];
  146. }
  147. -(void)submit
  148. {
  149. //NSLog(@"提交报名信息");
  150. NSMutableArray *arr=[NSMutableArray array];
  151. [arr addPro:@"name" Value:nameField.text];
  152. [arr addPro:@"zjlx" Value:identField.text];
  153. [arr addPro:@"zjhm" Value:[identHMField.text uppercaseString]];
  154. [arr addPro:@"pxcx" Value:[carField.text substringToIndex:2]];
  155. [arr addPro:@"lxdz" Value:addressField.text];
  156. [arr addPro:@"mobile" Value:iponeField.text];
  157. [arr addPro:@"tel" Value:dhField.text];
  158. [arr addPro:@"jxbh" Value:self.jxbh];
  159. [arr addPro:@"jxmc" Value:self.jxmc];//已经改了,字段里是name
  160. [arr addPro:@"source" Value:@"3"];
  161. [arr addPro:@"code" Value:submitField.text];
  162. NSString* method = @"uploadStuSignInfo";
  163. [MBProgressHUD showLoadToView:self.view];
  164. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  165. [MBProgressHUD hideHUDForView:self.view];
  166. if (!root)
  167. {
  168. ShowMsgFailed();
  169. return;
  170. }
  171. if ( 1 == [root[@"code"] integerValue]) {
  172. ShowMsg(@"请勿重复报名!");
  173. return;
  174. }
  175. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"提交成功!" preferredStyle:UIAlertControllerStyleAlert];
  176. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  177. [self.navigationController popViewControllerAnimated:YES];
  178. }]];
  179. [self presentViewController:alertFind animated:true completion:nil];
  180. }];
  181. }
  182. #pragma mark - tableview delegate
  183. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  184. {
  185. return .1;
  186. }
  187. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  188. {
  189. return 25;
  190. }
  191. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  192. {
  193. // if (section == 0 || section == 1)
  194. // {
  195. UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
  196. return v;
  197. // }
  198. // else
  199. // {
  200. // UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 25)];
  201. // btn.backgroundColor = [UIColor clearColor];
  202. // [btn.titleLabel setFont:[UIFont scaleSize:14]];
  203. // [btn setTitle:@"点击获取验证码" forState:UIControlStateNormal];
  204. // [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
  205. // [btn addTarget:self action:@selector(clickToSubmitNumber) forControlEvents:UIControlEventTouchUpInside];
  206. // return btn;
  207. // }
  208. }
  209. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  210. {
  211. return [titles[section] count];
  212. }
  213. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  214. {
  215. return 3;
  216. }
  217. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  218. {
  219. applyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  220. if (cell == nil)
  221. {
  222. cell = [[applyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  223. }
  224. NSArray* secArr = titles[indexPath.section];
  225. [cell.titLabel setText:secArr[indexPath.row]];
  226. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  227. cell.detailField.delegate = self;
  228. if (indexPath.section == 0)
  229. {
  230. cell.detailField.userInteractionEnabled = NO;
  231. cell.detailField.textColor = defGreen;
  232. if (indexPath.row == 0)
  233. {
  234. cell.detailField.text = @"C1-小型汽车 >";
  235. carField = cell.detailField;
  236. }
  237. else
  238. {
  239. cell.detailField.text = @"身份证 >";
  240. identField = cell.detailField;
  241. }
  242. }
  243. if (indexPath.section == 1)
  244. {
  245. cell.detailField.userInteractionEnabled = YES;
  246. cell.detailField.textColor = kTitleColor;
  247. if (indexPath.row == 0)
  248. {
  249. cell.detailField.placeholder = @"姓名";
  250. nameField = cell.detailField;
  251. }
  252. else if (indexPath.row == 1)
  253. {
  254. cell.detailField.placeholder = @"证件号码";
  255. cell.detailField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  256. identHMField = cell.detailField;
  257. }
  258. else if (indexPath.row == 2)
  259. {
  260. cell.detailField.placeholder = @"固定号码";
  261. cell.detailField.keyboardType = UIKeyboardTypePhonePad;
  262. dhField = cell.detailField;
  263. }
  264. else if (indexPath.row == 3)
  265. {
  266. cell.detailField.placeholder = @"手机号码";
  267. cell.detailField.keyboardType = UIKeyboardTypePhonePad;
  268. iponeField = cell.detailField;
  269. }
  270. else
  271. {
  272. cell.detailField.placeholder = @"联系地址";
  273. addressField = cell.detailField;
  274. }
  275. }
  276. // if (indexPath.section == 2)
  277. // {
  278. // cell.detailField.userInteractionEnabled = YES;
  279. // cell.detailField.textColor = kTitleColor;
  280. // cell.detailField.placeholder = @"请输入验证码";
  281. // cell.detailField.keyboardType = UIKeyboardTypePhonePad;
  282. // submitField = cell.detailField;
  283. // }
  284. return cell;
  285. }
  286. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  287. {
  288. if (indexPath.section == 0)
  289. {
  290. UIActionSheet *myActionSheet;
  291. if (indexPath.row == 0)
  292. {
  293. sheetNow = 0;
  294. sheetsArray = @[@"A1-大型客车", @"A2-牵引车",@"A3-城市公交车",@"B1-中型客车",@"B2-大型货车",@"C1-小型汽车",@"C2-小型自动挡汽车",@"C3-低速载货汽车",@"C4-三轮汽车",@"C5-残疾人专用小型自动挡载客汽车",@"D-普通三轮摩托车",@"E-普通二轮摩托车",@"F-轻便摩托车",@"M-轮式自行机械车",@"N-无轨电车",@"P-有轨电车"];
  295. 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];
  296. }
  297. else
  298. {
  299. sheetNow = 1;
  300. sheetsArray = @[@"身份证",@"军官证",@"士兵证",@"军官离退休证",@"境外人员身份证明",@"外交人员身份证明"];
  301. myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"身份证",@"军官证",@"士兵证",@"军官离退休证",@"境外人员身份证明",@"外交人员身份证明", nil];
  302. }
  303. [myActionSheet showInView:self.view];
  304. }
  305. else
  306. {
  307. if (tfNow)
  308. {
  309. [tfNow resignFirstResponder];
  310. }
  311. }
  312. }
  313. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  314. [self.view endEditing:YES];
  315. }
  316. #pragma mark -
  317. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  318. {
  319. if (buttonIndex == actionSheet.cancelButtonIndex)
  320. {
  321. return;
  322. }
  323. if (sheetNow == 0)
  324. {
  325. carField.text = sheetsArray[buttonIndex];
  326. }
  327. else
  328. {
  329. identField.text = sheetsArray[buttonIndex];
  330. }
  331. }
  332. -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  333. {
  334. tfNow = textField;
  335. return YES;
  336. }
  337. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  338. {
  339. [textField endEditing:YES];
  340. return YES;
  341. }
  342. @end