1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//
// BillListViewController.m
// Car
//
// Created by Javen on 2016/12/27.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "BillListViewController.h"
#import "HttpCilent.h"
#import "BillListTableViewCell.h"
#import "BillHeaderModel.h"
@interface BillListViewController ()
@property (nonatomic, strong) NSMutableDictionary *dicMonthData;
@property (nonatomic, strong) NSMutableArray *arrSortedData;
@property (nonatomic, strong) NSMutableArray *arrSortedMonths;
@end
@implementation BillListViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"工分账单";
[self httpRequest];
self.tableView.mj_header = nil;
WS(weakSelf);
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
weakSelf.page++;
[weakSelf httpRequest];
}];
// Do any additional setup after loading the view.
}
- (void)httpRequest {
NSDictionary *myDictionary = @{@"userId" : kUser.fid,
@"pageNumber" : @(self.page),
@"pageSize" : @(self.pageSize)};
[MBProgressHUD j_loading];
[kHttp POST:kAccountQueryUrl parameters:myDictionary complete:^(id _Nullable response, NSError * _Nullable error) {
[MBProgressHUD j_hideLoadingView];
WS(weakSelf);
if (kRsSuccess(response)) {
for (NSDictionary *dict in response[@"data"][@"records"]) {
StationUserAcctHisEntity *model = [[StationUserAcctHisEntity alloc] initWithDictionary:dict error:nil];
[weakSelf.dicMonthData setObject:model forKey:[model.createDate substringToIndex:7]];
[weakSelf.arrData addObject:model];
}
[weakSelf configData];
[weakSelf listTableViewReloadData];
}else{
kShowRsMsg(response);
if (self.page > 0) {
self.page--;
}
}
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.arrSortedMonths.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.arrSortedData[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UITableViewCell *header = [tableView dequeueReusableCellWithIdentifier:@"headerCell"];
BillHeaderModel *model = self.arrSortedMonths[section];
UILabel *month = (UILabel *)[header viewWithTag:1111];
month.text = model.date;
UILabel *money = (UILabel *)[header viewWithTag:2222];
money.text = model.total;
return header.contentView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BillListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BillListTableViewCell" forIndexPath:indexPath];
[cell configWithArray:self.arrSortedData indexPath:indexPath];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
kDebugIndex(indexPath);
}
- (void)listDidSelect:(id)model {
}
- (void)configData {
[self.arrSortedData removeAllObjects];
[self.arrSortedMonths removeAllObjects];
//先把整体倒序排序一遍
NSArray *tempSortData = [self.arrData sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
StationUserAcctHisEntity *a = (StationUserAcctHisEntity *)obj1;
StationUserAcctHisEntity *b = (StationUserAcctHisEntity *)obj2;
return [b.createDate compare:a.createDate];
}];
NSArray *months = self.dicMonthData.allKeys;
NSArray *sortMonths = [months sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj2 compare:obj1];
}];
NSInteger count = sortMonths.count;
for (NSInteger i = 0; i < count; i++) {
NSDecimalNumber *monthTotal = [CalculateHelper decimalNumber:0];
NSMutableArray *array = [NSMutableArray array];
for (StationUserAcctHisEntity *model in tempSortData) {
NSString *timeStr = [model.createDate substringToIndex:7];
if ([timeStr isEqualToString:sortMonths[i]]) {
CLog(@"%@", model.createDate);
monthTotal = [CalculateHelper add:monthTotal num2:model.occur];
[array addObject:model];
}
}
BillHeaderModel *headerModel = [[BillHeaderModel alloc] init];
headerModel.date = sortMonths[i];
headerModel.total = [CalculateHelper moneyStringWithPrefix:monthTotal];
[self.arrSortedMonths addObject:headerModel];
[self.arrSortedData addObject:array];
}
}
#pragma mark - lazy
- (NSMutableDictionary *)dicMonthData {
if (!_dicMonthData) {
_dicMonthData = [NSMutableDictionary dictionary];
}
return _dicMonthData;
}
- (NSMutableArray *)arrSortedData {
if (!_arrSortedData) {
_arrSortedData = [NSMutableArray array];
}
return _arrSortedData;
}
- (NSMutableArray *)arrSortedMonths {
if (!_arrSortedMonths) {
_arrSortedMonths = [NSMutableArray array];
}
return _arrSortedMonths;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end