ListDayViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. //
  2. // ListDayViewController.m
  3. // BuguLive
  4. //
  5. // Created by ycp on 16/10/14.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "ListDayViewController.h"
  9. #import "UserModel.h"
  10. #import "LeaderboardTableViewCell.h"
  11. #import "SHomePageVC.h"
  12. #import "SLeaderHeadView.h"
  13. #import "ContributionLsitBottomView.h"
  14. @interface ListDayViewController ()<UITableViewDelegate,UITableViewDataSource>
  15. @property ( nonatomic,strong) UITableView *listTableView;
  16. @property ( nonatomic,strong) NSMutableArray *dataArray; //数据数组
  17. @property ( nonatomic,strong) NSMutableArray *haloArray; //前三名
  18. @property ( nonatomic,assign) int page;
  19. @property ( nonatomic,assign) int has_next;
  20. @property ( nonatomic,strong) SLeaderHeadView *leadheadView; //listTableView 的头部视图
  21. @property(nonatomic, strong) ContributionLsitBottomView *bottomView;
  22. @end
  23. @implementation ListDayViewController
  24. - (void)viewDidLoad
  25. {
  26. [super viewDidLoad];
  27. self.dataArray = [[NSMutableArray alloc]init];
  28. self.haloArray = [[NSMutableArray alloc]init];
  29. self.view.backgroundColor = kClearColor;
  30. self.page = 1;
  31. [self createTableView];
  32. // self.bottomView.backgroundColor = kWhiteColor;
  33. [self.view addSubview:self.bottomView];
  34. }
  35. - (void)showNoContentView
  36. {
  37. [super showNoContentView];
  38. // [self.view addSubview:self.noContentView];
  39. self.noContentView.noContentTipLabel.text = ASLocalizedString(@"暂无数据");
  40. }
  41. #pragma mark 创建表
  42. - (void)createTableView
  43. {
  44. if (!_listTableView)
  45. {
  46. if (self.isHiddenTabbar)
  47. {
  48. _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW , kScreenH-kStatusBarHeight-44 -44 - kRealValue(76) - SafeAreaBottomHeight)];
  49. if (isIPhoneX())
  50. {
  51. _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-kTopHeight-44 - kRealValue(76) - MG_BOTTOM_MARGIN - 44 - SafeAreaBottomHeight)];
  52. }
  53. }
  54. else
  55. {
  56. _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW , kScreenH-kStatusBarHeight-44 -44-49 - kRealValue(76) - - SafeAreaBottomHeight)];
  57. if (isIPhoneX())
  58. {
  59. _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-kStatusBarHeight*2-44 -44-40 - kRealValue(76) - SafeAreaBottomHeight)];
  60. }
  61. }
  62. if (@available(iOS 15.0, *)) {
  63. _listTableView.sectionHeaderTopPadding = 0;
  64. }
  65. _listTableView.delegate =self;
  66. _listTableView.dataSource =self;
  67. _listTableView.backgroundColor = kClearColor;
  68. _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  69. self.leadheadView = [[SLeaderHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 0)];
  70. // self.leadheadView.layer.borderColor = UIColor.redColor.CGColor;
  71. // self.leadheadView.layer.borderWidth = 3;
  72. FWWeakify(self)
  73. [self.leadheadView setLeadBlock:^(int imgaeIdnex){
  74. FWStrongify(self)
  75. if (imgaeIdnex < self.haloArray.count)
  76. {
  77. UserModel *model = self.haloArray[imgaeIdnex];
  78. if (self.delegate && [self.delegate respondsToSelector:@selector(pushToHomePage:)])
  79. {
  80. [self.delegate pushToHomePage:model];
  81. }
  82. }
  83. }];
  84. [self.view addSubview:_listTableView];
  85. }
  86. [self.listTableView registerNib:[UINib nibWithNibName:@"LeaderboardTableViewCell" bundle:nil] forCellReuseIdentifier:@"LeaderboardTableViewCell"];
  87. [BGMJRefreshManager refresh:_listTableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(footerReresh)];
  88. }
  89. #pragma mark 下拉刷新
  90. - (void)headerReresh
  91. {
  92. [self loadDataWithPage:1];
  93. }
  94. #pragma mark 上拉加载
  95. - (void)footerReresh
  96. {
  97. if (self.has_next == 1)
  98. {
  99. self.page ++;
  100. [self loadDataWithPage:self.page];
  101. }
  102. else
  103. {
  104. [BGMJRefreshManager endRefresh:self.listTableView];
  105. }
  106. }
  107. - (void)loadDataWithPage:(int)page
  108. {
  109. MMWeakify(self)
  110. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  111. [parmDict setObject:@"rank" forKey:@"ctl"];
  112. if (self.type < 4)
  113. {
  114. // [parmDict setObject:@"contribution_ranking" forKey:@"act"];
  115. [parmDict setObject:@"contribution" forKey:@"act"];
  116. if (self.type == 1)
  117. {
  118. [parmDict setObject:@"day" forKey:@"rank_name"];
  119. }
  120. else if (self.type == 2)
  121. {
  122. [parmDict setObject:@"month" forKey:@"rank_name"];
  123. }
  124. else if (self.type == 3)
  125. {
  126. [parmDict setObject:@"all" forKey:@"rank_name"];
  127. }
  128. }
  129. else
  130. {
  131. // [parmDict setObject:@"revenue_ranking" forKey:@"act"];
  132. [parmDict setObject:@"consumption" forKey:@"act"];
  133. if (self.type == 4)
  134. {
  135. [parmDict setObject:@"day" forKey:@"rank_name"];
  136. }
  137. else if (self.type == 5)
  138. {
  139. [parmDict setObject:@"month" forKey:@"rank_name"];
  140. }
  141. else if (self.type == 6)
  142. {
  143. [parmDict setObject:@"all" forKey:@"rank_name"];
  144. }
  145. }
  146. [parmDict setObject:[NSString stringWithFormat:@"%d",page] forKey:@"p"];
  147. FWWeakify(self)
  148. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  149. {
  150. FWStrongify(self)
  151. if ([responseJson toInt:@"status"] == 1)
  152. {
  153. self.page = [responseJson toInt:@"page"];
  154. //用户信息
  155. self.has_next = [responseJson toInt:@"has_next"];
  156. if (page == 1)
  157. {
  158. [self.dataArray removeAllObjects];
  159. }
  160. NSArray *array = [responseJson objectForKey:@"list"];
  161. if (array && [array isKindOfClass:[NSArray class]])
  162. {
  163. if (array.count > 0)
  164. {
  165. for (NSDictionary *dict in array)
  166. {
  167. UserModel *model = [UserModel mj_objectWithKeyValues:dict];
  168. [self.dataArray addObject:model];
  169. }
  170. }
  171. }
  172. if (self.dataArray.count)
  173. {
  174. MMStrongify(self)
  175. [self disposeNOForThreeData];
  176. self.listTableView.tableHeaderView = self.leadheadView;
  177. [self hideNoContentView];
  178. }else
  179. {
  180. [self showNoContentView];
  181. self.listTableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _listTableView.width, 0.01)];
  182. }
  183. [self.listTableView reloadData];
  184. [self getRankListNum:responseJson];
  185. }
  186. [BGMJRefreshManager endRefresh:self.listTableView];
  187. } FailureBlock:^(NSError *error) {
  188. FWStrongify(self)
  189. [BGMJRefreshManager endRefresh:self.listTableView];
  190. }];
  191. }
  192. -(void)getRankListNum:(NSDictionary *)responseJson {
  193. NSDictionary * dict = responseJson[@"user"];
  194. // self.bottomView.contentL.text = [rankNum isEqualToString:@"0"] ?ASLocalizedString( @"未上榜") : rankNum;
  195. if ([[NSString stringWithFormat:@"%d",[responseJson toInt:@"my_ranking"]] isEqualToString:@"0"]) {
  196. self.bottomView.contentL.hidden = NO;
  197. self.bottomView.titleL.text = @"- -";
  198. } else {
  199. self.bottomView.contentL.hidden = YES;
  200. self.bottomView.titleL.text = [responseJson toString:@"my_ranking"];
  201. }
  202. self.bottomView.contentL.text = ASLocalizedString( @"未上榜");
  203. [self.bottomView.headImageView sd_setImageWithURL:[NSURL URLWithString:[dict toString:@"avatar"]] placeholderImage:kDefaultPreloadHeadImg];
  204. self.bottomView.nicknameLabel.text = [dict toString:@"nickname"];
  205. //等级
  206. if ([dict toInt:@"user_level"] !=0) {
  207. self.bottomView.rankImgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"level%d",[dict toInt:@"user_level"]]];
  208. } else {
  209. self.bottomView.rankImgV.image = [UIImage imageNamed:@"rank_1"];
  210. }
  211. self.bottomView.valueLabel.text = [dict toString:@"ticket"];
  212. }
  213. - (void)disposeNOForThreeData
  214. {
  215. if (self.haloArray.count)
  216. {
  217. [self.haloArray removeAllObjects];
  218. }
  219. for (int i=0; i<3; i++)
  220. {
  221. [self judgeAndLoadHaloData];
  222. }
  223. [self.leadheadView setMyViewWithMArr:self.haloArray andType:0 consumeType:self.type];
  224. }
  225. - (void)judgeAndLoadHaloData
  226. {
  227. if (_dataArray.count)
  228. {
  229. [_haloArray addObject:_dataArray[0]];
  230. [_dataArray removeObjectAtIndex:0];
  231. }
  232. }
  233. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  234. {
  235. return _dataArray.count;
  236. }
  237. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  238. {
  239. return 65;
  240. }
  241. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  242. {
  243. LeaderboardTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"LeaderboardTableViewCell"];
  244. if (!cell)
  245. {
  246. cell = [[NSBundle mainBundle] loadNibNamed:@"LeaderboardTableViewCell" owner:nil options:nil].firstObject;
  247. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  248. }
  249. UserModel *model = _dataArray[indexPath.row];
  250. [cell createCellWithModel:model withRow:(int)indexPath.row withType:self.type];
  251. if (indexPath.row == _dataArray.count-1)
  252. {
  253. cell.lineView.hidden = YES;
  254. }
  255. cell.contentView.backgroundColor = [UIColor colorWithHexString:@"#301754"];
  256. cell.backgroundColor = kClearColor;
  257. return cell;
  258. }
  259. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  260. {
  261. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  262. [self jumpOffHomePage:_dataArray selectRow:indexPath.row];
  263. }
  264. /**
  265. 跳转到主页
  266. @param array 数据源
  267. @param selectRow 所选择的行
  268. */
  269. - (void)jumpOffHomePage:(NSMutableArray *)array selectRow:(NSInteger)selectRow
  270. {
  271. if (array.count >0 && selectRow < array.count)
  272. {
  273. UserModel *model = array[selectRow];
  274. if (model.is_noble_ranking_stealth.integerValue == 1) {
  275. [FanweMessage alertHUD:ASLocalizedString(@"不能查看神秘人身份信息")];
  276. return;
  277. }
  278. if (_delegate && [_delegate respondsToSelector:@selector(pushToHomePage:)])
  279. {
  280. [_delegate pushToHomePage:model];
  281. }
  282. }
  283. }
  284. -(ContributionLsitBottomView *)bottomView{
  285. if (!_bottomView) {
  286. _bottomView = [[ContributionLsitBottomView alloc]initWithFrame:CGRectMake(0, self.listTableView.height, kScreenW, kRealValue(76))];
  287. // _bottomView.layer.borderColor = UIColor.redColor.CGColor;
  288. // _bottomView.layer.borderWidth = 5;
  289. }
  290. return _bottomView;
  291. }
  292. @end