酷店

KDPTodayListViewController.m 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // KDPTodayListViewController.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/9.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPTodayListViewController.h"
  9. #import "KDPTodayListCell.h"
  10. #import "SSWLineChartView.h"
  11. @interface KDPTodayListViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  12. {
  13. UILabel *numLabel;
  14. NSTimer *timer_add;
  15. SSWLineChartView *chartView;
  16. NSString *timeHourType;
  17. }
  18. @property(nonatomic,strong)UITableView *tableView;
  19. @property(nonatomic,copy)NSString *last_order_id;
  20. @property(nonatomic,copy)NSString *is_new;
  21. @property(nonatomic,strong)NSMutableArray *dataArray;
  22. @end
  23. @implementation KDPTodayListViewController
  24. -(void)viewWillDisappear:(BOOL)animated
  25. {
  26. [super viewWillDisappear:animated];
  27. [timer_add invalidate];
  28. }
  29. -(void)viewWillAppear:(BOOL)animated
  30. {
  31. [super viewWillAppear:animated];
  32. if ([self.todayStr isEqualToString:@"实时订单"]) {
  33. timer_add = [NSTimer timerWithTimeInterval:30 target:self selector:@selector(timerClickAction) userInfo:nil repeats:YES];
  34. }
  35. }
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. self.navBar.hidden=YES;
  39. self.is_new=@"1";
  40. self.last_order_id=@"";
  41. self.view.backgroundColor=[UIColor whiteColor];
  42. [self.view addSubview:self.tableView];
  43. if (![self.todayStr isEqualToString:@"销量走势"]) {
  44. _tableView.emptyDataSetDelegate = self;
  45. _tableView.emptyDataSetSource = self;
  46. if ([self.todayStr isEqualToString:@"实时订单"]) {
  47. [self timerClickAction];
  48. [self orderlistDAta];
  49. }else{//热销商品
  50. [self hotGoodList];
  51. }
  52. [self addtablevHeadvew];
  53. }else{
  54. timeHourType=@"1";//最近1小时
  55. [self addChart];
  56. [self saleTotlaData];
  57. }
  58. }
  59. #pragma mark---销量统计
  60. -(void)saleTotlaData
  61. {
  62. [LoadingView show];
  63. [KDPNetworkRequestHTTP postURL:SaleStatisticsURL params:@{@"type":timeHourType} success:^(id _Nonnull json) {
  64. NSArray *jsonArr =(NSArray *)json;
  65. NSMutableArray *xArray=[NSMutableArray array];
  66. NSMutableArray *valueArray =[NSMutableArray array];
  67. for (NSDictionary *dic in jsonArr) {
  68. [xArray addObject:dic[@"time"]];
  69. [valueArray addObject:dic[@"num"]];
  70. }
  71. chartView.xValuesArr=[xArray mutableCopy];
  72. chartView.yValuesArr=[valueArray mutableCopy];
  73. [LoadingView dismiss];
  74. } failure:^(NSError * _Nonnull error) {
  75. [LoadingView dismiss];
  76. }];
  77. }
  78. #pragma mark---热销商品
  79. -(void)hotGoodList
  80. {
  81. [LoadingView show];
  82. [KDPNetworkRequestHTTP postURL:hotGoodListURL params:nil success:^(id _Nonnull json) {
  83. NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]];
  84. [self.dataArray addObjectsFromArray:array];
  85. numLabel.text=[NSString stringWithFormat:@"共%@件商品",json[@"count"]];
  86. [self.tableView reloadData];
  87. [LoadingView dismiss];
  88. } failure:^(NSError * _Nonnull error) {
  89. [LoadingView dismiss];
  90. }];
  91. }
  92. #pragma mark---更新
  93. -(void)timerClickAction
  94. {
  95. self.is_new =@"1";
  96. if (self.dataArray.count>0) {
  97. KDPGoodsModel *model=self.dataArray.firstObject;
  98. self.last_order_id=model.Id;
  99. }
  100. [self orderlistDAta];
  101. }
  102. #pragma mark---实时订单
  103. -(void)orderlistDAta
  104. {
  105. NSDictionary *para=@{@"is_new":self.is_new,@"last_order_id":self.last_order_id};
  106. [LoadingView show];
  107. [KDPNetworkRequestHTTP postURL:todayOrderURL params:para success:^(id _Nonnull json) {
  108. if (self.is_new.integerValue == 1) {
  109. numLabel.text=[NSString stringWithFormat:@"共%@单",json[@"order_count"]];
  110. }
  111. NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"order_list"]];
  112. [self.dataArray addObjectsFromArray:array];
  113. [self.tableView reloadData];
  114. [self.tableView.mj_footer endRefreshing];
  115. [self.tableView.mj_header endRefreshing];
  116. [LoadingView dismiss];
  117. } failure:^(NSError * _Nonnull error) {
  118. [LoadingView dismiss];
  119. }];
  120. }
  121. -(void)viewWillLayoutSubviews
  122. {
  123. self.view.frame=[UIScreen mainScreen].bounds;
  124. }
  125. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  126. {
  127. KDPTodayListCell *listC=[tableView dequeueReusableCellWithIdentifier:@"today"];
  128. if (!listC) {
  129. listC=[[KDPTodayListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"today"];
  130. listC.selectionStyle=UITableViewCellSelectionStyleNone;
  131. }
  132. listC.model=self.dataArray[indexPath.row];
  133. if ([self.todayStr isEqualToString:@"实时订单"]) {
  134. listC.timeLabel.hidden=NO;
  135. listC.numL.hidden=YES;
  136. }else{
  137. listC.timeLabel.hidden=YES;
  138. listC.numL.hidden=NO;
  139. }
  140. return listC;
  141. }
  142. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  143. {
  144. return self.dataArray.count;
  145. }
  146. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  147. {
  148. }
  149. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  150. {
  151. return 116;
  152. }
  153. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  154. {
  155. return 1;
  156. }
  157. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  158. return [UIImage imageNamed:@"no_order"];
  159. }
  160. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  161. return YES;
  162. }
  163. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  164. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  165. }
  166. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  167. return 30;
  168. }
  169. -(UITableView *)tableView
  170. {
  171. if (!_tableView) {
  172. _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight-40)];
  173. _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  174. _tableView.delegate=self;
  175. _tableView.dataSource=self;
  176. if (@available(iOS 11.0, *)) {
  177. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  178. } else {
  179. self.automaticallyAdjustsScrollViewInsets = NO;
  180. }
  181. _tableView.showsVerticalScrollIndicator=NO;
  182. _tableView.showsHorizontalScrollIndicator=NO;
  183. }
  184. return _tableView;
  185. }
  186. -(NSMutableArray *)dataArray
  187. {
  188. if (!_dataArray) {
  189. _dataArray =[NSMutableArray array];
  190. }
  191. return _dataArray;
  192. }
  193. -(void)addtablevHeadvew
  194. {
  195. UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
  196. self.tableView.tableHeaderView =backv;
  197. numLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 35)];
  198. numLabel.textColor=[UIColor colorWithHexString:@"5b5b5b"];
  199. numLabel.font=[UIFont systemFontOfSize:13];
  200. [backv addSubview:numLabel];
  201. if ([self.todayStr isEqualToString:@"实时订单"]) {
  202. numLabel.text=@"共--单";
  203. }else if([self.todayStr isEqualToString:@"热销商品"]){
  204. numLabel.text=@"共--件商品";
  205. }
  206. }
  207. -(void)addChart
  208. {
  209. UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 409)];
  210. self.tableView.tableHeaderView=backv;
  211. backv.backgroundColor=[UIColor whiteColor];
  212. chartView =[[SSWLineChartView alloc]initWithChartType:SSWChartsTypeBar];
  213. chartView.layer.cornerRadius=3;
  214. chartView.layer.masksToBounds=YES;
  215. chartView.backgroundColor = [UIColor whiteColor];
  216. chartView.unit = @"单";
  217. chartView.showEachYValus=NO;
  218. chartView.yScaleValue=100;
  219. chartView.frame=CGRectMake(10, 20, SCREEN_WIDTH-20, 329);
  220. __weak KDPTodayListViewController *weakSelf = self;
  221. chartView.changeBtn = ^(UIButton *button) {
  222. if (button.tag == 1001) {
  223. timeHourType =@"1";
  224. }else{
  225. timeHourType = @"0";
  226. }
  227. [weakSelf saleTotlaData];
  228. };
  229. [backv addSubview:chartView];
  230. }
  231. @end