123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- //
- // LDChildFansViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/19.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "LDChildFansViewController.h"
- #import "LDChildFansCell.h"
- #import "LDChildFansModel.h"
- #import "LDFanRecommendController.h"
- #import "LDFansSuperView.h"
- #import "CCAlertShowView.h"
- #import "LDInviteFansViewController.h"
- #import "LDUserInfo.h"
- @interface LDChildFansViewController ()
- <
- UITableViewDelegate,
- UITableViewDataSource,
- YHChildFansDelegate
- >
- @property (nonatomic,strong) UIView *headerView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic) NSInteger page;
- @property (nonatomic) NSInteger member_type;
- @end
- @implementation LDChildFansViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self configTableView];
- [self request:NO];
- }
- - (void)configTableView {
- self.page = 1;
- // [self.view addSubview:self.headerView];
- [self.view addSubview:self.tableView];
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- }
- #pragma mark -------- UITableView Delegate -----
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 67;
- }
- //- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- // return self.headerView;
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 0.1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- LDChildFansCell *cell = [LDChildFansCell cellWithTableView:tableView];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.updateAction = ^(LDChildFansModel *fanModel) {
- [self updateVipToSVip:fanModel];
- };
- LDChildFansModel *model = self.dataArr[indexPath.row];
- cell.cellType = self.type;//区分好友类型
- cell.model = model;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.delegate = self;
-
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- LDChildFansModel *model = self.dataArr[indexPath.row];
-
- NSDictionary *userDic= [LDUserInfoManager shareManager].userInfoDic;
- LDUserInfo *userInfo = [LDUserInfo yy_modelWithJSON:userDic];
- if (self.type == 5) {//潜在好友邀请注册
- [self goToInviteFansPage];
- }else{
- if ([userInfo.user_level isEqualToString:@"3"]) {//运营商显示二级列表
- if (self.type!=5 ) {
- LDSuperInfoVC *InfoV = [[LDSuperInfoVC alloc] init];
- InfoV.fansmodel = model;
- [self.navigationController pushViewController:InfoV animated:YES];
- }
- }else{
- if (self.type==1 || self.type == 3 || self.type ==4 ) {
-
- LDFansSuperView *superView = [[LDFansSuperView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) model:model];
- CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:superView backgroundDismissEnable:NO];
- superView.tapDismissBlock = ^{
- [showView dismiss];
- };
- [showView show];
- }
- }
- }
-
-
-
- }
- /**
- 邀请好友
- */
- - (void)goToInviteFansPage {
-
- LDInviteFansViewController *invite = [[LDInviteFansViewController alloc] init];
- [self.navigationController pushViewController:invite animated:YES];
- }
- #pragma mark ------ private -----
- - (void)updateVipToSVip:(LDChildFansModel *)fansModel {
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/adzoneCreate/upUserLevel",BaseURL];
- NSDictionary *para = @{@"user_id":fansModel.user_id};
- [LDHttp post:url params:para success:^(id json) {
- NSNumber *flag = json[@"data"][@"flag"];
- if (flag.integerValue == 1) {
- [self request:YES];
- }
- [MBProgressHUD showMessage:json[@"data"][@"info"]];
-
- } failure:^(NSError *error) {
- [MBProgressHUD showMessage:@"加载失败,请稍后再试"];
- }];
- }
- #pragma mark -代理 YHChildFansDelegate
- - (void)recommendFansByUserID:(NSString *)userId withUserName:(NSString *)userName{
- LDFanRecommendController *vc=[[LDFanRecommendController alloc]init];
- vc.userId=userId;
- vc.userName=userName;
- [self.navigationController pushViewController:vc animated:YES];
- }
- #pragma mark -网络请求
- #pragma mark - request
- - (void)request:(BOOL)isChange {
- NSDictionary * userinfoDic =[LDUserInfoManager shareManager].userInfoDic;
- if ([userinfoDic[@"user_level"] integerValue]==1) {//会员
- [self.tableView.mj_header endRefreshing];
- self.tableView.showNoDataView = YES;
- self.tableView.noDataImageOffsetY = -70;
- self.tableView.defaultNoDataText = @"您还没有好友,快去邀请吧~";
- self.tableView.defaultNoDataImage = [UIImage imageNamed:@"no_order"];
- [self.tableView reloadData];
- }else{
- NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/getTypeOperate",BaseURL];
- NSDictionary *dic=@{
- @"type":@(self.type),
- @"page":@(self.page)
- };
- [LDHttp post:url params:dic success:^(id json) {
- if ([json[@"count"]integerValue] !=0) {
- NSArray *arr = [NSArray yy_modelArrayWithClass:[LDChildFansModel class] json:json[@"data"]];
- if (isChange) {
- [self.dataArr removeAllObjects];
- }
-
- if (arr.count>0) {
- [self.dataArr addObjectsFromArray:arr];
- [self.tableView reloadData];
- [self.tableView.mj_footer endRefreshing];
- }else {
- [self setUpNoDataView];
- [self noMoreDataWithArray:arr];
- if (self.page==1) {
- [self.tableView reloadData];
- }
- }
- }
-
-
-
- [self.tableView reloadData];
- [self.tableView.mj_header endRefreshing];
- } failure:^(NSError *error) {
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- }];
- }
-
-
- }
- - (void)noMoreDataWithArray:(NSArray *)array {
- if (array==nil || array.count <= 0) {
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- }
- - (void)setUpNoDataView {
- self.tableView.showNoDataView = YES;
- self.tableView.noDataImageOffsetY = -70;
- self.tableView.defaultNoDataText = @"您还没有粉丝记录";
- self.tableView.defaultNoDataImage = [UIImage imageNamed:@"noData"];
- }
- #pragma mark -事件
- -(void)segAction{
- UISegmentedControl *segment=[self.headerView viewWithTag:10001];
- self.member_type=segment.selectedSegmentIndex;
- [self request:YES];
- }
- - (void)refreshData {
- self.page = 1;
- [self request:YES];
- }
- #pragma mark ------- layzer ------
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-70-FITSIZE(40)) style:UITableViewStylePlain];
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.sectionFooterHeight = 0;
- _tableView.sectionHeaderHeight = 0;
- _tableView.estimatedRowHeight = 0;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableView.backgroundColor = [UIColor yhGrayColor];
- _tableView.bounces = YES;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- _tableView.separatorColor = [UIColor YHColorWithHex:0xEEEEEE];
- MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
- [self refreshData];
- }];
- header.lastUpdatedTimeLabel.hidden = YES;
- header.stateLabel.hidden = YES;
-
- //正在刷新的图片
- NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
- [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
- [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
- [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
- _tableView.mj_header = header;
-
- _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- self.page ++;
- [self request:NO];
- }];
- }
- return _tableView;
- }
- -(NSMutableArray *)dataArr{
- if (!_dataArr) {
- _dataArr=[NSMutableArray array];
- }
- return _dataArr;
- }
- -(UIView *)headerView{
- if (!_headerView) {
- _headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 48)];
- _headerView.backgroundColor=[UIColor yhGrayColor];
- NSArray *array = [NSArray arrayWithObjects:@"全部:--位",@"超级会员:--位",@"会员:--位", nil];
- UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
- segment.frame=CGRectMake(0, 0, _headerView.width-2*FITSIZE(20), 28);
- segment.center=CGPointMake(_headerView.width/2, _headerView.height/2);
- segment.layer.borderColor=[UIColor homeRedColor].CGColor;
- segment.layer.borderWidth=1;
- segment.layer.cornerRadius = 15.0f;
- segment.layer.masksToBounds = YES;
- segment.tag=10001;
- // [segment addTarget:self action:@selector(segAction) forControlEvents:UIControlEventTouchUpInside];
- [[segment rac_signalForControlEvents:UIControlEventValueChanged] subscribeNext:^(id x) {
- UISegmentedControl *segment=(UISegmentedControl *)x;
- if (self.member_type!=segment.selectedSegmentIndex) {
- self.page=1;
-
- }
- self.member_type=segment.selectedSegmentIndex;
- [self request:YES];
- }];
- //选中的颜色
- segment.tintColor=[UIColor homeRedColor];
- [segment setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
- //未选中的颜色
- segment.selectedSegmentIndex=0;
- [segment setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor homeRedColor]} forState:UIControlStateNormal];
- [segment setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f]} forState:UIControlStateNormal];
- [_headerView addSubview:segment];
-
- }
- return _headerView;
- }
- @end
|