// // MyAccountDetailVC.m // jiaPei // // Created by apple on 16/8/23. // Copyright © 2016年 JCZ. All rights reserved. // #import "MyAccountDetailVC.h" #import "HolderView.h" #import "AccountDetailCell.h" @interface MyAccountDetailVC () { UIBarButtonItem *item; UITableView *mainTableView; NSMutableArray *dataArray; HolderView *holder; UIView *backView; UIView *btnBar; NSInteger currentPage; NSInteger currentSource; NSMutableArray *btnArray; } @end @implementation MyAccountDetailVC - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; } -(void)myInit { [self configNavigationBar]; [self setTitle:@"资金详细"]; [self.view setBackgroundColor:[UIColor whiteColor]]; currentSource = 0; currentPage = 1; dataArray = [NSMutableArray array]; item = [[UIBarButtonItem alloc] initWithTitle:@"查找" style:UIBarButtonItemStyleDone target:self action:@selector(clickToSearch)]; [item setTintColor:defGreen]; [self.navigationItem setRightBarButtonItem:item]; mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain]; mainTableView.height -= kNavOffSet; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.rowHeight = 60.5; [self.view addSubview:mainTableView]; holder = [[HolderView alloc] initWithFrame:mainTableView.frame]; [holder freshBlock:^{ currentPage = 1; [self getAccountDetails]; }]; [self.view addSubview:holder]; [self getAccountDetails]; } -(void)clickToSearch { if (backView || btnBar) { //做关闭的操作 [self removeSearchView]; return; } backView = [[UIView alloc] initWithFrame:kFrame]; backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1]; UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)]; [backView addGestureRecognizer:tapGR]; [self.view addSubview:backView]; btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, -165, kSize.width, 165)]; [btnBar setBackgroundColor:[UIColor whiteColor]]; [self.view addSubview:btnBar]; //1 充值 2 消费 3 积分 4 提现 5 红包 6返现 NSArray *titles = @[@"全部",@"充值",@"消费",@"积分",@"提现",@"红包",@"返现"]; btnArray = [NSMutableArray array]; CGFloat w = (kSize.width - 40)/3.0; CGFloat h = 35; for (int i = 0; i < 7; i ++) { int row = i/3; int column = i%3; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10 + column*(w + 10), 20 + row*(h + 10), w, h)]; [btn borderColor:KlineColor width:1 cornorRadios:3]; [btn setTitle:titles[i] textColor:kTitleColor font:FontTitle fotState:UIControlStateNormal]; //点击状态的按钮 [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; UIImage *btnSelectedImg = [UIImage imageWithColor:[UIColor colorWithRed:55/255.0 green:147/255.0 blue:239/255.0 alpha:1]]; [btn setBackgroundImage:btnSelectedImg forState:UIControlStateSelected]; [btn target:self tag:i]; [btnBar addSubview:btn]; [btnArray addObject:btn]; if (i == currentSource) { btn.selected = YES; } } [UIView animateWithDuration:.4 animations:^{ backView.backgroundColor = [UIColor colorWithWhite:.3 alpha:.5]; btnBar.y = 0; }]; } -(void)btnClick:(UIButton *)sender { UIButton *btn = btnArray[currentSource]; [btn setSelected:NO]; btn = (UIButton *)sender; [btn setSelected:YES]; //这里考录要不要做成 点击原来的不变呢 还是不要做了 因为用户可能要通过这个来刷新 currentSource = sender.tag; currentPage = 1; [self getAccountDetails]; //做关闭的操作 [self removeSearchView]; } -(void)tapAction:(UITapGestureRecognizer *)gesture { //做关闭的操作 [self removeSearchView]; } -(void)removeSearchView { [UIView animateWithDuration:.4 animations:^{ backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1]; btnBar.y = -165; } completion:^(BOOL finished) { [backView removeFromSuperview]; [btnBar removeFromSuperview]; backView = nil; btnBar = nil; }]; } #pragma mark tableView delegate -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 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; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { CGPoint off = scrollView.contentOffset; if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) { [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES]; // NSLog(@"AT bottom"); [self getAccountDetails]; } } #pragma mark 数据请求 //获取我的账户明细 -(void)getAccountDetails { if (![Util connectedToNetWork]) { return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"user" Value:defUser.userDict[@"id"]]; [arr addPro:@"source" Value:currentSource == 0?@"":[NSString stringWithFormat:@"%d",(int)currentSource]];//收支类型 [arr addPro:@"isPage" Value:@"1"]; [arr addPro:@"pageSize" Value:@"20"]; [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]]; NSString* method = @"getAccountDetails"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsg(@"明细获取失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } NSArray *array = root[@"body"]; if ([array count] < 1) { if (currentPage == 1) { holder.hidden = NO; return; }else{ ShowMsg(@"已加载全部明细"); return; } } if (currentPage == 1 && dataArray.count > 0) { [dataArray removeAllObjects]; } currentPage += 1; [dataArray addObjectsFromArray:array]; holder.hidden = YES; [mainTableView reloadData]; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end