123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- //
- // MyAccountVC.m
- // jiaPei
- //
- // Created by apple on 16/8/22.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "MyAccountVC.h"
- #import "PieView.h"
- #import "MyAccountDetailVC.h"
- #import "AccountDetailCell.h"
- @interface MyAccountVC ()<PieViewDataSource,UITableViewDelegate,UITableViewDataSource>
- {
- PieView *pieV;
- UITableView *mainTableView;
- UILabel *holderLabel;
- UILabel *consumeLabel,*freeLabel,*freezeLabel,*allLabel;
-
- NSArray *colors;
- NSArray *dataArray;
- NSInteger cntFree;
- NSInteger cntFreeze;
- NSInteger cntConsume;
- NSInteger cntAll;
- }
- @end
- @implementation MyAccountVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
- [self getMyAccount];
- }
- -(void)myInit
- {
- [self configNavigationBar];
- [self setTitle:@"我的账户"];
- [self.view setBackgroundColor:[UIColor whiteColor]];
-
- cntFree = 99;
- cntFreeze = 1;
- cntAll = 100;
- dataArray = [NSArray array];
-
- CGFloat x,y,w,h,bd;
- x = bd = 10;
- y = 10;
- w = kSize.width - 20;
- h = 40;
-
- UILabel *label = [[UILabel alloc] setxywh];
- [label setText:@"总资产" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- [label addViewWithRect:CGRectMake(0, 0, w, 10)];
- [label addViewWithRect:CGRectMake(10, y + h, w - 20, 1.5)];
-
- y += h + 1.5;
- x = 0;
- w = kSize.width/2.0 + bd;
- h = w/3.0*2.0 + 4*bd;
- UIView *pieBackView = [[UIView alloc] setxywh];
- pieBackView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:pieBackView];
- [pieBackView addViewWithRect:CGRectMake(0, y + h, kSize.width, 10)];
-
- colors = @[[UIColor redColor],[UIColor orangeColor],defGreen];
- pieV = [[PieView alloc] init];
- [pieV setBounds:CGRectMake(0, 0, w/3.0*2.0, w/3.0*2.0)];
- [pieV setCenter:pieBackView.center];
- [pieV setDatasource:self];
- [self.view addSubview:pieV];
- UIView *frontView = [[UIView alloc] init];
- [frontView setBounds:CGRectMake(0, 0, w/9.0*2.0, w/9.0*2.0)];
- [frontView setCenter:pieBackView.center];
- [frontView setRound];
- frontView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:frontView];
-
- x = kSize.width/2.0 + bd;
- NSArray *titles = @[@"总资金",@"消费金额",@"冻结金额",@"可用金额"];
- NSMutableArray *labelArray = [NSMutableArray arrayWithCapacity:4];
- for (int i = 0; i < 4 ; i ++) {
- //小圆点
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y + 20 + w/12.0*2.0*i + w/12.0 - 5, 10, 10)];
- if (i == 0) {
- label.backgroundColor = [UIColor whiteColor];
- }else{
- label.backgroundColor = colors[i - 1];
- }
- [label setRound];
- [self.view addSubview:label];
- //名称
- CGFloat labelW = [titles[i] sizeForFont:NormalFont].width + 10;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x + 20, y + 20 + w/12.0*2.0*i + w/12.0 - 10, labelW, 20)];
- [label setText:titles[i] Font:NormalFont TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- //数据
- 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)];
- [label setText:@"" Font:NormalFont TextColor:contentTextColor Alignment:NSTextAlignmentRight];
- [self.view addSubview:label];
- [labelArray addObject:label];
- }
-
- if (labelArray.count > 2) {
- allLabel = labelArray[0];
- consumeLabel = labelArray[1];
- freezeLabel = labelArray[2];
- freeLabel = labelArray[3];
- }
-
- y += h + 10;
- x = bd;
- w = kSize.width - 20;
- h = 40;
- label = [[UILabel alloc] setxywh];
- [label setText:@"资金明细" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
- [label addViewWithRect:CGRectMake(10, y + h, w - 20, 1.5)];
-
- y += h + 1.5;
- x = 0;
- w = kSize.width;
- h = kSize.height - y - kNavOffSet;
- mainTableView = [[UITableView alloc] setxywh];
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- [self.view addSubview:mainTableView];
-
- h = 70;
- holderLabel = [[UILabel alloc] setxywh];
- [holderLabel setText:@"暂无收支明细" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentCenter];
- [self.view addSubview:holderLabel];
- }
- -(void)btnClick:(UIButton *)sender
- {
- //NSLog(@"%d",(int)sender.tag);
- if (sender.tag == 1) {
- MyAccountDetailVC *detailVC = [[MyAccountDetailVC alloc] init];
- [self navPushHideTabbarToVC:detailVC];
- }
-
- }
- #pragma mark tableview delegate
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (dataArray.count == 0) {
- return 0;
- }else{
- return dataArray.count + 1;
- }
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.row == dataArray.count) {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"firstCell"];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"firstCell"];
-
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
- [btn setTitle:@"点击查看更多" textColor:defGreen font:FontTitle fotState:UIControlStateNormal];
- [btn target:self tag:1];
- [cell.contentView addSubview:btn];
- }
- return cell;
- }
-
- AccountDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountDetailCell"];
- if (cell == nil)
- {
- cell = [[AccountDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AccountDetailCell"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- cell.dataDic = dataArray[indexPath.row];
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.row == dataArray.count) {
- return 40.5;
- }
- return 60.5;
- }
- #pragma mark 扇形图delegate
- - (int)numberOfSlicesInPieChartView:(PieView *)pieChartView
- {
- return 3;
- }
- /**
- 返回某个index的饼片的比例。0-100
- */
- - (double)pieChartView:(PieView *)pieChartView valueForSliceAtIndex:(NSUInteger)index
- {
- NSInteger cnt;
- switch (index) {
- case 0:
- cnt = cntConsume;
- break;
- case 1:
- cnt = cntFreeze;
- break;
- case 2:
- cnt = cntFree;
- break;
- default:
- cnt = 0;
- break;
- }
- //不能除0 会爆炸
-
- if (cntAll == 0.0) {
- if (index == 0 || index == 1) {
- return 0.0;
- }else{
- return 1.0;
- }
- }else{
- return cnt*100.0 / cntAll;
- }
- }
- /**返回某个index饼片的颜色
- */
- - (UIColor *)pieChartView:(PieView *)pieChartView colorForSliceAtIndex:(NSUInteger)index
- {
- return colors[index];
- }
- #pragma mark 数据请求
- //获取我的账户
- -(void)getMyAccount
- {
- if (![Util connectedToNetWork]) {
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
-
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
-
- NSString* method = @"getMyAccount";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- [MBProgressHUD hideHUDForView:self.view];
- //NSLog(@"我的账户-->%@-->%@",arr,root);
- if (!root) {
- ShowMsgFailed();
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
- /**
- moneyIn = 700,
- moneyOut = 0,
- moneyLock = 0,
- trades = [
- {
- MSA_SOURCE = 充值,
- MAD_ID = 62,
- MSA_ID = 2,
- MSA_CRDATE = 2016-08-30 17:01:28,
- MSA_MONEY = 1,
- MSA_TYPE = 1
- STATUS = 0,//0进行中 1成功 2失败
- }
- */
-
- if (![root[@"body"] isKindOfClass:[NSDictionary class]])
- {
- return;
- }
-
- CGFloat allF = [[root[@"body"] objectForKey:@"moneyIn"] floatValue];
- CGFloat consumeF = [[root[@"body"] objectForKey:@"moneyOut"] floatValue];
- CGFloat freeZ = [[root[@"body"] objectForKey:@"moneyLock"] floatValue];//冻结资产
- CGFloat freeF = allF - consumeF - freeZ;//可用余额
-
- cntFreeze = (NSInteger)freeZ;
- cntConsume = (NSInteger)consumeF;
- cntAll = (NSInteger)allF;
- cntFree = cntAll - cntConsume - cntFreeze;
-
- if (cntFree < 0) {
- cntFree = 0;
- }
-
- dataArray = [root[@"body"] objectForKey:@"trades"];
-
- allLabel.text = [NSString stringWithFormat:@"%.2f",allF];
- consumeLabel.text = [NSString stringWithFormat:@"%.2f",consumeF];
- freezeLabel.text = [NSString stringWithFormat:@"%.2f",freeZ];
- freeLabel.text = [NSString stringWithFormat:@"%.2f",freeF];
-
- [pieV reloadData];
- if (dataArray.count > 0) {
- [holderLabel setHidden:YES];
- [mainTableView reloadData];
- }else{
- [holderLabel setHidden:NO];
- }
- }];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|