RankChildController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // RankChildController.m
  3. // model
  4. //
  5. // Created by Drew on 2018/11/2.
  6. // Copyright © 2018 Mine. All rights reserved.
  7. //
  8. #import "RankChildController.h"
  9. #import "RankCell.h"
  10. #import "RankHeader.h"
  11. static NSString *cellId = @"RankCell";
  12. @interface RankChildController () <UITableViewDelegate, UITableViewDataSource>
  13. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  14. @property (weak, nonatomic) IBOutlet UILabel *myRank;
  15. @property (weak, nonatomic) IBOutlet UILabel *myName;
  16. @property (weak, nonatomic) IBOutlet UIImageView *myAvatar;
  17. @property (weak, nonatomic) IBOutlet UILabel *myMoney;
  18. @property (weak, nonatomic) IBOutlet UIView *myView;
  19. @property (nonatomic, strong) NSMutableArray* tableData;
  20. @property (nonatomic, strong) RankHeader* headerView;
  21. @end
  22. @implementation RankChildController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.myView.layer.cornerRadius = 8;
  26. self.myView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1].CGColor;
  27. self.myView.layer.shadowOffset = CGSizeMake(0,-4);
  28. self.myView.layer.shadowOpacity = 1;
  29. self.myView.layer.shadowRadius = 4;
  30. self.tableView.dataSource = self;
  31. self.tableView.delegate = self;
  32. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  33. self.tableView.contentInset = UIEdgeInsetsMake(15, 0, 48, 0);
  34. self.tableView.tableHeaderView = self.headerView;
  35. [self getData];
  36. }
  37. - (NSMutableArray*)tableData {
  38. if (!_tableData) {
  39. _tableData = [NSMutableArray arrayWithCapacity:0];
  40. }
  41. return _tableData;
  42. }
  43. - (RankHeader*)headerView {
  44. if (!_headerView) {
  45. _headerView = [[RankHeader alloc] init];
  46. _headerView.frame = CGRectMake(0, 0, ScreenWidth - 30, 240);
  47. }
  48. return _headerView;
  49. }
  50. - (void)getData {
  51. NSString* day;
  52. if ([@"week" isEqualToString:self.type]) {
  53. day = @"7";
  54. } else {
  55. day = @"30";
  56. }
  57. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[ModelUser modelUser].pk, @"memberpk", day, @"day", nil];
  58. [YanCNetWorkManager requestPostWithURLStr:Url_rank(PublicUrl)
  59. parameters:dic
  60. finish:^(id res) {
  61. BOOL success = [res[@"success"] intValue];
  62. if (success) {
  63. [self.tableData addObjectsFromArray:res[@"data"][@"list"]];
  64. [self.tableView reloadData];
  65. self.headerView.data = res[@"data"][@"list"];
  66. if (res[@"data"][@"myRank"]) {
  67. self.myView.hidden = NO;
  68. self.myName.text = res[@"data"][@"myRank"][@"name"];
  69. [self.myAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", imageURl, res[@"data"][@"myRank"][@"avatar"]]]
  70. placeholderImage:[UIImage imageNamed:@"morentouxinag"]];
  71. self.myMoney.text = [[NSDecimalNumber numberWithDouble:[res[@"data"][@"myRank"][@"coin"] doubleValue]] stringValue];
  72. if (res[@"data"][@"myRank"][@"rank"] > 0) {
  73. self.myRank.text = [NSString stringWithFormat:@"第%@名", res[@"data"][@"myRank"][@"rank"]];
  74. } else {
  75. self.myRank.text = @"未上榜";
  76. }
  77. } else {
  78. self.myView.hidden = YES;
  79. }
  80. } else {
  81. [MBProgressHUD showInfo:@"请求失败!"];
  82. }
  83. }
  84. enError:^(NSError *error) {
  85. [MBProgressHUD hideHUDForView:self.view animated:YES];
  86. }];
  87. }
  88. #pragma mark - UITableView Delegate
  89. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  90. return 1;
  91. }
  92. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  93. if (self.tableData.count > 3) {
  94. return self.tableData.count - 3;
  95. }
  96. return 0;
  97. }
  98. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  99. return 64;
  100. }
  101. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  102. RankCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellId];
  103. if (!cell) {
  104. NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellId owner:self options:nil];
  105. cell = [nib objectAtIndex:0];
  106. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  107. cell.data = [self.tableData objectAtIndex:indexPath.row + 3];
  108. }
  109. return cell;
  110. }
  111. #pragma mark -
  112. @end