酷店

KDPLiveLeftViewController.m 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. self.page = 1;
  24. [self requestData];
  25. }
  26. - (void)requestData{
  27. NSDictionary *params = @{@"page":@(self.page)};
  28. NSString *liveListUrl = [NSString stringWithFormat:@"%@api/onlive/liveList",KDURL];
  29. [KDPNetworkRequestHTTP postURL:liveListUrl params:params success:^(id _Nonnull json) {
  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. [self.tableView.mj_footer endRefreshing];
  44. [self.tableView.mj_header endRefreshing];
  45. }];
  46. }
  47. - (void)viewWillAppear:(BOOL)animated{
  48. [super viewWillAppear:animated];
  49. [self requestData];
  50. }
  51. - (void)setUpUI{
  52. // tip view
  53. UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,8, 223, 21)];
  54. tipLabel.backgroundColor = [UIColor colorWithHex:0xFFF3F3];
  55. tipLabel.font = FONT_SYS(12);
  56. tipLabel.textColor = [UIColor colorWithHex:0xFF7075];
  57. tipLabel.layer.cornerRadius = 11;
  58. tipLabel.layer.masksToBounds = YES;
  59. tipLabel.text = @"目前只统计直播期间该商品订单数哦";
  60. tipLabel.centerX = self.view.centerX;
  61. [self.view addSubview:tipLabel];
  62. self.view.backgroundColor = [UIColor colorWithHex:0xF9F9F9];
  63. [self.view addSubview:self.tableView];
  64. }
  65. - (UITableView *)tableView{
  66. if (!_tableView) {
  67. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 36, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-KDTabBarHeight-36) style:UITableViewStylePlain];
  68. _tableView.delegate = self;
  69. _tableView.dataSource = self;
  70. _tableView.showsVerticalScrollIndicator = NO;
  71. _tableView.showsHorizontalScrollIndicator = NO;
  72. _tableView.emptyDataSetDelegate = self;
  73. _tableView.emptyDataSetSource = self;
  74. _tableView.rowHeight = 136;
  75. _tableView.backgroundColor = [UIColor clearColor];
  76. [_tableView registerClass:[KDPLiveLeftTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPLiveLeftTableViewCell class])];
  77. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  78. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  79. self.page = 1;
  80. [self requestData];
  81. }];
  82. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  83. self.page ++;
  84. [self requestData];
  85. }];
  86. }
  87. return _tableView;
  88. }
  89. - (NSMutableArray *)dataSource{
  90. if (!_dataSource) {
  91. _dataSource = [NSMutableArray array];
  92. }
  93. return _dataSource;
  94. }
  95. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  96. KDPLiveLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPLiveLeftTableViewCell class])];
  97. cell.orderClickBlock = ^(UIButton * _Nonnull btn) {
  98. KDPOrderDetailViewController *detailVC = [[KDPOrderDetailViewController alloc] init];
  99. KDPLiveListModel *model = self.dataSource[indexPath.row];
  100. detailVC.live_time = model.show_time;
  101. detailVC.live_stream_id = model.live_stream_id;
  102. WeakSelf(weakSelf);
  103. [weakSelf.navigationController pushViewController:detailVC animated:YES];
  104. };
  105. [cell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  106. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  107. return cell;
  108. }
  109. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  110. return 1;
  111. }
  112. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  113. return self.dataSource.count;
  114. }
  115. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  116. return [UIImage imageNamed:@"no_order"];
  117. }
  118. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  119. return YES;
  120. }
  121. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  122. return 30;
  123. }
  124. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  125. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  126. }
  127. @end