123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //
- // KDPLiveLeftViewController.m
- // KuDianProject
- //
- // Created by admin on 2019/7/9.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPLiveLeftViewController.h"
- #import "KDPLiveLeftTableViewCell.h"
- #import "KDPOrderDetailViewController.h"
- #import "KDPLiveListModel.h"
- @interface KDPLiveLeftViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, assign) NSInteger page;
- @property (nonatomic, strong) NSMutableArray *dataSource;
- @end
- @implementation KDPLiveLeftViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.navBar.hidden = YES;
- [self setUpUI];
- self.page = 1;
- [self requestData];
- }
- - (void)requestData{
- NSDictionary *params = @{@"page":@(self.page)};
- NSString *liveListUrl = [NSString stringWithFormat:@"%@api/onlive/liveList",KDURL];
- [KDPNetworkRequestHTTP postURL:liveListUrl params:params success:^(id _Nonnull json) {
- NSArray *liveDataArr = [NSArray yy_modelArrayWithClass:[KDPLiveListModel class] json:json[@"data"]];
- if (self.page == 1) {
- [self.dataSource removeAllObjects];
- }
- if (liveDataArr.count > 0) {
- [self.dataSource addObjectsFromArray:liveDataArr];
- } else{
- [self.tableView.mj_footer endRefreshingWithNoMoreData];
- }
- [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 requestData];
- }
- - (void)setUpUI{
- // tip view
- UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,8, 223, 21)];
- tipLabel.backgroundColor = [UIColor colorWithHex:0xFFF3F3];
- tipLabel.font = FONT_SYS(12);
- tipLabel.textColor = [UIColor colorWithHex:0xFF7075];
- tipLabel.layer.cornerRadius = 11;
- tipLabel.textAlignment=NSTextAlignmentCenter;
- tipLabel.layer.masksToBounds = YES;
- tipLabel.textAlignment = NSTextAlignmentCenter;
- tipLabel.text = @"目前只统计直播期间该商品订单数哦";
- tipLabel.centerX = self.view.centerX;
- [self.view addSubview:tipLabel];
- self.view.backgroundColor = [UIColor colorWithHex:0xF9F9F9];
- [self.view addSubview:self.tableView];
- }
- - (UITableView *)tableView{
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 36, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-KDTabBarHeight-36) style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.emptyDataSetDelegate = self;
- _tableView.emptyDataSetSource = self;
- _tableView.rowHeight = 136;
- _tableView.backgroundColor = [UIColor clearColor];
- [_tableView registerClass:[KDPLiveLeftTableViewCell class] forCellReuseIdentifier:NSStringFromClass([KDPLiveLeftTableViewCell class])];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- self.page = 1;
- [self requestData];
- }];
- _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- self.page ++;
- [self requestData];
- }];
- }
- return _tableView;
- }
- - (NSMutableArray *)dataSource{
- if (!_dataSource) {
- _dataSource = [NSMutableArray array];
- }
- return _dataSource;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- KDPLiveLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([KDPLiveLeftTableViewCell class])];
- cell.orderClickBlock = ^(UIButton * _Nonnull btn) {
- KDPOrderDetailViewController *detailVC = [[KDPOrderDetailViewController alloc] init];
- KDPLiveListModel *model = self.dataSource[indexPath.row];
- detailVC.live_time = model.show_time;
- detailVC.live_stream_id = model.live_stream_id;
- WeakSelf(weakSelf);
- [weakSelf.navigationController pushViewController:detailVC animated:YES];
- };
- [cell configWithViewModel:self.dataSource[indexPath.row] indexpath:indexPath];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.dataSource.count;
- }
- - (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
|