LeaderboardTableViewCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // LeaderboardTableViewCell.m
  3. // BuguLive
  4. //
  5. // Created by yy on 16/10/11.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "LeaderboardTableViewCell.h"
  9. @implementation LeaderboardTableViewCell
  10. {
  11. GlobalVariables *_BuguLive;
  12. }
  13. - (void)awakeFromNib
  14. {
  15. [super awakeFromNib];
  16. _BuguLive = [GlobalVariables sharedInstance];
  17. self.nameLabel.textColor = UIColor.whiteColor;
  18. self.numLabel.layer.cornerRadius = 2;
  19. self.numLabel.clipsToBounds = YES;
  20. self.ticketLabel.textColor = [UIColor.whiteColor colorWithAlphaComponent:0.6];
  21. self.contentView.backgroundColor = kWhiteColor;
  22. }
  23. - (void)createCellWithModel:(UserModel *)model withRow:(int)row withType:(int)type
  24. {
  25. NSLog(@"createCellWithModel:(UserModel *)model withRow:(int)row withType:%d",type);
  26. self.headImgView.layer.cornerRadius = 20;
  27. self.headImgView.layer.masksToBounds = YES;
  28. self.model = model;
  29. //名次
  30. self.numLabel.text = [NSString stringWithFormat:@"%d",row+4];
  31. //昵称
  32. self.nameLabel.text = model.nick_name;
  33. //头像
  34. [self.headImgView sd_setImageWithURL:[NSURL URLWithString:model.head_image] placeholderImage:kDefaultPreloadHeadImg];
  35. //认证
  36. if ([model.is_authentication intValue] == 2)
  37. {
  38. self.vImgView.hidden = NO;
  39. [self.vImgView sd_setImageWithURL:[NSURL URLWithString:model.v_icon]];
  40. }
  41. else
  42. {
  43. self.vImgView.hidden = YES;
  44. }
  45. //性别
  46. if ([model.sex isEqualToString:@"1"])
  47. {
  48. self.sexImgView.image = [UIImage imageNamed:@"com_male_selected"];
  49. }
  50. else
  51. {
  52. self.sexImgView.image = [UIImage imageNamed:@"com_female_selected"];
  53. }
  54. //等级
  55. if ([model.user_level intValue] !=0)
  56. {
  57. self.rankImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"level%@",model.user_level]];
  58. }
  59. else
  60. {
  61. self.rankImgView.image = [UIImage imageNamed:@"rank_1"];
  62. }
  63. //善券
  64. NSString *string = type <= 3 ? ASLocalizedString(@"贡献"): ASLocalizedString(@"获得");
  65. NSString *ticketName = type <= 3 ? _BuguLive.appModel.diamond_name : _BuguLive.appModel.ticket_name;
  66. self.ticketLabel.text = [NSString stringWithFormat:@"%@",[self checkDiamondNum:model.ticket]];
  67. [self.concertBtn setTitle:@"" forState:UIControlStateNormal];
  68. if ([model.is_focus isEqualToString:@"1"]) {
  69. [self.concertBtn setTitle:ASLocalizedString(@"取关")forState:UIControlStateNormal];
  70. [self.concertBtn setBackgroundImage:[UIImage imageNamed:@"mg_new_rank_headBGGroup_Selected"] forState:UIControlStateNormal];
  71. }else{
  72. [self.concertBtn setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  73. [self.concertBtn setBackgroundImage:[UIImage imageNamed:@"mg_new_rank_headBGGroup"] forState:UIControlStateNormal];
  74. }
  75. if ([model.user_id isEqualToString:[IMAPlatform sharedInstance].host.imUserId]) {
  76. self.concertBtn.hidden = YES;
  77. }else{
  78. self.concertBtn.hidden = NO;
  79. }
  80. if (model.is_noble_ranking_stealth.integerValue == 1) {
  81. self.nameLabel.text =ASLocalizedString(@"神秘人");
  82. // [NSString stringWithFormat:ASLocalizedString(@"神秘人%@"), model.user_id];
  83. //头像
  84. [self.headImgView sd_setImageWithURL:nil placeholderImage:kDefaultNobleMysteriousHeadImg];
  85. self.concertBtn.hidden = YES;
  86. self.rankImgView.hidden = self.sexImgView.hidden = YES;
  87. }else{
  88. self.concertBtn.hidden = NO;
  89. self.rankImgView.hidden = self.sexImgView.hidden = NO;
  90. self.sexImgView.hidden = YES;
  91. }
  92. if ([model.user_id isEqualToString:[GlobalVariables sharedInstance].userModel.user_id]) {
  93. self.concertBtn.hidden = YES;
  94. }
  95. }
  96. -(NSString *)checkDiamondNum:(NSString *)num{
  97. NSString *numStr = @"";
  98. float numF = num.floatValue;
  99. if (numF > 10000) {
  100. numStr = [NSString stringWithFormat:ASLocalizedString(@"%.1f万"),floorf(numF/1000) / 10];
  101. // [NSString stringWithFormat:@"%.2f",num.floatValue];
  102. }else{
  103. numStr = [NSString stringWithFormat:@"%.0f",numF];
  104. }
  105. return numStr;
  106. }
  107. - (IBAction)clickAttentions:(UIButton *)sender {
  108. NSString *uid = self.model.user_id;
  109. NSMutableDictionary *dictM = [[NSMutableDictionary alloc]init];
  110. [dictM setObject:@"user" forKey:@"ctl"];
  111. [dictM setObject:@"follow" forKey:@"act"];
  112. [dictM setObject:uid forKey:@"to_user_id"];
  113. FWWeakify(self)
  114. [[NetHttpsManager manager] POSTWithParameters:dictM SuccessBlock:^(NSDictionary *responseJson)
  115. {
  116. FWStrongify(self)
  117. if ([responseJson toInt:@"status"] == 1)
  118. {
  119. NSInteger has_focus = [responseJson toInt:@"has_focus"];
  120. if (has_focus == 1) {
  121. [sender setTitle:ASLocalizedString(@"取关")forState:UIControlStateNormal];
  122. [self.concertBtn setBackgroundImage:[UIImage imageNamed:@"mg_new_rank_headBGGroup_Selected"] forState:UIControlStateNormal];
  123. }else{
  124. [sender setTitle:ASLocalizedString(@"关注")forState:UIControlStateNormal];
  125. [self.concertBtn setBackgroundImage:[UIImage imageNamed:@"mg_new_rank_headBGGroup"] forState:UIControlStateNormal];
  126. }
  127. }
  128. } FailureBlock:^(NSError *error)
  129. {
  130. NSLog(@"error===%@",error);
  131. }];
  132. }
  133. @end