JXTransferRecordTableVC.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // JXTransferRecordTableVC.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2019/4/20.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXTransferRecordTableVC.h"
  9. #import "JXRecordModel.h"
  10. #import "JXRecordCell.h"
  11. @interface JXTransferRecordTableVC ()
  12. //@property (nonatomic, strong) JXRecordModel *model;
  13. @property (nonatomic, strong) NSMutableArray *array;
  14. @property (nonatomic, strong) NSMutableArray *indexArr;
  15. @end
  16. @implementation JXTransferRecordTableVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.heightHeader = JX_SCREEN_TOP;
  20. self.heightFooter = 0;
  21. self.isGotoBack = YES;
  22. [self createHeadAndFoot];
  23. _array = [[NSMutableArray alloc] init];
  24. _indexArr = [[NSMutableArray alloc] init];
  25. self.title = Localized(@"JX_TransferTheDetail");
  26. _table.backgroundColor = HEXCOLOR(0xF2F2F2);
  27. [self getServerData];
  28. }
  29. - (void)getServerData {
  30. [g_server getConsumeRecordList:self.userId pageIndex:_page pageSize:20 toView:self];
  31. }
  32. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  33. if (self.indexArr.count > 0) {
  34. return self.indexArr.count;
  35. }
  36. return 1;
  37. }
  38. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  39. return 64;
  40. }
  41. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  42. return 50;
  43. }
  44. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  45. if (_array.count > 0) {
  46. return [(NSArray *)[_array objectAtIndex:section] count];
  47. }
  48. return 0;
  49. }
  50. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  51. static NSString *identifier = @"JXRecordCell";
  52. JXRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  53. if (!cell) {
  54. cell = [[JXRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  55. }
  56. JXRecordModel *model = _array[indexPath.section][indexPath.row];
  57. [cell setData:model];
  58. if (indexPath.row == [(NSArray *)[_array objectAtIndex:indexPath.section] count]-1) {
  59. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width,0);
  60. }else {
  61. cell.lineView.frame = CGRectMake(cell.lineView.frame.origin.x, cell.lineView.frame.origin.y, cell.lineView.frame.size.width,LINE_WH);
  62. }
  63. return cell;
  64. }
  65. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  66. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 40)];
  67. view.backgroundColor = HEXCOLOR(0xF2F2F2);
  68. UILabel *label = [[JXLabel alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 48)];
  69. double payMoney = 0;
  70. double getMoney = 0;
  71. if (self.indexArr.count > 0) {
  72. for (JXRecordModel *model in _array[section]) {
  73. if (model.type == 1 || model.type == 2 || model.type == 3 || model.type == 4 || model.type == 7 || model.type == 10 || model.type == 12) {
  74. payMoney += model.money;
  75. }else {
  76. getMoney += model.money;
  77. }
  78. }
  79. label.text = [NSString stringWithFormat:@"%@ 支出:%.2f 收入:%.2f",[self.indexArr objectAtIndex:section],payMoney,getMoney];
  80. }
  81. label.font = SYSFONT(13);
  82. label.textAlignment = NSTextAlignmentCenter;
  83. label.textColor = [UIColor grayColor];
  84. [view addSubview:label];
  85. return view;
  86. }
  87. - (void)handleBillData:(NSArray *)arr
  88. {
  89. NSCalendar *calendar = [NSCalendar currentCalendar];
  90. // 获得当前时间的年月日
  91. NSDateComponents *nowCmps = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:[NSDate date]];
  92. NSInteger currentYear = nowCmps.year;
  93. NSInteger currentMonth = nowCmps.month;
  94. for (JXRecordModel *model in arr) {
  95. NSString *key;
  96. NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:[NSDate dateWithTimeIntervalSince1970:model.time]];
  97. NSInteger billYear = [components year];
  98. NSInteger billMonth = [components month];
  99. if (billYear == currentYear)//本年,对比之后的结果是本年
  100. {
  101. if (billMonth ==currentMonth)//本月
  102. {
  103. key =@"本月";
  104. }
  105. else//其他月
  106. {
  107. key =[NSString stringWithFormat:@"%02ld月",billMonth];
  108. }
  109. }
  110. else//非本年
  111. {
  112. key =[NSString stringWithFormat:@"%ld年%2ld月",billYear,billMonth];
  113. }
  114. BOOL isContained =NO;//_indexArr 是否包含key
  115. NSInteger containedIndex = 0;//记录index
  116. if ([self.indexArr containsObject:key]) {
  117. isContained = YES;
  118. containedIndex = [self.indexArr indexOfObject:key];
  119. }else {
  120. [self.indexArr addObject:key];
  121. }
  122. if (isContained)//如果包含,把Model加进小数组存储
  123. {
  124. [[_array objectAtIndex:containedIndex] addObject:model];
  125. }
  126. else//如果不包含,则创建个小数组添加进_array,然后把model添加进去
  127. {
  128. NSMutableArray *subArr = [[NSMutableArray alloc] init];
  129. [subArr addObject:model];
  130. [_array addObject:subArr];
  131. }
  132. }
  133. [_table reloadData];
  134. }
  135. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  136. [_wait stop];
  137. if( [aDownload.action isEqualToString:act_getConsumeRecordList]){
  138. NSArray *arr = [dict objectForKey:@"pageData"];
  139. if (arr.count <= 0) {
  140. }
  141. NSMutableArray *mutArr = [[NSMutableArray alloc] init];
  142. if(_page == 0){
  143. [_array removeAllObjects];
  144. [_indexArr removeAllObjects];
  145. for (int i = 0; i < arr.count; i++) {
  146. JXRecordModel *model = [[JXRecordModel alloc] init];
  147. [model getDataWithDict:arr[i]];
  148. [mutArr addObject:model];
  149. }
  150. // [_array addObjectsFromArray:mutArr];
  151. }else{
  152. if([arr count]>0){
  153. for (int i = 0; i < arr.count; i++) {
  154. JXRecordModel *model = [[JXRecordModel alloc] init];
  155. [model getDataWithDict:arr[i]];
  156. [mutArr addObject:model];
  157. }
  158. // [_array addObjectsFromArray:mutArr];
  159. }
  160. }
  161. _page ++;
  162. if (mutArr.count > 0) {
  163. [_table hideEmptyImage];
  164. }else {
  165. [_table showEmptyImage:EmptyTypeNoData];
  166. }
  167. [self setIsShowFooterPull:arr.count >= 20];
  168. [self handleBillData:mutArr];
  169. }
  170. }
  171. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  172. [_wait stop];
  173. return show_error;
  174. }
  175. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  176. [_wait stop];
  177. return show_error;
  178. }
  179. -(void) didServerConnectStart:(JXConnection*)aDownload{
  180. [_wait start];
  181. }
  182. @end