123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- //
- // YOUPAILZLiveOnlineMemberListVC.m
- // VQU
- //
- // Created by CY on 2021/7/22.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZLiveOnlineMemberListVC.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAILZLiveOnlineMemberCell.h"
- #import "YOUPAILZLiveMemberModel.h"
- @interface YOUPAILZLiveOnlineMemberListVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, weak) UITableView *youpaiptableView;
- @property (nonatomic, strong) NSString *youpaipendtime;
- @property (nonatomic, strong) NSMutableArray<YOUPAILZLiveMemberModel *> *youpaipdataSource;
- @end
- @implementation YOUPAILZLiveOnlineMemberListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self youpaifinitUI];
- /// 关注状态改变,接收通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
- [self youpaifrequestMemberListWithStatus:kRefreshNormal];
- }
- - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
- NSDictionary *dict = [notification userInfo];
- NSString *idStr = dict[@"follow_uid"];
- NSInteger isfollow = [dict[@"is_follow"] intValue];
- NSArray *arr = self.youpaipdataSource;
- NSMutableArray *arrM = [NSMutableArray new];
- if (arr.count>0) {
- for (int i = 0; i<arr.count; i++) {
- YOUPAILZLiveMemberModel *model = arr[i];
- if ([model.youpaipid isEqualToString:idStr]) {
- model.youpaipis_follow = isfollow;
- }
- [arrM addObject:model];
- }
- [self.youpaipdataSource removeAllObjects];
- self.youpaipdataSource = arrM;
- [self.youpaiptableView reloadData];
- }
-
- }
- -(void)dealloc{
- [[NSNotificationCenter defaultCenter]removeObserver:self];
- }
- - (void)youpaifinitUI{
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- tableView.delegate = self;
- tableView.dataSource = self;
- tableView.rowHeight = 60.0f;
- tableView.estimatedRowHeight = 60.0f;
- tableView.estimatedSectionHeaderHeight = 0.0f;
- tableView.estimatedSectionFooterHeight = 0.0f;
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.backgroundColor = [UIColor clearColor];
- [self.view addSubview:tableView];
- self.youpaiptableView = tableView;
- __weak typeof(self) weakSelf = self;
- [tableView setRefreshHeaderWithBlock:^{
- [weakSelf youpaifrequestMemberListWithStatus:kRefreshHeader];
- }];
- [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.offset(0.0f);
- make.bottom.offset(-SafeHeight);
- }];
-
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.youpaipdataSource.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSString *cellID = @"YOUPAILZLiveOnlineMemberCell";
- YOUPAILZLiveOnlineMemberCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (!cell) {
- cell = [[YOUPAILZLiveOnlineMemberCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- }
- [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] indexPath:indexPath type:self.youpaiptype youpaipthemeColor:HexColorFromRGB(0xFFDD8D)];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [self dismissViewControllerAnimated:YES completion:^{
- if (self.youpaipisAnchor == YES) {
- if (self.selectedMemberBlock != nil) {
- self.selectedMemberBlock(self.youpaipdataSource[indexPath.row]);
- }
- }else{
- if (self.selectedMemberBlock != nil) {
- self.selectedMemberBlock(self.youpaipdataSource[indexPath.row]);
- }
- }
- }];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- __weak typeof(self) weakSelf = self;
- [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
- [weakSelf youpaifrequestMemberListWithStatus:kRefreshFooter];
- }];
- }
- /// 获取预约列表数据
- - (void)youpaifrequestMemberListWithStatus:(kRefreshStatus)status{
-
- if (status != kRefreshFooter) {
- self.youpaipendtime = @"0";
- }
- WeakSelf;
- [LCHttpHelper requestWithURLString:GetLiveOnlineUsers parameters:@{@"endtime":self.youpaipendtime,@"live_id":self.youpaiplive_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [weakSelf.youpaipdataSource removeAllObjects];
- }
- NSDictionary *data = [dict objectForKey:@"data"];
- NSString *endTime = [NSString stringWithFormat:@"%@",[data objectForKey:@"end_time"]];
- NSArray <YOUPAILZLiveMemberModel *>*list = [YOUPAILZLiveMemberModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
- [weakSelf.youpaipdataSource addObjectsFromArray:list];
- [weakSelf.youpaiptableView reloadData];
- [weakSelf.youpaiptableView lz_hideEmptyView];
- if (weakSelf.youpaipdataSource.count == 0) {
- [weakSelf.youpaiptableView lz_showEmptyViewWithImage:nil content:@"当前还没有观众呢~"];
- }
- if ([weakSelf.youpaipendtime isEqual:endTime]) {
- [weakSelf youpaifrefreshFooterWithHidden:YES];
- }else{
- weakSelf.youpaipendtime = endTime;
- [weakSelf youpaifrefreshFooterWithHidden:NO];
- }
-
- }
- } failure:^(NSError *error) {
- [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
- }];
- }
- - (NSMutableArray<YOUPAILZLiveMemberModel *> *)youpaipdataSource{
- if (!_youpaipdataSource) {
- _youpaipdataSource = [NSMutableArray array];
- }
- return _youpaipdataSource;
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (UIView *)listView{
- return self.view;
- }
- @end
|