This commit is contained in:
lianxiang
2018-09-17 22:58:04 +08:00
parent 718900a428
commit 1a4b9db16f
22 changed files with 17646 additions and 32 deletions
@@ -37,10 +37,11 @@
self.tableView.estimatedSectionFooterHeight= 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.bounces = NO;
self.tableView.frame = CGRectMake(0,PhoneX_TopMargin + 1, KMainW,KMainH - PhoneX_BottomMargin);
self.tableView.frame = CGRectMake(0, 1, KMainW, self.view.bounds.size.height - SAFE_NAV_HEIGHT);
[self loadUserInfo];
}
-(void)loadUserInfo{
GiGaUser *currentuser = [[GiGaUserManager shareUser] getCurrentUser];
@@ -16,18 +16,31 @@
#import "GiGaUserManager.h"
#import "LYSDatePickerController.h"
#import "JYAddressPicker.h"
#import "GiGaBaseAPiRequest.h"
#import "GiGaUserJobViewCell.h"
@interface GiGaUserViewController ()<LYSDatePickerSelectDelegate>
@property (nonatomic,strong) GiGaUser *user;
@property (nonatomic,strong) NSMutableArray *jobArr;
@property (nonatomic) BOOL jobSpread;
@end
@implementation GiGaUserViewController
- (NSArray *)jobArr{
if (!_jobArr) {
_jobArr = [NSMutableArray new];
}
return _jobArr;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//self.title = @"个人中心";
_jobSpread = NO;
[self getJobInfos];
self.user = [[GiGaUserManager shareUser] getCurrentUser];
[self addNavTitile:@"个人信息"];
@@ -50,15 +63,18 @@
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
self.tableView.sectionFooterHeight = 0;
self.tableView.estimatedSectionFooterHeight= 0;
self.tableView.estimatedSectionFooterHeight= 10;
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 10)];
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.bounces = NO;
self.tableView.frame = CGRectMake(0,PhoneX_TopMargin + 1, KMainW,KMainH - PhoneX_BottomMargin);
self.tableView.bounces = YES;
self.tableView.frame = CGRectMake(0, 1, KMainW,self.view.bounds.size.height - SAFE_NAV_HEIGHT);
[self.tableView registerClass: [GiGaUserJobViewCell class] forCellReuseIdentifier:@"GiGaUserJobViewCell"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 3;
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
@@ -67,8 +83,11 @@
return 1;
}else if (section == 1){
return 3;
}else if (section == 3){
return 1;
}
return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
@@ -86,7 +105,6 @@
cell = [[[NSBundle mainBundle] loadNibNamed:@"GIGaUserIDViewCell" owner:self options:nil] lastObject];
}
[cell loadCellData:indexPath user: self.user];
return cell;
@@ -121,8 +139,30 @@
cell = [[[NSBundle mainBundle] loadNibNamed:@"GIGaUserCityViewCell" owner:self options:nil] lastObject];
}
[cell loadCellData:indexPath user:self.user];
return cell;
}else if (indexPath.section == 3){
static NSString *cellID = @"GiGaUserJobViewCell";
GiGaUserJobViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
if (!cell) {
cell = [[GiGaUserJobViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
[cell userSelectjobAction:^() {
self.jobSpread = !self.jobSpread;
[tableView reloadSections:[NSIndexSet indexSetWithIndex:3] withRowAnimation:UITableViewRowAnimationNone];
}];
[cell setButtnImage:self.jobSpread with:self.jobArr];
[cell userSelectjob:^(NSString *title) {
self.user.occupationCode = title;
[tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:3 inSection:2]] withRowAnimation:UITableViewRowAnimationNone];
}];
return cell;
}
return nil;
}
@@ -131,33 +171,47 @@
if (indexPath.section == 2 && indexPath.row == 1) {
[LYSDatePickerController alertDatePickerWithController:self type:(LYSDatePickerTypeDay)];
[LYSDatePickerController customPickerDelegate:self];
weakify(self);
[LYSDatePickerController customdidSelectDatePicker:^(NSDate *date) {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy/MM/dd"];
NSString *currentDate = [dateFormat stringFromDate:date];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.detailTextLabel.text = currentDate;
GIGaUserCityViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
weakSelf.user.birthday = currentDate;
[cell loadCellData:indexPath user:weakSelf.user];
}];
}else if (indexPath.section == 2 && indexPath.row == 2){
JYAddressPicker *addressPicker = [JYAddressPicker jy_showAt:self];
weakify(self);
addressPicker.selectedItemBlock = ^(NSArray *addressArr) {
NSString *province = [addressArr objectAtIndex:0][@"text"];
NSString *city = [addressArr objectAtIndex:1][@"text"];
NSString *county = [addressArr objectAtIndex:2][@"text"];
NSString *addres = [NSString stringWithFormat:@"%@%@%@",province,city,county];
GILog(@"%@",addres);
GIGaUserCityViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
weakSelf.user.provinceName = province;
weakSelf.user.cityName = city;
weakSelf.user.areaName = county;
[cell loadCellData:indexPath user:self.user];
};
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section==0){
return 133;
}else if (indexPath.section==3){
if (self.jobArr.count <= 0) {
return 0;
}else{
return self.jobSpread == YES ? 246 : 85;
}
}else {
return 44;
}
@@ -168,6 +222,7 @@
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 1){
return 10;
}else if (section == 2){
@@ -192,10 +247,67 @@
}
#pragma mark - 保存用户信息
-(void)saveUserInfo{
if (!self.user.nickName || [self.user.nickName isKindOfClass:[NSNull class]]) {
self.user.nickName = @"";
}
if (!self.user.weixin || [self.user.weixin isKindOfClass:[NSNull class]]) {
self.user.weixin = @"";
}
if (!self.user.birthday || [self.user.birthday isKindOfClass:[NSNull class]]) {
self.user.birthday = @"";
}
if (!self.user.occupationCode|| [self.user.occupationCode isKindOfClass:[NSNull class]]) {
self.user.occupationCode = @"";
}
NSDictionary *param = @{
@"provinceId":@"1_11",
@"cityId":@"1_11",
@"areaId":@"1_11_8",
@"nickName":self.user.nickName,
@"weixin":self.user.weixin,
@"sexCode":[NSString stringWithFormat:@"%d",self.user.sexCode],
@"birthday":self.user.birthday,
@"occupationCode":self.user.occupationCode
};
GiGaBaseAPiRequest *api =[GiGaBaseAPiRequest initWithRequestPath:kFixUserInfo method:RequestPostMethod parms:param];
[api requstDataWithResult:^(GiGaAPIResult *result) {
if (result.success) {
GIGA_ShowToast(@"修改成功");
}else{
GIGA_ShowToast(result.dic[@"msg"]);
}
}];
}
#pragma mark - 获取职业数据
-(void)getJobInfos{
NSDictionary *param = @{};
GiGaBaseAPiRequest *api =[GiGaBaseAPiRequest initWithRequestPath:kApiOccuption method:RequestPostMethod parms:param];
[api requstDataWithResult:^(GiGaAPIResult *result) {
if (result.success) {
GILog(@"%@",result.dic);
NSDictionary *dic = result.dic;
NSArray *josA = dic[@"list"];
for (NSDictionary *jobDic in josA ) {
[self.jobArr addObject:jobDic[@"dictLabel"]];
}
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:3] withRowAnimation:UITableViewRowAnimationNone];
}else{
NSString *msg = result.dic[@"msg"];
GIGA_ShowToast(msg);
}
}];
}
@end
+4 -4
View File
@@ -25,7 +25,7 @@
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.backgroundColor = [UIColor lightGrayColor];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
self.tableView.sectionFooterHeight = 0;
self.tableView.estimatedSectionFooterHeight= 0;
@@ -49,7 +49,6 @@
if(!cell){
cell = [[[NSBundle mainBundle] loadNibNamed:@"GiGaSettingsViewCell" owner:self options:nil] lastObject];
}
[cell loadCellDataAt:indexPath];
return cell;
@@ -59,7 +58,6 @@
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
@@ -84,11 +82,13 @@
[btn setTitle:@"退出登录" forState:UIControlStateNormal];
btn.layer.masksToBounds = YES;
btn.layer.cornerRadius = btn.frame.size.height / 2;
btn.backgroundColor = [UIColor greenColor];
btn.backgroundColor = GIGA_MAIN_BGCOLOR;
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(userLogOutAction) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:btn];
return view;
}
- (void)didReceiveMemoryWarning {
+13
View File
@@ -0,0 +1,13 @@
//
// JobMaskButton.h
// GIGA
//
// Created by lianxiang on 2018/9/17.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface JobMaskButton : UIButton
@property (nonatomic,copy) NSString *jobStr;
@end
+21
View File
@@ -0,0 +1,21 @@
//
// JobMaskButton.m
// GIGA
//
// Created by lianxiang on 2018/9/17.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "JobMaskButton.h"
@implementation JobMaskButton
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
@@ -18,7 +18,7 @@
-(void)loadCellData:(NSIndexPath*)indexPath user:(GiGaUser*)user{
if (indexPath.section == 2 && indexPath.row == 1) {
self.cityLabel.text = @"生日";
if (user.birthday && ![user.birthday isKindOfClass:[NSNull class]]) {
if (user.birthday && ![user.birthday isKindOfClass:[NSNull class]] && ![user.birthday isEqualToString:@""]) {
self.detalTitle.text = user.birthday;
}else{
self.detalTitle.text = @"选择生日";
@@ -26,17 +26,28 @@
}else if (indexPath.section == 2 && indexPath.row == 2){
self.cityLabel.text = @"城市";
if (user.cityName && ![user.cityName isKindOfClass:[NSNull class]]) {
self.detalTitle.text = user.cityName;
}else{
if (!user.provinceName || [user.provinceName isKindOfClass:[NSNull class]]) {
user.provinceName = @"";
}
if (!user.cityName || [user.cityName isKindOfClass:[NSNull class]]) {
user.cityName = @"";
}
if (!user.areaName || [user.areaName isKindOfClass:[NSNull class]]) {
user.areaName = @"";
}
if ([user.provinceName isEqualToString:@""] && [user.provinceName isEqualToString:@""] && [user.provinceName isEqualToString:@""] ) {
self.detalTitle.text = @"选择城市";
}else{
self.detalTitle.text = [NSString stringWithFormat:@"%@%@%@",user.provinceName,user.cityName,user.areaName];
}
}else if (indexPath.section == 2 && indexPath.row == 3){
self.cityLabel.text = @"职业";
if (user.occupationCode && ![user.occupationCode isKindOfClass:[NSNull class]]) {
if (user.occupationCode && ![user.occupationCode isKindOfClass:[NSNull class]] && ![user.occupationCode isEqualToString:@""]) {
self.detalTitle.text = user.occupationCode;
}else{
self.detalTitle.text = @"选择职业";
self.detalTitle.text = @"请从下方标签中选择一项";
}
}
@@ -0,0 +1,27 @@
//
// GiGaUserJobViewCell.h
// GIGA
//
// Created by lianxiang on 2018/9/17.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
//展开关闭按钮
typedef void (^jobBtnAction)(void);
//选中
typedef void (^jobSelectAction)(NSString *title);
@interface GiGaUserJobViewCell : UITableViewCell
@property (nonatomic,strong) UIButton *upDownBtn;
@property (nonatomic,strong) NSArray *jobs;
-(void)userSelectjobAction:(jobBtnAction)block;
@property (nonatomic,copy) jobBtnAction actionblock;
-(void)userSelectjob:(jobSelectAction)block;
@property (nonatomic,copy) jobSelectAction jobblock;
-(void)setButtnImage:(BOOL)isUp with:(NSArray *)titles;
@end
@@ -0,0 +1,237 @@
//
// GiGaUserJobViewCell.m
// GIGA
//
// Created by lianxiang on 2018/9/17.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GiGaUserJobViewCell.h"
#import "JobMaskButton.h"
#define SPACE_X 8.f //横向间隔
#define SPACE_Y 8.f //纵向间隔
#define MAR_GAINX 22.f //左右边距
#define MARK_H 31.f //高
@interface GiGaUserJobViewCell()
@property (nonatomic,assign) int countY;
@property (nonatomic,assign) int countX;
@property (nonatomic,strong) NSArray *titles;
@property (nonatomic,copy) NSString *selectjob;
@end
@implementation GiGaUserJobViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
_countY = 0;
_countX = 0;
[self creatUI];
self.titles = [NSArray new];
//self.backgroundColor = [UIColor blueColor];
}
return self;
}
-(void)creatUI{
[self addSubview:self.upDownBtn];
}
-(void)updateActionBtnFrame{
_upDownBtn.frame = CGRectMake(KMainW - 22 - 55,self.frame.size.height - 31, 55, 31);
}
- (UIButton *)upDownBtn{
if (!_upDownBtn) {
_upDownBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_upDownBtn.frame = CGRectMake(KMainW - 22 - 55, 10, 55, 31);
[_upDownBtn addTarget:self action:@selector(upDownBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _upDownBtn;
}
-(void)upDownBtnAction:(UIButton *)btn{
if (btn.selected) {
NSLog(@"up");
}else{
NSLog(@"down");
}
//btn.selected = btn.selected;
self.actionblock();
}
-(void)setButtnImage:(BOOL)isUp with:(NSArray *)titles{
self.titles = titles;
self.selectjob = @"";
if (isUp) {
[self setUpUPSubViewstitles:titles isUp:isUp];
}else{
[self setUpDownSubviewstitles:titles isUp:isUp];
}
}
-(void)setUpUPSubViewstitles:(NSArray *)titles isUp:(BOOL)isUp{
//展开状态
[_upDownBtn setBackgroundImage:[UIImage imageNamed:@"userjob_up"] forState:UIControlStateNormal];
if (titles.count > 0) {
for (JobMaskButton *btn in self.subviews) {
if ([btn isKindOfClass:[JobMaskButton class]]) {
[btn removeFromSuperview];
}
}
_countX =0;
_countY = 0;
CGFloat X = MAR_GAINX;
for (int i=0; i<titles.count; i ++) {
CGFloat width = 0;
NSString *title = titles[i];
if (title.length == 2) {
width = 55;
}else if (title.length == 3){
width = 68;
}else if (title.length == 4){
width = 88;
}else{
//[self makeToast:@"最小两个字"];
width = 55;
}
[self creatjob:titles[i] index:i isUp:isUp orinX:X width:width];
if (_countX == 0) {
X = MAR_GAINX;
}else{
X = X + width + SPACE_X;
}
}
}
}
-(void)setUpDownSubviewstitles:(NSArray *)titles isUp:(BOOL)isUp{
//收起状态
[_upDownBtn setBackgroundImage:[UIImage imageNamed:@"userjob_down"] forState:UIControlStateNormal];
if (titles.count > 0) {
// [titles enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// NSString *title = obj;
// [self creatjob:title index:idx];
// }];
for (JobMaskButton *btn in self.subviews) {
if ([btn isKindOfClass:[JobMaskButton class]]) {
[btn removeFromSuperview];
}
}
_countX =0;
_countY = 0;
CGFloat X = MAR_GAINX;
for (int i=0; i<titles.count; i ++) {
CGFloat width = 0;
NSString *title = titles[i];
if (title.length == 2) {
width = 55;
}else if (title.length == 3){
width = 68;
}else if (title.length == 4){
width = 88;
}else{
//[self makeToast:@"最小两个字"];
width = 55;
}
[self creatjob:titles[i] index:i isUp:isUp orinX:X width:width];
if (_countX == 0) {
X = MAR_GAINX;
}else{
X = X + width + SPACE_X;
}
}
}
}
-(void)creatjob:(NSString *)title index:(int)idx isUp:(BOOL)isUp orinX:(CGFloat)X width:(CGFloat)width{
CGFloat Y = 10 + (MARK_H + SPACE_Y)*_countY;
_countX ++;
if (!isUp) {
//关闭状态 只展示一行
if ((X + width + SPACE_X) > (KMainW - 55 - 22)){
return;
}
}else{
if (_countY == 0) {
if ((X + width + SPACE_X) > (KMainW - 55 - 22)){
_countY ++;
_countX = 0;
}
}else{
if ((X + width + SPACE_X) > (KMainW - 22 - width)){
_countY ++;
_countX = 0;
}
if (idx == self.titles.count - 1) {
[self updateActionBtnFrame];
}
}
}
JobMaskButton *jobBtn = [JobMaskButton buttonWithType:UIButtonTypeCustom];
[jobBtn setBackgroundImage:[UIImage imageNamed:@"btn_job"] forState:UIControlStateNormal];
jobBtn.jobStr = title;
NSAttributedString *attri = [GiGaHelper stringWithText:title textColor:GIGARGB(151, 151, 151, 1) textFont:GIGA_TEXTFONTMEDIUM(13) leterSpace:0];
[jobBtn setAttributedTitle:attri forState:UIControlStateNormal];
jobBtn.frame = CGRectMake(X,Y, width, MARK_H);
[jobBtn addTarget:self action:@selector(jobClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:jobBtn];
}
-(void)userSelectjobAction:(jobBtnAction)block{
self.actionblock = block;
}
-(void)userSelectjob:(jobSelectAction)block{
self.jobblock = block;
}
-(void)jobClick:(JobMaskButton *)btn{
self.jobblock(btn.jobStr);
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end