酷店

KDPLiveLeftViewController.m 5.3KB

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. 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.textAlignment=NSTextAlignmentCenter;
  59. tipLabel.layer.masksToBounds = YES;
  60. tipLabel.textAlignment = NSTextAlignmentCenter;
  61. tipLabel.text = @"目前只统计直播期间该商品订单数哦";
  62. tipLabel.centerX = self.view.centerX;
  63. [self.view addSubview:tipLabel];
  64. self.view.backgroundColor = [UIColor colorWithHex:0xF9F9F9];
  65. [self.view addSubview:self.tableView];
  66. }
  67. - (UITableView *)tableView{
  68. if (!_tableView) {
  69. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 36, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-KDTabBarHeight-36) style:UITableViewStylePlain];
  70. _tableView.delegate = self;
  71. _tableView.dataSource = self;
  72. _tableView.showsVerticalScrollIndicator = NO;
  73. _tableView.showsHorizontalScrollIndicator = NO;
  74. _tableView.emptyDataSetDelegate = self;
  75. _tableView.emptyDataSetSource = self;
  76. _tableView.rowHeight = 136;
  77. _tableView.backgroundColor = [UIColor clearColor];
  78. [_tableView registerClass:[KDPLiveLeftTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPLiveLeftTableViewCell class])];
  79. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  80. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  81. self.page = 1;
  82. [self requestData];
  83. }];
  84. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  85. self.page ++;
  86. [self requestData];
  87. }];
  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 30;
  125. }
  126. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  127. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  128. }
  129. @end