IVTMeSupportViewController.m 5.81 KB
//
//  IVTMeSupportViewController.m
//  IVTMeLiveTwo
//
//  Created by XRG on 16/8/22.
//  Copyright © 2016年 QLQ. All rights reserved.
//

#import "IVTMeSupportViewController.h"
#import "IVTMeSupportFirstCell.h"
#import "IVTMeSupportCommonCell.h"
#import "IVTUserInfoCenterViewController.h"

@interface IVTMeSupportViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray *imageArray;
    NSMutableArray *requestDataArray;
    UITableView *myTableView;
    UILabel *noDataLabel;
}
@end

@implementation IVTMeSupportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    __weak __typeof(self)weakSelf = self;
    
    [self setNavigationBar];
    
    [self doRequest];
    
    imageArray = @[@"贡献榜第一名",@"贡献榜第二名",@"贡献榜第三名"];
    requestDataArray = [[NSMutableArray alloc]initWithCapacity:10];
    
    noDataLabel = [[UILabel alloc]init];
    noDataLabel.font = [UIFont systemFontOfSize:13];
    noDataLabel.frame = CGRectMake(kScreenWidth / 2 - 100, kScreenWidth / 2 + 50, 200, 100);
    noDataLabel.text = @"没有数据";
    noDataLabel.hidden = YES;
    noDataLabel.font = [UIFont systemFontOfSize:16];
    noDataLabel.text = @"空空如也~~";
    noDataLabel.textAlignment = 1;
    [self.view addSubview:noDataLabel];

    myTableView = [[UITableView alloc]init];
    myTableView.delegate = self;
    myTableView.dataSource = self;
    myTableView.showsVerticalScrollIndicator = NO;
    myTableView.showsHorizontalScrollIndicator = NO;
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:myTableView];
    [myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.view.mas_left);
        make.right.equalTo(weakSelf.view.mas_right);
        make.top.equalTo(weakSelf.view.mas_top);
        make.bottom.equalTo(weakSelf.view.mas_bottom);
    }];
    
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doChangeFollowStatus) name:@"followedChanged" object:nil];
}

- (void)setNavigationBar{
    self.navigationItem.title = @"我的支持度";
}

- (void)doChangeFollowStatus{
    [myTableView reloadData];
}

- (void)doRequest{
    [HUDUtil showLoading];

    [[IVTNetworkAPIClient sharedClient] getMySupportListSuccess:^(NSDictionary *successData) {
        NSMutableArray *dataArray = [[successData valueForKey:@"data"] mutableCopy];
        [HUDUtil hide];
        if (requestDataArray!=nil) {

            for (int i=0; i<[dataArray count]; i++) {
                NSMutableDictionary *listDic =[[dataArray objectAtIndex:i] mutableCopy];
                [listDic setObject:[NSString stringWithFormat:@"%ld",[listDic[@"userId"] integerValue]] forKey:@"id"];
                [dataArray replaceObjectAtIndex:i withObject:[listDic copy]];
            }
            [requestDataArray addObjectsFromArray:dataArray];
            if (requestDataArray.count > 0) {
                noDataLabel.hidden = NO;
            }
            else{
                noDataLabel.hidden = YES;
            }
        }
        [myTableView reloadData];
    } error:^(NSDictionary *successData) {
        NSString *msg = successData[@"description"];
        [HUDUtil showError:msg];
    } failure:^(NSError *failureError) {
        [HUDUtil showError:@"网络异常"];
    }];
}
#pragma --mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return requestDataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0 || indexPath.row==2 || indexPath.row==1) {
        return 77;
    }else{
        return 59;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0 || indexPath.row==1 || indexPath.row==2) {
        IVTMeSupportFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"supportFirstCell"];
        if (!cell) {
            cell = [[IVTMeSupportFirstCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"supportFirstCell"];
            cell.backgroundColor  =[UIColor IVTTitleColor];
            cell.selectionStyle  =UITableViewCellSelectionStyleNone;
        }
        cell.entity = [requestDataArray objectAtIndex:indexPath.row];
        cell.goldImageName = imageArray[indexPath.row];
        return cell;
    }
    else{
        IVTMeSupportCommonCell *cell = [tableView dequeueReusableCellWithIdentifier:@"supportCell"];
        if (!cell) {
            cell = [[IVTMeSupportCommonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"supportCell"];
            cell.backgroundColor  =[UIColor IVTTitleColor];
            cell.selectionStyle  =UITableViewCellSelectionStyleNone;
        }
        cell.entity = [requestDataArray objectAtIndex:indexPath.row];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    IVTUserInfoCenterViewController *userInfoCenterVC = [[IVTUserInfoCenterViewController alloc]init];
    userInfoCenterVC.userId = [NSString stringWithFormat:@"%ld",[[[requestDataArray objectAtIndex:indexPath.row] valueForKey:@"id"] integerValue]];
    [self.navigationController pushViewController:userInfoCenterVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#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