口袋优选

KBChildFansViewController.m 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. //
  2. // KBChildFansViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/19.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBChildFansViewController.h"
  9. #import "KBChildFansCell.h"
  10. #import "KBChildFansModel.h"
  11. #import "KBFanRecommendController.h"
  12. @interface KBChildFansViewController ()
  13. <
  14. UITableViewDelegate,
  15. UITableViewDataSource,
  16. YHChildFansDelegate
  17. >
  18. @property (nonatomic,strong) UIView *headerView;
  19. @property (nonatomic, strong) NSMutableArray *dataArr;
  20. @property (nonatomic) NSInteger page;
  21. @property (nonatomic) NSInteger member_type;
  22. @end
  23. @implementation KBChildFansViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self configTableView];
  27. [self request:NO];
  28. }
  29. - (void)configTableView {
  30. self.page = 1;
  31. [self.view addSubview:self.headerView];
  32. [self.view addSubview:self.tableView];
  33. if (@available(iOS 11.0, *)) {
  34. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  35. }else {
  36. self.automaticallyAdjustsScrollViewInsets = NO;
  37. }
  38. }
  39. #pragma mark -------- UITableView Delegate -----
  40. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  41. if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
  42. [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
  43. }
  44. }
  45. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  46. return self.dataArr.count;
  47. }
  48. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  49. return 67;
  50. }
  51. //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  52. // return self.headerView;
  53. //}
  54. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  55. return 0.1;
  56. }
  57. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  58. return 0.1;
  59. }
  60. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  61. KBChildFansCell *cell = [KBChildFansCell cellWithTableView:tableView];
  62. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  63. cell.updateAction = ^(KBChildFansModel *fanModel) {
  64. [self updateVipToSVip:fanModel];
  65. };
  66. KBChildFansModel *model = self.dataArr[indexPath.row];
  67. cell.model = model;
  68. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  69. cell.delegate = self;
  70. if (self.type == 0) {
  71. cell.sencondFansSumBtn.hidden = YES;
  72. }
  73. if (self.type == 0 || self.type == 2) {
  74. cell.updateBtn.hidden = YES;
  75. }
  76. return cell;
  77. }
  78. #pragma mark ------ private -----
  79. - (void)updateVipToSVip:(KBChildFansModel *)fansModel {
  80. NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/upUserLevel",BaseURL];
  81. NSDictionary *para = @{@"user_id":fansModel.user_id};
  82. [KBHttp post:url params:para success:^(id json) {
  83. NSNumber *flag = json[@"data"][@"flag"];
  84. if (flag.integerValue == 1) {
  85. [self request:YES];
  86. }
  87. [MBProgressHUD showMessage:json[@"data"][@"info"]];
  88. } failure:^(NSError *error) {
  89. [MBProgressHUD showMessage:@"加载失败,请稍后再试"];
  90. }];
  91. }
  92. #pragma mark -代理 YHChildFansDelegate
  93. - (void)recommendFansByUserID:(NSString *)userId withUserName:(NSString *)userName{
  94. KBFanRecommendController *vc=[[KBFanRecommendController alloc]init];
  95. vc.userId=userId;
  96. vc.userName=userName;
  97. [self.navigationController pushViewController:vc animated:YES];
  98. }
  99. #pragma mark -网络请求
  100. #pragma mark - request
  101. - (void)request:(BOOL)isChange {
  102. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/fansList",BaseURL];
  103. NSDictionary *dic=@{
  104. @"type":@(self.type),
  105. @"page":@(self.page),
  106. @"member_type":@(self.member_type)
  107. };
  108. [KBHttp post:url params:dic success:^(id json) {
  109. NSArray *arr = [NSArray yy_modelArrayWithClass:[KBChildFansModel class] json:json[@"data"]];
  110. if (isChange) {
  111. [self.dataArr removeAllObjects];
  112. }
  113. if (arr.count>0) {
  114. [self.dataArr addObjectsFromArray:arr];
  115. [self.tableView reloadData];
  116. [self.tableView.mj_footer endRefreshing];
  117. }else {
  118. [self setUpNoDataView];
  119. [self noMoreDataWithArray:arr];
  120. if (self.page==1) {
  121. [self.tableView reloadData];
  122. }
  123. }
  124. UISegmentedControl *seg=[self.headerView viewWithTag:10001];
  125. [seg setTitle:[NSString stringWithFormat:@"全部:%@位",json[@"fans_all"]] forSegmentAtIndex:0];
  126. [seg setTitle:[NSString stringWithFormat:@"超级会员:%@位",json[@"fans_super"]] forSegmentAtIndex:1];
  127. [seg setTitle:[NSString stringWithFormat:@"会员:%@位",json[@"fans_simple"]] forSegmentAtIndex:2];
  128. [self.tableView.mj_header endRefreshing];
  129. } failure:^(NSError *error) {
  130. [self.tableView.mj_footer endRefreshing];
  131. }];
  132. }
  133. - (void)noMoreDataWithArray:(NSArray *)array {
  134. if (array==nil || array.count <= 0) {
  135. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  136. }
  137. }
  138. - (void)setUpNoDataView {
  139. self.tableView.showNoDataView = YES;
  140. self.tableView.noDataImageOffsetY = -70;
  141. self.tableView.defaultNoDataText = @"您还没有粉丝记录";
  142. self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
  143. }
  144. #pragma mark -事件
  145. -(void)segAction{
  146. UISegmentedControl *segment=[self.headerView viewWithTag:10001];
  147. self.member_type=segment.selectedSegmentIndex;
  148. [self request:YES];
  149. }
  150. - (void)refreshData {
  151. self.page = 1;
  152. [self request:YES];
  153. }
  154. #pragma mark ------- layzer ------
  155. - (UITableView *)tableView {
  156. if (!_tableView) {
  157. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 48, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-88) style:UITableViewStylePlain];
  158. _tableView.estimatedSectionHeaderHeight = 0;
  159. _tableView.estimatedSectionFooterHeight = 0;
  160. _tableView.sectionFooterHeight = 0;
  161. _tableView.sectionHeaderHeight = 0;
  162. _tableView.estimatedRowHeight = 0;
  163. _tableView.delegate = self;
  164. _tableView.dataSource = self;
  165. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  166. _tableView.backgroundColor = [UIColor yhGrayColor];
  167. _tableView.bounces = YES;
  168. _tableView.showsVerticalScrollIndicator = NO;
  169. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  170. _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
  171. MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
  172. [self refreshData];
  173. }];
  174. header.lastUpdatedTimeLabel.hidden = YES;
  175. header.stateLabel.hidden = YES;
  176. //正在刷新的图片
  177. NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
  178. [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
  179. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
  180. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
  181. _tableView.mj_header = header;
  182. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  183. self.page ++;
  184. [self request:NO];
  185. }];
  186. }
  187. return _tableView;
  188. }
  189. -(NSMutableArray *)dataArr{
  190. if (!_dataArr) {
  191. _dataArr=[NSMutableArray array];
  192. }
  193. return _dataArr;
  194. }
  195. -(UIView *)headerView{
  196. if (!_headerView) {
  197. _headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 48)];
  198. _headerView.backgroundColor=[UIColor yhGrayColor];
  199. NSArray *array = [NSArray arrayWithObjects:@"全部:--位",@"超级会员:--位",@"会员:--位", nil];
  200. UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
  201. segment.frame=CGRectMake(0, 0, _headerView.width-2*FITSIZE(20), 28);
  202. segment.center=CGPointMake(_headerView.width/2, _headerView.height/2);
  203. segment.layer.borderColor=[UIColor YHColorWithHex:0xFF8600].CGColor;
  204. segment.layer.borderWidth=1;
  205. segment.layer.cornerRadius = 15.0f;
  206. segment.layer.masksToBounds = YES;
  207. segment.tag=10001;
  208. // [segment addTarget:self action:@selector(segAction) forControlEvents:UIControlEventTouchUpInside];
  209. [[segment rac_signalForControlEvents:UIControlEventValueChanged] subscribeNext:^(id x) {
  210. UISegmentedControl *segment=(UISegmentedControl *)x;
  211. if (self.member_type!=segment.selectedSegmentIndex) {
  212. self.page=1;
  213. [self.dataArr removeAllObjects];
  214. }
  215. self.member_type=segment.selectedSegmentIndex;
  216. [self request:YES];
  217. }];
  218. //选中的颜色
  219. segment.tintColor=[UIColor YHColorWithHex:0xFF8600];
  220. [segment setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
  221. //未选中的颜色
  222. segment.selectedSegmentIndex=0;
  223. [segment setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
  224. [segment setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f]} forState:UIControlStateNormal];
  225. [_headerView addSubview:segment];
  226. }
  227. return _headerView;
  228. }
  229. @end