YXMyInfoViewController.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // YXMyInfoViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/2/15.
  6. //
  7. #import "YXMyInfoViewController.h"
  8. #import "LCActionSheet.h"
  9. #import "RDSImagePicker.h"
  10. #import "UIImageView+webImage.h"
  11. #import "RDSResetPwdVC.h"
  12. #import "RDSRootControl.h"
  13. @interface YXMyInfoViewController ()<LCActionSheetDelegate>
  14. @property (weak, nonatomic) IBOutlet UIView *myPicView;
  15. @property (weak, nonatomic) IBOutlet UIImageView *myImageView;
  16. @property (weak, nonatomic) IBOutlet UIView *myNameView;
  17. @property (weak, nonatomic) IBOutlet UILabel *myNameLabel;
  18. @property (weak, nonatomic) IBOutlet UIView *changePWBgView;
  19. @property (weak, nonatomic) IBOutlet UIView *logoffBgView;
  20. @end
  21. @implementation YXMyInfoViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.navigationItem.title = @"个人资料";
  25. self.myImageView.layer.cornerRadius = 27.5;
  26. self.myImageView.clipsToBounds = YES;
  27. NSString *urlStr = TheDataManager.currentUser.photo;
  28. [self.myImageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"my_pic"]];
  29. self.myNameLabel.text = TheDataManager.currentUser.user_name;
  30. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(setUserPic)];
  31. [self.myPicView addGestureRecognizer:tap];
  32. UITapGestureRecognizer *nameTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userNameAlert)];
  33. [self.myNameView addGestureRecognizer:nameTap];
  34. UITapGestureRecognizer *pwTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pwTapAction)];
  35. [self.changePWBgView addGestureRecognizer:pwTap];
  36. UITapGestureRecognizer *logoffTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(logoffAlert)];
  37. [self.logoffBgView addGestureRecognizer:logoffTap];
  38. }
  39. -(void)pwTapAction
  40. {
  41. RDSResetPwdVC *resetPwdVC = [[RDSResetPwdVC alloc] init];
  42. [self pushViewController:resetPwdVC animated:YES];
  43. }
  44. -(void)logoffAlert
  45. {
  46. RDS_WEAKSELF(weakSelf)
  47. UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"注销" message:@"是否确定注销用账户?" preferredStyle:UIAlertControllerStyleAlert];
  48. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  49. [weakSelf logoff];
  50. }];
  51. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
  52. }];
  53. [ac addAction:okAction];
  54. [ac addAction:cancelAction];
  55. [self presentViewController:ac animated:YES completion:nil];
  56. }
  57. -(void)logoff
  58. {
  59. [RDSDemoApiHelper rds_unsubscribeSuccess:^(id responseObject) {
  60. if ([responseObject[@"code"] intValue] == 0) {
  61. [RDSRootControl shareControl].isLoginSuccess = NO;
  62. } else{
  63. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  64. }
  65. } failure:^(NSError *error) {
  66. [RDSHudShower showBottomToast:@"连接服务器失败"];
  67. }];
  68. }
  69. -(void)setUserPic
  70. {
  71. LCActionSheet *actionSheet = [LCActionSheet sheetWithTitle:nil buttonTitles:@[@"拍照", @"从手机相册选择"] redButtonIndex:-1 delegate:self];
  72. [actionSheet show];
  73. }
  74. #pragma mark - LCActionSheetDelegate
  75. - (void)actionSheet:(LCActionSheet *)actionSheet didClickedButton:(UIButton *)button {
  76. if (button.tag >= 2) return; // 取消
  77. RDS_WEAKSELF(weakSelf)
  78. EImageSourceType type = button.tag == 1 ? EImageFromPhoto : EImageFromCamera;
  79. [[RDSImagePicker sharePicker] rds_pickImageFrom:type needEdit:YES complected:^(UIImage *pickImage) {
  80. if (pickImage) {
  81. [weakSelf p_uploadUserPic:pickImage];
  82. }
  83. }];
  84. }
  85. // 上传头像
  86. - (void)p_uploadUserPic:(UIImage *)userPic {
  87. RDS_WEAKSELF(weakSelf)
  88. [RDSDemoApiHelper rds_postImage:userPic success:^(id responseObject) {
  89. if ([responseObject[@"code"] intValue] == 9999) {
  90. [RDSRootControl shareControl].isLoginSuccess = NO;
  91. TheDataManager.token = @"";
  92. }
  93. if ([responseObject[@"code"] intValue] == 0) {
  94. NSDictionary *data = responseObject[@"data"];
  95. NSString *url = data[@"url"];
  96. [weakSelf p_updateUserInfoChangeName:nil photoUrl:url];
  97. } else{
  98. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  99. }
  100. } failure:^(NSError *error) {
  101. [RDSHudShower showBottomToast:@"连接服务器失败"];
  102. }];
  103. return;
  104. }
  105. -(void)userNameAlert
  106. {
  107. RDS_WEAKSELF(weakSelf)
  108. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"修改昵称" message:nil preferredStyle:UIAlertControllerStyleAlert];
  109. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  110. UITextField *txt = [alertController.textFields objectAtIndex:0];
  111. NSLog(@"%@",txt.text);
  112. [self p_updateUserInfoChangeName:txt.text photoUrl:nil];
  113. }];
  114. [alertController addAction:sureAction];
  115. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  116. }];
  117. [alertController addAction:cancelAction];
  118. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  119. textField.placeholder = @"请输入昵称";
  120. textField.text = TheDataManager.currentUser.user_name;
  121. }];
  122. [self presentViewController:alertController animated:YES completion:nil];
  123. }
  124. - (void)p_updateUserInfoChangeName:(NSString *)userName photoUrl:(NSString *)photoUrl{
  125. RDS_WEAKSELF(weakSelf)
  126. [RDSDemoApiHelper rds_updateUserInfoChangeUserName:userName photoUrl:photoUrl defaultHomeId:nil isSetPwd:NO success:^(id responseObject) {
  127. if ([responseObject[@"code"] intValue] == 0) {
  128. weakSelf.myNameLabel.text = userName;
  129. [weakSelf p_getCurrentUserInfo];
  130. [RDSHudShower showCenterToast:@"设置成功"];
  131. } else{
  132. [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
  133. }
  134. } failure:^(NSError *error) {
  135. [RDSHudShower showBottomToast:@"连接服务器失败"];
  136. }];
  137. }
  138. - (void)p_getCurrentUserInfo{
  139. RDS_WEAKSELF(weakSelf)
  140. [RDSUserInfoModel rds_getCurrentUserInfoFinished:^(NSError *error) {
  141. if (!error) {
  142. [weakSelf.myImageView sd_setImageWithURL:[NSURL URLWithString:TheDataManager.currentUser.photo]];
  143. }
  144. }];
  145. }
  146. /*
  147. #pragma mark - Navigation
  148. // In a storyboard-based application, you will often want to do a little preparation before navigation
  149. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  150. // Get the new view controller using [segue destinationViewController].
  151. // Pass the selected object to the new view controller.
  152. }
  153. */
  154. @end