《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRChildFansViewController.m 11KB

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