Files
featherVoice/QXLive/Mine(音域)/Controller/编辑/QXUserInfoEidtViewController.m
2025-08-08 10:49:36 +08:00

253 lines
11 KiB
Objective-C

//
// QXUserInfoEidtViewController.m
// QXLive
//
// Created by 启星 on 2025/5/9.
//
#import "QXUserInfoEidtViewController.h"
#import "QXUserInfoEditCell.h"
#import "QXUserInfoEditFooterView.h"
#import "QXUserInfoEditHeaderView.h"
#import "QXChangeNicknameViewController.h"
#import "QXChangeIntroduceViewController.h"
#import "BRDatePickerView.h"
#import "BRTextPickerView.h"
#import "NSDate+BRPickerView.h"
#import "QXMineNetwork.h"
@interface QXUserInfoEidtViewController ()<UITableViewDelegate,UITableViewDataSource,QXUserInfoEditHeaderViewDelegate,QXUserInfoImageCellDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)QXUserInfoEditFooterView *tableFooterView;
@property (nonatomic,strong)QXUserInfoEditHeaderView *tableHeaderView;
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)NSMutableDictionary *valueDict;
@property (nonatomic,strong)UILabel* titleLabel;
@property (nonatomic,strong)UIButton* backBtn;
@property (nonatomic,strong)NSMutableArray* imgsArray;
@property (nonatomic,strong)QXUserHomeModel * userModel;
@end
@implementation QXUserInfoEidtViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self getUserInfo];
}
- (void)initSubViews{
// [self.view addSubview:self.bgView];
self.dataArray = [NSMutableArray arrayWithArray:@[
QXText(@"昵称"),QXText(@"性别"),QXText(@"出生日期"),QXText(@"简介")
]];
self.valueDict = [NSMutableDictionary dictionaryWithDictionary:@{
QXText(@"昵称"):[QXGlobal shareGlobal].loginModel.nickname?[QXGlobal shareGlobal].loginModel.nickname:@"",
QXText(@"性别"):[QXGlobal shareGlobal].loginModel.sex.integerValue== 1?QXText(@""):QXText(@""),
QXText(@"出生日期"):[QXGlobal shareGlobal].loginModel.birthday?[QXGlobal shareGlobal].loginModel.birthday:@"",
QXText(@"简介"):[QXGlobal shareGlobal].loginModel.profile?[QXGlobal shareGlobal].loginModel.profile:@"",
}];
self.tableView.tableHeaderView = self.tableHeaderView;
self.tableView.tableFooterView = self.tableFooterView;
[self.view addSubview:self.tableView];
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, kSafeAreaTop, SCREEN_WIDTH-140, 40)];
self.titleLabel.text = QXText(@"编辑资料");
self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
self.titleLabel.textColor = RGB16(0x333333);
self.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:self.titleLabel];
self.backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, kSafeAreaTop, 40, 40)];
[self.backBtn setImage:[UIImage imageNamed:@"back"] forState:(UIControlStateNormal)];
[self.backBtn addTarget:self action:@selector(backAction) forControlEvents:(UIControlEventTouchUpInside)];
[self.view addSubview:self.backBtn];
}
-(void)getUserInfo{
MJWeakSelf
[QXMineNetwork userHomePageWithUserId:[QXGlobal shareGlobal].loginModel.user_id successBlock:^(QXUserHomeModel * _Nonnull userModel) {
weakSelf.userModel = userModel;
weakSelf.valueDict = [NSMutableDictionary dictionaryWithDictionary:@{
QXText(@"昵称"):userModel.nickname?userModel.nickname:@"",
QXText(@"性别"):userModel.sex.integerValue== 1?QXText(@""):QXText(@""),
QXText(@"出生日期"):userModel.birthday?userModel.birthday:@"",
QXText(@"简介"):userModel.profile?userModel.profile:@"",
}];
NSArray *imgs;
if (userModel.home_bgimages.length > 0) {
imgs = [userModel.home_bgimages componentsSeparatedByString:@","];
}
[weakSelf.imgsArray removeAllObjects];
if (imgs != nil) {
[weakSelf.imgsArray addObjectsFromArray:imgs];
}
weakSelf.tableHeaderView.imgs = weakSelf.imgsArray;
weakSelf.tableFooterView.imgs = weakSelf.imgsArray;
[weakSelf.tableView reloadData];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
}];
}
#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QXUserInfoEditCell *cell = [QXUserInfoEditCell cellWithTableView:tableView];
NSString *title = self.dataArray[indexPath.row];
cell.titleLabel.text = title;
cell.textField.text = self.valueDict[title];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *title = self.dataArray[indexPath.row];
if ([title isEqualToString:QXText(@"昵称")]) {
QXChangeNicknameViewController *vc = [[QXChangeNicknameViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}else if ([title isEqualToString:QXText(@"简介")]){
QXChangeIntroduceViewController *vc= [[QXChangeIntroduceViewController alloc] init];
vc.introduce = self.userModel.profile;
[self.navigationController pushViewController:vc animated:YES];
}else if ([title isEqualToString:QXText(@"出生日期")]){
BRDatePickerView *piker = [[BRDatePickerView alloc] initWithPickerMode:(BRDatePickerModeYMD)];
NSDate *minDate = [NSDate br_setYear:1900 month:1 day:1];
piker.minDate = minDate;
piker.maxDate = [NSDate date];
piker.selectValue = [QXGlobal shareGlobal].loginModel.birthday;
piker.isAutoSelect = NO;
MJWeakSelf
piker.resultBlock = ^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
[weakSelf editBirthday:selectValue];
};
[piker show];
}else if ([title isEqualToString:QXText(@"性别")]){
MJWeakSelf
// BRTextPickerView *piker = [[BRTextPickerView alloc] initWithPickerMode:BRTextPickerComponentSingle];
// piker.dataSourceArr = @[QXText(@"男"),QXText(@"女")];
// piker.singleResultBlock = ^(BRTextModel * _Nullable model, NSInteger index) {
// if (index == 1) {
// [weakSelf editSex:@"2"];
// }else{
// [weakSelf editSex:@"1"];
// }
// };
// [piker show];
}
}
-(void)didClickDelete:(NSString *)imageUrl index:(NSInteger)index{
[self.imgsArray removeObjectAtIndex:index];
[self uploadImageWithUlrList:self.imgsArray];
}
-(void)didUploadFinishedWithImageUrlList:(NSArray *)urlList{
[self.imgsArray addObjectsFromArray:urlList];
[self uploadImageWithUlrList:self.imgsArray];
}
-(void)uploadImageWithUlrList:(NSArray*)urlList{
MJWeakSelf
NSString *images = @"";
if (urlList.count > 0) {
images = [urlList componentsJoinedByString:@","];
}
[QXMineNetwork editUserHomeBgWithImages:images successBlock:^(NSDictionary * _Nonnull dict) {
[weakSelf getUserInfo];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
-(void)editBirthday:(NSString*)birthday{
MJWeakSelf
__block NSString *saveBirthday = birthday;
[QXMineNetwork editUserInfoWithNickname:@""
birthday:birthday
sex:@""
avatar:@""
images:@""
profile:@""
tag_id:@""
successBlock:^(NSDictionary * _Nonnull dict) {
showToast(QXText(@"修改成功"));
[weakSelf getUserInfo];
[QXGlobal shareGlobal].loginModel.birthday = saveBirthday;
[[QXGlobal shareGlobal] updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel];
[weakSelf.valueDict setObject:saveBirthday forKey:QXText(@"出生日期")];
[weakSelf.tableView reloadRow:2 inSection:0 withRowAnimation:(UITableViewRowAnimationAutomatic)];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
-(void)editSex:(NSString*)sex{
MJWeakSelf
__block NSString *saveSex = sex;
[QXMineNetwork editUserInfoWithNickname:@""
birthday:@""
sex:sex
avatar:@""
images:@""
profile:@""
tag_id:@""
successBlock:^(NSDictionary * _Nonnull dict) {
showToast(QXText(@"修改成功"));
[weakSelf getUserInfo];
[QXGlobal shareGlobal].loginModel.sex = saveSex;
[[QXGlobal shareGlobal] updateUserInfoWithMolde:[QXGlobal shareGlobal].loginModel];
[weakSelf.valueDict setObject:saveSex.integerValue== 1?QXText(@""):QXText(@"") forKey:QXText(@"性别")];
[weakSelf.tableView reloadRow:1 inSection:0 withRowAnimation:(UITableViewRowAnimationAutomatic)];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
showToast(msg);
}];
}
-(UITableView *)tableView{
if (!_tableView) {
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.tableView.rowHeight = 48;
}
return _tableView;
}
-(UIView *)bgView{
if (!_bgView) {
_bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.tableHeaderView.height, SCREEN_WIDTH,SCREEN_HEIGHT-self.tableHeaderView.height )];
_bgView.backgroundColor = [UIColor whiteColor];
}
return _bgView;
}
-(QXUserInfoEditHeaderView *)tableHeaderView{
if (!_tableHeaderView) {
_tableHeaderView = [[QXUserInfoEditHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 263+kSafeAreaTop)];
}
return _tableHeaderView;
}
-(QXUserInfoEditFooterView *)tableFooterView{
if (!_tableFooterView) {
CGFloat itemWidth = (SCREEN_WIDTH-16*2-20*2)/3;
_tableFooterView = [[QXUserInfoEditFooterView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, itemWidth*2+20+40)];
_tableFooterView.delegate = self;
}
return _tableFooterView;
}
-(NSMutableArray *)imgsArray{
if (!_imgsArray) {
_imgsArray = [NSMutableArray array];
}
return _imgsArray;
}
@end