MyAccountVC.m 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //
  2. // MyAccountVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/8/22.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "MyAccountVC.h"
  9. #import "PieView.h"
  10. #import "MyAccountDetailVC.h"
  11. #import "AccountDetailCell.h"
  12. @interface MyAccountVC ()<PieViewDataSource,UITableViewDelegate,UITableViewDataSource>
  13. {
  14. PieView *pieV;
  15. UITableView *mainTableView;
  16. UILabel *holderLabel;
  17. UILabel *consumeLabel,*freeLabel,*freezeLabel,*allLabel;
  18. NSArray *colors;
  19. NSArray *dataArray;
  20. NSInteger cntFree;
  21. NSInteger cntFreeze;
  22. NSInteger cntConsume;
  23. NSInteger cntAll;
  24. }
  25. @end
  26. @implementation MyAccountVC
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. [self myInit];
  30. [self getMyAccount];
  31. }
  32. -(void)myInit
  33. {
  34. [self configNavigationBar];
  35. [self setTitle:@"我的账户"];
  36. [self.view setBackgroundColor:[UIColor whiteColor]];
  37. cntFree = 99;
  38. cntFreeze = 1;
  39. cntAll = 100;
  40. dataArray = [NSArray array];
  41. CGFloat x,y,w,h,bd;
  42. x = bd = 10;
  43. y = 10;
  44. w = kSize.width - 20;
  45. h = 40;
  46. UILabel *label = [[UILabel alloc] setxywh];
  47. [label setText:@"总资产" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  48. [self.view addSubview:label];
  49. [label addViewWithRect:CGRectMake(0, 0, w, 10)];
  50. [label addViewWithRect:CGRectMake(10, y + h, w - 20, 1.5)];
  51. y += h + 1.5;
  52. x = 0;
  53. w = kSize.width/2.0 + bd;
  54. h = w/3.0*2.0 + 4*bd;
  55. UIView *pieBackView = [[UIView alloc] setxywh];
  56. pieBackView.backgroundColor = [UIColor whiteColor];
  57. [self.view addSubview:pieBackView];
  58. [pieBackView addViewWithRect:CGRectMake(0, y + h, kSize.width, 10)];
  59. colors = @[[UIColor redColor],[UIColor orangeColor],defGreen];
  60. pieV = [[PieView alloc] init];
  61. [pieV setBounds:CGRectMake(0, 0, w/3.0*2.0, w/3.0*2.0)];
  62. [pieV setCenter:pieBackView.center];
  63. [pieV setDatasource:self];
  64. [self.view addSubview:pieV];
  65. UIView *frontView = [[UIView alloc] init];
  66. [frontView setBounds:CGRectMake(0, 0, w/9.0*2.0, w/9.0*2.0)];
  67. [frontView setCenter:pieBackView.center];
  68. [frontView setRound];
  69. frontView.backgroundColor = [UIColor whiteColor];
  70. [self.view addSubview:frontView];
  71. x = kSize.width/2.0 + bd;
  72. NSArray *titles = @[@"总资金",@"消费金额",@"冻结金额",@"可用金额"];
  73. NSMutableArray *labelArray = [NSMutableArray arrayWithCapacity:4];
  74. for (int i = 0; i < 4 ; i ++) {
  75. //小圆点
  76. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + 20 + w/12.0*2.0*i + w/12.0 - 5, 10, 10)];
  77. if (i == 0) {
  78. label.backgroundColor = [UIColor whiteColor];
  79. }else{
  80. label.backgroundColor = colors[i - 1];
  81. }
  82. [label setRound];
  83. [self.view addSubview:label];
  84. //名称
  85. CGFloat labelW = [titles[i] sizeForFont:NormalFont].width + 10;
  86. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 20, y + 20 + w/12.0*2.0*i + w/12.0 - 10, labelW, 20)];
  87. [label setText:titles[i] Font:NormalFont TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  88. [self.view addSubview:label];
  89. //数据
  90. label = [[UILabel alloc] initWithFrame:CGRectMake(x + 20 + labelW, y + 20 + w/12.0*2.0*i + w/12.0 - 10, kSize.width - x - 40 - labelW, 20)];
  91. [label setText:@"" Font:NormalFont TextColor:contentTextColor Alignment:NSTextAlignmentRight];
  92. [self.view addSubview:label];
  93. [labelArray addObject:label];
  94. }
  95. if (labelArray.count > 2) {
  96. allLabel = labelArray[0];
  97. consumeLabel = labelArray[1];
  98. freezeLabel = labelArray[2];
  99. freeLabel = labelArray[3];
  100. }
  101. y += h + 10;
  102. x = bd;
  103. w = kSize.width - 20;
  104. h = 40;
  105. label = [[UILabel alloc] setxywh];
  106. [label setText:@"资金明细" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  107. [self.view addSubview:label];
  108. [label addViewWithRect:CGRectMake(10, y + h, w - 20, 1.5)];
  109. y += h + 1.5;
  110. x = 0;
  111. w = kSize.width;
  112. h = kSize.height - y - kNavOffSet;
  113. mainTableView = [[UITableView alloc] setxywh];
  114. mainTableView.delegate = self;
  115. mainTableView.dataSource = self;
  116. [self.view addSubview:mainTableView];
  117. h = 70;
  118. holderLabel = [[UILabel alloc] setxywh];
  119. [holderLabel setText:@"暂无收支明细" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentCenter];
  120. [self.view addSubview:holderLabel];
  121. }
  122. -(void)btnClick:(UIButton *)sender
  123. {
  124. //NSLog(@"%d",(int)sender.tag);
  125. if (sender.tag == 1) {
  126. MyAccountDetailVC *detailVC = [[MyAccountDetailVC alloc] init];
  127. [self navPushHideTabbarToVC:detailVC];
  128. }
  129. }
  130. #pragma mark tableview delegate
  131. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  132. {
  133. if (dataArray.count == 0) {
  134. return 0;
  135. }else{
  136. return dataArray.count + 1;
  137. }
  138. }
  139. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  140. {
  141. if (indexPath.row == dataArray.count) {
  142. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"firstCell"];
  143. if (cell == nil)
  144. {
  145. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"firstCell"];
  146. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  147. [btn setTitle:@"点击查看更多" textColor:defGreen font:FontTitle fotState:UIControlStateNormal];
  148. [btn target:self tag:1];
  149. [cell.contentView addSubview:btn];
  150. }
  151. return cell;
  152. }
  153. AccountDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountDetailCell"];
  154. if (cell == nil)
  155. {
  156. cell = [[AccountDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AccountDetailCell"];
  157. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  158. }
  159. cell.dataDic = dataArray[indexPath.row];
  160. return cell;
  161. }
  162. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. if (indexPath.row == dataArray.count) {
  165. return 40.5;
  166. }
  167. return 60.5;
  168. }
  169. #pragma mark 扇形图delegate
  170. - (int)numberOfSlicesInPieChartView:(PieView *)pieChartView
  171. {
  172. return 3;
  173. }
  174. /**
  175. 返回某个index的饼片的比例。0-100
  176. */
  177. - (double)pieChartView:(PieView *)pieChartView valueForSliceAtIndex:(NSUInteger)index
  178. {
  179. NSInteger cnt;
  180. switch (index) {
  181. case 0:
  182. cnt = cntConsume;
  183. break;
  184. case 1:
  185. cnt = cntFreeze;
  186. break;
  187. case 2:
  188. cnt = cntFree;
  189. break;
  190. default:
  191. cnt = 0;
  192. break;
  193. }
  194. //不能除0 会爆炸
  195. if (cntAll == 0.0) {
  196. if (index == 0 || index == 1) {
  197. return 0.0;
  198. }else{
  199. return 1.0;
  200. }
  201. }else{
  202. return cnt*100.0 / cntAll;
  203. }
  204. }
  205. /**返回某个index饼片的颜色
  206. */
  207. - (UIColor *)pieChartView:(PieView *)pieChartView colorForSliceAtIndex:(NSUInteger)index
  208. {
  209. return colors[index];
  210. }
  211. #pragma mark 数据请求
  212. //获取我的账户
  213. -(void)getMyAccount
  214. {
  215. if (![Util connectedToNetWork]) {
  216. return;
  217. }
  218. NSMutableArray *arr=[NSMutableArray array];
  219. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  220. NSString* method = @"getMyAccount";
  221. [MBProgressHUD showLoadToView:self.view];
  222. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  223. [MBProgressHUD hideHUDForView:self.view];
  224. //NSLog(@"我的账户-->%@-->%@",arr,root);
  225. if (!root) {
  226. ShowMsgFailed();
  227. return;
  228. }
  229. if ([root[@"code"] isEqualToString:@"1"]) {
  230. ShowMsg(root[@"body"]);
  231. return;
  232. }
  233. /**
  234. moneyIn = 700,
  235. moneyOut = 0,
  236. moneyLock = 0,
  237. trades = [
  238. {
  239. MSA_SOURCE = 充值,
  240. MAD_ID = 62,
  241. MSA_ID = 2,
  242. MSA_CRDATE = 2016-08-30 17:01:28,
  243. MSA_MONEY = 1,
  244. MSA_TYPE = 1
  245. STATUS = 0,//0进行中 1成功 2失败
  246. }
  247. */
  248. if (![root[@"body"] isKindOfClass:[NSDictionary class]])
  249. {
  250. return;
  251. }
  252. CGFloat allF = [[root[@"body"] objectForKey:@"moneyIn"] floatValue];
  253. CGFloat consumeF = [[root[@"body"] objectForKey:@"moneyOut"] floatValue];
  254. CGFloat freeZ = [[root[@"body"] objectForKey:@"moneyLock"] floatValue];//冻结资产
  255. CGFloat freeF = allF - consumeF - freeZ;//可用余额
  256. cntFreeze = (NSInteger)freeZ;
  257. cntConsume = (NSInteger)consumeF;
  258. cntAll = (NSInteger)allF;
  259. cntFree = cntAll - cntConsume - cntFreeze;
  260. if (cntFree < 0) {
  261. cntFree = 0;
  262. }
  263. dataArray = [root[@"body"] objectForKey:@"trades"];
  264. allLabel.text = [NSString stringWithFormat:@"%.2f",allF];
  265. consumeLabel.text = [NSString stringWithFormat:@"%.2f",consumeF];
  266. freezeLabel.text = [NSString stringWithFormat:@"%.2f",freeZ];
  267. freeLabel.text = [NSString stringWithFormat:@"%.2f",freeF];
  268. [pieV reloadData];
  269. if (dataArray.count > 0) {
  270. [holderLabel setHidden:YES];
  271. [mainTableView reloadData];
  272. }else{
  273. [holderLabel setHidden:NO];
  274. }
  275. }];
  276. }
  277. - (void)didReceiveMemoryWarning {
  278. [super didReceiveMemoryWarning];
  279. }
  280. @end