YOUPAILZLiveInviteListVC.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // YOUPAILZLiveInviteListVC.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/28.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveInviteListVC.h"
  9. #import "YOUPAILZLiveInviteCell.h"
  10. #import "UIScrollView+LZRefresh.h"
  11. #import "YOUPAILZLiveInviteModel.h"
  12. @interface YOUPAILZLiveInviteListVC () <UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic,assign) LZLiveInviteType youpaiptype;
  14. @property (nonatomic,weak) UITableView *youpaiptableView;
  15. @property (nonatomic,assign) NSInteger youpaippage;
  16. @property (nonatomic,strong)NSMutableArray <YOUPAILZLiveInviteModel *>*youpaipdataSource;
  17. @end
  18. @implementation YOUPAILZLiveInviteListVC
  19. -(instancetype)initWithType:(LZLiveInviteType)type{
  20. if (self = [super init]) {
  21. _youpaiptype = type;
  22. }
  23. return self;
  24. }
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. self.view.backgroundColor = [UIColor clearColor];
  28. [self youpaifinitUI];
  29. [self youpaifrequestInviteListWithStatus:kRefreshHeader];
  30. }
  31. - (void)youpaifinitUI{
  32. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  33. tableView.delegate = self;
  34. tableView.dataSource = self;
  35. tableView.rowHeight = 60.0f;
  36. tableView.estimatedRowHeight = 60.0f;
  37. tableView.estimatedSectionFooterHeight = CGFLOAT_MIN;
  38. tableView.sectionFooterHeight = CGFLOAT_MIN;
  39. tableView.estimatedSectionHeaderHeight = CGFLOAT_MIN;
  40. tableView.sectionHeaderHeight = CGFLOAT_MIN;
  41. tableView.backgroundColor = [UIColor clearColor];
  42. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  43. tableView.showsVerticalScrollIndicator = NO;
  44. tableView.showsHorizontalScrollIndicator = NO;
  45. [self.view addSubview:tableView];
  46. self.youpaiptableView = tableView;
  47. __weak typeof(self) weakSelf = self;
  48. [tableView setRefreshHeaderWithBlock:^{
  49. [weakSelf youpaifrequestInviteListWithStatus:kRefreshHeader];
  50. }];
  51. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.right.top.bottom.offset(0.0f);
  53. }];
  54. }
  55. #pragma mark - UITableViewDataSource
  56. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  57. return self.youpaipdataSource.count;
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  60. NSString *cellID = @"YOUPAILZLiveInviteCell";
  61. YOUPAILZLiveInviteCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  62. if (cell == nil) {
  63. cell = [[YOUPAILZLiveInviteCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  64. }
  65. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row] type:self.youpaiptype];
  66. __weak typeof(self) weakSelf = self;
  67. [cell setYoupaipinviteBlock:^(YOUPAILZLiveInviteModel * _Nonnull model) {
  68. if (weakSelf.youpaipinviteBlock != nil) {
  69. weakSelf.youpaipinviteBlock(weakSelf.youpaiptype, model);
  70. }
  71. }];
  72. return cell;
  73. }
  74. #pragma mark - UITableViewDelegate
  75. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  76. return CGFLOAT_MIN;
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  79. return CGFLOAT_MIN;
  80. }
  81. /// 设置加载更多
  82. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  83. __weak typeof(self) weakSelf = self;
  84. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  85. [weakSelf youpaifrequestInviteListWithStatus:kRefreshFooter];
  86. }];
  87. }
  88. /// 获取预约列表数据
  89. - (void)youpaifrequestInviteListWithStatus:(kRefreshStatus)status{
  90. if (status == kRefreshFooter) {
  91. self.youpaippage ++;
  92. }else{
  93. self.youpaippage = 1;
  94. }
  95. NSString *invite_type = @"pk";
  96. if (self.youpaiptype == LZLiveInviteTypeLianMai) {
  97. invite_type = @"lianmai";
  98. }
  99. WeakSelf;
  100. [LCHttpHelper requestWithURLString:GetInviteList parameters:@{@"page":@(self.youpaippage),@"is_invite":@(self.youpaipis_invite),@"invite_type":invite_type} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  101. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  102. NSDictionary* dict = (NSDictionary*)responseObject;
  103. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  104. if (code == 0) {//成功
  105. if (status != kRefreshFooter) {
  106. [weakSelf.youpaipdataSource removeAllObjects];
  107. }
  108. NSDictionary *data = [dict objectForKey:@"data"];
  109. NSArray <YOUPAILZLiveInviteModel *>*list = [YOUPAILZLiveInviteModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  110. [weakSelf.youpaipdataSource addObjectsFromArray:list];
  111. [weakSelf.youpaiptableView reloadData];
  112. NSInteger youpaiptotalPage = [[data objectForKey:@"total_page"] integerValue];
  113. [weakSelf youpaifrefreshFooterWithHidden:self.youpaippage >= youpaiptotalPage];
  114. }
  115. } failure:^(NSError *error) {
  116. [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
  117. }];
  118. }
  119. - (NSMutableArray<YOUPAILZLiveInviteModel *> *)youpaipdataSource{
  120. if (!_youpaipdataSource) {
  121. _youpaipdataSource = [NSMutableArray array];
  122. }
  123. return _youpaipdataSource;
  124. }
  125. #pragma mark - JXCategoryListContentViewDelegate
  126. - (UIView *)listView{
  127. return self.view;
  128. }
  129. @end