// // ModelFansViewController.m // 千模 // // Created by Drew on 2018/12/24. // Copyright © 2018 MUMEI. All rights reserved. // #import "ModelFansViewController.h" #import "ModelFansTableViewCell.h" #import "Masonry.h" #import "GroupSendViewController.h" @interface ModelFansViewController () { NSInteger page; } @property(weak, nonatomic) IBOutlet UITableView *tableView; @property(nonatomic, strong) NSMutableArray *data; @property(nonatomic, strong) UIView *headView; @end @implementation ModelFansViewController - (void)viewDidLoad { [super viewDidLoad]; page = 1; self.navigationItem.title = @"粉丝团"; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)]; self.navigationItem.leftBarButtonItem = leftItem; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F4F5"]; self.data = [NSMutableArray arrayWithCapacity:0]; self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.contentInset = UIEdgeInsetsMake(5, 0, 5, 0); self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refresh)]; self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)]; if ([self.modelPK isEqualToString:[ModelUser user].modelpk]) { self.tableView.tableHeaderView = self.headView; } [self getData]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBar.tintColor = [UIColor blackColor]; } - (void)backClick { [self.navigationController popViewControllerAnimated:YES]; } - (void)getData { NSString *url = [NSString stringWithFormat:@"%@/modelInfo?action=modelfans&modelpk=%@&page=%zd&size=20", PublicUrl, self.modelPK, page]; [[AHHttpManager sharedManager] POST:url parameters:nil success:^(id responseObject) { if ([@"success" isEqualToString:responseObject[@"msg"]]) { [self.tableView reloadData]; NSArray *data = responseObject[@"data"]; if (page == 1) { [self.data removeAllObjects]; } [self.data addObjectsFromArray:data]; [self.tableView reloadData]; [self.tableView.mj_header endRefreshing]; if (data.count < 20) { [self.tableView.mj_footer endRefreshingWithNoMoreData]; } else { [self.tableView.mj_footer endRefreshing]; } } } failure:^(NSError *error) { }]; } - (void)refresh { page = 1; [self getData]; } - (void)loadMore { page++; [self getData]; } - (UIView *)headView { if (!_headView) { _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)]; UIButton *button = [[UIButton alloc] init]; button.layer.backgroundColor = [UIColor colorWithRed:1.0 green:64 / 255.f blue:149 / 255.f alpha:1.0].CGColor; button.layer.cornerRadius = 22; [button setImage:[UIImage imageNamed:@"icon_liaotian"] forState:UIControlStateNormal]; [button setTitle:@"群发消息" forState:UIControlStateNormal]; [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; button.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; [_headView addSubview:button]; [button mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_headView).offset(20); make.right.equalTo(_headView).offset(-20); make.height.mas_equalTo(44); make.centerY.equalTo(_headView); }]; [button addTarget:self action:@selector(sendMsgToFans) forControlEvents:UIControlEventTouchUpInside]; } return _headView; } - (void)sendMsgToFans { GroupSendViewController *vc = [[GroupSendViewController alloc] init]; vc.modelPK = self.modelPK; [self.navigationController pushViewController:vc animated:YES]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.data.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ModelFansTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ModelFansTableViewCell"]; if (!cell) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ModelFansTableViewCell" owner:self options:nil]; cell = nib[0]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.data = self.data[indexPath.row]; } return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70; } @end