123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- //
- // ASInfomationSetController.m
- // Asteria
- //
- // Created by iOS on 2023/7/5.
- //
- #import "ASInfomationSetController.h"
- #import "KWTextField.h"
- #import <BRPickerView/BRPickerView.h>
- #import "ASHomeAlertWindow.h"
- @interface ASInfomationSetController () <UITextFieldDelegate>
- /// 0: 只有邮箱 1: 邮箱加密码 2: 邮箱+验证码+密码 3 邮箱+验证码
- @property (nonatomic,assign) NSInteger showType;
- @property (nonatomic, strong) UIScrollView *scrollV;
- @property (nonatomic, strong) UIStackView *totalStackV;
- @property (nonatomic, strong) KWTextField *lastNTf;
- @property (nonatomic, strong) KWTextField *nameTf;
- @property (nonatomic, strong) KWTextField *birthTf;
- @property (nonatomic, strong) UIStackView *passStackV;
- @property (nonatomic, strong) UIButton *changePassBt;
- @property (nonatomic, strong) KWTextField *emailTf;
- @property (nonatomic, strong) KWTextField *oldPassTf;
- @property (nonatomic, strong) KWTextField *nPassTf;
- @property (nonatomic, strong) UIButton *bottomBt;
- @property (nonatomic, strong) NSDate *currentDate;
- //@property (nonatomic, strong) KWInfoSettingViewModel *vm;
- @end
- @implementation ASInfomationSetController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // self.vm = [KWInfoSettingViewModel new];
- self.titleStr = @"Information";
- [self setNavRightSearch:^{
-
- }];
-
- self.statusBgV.backgroundColor = Col_FFF;
- self.customNavBar.backgroundColor = Col_FFF;
-
- [self loadSubVs];
-
- [self setData];
-
- }
- - (void)setData {
- ASUserModel *m = ASUserInfoManager.shared.userInfo;
- NSString *bob = ASUserInfoManager.shared.birthDay;
- self.lastNTf.text = m.lastname;
- self.nameTf.text = m.firstname;
- self.currentDate = [NSDate dateWithString:bob format:@"MM dd, yyyy"];
- self.birthTf.text = [self.currentDate stringWithFormat:@"MM/dd/yyyy"];
-
- self.showType = 0;
-
- self.emailTf.text = m.email;
- [self configViewsByShowType];
-
- }
- - (void)loadSubVs {
-
- [self.view addSubview:self.scrollV];
-
-
- UIStackView *tStackV = [[UIStackView alloc] init];
- tStackV.axis = UILayoutConstraintAxisVertical;
- tStackV.alignment = UIStackViewAlignmentFill;
- tStackV.distribution = UIStackViewDistributionFill;
- tStackV.spacing = 20;
- self.totalStackV = tStackV;
-
- UIStackView *topStackV = [[UIStackView alloc] init];
- topStackV.axis = UILayoutConstraintAxisHorizontal;
- topStackV.alignment = UIStackViewAlignmentFill;
- topStackV.distribution = UIStackViewDistributionFillEqually;
- topStackV.spacing = 20;
- [self.totalStackV addArrangedSubview:topStackV];
-
- NSArray *titles = @[@"First Name", @"Last Name", @"Date Of Birth"];
- NSArray *placeHolders = @[@"Pleace Input Name", @"Pleace Input Last Name", @"Pleace Select Date Of Birth"];
- for (int i = 0; i<titles.count; i++) {
- UILabel *lb = [[UILabel alloc] init];
- lb.font = [UIFont fontWithName:Rob_Regular size:12];
- lb.textColor = UIColor.blackColor;
- KWTextField *tf = [[KWTextField alloc] init];
- UIStackView *stackV = [[UIStackView alloc] init];
- stackV.axis = UILayoutConstraintAxisVertical;
- stackV.alignment = UIStackViewAlignmentFill;
- stackV.distribution = UIStackViewDistributionFill;
- stackV.spacing = 5;
- [stackV addArrangedSubview:lb];
- [stackV addArrangedSubview:tf];
- // lb.text = titles[i];
- tf.placeholder = placeHolders[i];
- [lb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@5);
- }];
- [tf mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@45);
- }];
- if (i == 0 || i == 1) {
- [topStackV addArrangedSubview:stackV];
- } else {
- [self.totalStackV addArrangedSubview:stackV];
- }
- switch (i) {
- case 0: {
- self.nameTf = tf;
- break;
- }
- case 1: {
- self.lastNTf = tf;
- break;
- }
- case 2: {
- self.birthTf = tf;
- break;
- }
- default:
- break;
- }
- }
-
- UIStackView *pStackV = [[UIStackView alloc] init];
- pStackV.axis = UILayoutConstraintAxisVertical;
- pStackV.alignment = UIStackViewAlignmentFill;
- pStackV.distribution = UIStackViewDistributionFillEqually;
- pStackV.spacing = 20;
- self.passStackV = pStackV;
-
-
- NSArray *titleArr = @[@"Email",@"",@""];
- NSArray *placeArr = @[@"Place Input Email",@"* OLD Password",@"* New Password"];
- for (int i=0; i<titleArr.count; i++) {
- KWTextField *tf = [[KWTextField alloc] init];
- UIStackView *stackV = [[UIStackView alloc] init];
- stackV.axis = UILayoutConstraintAxisVertical;
- stackV.alignment = UIStackViewAlignmentFill;
- stackV.distribution = UIStackViewDistributionFill;
- stackV.spacing = 5;
- if (![titleArr[i] isEqualToString:@""]) {
- UILabel *lb = [[UILabel alloc] init];
- lb.font = [UIFont fontWithName:Rob_Regular size:12];
- lb.textColor = UIColor.blackColor;
- [stackV addArrangedSubview:lb];
- // lb.text = titleArr[i];
- [lb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@5);
- }];
- }
- [stackV addArrangedSubview:tf];
- tf.placeholder = placeArr[i];
- [tf mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@45);
- }];
- tf.delegate = self;
- [tf addTarget:self action:@selector(textfieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- [tf addTarget:self action:@selector(textfieldDidChange:) forControlEvents:UIControlEventValueChanged];
-
- switch (i) {
- case 0: {
- self.emailTf = tf;
- [self.totalStackV addArrangedSubview:stackV];
- UIView *v = [UIView new];
- v.backgroundColor = UIColor.clearColor;
- [v addSubview:self.changePassBt];
- [self.totalStackV addArrangedSubview:v];
- [v mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@30);
- }];
- [self.changePassBt mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.equalTo(v);
- }];
- break;
- }
- case 1: {
- self.oldPassTf = tf;
- self.oldPassTf.secureTextEntry = true;
- UIView *lv = [self getPassRightBt:800000];
- self.oldPassTf.rightView = lv;
- [lv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@50);
- make.height.equalTo(@45);
- }];
- self.oldPassTf.rightViewMode = UITextFieldViewModeAlways;
- [self.totalStackV addArrangedSubview:self.passStackV];
- [self.passStackV addArrangedSubview:stackV];
- break;
- }
- case 2: {
- self.nPassTf = tf;
- self.nPassTf.secureTextEntry = true;
-
- UIView *lv = [self getPassRightBt:800001];
- lv.frame = CGRectMake(0, 0, 50, 45);
- self.nPassTf.rightView = lv;
- [lv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@50);
- make.height.equalTo(@45);
- }];
- self.nPassTf.rightViewMode = UITextFieldViewModeAlways;
- [self.passStackV addArrangedSubview:stackV];
- break;
- }
- default:
- break;
- }
- }
- self.passStackV.hidden = true;
- [self.scrollV addSubview:self.totalStackV];
- [self.totalStackV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.scrollV).offset(20);
- make.left.equalTo(self.scrollV).offset(20);
- make.right.equalTo(self.view).offset(-20);
- make.bottom.equalTo(self.scrollV).offset(20);
- make.width.equalTo([NSNumber numberWithFloat:KScreenWidth-40]);
- }];
-
- [self.view addSubview:self.bottomBt];
- [self.bottomBt mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view).offset(20);
- make.right.equalTo(self.view).offset(-20);
- make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-20);
- make.height.equalTo(@45);
- }];
-
- [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.view);
- make.top.equalTo(self.customNavBar.mas_bottom);
- make.bottom.equalTo(self.bottomBt.mas_top).offset(-10);
- }];
-
- self.birthTf.delegate = self;
-
- }
- - (UIScrollView *)scrollV {
- if (!_scrollV) {
- UIScrollView *v = [[UIScrollView alloc] init];
- v.showsVerticalScrollIndicator = false;
- v.showsHorizontalScrollIndicator = false;
- v.alwaysBounceVertical = true;
- v.backgroundColor = [UIColor colorWithHexString:@"#f8f8f8"];
- _scrollV = v;
- }
- return _scrollV;
- }
- - (UIButton *)changePassBt {
- if (!_changePassBt) {
- UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
- [bt setImage:[UIImage imageNamed:@"login_selectRido"] forState:UIControlStateNormal];
- [bt setImage:[UIImage imageNamed:@"login_selectRido_select"] forState:UIControlStateSelected];
- [bt setTitle:@" Change Password" forState:UIControlStateNormal];
- bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:12];
- [bt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [bt addTarget:self action:@selector(changePassTypeChanege) forControlEvents:UIControlEventTouchUpInside];
- _changePassBt = bt;
- }
- return _changePassBt;
- }
- - (void)changePassTypeChanege {
- switch (self.showType) {
- case 0:
- self.showType = 1;
- break;
- case 1:
- self.showType = 0;
- break;
-
- default:
- break;
- }
- [self configViewsByShowType];
-
- }
- - (void)configViewsByShowType {
- switch (self.showType) {
- case 0:
- self.changePassBt.selected = false;
- self.passStackV.hidden = true;
- [self.bottomBt setTitle:@"SAVE CHANGES" forState:UIControlStateNormal];
- break;
- case 1:
- self.changePassBt.selected = true;
- self.passStackV.hidden = false;
- [self.bottomBt setTitle:@"SAVE CHANGES" forState:UIControlStateNormal];
- break;
- default:
- break;
- }
- [self configBtState];
-
- }
- - (void)configBtState {
- switch (self.showType) {
- case 0:
- self.bottomBt.enabled = !self.emailTf.text.isEmpty && !self.nameTf.text.isEmpty && !self.lastNTf.text.isEmpty && !self.birthTf.text.isEmpty;
- break;
- case 1: {
- 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;
- self.bottomBt.enabled = isflag;
- break;
- }
- default:
- break;
- }
- self.bottomBt.backgroundColor = self.bottomBt.isEnabled ? [UIColor blackColor] : [UIColor colorWithHexString:@"#ADADAD"];
- }
- - (UIView *)getPassRightBt:(NSInteger)tag {
- UIView *v = [UIView new];
- v.backgroundColor = UIColor.whiteColor;
- UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
- [bt setImage:[UIImage imageNamed:@"login_password_secure"] forState:UIControlStateNormal];
- [bt setImage:[UIImage imageNamed:@"login_password_secure_display"] forState:UIControlStateSelected];
- [bt addTarget:self action:@selector(tfBtAction:) forControlEvents:UIControlEventTouchUpInside];
- bt.tag = tag;
- [v addSubview:bt];
- [bt mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.height.equalTo(@30);
- make.right.equalTo(v).offset(-17);
- make.centerY.equalTo(v);
- }];
- return v;
- }
- - (void)tfBtAction:(UIButton *)bt {
- NSInteger tag = bt.tag - 800000;
- bt.selected = !bt.isSelected;
- if (tag == 0) {
- self.oldPassTf.secureTextEntry = !bt.isSelected;
- } else {
- self.nPassTf.secureTextEntry = !bt.isSelected;
- }
- }
- - (UIButton *)bottomBt {
- if (!_bottomBt) {
- UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
- [bt setTitle:@"NEXT" forState:UIControlStateNormal];
- bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
- [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [bt setBackgroundColor:[UIColor colorWithHexString:@"#ADADAD"]];
- bt.layer.cornerRadius = 4;
- bt.layer.masksToBounds = true;
- bt.enabled = false;
- [bt addTarget:self action:@selector(bottomBtAction) forControlEvents:UIControlEventTouchUpInside];
- _bottomBt = bt;
- }
- return _bottomBt;
- }
- - (void)bottomBtAction {
-
- if (self.emailTf.text == nil || self.emailTf.text.length == 0) {
- [self.view makeToast:@"The email address con't be empty"];
- return;
- }
- if (self.nameTf.text == nil || self.nameTf.text.length == 0) {
- [self.view makeToast:@"The firstName con't be empty"];
- return;
- }
- if (self.lastNTf.text == nil || self.lastNTf.text.length == 0) {
- [self.view makeToast:@"The lastName con't be empty"];
- return;
- }
- if (self.changePassBt.isSelected) {
- if (self.oldPassTf.text == nil || self.oldPassTf.text.length == 0) {
- [self.view makeToast:@"The old password con't be empty"];
- return;
- }
- if (self.nPassTf.text == nil || self.nPassTf.text.length == 0) {
- [self.view makeToast:@"The new password con't be empty"];
- return;
- }
- }
-
- NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:@{
- @"email": self.emailTf.text,
- @"firstname": self.nameTf.text,
- @"lastname": self.lastNTf.text,
- }];
- if (self.birthTf.text != nil && self.birthTf.text.length > 0) {
- param[@"dob"] = self.birthTf.text;
- }
- BOOL __block isInfoSuc = false;
- BOOL __block isPassSuc = false;
- __weak typeof(self) weakSelf = self;
- [MBProgressHUD showHUDAddedTo:self.view animated:true];
- dispatch_group_t group = dispatch_group_create();
- dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
-
- dispatch_group_enter(group);
- dispatch_group_async(group, queue, ^{
- [ASNetTools.shared putWithPath:putUserInfo param: @{@"customer":param} success:^(id _Nonnull json) {
- isInfoSuc = true;
- dispatch_group_leave(group);
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- [weakSelf.view makeToast:@"Bad Net"];
- isInfoSuc = false;
- dispatch_group_leave(group);
- }];
- });
-
- if (!self.changePassBt.isSelected) {
- isPassSuc = true;
- dispatch_group_notify(group, dispatch_get_main_queue(), ^{
- [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
- BOOL flag = isInfoSuc;
- NSString *str = @"Successfully Change Information";
- if (weakSelf.changePassBt.isSelected) {
- flag = isInfoSuc && isPassSuc;
- str = @"Successfully Change Information, Please Log In Again";
- }
- if (!flag) {
- [ASUserInfoManager.shared getInfo];
- return;
- }
-
- [ASHomeAlertWindow alertMsg:str];
- if (weakSelf.changePassBt.isSelected) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [ASHomeAlertWindow clearWindow];
- [weakSelf popAndToLogin];
- });
- } else {
- [ASUserInfoManager.shared getInfo];
- }
-
- });
- return;
- }
- NSDictionary *dic = @{
- @"currentPassword": self.oldPassTf.text,
- @"newPassword": self.nPassTf.text,
- };
- dispatch_group_enter(group);
- dispatch_group_async(group, queue, ^{
- [ASNetTools.shared putWithPath:putUserPassword param:dic success:^(id _Nonnull json) {
- isPassSuc = true;
- dispatch_group_leave(group);
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- [weakSelf.view makeToast:@"Bad Net"];
- isPassSuc = false;
- dispatch_group_leave(group);
- }];
- });
- dispatch_group_notify(group, dispatch_get_main_queue(), ^{
- [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
- BOOL flag = isInfoSuc;
- NSString *str = @"Successfully Change Information";
- if (weakSelf.changePassBt.isSelected) {
- flag = isInfoSuc && isPassSuc;
- str = @"Successfully Change Information, Please Log In Again";
- }
- if (!flag) {
- [ASUserInfoManager.shared getInfo];
- return;
- }
-
- [ASHomeAlertWindow alertMsg:str];
- if (weakSelf.changePassBt.isSelected) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [ASHomeAlertWindow clearWindow];
- [weakSelf popAndToLogin];
- });
- } else {
- [ASUserInfoManager.shared getInfo];
- }
-
- });
-
- }
- - (void)textfieldDidChange:(UITextField *)tf {
- [self configBtState];
- }
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
- if ([self.birthTf isEqual:textField]) {
- BRDatePickerView *datePickerView = [[BRDatePickerView alloc]init];
- datePickerView.pickerMode = BRDatePickerModeDate;
- datePickerView.title = @"Please Select The Date Of Birth";
- datePickerView.selectDate = self.currentDate;
- datePickerView.minDate = [NSDate br_setYear:1900 month:1 day:1];
- datePickerView.maxDate = [NSDate date];
- datePickerView.isAutoSelect = YES;
- @weakify(self);
- datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
- weak_self.currentDate = selectDate;
- NSDateFormatter *formartter= [[NSDateFormatter alloc]init];
- [formartter setDateFormat:@"MM/dd/yyyy"];
- NSString *currentDateStr = [formartter stringFromDate:selectDate];
- weak_self.birthTf.text = currentDateStr;
- [weak_self configBtState];
- NSLog(@"selectValue=%@", selectValue);
- NSLog(@"selectDate=%@", selectDate);
- NSLog(@"---------------------------------");
-
- };
- [datePickerView show];
- return false;
- }
- return true;
- }
- @end
|