ASInfomationSetController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. //
  2. // ASInfomationSetController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/7/5.
  6. //
  7. #import "ASInfomationSetController.h"
  8. #import "KWTextField.h"
  9. #import <BRPickerView/BRPickerView.h>
  10. #import "ASHomeAlertWindow.h"
  11. @interface ASInfomationSetController () <UITextFieldDelegate>
  12. /// 0: 只有邮箱 1: 邮箱加密码 2: 邮箱+验证码+密码 3 邮箱+验证码
  13. @property (nonatomic,assign) NSInteger showType;
  14. @property (nonatomic, strong) UIScrollView *scrollV;
  15. @property (nonatomic, strong) UIStackView *totalStackV;
  16. @property (nonatomic, strong) KWTextField *lastNTf;
  17. @property (nonatomic, strong) KWTextField *nameTf;
  18. @property (nonatomic, strong) KWTextField *birthTf;
  19. @property (nonatomic, strong) UIStackView *passStackV;
  20. @property (nonatomic, strong) UIButton *changePassBt;
  21. @property (nonatomic, strong) KWTextField *emailTf;
  22. @property (nonatomic, strong) KWTextField *oldPassTf;
  23. @property (nonatomic, strong) KWTextField *nPassTf;
  24. @property (nonatomic, strong) UIButton *bottomBt;
  25. @property (nonatomic, strong) NSDate *currentDate;
  26. //@property (nonatomic, strong) KWInfoSettingViewModel *vm;
  27. @end
  28. @implementation ASInfomationSetController
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. // self.vm = [KWInfoSettingViewModel new];
  32. self.titleStr = @"Information";
  33. [self setNavRightSearch:^{
  34. }];
  35. self.statusBgV.backgroundColor = Col_FFF;
  36. self.customNavBar.backgroundColor = Col_FFF;
  37. [self loadSubVs];
  38. [self setData];
  39. }
  40. - (void)setData {
  41. // KWLoginedUserModel *m = [KWLoginedManager.shareInstance getCurrentLoginedUser];
  42. //// self.userModel = m;
  43. // self.lastNTf.text = m.lastname;
  44. // self.nameTf.text = m.firstname;
  45. // self.currentDate = [NSDate dateWithString:m.dob format:@"yyyy-MM-dd HH:mm:ss"];
  46. // self.birthTf.text = [self.currentDate stringWithFormat:@"MM/dd/yyyy"];
  47. self.showType = 0;
  48. // self.emailTf.text = m.email;
  49. [self configViewsByShowType];
  50. }
  51. - (void)loadSubVs {
  52. [self.view addSubview:self.scrollV];
  53. UIStackView *tStackV = [[UIStackView alloc] init];
  54. tStackV.axis = UILayoutConstraintAxisVertical;
  55. tStackV.alignment = UIStackViewAlignmentFill;
  56. tStackV.distribution = UIStackViewDistributionFill;
  57. tStackV.spacing = 20;
  58. self.totalStackV = tStackV;
  59. UIStackView *topStackV = [[UIStackView alloc] init];
  60. topStackV.axis = UILayoutConstraintAxisHorizontal;
  61. topStackV.alignment = UIStackViewAlignmentFill;
  62. topStackV.distribution = UIStackViewDistributionFillEqually;
  63. topStackV.spacing = 20;
  64. [self.totalStackV addArrangedSubview:topStackV];
  65. NSArray *titles = @[@"First Name", @"Last Name", @"Date Of Birth"];
  66. NSArray *placeHolders = @[@"Pleace Input Name", @"Pleace Input Last Name", @"Pleace Select Date Of Birth"];
  67. for (int i = 0; i<titles.count; i++) {
  68. UILabel *lb = [[UILabel alloc] init];
  69. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  70. lb.textColor = UIColor.blackColor;
  71. KWTextField *tf = [[KWTextField alloc] init];
  72. UIStackView *stackV = [[UIStackView alloc] init];
  73. stackV.axis = UILayoutConstraintAxisVertical;
  74. stackV.alignment = UIStackViewAlignmentFill;
  75. stackV.distribution = UIStackViewDistributionFill;
  76. stackV.spacing = 5;
  77. [stackV addArrangedSubview:lb];
  78. [stackV addArrangedSubview:tf];
  79. // lb.text = titles[i];
  80. tf.placeholder = placeHolders[i];
  81. [lb mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.height.equalTo(@5);
  83. }];
  84. [tf mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.height.equalTo(@45);
  86. }];
  87. if (i == 0 || i == 1) {
  88. [topStackV addArrangedSubview:stackV];
  89. } else {
  90. [self.totalStackV addArrangedSubview:stackV];
  91. }
  92. switch (i) {
  93. case 0: {
  94. self.nameTf = tf;
  95. break;
  96. }
  97. case 1: {
  98. self.lastNTf = tf;
  99. break;
  100. }
  101. case 2: {
  102. self.birthTf = tf;
  103. break;
  104. }
  105. default:
  106. break;
  107. }
  108. }
  109. UIStackView *pStackV = [[UIStackView alloc] init];
  110. pStackV.axis = UILayoutConstraintAxisVertical;
  111. pStackV.alignment = UIStackViewAlignmentFill;
  112. pStackV.distribution = UIStackViewDistributionFillEqually;
  113. pStackV.spacing = 20;
  114. self.passStackV = pStackV;
  115. NSArray *titleArr = @[@"Email",@"",@""];
  116. NSArray *placeArr = @[@"Place Input Email",@"* OLD Password",@"* New Password"];
  117. for (int i=0; i<titleArr.count; i++) {
  118. KWTextField *tf = [[KWTextField alloc] init];
  119. UIStackView *stackV = [[UIStackView alloc] init];
  120. stackV.axis = UILayoutConstraintAxisVertical;
  121. stackV.alignment = UIStackViewAlignmentFill;
  122. stackV.distribution = UIStackViewDistributionFill;
  123. stackV.spacing = 5;
  124. if (![titleArr[i] isEqualToString:@""]) {
  125. UILabel *lb = [[UILabel alloc] init];
  126. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  127. lb.textColor = UIColor.blackColor;
  128. [stackV addArrangedSubview:lb];
  129. // lb.text = titleArr[i];
  130. [lb mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.height.equalTo(@5);
  132. }];
  133. }
  134. [stackV addArrangedSubview:tf];
  135. tf.placeholder = placeArr[i];
  136. [tf mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.height.equalTo(@45);
  138. }];
  139. tf.delegate = self;
  140. [tf addTarget:self action:@selector(textfieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  141. [tf addTarget:self action:@selector(textfieldDidChange:) forControlEvents:UIControlEventValueChanged];
  142. switch (i) {
  143. case 0: {
  144. self.emailTf = tf;
  145. [self.totalStackV addArrangedSubview:stackV];
  146. UIView *v = [UIView new];
  147. v.backgroundColor = UIColor.clearColor;
  148. [v addSubview:self.changePassBt];
  149. [self.totalStackV addArrangedSubview:v];
  150. [v mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.height.equalTo(@30);
  152. }];
  153. [self.changePassBt mas_makeConstraints:^(MASConstraintMaker *make) {
  154. make.top.left.bottom.equalTo(v);
  155. }];
  156. break;
  157. }
  158. case 1: {
  159. self.oldPassTf = tf;
  160. self.oldPassTf.secureTextEntry = true;
  161. UIView *lv = [self getPassRightBt:800000];
  162. self.oldPassTf.rightView = lv;
  163. [lv mas_makeConstraints:^(MASConstraintMaker *make) {
  164. make.width.equalTo(@50);
  165. make.height.equalTo(@45);
  166. }];
  167. self.oldPassTf.rightViewMode = UITextFieldViewModeAlways;
  168. [self.totalStackV addArrangedSubview:self.passStackV];
  169. [self.passStackV addArrangedSubview:stackV];
  170. break;
  171. }
  172. case 2: {
  173. self.nPassTf = tf;
  174. self.nPassTf.secureTextEntry = true;
  175. UIView *lv = [self getPassRightBt:800001];
  176. lv.frame = CGRectMake(0, 0, 50, 45);
  177. self.nPassTf.rightView = lv;
  178. [lv mas_makeConstraints:^(MASConstraintMaker *make) {
  179. make.width.equalTo(@50);
  180. make.height.equalTo(@45);
  181. }];
  182. self.nPassTf.rightViewMode = UITextFieldViewModeAlways;
  183. [self.passStackV addArrangedSubview:stackV];
  184. break;
  185. }
  186. default:
  187. break;
  188. }
  189. }
  190. self.passStackV.hidden = true;
  191. [self.scrollV addSubview:self.totalStackV];
  192. [self.totalStackV mas_makeConstraints:^(MASConstraintMaker *make) {
  193. make.top.equalTo(self.scrollV).offset(20);
  194. make.left.equalTo(self.scrollV).offset(20);
  195. make.right.equalTo(self.view).offset(-20);
  196. make.bottom.equalTo(self.scrollV).offset(20);
  197. make.width.equalTo([NSNumber numberWithFloat:KScreenWidth-40]);
  198. }];
  199. [self.view addSubview:self.bottomBt];
  200. [self.bottomBt mas_makeConstraints:^(MASConstraintMaker *make) {
  201. make.left.equalTo(self.view).offset(20);
  202. make.right.equalTo(self.view).offset(-20);
  203. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-20);
  204. make.height.equalTo(@45);
  205. }];
  206. [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
  207. make.left.right.equalTo(self.view);
  208. make.top.equalTo(self.customNavBar.mas_bottom);
  209. make.bottom.equalTo(self.bottomBt.mas_top).offset(-10);
  210. }];
  211. self.birthTf.delegate = self;
  212. }
  213. - (UIScrollView *)scrollV {
  214. if (!_scrollV) {
  215. UIScrollView *v = [[UIScrollView alloc] init];
  216. v.showsVerticalScrollIndicator = false;
  217. v.showsHorizontalScrollIndicator = false;
  218. v.alwaysBounceVertical = true;
  219. v.backgroundColor = [UIColor colorWithHexString:@"#f8f8f8"];
  220. _scrollV = v;
  221. }
  222. return _scrollV;
  223. }
  224. - (UIButton *)changePassBt {
  225. if (!_changePassBt) {
  226. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  227. [bt setImage:[UIImage imageNamed:@"login_selectRido"] forState:UIControlStateNormal];
  228. [bt setImage:[UIImage imageNamed:@"login_selectRido_select"] forState:UIControlStateSelected];
  229. [bt setTitle:@" Change Password" forState:UIControlStateNormal];
  230. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
  231. [bt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  232. [bt addTarget:self action:@selector(changePassTypeChanege) forControlEvents:UIControlEventTouchUpInside];
  233. _changePassBt = bt;
  234. }
  235. return _changePassBt;
  236. }
  237. - (void)changePassTypeChanege {
  238. switch (self.showType) {
  239. case 0:
  240. self.showType = 1;
  241. break;
  242. case 1:
  243. self.showType = 0;
  244. break;
  245. default:
  246. break;
  247. }
  248. [self configViewsByShowType];
  249. }
  250. - (void)configViewsByShowType {
  251. switch (self.showType) {
  252. case 0:
  253. self.changePassBt.selected = false;
  254. self.passStackV.hidden = true;
  255. [self.bottomBt setTitle:@"SAVE CHANGES" forState:UIControlStateNormal];
  256. break;
  257. case 1:
  258. self.changePassBt.selected = true;
  259. self.passStackV.hidden = false;
  260. [self.bottomBt setTitle:@"SAVE CHANGES" forState:UIControlStateNormal];
  261. break;
  262. default:
  263. break;
  264. }
  265. [self configBtState];
  266. }
  267. - (void)configBtState {
  268. switch (self.showType) {
  269. case 0:
  270. self.bottomBt.enabled = !self.emailTf.text.isEmpty && !self.nameTf.text.isEmpty && !self.lastNTf.text.isEmpty && !self.birthTf.text.isEmpty;
  271. break;
  272. case 1: {
  273. BOOL isflag = !self.emailTf.text.isEmpty && !self.oldPassTf.text.isEmpty && !self.nPassTf.text.isEmpty && !self.nameTf.text.isEmpty && !self.lastNTf.text.isEmpty && !self.birthTf.text.isEmpty;
  274. self.bottomBt.enabled = isflag;
  275. break;
  276. }
  277. default:
  278. break;
  279. }
  280. self.bottomBt.backgroundColor = self.bottomBt.isEnabled ? [UIColor blackColor] : [UIColor colorWithHexString:@"#ADADAD"];
  281. }
  282. - (UIView *)getPassRightBt:(NSInteger)tag {
  283. UIView *v = [UIView new];
  284. v.backgroundColor = UIColor.whiteColor;
  285. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  286. [bt setImage:[UIImage imageNamed:@"login_password_secure"] forState:UIControlStateNormal];
  287. [bt setImage:[UIImage imageNamed:@"login_password_secure_display"] forState:UIControlStateSelected];
  288. [bt addTarget:self action:@selector(tfBtAction:) forControlEvents:UIControlEventTouchUpInside];
  289. bt.tag = tag;
  290. [v addSubview:bt];
  291. [bt mas_makeConstraints:^(MASConstraintMaker *make) {
  292. make.width.height.equalTo(@30);
  293. make.right.equalTo(v).offset(-17);
  294. make.centerY.equalTo(v);
  295. }];
  296. return v;
  297. }
  298. - (void)tfBtAction:(UIButton *)bt {
  299. NSInteger tag = bt.tag - 800000;
  300. bt.selected = !bt.isSelected;
  301. if (tag == 0) {
  302. self.oldPassTf.secureTextEntry = !bt.isSelected;
  303. } else {
  304. self.nPassTf.secureTextEntry = !bt.isSelected;
  305. }
  306. }
  307. - (UIButton *)bottomBt {
  308. if (!_bottomBt) {
  309. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  310. [bt setTitle:@"NEXT" forState:UIControlStateNormal];
  311. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  312. [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  313. [bt setBackgroundColor:[UIColor colorWithHexString:@"#ADADAD"]];
  314. bt.layer.cornerRadius = 4;
  315. bt.layer.masksToBounds = true;
  316. bt.enabled = false;
  317. [bt addTarget:self action:@selector(bottomBtAction) forControlEvents:UIControlEventTouchUpInside];
  318. _bottomBt = bt;
  319. }
  320. return _bottomBt;
  321. }
  322. - (void)bottomBtAction {
  323. [ASHomeAlertWindow alertMsg:@"Successfully Change Information, Please Log In Again"];
  324. // KWLoginedUserModel *tempInfo = [[KWLoginedUserModel alloc] init];
  325. // tempInfo.firstname = self.nameTf.text;
  326. // tempInfo.lastname = self.lastNTf.text;
  327. // tempInfo.email = self.emailTf.text;
  328. // tempInfo.dob = self.birthTf.text;
  329. //
  330. //
  331. //
  332. // [MBProgressHUD showHUDAddedTo:self.view animated:true];
  333. // @weakify(self);
  334. // [self.vm editUserInfo:tempInfo changePass:[NSString stringWithFormat:@"%ld", self.showType] oldPass:self.oldPassTf.text nPass:self.nPassTf.text complate:^(BOOL flag, NSString * _Nonnull msg) {
  335. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  336. // if (!flag) {
  337. // [weak_self.view makeToast:msg];
  338. // } else {
  339. // [weak_self.view makeToast:@"Save Successed"];
  340. // [weak_self.navigationController popViewControllerAnimated:true];
  341. // }
  342. // }];
  343. }
  344. - (void)textfieldDidChange:(UITextField *)tf {
  345. [self configBtState];
  346. }
  347. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  348. if ([self.birthTf isEqual:textField]) {
  349. BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
  350. datePickerView.pickerMode = BRDatePickerModeDate;
  351. datePickerView.title = @"Please Select The Date Of Birth";
  352. datePickerView.selectDate = self.currentDate;
  353. datePickerView.minDate = [NSDate br_setYear:1900 month:1 day:1];
  354. datePickerView.maxDate = [NSDate date];
  355. datePickerView.isAutoSelect = YES;
  356. @weakify(self);
  357. datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
  358. weak_self.currentDate = selectDate;
  359. NSDateFormatter *formartter= [[NSDateFormatter alloc]init];
  360. [formartter setDateFormat:@"MM/dd/yyyy"];
  361. NSString *currentDateStr = [formartter stringFromDate:selectDate];
  362. weak_self.birthTf.text = currentDateStr;
  363. [weak_self configBtState];
  364. NSLog(@"selectValue=%@", selectValue);
  365. NSLog(@"selectDate=%@", selectDate);
  366. NSLog(@"---------------------------------");
  367. };
  368. [datePickerView show];
  369. return false;
  370. }
  371. return true;
  372. }
  373. @end