FirstSettingViewController.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // FirstSettingViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/20.
  6. //
  7. #import "FirstSettingViewController.h"
  8. #import "FirstSettingBodyView.h"
  9. #import "AppDelegate.h"
  10. #import "UserInfoManager.h"
  11. @interface FirstSettingViewController ()
  12. @property (nonatomic, strong) FirstSettingBodyView *bodyView;
  13. @property (nonatomic, strong) NSString *userSex;
  14. @end
  15. @implementation FirstSettingViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. self.ks_prefersNavigationBarHidden = YES;
  20. [self configUI];
  21. [self requestConfig];
  22. }
  23. - (void)requestConfig {
  24. [KSNetworkingManager queryByParamName:KS_GET paramName:@"last_username_month" success:^(NSDictionary * _Nonnull dic) {
  25. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  26. NSInteger month = [[dic dictionaryValueForKey:@"data"] integerValueForKey:@"paramValue"];
  27. self.bodyView.descLabel.hidden = NO;
  28. self.bodyView.descLabel.text = [NSString stringWithFormat:@"每隔%zd个月可修改一次",month];
  29. }
  30. else {
  31. [self MBPShow:MESSAGEKEY];
  32. }
  33. } faliure:^(NSError * _Nonnull error) {
  34. }];
  35. }
  36. - (void)configUI {
  37. CGFloat height = KPortraitHeight;
  38. _bodyView = [FirstSettingBodyView shareInstance];
  39. [self.scrollView addSubview:_bodyView];
  40. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.top.mas_equalTo(self.scrollView.mas_top);
  42. make.right.left.mas_equalTo(self.view);
  43. make.height.mas_equalTo(height);
  44. make.bottom.mas_equalTo(self.scrollView.mas_bottom);
  45. }];
  46. MJWeakSelf;
  47. [_bodyView sureCallback:^(NSString *myCode, NSString *nickName) {
  48. [weakSelf settingPassword:myCode nickName:nickName];
  49. }];
  50. [_bodyView chooseSexCallback:^{
  51. [weakSelf showModifySexAlert];
  52. }];
  53. }
  54. - (void)showModifySexAlert {
  55. NSString *titleString = @"选择性别";
  56. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:titleString preferredStyle:IS_IPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
  57. NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:titleString];
  58. [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.0f] range:NSMakeRange(0, titleString.length)];
  59. [titleAtt addAttribute:NSForegroundColorAttributeName value:HexRGB(0x999999) range:NSMakeRange(0, titleString.length)];
  60. [alertVC setValue:titleAtt forKey:@"attributedMessage"];
  61. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  62. self.bodyView.sexField.text = @"男";
  63. self.userSex = @"1";
  64. }];
  65. [actionOne setValue:THEMECOLOR forKey:@"_titleTextColor"];
  66. [alertVC addAction:actionOne];
  67. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  68. self.bodyView.sexField.text = @"女";
  69. self.userSex = @"0";
  70. }];
  71. [actionTwo setValue:THEMECOLOR forKey:@"_titleTextColor"];
  72. [alertVC addAction:actionTwo];
  73. UIAlertAction *cancleAlert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  74. }];
  75. [alertVC addAction:cancleAlert];
  76. [cancleAlert setValue:HexRGB(0x444444) forKey:@"_titleTextColor"];
  77. alertVC.modalPresentationStyle = UIModalPresentationFullScreen;
  78. [self presentViewController:alertVC animated:true completion:nil];
  79. }
  80. - (void)settingPassword:(NSString *)pwdCode nickName:(NSString *)nickName {
  81. if ([NSString isEmptyString:self.userSex]) {
  82. [self MBPShow:@"请设置性别"];
  83. return;
  84. }
  85. [self showhud];
  86. [KSNetworkingManager setPasswordRequest:KS_POST username:nickName password:pwdCode userSex:self.userSex token:self.access_token success:^(NSDictionary * _Nonnull dic) {
  87. [self removehub];
  88. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  89. MJWeakSelf;
  90. UserDefaultSet(self.phone, PHONEKEY);
  91. UserDefaultSet(self.access_token, TokenKey);
  92. UserDefaultSet(pwdCode, PASSWORDKEY);
  93. [self KSShowMsg:@"设置成功" promptCompletion:^{
  94. [weakSelf toHomeView];
  95. }];
  96. }
  97. else {
  98. [self MBPShow:MESSAGEKEY];
  99. }
  100. } faliure:^(NSError * _Nonnull error) {
  101. [self removehub];
  102. }];
  103. }
  104. - (void)toHomeView {
  105. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  106. [appDelegate initTableBar];
  107. UITabBarController *tabBarController = appDelegate.tabBarController;
  108. [tabBarController setSelectedIndex:0];
  109. appDelegate.window.rootViewController = tabBarController;
  110. }
  111. /*
  112. #pragma mark - Navigation
  113. // In a storyboard-based application, you will often want to do a little preparation before navigation
  114. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  115. // Get the new view controller using [segue destinationViewController].
  116. // Pass the selected object to the new view controller.
  117. }
  118. */
  119. @end