StatisticsDataAnalysisDetailVC.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. //
  2. // StatisticsDataAnalysisDetailVC.m
  3. // IBOSS-HJ
  4. //
  5. // Created by 关宏厚 on 2020/12/30.
  6. // Copyright © 2020 elongtian. All rights reserved.
  7. //
  8. #import "StatisticsDataAnalysisDetailVC.h"
  9. #import "Util.h"
  10. #import "IntAxisValueFormatter.h"
  11. @interface StatisticsDataAnalysisDetailVC ()
  12. {
  13. UIScrollView *scroll;
  14. UIView *content;
  15. UIView *detailContent;
  16. UILabel *lblDepartment;
  17. UILabel *lblTotalAmount;
  18. NSMutableArray *feeItemArray;
  19. NSMutableArray *yArray;
  20. CustomBorderView *detailBorderV;
  21. }
  22. @end
  23. @implementation StatisticsDataAnalysisDetailVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. feeItemArray=[[NSMutableArray alloc]init];
  27. yArray=[[NSMutableArray alloc]init];
  28. [self loadNavStyle];
  29. [self initUI];
  30. [self loadFeesDetailData];
  31. }
  32. /**
  33. 导航按钮样式
  34. */
  35. -(void)loadNavStyle
  36. {
  37. self.navigationItem.title=@"费用情况明细";
  38. //返回
  39. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  40. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  41. forState:UIControlStateNormal];
  42. [button addTarget:self action:@selector(goBack)
  43. forControlEvents:UIControlEventTouchUpInside];
  44. button.frame = CGRectMake(0, 0, 15, 18);
  45. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  46. self.navigationItem.leftBarButtonItem = menuButton;
  47. }
  48. -(void)initUI
  49. {
  50. int rowHeight=50;
  51. content=[UIView new];
  52. content.frame=CGRectMake(0, 0,Screen_Width,0);
  53. detailContent=[UIView new];
  54. detailContent.frame=CGRectMake(10, 10,Screen_Width,0);
  55. detailContent.backgroundColor=[UIColor whiteColor];
  56. scroll=[[UIScrollView alloc]init];
  57. scroll.frame=CGRectMake(0,0, Screen_Width, Screen_Height);
  58. [self.view addSubview:scroll];
  59. [scroll addSubview:content];
  60. [content addSubview:detailContent];
  61. UIView *detailTitleView = [[UIView alloc]init];
  62. detailTitleView.frame = CGRectMake(0,0 ,Screen_Width, 45);
  63. UIView *detailImgView=[UIImageView new];
  64. detailImgView.frame=CGRectMake(10, 10,10 , 25);
  65. [detailImgView setBackgroundColor:[UIColor hexColor:LIGHT_BROWN]];
  66. [detailTitleView addSubview:detailImgView];
  67. UILabel *titleDetail = [[UILabel alloc]init];
  68. titleDetail.frame = CGRectMake(CGRectGetMaxX(detailImgView.frame)+10, 10, 100, 25);
  69. titleDetail.text = @"详细";
  70. titleDetail.textColor = [UIColor blackColor];
  71. titleDetail.font = [UIFont systemFontOfSize:NoDataFontOfSize];
  72. [detailTitleView addSubview:titleDetail];
  73. [detailContent addSubview:detailTitleView];
  74. UIView *separator=[UIView new];
  75. separator.frame=CGRectMake(0,detailTitleView.frame.size.height-1, detailTitleView.frame.size.width-20, 0.5);
  76. [separator setBackgroundColor:[UIColor lightGrayColor]];
  77. [detailTitleView addSubview:separator ];
  78. UIView *departmentView= [[UIView alloc]init];
  79. departmentView.frame = CGRectMake(0,CGRectGetMaxY(detailTitleView.frame)+15, Screen_Width, 25);
  80. lblDepartment= [[UILabel alloc]init];
  81. lblDepartment.frame = CGRectMake(0, 0,Screen_Width, 25);
  82. lblDepartment.textAlignment=NSTextAlignmentCenter;
  83. lblDepartment.textColor = [UIColor blackColor];
  84. lblDepartment.font = [UIFont systemFontOfSize:NoDataFontOfSize];
  85. [departmentView addSubview:lblDepartment];
  86. [detailContent addSubview:departmentView];
  87. UIView *totalView= [[UIView alloc]init];
  88. totalView.frame = CGRectMake(0,CGRectGetMaxY(departmentView.frame)+15, Screen_Width, 25);
  89. lblTotalAmount= [[UILabel alloc]init];
  90. lblTotalAmount.frame = CGRectMake(0, 0,Screen_Width, 25);
  91. lblTotalAmount.textAlignment=NSTextAlignmentCenter;
  92. lblTotalAmount.textColor = [UIColor blackColor];
  93. lblTotalAmount.font = [UIFont systemFontOfSize:NoDataFontOfSize];
  94. [totalView addSubview:lblTotalAmount];
  95. [detailContent addSubview:totalView];
  96. detailBorderV=[CustomBorderView new];
  97. detailBorderV.frame=CGRectMake(5, CGRectGetMaxY(totalView.frame)+15,Screen_Width-30, 350);
  98. [detailBorderV setBackgroundColor:[UIColor whiteColor]];
  99. [detailBorderV drawBoardLine:1 cornerRadius:2 color:[UIColor hexColor:@"D5CDCD"]];
  100. [detailContent addSubview:detailBorderV];
  101. _singleChartView=[[HorizontalBarChartView alloc]init];
  102. _singleChartView.frame=CGRectMake(5, 5,detailBorderV.frame.size.width-10, 340);
  103. [detailBorderV addSubview:_singleChartView];
  104. detailContent.frame=CGRectMake(10, 10,Screen_Width-20,CGRectGetMaxY(detailBorderV.frame)+10);
  105. detailContent.layer.cornerRadius=CornerRadius;
  106. CGFloat height=CGRectGetMaxY(detailContent.frame);
  107. content.frame=CGRectMake(0, 0,Screen_Width,height);
  108. scroll.contentSize = CGSizeMake(self.view.frame.size.width, height+rectStatusHeight+rectNavHeight+100);
  109. }
  110. -(void)loadFeesDetailData
  111. {
  112. NSString *urlStr = [NSString stringWithFormat:@"%@", ServerURL];
  113. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  114. [dict setObject:@"GetAccountFeeDetailReportDataIphone" forKey:@"Action"];
  115. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  116. [dict setObject:kkUserCode forKey:@"UserCode"];
  117. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  118. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  119. [dict setObject:_accountMonth forKey:@"AccountMonth"];
  120. [dict setObject:_typeId forKey:@"TypeID"];
  121. [dict setObject:_organizationId forKey:@"OrganizationID"];
  122. _feesDetailDownManager = [[ASIDownManager alloc] init];
  123. _feesDetailDownManager.delegate = self;
  124. _feesDetailDownManager.onRequestSuccess = @selector(onFeesDetailLoadFinish:);
  125. _feesDetailDownManager.onRequestFail = @selector(onFeesDetailLoadFail:);
  126. [_feesDetailDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  127. }
  128. /**
  129. 销售利润加载完成
  130. */
  131. - (void)onFeesDetailLoadFinish:(ASIDownManager *)sender {
  132. // 取消进度条
  133. // 服务器返回数据
  134. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  135. // 服务器返回数据状态值
  136. int iStatus = resultModel.status;
  137. // 服务器返回数据消息
  138. NSString *message = resultModel.message;
  139. [self stopLoading];
  140. // 服务器返回数据状态值正确
  141. if (iStatus == 0)
  142. {
  143. NSDictionary *result=(NSDictionary*)resultModel.result;
  144. NSArray *resultArray= [result objectForKey:@"Table"];
  145. if(resultArray!=nil&&resultArray.count>0)
  146. {
  147. double totalFeeSum=0;
  148. NSDictionary *dic=[resultArray objectAtIndex:0];
  149. NSString *organizationName=[dic objectForKey:@"OrganizationName"];
  150. for(int i=0;i<resultArray.count;i++)
  151. {
  152. NSDictionary *dic=[resultArray objectAtIndex:i];
  153. double confirmFeeSum= [[dic objectForKey:@"ConfirmFeeSum"]doubleValue];
  154. totalFeeSum+=confirmFeeSum;
  155. NSString *confirmFeeSumStr=[NSString stringWithFormat:@"%.2f",confirmFeeSum];
  156. NSString *feeItemName=[dic objectForKey:@"FeeItemName"];
  157. [feeItemArray addObject:feeItemName];
  158. [yArray addObject:confirmFeeSumStr];
  159. }
  160. NSString *totalFeeSumStr=[NSString stringWithFormat:@"%.2f",totalFeeSum];
  161. totalFeeSumStr=[Util thousandSeparatorFormat:totalFeeSumStr];
  162. lblDepartment.text=[NSString stringWithFormat:@"%@%@",organizationName,@"-费用明细"];
  163. lblTotalAmount.text=[NSString stringWithFormat:@"%@%@",@"总额:",totalFeeSumStr];
  164. IntAxisValueFormatter *formatter=[[IntAxisValueFormatter alloc]init];
  165. [formatter setTitle:feeItemArray];
  166. double maximumValue=[self getYAxisMaximumValue:yArray];
  167. double minimumValue=[self getYAxisMinimumValue:yArray];
  168. [self drawSingleBarchart:yArray chartView:_singleChartView axisValueFormatter:formatter yAxisLabelCount:feeItemArray.count maximumValue:maximumValue minimumValue:minimumValue];
  169. }
  170. // 服务器返回数据状态值异常
  171. else if(iStatus == ActionResultStatusAuthError
  172. ||iStatus == ActionResultStatusNoLogin
  173. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  174. [self showReLoginDialog:message];
  175. }
  176. else {
  177. [self showAlertViewText:message];
  178. }
  179. }
  180. }
  181. -(void)onFeesDetailLoadFail:(ASIDownManager *)sender {
  182. [self stopLoading];
  183. [self showAlertViewText:@"网络连接异常"];
  184. }
  185. /**
  186. 获取y轴最大值
  187. */
  188. -(double)getYAxisMaximumValue:(NSMutableArray*) yValueArray
  189. {
  190. double maximumValue=[[yValueArray objectAtIndex:0]doubleValue];
  191. for(int i=1;i<yValueArray.count;i++)
  192. {
  193. double yValue=[[yValueArray objectAtIndex:i]doubleValue];
  194. if(yValue>maximumValue)
  195. {
  196. maximumValue=yValue;
  197. }
  198. }
  199. return maximumValue;
  200. }
  201. /**
  202. 获取y轴最小值
  203. */
  204. -(double)getYAxisMinimumValue:(NSMutableArray*) yValueArray
  205. {
  206. double minimumValue=[[yValueArray objectAtIndex:0]doubleValue];
  207. for(int i=1;i<yValueArray.count;i++)
  208. {
  209. double yValue=[[yValueArray objectAtIndex:i]doubleValue];
  210. if(yValue<minimumValue)
  211. {
  212. minimumValue=yValue;
  213. }
  214. }
  215. return minimumValue;
  216. }
  217. -(void)drawSingleBarchart:(NSMutableArray*)barchartArray chartView:(HorizontalBarChartView*) barchartView
  218. axisValueFormatter:(id<ChartAxisValueFormatter>)formatter yAxisLabelCount:(NSInteger)count maximumValue:(double)maximumValue
  219. minimumValue:(double)minimumValue
  220. {
  221. barchartView.chartDescription.enabled = NO;
  222. barchartView.drawGridBackgroundEnabled = NO;
  223. barchartView.extraBottomOffset=20;
  224. barchartView.dragEnabled = NO;
  225. [barchartView setScaleEnabled:NO];
  226. barchartView.pinchZoomEnabled = NO;
  227. barchartView.delegate = self;
  228. barchartView.drawBarShadowEnabled = NO;
  229. barchartView.drawValueAboveBarEnabled = YES;
  230. // barchartView.maxVisibleCount = 60;
  231. barchartView.legend.enabled=NO;
  232. ChartXAxis *xAxis = barchartView.xAxis;
  233. xAxis.labelPosition = XAxisLabelPositionBottom;
  234. xAxis.labelFont = [UIFont systemFontOfSize:10.f];
  235. xAxis.drawAxisLineEnabled = NO;
  236. xAxis.granularity=1;
  237. xAxis.drawGridLinesEnabled = NO;
  238. xAxis.valueFormatter=formatter;
  239. ChartYAxis *leftAxis = barchartView.leftAxis;
  240. leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
  241. leftAxis.drawAxisLineEnabled =NO;
  242. leftAxis.granularity=1;
  243. leftAxis.drawGridLinesEnabled = NO;
  244. leftAxis.labelFont = [UIFont systemFontOfSize:10.f];
  245. if(minimumValue<0)
  246. {
  247. leftAxis.axisMinimum = minimumValue;
  248. }
  249. else
  250. {
  251. leftAxis.axisMinimum = 0;
  252. }
  253. leftAxis.axisMaximum=maximumValue+100;
  254. ChartYAxis *rightAxis = barchartView.rightAxis;
  255. rightAxis.enabled = YES;
  256. rightAxis.labelFont = [UIFont systemFontOfSize:10.f];
  257. rightAxis.drawAxisLineEnabled = YES;
  258. rightAxis.drawGridLinesEnabled = NO;
  259. if(minimumValue<0)
  260. {
  261. rightAxis.axisMinimum = minimumValue;
  262. }
  263. else
  264. {
  265. rightAxis.axisMinimum = 0;
  266. }
  267. rightAxis.axisMaximum=maximumValue+100;
  268. rightAxis.granularity=1;
  269. rightAxis.drawGridLinesEnabled = YES;
  270. // ChartLegend *l = _singleChartView.legend;
  271. // l.horizontalAlignment = ChartLegendHorizontalAlignmentLeft;
  272. // l.verticalAlignment = ChartLegendVerticalAlignmentBottom;
  273. // l.orientation = ChartLegendOrientationHorizontal;
  274. // l.drawInside = NO;
  275. // l.form = ChartLegendFormSquare;
  276. // l.formSize = 8.0;
  277. // l.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:11.f];
  278. // l.xEntrySpace = 4.0;
  279. barchartView.fitBars = YES;
  280. double barWidth = 0.6;
  281. NSMutableArray *yVals = [[NSMutableArray alloc] init];
  282. for (int i = 0; i < barchartArray.count; i++)
  283. {
  284. [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:[[barchartArray objectAtIndex:i]doubleValue] icon: [UIImage imageNamed:@"icon"]]];
  285. }
  286. BarChartDataSet *set1 = nil;
  287. if (barchartView.data.dataSetCount > 0)
  288. {
  289. set1 = (BarChartDataSet *)barchartView.data.dataSets[0];
  290. [set1 replaceEntries:yVals];
  291. [barchartView.data notifyDataChanged];
  292. [barchartView notifyDataSetChanged];
  293. }
  294. else
  295. {
  296. set1 = [[BarChartDataSet alloc] initWithEntries:yVals label:@"DataSet"];
  297. [set1 setColor: [UIColor colorWithRed:70/255.0f green:116/255.0f blue:193/255.0f alpha:1]];
  298. set1.drawIconsEnabled = NO;
  299. NSMutableArray *dataSets = [[NSMutableArray alloc] init];
  300. [dataSets addObject:set1];
  301. BarChartData *data = [[BarChartData alloc] initWithDataSets:dataSets];
  302. [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:10.f]];
  303. data.barWidth = barWidth;
  304. barchartView.data = data;
  305. }
  306. }
  307. @end