// // YOUPAILZLiveInviteListVC.m // TIANYAN // // Created by CY on 2021/5/28. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZLiveInviteListVC.h" #import "YOUPAILZLiveInviteCell.h" #import "UIScrollView+LZRefresh.h" #import "YOUPAILZLiveInviteModel.h" @interface YOUPAILZLiveInviteListVC () @property (nonatomic,assign) LZLiveInviteType youpaiptype; @property (nonatomic,weak) UITableView *youpaiptableView; @property (nonatomic,assign) NSInteger youpaippage; @property (nonatomic,strong)NSMutableArray *youpaipdataSource; @end @implementation YOUPAILZLiveInviteListVC -(instancetype)initWithType:(LZLiveInviteType)type{ if (self = [super init]) { _youpaiptype = type; } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor clearColor]; [self youpaifinitUI]; [self youpaifrequestInviteListWithStatus:kRefreshHeader]; } - (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.estimatedSectionFooterHeight = CGFLOAT_MIN; tableView.sectionFooterHeight = CGFLOAT_MIN; tableView.estimatedSectionHeaderHeight = CGFLOAT_MIN; tableView.sectionHeaderHeight = CGFLOAT_MIN; tableView.backgroundColor = [UIColor clearColor]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.showsVerticalScrollIndicator = NO; tableView.showsHorizontalScrollIndicator = NO; [self.view addSubview:tableView]; self.youpaiptableView = tableView; __weak typeof(self) weakSelf = self; [tableView setRefreshHeaderWithBlock:^{ [weakSelf youpaifrequestInviteListWithStatus:kRefreshHeader]; }]; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.offset(0.0f); }]; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *cellID = @"YOUPAILZLiveInviteCell"; YOUPAILZLiveInviteCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[YOUPAILZLiveInviteCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] type:self.youpaiptype]; __weak typeof(self) weakSelf = self; [cell setYoupaipinviteBlock:^(YOUPAILZLiveInviteModel * _Nonnull model) { if (weakSelf.youpaipinviteBlock != nil) { weakSelf.youpaipinviteBlock(weakSelf.youpaiptype, model); } }]; return cell; } #pragma mark - UITableViewDelegate - (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 youpaifrequestInviteListWithStatus:kRefreshFooter]; }]; } /// 获取预约列表数据 - (void)youpaifrequestInviteListWithStatus:(kRefreshStatus)status{ if (status == kRefreshFooter) { self.youpaippage ++; }else{ self.youpaippage = 1; } NSString *invite_type = @"pk"; if (self.youpaiptype == LZLiveInviteTypeLianMai) { invite_type = @"lianmai"; } WeakSelf; [LCHttpHelper requestWithURLString:GetInviteList parameters:@{@"page":@(self.youpaippage),@"is_invite":@(self.youpaipis_invite),@"invite_type":invite_type} 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"]; NSArray *list = [YOUPAILZLiveInviteModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]]; [weakSelf.youpaipdataSource addObjectsFromArray:list]; [weakSelf.youpaiptableView reloadData]; NSInteger youpaiptotalPage = [[data objectForKey:@"total_page"] integerValue]; [weakSelf youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage]; } } failure:^(NSError *error) { [weakSelf.youpaiptableView endRefreshing:kRefreshAll]; }]; } - (NSMutableArray *)youpaipdataSource{ if (!_youpaipdataSource) { _youpaipdataSource = [NSMutableArray array]; } return _youpaipdataSource; } #pragma mark - JXCategoryListContentViewDelegate - (UIView *)listView{ return self.view; } @end