// // 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 () @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]; } - (void)requestData{ NSDictionary *params = @{@"page":@(self.page)}; NSString *liveListUrl = [NSString stringWithFormat:@"%@api/onlive/liveList",KDURL]; [LoadingView showInView:self.view]; [KDPNetworkRequestHTTP postURL:liveListUrl params:params success:^(id _Nonnull json) { [LoadingView dismiss]; 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) { [LoadingView dismiss]; [self.tableView.mj_footer endRefreshing]; [self.tableView.mj_header endRefreshing]; }]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.tableView.mj_header beginRefreshing]; } - (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.layer.masksToBounds = YES; 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 = [MJRefreshBackFooter footerWithRefreshingBlock:^{ self.page ++; [self requestData]; }]; [_tableView.mj_header beginRefreshing]; } 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 50; } - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{ return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}]; } @end