GameDistributionViewController.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // GameDistributionViewController.m
  3. // BuguLive
  4. //
  5. // Created by 王珂 on 17/4/5.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "GameDistributionViewController.h"
  9. #import "GameDistributionCell.h"
  10. #import "GameDistributionModel.h"
  11. #import "SHomePageVC.h"
  12. #import "EdgeInsetsLabel.h"
  13. @interface GameDistributionViewController ()<UITableViewDelegate,UITableViewDataSource>
  14. {
  15. int _page; //页数
  16. int _has_next; //是否还有下一页
  17. }
  18. @property (nonatomic, strong) GameDistributionModel *model;
  19. @property (nonatomic, strong) UITableView *listTableView;
  20. @property (nonatomic, strong) NSMutableArray *listArray; //数据数组
  21. @end
  22. @implementation GameDistributionViewController
  23. - (void)viewDidLoad
  24. {
  25. [super viewDidLoad];
  26. _listArray = [[NSMutableArray alloc]init];
  27. _page = 1;
  28. self.view.backgroundColor = kWhiteColor;
  29. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  30. self.title = ASLocalizedString(@"游戏分享收益");
  31. [self creatView];
  32. }
  33. - (void)creatView
  34. {
  35. if (!_listTableView)
  36. {
  37. _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-64)];
  38. _listTableView.delegate =self;
  39. _listTableView.dataSource =self;
  40. _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  41. [self.view addSubview:_listTableView];
  42. }
  43. [BGMJRefreshManager refresh:_listTableView target:self headerRereshAction:@selector(headerReresh) footerRereshAction:@selector(footerReresh)];
  44. }
  45. - (void)backClick
  46. {
  47. [self.navigationController popViewControllerAnimated:NO];
  48. }
  49. #pragma mark 下拉刷新
  50. - (void)headerReresh
  51. {
  52. [self loadDataWithPage:1];
  53. }
  54. #pragma mark 上拉加载
  55. - (void)footerReresh
  56. {
  57. if (_has_next == 1)
  58. {
  59. _page ++;
  60. [self loadDataWithPage:_page];
  61. }
  62. else
  63. {
  64. [BGMJRefreshManager endRefresh:_listTableView];
  65. }
  66. }
  67. - (void)loadDataWithPage:(int)page
  68. {
  69. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  70. [parmDict setObject:@"games" forKey:@"ctl"];
  71. [parmDict setObject:@"getDistributionList" forKey:@"act"];
  72. [parmDict setObject:@(page) forKey:@"page"];
  73. FWWeakify(self)
  74. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  75. FWStrongify(self)
  76. if ([responseJson toInt:@"status"] == 1)
  77. {
  78. if (page == 1 || page == 0)
  79. {
  80. [self.listArray removeAllObjects];
  81. }
  82. NSDictionary * dataDic = responseJson[@"data"];
  83. GameDistributionModel * distrModel = [GameDistributionModel mj_objectWithKeyValues:dataDic];
  84. self.model = distrModel;
  85. [self.listArray addObjectsFromArray:distrModel.list];
  86. _has_next = [dataDic[@"page"] toInt:@"has_next"];
  87. _page = [dataDic[@"page"] toInt:@"page"];
  88. [self.listTableView reloadData];
  89. }
  90. [BGMJRefreshManager endRefresh:self.listTableView];
  91. if (!self.listArray.count)
  92. {
  93. [self showNoContentView];
  94. }
  95. else
  96. {
  97. [self hideNoContentView];
  98. }
  99. } FailureBlock:^(NSError *error) {
  100. FWStrongify(self)
  101. [BGMJRefreshManager endRefresh:self.listTableView];
  102. }];
  103. }
  104. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  105. {
  106. return 2;
  107. }
  108. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  109. {
  110. if (section == 0)
  111. {
  112. return [self.model.parent.userID integerValue] > 0 ? 1 : 0;
  113. }
  114. else if (section == 1)
  115. {
  116. return _listArray.count;
  117. }
  118. return 0;
  119. }
  120. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  121. {
  122. return 51;
  123. }
  124. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  125. {
  126. if (section == 0)
  127. {
  128. return [self.model.parent.userID integerValue] > 0 ? 25 : 0;
  129. }
  130. return 25;
  131. }
  132. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  133. {
  134. EdgeInsetsLabel *titleLabel = [[EdgeInsetsLabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 25)];
  135. titleLabel.textColor = kAppGrayColor1;
  136. titleLabel.font = kAppMiddleTextFont_1;
  137. titleLabel.backgroundColor = kBackGroundColor;
  138. titleLabel.edgeInsets = UIEdgeInsetsMake(0 , 15, 0, 15); // 设置内边距
  139. if (section == 0)
  140. {
  141. titleLabel.text = ASLocalizedString(@"我的推荐人");
  142. }
  143. else
  144. {
  145. titleLabel.text = ASLocalizedString(@"我的收益");
  146. }
  147. return titleLabel;
  148. }
  149. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  150. {
  151. if (section == 0)
  152. {
  153. return ASLocalizedString(@"我的推荐人");
  154. }
  155. else
  156. {
  157. return ASLocalizedString(@"我的收益");
  158. }
  159. }
  160. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  161. {
  162. GameDistributionCell * cell = [GameDistributionCell cellWithTableView:tableView];
  163. GameUserModel * userModel =[[GameUserModel alloc] init];
  164. if (indexPath.section == 0)
  165. {
  166. userModel = self.model.parent;
  167. userModel.isParent = YES;
  168. cell.model = userModel;
  169. }
  170. else if (indexPath.section == 1)
  171. {
  172. userModel = _listArray[indexPath.row];;
  173. userModel.isParent = NO;
  174. cell.model = userModel;
  175. }
  176. return cell;
  177. }
  178. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  179. {
  180. GameUserModel * gameUserModel;
  181. if (indexPath.section == 0)
  182. {
  183. gameUserModel = self.model.parent;
  184. }
  185. else if (indexPath.section == 1)
  186. {
  187. gameUserModel = _listArray[indexPath.row];
  188. }
  189. SHomePageVC *homeVC = [[SHomePageVC alloc]init];
  190. homeVC.user_id = gameUserModel.userID;
  191. // homeVC.user_nickname =gameUserModel.nick_name;
  192. homeVC.type = 0;
  193. [[AppDelegate sharedAppDelegate]pushViewController:homeVC animated:YES];
  194. }
  195. @end