// // YXMyInfoViewController.m // Temperature // // Created by TC on 2025/2/15. // #import "YXMyInfoViewController.h" #import "LCActionSheet.h" #import "RDSImagePicker.h" #import "UIImageView+webImage.h" #import "RDSResetPwdVC.h" #import "RDSRootControl.h" @interface YXMyInfoViewController () @property (weak, nonatomic) IBOutlet UIView *myPicView; @property (weak, nonatomic) IBOutlet UIImageView *myImageView; @property (weak, nonatomic) IBOutlet UIView *myNameView; @property (weak, nonatomic) IBOutlet UILabel *myNameLabel; @property (weak, nonatomic) IBOutlet UIView *changePWBgView; @property (weak, nonatomic) IBOutlet UIView *logoffBgView; @end @implementation YXMyInfoViewController - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"个人资料"; self.myImageView.layer.cornerRadius = 27.5; self.myImageView.clipsToBounds = YES; NSString *urlStr = TheDataManager.currentUser.photo; [self.myImageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"my_pic"]]; self.myNameLabel.text = TheDataManager.currentUser.user_name; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(setUserPic)]; [self.myPicView addGestureRecognizer:tap]; UITapGestureRecognizer *nameTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userNameAlert)]; [self.myNameView addGestureRecognizer:nameTap]; UITapGestureRecognizer *pwTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pwTapAction)]; [self.changePWBgView addGestureRecognizer:pwTap]; UITapGestureRecognizer *logoffTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(logoffAlert)]; [self.logoffBgView addGestureRecognizer:logoffTap]; } -(void)pwTapAction { RDSResetPwdVC *resetPwdVC = [[RDSResetPwdVC alloc] init]; [self pushViewController:resetPwdVC animated:YES]; } -(void)logoffAlert { RDS_WEAKSELF(weakSelf) UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"注销" message:@"是否确定注销用账户?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [weakSelf logoff]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { }]; [ac addAction:okAction]; [ac addAction:cancelAction]; [self presentViewController:ac animated:YES completion:nil]; } -(void)logoff { [RDSDemoApiHelper rds_unsubscribeSuccess:^(id responseObject) { if ([responseObject[@"code"] intValue] == 0) { [RDSRootControl shareControl].isLoginSuccess = NO; } else{ [RDSHudShower showErrorWithStatus:responseObject[@"message"]]; } } failure:^(NSError *error) { [RDSHudShower showBottomToast:@"连接服务器失败"]; }]; } -(void)setUserPic { LCActionSheet *actionSheet = [LCActionSheet sheetWithTitle:nil buttonTitles:@[@"拍照", @"从手机相册选择"] redButtonIndex:-1 delegate:self]; [actionSheet show]; } #pragma mark - LCActionSheetDelegate - (void)actionSheet:(LCActionSheet *)actionSheet didClickedButton:(UIButton *)button { if (button.tag >= 2) return; // 取消 RDS_WEAKSELF(weakSelf) EImageSourceType type = button.tag == 1 ? EImageFromPhoto : EImageFromCamera; [[RDSImagePicker sharePicker] rds_pickImageFrom:type needEdit:YES complected:^(UIImage *pickImage) { if (pickImage) { [weakSelf p_uploadUserPic:pickImage]; } }]; } // 上传头像 - (void)p_uploadUserPic:(UIImage *)userPic { RDS_WEAKSELF(weakSelf) [RDSDemoApiHelper rds_postImage:userPic success:^(id responseObject) { if ([responseObject[@"code"] intValue] == 9999) { [RDSRootControl shareControl].isLoginSuccess = NO; TheDataManager.token = @""; } if ([responseObject[@"code"] intValue] == 0) { NSDictionary *data = responseObject[@"data"]; NSString *url = data[@"url"]; [weakSelf p_updateUserInfoChangeName:nil photoUrl:url]; } else{ [RDSHudShower showErrorWithStatus:responseObject[@"message"]]; } } failure:^(NSError *error) { [RDSHudShower showBottomToast:@"连接服务器失败"]; }]; return; } -(void)userNameAlert { RDS_WEAKSELF(weakSelf) UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"修改昵称" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"完成" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { UITextField *txt = [alertController.textFields objectAtIndex:0]; NSLog(@"%@",txt.text); [self p_updateUserInfoChangeName:txt.text photoUrl:nil]; }]; [alertController addAction:sureAction]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertController addAction:cancelAction]; [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = @"请输入昵称"; textField.text = TheDataManager.currentUser.user_name; }]; [self presentViewController:alertController animated:YES completion:nil]; } - (void)p_updateUserInfoChangeName:(NSString *)userName photoUrl:(NSString *)photoUrl{ RDS_WEAKSELF(weakSelf) [RDSDemoApiHelper rds_updateUserInfoChangeUserName:userName photoUrl:photoUrl defaultHomeId:nil isSetPwd:NO success:^(id responseObject) { if ([responseObject[@"code"] intValue] == 0) { weakSelf.myNameLabel.text = userName; [weakSelf p_getCurrentUserInfo]; [RDSHudShower showCenterToast:@"设置成功"]; } else{ [RDSHudShower showErrorWithStatus:responseObject[@"message"]]; } } failure:^(NSError *error) { [RDSHudShower showBottomToast:@"连接服务器失败"]; }]; } - (void)p_getCurrentUserInfo{ RDS_WEAKSELF(weakSelf) [RDSUserInfoModel rds_getCurrentUserInfoFinished:^(NSError *error) { if (!error) { [weakSelf.myImageView sd_setImageWithURL:[NSURL URLWithString:TheDataManager.currentUser.photo]]; } }]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end