// // KDPTodayListViewController.m // KuDianProject // // Created by 学丽 on 2019/7/9. // Copyright © 2019 KDP. All rights reserved. // #import "KDPTodayListViewController.h" #import "KDPTodayListCell.h" #import "SSWLineChartView.h" @interface KDPTodayListViewController () { UILabel *numLabel; NSTimer *timer_add; SSWLineChartView *chartView; NSString *timeHourType; } @property(nonatomic,strong)UITableView *tableView; @property(nonatomic,copy)NSString *last_order_id; @property(nonatomic,copy)NSString *is_new; @property(nonatomic,strong)NSMutableArray *dataArray; @end @implementation KDPTodayListViewController -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [timer_add invalidate]; } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if ([self.todayStr isEqualToString:@"实时订单"]) { timer_add = [NSTimer timerWithTimeInterval:30 target:self selector:@selector(timerClickAction) userInfo:nil repeats:YES]; } } - (void)viewDidLoad { [super viewDidLoad]; self.navBar.hidden=YES; self.is_new=@"1"; self.last_order_id=@""; self.view.backgroundColor=[UIColor whiteColor]; [self.view addSubview:self.tableView]; if (![self.todayStr isEqualToString:@"销量走势"]) { _tableView.emptyDataSetDelegate = self; _tableView.emptyDataSetSource = self; if ([self.todayStr isEqualToString:@"实时订单"]) { [self timerClickAction]; [self orderlistDAta]; }else{//热销商品 [self hotGoodList]; } [self addtablevHeadvew]; }else{ timeHourType=@"1";//最近1小时 [self addChart]; [self saleTotlaData]; } } #pragma mark---销量统计 -(void)saleTotlaData { [LoadingView show]; [KDPNetworkRequestHTTP postURL:SaleStatisticsURL params:@{@"type":timeHourType} success:^(id _Nonnull json) { NSArray *jsonArr =(NSArray *)json; NSMutableArray *xArray=[NSMutableArray array]; NSMutableArray *valueArray =[NSMutableArray array]; for (NSDictionary *dic in jsonArr) { [xArray addObject:dic[@"time"]]; [valueArray addObject:dic[@"num"]]; } chartView.xValuesArr=[xArray mutableCopy]; chartView.yValuesArr=[valueArray mutableCopy]; [LoadingView dismiss]; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } #pragma mark---热销商品 -(void)hotGoodList { [LoadingView show]; [KDPNetworkRequestHTTP postURL:hotGoodListURL params:nil success:^(id _Nonnull json) { NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]]; [self.dataArray addObjectsFromArray:array]; numLabel.text=[NSString stringWithFormat:@"共%@件商品",json[@"count"]]; [self.tableView reloadData]; [LoadingView dismiss]; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } #pragma mark---更新 -(void)timerClickAction { self.is_new =@"1"; if (self.dataArray.count>0) { KDPGoodsModel *model=self.dataArray.firstObject; self.last_order_id=model.Id; } [self orderlistDAta]; } #pragma mark---实时订单 -(void)orderlistDAta { NSDictionary *para=@{@"is_new":self.is_new,@"last_order_id":self.last_order_id}; [LoadingView show]; [KDPNetworkRequestHTTP postURL:todayOrderURL params:para success:^(id _Nonnull json) { if (self.is_new.integerValue == 1) { numLabel.text=[NSString stringWithFormat:@"共%@单",json[@"order_count"]]; } NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"order_list"]]; [self.dataArray addObjectsFromArray:array]; [self.tableView reloadData]; [self.tableView.mj_footer endRefreshing]; [self.tableView.mj_header endRefreshing]; [LoadingView dismiss]; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } -(void)viewWillLayoutSubviews { self.view.frame=[UIScreen mainScreen].bounds; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { KDPTodayListCell *listC=[tableView dequeueReusableCellWithIdentifier:@"today"]; if (!listC) { listC=[[KDPTodayListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"today"]; listC.selectionStyle=UITableViewCellSelectionStyleNone; } listC.model=self.dataArray[indexPath.row]; if ([self.todayStr isEqualToString:@"实时订单"]) { listC.timeLabel.hidden=NO; listC.numL.hidden=YES; }else{ listC.timeLabel.hidden=YES; listC.numL.hidden=NO; } return listC; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 116; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{ return [UIImage imageNamed:@"no_order"]; } - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{ return YES; } - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{ return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}]; } - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{ return 30; } -(UITableView *)tableView { if (!_tableView) { _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-40)]; _tableView.separatorStyle=UITableViewCellSeparatorStyleNone; _tableView.delegate=self; _tableView.dataSource=self; if (@available(iOS 11.0, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { self.automaticallyAdjustsScrollViewInsets = NO; } _tableView.showsVerticalScrollIndicator=NO; _tableView.showsHorizontalScrollIndicator=NO; } return _tableView; } -(NSMutableArray *)dataArray { if (!_dataArray) { _dataArray =[NSMutableArray array]; } return _dataArray; } -(void)addtablevHeadvew { UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)]; self.tableView.tableHeaderView =backv; numLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 35)]; numLabel.textColor=[UIColor colorWithHexString:@"5b5b5b"]; numLabel.font=[UIFont systemFontOfSize:13]; [backv addSubview:numLabel]; if ([self.todayStr isEqualToString:@"实时订单"]) { numLabel.text=@"共--单"; }else if([self.todayStr isEqualToString:@"热销商品"]){ numLabel.text=@"共--件商品"; } } -(void)addChart { UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 409)]; self.tableView.tableHeaderView=backv; backv.backgroundColor=[UIColor whiteColor]; chartView =[[SSWLineChartView alloc]initWithChartType:SSWChartsTypeBar]; chartView.layer.cornerRadius=3; chartView.layer.masksToBounds=YES; chartView.backgroundColor = [UIColor whiteColor]; chartView.unit = @"单"; chartView.showEachYValus=NO; chartView.yScaleValue=100; chartView.frame=CGRectMake(10, 20, SCREEN_WIDTH-20, 329); __weak KDPTodayListViewController *weakSelf = self; chartView.changeBtn = ^(UIButton *button) { if (button.tag == 1001) { timeHourType =@"1"; }else{ timeHourType = @"0"; } [weakSelf saleTotlaData]; }; [backv addSubview:chartView]; } @end