JXPayPasswordVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //
  2. // JXPayPasswordVC.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2018/9/18.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXPayPasswordVC.h"
  9. #import "UIImage+Color.h"
  10. #import "JXMoneyMenuViewController.h"
  11. #import "JXTextField.h"
  12. #import "JXUserObject.h"
  13. #import "JXSendRedPacketViewController.h"
  14. #import "JXCashWithDrawViewController.h"
  15. #import "JXTransferViewController.h"
  16. #import "JXInputMoneyVC.h"
  17. #import "webpageVC.h"
  18. #import "JXPayViewController.h"
  19. #define kDotSize CGSizeMake (10, 10) //密码点的大小
  20. #define kDotCount 6 //密码个数
  21. #define K_Field_Height 45 //每一个输入框的高度
  22. @interface JXPayPasswordVC () <UITextFieldDelegate>
  23. @property (nonatomic, strong) JXTextField *textField;
  24. @property (nonatomic, strong) NSMutableArray *dotArray; //用于存放黑色的点点
  25. @property (nonatomic, strong) UILabel *titleLab;
  26. @property (nonatomic, strong) UILabel *detailLab;
  27. @property (nonatomic, strong) UIButton *nextBtn;
  28. @end
  29. @implementation JXPayPasswordVC
  30. - (instancetype)init {
  31. self = [super init];
  32. if (self) {
  33. self.view.backgroundColor = [UIColor whiteColor];
  34. [self setupViews];
  35. [self initPwdTextField];
  36. [self setupTitle];
  37. }
  38. return self;
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. //页面出现时让键盘弹出
  43. [self.textField becomeFirstResponder];
  44. }
  45. - (void)viewDidAppear:(BOOL)animated {
  46. [super viewDidAppear:animated];
  47. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  48. }
  49. - (void)setupViews {
  50. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, JX_SCREEN_TOP - 46, 46, 46)];
  51. [btn setBackgroundImage:[UIImage imageNamed:@"title_back_black_big"] forState:UIControlStateNormal];
  52. [btn addTarget:self action:@selector(didDissVC) forControlEvents:UIControlEventTouchUpInside];
  53. [self.view addSubview:btn];
  54. self.titleLab.frame = CGRectMake(0, 160, JX_SCREEN_WIDTH, 20);
  55. self.detailLab.frame = CGRectMake(0, CGRectGetMaxY(self.titleLab.frame)+30, JX_SCREEN_WIDTH, 17);
  56. self.textField.frame = CGRectMake(30, CGRectGetMaxY(self.detailLab.frame)+70, JX_SCREEN_WIDTH - 30*2, K_Field_Height);
  57. self.nextBtn.frame = CGRectMake(self.textField.frame.origin.x, CGRectGetMaxY(self.textField.frame)+25, JX_SCREEN_WIDTH-30*2, 40);
  58. [self.view addSubview:self.textField];
  59. [self.view addSubview:self.titleLab];
  60. [self.view addSubview:self.detailLab];
  61. [self.view addSubview:self.nextBtn];
  62. }
  63. - (void)didDissVC {
  64. if (self.type == JXPayTypeInputPassword) {
  65. [self goBackToVC];
  66. }else {
  67. [g_App showAlert:Localized(@"JX_CancelPayPsw") delegate:self];
  68. }
  69. }
  70. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
  71. if (buttonIndex == 1) {
  72. [self goBackToVC];
  73. }
  74. }
  75. - (void)setupTitle {
  76. if (self.type == JXPayTypeSetupPassword) { // 第一次设置密码
  77. [self.nextBtn setHidden:YES];
  78. self.titleLab.text = Localized(@"JX_SetPayPsw");
  79. self.detailLab.text = Localized(@"JX_SetPayPswNo.1");
  80. } else if (self.type == JXPayTypeRepeatPassword) { // 第二次设置密码
  81. [self.nextBtn setHidden:NO];
  82. self.titleLab.text = Localized(@"JX_SetPayPsw");
  83. self.detailLab.text = Localized(@"JX_SetPayPswNo.2");
  84. } else if (self.type == JXPayTypeInputPassword) { // 如果有密码,进入需要确认密码
  85. [self.nextBtn setHidden:YES];
  86. self.titleLab.text = Localized(@"JX_UpdatePassWord");
  87. self.detailLab.text = Localized(@"JX_EnterToVerify");
  88. }
  89. }
  90. - (void)didNextButton {
  91. if ([self.textField.text length] < 6) {
  92. [g_App showAlert:Localized(@"JX_PswError")];
  93. [self clearUpPassword];
  94. return;
  95. }
  96. if (![self.textField.text isEqualToString:self.lastPsw]) {
  97. [g_App showAlert:Localized(@"JX_NotMatch")];
  98. [self goToSetupTypeVCWithOld:NO];
  99. return;
  100. }
  101. if ([self.textField.text isEqualToString:self.oldPsw]) {
  102. [g_App showAlert:Localized(@"JX_NewEqualOld")];
  103. [self goToSetupTypeVCWithOld:NO];
  104. return;
  105. }
  106. if(self.type == JXPayTypeRepeatPassword) {
  107. JXUserObject *user = [[JXUserObject alloc] init];
  108. user.payPassword = self.textField.text;
  109. user.oldPayPassword = self.oldPsw;
  110. [g_server updatePayPasswordWithUser:user toView:self];
  111. }
  112. }
  113. - (void)didReceiveMemoryWarning {
  114. [super didReceiveMemoryWarning];
  115. // Dispose of any resources that can be recreated.
  116. }
  117. - (void)initPwdTextField {
  118. //每个密码输入框的宽度
  119. CGFloat width = (JX_SCREEN_WIDTH - 30*2) / kDotCount;
  120. //生成分割线
  121. for (int i = 0; i < kDotCount - 1; i++) {
  122. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.textField.frame) + (i + 1) * width, CGRectGetMinY(self.textField.frame), 0.5, K_Field_Height)];
  123. lineView.backgroundColor = [UIColor blackColor];
  124. [self.view addSubview:lineView];
  125. }
  126. self.dotArray = [[NSMutableArray alloc] init];
  127. //生成中间的点
  128. for (int i = 0; i < kDotCount; i++) {
  129. UIView *dotView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.textField.frame) + (width - kDotCount) / 2 + i * width, CGRectGetMinY(self.textField.frame) + (K_Field_Height - kDotSize.height) / 2, kDotSize.width, kDotSize.height)];
  130. dotView.backgroundColor = [UIColor blackColor];
  131. dotView.layer.cornerRadius = kDotSize.width / 2.0f;
  132. dotView.clipsToBounds = YES;
  133. dotView.hidden = YES; //先隐藏
  134. [self.view addSubview:dotView];
  135. //把创建的黑色点加入到数组中
  136. [self.dotArray addObject:dotView];
  137. }
  138. }
  139. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  140. if([string isEqualToString:@"\n"]) {
  141. //按回车关闭键盘
  142. [textField resignFirstResponder];
  143. return NO;
  144. } else if(string.length == 0) {
  145. //判断是不是删除键
  146. return YES;
  147. }
  148. else if(textField.text.length >= kDotCount) {
  149. //输入的字符个数大于6,则无法继续输入,返回NO表示禁止输入
  150. return NO;
  151. } else {
  152. return YES;
  153. }
  154. }
  155. /**
  156. * 清除密码
  157. */
  158. - (void)clearUpPassword {
  159. self.textField.text = @"";
  160. [self textFieldDidChange:self.textField];
  161. }
  162. /**
  163. * 重置显示的点
  164. */
  165. - (void)textFieldDidChange:(UITextField *)textField {
  166. for (UIView *dotView in self.dotArray) {
  167. dotView.hidden = YES;
  168. }
  169. for (int i = 0; i < textField.text.length; i++) {
  170. ((UIView *)[self.dotArray objectAtIndex:i]).hidden = NO;
  171. }
  172. if (textField.text.length >= kDotCount) {
  173. if (self.type == JXPayTypeSetupPassword) {
  174. JXPayPasswordVC *payVC = [JXPayPasswordVC alloc];
  175. payVC.delegate = self.delegate;
  176. payVC.type = JXPayTypeRepeatPassword;
  177. payVC.enterType = self.enterType;
  178. payVC.lastPsw = self.textField.text;
  179. payVC.oldPsw = self.oldPsw;
  180. payVC = [payVC init];
  181. [g_navigation pushViewController:payVC animated:YES];
  182. }else if(self.type == JXPayTypeRepeatPassword) {
  183. [self.nextBtn setUserInteractionEnabled:YES];
  184. [_nextBtn setBackgroundColor:THEMECOLOR];
  185. } else if(self.type == JXPayTypeInputPassword) {
  186. JXUserObject *user = [[JXUserObject alloc] init];
  187. user.payPassword = self.textField.text;
  188. [g_server checkPayPasswordWithUser:user toView:self];
  189. }
  190. }else {
  191. [self.nextBtn setUserInteractionEnabled:NO];
  192. [_nextBtn setBackgroundColor:[THEMECOLOR colorWithAlphaComponent:0.5]];
  193. }
  194. }
  195. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  196. [_wait stop];
  197. if([aDownload.action isEqualToString:act_UpdatePayPassword]){
  198. [self.textField resignFirstResponder];
  199. if ([self.delegate respondsToSelector:@selector(updatePayPasswordSuccess:)]) {
  200. [self.delegate updatePayPasswordSuccess:self.textField.text];
  201. }
  202. [self clearUpPassword];
  203. [g_App showAlert:Localized(@"JX_SetUpSuccess")];
  204. g_server.myself.isPayPassword = [dict objectForKey:@"payPassword"];
  205. [self goBackToVC];
  206. }
  207. if([aDownload.action isEqualToString:act_CheckPayPassword]){
  208. [self goToSetupTypeVCWithOld:YES];
  209. }
  210. }
  211. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  212. [_wait stop];
  213. return show_error;
  214. }
  215. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  216. [_wait stop];
  217. return show_error;
  218. }
  219. -(void) didServerConnectStart:(JXConnection*)aDownload{
  220. [_wait start];
  221. }
  222. - (void)goBackToVC {
  223. if (self.enterType == JXEnterTypeDefault) {
  224. [g_navigation popToViewController:[JXMoneyMenuViewController class] animated:YES];
  225. }
  226. else if (self.enterType == JXEnterTypeWithdrawal){
  227. [g_navigation popToViewController:[JXCashWithDrawViewController class] animated:YES];
  228. }
  229. else if (self.enterType == JXEnterTypeTransfer){
  230. [g_navigation popToViewController:[JXTransferViewController class] animated:YES];
  231. }
  232. else if (self.enterType == JXEnterTypeQr){
  233. [g_navigation popToViewController:[JXInputMoneyVC class] animated:YES];
  234. }
  235. else if (self.enterType == JXEnterTypeSkPay){
  236. [g_navigation popToViewController:[webpageVC class] animated:YES];
  237. }
  238. else if (self.enterType == JXEnterTypePayQr){
  239. [g_navigation popToViewController:[JXPayViewController class] animated:YES];
  240. }
  241. else {
  242. [g_navigation popToViewController:[JXSendRedPacketViewController class] animated:YES];
  243. }
  244. }
  245. - (void)goToSetupTypeVCWithOld:(BOOL)isOld {
  246. JXPayPasswordVC *payVC = [JXPayPasswordVC alloc];
  247. payVC.delegate = self.delegate;
  248. payVC.type = JXPayTypeSetupPassword;
  249. payVC.enterType = self.enterType;
  250. payVC.lastPsw = self.textField.text;
  251. // 这个是记录旧密码的
  252. payVC.oldPsw = isOld ? self.textField.text : self.oldPsw;
  253. payVC = [payVC init];
  254. [g_navigation pushViewController:payVC animated:YES];
  255. }
  256. #pragma mark - init
  257. - (UITextField *)textField {
  258. if (!_textField) {
  259. _textField = [[JXTextField alloc] init];
  260. _textField.backgroundColor = [UIColor whiteColor];
  261. _textField.textColor = [UIColor whiteColor];
  262. _textField.tintColor = [UIColor whiteColor];
  263. _textField.delegate = self;
  264. _textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
  265. _textField.keyboardType = UIKeyboardTypeNumberPad;
  266. _textField.layer.borderColor = [[UIColor blackColor] CGColor];
  267. _textField.layer.borderWidth = 0.5;
  268. [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  269. }
  270. return _textField;
  271. }
  272. - (UILabel *)titleLab {
  273. if (!_titleLab) {
  274. _titleLab = [[UILabel alloc] init];
  275. _titleLab.textAlignment = NSTextAlignmentCenter;
  276. _titleLab.font = SYSFONT(26);
  277. }
  278. return _titleLab;
  279. }
  280. - (UILabel *)detailLab {
  281. if (!_detailLab) {
  282. _detailLab = [[UILabel alloc] init];
  283. _detailLab.textAlignment = NSTextAlignmentCenter;
  284. }
  285. return _detailLab;
  286. }
  287. - (UIButton *)nextBtn {
  288. if (!_nextBtn) {
  289. _nextBtn = [[UIButton alloc] init];
  290. [_nextBtn setTitle:Localized(@"JX_Finish") forState:UIControlStateNormal];
  291. [_nextBtn setBackgroundColor:[THEMECOLOR colorWithAlphaComponent:0.6]];
  292. _nextBtn.userInteractionEnabled = NO;
  293. _nextBtn.layer.masksToBounds = YES;
  294. _nextBtn.layer.cornerRadius = 4.f;
  295. [self.nextBtn setHidden:YES];
  296. [_nextBtn addTarget:self action:@selector(didNextButton) forControlEvents:UIControlEventTouchUpInside];
  297. }
  298. return _nextBtn;
  299. }
  300. @end