| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- //
- // StatisticsDataAnalysisDetailVC.m
- // IBOSS-HJ
- //
- // Created by 关宏厚 on 2020/12/30.
- // Copyright © 2020 elongtian. All rights reserved.
- //
- #import "StatisticsDataAnalysisDetailVC.h"
- #import "Util.h"
- #import "IntAxisValueFormatter.h"
- @interface StatisticsDataAnalysisDetailVC ()
- {
- UIScrollView *scroll;
- UIView *content;
- UIView *detailContent;
- UILabel *lblDepartment;
- UILabel *lblTotalAmount;
- NSMutableArray *feeItemArray;
- NSMutableArray *yArray;
- CustomBorderView *detailBorderV;
- }
- @end
- @implementation StatisticsDataAnalysisDetailVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- feeItemArray=[[NSMutableArray alloc]init];
- yArray=[[NSMutableArray alloc]init];
- [self loadNavStyle];
- [self initUI];
- [self loadFeesDetailData];
-
- }
- /**
- 导航按钮样式
- */
- -(void)loadNavStyle
- {
- self.navigationItem.title=@"费用情况明细";
-
- //返回
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- }
- -(void)initUI
- {
- int rowHeight=50;
- content=[UIView new];
- content.frame=CGRectMake(0, 0,Screen_Width,0);
-
- detailContent=[UIView new];
- detailContent.frame=CGRectMake(10, 10,Screen_Width,0);
- detailContent.backgroundColor=[UIColor whiteColor];
- scroll=[[UIScrollView alloc]init];
- scroll.frame=CGRectMake(0,0, Screen_Width, Screen_Height);
- [self.view addSubview:scroll];
- [scroll addSubview:content];
- [content addSubview:detailContent];
-
- UIView *detailTitleView = [[UIView alloc]init];
-
- detailTitleView.frame = CGRectMake(0,0 ,Screen_Width, 45);
-
- UIView *detailImgView=[UIImageView new];
- detailImgView.frame=CGRectMake(10, 10,10 , 25);
- [detailImgView setBackgroundColor:[UIColor hexColor:LIGHT_BROWN]];
- [detailTitleView addSubview:detailImgView];
-
- UILabel *titleDetail = [[UILabel alloc]init];
- titleDetail.frame = CGRectMake(CGRectGetMaxX(detailImgView.frame)+10, 10, 100, 25);
- titleDetail.text = @"详细";
- titleDetail.textColor = [UIColor blackColor];
- titleDetail.font = [UIFont systemFontOfSize:NoDataFontOfSize];
- [detailTitleView addSubview:titleDetail];
- [detailContent addSubview:detailTitleView];
-
- UIView *separator=[UIView new];
- separator.frame=CGRectMake(0,detailTitleView.frame.size.height-1, detailTitleView.frame.size.width-20, 0.5);
- [separator setBackgroundColor:[UIColor lightGrayColor]];
- [detailTitleView addSubview:separator ];
-
- UIView *departmentView= [[UIView alloc]init];
- departmentView.frame = CGRectMake(0,CGRectGetMaxY(detailTitleView.frame)+15, Screen_Width, 25);
- lblDepartment= [[UILabel alloc]init];
- lblDepartment.frame = CGRectMake(0, 0,Screen_Width, 25);
- lblDepartment.textAlignment=NSTextAlignmentCenter;
- lblDepartment.textColor = [UIColor blackColor];
- lblDepartment.font = [UIFont systemFontOfSize:NoDataFontOfSize];
- [departmentView addSubview:lblDepartment];
- [detailContent addSubview:departmentView];
-
- UIView *totalView= [[UIView alloc]init];
- totalView.frame = CGRectMake(0,CGRectGetMaxY(departmentView.frame)+15, Screen_Width, 25);
- lblTotalAmount= [[UILabel alloc]init];
- lblTotalAmount.frame = CGRectMake(0, 0,Screen_Width, 25);
- lblTotalAmount.textAlignment=NSTextAlignmentCenter;
- lblTotalAmount.textColor = [UIColor blackColor];
- lblTotalAmount.font = [UIFont systemFontOfSize:NoDataFontOfSize];
- [totalView addSubview:lblTotalAmount];
- [detailContent addSubview:totalView];
-
- detailBorderV=[CustomBorderView new];
- detailBorderV.frame=CGRectMake(5, CGRectGetMaxY(totalView.frame)+15,Screen_Width-30, 350);
- [detailBorderV setBackgroundColor:[UIColor whiteColor]];
- [detailBorderV drawBoardLine:1 cornerRadius:2 color:[UIColor hexColor:@"D5CDCD"]];
- [detailContent addSubview:detailBorderV];
-
- _singleChartView=[[HorizontalBarChartView alloc]init];
- _singleChartView.frame=CGRectMake(5, 5,detailBorderV.frame.size.width-10, 340);
- [detailBorderV addSubview:_singleChartView];
-
- detailContent.frame=CGRectMake(10, 10,Screen_Width-20,CGRectGetMaxY(detailBorderV.frame)+10);
-
- detailContent.layer.cornerRadius=CornerRadius;
-
- CGFloat height=CGRectGetMaxY(detailContent.frame);
- content.frame=CGRectMake(0, 0,Screen_Width,height);
- scroll.contentSize = CGSizeMake(self.view.frame.size.width, height+rectStatusHeight+rectNavHeight+100);
-
- }
- -(void)loadFeesDetailData
- {
- NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL];
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetAccountFeeDetailReportDataIphone" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:_accountMonth forKey:@"AccountMonth"];
- [dict setObject:_typeId forKey:@"TypeID"];
- [dict setObject:_organizationId forKey:@"OrganizationID"];
- _feesDetailDownManager = [[ASIDownManager alloc] init];
- _feesDetailDownManager.delegate = self;
- _feesDetailDownManager.onRequestSuccess = @selector(onFeesDetailLoadFinish:);
- _feesDetailDownManager.onRequestFail = @selector(onFeesDetailLoadFail:);
- [_feesDetailDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
- }
- /**
- 销售利润加载完成
- */
- - (void)onFeesDetailLoadFinish:(ASIDownManager *)sender {
- // 取消进度条
-
- // 服务器返回数据
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- [self stopLoading];
-
- // 服务器返回数据状态值正确
- if (iStatus == 0)
- {
- NSDictionary *result=(NSDictionary*)resultModel.result;
- NSArray *resultArray= [result objectForKey:@"Table"];
- if(resultArray!=nil&&resultArray.count>0)
- {
- double totalFeeSum=0;
- NSDictionary *dic=[resultArray objectAtIndex:0];
- NSString *organizationName=[dic objectForKey:@"OrganizationName"];
- for(int i=0;i<resultArray.count;i++)
- {
- NSDictionary *dic=[resultArray objectAtIndex:i];
- double confirmFeeSum= [[dic objectForKey:@"ConfirmFeeSum"]doubleValue];
- totalFeeSum+=confirmFeeSum;
- NSString *confirmFeeSumStr=[NSString stringWithFormat:@"%.2f",confirmFeeSum];
- NSString *feeItemName=[dic objectForKey:@"FeeItemName"];
- [feeItemArray addObject:feeItemName];
- [yArray addObject:confirmFeeSumStr];
-
- }
- NSString *totalFeeSumStr=[NSString stringWithFormat:@"%.2f",totalFeeSum];
- totalFeeSumStr=[Util thousandSeparatorFormat:totalFeeSumStr];
- lblDepartment.text=[NSString stringWithFormat:@"%@%@",organizationName,@"-费用明细"];
- lblTotalAmount.text=[NSString stringWithFormat:@"%@%@",@"总额:",totalFeeSumStr];
- IntAxisValueFormatter *formatter=[[IntAxisValueFormatter alloc]init];
- [formatter setTitle:feeItemArray];
- double maximumValue=[self getYAxisMaximumValue:yArray];
- double minimumValue=[self getYAxisMinimumValue:yArray];
- [self drawSingleBarchart:yArray chartView:_singleChartView axisValueFormatter:formatter yAxisLabelCount:feeItemArray.count maximumValue:maximumValue minimumValue:minimumValue];
-
- }
-
- // 服务器返回数据状态值异常
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- }
- else {
-
- [self showAlertViewText:message];
- }
- }
- }
- -(void)onFeesDetailLoadFail:(ASIDownManager *)sender {
- [self stopLoading];
- [self showAlertViewText:@"网络连接异常"];
- }
- /**
- 获取y轴最大值
- */
- -(double)getYAxisMaximumValue:(NSMutableArray*) yValueArray
- {
- double maximumValue=[[yValueArray objectAtIndex:0]doubleValue];
- for(int i=1;i<yValueArray.count;i++)
- {
- double yValue=[[yValueArray objectAtIndex:i]doubleValue];
- if(yValue>maximumValue)
- {
- maximumValue=yValue;
- }
- }
-
- return maximumValue;
- }
- /**
- 获取y轴最小值
- */
- -(double)getYAxisMinimumValue:(NSMutableArray*) yValueArray
- {
- double minimumValue=[[yValueArray objectAtIndex:0]doubleValue];
- for(int i=1;i<yValueArray.count;i++)
- {
- double yValue=[[yValueArray objectAtIndex:i]doubleValue];
- if(yValue<minimumValue)
- {
- minimumValue=yValue;
- }
- }
-
- return minimumValue;
- }
- -(void)drawSingleBarchart:(NSMutableArray*)barchartArray chartView:(HorizontalBarChartView*) barchartView
- axisValueFormatter:(id<ChartAxisValueFormatter>)formatter yAxisLabelCount:(NSInteger)count maximumValue:(double)maximumValue
- minimumValue:(double)minimumValue
- {
-
- barchartView.chartDescription.enabled = NO;
-
- barchartView.drawGridBackgroundEnabled = NO;
- barchartView.extraBottomOffset=20;
- barchartView.dragEnabled = NO;
- [barchartView setScaleEnabled:NO];
- barchartView.pinchZoomEnabled = NO;
- barchartView.delegate = self;
-
- barchartView.drawBarShadowEnabled = NO;
- barchartView.drawValueAboveBarEnabled = YES;
-
- // barchartView.maxVisibleCount = 60;
- barchartView.legend.enabled=NO;
-
- ChartXAxis *xAxis = barchartView.xAxis;
- xAxis.labelPosition = XAxisLabelPositionBottom;
- xAxis.labelFont = [UIFont systemFontOfSize:10.f];
- xAxis.drawAxisLineEnabled = NO;
- xAxis.granularity=1;
- xAxis.drawGridLinesEnabled = NO;
- xAxis.valueFormatter=formatter;
-
- ChartYAxis *leftAxis = barchartView.leftAxis;
- leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
- leftAxis.drawAxisLineEnabled =NO;
- leftAxis.granularity=1;
- leftAxis.drawGridLinesEnabled = NO;
- leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
- if(minimumValue<0)
- {
- leftAxis.axisMinimum = minimumValue;
- }
- else
- {
- leftAxis.axisMinimum = 0;
- }
- leftAxis.axisMaximum=maximumValue+100;
-
- ChartYAxis *rightAxis = barchartView.rightAxis;
- rightAxis.enabled = YES;
- rightAxis.labelFont = [UIFont systemFontOfSize:10.f];
- rightAxis.drawAxisLineEnabled = YES;
- rightAxis.drawGridLinesEnabled = NO;
-
-
-
- if(minimumValue<0)
- {
- rightAxis.axisMinimum = minimumValue;
- }
- else
- {
- rightAxis.axisMinimum = 0;
- }
- rightAxis.axisMaximum=maximumValue+100;
- rightAxis.granularity=1;
- rightAxis.drawGridLinesEnabled = YES;
-
- // ChartLegend *l = _singleChartView.legend;
- // l.horizontalAlignment = ChartLegendHorizontalAlignmentLeft;
- // l.verticalAlignment = ChartLegendVerticalAlignmentBottom;
- // l.orientation = ChartLegendOrientationHorizontal;
- // l.drawInside = NO;
- // l.form = ChartLegendFormSquare;
- // l.formSize = 8.0;
- // l.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:11.f];
- // l.xEntrySpace = 4.0;
- barchartView.fitBars = YES;
-
-
- double barWidth = 0.6;
- NSMutableArray *yVals = [[NSMutableArray alloc] init];
-
- for (int i = 0; i < barchartArray.count; i++)
- {
-
- [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[barchartArray objectAtIndex:i]doubleValue] icon: [UIImage imageNamed:@"icon"]]];
- }
-
- BarChartDataSet *set1 = nil;
- if (barchartView.data.dataSetCount > 0)
- {
- set1 = (BarChartDataSet *)barchartView.data.dataSets[0];
- [set1 replaceEntries:yVals];
- [barchartView.data notifyDataChanged];
- [barchartView notifyDataSetChanged];
- }
- else
- {
- set1 = [[BarChartDataSet alloc] initWithEntries:yVals label:@"DataSet"];
- [set1 setColor: [UIColor colorWithRed:70/255.0f green:116/255.0f blue:193/255.0f alpha:1]];
- set1.drawIconsEnabled = NO;
-
- NSMutableArray *dataSets = [[NSMutableArray alloc] init];
- [dataSets addObject:set1];
-
- BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];
- [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
- data.barWidth = barWidth;
-
- barchartView.data = data;
- }
-
- }
- @end
|