123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
- {
- 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
|