| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // RankChildController.m
- // model
- //
- // Created by Drew on 2018/11/2.
- // Copyright © 2018 Mine. All rights reserved.
- //
- #import "RankChildController.h"
- #import "RankCell.h"
- #import "RankHeader.h"
- static NSString *cellId = @"RankCell";
- @interface RankChildController () <UITableViewDelegate, UITableViewDataSource>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (weak, nonatomic) IBOutlet UILabel *myRank;
- @property (weak, nonatomic) IBOutlet UILabel *myName;
- @property (weak, nonatomic) IBOutlet UIImageView *myAvatar;
- @property (weak, nonatomic) IBOutlet UILabel *myMoney;
- @property (weak, nonatomic) IBOutlet UIView *myView;
- @property (nonatomic, strong) NSMutableArray* tableData;
- @property (nonatomic, strong) RankHeader* headerView;
- @end
- @implementation RankChildController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.myView.layer.cornerRadius = 8;
- self.myView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1].CGColor;
- self.myView.layer.shadowOffset = CGSizeMake(0,-4);
- self.myView.layer.shadowOpacity = 1;
- self.myView.layer.shadowRadius = 4;
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.contentInset = UIEdgeInsetsMake(15, 0, 48, 0);
- self.tableView.tableHeaderView = self.headerView;
- [self getData];
- }
- - (NSMutableArray*)tableData {
- if (!_tableData) {
- _tableData = [NSMutableArray arrayWithCapacity:0];
- }
- return _tableData;
- }
- - (RankHeader*)headerView {
- if (!_headerView) {
- _headerView = [[RankHeader alloc] init];
- _headerView.frame = CGRectMake(0, 0, ScreenWidth - 30, 240);
- }
- return _headerView;
- }
- - (void)getData {
- NSString* day;
- if ([@"week" isEqualToString:self.type]) {
- day = @"7";
- } else {
- day = @"30";
- }
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser modelUser].pk, @"memberpk", day, @"day", nil];
- [YanCNetWorkManager requestPostWithURLStr:Url_rank(PublicUrl)
- parameters:dic
- finish:^(id res) {
- BOOL success = [res[@"success"] intValue];
- if (success) {
- [self.tableData addObjectsFromArray:res[@"data"][@"list"]];
- [self.tableView reloadData];
- self.headerView.data = res[@"data"][@"list"];
- if (res[@"data"][@"myRank"]) {
- self.myView.hidden = NO;
- self.myName.text = res[@"data"][@"myRank"][@"name"];
- [self.myAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", imageURl, res[@"data"][@"myRank"][@"avatar"]]]
- placeholderImage:[UIImage imageNamed:@"morentouxinag"]];
- self.myMoney.text = [[NSDecimalNumber numberWithDouble:[res[@"data"][@"myRank"][@"coin"] doubleValue]] stringValue];
- if (res[@"data"][@"myRank"][@"rank"] > 0) {
- self.myRank.text = [NSString stringWithFormat:@"第%@名", res[@"data"][@"myRank"][@"rank"]];
- } else {
- self.myRank.text = @"未上榜";
- }
- } else {
- self.myView.hidden = YES;
- }
- } else {
- [MBProgressHUD showInfo:@"请求失败!"];
- }
- }
- enError:^(NSError *error) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }];
- }
- #pragma mark - UITableView Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (self.tableData.count > 3) {
- return self.tableData.count - 3;
- }
- return 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 64;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- RankCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellId];
- if (!cell) {
- NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellId owner:self options:nil];
- cell = [nib objectAtIndex:0];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.data = [self.tableData objectAtIndex:indexPath.row + 3];
- }
- return cell;
- }
- #pragma mark -
- @end
|