ASInfomationSetController.m 15 KB

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