CNLiveUserInfoController.m 8.69 KB
//
//  CNLiveMineController.m
//  CNLiveMineModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright (c) 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveUserInfoController.h"
#import "MJExtension.h"
#import "QMUIKit.h"

#import "CNLiveUserInfoCell.h"
#import "CNLiveUserInfoModel.h"
#import "CNLiveInfoUpdateController.h"
#import "CNLiveUserInfoNotification.h"
#import "CNLiveMyQrCodeController.h"
#import "CNLiveUserInfoNavigationBar.h"

@interface CNLiveUserInfoController ()<UITableViewDelegate, UITableViewDataSource, CNLiveInfoUpdateDelegate, CNLiveUserInfoNavigationBarDelegate>{
    UIImage *_image;
}
@property (nonatomic, strong) CNLiveUserInfoNavigationBar *navigationBar;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *data;

@end

@implementation CNLiveUserInfoController
#pragma mark - 加载数据
- (void)loadData {
    NSArray *data = @[
                      @{
                          @"layout":@"2",
                          @"data":@"0",
                          @"title":@"头像",
                          @"content":@"default_avatar_f",
                          @"height":@"81",
                          @"lineHeight":@"0.5"
                          },
                      @{
                          @"layout":@"1",
                          @"data":@"1",
                          @"title":@"昵称",
                          @"content":@"User_Name",
                          @"height":@"51",
                          @"lineHeight":@"0.5"
                          },
                      @{
                          @"layout":@"1",
                          @"data":@"2",
                          @"title":@"性别",
                          @"content":@"User_Gender",
                          @"height":@"60",
                          @"lineHeight":@"10"
                          },
                      @{
                          @"layout":@"2",
                          @"data":@"3",
                          @"title":@"二维码",
                          @"content":@"二维码",
                          @"height":@"51",
                          @"lineHeight":@"0.5"
                          },
                      @{
                          @"layout":@"1",
                          @"data":@"4",
                          @"title":@"地区",
                          @"content":@"User_Address",
                          @"height":@"60",
                          @"lineHeight":@"10"
                          },
                      @{
                          @"layout":@"1",
                          @"data":@"5",
                          @"title":@"个性签名",
//                          @"content":User_Introduction?User_Introduction:@"这个人很懒!!!",
                          @"content":@"这个人很懒!!!",
                          @"height":@"51",
                          @"lineHeight":@"0.5"
                          }
                      
                      ];
    for(NSDictionary *dic in data){
        [self.data addObject:[CNLiveUserInfoModel mj_objectWithKeyValues:dic]];
    }
    [self.tableView reloadData];
    
}

#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 11, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self createSubViews];
    [self loadData];
    
}

- (void)dealloc {
    
    
}

- (void)createSubViews {
    [self.view addSubview:self.navigationBar];
    [self.view addSubview:self.tableView];

}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CNLiveUserInfoModel *model = self.data[indexPath.row];
    return model.height;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CNLiveUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveUserInfoCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    CNLiveUserInfoModel *model = self.data[indexPath.row];
    cell.model = model;
    if(_image){
        cell.image = _image;
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CNLiveUserInfoModel *model = self.data[indexPath.row];
    switch (model.dataType) {
        case CNLiveUserInfoDataTypeHead:
        {
            [self updateHeaderActionSheetView];
        }
            break;
        case CNLiveUserInfoDataTypeNickname:
        {
            CNLiveInfoUpdateController *vc = [[CNLiveInfoUpdateController alloc]initWithModel:model];
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case CNLiveUserInfoDataTypeGender:
        {
            [self updateGenderActionSheetView];
        }
            break;
        case CNLiveUserInfoDataTypeCode:
        {
            CNLiveMyQrCodeController *vc = [[CNLiveMyQrCodeController alloc]init];;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case CNLiveUserInfoDataTypeAddress:
        {
            CNLiveInfoUpdateController *vc = [[CNLiveInfoUpdateController alloc]initWithModel:model];
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case CNLiveUserInfoDataTypeIntroduction:
        {
            CNLiveInfoUpdateController *vc = [[CNLiveInfoUpdateController alloc]initWithModel:model];
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        default:
            break;
    }
}
#pragma mark - CNLiveInfoUpdateDelegate
- (void)updateSuccess:(CNLiveUserInfoDataType)dataType info:(NSString *)info{
    [self updateDataType:dataType info:info];
}

- (void)navigationBar:(CNLiveUserInfoNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
    if ([actionEvents isEqualToString:@"1"]) {
        [self goBack];
    }
}
#pragma mark - 私有方法
// 修改头像
- (void)updateHeaderActionSheetView{
    __weak typeof(self) weakSelf = self;

}

// 更新头像
- (void)requestUpdateUserHeader:(UIImage *)image{
    // 数据请求更新
    

}

// 修改性别
- (void)updateGenderActionSheetView{
    __weak typeof(self) weakSelf = self;
    
}

// 更新性别
- (void)requestUpdateUserGender:(NSString *)gender{
    // 数据请求更新
   
    
}
// 更新cell展示信息
- (void)updateDataType:(CNLiveUserInfoDataType)dataType info:(NSString *)info{
    for(CNLiveUserInfoModel *model in self.data){
        if(dataType == model.dataType){
            model.content = info;
            break;
        }
    }
    [self.tableView reloadData];
}

#pragma mark - 懒加载
- (CNLiveUserInfoNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [[CNLiveUserInfoNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
        _navigationBar.delegate = self;
        _navigationBar.title.text = @"个人资料";
        _navigationBar.right = nil;
    }
    return _navigationBar;
}

- (NSMutableArray *)data {
    if (!_data) {
        _data = [NSMutableArray array];
    }
    return _data;
}

- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.bounces = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[CNLiveUserInfoCell class] forCellReuseIdentifier:kCNLiveUserInfoCell];
    }
    return _tableView;
}

#pragma mark - 响应方法
- (void)goBack {
    if (self.presentingViewController != nil) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

@end