123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // KDPLiveRightViewController.m
- // KuDianProject
- //
- // Created by admin on 2019/7/9.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPLiveRightViewController.h"
- #import "KDPLiveRightTableViewCell.h"
- #import "KDPLiveRightHeaderView.h"
- #import "KDPLiveStatisticsModel.h"
- @interface KDPLiveRightViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) KDPLiveRightHeaderView *headerView;
- @property (nonatomic, strong) NSString *type;
- @property (nonatomic, assign) NSInteger page;
- @property (nonatomic, strong) NSMutableArray *dataSource;
- @end
- @implementation KDPLiveRightViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.navBar.hidden = YES;
- self.type = @"today";
-
- UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115)];
- [backView setGradientBackgroundWithColors:@[[UIColor colorWithHex:0xFF235F],[UIColor colorWithHex:0xFF7676]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- [self.view addSubview:backView];
- [self.view addSubview:self.tableView];
- self.view.backgroundColor = [UIColor colorWithHex:0xF9F9F9];
- self.tableView.tableHeaderView = self.headerView;
- }
- - (void)requestTotalData{
- NSDictionary *params = @{@"type":self.type,@"page":@(self.page)};
- [LoadingView show];
- NSString *statisticsUrl = [NSString stringWithFormat:@"%@api/onlive/statistics",KDURL];
- [KDPNetworkRequestHTTP postURL:statisticsUrl params:params success:^(id _Nonnull json) {
- [LoadingView dismiss];
- NSArray *liveDataArr = [NSArray yy_modelArrayWithClass:[KDPLiveStatisticsModel class] json:json[@"data"]];
- NSDictionary *headerDict = json[@"total"];
- [self.headerView reloadHeaderData:headerDict];
- if (self.page == 1) {
- [self.dataSource removeAllObjects];
- }
- if (liveDataArr.count > 0) {
- [self.dataSource addObjectsFromArray:liveDataArr];
- } else{
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- self.headerView.hiddenGoodTipView = self.dataSource.count > 0 ? NO : YES;
- [self.tableView.mj_footer endRefreshing];
- [self.tableView.mj_header endRefreshing];
- [self.tableView reloadData];
- } failure:^(NSError * _Nonnull error) {
- [self.tableView.mj_footer endRefreshing];
- [self.tableView.mj_header endRefreshing];
- }];
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.tableView.mj_header beginRefreshing];
- }
- - (UITableView *)tableView{
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, SCREEN_HEIGHT-KDNavBarHeight-KDTabBarHeight) style:UITableViewStylePlain];
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.emptyDataSetDelegate = self;
- _tableView.emptyDataSetSource = self;
- [_tableView registerClass:[KDPLiveRightTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPLiveRightTableViewCell class])];
- _tableView.rowHeight = 105;
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 0.1f)];
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- self.page = 1;
- [self requestTotalData];
- }];
- _tableView.mj_footer = [MJRefreshBackFooter footerWithRefreshingBlock:^{
- self.page ++;
- [self requestTotalData];
- }];
- [_tableView.mj_header beginRefreshing];
- }
- return _tableView;
- }
- - (NSMutableArray *)dataSource{
- if (!_dataSource) {
- _dataSource = [NSMutableArray array];
- }
- return _dataSource;
- }
- - (KDPLiveRightHeaderView *)headerView{
- if (!_headerView) {
- _headerView = [[KDPLiveRightHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 171)];
- _headerView.backgroundColor = [UIColor clearColor];
- _headerView.selectIndex = 0;
- NSArray *typeArray = @[@"today",@"yesterday",@"all"];
- WeakSelf(weakSelf);
- _headerView.clickBlock = ^(NSInteger index) {
- weakSelf.type = typeArray[index];
- [weakSelf requestTotalData];
- };
- }
- return _headerView;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- KDPLiveRightTableViewCell *tabCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPLiveRightTableViewCell class])];
- tabCell.selectionStyle = UITableViewCellSelectionStyleNone;
- [tabCell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
- return tabCell;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataSource.count;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
- KDPLiveStatisticsModel *statusModel = self.dataSource[indexPath.row];
- KDPGoodsModel *goodModel = [[KDPGoodsModel alloc] init];
- goodModel.goods_id = statusModel.goods_id;
- goodModel.img = statusModel.img;
- detailVC.model = goodModel;
- [self.navigationController pushViewController:detailVC animated:YES];
-
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
- return [UIImage imageNamed:@"no_order"];
- }
- - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
- return YES;
- }
- - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
- return 50;
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
- return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
- }
- @end
|