201 lines
7.3 KiB
Objective-C
Executable File
201 lines
7.3 KiB
Objective-C
Executable File
//
|
|
// SPMineEditInfoVC.m
|
|
// SweetParty
|
|
//
|
|
// Created by bj_szd on 2022/6/9.
|
|
//
|
|
|
|
#import "SPMineEditInfoVC.h"
|
|
#import "SPMineEditInfoCell.h"
|
|
#import "SPMineEditAlbumView.h"
|
|
#import "BRPickerView.h"
|
|
|
|
@interface SPMineEditInfoVC () <UITextFieldDelegate>
|
|
|
|
@property (nonatomic, strong) SPMineEditAlbumView *albumView;
|
|
@property (nonatomic, strong) NSArray *titlesArr;
|
|
|
|
@end
|
|
|
|
@implementation SPMineEditInfoVC
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
self.titlesArr = @[@"头像", @"昵称", @"性别", @"生日", @"个性签名"];
|
|
|
|
[self showNaviBarWithTitle:@"编辑资料"];
|
|
|
|
[self createUI];
|
|
|
|
[self fetchAlbumData];
|
|
}
|
|
|
|
-(void)createUI {
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"SPMineEditInfoCell" bundle:nil] forCellReuseIdentifier:@"SPMineEditInfoCell"];
|
|
|
|
[ControlCreator createButton:self.naviView rect:CGRectMake(ScreenWidth-40-12, yb_StatusBar_H+7, 40, 30) text:@"保存" font:YBMediumFont(14) color:HEXCOLOR(0x333333) backguoundColor:nil imageName:nil target:self action:@selector(onSave)];
|
|
}
|
|
|
|
-(void)fetchAlbumData {
|
|
NSDictionary *params = @{@"from_id":C_string(self.model.uid)};
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"api/player/player_home_page" Loading:YES Hud:NO Success:^(id _Nonnull responseDic) {
|
|
SPHomepageModel *model = [SPHomepageModel mj_objectWithKeyValues:responseDic[@"data"]];
|
|
self.albumView.model = model;
|
|
self.tableView.tableFooterView = self.albumView;
|
|
|
|
} Failure:^(id _Nonnull errorData) {
|
|
|
|
}];
|
|
}
|
|
|
|
- (void)onSave {
|
|
if (self.model.nick_name <= 0) {
|
|
[HelpPageDefine showMessage:@"请输入昵称"];
|
|
return;
|
|
}
|
|
if (self.model.autograph <= 0) {
|
|
[HelpPageDefine showMessage:@"请输入个性签名"];
|
|
return;
|
|
}
|
|
NSDictionary *params = @{@"head_pic":self.model.head_pic, @"nick_name":self.model.nick_name, @"autograph":self.model.autograph, @"sex":@(self.model.sex), @"birthday":self.model.birthday};
|
|
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"api/user/modify_user_info" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
} Failure:^(id _Nonnull errorData) {
|
|
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return self.titlesArr.count;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
SPMineEditInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SPMineEditInfoCell" forIndexPath:indexPath];
|
|
cell.selectionStyle = NO;
|
|
WEAK_SELF
|
|
cell.contentTF.tag = indexPath.row;
|
|
cell.contentTF.delegate = self;
|
|
NSString *title = self.titlesArr[indexPath.row];
|
|
cell.titleLab.text = title;
|
|
if ([title isEqualToString:@"头像"]) {
|
|
cell.avatarImgV.hidden = NO;
|
|
cell.contentTF.hidden = YES;
|
|
}else {
|
|
cell.avatarImgV.hidden = YES;
|
|
cell.contentTF.hidden = NO;
|
|
}
|
|
|
|
if ([title isEqualToString:@"头像"]) {
|
|
[cell.avatarImgV sd_setImageWithURL:[NSURL URLWithString:self.model.head_pic] placeholderImage:kDefaultUserIcon];
|
|
cell.onUploadAvatarBlock = ^(NSString * _Nonnull headUrlStr) {
|
|
weakSelf.model.head_pic = headUrlStr;
|
|
};
|
|
} else if ([title isEqualToString:@"昵称"]) {
|
|
cell.contentTF.text = self.model.nick_name;
|
|
cell.textChangeBlock = ^(NSString * _Nonnull text) {
|
|
weakSelf.model.nick_name = text;
|
|
};
|
|
} else if ([title isEqualToString:@"性别"]) {
|
|
cell.contentTF.text = self.model.sex == 1 ? @"男" : @"女";
|
|
} else if ([title isEqualToString:@"生日"]) {
|
|
cell.contentTF.text = self.model.birthday;
|
|
} else if ([title isEqualToString:@"个性签名"]) {
|
|
cell.contentTF.text = self.model.autograph;
|
|
cell.textChangeBlock = ^(NSString * _Nonnull text) {
|
|
weakSelf.model.autograph = text;
|
|
};
|
|
}
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (0 == indexPath.row) {
|
|
return 80;
|
|
}else {
|
|
return 54;
|
|
}
|
|
}
|
|
|
|
#pragma mark - UITextFieldDelegate
|
|
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
|
|
NSString *title = self.titlesArr[textField.tag];
|
|
if ([title isEqualToString:@"昵称"] || [title isEqualToString:@"个性签名"]) {
|
|
return YES; // 当前 textField 可以编辑
|
|
} else {
|
|
[self.view endEditing:YES];
|
|
[self handlerTextFieldSelect:textField];
|
|
return NO; // 当前 textField 不可编辑,可以响应点击事件
|
|
}
|
|
}
|
|
|
|
#pragma mark - 处理点击事件
|
|
- (void)handlerTextFieldSelect:(UITextField *)textField {
|
|
NSString *title = self.titlesArr[textField.tag];
|
|
if ([title isEqualToString:@"性别"]) {
|
|
BRStringPickerView *stringPickerView = [[BRStringPickerView alloc] init];
|
|
stringPickerView.pickerMode = BRStringPickerComponentSingle;
|
|
stringPickerView.dataSourceArr = @[@"男", @"女"];
|
|
stringPickerView.resultModelBlock = ^(BRResultModel *resultModel) {
|
|
self.model.sex = resultModel.index+1;
|
|
textField.text = resultModel.selectValue;
|
|
};
|
|
stringPickerView.pickerStyle = [self customPickerViewUI];
|
|
[stringPickerView show];
|
|
} else if ([title isEqualToString:@"生日"]) {
|
|
BRDatePickerView *datePickerView = [[BRDatePickerView alloc] init];
|
|
datePickerView.pickerMode = BRDatePickerModeYMD;
|
|
datePickerView.minDate = [NSDate br_setYear:1900 month:1 day:1];
|
|
datePickerView.maxDate = [NSDate date];
|
|
datePickerView.showUnitType = BRShowUnitTypeNone;
|
|
datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
|
|
self.model.birthday = selectValue;
|
|
textField.text = selectValue;
|
|
};
|
|
datePickerView.pickerStyle = [self customPickerViewUI];
|
|
[datePickerView show];
|
|
}
|
|
}
|
|
|
|
- (BRPickerStyle *)customPickerViewUI {
|
|
BRPickerStyle *style = [[BRPickerStyle alloc] init];
|
|
style.selectedColor = [UIColor whiteColor];
|
|
style.topCornerRadius = 10;
|
|
style.hiddenShadowLine = YES;
|
|
style.hiddenTitleLine = YES;
|
|
style.hiddenTitleLabel = YES;
|
|
style.titleBarColor = HEXCOLOR(0xF5F7F7);
|
|
style.cancelTextColor = HEXCOLOR(0x999999);
|
|
style.cancelTextFont = [UIFont boldSystemFontOfSize:16];
|
|
style.cancelBtnFrame = CGRectMake(0, 0, 60, 50);
|
|
style.cancelBtnTitle = @"取消";
|
|
style.doneTextColor = mainDeepColor;
|
|
style.doneTextFont = [UIFont boldSystemFontOfSize:16];
|
|
style.doneBtnFrame = CGRectMake(SCREEN_WIDTH-60, 0, 60, 50);
|
|
style.doneBtnTitle = @"确定";
|
|
style.separatorColor = [UIColor clearColor];
|
|
style.pickerTextColor = HEXCOLOR(0x333333);
|
|
style.pickerTextFont = [UIFont systemFontOfSize:16];
|
|
style.pickerColor = HEXCOLOR(0xF5F7F7);;
|
|
style.rowHeight = 44;
|
|
return style;
|
|
}
|
|
|
|
- (SPMineEditAlbumView *)albumView {
|
|
if (!_albumView) {
|
|
_albumView = [[NSBundle mainBundle] loadNibNamed:@"SPMineEditAlbumView" owner:self options:nil].firstObject;
|
|
CGFloat itemW = (ScreenWidth-15*2-12*2)/3;
|
|
_albumView.frame = CGRectMake(0, 0, ScreenWidth, 70+itemW*2+12);
|
|
}
|
|
return _albumView;
|
|
}
|
|
|
|
@end
|