// // KDPEarnTableHeadView.m // KuDianProject // // Created by 学丽 on 2019/7/4. // Copyright © 2019 KDP. All rights reserved. // #import "KDPEarnTableHeadView.h" #import "SSWlineIncomeChartView.h" @implementation KDPEarnTableHeadView -(instancetype)initWithFrame:(CGRect)frame { self =[super initWithFrame:frame]; if (self) { self.backgroundColor=[UIColor clearColor]; [self addOrderView]; [self addCurveView]; self.userInteractionEnabled=YES; } return self; } -(void)addCurveView { UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(10, 80, SCREEN_WIDTH-20, 300)]; backv.backgroundColor=[UIColor whiteColor]; backv.layer.cornerRadius=6; backv.layer.masksToBounds=YES; [self addSubview:backv]; [self addChangeView]; self.chartView.frame=CGRectMake(0, 60, backv.width, 240); self.chartView.userInteractionEnabled=YES; backv.userInteractionEnabled=YES; [backv addSubview:self.chartView]; } #pragma mark---添加切换按钮 -(void)addChangeView { UIView *backV=[[UIView alloc]initWithFrame:CGRectMake(10, 80, self.width-20, 60)]; [self addSubview:backV]; self.chartType=@"0"; self.chartcate=@"0"; [self requestChartData]; UIButton *volumeButton =[[UIButton alloc]initWithFrame:CGRectMake(14, 15, 70, 30)]; [volumeButton setTitle:@"销量走势" forState:UIControlStateNormal]; self.volumeButton =volumeButton; [volumeButton addTarget:self action:@selector(volumeClickButton) forControlEvents:UIControlEventTouchUpInside]; [volumeButton setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal]; volumeButton.titleLabel.font=[UIFont systemFontOfSize:16]; [backV addSubview:volumeButton]; UIView *LineV =[[UIView alloc]initWithFrame:CGRectMake(volumeButton.right+5, 25, 1, 10)]; LineV.backgroundColor=[UIColor colorWithHexString:@"#999999"]; [backV addSubview:LineV]; UIButton *incomeButton =[[UIButton alloc]initWithFrame:CGRectMake(LineV.right+5, 15, 70, 30)]; [incomeButton addTarget:self action:@selector(incomeClickButton) forControlEvents:UIControlEventTouchUpInside]; [incomeButton setTitle:@"收益走势" forState:UIControlStateNormal]; [incomeButton setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal]; self.incomeButton=incomeButton; incomeButton.titleLabel.font=[UIFont systemFontOfSize:16]; [backV addSubview:incomeButton]; } -(SSWlineIncomeChartView *)chartView { if (!_chartView) { _chartView=[[SSWlineIncomeChartView alloc]initWithChartType:SSWChartsTypeBar]; _chartView.unit=@"单"; _chartView.yScaleValue=100; _chartView.showEachYValus=NO; __weak KDPEarnTableHeadView *headview=self; _chartView.changeMineBtn = ^(UIButton * _Nonnull button) { if (button.tag == 1001) {//昨天 headview.chartType=@"1"; }else if (button.tag == 2001){//本月 headview.chartType=@"2"; }else{//今天 headview.chartType=@"0"; } [headview requestChartData]; }; } return _chartView; } -(void)addOrderView { UIView *backv=[[UIView alloc]initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 70)]; backv.backgroundColor=[UIColor whiteColor]; backv.layer.cornerRadius=6; backv.layer.masksToBounds=YES; [self addSubview:backv]; self.balanceButton =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, backv.width/2, backv.height)]; [self.balanceButton setImage:[UIImage imageNamed:@"account_balance_icon"] forState:UIControlStateNormal]; [self.balanceButton setTitle:@"账号余额" forState:UIControlStateNormal]; [self.balanceButton setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal]; self.balanceButton.adjustsImageWhenHighlighted=NO; [self.balanceButton addTarget:self action:@selector(balanclickBtn) forControlEvents:UIControlEventTouchUpInside]; self.balanceButton.titleLabel.font=[UIFont systemFontOfSize:15]; [self.balanceButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)]; [backv addSubview:self.balanceButton]; self.orderButton =[[UIButton alloc]initWithFrame:CGRectMake(backv.width/2, 0, backv.width/2, backv.height)]; [self.orderButton setImage:[UIImage imageNamed:@"order_detail"] forState:UIControlStateNormal]; [self.orderButton setTitle:@"订单明细" forState:UIControlStateNormal]; [self.orderButton setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal]; [self.orderButton addTarget:self action:@selector(orderDetailClickBtn) forControlEvents:UIControlEventTouchUpInside]; self.orderButton.titleLabel.font=[UIFont systemFontOfSize:15]; [self.orderButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)]; [backv addSubview:self.orderButton]; UIView *lineV=[[UIView alloc]initWithFrame:CGRectMake(backv.width/2-0.5, 10, 1, backv.height-20)]; lineV.backgroundColor=[UIColor colorWithHexString:LineColor]; [backv addSubview:lineV]; } #pragma makr---销量走势 -(void)volumeClickButton { [self.volumeButton setTitleColor:[UIColor colorWithHexString:fontColor] forState:UIControlStateNormal]; [self.incomeButton setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal]; self.chartcate=@"0"; [self requestChartData]; } #pragma mark---收益走势 -(void)incomeClickButton { [self.incomeButton setTitleColor:[UIColor colorWithHexString:fontColor] forState:UIControlStateNormal]; [self.volumeButton setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal]; self.chartcate=@"1"; [self requestChartData]; } #pragma mark---账号余额 -(void)balanclickBtn { if (self.accountBlock) { self.accountBlock(); } } #pragma mark---订单明细 -(void)orderDetailClickBtn { if (self.orderBlock) { self.orderBlock(); } } -(void)requestChartData { [LoadingView show]; NSDictionary *param=@{@"type":self.chartType,@"cate":self.chartcate}; [KDPNetworkRequestHTTP postURL:ChartAllMoneyURL params:param success:^(id _Nonnull json) { [LoadingView dismiss]; NSArray *arrya =json; NSMutableArray *xArr=[NSMutableArray array]; NSMutableArray *yArr=[NSMutableArray array]; for (NSDictionary *dic in arrya) { [yArr addObject:dic[@"num"]]; [xArr addObject:dic[@"time"]]; } self.chartView.barWidth=SCREEN_WIDTH/xArr.count-80/xArr.count; self.chartView.xValuesArr=xArr; self.chartView.yValuesArr=yArr; } failure:^(NSError * _Nonnull error) { [LoadingView dismiss]; }]; } @end