// // 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 () @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; self.page = 1; [self requestTotalData]; } - (void)requestTotalData{ NSDictionary *params = @{@"type":self.type,@"page":@(self.page)}; NSString *statisticsUrl = [NSString stringWithFormat:@"%@api/onlive/statistics",KDURL]; [KDPNetworkRequestHTTP postURL:statisticsUrl params:params success:^(id _Nonnull json) { 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 requestTotalData]; } - (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; if (@available(iOS 11.0, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; } _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 = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ self.page ++; [self requestTotalData]; }]; } 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; goodModel.commission_rate=statusModel.commission_rate_2; 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 30; } - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{ return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}]; } @end