BindVC.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //
  2. // BindVC.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/8/15.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "BindVC.h"
  9. #import "Tools.h"
  10. //#import <SMS_SDK/SMSSDK.h>
  11. @interface BindVC ()<UIAlertViewDelegate>
  12. {
  13. UITextField *telNumField;
  14. UITextField *bindNumField;
  15. UIButton *getBindNumBtn;
  16. UILabel *countDownLabel;
  17. NSTimer *timer;
  18. NSInteger second;
  19. }
  20. @end
  21. @implementation BindVC
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.title = @"手机绑定";
  25. self.view.backgroundColor = backGroundColor;
  26. [self configNavigationBar];
  27. [self myInit];
  28. }
  29. /**
  30. 1 每部手机只能绑定一次,绑定后本手机只能用于绑定用户实操和先学后付计时
  31. 2 绑定手机后,如因特殊情况如手机丢失,可向驾校申请,由运管审批后可以更改绑定
  32. 3 学员只有绑定后才能进行实操计时
  33. 4 绑定流程:输入手机号码-获取绑定码-确认绑定
  34. */
  35. -(void)viewWillDisappear:(BOOL)animated
  36. {
  37. [super viewWillDisappear:animated];
  38. [self.view endEditing:YES];
  39. if (timer) {
  40. [timer invalidate];
  41. timer = nil;
  42. }
  43. }
  44. -(void)configNavigationBarDismissNav
  45. {
  46. UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNav)];
  47. [backBbi setTintColor:defGreen];
  48. self.navigationController.navigationBar.translucent = NO;
  49. [self.navigationItem setLeftBarButtonItem:backBbi];
  50. }
  51. -(void)dismissNav
  52. {
  53. [self.view endEditing:YES];
  54. [self.navigationController dismissViewControllerAnimated:NO completion:nil];
  55. }
  56. -(void)myInit
  57. {
  58. UIScrollView *scrV = [[UIScrollView alloc]initWithFrame:kFrame];
  59. scrV.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  60. UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchScrollView)];
  61. [scrV addGestureRecognizer:recognizer];
  62. [self.view addSubview:scrV];
  63. CGFloat x,y,w,h;
  64. x = 20;
  65. w = kSize.width - 40;
  66. y = 20;
  67. h = 40;
  68. UITextField *textField = [[UITextField alloc] setxywh];
  69. textField.borderStyle = UITextBorderStyleNone;
  70. textField.placeholder = @"请输入手机号";
  71. textField.keyboardType = UIKeyboardTypeNumberPad;
  72. textField.backgroundColor = [UIColor clearColor];
  73. [scrV addSubview:textField];
  74. telNumField = textField;
  75. y += h + 10;
  76. x = 20;
  77. w = kSize.width - 40;
  78. h = 40;
  79. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  80. btn.frame = setDIYFrame;
  81. [btn target:self tag:1];
  82. [btn setTitle:@"点击获取验证码" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
  83. btn.backgroundColor = defGreen;
  84. [btn borderColor:defGreen width:1 cornorRadios:10];
  85. [scrV addSubview:btn];
  86. getBindNumBtn = btn;
  87. countDownLabel = [[UILabel alloc] initWithFrame:setDIYFrame];
  88. [countDownLabel setText:@"" Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  89. countDownLabel.backgroundColor = [UIColor clearColor];
  90. [scrV addSubview:countDownLabel];
  91. countDownLabel.hidden = YES;
  92. x = 20;
  93. w = kSize.width - 40;
  94. y += h + 30;
  95. h = 40;
  96. textField = [[UITextField alloc] setxywh];
  97. textField.borderStyle = UITextBorderStyleRoundedRect;
  98. textField.clearButtonMode = UITextFieldViewModeAlways;
  99. textField.placeholder = @"请输入验证码";
  100. textField.keyboardType = UIKeyboardTypeNumberPad;
  101. [scrV addSubview:textField];
  102. bindNumField = textField;
  103. y += h + 10;
  104. x = 20;
  105. w = kSize.width - 40;
  106. h = 40;
  107. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  108. btn.frame = setDIYFrame;
  109. [btn target:self tag:2];
  110. [btn setTitle:@"绑定" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
  111. btn.backgroundColor = defGreen;
  112. [btn borderColor:defGreen width:1 cornorRadios:10];
  113. [scrV addSubview:btn];
  114. y += 20 + h;
  115. h = 0;
  116. UILabel *label = [[UILabel alloc] setxywh];
  117. label.numberOfLines = 0;
  118. [label setText:@"1 每部手机只能绑定一次,绑定成功后该手机只能用于绑定用户计学时;\n2 如因特殊情况(如手机丢失),可向驾校申请重新绑定;\n3 学员只有绑定后才能进行计学时;\n4该手机号为学员报名时登记的手机号。如果手机号码有误,请联系驾校修改 \n5 绑定流程:点击获取验证码-输入验证码-点击绑定" Font:NormalFont TextColor:contentTextColor];
  119. [label sizeToFit];
  120. [scrV addSubview:label];
  121. [scrV setContentSize:CGSizeMake(0, CGRectGetMaxY(label.frame))];
  122. telNumField.text = defUser.userDict[@"telphone"];
  123. telNumField.userInteractionEnabled = NO;
  124. }
  125. -(void)btnClick:(UIButton *)sender
  126. {
  127. [self.view endEditing:YES];
  128. if (sender.tag == 1) {
  129. //获取验证码
  130. if ([Tools isMobileNumber:telNumField.text]) {
  131. [self applyAppBindStudent];
  132. }else{
  133. ShowMsg(@"请核对电话号码");
  134. }
  135. }
  136. if (sender.tag == 2) {
  137. if (telNumField.text.length < 1) {
  138. ShowMsg(@"请输入手机号获取验证码");
  139. return;
  140. }
  141. if (bindNumField.text.length < 1) {
  142. ShowMsg(@"请输入验证码!");
  143. return;
  144. }
  145. //绑定
  146. [self clickToSubmit];
  147. }
  148. }
  149. -(void)timeRun
  150. {
  151. second --;
  152. countDownLabel.text = [NSString stringWithFormat:@"重新获取验证码(%d秒)",(int)second];
  153. if (second <1) {
  154. [timer invalidate];
  155. timer = nil;
  156. [getBindNumBtn setTitle:@"点击获取验证码" forState:UIControlStateNormal];
  157. countDownLabel.hidden = YES;
  158. getBindNumBtn.userInteractionEnabled = YES;
  159. }
  160. }
  161. -(void)bindSuccessWithBlock:(BlockTypeVo)aBlock
  162. {
  163. bindBlock = aBlock;
  164. }
  165. -(void)applyAppBindStudent
  166. {
  167. // if (![Util connectedToNetWork]) {
  168. // showMsgUnconnect();
  169. // return;
  170. // }
  171. //
  172. // getBindNumBtn.userInteractionEnabled = NO;
  173. // [MBProgressHUD showLoadToView:self.view];
  174. // [RQ_SHARE_FUNCTION checkMobPolicyOnResult:^(BOOL success) {
  175. // [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:telNumField.text zone:@"86" template:nil result:^(NSError *error) {
  176. // [MBProgressHUD hideHUDForView:self.view];
  177. //
  178. // if (error)
  179. // {
  180. // if (error.code == 477) {
  181. // ShowMsg(@"当天验证次数已超上限");
  182. // }else{
  183. // ShowMsg(@"请检查手机号码是否正确");
  184. // }
  185. //
  186. // getBindNumBtn.userInteractionEnabled = YES;
  187. // return;
  188. // }
  189. // ShowMsg(@"验证码已发送。请注意查收");
  190. // second = 60;
  191. // timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
  192. // countDownLabel.hidden = NO;
  193. // [getBindNumBtn setTitle:@"" forState:UIControlStateNormal];
  194. // }];
  195. // }];
  196. }
  197. -(void)clickToSubmit
  198. {
  199. // //验证验证码是否正确
  200. // if (![Util connectedToNetWork]) {
  201. // showMsgUnconnect();
  202. // return;
  203. // }
  204. //
  205. // [MBProgressHUD showLoadToView:self.view];
  206. // [SMSSDK commitVerificationCode:bindNumField.text phoneNumber:telNumField.text zone:@"86" result:^(NSError *error) {
  207. //
  208. // if (error) {
  209. // [MBProgressHUD hideHUDForView:self.view];
  210. // ShowMsg(@"验证码错误,请重新输入验证码");
  211. // } else {
  212. // //验证成功 发起绑定
  213. // //ShowMsg(@"短信验证成功,正在进行绑定。。。");
  214. // [self uploadBindStuImei];
  215. // }
  216. // }];
  217. //
  218. }
  219. - (void)uploadBindStuImei {
  220. NSMutableArray *arr=[NSMutableArray array];
  221. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  222. [arr addPro:@"sfzhm" Value:defUser.sfzmhm];
  223. [arr addPro:@"tel" Value:telNumField.text];
  224. if ([Tools getIDFAWithType:GetIDFAType_Default]) {
  225. [arr addPro:@"imei" Value:[Tools getIDFAWithType:GetIDFAType_Default]];
  226. }else {
  227. return;
  228. }
  229. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  230. NSString* method = @"bindImei";
  231. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  232. [MBProgressHUD hideHUDForView:self.view];
  233. if (!root) {
  234. ShowMsg(@"绑定失败,请重试");
  235. return;
  236. }
  237. if ([root[@"code"] isEqualToString:@"0"]) {
  238. showMsgByAlertWithSureBlock(self, @"绑定成功", ^{
  239. [self.navigationController dismissViewControllerAnimated:NO completion:nil];
  240. if (bindBlock) {
  241. bindBlock();
  242. }
  243. });
  244. }else{
  245. showMsgByAlert(self, root[@"msg"]);
  246. }
  247. }];
  248. }
  249. -(void)touchScrollView{
  250. [self.view endEditing:YES];
  251. }
  252. - (void)didReceiveMemoryWarning {
  253. [super didReceiveMemoryWarning];
  254. }
  255. @end