SContributionView.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // SContributionView.m
  3. // BuguLive
  4. //
  5. // Created by 丁凯 on 2017/9/5.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "SContributionView.h"
  9. #import "LeaderboardTableViewCell.h"
  10. @implementation SContributionView
  11. - (id)initWithFrame:(CGRect)frame andDataType:(int)dataType andUserId:(NSString *)userId andLiveRoomId:(NSString *)liveRoomId
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self)
  15. {
  16. self.dataType = dataType;
  17. self.user_id = userId;
  18. self.liveRoom_id = liveRoomId;
  19. self.userArray = [[NSMutableArray alloc]init];
  20. self.dataArray = [[NSMutableArray alloc]init];
  21. self.backgroundColor = kClearColor;
  22. [self creatMyUI];
  23. // [self loadDataWithType:dataType andPage:1];
  24. }
  25. return self;
  26. }
  27. - (void)creatMyUI
  28. {
  29. self.headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 25*kScaleHeight)];
  30. self.SHeadView.backgroundColor = kClearColor;
  31. self.SHeadView = [[UIView alloc]initWithFrame:CGRectMake(self.headView.width/2 -10, 5*kScaleHeight, 20, 20*kScaleHeight)];
  32. [self.headView addSubview:self.SHeadView];
  33. self.headImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, (self.headView.height-13)/2, 15, 13)];
  34. self.headImgView.image = [UIImage imageNamed:@"hm_top_ticket"];
  35. [self.SHeadView addSubview:self.headImgView];
  36. self.headLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.headImgView.frame)+5, 0, self.headView.width-self.headImgView.width-5, self.headView.height)];
  37. self.headLabel.textColor = kAppGrayColor1;
  38. self.headLabel.font = [UIFont systemFontOfSize:12];
  39. [self.SHeadView addSubview:self.headLabel];
  40. self.SHeadView.hidden = YES;
  41. self.SHeadView.top = self.SHeadView.height = 0;
  42. self.LeaderHeadV = [[SLeaderHeadView alloc]initWithFrame:CGRectMake(0, 0, self.width,0)];
  43. FWWeakify(self)
  44. [self.LeaderHeadV setLeadBlock:^(int imgaeIdnex){
  45. FWStrongify(self)
  46. if (imgaeIdnex < self.dataArray.count)
  47. {
  48. UserModel *model = self.dataArray[imgaeIdnex];
  49. [self goTomyDelegateWithModel:model];
  50. }
  51. }];
  52. _myTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height)];
  53. _myTableview.backgroundColor = kClearColor;
  54. _myTableview.dataSource = self;
  55. _myTableview.delegate = self;
  56. _myTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
  57. [self addSubview:_myTableview];
  58. [BGMJRefreshManager refresh:_myTableview target:self headerRereshAction:@selector(headerReresh) shouldHeaderBeginRefresh:YES footerRereshAction:@selector(footerReresh) refreshFooterType:@"MJRefreshBackNormalFooter"];
  59. }
  60. - (void)headerReresh
  61. {
  62. [self loadDataWithType:self.dataType andPage:1];
  63. }
  64. - (void)footerReresh
  65. {
  66. if (_has_next == 1)
  67. {
  68. _currentPage ++;
  69. [self loadDataWithType:self.dataType andPage:1];
  70. }
  71. else
  72. {
  73. [BGMJRefreshManager endRefresh:_myTableview];
  74. }
  75. }
  76. - (void)loadDataWithType:(int)dataType andPage:(int)page
  77. {
  78. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  79. [parmDict setObject:@"video" forKey:@"ctl"];
  80. [parmDict setObject:@"cont" forKey:@"act"];
  81. //当天的传roomID传userID
  82. //总的userID传userID
  83. if (self.dataType == 1)
  84. {
  85. // if (self.liveRoom_id)
  86. // {
  87. // [parmDict setObject:self.liveRoom_id forKey:@"room_id"];
  88. // }
  89. [parmDict setObject:self.user_id forKey:@"room_id"];
  90. [parmDict setObject:self.user_id forKey:@"user_id"];
  91. }else
  92. {
  93. if (self.user_id)
  94. {
  95. [parmDict setObject:self.user_id forKey:@"user_id"];
  96. }
  97. }
  98. [parmDict setObject:@(page) forKey:@"p"];
  99. FWWeakify(self)
  100. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  101. FWStrongify(self)
  102. if ([responseJson toInt:@"status"] == 1)
  103. {
  104. [_userArray removeAllObjects];
  105. //用户信息
  106. _currentPage = [responseJson toInt:@"page"];
  107. _has_next = [responseJson toInt:@"has_next"];
  108. if (_currentPage <= 1)
  109. {
  110. [_userArray removeAllObjects];
  111. }
  112. _total_num = [responseJson toInt:@"total_num"];
  113. //贡献榜的排名
  114. NSArray *array = [responseJson objectForKey:@"list"];
  115. if (array && [array isKindOfClass:[NSArray class]])
  116. {
  117. if (array.count > 0)
  118. {
  119. for (NSDictionary *dict in array)
  120. {
  121. UserModel *model = [UserModel mj_objectWithKeyValues:dict];
  122. [_userArray addObject:model];
  123. }
  124. }
  125. }
  126. // if (self.userArray.count)
  127. // {
  128. [self disposeNOForThreeData];
  129. [self updateTopView];
  130. _myTableview.tableHeaderView = self.headView;
  131. [self hideNoContentViewOnView:self];
  132. // }else
  133. // {
  134. // _myTableview.tableHeaderView = self.headView;
  135. // [self showNoContentViewOnView:self];
  136. //// self.myTableview.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 0.01)];
  137. // }
  138. [_myTableview reloadData];
  139. }
  140. [BGMJRefreshManager endRefresh:_myTableview];
  141. } FailureBlock:^(NSError *error) {
  142. FWStrongify(self)
  143. [BGMJRefreshManager endRefresh:self.myTableview];
  144. }];
  145. }
  146. - (void)disposeNOForThreeData
  147. {
  148. if (self.dataArray.count)
  149. {
  150. [self.dataArray removeAllObjects];
  151. }
  152. for (int i = 0; i < 3; i ++)
  153. {
  154. [self addAndRemoveData];
  155. }
  156. [self.LeaderHeadV setMyViewWithMArr:self.dataArray andType:1 consumeType:0];
  157. }
  158. - (void)addAndRemoveData
  159. {
  160. if (_userArray.count)
  161. {
  162. [_dataArray addObject:_userArray[0]];
  163. [_userArray removeObjectAtIndex:0];
  164. }else{
  165. UserModel *model = [UserModel new];
  166. [_dataArray addObject:model];
  167. }
  168. }
  169. - (void)updateTopView
  170. {
  171. CGFloat width =[[NSString stringWithFormat:@"%d%@",_total_num,self.BuguLive.appModel.ticket_name] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}].width;
  172. CGRect rect = self.headLabel.frame;
  173. rect.size.width = width;
  174. self.headLabel.frame = rect;
  175. CGRect rect1 = self.SHeadView.frame;
  176. rect1.size.width = width+20;
  177. rect1.origin.x = (self.width-width-20)/2;
  178. self.SHeadView.frame = rect1;
  179. self.headLabel.text = [NSString stringWithFormat:@"%d%@",_total_num,self.BuguLive.appModel.ticket_name];
  180. }
  181. #pragma mark -UITableViewDelegate&UITableViewDataSource
  182. //返回行数
  183. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  184. {
  185. if (self.dataArray.count)
  186. {
  187. return self.userArray.count +1;
  188. }else
  189. {
  190. return 0;
  191. }
  192. }
  193. //返回段数
  194. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  195. {
  196. return 1;
  197. }
  198. //返回单元格
  199. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  200. {
  201. if (indexPath.row == 0)
  202. {
  203. static NSString *CellIdentifier1 = @"CellIdentifier1";
  204. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
  205. if (!cell)
  206. {
  207. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
  208. cell.accessoryType = UITableViewCellAccessoryNone;
  209. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  210. cell.backgroundColor = kClearColor;
  211. [cell.contentView addSubview:self.LeaderHeadV];
  212. }
  213. return cell;
  214. }else
  215. {
  216. LeaderboardTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"LeaderboardTableViewCell"];
  217. if (!cell)
  218. {
  219. cell = [[NSBundle mainBundle] loadNibNamed:@"LeaderboardTableViewCell" owner:nil options:nil].firstObject;
  220. }
  221. UserModel *model = self.userArray[indexPath.row-1];
  222. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  223. [cell createCellWithModel:model withRow:(int)indexPath.row-1 withType:0];
  224. cell.ticketLabel.text = [NSString stringWithFormat:ASLocalizedString(@"贡献%@%@"),[self checkDiamondNum:model.use_ticket],self.BuguLive.appModel.ticket_name];
  225. return cell;
  226. }
  227. }
  228. -(NSString *)checkDiamondNum:(NSString *)num{
  229. NSString *numStr = @"";
  230. float numF = num.floatValue;
  231. if (numF > 1000) {
  232. numStr = [NSString stringWithFormat:ASLocalizedString(@"%.1fK"),floorf(numF/1000)];
  233. // [NSString stringWithFormat:@"%.2f",num.floatValue];
  234. }else{
  235. numStr = [NSString stringWithFormat:@"%.0f",numF];
  236. }
  237. return numStr;
  238. }
  239. //返回cell高度
  240. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  241. {
  242. if (indexPath.row == 0)
  243. {
  244. return self.LeaderHeadV.height;
  245. }else
  246. {
  247. return 65*kAppRowHScale;
  248. }
  249. }
  250. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  251. {
  252. if (indexPath.row > 0)
  253. {
  254. if (indexPath.row -1 < self.userArray.count)
  255. {
  256. UserModel *model = self.userArray[indexPath.row-1];
  257. if (model.is_noble_ranking_stealth.integerValue == 1) {
  258. [FanweMessage alertHUD:ASLocalizedString(@"不能查看神秘人身份信息")];
  259. return;
  260. }
  261. [self goTomyDelegateWithModel:model];
  262. }
  263. }
  264. }
  265. - (void)goTomyDelegateWithModel:(UserModel *)model
  266. {
  267. if (model.is_noble_ranking_stealth.integerValue == 1) {
  268. [FanweMessage alertHUD:ASLocalizedString(@"不能查看神秘人身份信息")];
  269. return;
  270. }
  271. if (self.CDelegate)
  272. {
  273. if ([self.CDelegate respondsToSelector:@selector(goToHomeWithModel:)])
  274. {
  275. if(model.user_id)
  276. {
  277. [self.CDelegate goToHomeWithModel:model];
  278. }
  279. }
  280. }
  281. }
  282. @end