RDSMyInfoVC.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //
  2. // RDSMyInfoVC.m
  3. // Temperature
  4. //
  5. // Created by RD on 2022/12/15.
  6. //
  7. #import "RDSMyInfoVC.h"
  8. #import "RDSRootControl.h"
  9. #import "LCActionSheet.h"
  10. #import "RDSImagePicker.h"
  11. #import "RDSSetPwdVC.h"
  12. #import "RDSResetPwdVC.h"
  13. @interface RDSMyInfoVC ()<LCActionSheetDelegate>
  14. @property (weak, nonatomic) IBOutlet UIButton *headBtn;
  15. @property (weak, nonatomic) IBOutlet UILabel *userNameLab;
  16. @property (weak, nonatomic) IBOutlet UILabel *phoneLab;
  17. @end
  18. @implementation RDSMyInfoVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view from its nib.
  22. self.title = @"个人信息";
  23. [self p_getCurrentUserInfo];
  24. [self refreshUserInfoUI];
  25. }
  26. - (void)p_getCurrentUserInfo{
  27. RDS_WEAKSELF(weakSelf)
  28. [RDSUserInfoModel rds_getCurrentUserInfoFinished:^(NSError *error) {
  29. if (!error) {
  30. [weakSelf refreshUserInfoUI];
  31. }
  32. }];
  33. }
  34. - (void)refreshUserInfoUI{
  35. RDS_WEAKSELF(weakSelf)
  36. dispatch_async(dispatch_get_main_queue(), ^{
  37. weakSelf.userNameLab.text = TheDataManager.currentUser.user_name;
  38. weakSelf.phoneLab.text = TheDataManager.currentUser.phone;
  39. if (!TheDataManager.currentUser.headImg) {
  40. [TheDataManager.currentUser rds_getHeadImgFinished:^(NSError *error) {
  41. [weakSelf.headBtn setImage:TheDataManager.currentUser.headImg forState:UIControlStateNormal];
  42. }];
  43. }else{
  44. [weakSelf.headBtn setImage:TheDataManager.currentUser.headImg forState:UIControlStateNormal];
  45. }
  46. });
  47. }
  48. /// 点击头像
  49. - (IBAction)onHeadClick {
  50. LCActionSheet *actionSheet = [LCActionSheet sheetWithTitle:nil
  51. buttonTitles:@[@"拍照", @"从手机相册选择"]
  52. redButtonIndex:-1
  53. delegate:self];
  54. [actionSheet show];
  55. }
  56. /// 点击用户名
  57. - (IBAction)onUserNameClick {
  58. RDS_WEAKSELF(weakSelf)
  59. [self rds_alertInputTitle:@"设置用户名" msg:nil placeholder:TheDataManager.currentUser.user_name doneAction:^(NSString *name) {
  60. [weakSelf p_updateUserInfoChangeName:name photoUrl:nil];
  61. TheDataManager.currentUser.user_name = name;
  62. }];
  63. }
  64. /// 点击手机号
  65. - (IBAction)onPhoneClick {
  66. }
  67. // 设置密码
  68. //1、未设置过密码 跳转到 设置密码 页面
  69. //2、设置过密码 跳转到 重置密码 页面
  70. - (IBAction)setPwdAction:(id)sender {
  71. if(TheDataManager.currentUser.set_password){
  72. RDSResetPwdVC *vc = [[RDSResetPwdVC alloc] init];
  73. [self pushViewController:vc animated:YES];
  74. }
  75. else{
  76. RDSSetPwdVC *vc = [[RDSSetPwdVC alloc] init];
  77. [self pushViewController:vc animated:YES];
  78. }
  79. }
  80. // 注销账户
  81. - (IBAction)unsubscribeAction:(id)sender {
  82. RDS_WEAKSELF(weakSelf)
  83. [TheAlertCtrl rds_alertWithTitle:@"提示" message:@"注销账户将清空用户所有数据,确认注销?" cancel:@"取消" sure:@"注销账户" cancelColor:nil sureColor:RDSRedColor cancelAction:nil sureAction:^{
  84. [weakSelf p_unsubscribe];
  85. }];
  86. }
  87. // 注销账户
  88. - (void)p_unsubscribe{
  89. [RDSDemoApiHelper rds_unsubscribeSuccess:^(id responseObject) {
  90. if ([responseObject[@"code"] intValue] == 0) {
  91. [RDSRootControl shareControl].isLoginSuccess = NO;
  92. } else{
  93. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  94. }
  95. } failure:^(NSError *error) {
  96. [RDSHudShower showBottomToast:@"连接服务器失败"];
  97. }];
  98. }
  99. // 退出登录
  100. - (IBAction)logoutAction:(id)sender {
  101. RDS_WEAKSELF(weakSelf)
  102. [RDSHudShower showWithStatus:@"加载中..." autoDismiss:NO];
  103. [RDSDemoApiHelper rds_logoutSuccess:^(id responseObject) {
  104. if ([responseObject[@"code"] intValue] == 0) {
  105. [RDSHudShower dismissHUD];
  106. [RDSRootControl shareControl].isLoginSuccess = NO;
  107. } else{
  108. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  109. }
  110. } failure:^(NSError *error) {
  111. [RDSHudShower showBottomToast:@"连接服务器失败"];
  112. [RDSRootControl shareControl].isLoginSuccess = NO;
  113. }];
  114. TheDataManager.token = @"";
  115. }
  116. #pragma mark - LCActionSheetDelegate
  117. - (void)actionSheet:(LCActionSheet *)actionSheet didClickedButton:(UIButton *)button {
  118. if (button.tag >= 2) return; // 取消
  119. RDS_WEAKSELF(weakSelf)
  120. EImageSourceType type = button.tag == 1 ? EImageFromPhoto : EImageFromCamera;
  121. [[RDSImagePicker sharePicker] rds_pickImageFrom:type needEdit:YES complected:^(UIImage *pickImage) {
  122. if (pickImage) {
  123. [weakSelf p_uploadUserPic:pickImage];
  124. }
  125. }];
  126. }
  127. // 上传头像
  128. - (void)p_uploadUserPic:(UIImage *)userPic {
  129. RDS_WEAKSELF(weakSelf)
  130. [RDSDemoApiHelper rds_postImage:userPic success:^(id responseObject) {
  131. if ([responseObject[@"code"] intValue] == 0) {
  132. NSDictionary *data = responseObject[@"data"];
  133. NSString *url = data[@"url"];
  134. TheDataManager.currentUser.photo = url;
  135. TheDataManager.currentUser.headImg = userPic;
  136. [weakSelf p_updateUserInfoChangeName:nil photoUrl:url];
  137. [RDSHudShower showCenterToast:@"设置成功"];
  138. } else{
  139. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  140. }
  141. } failure:^(NSError *error) {
  142. [RDSHudShower showBottomToast:@"连接服务器失败"];
  143. }];
  144. return;
  145. }
  146. - (void)p_updateUserInfoChangeName:(NSString *)userName photoUrl:(NSString *)photoUrl{
  147. RDS_WEAKSELF(weakSelf)
  148. [RDSDemoApiHelper rds_updateUserInfoChangeUserName:userName photoUrl:photoUrl defaultHomeId:nil isSetPwd:NO success:^(id responseObject) {
  149. if ([responseObject[@"code"] intValue] == 0) {
  150. [weakSelf refreshUserInfoUI];
  151. [RDSHudShower showCenterToast:@"设置成功"];
  152. [kNotificationCenter postNotificationName:RDSUpdateUserInfoNotice object:nil];
  153. } else{
  154. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  155. }
  156. } failure:^(NSError *error) {
  157. [RDSHudShower showBottomToast:@"连接服务器失败"];
  158. }];
  159. }
  160. @end