酷店

KDPLiveRightViewController.m 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 0.1f)];
  76. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  77. self.page = 1;
  78. [self requestTotalData];
  79. }];
  80. _tableView.mj_footer = [MJRefreshBackFooter footerWithRefreshingBlock:^{
  81. self.page ++;
  82. [self requestTotalData];
  83. }];
  84. [_tableView.mj_header beginRefreshing];
  85. }
  86. return _tableView;
  87. }
  88. - (NSMutableArray *)dataSource{
  89. if (!_dataSource) {
  90. _dataSource = [NSMutableArray array];
  91. }
  92. return _dataSource;
  93. }
  94. - (KDPLiveRightHeaderView *)headerView{
  95. if (!_headerView) {
  96. _headerView = [[KDPLiveRightHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 171)];
  97. _headerView.backgroundColor = [UIColor clearColor];
  98. _headerView.selectIndex = 0;
  99. NSArray *typeArray = @[@"today",@"yesterday",@"all"];
  100. WeakSelf(weakSelf);
  101. _headerView.clickBlock = ^(NSInteger index) {
  102. weakSelf.type = typeArray[index];
  103. [weakSelf requestTotalData];
  104. };
  105. }
  106. return _headerView;
  107. }
  108. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  109. KDPLiveRightTableViewCell *tabCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPLiveRightTableViewCell class])];
  110. tabCell.selectionStyle = UITableViewCellSelectionStyleNone;
  111. [tabCell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  112. return tabCell;
  113. }
  114. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  115. return 1;
  116. }
  117. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  118. return self.dataSource.count;
  119. }
  120. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  121. KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
  122. KDPLiveStatisticsModel *statusModel = self.dataSource[indexPath.row];
  123. KDPGoodsModel *goodModel = [[KDPGoodsModel alloc] init];
  124. goodModel.goods_id = statusModel.goods_id;
  125. goodModel.img = statusModel.img;
  126. detailVC.model = goodModel;
  127. [self.navigationController pushViewController:detailVC animated:YES];
  128. }
  129. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  130. return [UIImage imageNamed:@"no_order"];
  131. }
  132. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  133. return YES;
  134. }
  135. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  136. return 50;
  137. }
  138. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  139. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  140. }
  141. @end