酷店

KDPLiveLeftViewController.m 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // KDPLiveLeftViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPLiveLeftViewController.h"
  9. #import "KDPLiveLeftTableViewCell.h"
  10. #import "KDPOrderDetailViewController.h"
  11. #import "KDPLiveListModel.h"
  12. @interface KDPLiveLeftViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, assign) NSInteger page;
  15. @property (nonatomic, strong) NSMutableArray *dataSource;
  16. @end
  17. @implementation KDPLiveLeftViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.navBar.hidden = YES;
  22. [self setUpUI];
  23. }
  24. - (void)requestData{
  25. NSDictionary *params = @{@"page":@(self.page)};
  26. NSString *liveListUrl = [NSString stringWithFormat:@"%@api/onlive/liveList",KDURL];
  27. [LoadingView showInView:self.view];
  28. [KDPNetworkRequestHTTP postURL:liveListUrl params:params success:^(id _Nonnull json) {
  29. [LoadingView dismiss];
  30. NSArray *liveDataArr = [NSArray yy_modelArrayWithClass:[KDPLiveListModel class] json:json[@"data"]];
  31. if (self.page == 1) {
  32. [self.dataSource removeAllObjects];
  33. }
  34. if (liveDataArr.count > 0) {
  35. [self.dataSource addObjectsFromArray:liveDataArr];
  36. } else{
  37. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  38. }
  39. [self.tableView.mj_footer endRefreshing];
  40. [self.tableView.mj_header endRefreshing];
  41. [self.tableView reloadData];
  42. } failure:^(NSError * _Nonnull error) {
  43. [LoadingView dismiss];
  44. [self.tableView.mj_footer endRefreshing];
  45. [self.tableView.mj_header endRefreshing];
  46. }];
  47. }
  48. - (void)viewWillAppear:(BOOL)animated{
  49. [super viewWillAppear:animated];
  50. [self.tableView.mj_header beginRefreshing];
  51. }
  52. - (void)setUpUI{
  53. // tip view
  54. UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,8, 223, 21)];
  55. tipLabel.backgroundColor = [UIColor colorWithHex:0xFFF3F3];
  56. tipLabel.font = FONT_SYS(12);
  57. tipLabel.textColor = [UIColor colorWithHex:0xFF7075];
  58. tipLabel.layer.cornerRadius = 11;
  59. tipLabel.layer.masksToBounds = YES;
  60. tipLabel.text = @"目前只统计直播期间该商品订单数哦";
  61. tipLabel.centerX = self.view.centerX;
  62. [self.view addSubview:tipLabel];
  63. self.view.backgroundColor = [UIColor colorWithHex:0xF9F9F9];
  64. [self.view addSubview:self.tableView];
  65. }
  66. - (UITableView *)tableView{
  67. if (!_tableView) {
  68. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 36, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-KDTabBarHeight-36) style:UITableViewStylePlain];
  69. _tableView.delegate = self;
  70. _tableView.dataSource = self;
  71. _tableView.showsVerticalScrollIndicator = NO;
  72. _tableView.showsHorizontalScrollIndicator = NO;
  73. _tableView.emptyDataSetDelegate = self;
  74. _tableView.emptyDataSetSource = self;
  75. _tableView.rowHeight = 136;
  76. _tableView.backgroundColor = [UIColor clearColor];
  77. [_tableView registerClass:[KDPLiveLeftTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPLiveLeftTableViewCell class])];
  78. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  79. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  80. self.page = 1;
  81. [self requestData];
  82. }];
  83. _tableView.mj_footer = [MJRefreshBackFooter footerWithRefreshingBlock:^{
  84. self.page ++;
  85. [self requestData];
  86. }];
  87. [_tableView.mj_header beginRefreshing];
  88. }
  89. return _tableView;
  90. }
  91. - (NSMutableArray *)dataSource{
  92. if (!_dataSource) {
  93. _dataSource = [NSMutableArray array];
  94. }
  95. return _dataSource;
  96. }
  97. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  98. KDPLiveLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPLiveLeftTableViewCell class])];
  99. cell.orderClickBlock = ^(UIButton * _Nonnull btn) {
  100. KDPOrderDetailViewController *detailVC = [[KDPOrderDetailViewController alloc] init];
  101. KDPLiveListModel *model = self.dataSource[indexPath.row];
  102. detailVC.live_time = model.show_time;
  103. detailVC.live_stream_id = model.live_stream_id;
  104. WeakSelf(weakSelf);
  105. [weakSelf.navigationController pushViewController:detailVC animated:YES];
  106. };
  107. [cell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  108. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  109. return cell;
  110. }
  111. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  112. return 1;
  113. }
  114. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  115. return self.dataSource.count;
  116. }
  117. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  118. return [UIImage imageNamed:@"no_order"];
  119. }
  120. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  121. return YES;
  122. }
  123. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  124. return 50;
  125. }
  126. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  127. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  128. }
  129. @end