| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- //
- // MOApplicationTableView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/8/9.
- //
- //一页的size
- #define kPageSize 15
- #import "MOApplicationTableView.h"
- #import "MOApplicationTableViewCell.h"
- @interface MOApplicationTableView ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray *dataArr;
- /** 没有更多的数据视图 */
- @property (nonatomic, strong) MONoMoreDataView *noMoreDataView;
- @property (nonatomic, copy) NSString *next;
- @end
- @implementation MOApplicationTableView
- - (instancetype)init{
- self = [super init];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (void)setupUI{
- [self addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.equalTo(self);
- }];
- self.next = @"";
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (void)listWillAppear{
- if(self.dataArr.count == 0 && !self.isManage){
- [self getFirstHttpData];
- }
- }
- - (void)getFirstHttpData{
-
- NSString *roomId = self.roomId;
- if(roomId.length == 0){
- return;
- }
-
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"page":basePage,
- @"roomId":roomId};
- [self getAllLinkMicApplyListDataWith:baseDict];
- }
- - (void)getAllLinkMicApplyListDataWith:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toGetApplyListAboutLinkMicWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- __strong typeof(weakSelf) self = weakSelf;
- [self.tableView.mj_header endRefreshing];
- [self.tableView.mj_footer endRefreshing];
- if(kCode_Success){
- // MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
-
- MOPersonData *personModel = [MOPersonData modelObjectWithDictionary:data[@"data"]];
- if(personModel.next == nil || personModel.next.length == 0){
- if(self.next == nil || self.next.length == 0){
- //第一页
- self.dataArr = [personModel.personList mutableCopy];
- }
- else{
- //最后一页
- [self.dataArr addObjectsFromArray:personModel.personList];
- }
- self.next = @"";
-
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- else{
- self.next = personModel.next;
- [self.dataArr addObjectsFromArray:personModel.personList];
- }
-
- [self.tableView reloadData];
- self.tableView.mj_footer.hidden = (self.dataArr.count > 0) ? NO : YES;
- self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (UIView *)listView{
- return self;
- }
- - (void)setLinkMics:(NSArray *)linkMics{
- _linkMics = linkMics;
-
- [self.dataArr removeAllObjects];
-
- NSInteger seatNum = 1;
- for (MOLinkMic *linkObject in linkMics) {
- if(linkObject.profile.id.length > 0){
- linkObject.seatNum = seatNum;
- [self.dataArr addObject:linkObject];
- }
- seatNum ++;
- }
- self.noMoreDataView.isHaveData = (self.dataArr.count > 0) ? YES : NO;
- [self.tableView reloadData];
- }
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- WEAKSELF
- if(self.isManage){
- //管理Cell
- MOLinkMic *model = self.dataArr[indexPath.row];
- MOApplicationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MOApplicationTableViewCell_ID];
- cell.isManage = self.isManage;
- cell.roomId = self.roomId;
- cell.linkCellModel = model;
-
- __weak __typeof__(cell) weakCell = cell;
- cell.roomStatusChangeBlock = ^(MORoomStatus * _Nonnull roomStatus) {
- weakSelf.roomStatusChangeBlock ? weakSelf.roomStatusChangeBlock(roomStatus) : nil;
- };
-
- cell.hangUpBlock = ^(MOLinkMic * _Nonnull linkCellModel) {
- NSIndexPath *newIndexPath = [weakSelf.tableView indexPathForCell:weakCell];
- if (newIndexPath && newIndexPath.row < weakSelf.dataArr.count) {
- [weakSelf.dataArr removeObjectAtIndex:newIndexPath.row];
- [weakSelf.tableView deleteRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
- }
-
- weakSelf.hangUpBlock ? weakSelf.hangUpBlock(linkCellModel) : nil;
- };
-
- cell.addRTMTipBlock = ^(NSString * _Nonnull rtmTipStr) {
- weakSelf.addRTMTipBlock ? weakSelf.addRTMTipBlock(rtmTipStr) : nil;
- };
- return cell;
- }
- else{
- MOPersonList *moel = self.dataArr[indexPath.row];
- MOApplicationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MOApplicationTableViewCell_ID];
- cell.isManage = self.isManage;
- cell.roomId = self.roomId;
- cell.cellModel = moel;
-
- __weak __typeof__(cell) weakCell = cell;
- cell.roomStatusChangeBlock = ^(MORoomStatus * _Nonnull roomStatus) {
-
- NSIndexPath *newIndexPath = [weakSelf.tableView indexPathForCell:weakCell];
- [weakSelf.dataArr removeObjectAtIndex:newIndexPath.row];
- [weakSelf.tableView deleteRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
-
- if(roomStatus){
- weakSelf.roomStatusChangeBlock ? weakSelf.roomStatusChangeBlock(roomStatus) : nil;
- }
- };
-
- cell.addRTMTipBlock = ^(NSString * _Nonnull rtmTipStr) {
- weakSelf.addRTMTipBlock ? weakSelf.addRTMTipBlock(rtmTipStr) : nil;
- };
-
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
- #pragma mark - Lazy
- - (UITableView *)tableView{
- if (!_tableView)
- {
- _tableView= [[UITableView alloc] init];
- if (@available(iOS 11.0, *))
- {
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
-
- //iOS15适配
- if (@available(iOS 15.0, *))
- {
- self.tableView.sectionHeaderTopPadding = 0;
- }
-
- _tableView.backgroundColor = [UIColor whiteColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.rowHeight = 50.0;
- [_tableView registerNib:[UINib nibWithNibName:@"MOApplicationTableViewCell" bundle:nil] forCellReuseIdentifier:MOApplicationTableViewCell_ID];
- _tableView.backgroundView = self.noMoreDataView;
-
- WEAKSELF
- MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- if(!weakSelf.isManage){
- [weakSelf getFirstHttpData];
- }
- else{
- [weakSelf.tableView.mj_header endRefreshing];
- }
- }];
-
- header.lastUpdatedTimeLabel.hidden = YES;
- header.stateLabel.hidden = YES;
- _tableView.mj_header = header;
-
-
- _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
-
- NSString *roomId = weakSelf.roomId;
- if(roomId.length == 0){
- return;
- }
-
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":weakSelf.next};
- NSDictionary *baseDict = @{@"page":basePage,
- @"roomId":roomId};
- [weakSelf getAllLinkMicApplyListDataWith:baseDict];
- }];
-
- _tableView.mj_footer.hidden = YES;
- }
- return _tableView;
- }
- - (NSMutableArray *)dataArr{
- if(!_dataArr){
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (MONoMoreDataView *)noMoreDataView{
- if(!_noMoreDataView){
- _noMoreDataView = [MONoMoreDataView new];
- }
- return _noMoreDataView;
- }
- @end
|