酷店

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. self.page = 1;
  32. [self requestTotalData];
  33. }
  34. - (void)requestTotalData{
  35. NSDictionary *params = @{@"type":self.type,@"page":@(self.page)};
  36. NSString *statisticsUrl = [NSString stringWithFormat:@"%@api/onlive/statistics",KDURL];
  37. [KDPNetworkRequestHTTP postURL:statisticsUrl params:params success:^(id _Nonnull json) {
  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 requestTotalData];
  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. self.automaticallyAdjustsScrollViewInsets = NO;
  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. }
  90. return _tableView;
  91. }
  92. - (NSMutableArray *)dataSource{
  93. if (!_dataSource) {
  94. _dataSource = [NSMutableArray array];
  95. }
  96. return _dataSource;
  97. }
  98. - (KDPLiveRightHeaderView *)headerView{
  99. if (!_headerView) {
  100. _headerView = [[KDPLiveRightHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 171)];
  101. _headerView.backgroundColor = [UIColor clearColor];
  102. _headerView.selectIndex = 0;
  103. NSArray *typeArray = @[@"today",@"yesterday",@"all"];
  104. WeakSelf(weakSelf);
  105. _headerView.clickBlock = ^(NSInteger index) {
  106. weakSelf.type = typeArray[index];
  107. [weakSelf requestTotalData];
  108. };
  109. }
  110. return _headerView;
  111. }
  112. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  113. KDPLiveRightTableViewCell *tabCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPLiveRightTableViewCell class])];
  114. tabCell.selectionStyle = UITableViewCellSelectionStyleNone;
  115. [tabCell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
  116. return tabCell;
  117. }
  118. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  119. return 1;
  120. }
  121. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  122. return self.dataSource.count;
  123. }
  124. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  125. KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
  126. KDPLiveStatisticsModel *statusModel = self.dataSource[indexPath.row];
  127. KDPGoodsModel *goodModel = [[KDPGoodsModel alloc] init];
  128. goodModel.goods_id = statusModel.goods_id;
  129. goodModel.img = statusModel.img;
  130. goodModel.commission_rate=statusModel.commission_rate_2;
  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