MitangViewController.m 6.2 KB
//
//  MitangViewController.m
//  IVTMeLiveTwo
//
//  Created by xrg on 16/10/14.
//  Copyright © 2016年 QLQ. All rights reserved.
//

#import "MitangViewController.h"

@interface MitangViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSArray *imageArray;
    NSMutableArray *requestDataArray;
    UILabel * noDataLabel;
}
@property (nonatomic, retain) UITableView *hintTable;

@end
@implementation MitangViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    requestDataArray = [[NSMutableArray alloc]initWithCapacity:10];
    
    self.view.backgroundColor = [UIColor IVTBackgroundColor];

    [self buildHintTable];
    imageArray = @[@"贡献榜第一名",@"贡献榜第二名",@"贡献榜第三名"];
    [self request];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doChangeFollowStatus) name:@"followedChanged" object:nil];
    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];
    
    self.navigationItem.title = @"蜜糖贡献榜";
}




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


//返回按钮点击
-(void)backToTopPage:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)buildHintTable
{
    if (_hintTable==nil) {
        self.hintTable = [[UITableView alloc] init];
        _hintTable.backgroundColor = [UIColor IVTBackgroundColor];
        _hintTable.frame = CGRectMake(0, 0, kScreenWidth   , kScreenHeight-58);
        _hintTable.delegate = self;
        _hintTable.dataSource = self;
        _hintTable.showsHorizontalScrollIndicator = NO;
        _hintTable.showsVerticalScrollIndicator = NO;
        _hintTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _hintTable.tableFooterView = [UIView new];
        [self.view addSubview:_hintTable];
    }
}

#pragma Mark - 网络请求
-(void)request{
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    if (_isMain==YES) {
        [dict setObject:[IVTAccountTool getUserId] forKey:@"userId"];
    }else{
        [dict setObject:self.userID forKey:@"userId"];
    }
    
    [dict setObject:[IVTAccountTool getPassword] forKey:@"captcha"];
    [dict setObject:[IVTAccountTool getUserName] forKey:@"username"];
    [dict setObject:@"1"  forKey:@"page"];
    [[IVTNetworkAPIClient sharedClient] getContributionListForUser:dict success:^(NSDictionary *successData) {
        [requestDataArray addObjectsFromArray:[successData valueForKey:@"data"]];
        if (requestDataArray.count == 0) {
            noDataLabel.hidden = NO;
        }
        else{
            noDataLabel.hidden = YES;
            if (requestDataArray!=nil) {
                for (int i=0; i<[requestDataArray count]; i++) {
                    NSMutableDictionary *listDic =[[requestDataArray objectAtIndex:i] mutableCopy];
                    [listDic setObject:[NSString stringWithFormat:@"%ld",[listDic[@"userId"] integerValue]] forKey:@"id"];
                    [requestDataArray replaceObjectAtIndex:i withObject:[listDic copy]];
                }
            }
        }
        [_hintTable reloadData];
    } error:^(NSDictionary *successData) {
        
    } failure:^(NSError *failureError) {
        LRLog(@"failureError:%@",failureError);
    }];
}


#pragma mark - table datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return requestDataArray.count;
    
}

- (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 addSubview:[self addLineViews]];
        }
        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 addSubview:[self addLineView]];
            cell.selectionStyle  =UITableViewCellSelectionStyleNone;
        }
        cell.entity = [requestDataArray objectAtIndex:indexPath.row];
        
        return cell;
        
    }
}

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

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


- (UIView*)addLineView
{
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 59.0-0.5, kScreenWidth, 0.5)];
    line.backgroundColor = [UIColor IVTSeparatorColor];
    return line;
}
- (UIView*)addLineViews
{
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 77.0-0.5, kScreenWidth, 0.5)];
    line.backgroundColor = [UIColor IVTSeparatorColor];
    return line;
}



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

@end