猎豆优选

LDChildFansViewController.m 11KB

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