MyAccountDetailVC.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. //
  2. // MyAccountDetailVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/8/23.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "MyAccountDetailVC.h"
  9. #import "HolderView.h"
  10. #import "AccountDetailCell.h"
  11. @interface MyAccountDetailVC ()<UITableViewDelegate,UITableViewDataSource>
  12. {
  13. UIBarButtonItem *item;
  14. UITableView *mainTableView;
  15. NSMutableArray *dataArray;
  16. HolderView *holder;
  17. UIView *backView;
  18. UIView *btnBar;
  19. NSInteger currentPage;
  20. NSInteger currentSource;
  21. NSMutableArray *btnArray;
  22. }
  23. @end
  24. @implementation MyAccountDetailVC
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self myInit];
  28. }
  29. -(void)myInit
  30. {
  31. [self configNavigationBar];
  32. [self setTitle:@"资金详细"];
  33. [self.view setBackgroundColor:[UIColor whiteColor]];
  34. currentSource = 0;
  35. currentPage = 1;
  36. dataArray = [NSMutableArray array];
  37. item = [[UIBarButtonItem alloc] initWithTitle:@"查找" style:UIBarButtonItemStyleDone target:self action:@selector(clickToSearch)];
  38. [item setTintColor:defGreen];
  39. [self.navigationItem setRightBarButtonItem:item];
  40. mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
  41. mainTableView.height -= kNavOffSet;
  42. mainTableView.delegate = self;
  43. mainTableView.dataSource = self;
  44. mainTableView.rowHeight = 60.5;
  45. [self.view addSubview:mainTableView];
  46. holder = [[HolderView alloc] initWithFrame:mainTableView.frame];
  47. [holder freshBlock:^{
  48. currentPage = 1;
  49. [self getAccountDetails];
  50. }];
  51. [self.view addSubview:holder];
  52. [self getAccountDetails];
  53. }
  54. -(void)clickToSearch
  55. {
  56. if (backView || btnBar) {
  57. //做关闭的操作
  58. [self removeSearchView];
  59. return;
  60. }
  61. backView = [[UIView alloc] initWithFrame:kFrame];
  62. backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1];
  63. UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  64. [backView addGestureRecognizer:tapGR];
  65. [self.view addSubview:backView];
  66. btnBar = [[UIView alloc] initWithFrame:CGRectMake(0, -165, kSize.width, 165)];
  67. [btnBar setBackgroundColor:[UIColor whiteColor]];
  68. [self.view addSubview:btnBar];
  69. //1 充值 2 消费 3 积分 4 提现 5 红包 6返现
  70. NSArray *titles = @[@"全部",@"充值",@"消费",@"积分",@"提现",@"红包",@"返现"];
  71. btnArray = [NSMutableArray array];
  72. CGFloat w = (kSize.width - 40)/3.0;
  73. CGFloat h = 35;
  74. for (int i = 0; i < 7; i ++) {
  75. int row = i/3;
  76. int column = i%3;
  77. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(10 + column*(w + 10), 20 + row*(h + 10), w, h)];
  78. [btn borderColor:KlineColor width:1 cornorRadios:3];
  79. [btn setTitle:titles[i] textColor:kTitleColor font:FontTitle fotState:UIControlStateNormal];
  80. //点击状态的按钮
  81. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  82. UIImage *btnSelectedImg = [UIImage imageWithColor:[UIColor colorWithRed:55/255.0 green:147/255.0 blue:239/255.0 alpha:1]];
  83. [btn setBackgroundImage:btnSelectedImg forState:UIControlStateSelected];
  84. [btn target:self tag:i];
  85. [btnBar addSubview:btn];
  86. [btnArray addObject:btn];
  87. if (i == currentSource) {
  88. btn.selected = YES;
  89. }
  90. }
  91. [UIView animateWithDuration:.4 animations:^{
  92. backView.backgroundColor = [UIColor colorWithWhite:.3 alpha:.5];
  93. btnBar.y = 0;
  94. }];
  95. }
  96. -(void)btnClick:(UIButton *)sender
  97. {
  98. UIButton *btn = btnArray[currentSource];
  99. [btn setSelected:NO];
  100. btn = (UIButton *)sender;
  101. [btn setSelected:YES];
  102. //这里考录要不要做成 点击原来的不变呢 还是不要做了 因为用户可能要通过这个来刷新
  103. currentSource = sender.tag;
  104. currentPage = 1;
  105. [self getAccountDetails];
  106. //做关闭的操作
  107. [self removeSearchView];
  108. }
  109. -(void)tapAction:(UITapGestureRecognizer *)gesture
  110. {
  111. //做关闭的操作
  112. [self removeSearchView];
  113. }
  114. -(void)removeSearchView
  115. {
  116. [UIView animateWithDuration:.4 animations:^{
  117. backView.backgroundColor = [UIColor colorWithWhite:.7 alpha:.1];
  118. btnBar.y = -165;
  119. } completion:^(BOOL finished) {
  120. [backView removeFromSuperview];
  121. [btnBar removeFromSuperview];
  122. backView = nil;
  123. btnBar = nil;
  124. }];
  125. }
  126. #pragma mark tableView delegate
  127. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  128. {
  129. return dataArray.count;
  130. }
  131. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  132. {
  133. AccountDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccountDetailCell"];
  134. if (cell == nil)
  135. {
  136. cell = [[AccountDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AccountDetailCell"];
  137. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  138. }
  139. cell.dataDic = dataArray[indexPath.row];
  140. return cell;
  141. }
  142. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  143. {
  144. CGPoint off = scrollView.contentOffset;
  145. if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  146. [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  147. // NSLog(@"AT bottom");
  148. [self getAccountDetails];
  149. }
  150. }
  151. #pragma mark 数据请求
  152. //获取我的账户明细
  153. -(void)getAccountDetails
  154. {
  155. if (![Util connectedToNetWork]) {
  156. return;
  157. }
  158. NSMutableArray *arr=[NSMutableArray array];
  159. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  160. [arr addPro:@"source" Value:currentSource == 0?@"":[NSString stringWithFormat:@"%d",(int)currentSource]];//收支类型
  161. [arr addPro:@"isPage" Value:@"1"];
  162. [arr addPro:@"pageSize" Value:@"20"];
  163. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]];
  164. NSString* method = @"getAccountDetails";
  165. [MBProgressHUD showLoadToView:self.view];
  166. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  167. [MBProgressHUD hideHUDForView:self.view];
  168. if (!root) {
  169. ShowMsg(@"明细获取失败!");
  170. return;
  171. }
  172. if ([root[@"code"] isEqualToString:@"1"]) {
  173. ShowMsg(root[@"body"]);
  174. return;
  175. }
  176. NSArray *array = root[@"body"];
  177. if ([array count] < 1) {
  178. if (currentPage == 1) {
  179. holder.hidden = NO;
  180. return;
  181. }else{
  182. ShowMsg(@"已加载全部明细");
  183. return;
  184. }
  185. }
  186. if (currentPage == 1 && dataArray.count > 0) {
  187. [dataArray removeAllObjects];
  188. }
  189. currentPage += 1;
  190. [dataArray addObjectsFromArray:array];
  191. holder.hidden = YES;
  192. [mainTableView reloadData];
  193. }];
  194. }
  195. - (void)didReceiveMemoryWarning {
  196. [super didReceiveMemoryWarning];
  197. }
  198. @end