酷店

KDPLiveRightViewController.m 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // KDPLiveRightViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPLiveRightViewController.h"
  9. #import "KDPLiveRightTableViewCell.h"
  10. #import "KDPLiveRightHeaderView.h"
  11. #import "KDPLiveStatisticsModel.h"
  12. @interface KDPLiveRightViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, strong) KDPLiveRightHeaderView *headerView;
  15. @property (nonatomic, strong) NSString *type;
  16. @property (nonatomic, assign) NSInteger page;
  17. @property (nonatomic, strong) NSMutableArray *dataSource;
  18. @end
  19. @implementation KDPLiveRightViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.navBar.hidden = YES;
  24. self.type = @"today";
  25. UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115)];
  26. [backView setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF235F],[UIColor colorWithHex:0xFF7676]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
  27. [self.view addSubview:backView];
  28. [self.view addSubview:self.tableView];
  29. self.view.backgroundColor = [UIColor colorWithHex:0xF9F9F9];
  30. self.tableView.tableHeaderView = self.headerView;
  31. }
  32. - (void)requestTotalData{
  33. NSDictionary *params = @{@"type":self.type,@"page":@(self.page)};
  34. [LoadingView show];
  35. NSString *statisticsUrl = [NSString stringWithFormat:@"%@api/onlive/statistics",KDURL];
  36. [KDPNetworkRequestHTTP postURL:statisticsUrl params:params success:^(id _Nonnull json) {
  37. [LoadingView dismiss];
  38. NSArray *liveDataArr = [NSArray yy_modelArrayWithClass:[KDPLiveStatisticsModel class] json:json[@"data"]];
  39. NSDictionary *headerDict = json[@"total"];
  40. [self.headerView reloadHeaderData:headerDict];
  41. if (self.page == 1) {
  42. [self.dataSource removeAllObjects];
  43. }
  44. if (liveDataArr.count > 0) {
  45. [self.dataSource addObjectsFromArray:liveDataArr];
  46. } else{
  47. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  48. }
  49. self.headerView.hiddenGoodTipView = self.dataSource.count > 0 ? NO : YES;
  50. [self.tableView.mj_footer endRefreshing];
  51. [self.tableView.mj_header endRefreshing];
  52. [self.tableView reloadData];
  53. } failure:^(NSError * _Nonnull error) {
  54. [self.tableView.mj_footer endRefreshing];
  55. [self.tableView.mj_header endRefreshing];
  56. }];
  57. }
  58. - (void)viewWillAppear:(BOOL)animated{
  59. [super viewWillAppear:animated];
  60. [self.tableView.mj_header beginRefreshing];
  61. }
  62. - (UITableView *)tableView{
  63. if (!_tableView) {
  64. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, SCREEN_HEIGHT-KDNavBarHeight-KDTabBarHeight) style:UITableViewStylePlain];
  65. _tableView.showsVerticalScrollIndicator = NO;
  66. _tableView.showsHorizontalScrollIndicator = NO;
  67. _tableView.backgroundColor = [UIColor clearColor];
  68. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  69. _tableView.emptyDataSetDelegate = self;
  70. _tableView.emptyDataSetSource = self;
  71. [_tableView registerClass:[KDPLiveRightTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPLiveRightTableViewCell class])];
  72. _tableView.rowHeight = 105;
  73. _tableView.delegate = self;
  74. _tableView.dataSource = self;
  75. if (@available(iOS 11.0, *)) {
  76. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  77. } else {
  78. // Fallback on earlier versions
  79. }
  80. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 0.1f)];
  81. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  82. self.page = 1;
  83. [self requestTotalData];
  84. }];
  85. _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  86. self.page ++;
  87. [self requestTotalData];
  88. }];
  89. [_tableView.mj_header beginRefreshing];
  90. }
  91. return _tableView;
  92. }
  93. - (NSMutableArray *)dataSource{
  94. if (!_dataSource) {
  95. _dataSource = [NSMutableArray array];
  96. }
  97. return _dataSource;
  98. }
  99. - (KDPLiveRightHeaderView *)headerView{
  100. if (!_headerView) {
  101. _headerView = [[KDPLiveRightHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 171)];
  102. _headerView.backgroundColor = [UIColor clearColor];
  103. _headerView.selectIndex = 0;
  104. NSArray *typeArray = @[@"today",@"yesterday",@"all"];
  105. WeakSelf(weakSelf);
  106. _headerView.clickBlock = ^(NSInteger index) {
  107. weakSelf.type = typeArray[index];
  108. [weakSelf requestTotalData];
  109. };
  110. }
  111. return _headerView;
  112. }
  113. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  114. KDPLiveRightTableViewCell *tabCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPLiveRightTableViewCell class])];
  115. tabCell.selectionStyle = UITableViewCellSelectionStyleNone;
  116. [tabCell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  117. return tabCell;
  118. }
  119. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  120. return 1;
  121. }
  122. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  123. return self.dataSource.count;
  124. }
  125. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  126. KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
  127. KDPLiveStatisticsModel *statusModel = self.dataSource[indexPath.row];
  128. KDPGoodsModel *goodModel = [[KDPGoodsModel alloc] init];
  129. goodModel.goods_id = statusModel.goods_id;
  130. goodModel.img = statusModel.img;
  131. detailVC.model = goodModel;
  132. [self.navigationController pushViewController:detailVC animated:YES];
  133. }
  134. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  135. return [UIImage imageNamed:@"no_order"];
  136. }
  137. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  138. return YES;
  139. }
  140. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  141. return 30;
  142. }
  143. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  144. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  145. }
  146. @end