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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//
// MainViewController.m
// Car
//
// Created by Javen on 2016/12/23.
// Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//
#import "MainViewController.h"
#import "HttpCilent.h"
#import "OrderListTableViewCell.h"
#import "OrderListModel.h"
#import "OrderListFilterViewController.h"
#import "OrderDetailViewController.h"
@interface MainViewController ()
@property (strong, nonatomic) OrderListFilterViewController *filterVC;
@property (strong, nonatomic) OrderQueryDefintion *param;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintTop;
@property (weak, nonatomic) IBOutlet UIButton *btnSelectAll;
@property (weak, nonatomic) IBOutlet UIButton *btnCheck;
@property (strong, nonatomic) NSMutableSet *setBillToCheck;
@property (weak, nonatomic) IBOutlet UILabel *labelCount;
@property (weak, nonatomic) IBOutlet UILabel *labelAmount;
/**
底部的面板
*/
@property (weak, nonatomic) IBOutlet UIView *bottomBoard;
@property (strong, nonatomic) TradeStatisticsResult *total;
@end
@implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self httpRequest];
self.constraintTop.constant = 0;
[self.view layoutIfNeeded];
self.view.backgroundColor = [UIColor whiteColor];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(actionNoti:) name:kNotiSelectBill object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
kGlobal.mainVC = self;
}
- (void)httpRequest {
self.param.pageSize = self.pageSize;
self.param.pageNumber = self.page;
NSDictionary *param = [self.param toDictionary];
[MBProgressHUD j_loading:@"加载中…"];
WS(weakSelf);
[kHttp POST:kOrderQueryUrl
parameters:param
complete:^(id _Nullable response, NSError *_Nullable error) {
[MBProgressHUD j_hideLoadingView];
if (kRsSuccess(response)) {
weakSelf.total = [[TradeStatisticsResult alloc] initWithDictionary:response[@"data"][@"total"] error:nil];
for (NSDictionary *dict in response[@"data"][@"records"]) {
OrderListModel *model = [[OrderListModel alloc] initWithDictionary:dict error:nil];
if (weakSelf.btnSelectAll.isSelected) {
model.isSelected = YES;
}
[weakSelf.arrData addObject:model];
}
weakSelf.bottomBoard.hidden = weakSelf.arrData.count == 0;
[weakSelf listTableViewReloadData];
} else {
kShowRsMsg(response);
[weakSelf.tableView j_endRefresh];
if (self.page > 0) {
self.page--;
}
}
}];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 166;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arrData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
OrderListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderListTableViewCell" forIndexPath:indexPath];
[cell configCellArray:self.arrData indexPath:indexPath isShow:self.btnCheck.isSelected isAll:self.btnSelectAll.selected];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
// kDebugIndex(indexPath);
}
- (void)listDidSelect:(id)model {
// if (self.btnCheck.isSelected) {
// return;
// }
OrderDetailViewController *detailVC = [OrderDetailViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_MAIN];
detailVC.model = model;
[self.navigationController pushViewController:detailVC animated:YES];
}
#pragma mark - actions
- (IBAction)actionLeft:(UIBarButtonItem *)sender {
if (kGlobal.sideSlipVC.isShowLeft) {
[kGlobal.sideSlipVC showMainView];
} else {
[kGlobal.sideSlipVC showLeftView];
}
}
- (IBAction)actionRight:(id)sender {
if (self.filterVC.isOpen) {
[self.filterVC hideFilterView];
} else {
self.filterVC.view.frame = self.view.bounds;
[self.view addSubview:self.filterVC.view];
[self.filterVC showFilterView];
}
}
- (IBAction)actionCheck:(UIButton *)sender {
if (!sender.isSelected) {
sender.selected = YES;
[self.tableView reloadData];
self.constraintTop.constant = 44;
[UIView animateWithDuration:0.3
animations:^{
[self.view layoutIfNeeded];
}];
} else {
if (self.btnSelectAll.isSelected && self.setBillToCheck.count == 0) {
[self actionCancelCheck:nil];
return;
}
if (self.setBillToCheck.count == 0) {
[MBProgressHUD j_error:@"请选择对账的单据!" complete:nil];
return;
}
[self httpCheckBill];
}
}
/**
全选操作
@param isAll 是否全选
*/
- (void)configSelectData:(BOOL)isAll {
[self.setBillToCheck removeAllObjects];
for (OrderListModel *model in self.arrData) {
if (![model.checkState isEqualToString:@"checked"]) {
[self.setBillToCheck addObject:model];
model.isSelected = isAll;
if (isAll) {
[self.setBillToCheck addObject:model];
}
}
}
[self.tableView reloadData];
}
- (void)setTotal:(TradeStatisticsResult *)total {
_total = total;
self.labelCount.text = [NSString stringWithFormat:@"%lld", total.orderCount];
self.labelAmount.text = [NSString stringWithFormat:@"¥ %.2f", total.totalAmount ? total.totalAmount : 0];
}
- (IBAction)actionSelectAll:(UIButton *)sender {
sender.selected = !sender.isSelected;
[self configSelectData:sender.isSelected];
}
- (IBAction)actionCancelCheck:(id)sender {
self.constraintTop.constant = 0;
[UIView animateWithDuration:0.3
animations:^{
[self.view layoutIfNeeded];
}];
self.btnCheck.selected = NO;
self.btnSelectAll.selected = NO;
[self configSelectData:NO];
[self.tableView reloadData];
}
- (void)actionNoti:(NSNotification *)noti {
NSLog(@"%@", noti);
OrderListModel *model = noti.object;
if (model.isSelected) {
[self.setBillToCheck addObject:model];
} else {
[self.setBillToCheck removeObject:model];
}
self.btnSelectAll.selected = [self configIsAll];
}
/**
判断是否全选
*/
- (BOOL)configIsAll {
for (OrderListModel *model in self.arrData) {
if (![model.checkState isEqualToString:@"checked"]) {
if (!model.isSelected) {
return NO;
}
}
}
return YES;
}
- (void)showShadow {
self.shadow.hidden = NO;
}
- (void)hideShadow {
self.shadow.hidden = YES;
}
- (void)httpCheckBill {
CheckOrderRequest *request = [[CheckOrderRequest alloc] init];
request.userId = kUser.fid;
NSMutableArray *arr = [NSMutableArray array];
for (OrderListModel *model in self.setBillToCheck.allObjects) {
[arr addObject:model.fid];
}
request.orderIds = arr;
WS(weakSelf);
[kHttp POST:kUrlCheck
parameters:request.toDictionary
complete:^(id _Nullable response, NSError *_Nullable error) {
if (kRsSuccess(response)) {
[MBProgressHUD j_success:@"对账成功!" complete:nil];
for (OrderListModel *model in weakSelf.setBillToCheck.allObjects) {
model.checkState = @"checked";
}
[weakSelf.setBillToCheck removeAllObjects];
[weakSelf.tableView reloadData];
} else {
kShowRsMsg(response);
}
}];
}
#pragma mark - lazy
- (OrderListFilterViewController *)filterVC {
if (!_filterVC) {
_filterVC = [OrderListFilterViewController viewControllerWithStoryBoardType:STORYBOARD_TYPE_MAIN];
_filterVC.param = self.param;
WS(weakSelf);
[_filterVC setBlockSubmit:^{
[weakSelf.tableView.mj_header beginRefreshing];
}];
[self addChildViewController:_filterVC];
}
return _filterVC;
}
- (OrderQueryDefintion *)param {
if (!_param) {
_param = [[OrderQueryDefintion alloc] init];
QueryOrder *order = [[QueryOrder alloc] init];
order.field = @"payTime";
order.direction = @"desc";
_param.orders = (NSArray<QueryOrder> *) @[ order ];
_param.userId = kUser.fid;
_param.state = @"paid, invalid";
_param.beginDate = [[[NSDate date] yearMonthDayString] stringByAppendingString:@" 00:00:00"];
_param.endDate = [[[NSDate date] yearMonthDayString] stringByAppendingString:@" 23:59:59"];
}
return _param;
}
//
//- (NSMutableArray *)arrBillIdToCheck {
// if (!_arrBillIdToCheck) {
// _arrBillIdToCheck = [NSMutableArray array];
// }
//
// return _arrBillIdToCheck;
//}
- (NSMutableSet *)setBillToCheck {
if (!_setBillToCheck) {
_setBillToCheck = [NSMutableSet set];
}
return _setBillToCheck;
}
- (UIView *)shadow {
if (!_shadow) {
_shadow = [[UIView alloc] initWithFrame:self.view.bounds];
_shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.3];
[self.view addSubview:_shadow];
_shadow.hidden = YES;
_shadow.tag = 11112222;
}
return _shadow;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end