酷店

KDPEarnTableHeadView.m 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // KDPEarnTableHeadView.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/4.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPEarnTableHeadView.h"
  9. #import "SSWlineIncomeChartView.h"
  10. @implementation KDPEarnTableHeadView
  11. -(instancetype)initWithFrame:(CGRect)frame
  12. {
  13. self =[super initWithFrame:frame];
  14. if (self) {
  15. self.backgroundColor=[UIColor clearColor];
  16. [self addOrderView];
  17. [self addCurveView];
  18. self.userInteractionEnabled=YES;
  19. }
  20. return self;
  21. }
  22. -(void)addCurveView
  23. {
  24. UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(10, 80, SCREEN_WIDTH-20, 300)];
  25. backv.backgroundColor=[UIColor whiteColor];
  26. backv.layer.cornerRadius=6;
  27. backv.layer.masksToBounds=YES;
  28. [self addSubview:backv];
  29. [self addChangeView];
  30. self.chartView.frame=CGRectMake(0, 60, backv.width, 240);
  31. self.chartView.userInteractionEnabled=YES;
  32. backv.userInteractionEnabled=YES;
  33. [backv addSubview:self.chartView];
  34. }
  35. #pragma mark---添加切换按钮
  36. -(void)addChangeView
  37. {
  38. UIView *backV=[[UIView alloc]initWithFrame:CGRectMake(10, 80, self.width-20, 60)];
  39. [self addSubview:backV];
  40. self.chartType=@"0";
  41. self.chartcate=@"0";
  42. [self requestChartData];
  43. UIButton *volumeButton =[[UIButton alloc]initWithFrame:CGRectMake(14, 15, 70, 30)];
  44. [volumeButton setTitle:@"销量走势" forState:UIControlStateNormal];
  45. self.volumeButton =volumeButton;
  46. [volumeButton addTarget:self action:@selector(volumeClickButton) forControlEvents:UIControlEventTouchUpInside];
  47. [volumeButton setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
  48. volumeButton.titleLabel.font=[UIFont systemFontOfSize:16];
  49. [backV addSubview:volumeButton];
  50. UIView *LineV =[[UIView alloc]initWithFrame:CGRectMake(volumeButton.right+5, 25, 1, 10)];
  51. LineV.backgroundColor=[UIColor colorWithHexString:@"#999999"];
  52. [backV addSubview:LineV];
  53. UIButton *incomeButton =[[UIButton alloc]initWithFrame:CGRectMake(LineV.right+5, 15, 70, 30)];
  54. [incomeButton addTarget:self action:@selector(incomeClickButton) forControlEvents:UIControlEventTouchUpInside];
  55. [incomeButton setTitle:@"收益走势" forState:UIControlStateNormal];
  56. [incomeButton setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  57. self.incomeButton=incomeButton;
  58. incomeButton.titleLabel.font=[UIFont systemFontOfSize:16];
  59. [backV addSubview:incomeButton];
  60. }
  61. -(SSWlineIncomeChartView *)chartView
  62. {
  63. if (!_chartView) {
  64. _chartView=[[SSWlineIncomeChartView alloc]initWithChartType:SSWChartsTypeBar];
  65. _chartView.unit=@"单";
  66. _chartView.yScaleValue=100;
  67. _chartView.showEachYValus=NO;
  68. __weak KDPEarnTableHeadView *headview=self;
  69. _chartView.changeMineBtn = ^(UIButton * _Nonnull button) {
  70. if (button.tag == 1001) {//昨天
  71. headview.chartType=@"1";
  72. }else if (button.tag == 2001){//本月
  73. headview.chartType=@"2";
  74. }else{//今天
  75. headview.chartType=@"0";
  76. }
  77. [headview requestChartData];
  78. };
  79. }
  80. return _chartView;
  81. }
  82. -(void)addOrderView
  83. {
  84. UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 70)];
  85. backv.backgroundColor=[UIColor whiteColor];
  86. backv.layer.cornerRadius=6;
  87. backv.layer.masksToBounds=YES;
  88. [self addSubview:backv];
  89. self.balanceButton =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, backv.width/2, backv.height)];
  90. [self.balanceButton setImage:[UIImage imageNamed:@"account_balance_icon"] forState:UIControlStateNormal];
  91. [self.balanceButton setTitle:@"账户余额" forState:UIControlStateNormal];
  92. [self.balanceButton setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
  93. self.balanceButton.adjustsImageWhenHighlighted=NO;
  94. [self.balanceButton addTarget:self action:@selector(balanclickBtn) forControlEvents:UIControlEventTouchUpInside];
  95. self.balanceButton.titleLabel.font=[UIFont systemFontOfSize:15];
  96. [self.balanceButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
  97. [backv addSubview:self.balanceButton];
  98. self.orderButton =[[UIButton alloc]initWithFrame:CGRectMake(backv.width/2, 0, backv.width/2, backv.height)];
  99. [self.orderButton setImage:[UIImage imageNamed:@"order_detail"] forState:UIControlStateNormal];
  100. [self.orderButton setTitle:@"订单明细" forState:UIControlStateNormal];
  101. [self.orderButton setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
  102. [self.orderButton addTarget:self action:@selector(orderDetailClickBtn) forControlEvents:UIControlEventTouchUpInside];
  103. self.orderButton.titleLabel.font=[UIFont systemFontOfSize:15];
  104. [self.orderButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
  105. [backv addSubview:self.orderButton];
  106. UIView *lineV=[[UIView alloc]initWithFrame:CGRectMake(backv.width/2-0.5, 10, 1, backv.height-20)];
  107. lineV.backgroundColor=[UIColor colorWithHexString:LineColor];
  108. [backv addSubview:lineV];
  109. }
  110. #pragma makr---销量走势
  111. -(void)volumeClickButton
  112. {
  113. [self.volumeButton setTitleColor:[UIColor colorWithHexString:fontColor] forState:UIControlStateNormal];
  114. [self.incomeButton setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  115. self.chartcate=@"0";
  116. [self requestChartData];
  117. }
  118. #pragma mark---收益走势
  119. -(void)incomeClickButton
  120. {
  121. [self.incomeButton setTitleColor:[UIColor colorWithHexString:fontColor] forState:UIControlStateNormal];
  122. [self.volumeButton setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  123. self.chartcate=@"1";
  124. [self requestChartData];
  125. }
  126. #pragma mark---账号余额
  127. -(void)balanclickBtn
  128. {
  129. if (self.accountBlock) {
  130. self.accountBlock();
  131. }
  132. }
  133. #pragma mark---订单明细
  134. -(void)orderDetailClickBtn
  135. {
  136. if (self.orderBlock) {
  137. self.orderBlock();
  138. }
  139. }
  140. -(void)requestChartData
  141. {
  142. [LoadingView show];
  143. NSDictionary *param=@{@"type":self.chartType,@"cate":self.chartcate};
  144. [KDPNetworkRequestHTTP postURL:ChartAllMoneyURL params:param success:^(id _Nonnull json) {
  145. [LoadingView dismiss];
  146. NSArray *arrya =json;
  147. NSMutableArray *xArr=[NSMutableArray array];
  148. NSMutableArray *yArr=[NSMutableArray array];
  149. for (NSDictionary *dic in arrya) {
  150. [yArr addObject:dic[@"num"]];
  151. [xArr addObject:dic[@"time"]];
  152. }
  153. if (xArr.count > 7) {
  154. self.chartView.barWidth=50;
  155. }else{
  156. self.chartView.barWidth=SCREEN_WIDTH/xArr.count-80/xArr.count;
  157. }
  158. self.chartView.xValuesArr=xArr;
  159. self.chartView.yValuesArr=yArr;
  160. } failure:^(NSError * _Nonnull error) {
  161. [LoadingView dismiss];
  162. }];
  163. }
  164. @end