CNLiveTradingRecordController.m
9.33 KB
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
//
// CNLiveTradingRecordController.m
// CNLiveBalanceModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveTradingRecordController.h"
#import "MJExtension.h"
#import <SDWebImage/SDWebImage.h>
#import "QMUIKit.h"
#import "CNLiveNetworking.h"
#import "CNLiveEnvironment.h"
#import "CNUserInfoManager.h"
#import "CNLiveBaseKit.h"
#import "CNLiveCategory.h"
#import "CNLiveRefreshHeader.h"
#import "CNLiveServices.h"
#import "CNLiveBalanceRequest.h"
#import "CNLiveBalanceNavigationBar.h"
#import "CNLiveTradingRecordView.h"
#import "CNLiveMonthBillController.h" //月账单
#import "CNLiveTradingRecordModel.h"
#import "CNLiveTradingRecordCell.h"
#import "CNLiveTradingRecordDetailController.h"
@interface CNLiveTradingRecordController ()<UITableViewDelegate, UITableViewDataSource,CNLiveBalanceNavigationBarDelegate,CNLiveTradingRecordViewDelegate>
@property (nonatomic, strong) CNLiveBalanceNavigationBar *navigationBar;
@property (nonatomic, strong) CNLiveTradingRecordView *tradingRecordView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *data;
@property (nonatomic, assign) NSInteger pageNo;
//type: 0 -> 个人中心交易记录 1 -> 查看与此商户的交易记录
@property (nonatomic, assign) TradingRecordType type;
//ID: 0 -> 用户id 1 -> 查看与此商户的交易记录 toId
@property (nonatomic, copy) NSString *ID;
@property (nonatomic, copy) NSString *date;
@property (nonatomic, copy) NSString *startTime;
@property (nonatomic, copy) NSString *endTime;
@end
@implementation CNLiveTradingRecordController
static const CGFloat height = 80;
#pragma mark - 初始化
- (instancetype)initWithType:(TradingRecordType)type ID:(NSString *)ID date:(NSString *)date startTime:(NSString *)startTime endTime:(NSString *)endTime{
if(self = [super init]){
self.type = type;
self.ID = ID;
self.date = date;
self.startTime = startTime;
self.endTime = endTime;
}
return self;
}
#pragma mark - 加载数据
- (void)loadData {
[CNLiveBalanceRequest getTradingRecordListWithType:self.type == TradingRecordTypeDefault?@"0":@"Special" ID:self.ID startTime:self.startTime endTime:self.endTime block:^(BOOL isSuccess, NSDictionary * _Nonnull data, NSError *error) {
[self.tableView.mj_header endRefreshing];
[self.tableView.mj_footer endRefreshing];
if (error) {
[self.data removeAllObjects];
[self.tableView reloadData];
[self showEmptyViewWithImage:[UIImage imageNamed:@"wufalianjie"] text:error.localizedDescription detailText:@"别紧张,试试看刷新页面~" buttonTitle:@" 重试 " buttonAction:@selector(loadData)];
[self setCNAPIErrorEmptyView];
self.emptyView.verticalOffset = -(NavigationContentTop+height);
return;
}
if (isSuccess) {
CNLiveTradingRecordModel *model = [CNLiveTradingRecordModel mj_objectWithKeyValues:data];
if(self.pageNo == 1&&self.data.count > 0){
[self.data removeAllObjects];
}
[self.data addObjectsFromArray:self.type == TradingRecordTypeDefault?model.list:model.transferRecordList];
self.tradingRecordView.model = model;
[self.tableView reloadData];
}
}];
}
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
if (@available(iOS 11, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
[self createSubViews];
NSArray *times = [CNLiveBalanceRequest getMonthFirstAndLastDayWithDate:[NSDate date]];
self.startTime = self.startTime?self.startTime:times.firstObject;
self.endTime = self.endTime?self.endTime:times.lastObject;
self.pageNo = 1;
[self.tableView.mj_header beginRefreshing];
}
- (void)createSubViews {
[self.view addSubview:self.navigationBar];
[self.view addSubview:self.tradingRecordView];
[self.view addSubview:self.tableView];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 80.0;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CNLiveTradingRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveTradingRecordCell];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.model = self.data[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(self.type == TradingRecordTypeSpecial){
CNLiveTradingRecordListModel *model = self.data[indexPath.row];
CNLiveTradingRecordDetailController *vc = [[CNLiveTradingRecordDetailController alloc]initWithType:TradingRecordDetailTypeSpecial model:model date:self.date startTime:self.date endTime:self.date];
[self.navigationController pushViewController:vc animated:YES];
}else{
CNLiveTradingRecordListModel *model = self.data[indexPath.row];
CNLiveTradingRecordDetailController *vc = [[CNLiveTradingRecordDetailController alloc]initWithType:TradingRecordDetailTypeDefault model:model date:self.date startTime:self.date endTime:self.date];
[self.navigationController pushViewController:vc animated:YES];
}
}
#pragma mark - CNLiveTradingRecordViewDelegate
- (void)tradingRecordView:(CNLiveTradingRecordView *)view date:(NSString *)date startTime:(NSString *)startTime endTime:(NSString *)endTime{
self.date = date;
self.startTime = startTime;
self.endTime = endTime;
[self loadData];
}
- (void)pushToMonthBillController{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy年M月"];
NSString *dateTime = [formatter stringFromDate:[NSDate date]];
CNLiveMonthBillController *vc = [[CNLiveMonthBillController alloc]initWithDate:self.date?self.date:dateTime startTime:self.startTime endTime:self.endTime];
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 懒加载
- (NSMutableArray *)data {
if (!_data) {
_data = [[NSMutableArray alloc] init];
}
return _data;
}
- (CNLiveBalanceNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [[CNLiveBalanceNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
_navigationBar.backgroundColor = [UIColor whiteColor];
_navigationBar.delegate = self;
_navigationBar.title.text = @"交易记录";
_navigationBar.title.textColor = [UIColor blackColor];
UIImage *image = [self getImageWithImageName:@"mine_back_black_b" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
[_navigationBar.left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
_navigationBar.right = nil;
}
return _navigationBar;
}
- (CNLiveTradingRecordView *)tradingRecordView{
if(!_tradingRecordView){
_tradingRecordView = [[CNLiveTradingRecordView alloc]initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, height)];
_tradingRecordView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
_tradingRecordView.delegate = self;
_tradingRecordView.isShow = self.type == TradingRecordTypeDefault;
_tradingRecordView.date = self.date;
}
return _tradingRecordView;
}
- (UITableView *)tableView{
if(!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavigationContentTop+height, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop-height) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
[_tableView registerClass:[CNLiveTradingRecordCell class] forCellReuseIdentifier:kCNLiveTradingRecordCell];
_tableView.mj_header = [CNLiveRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
}
return _tableView;
}
#pragma mark - 响应方法
- (void)goBack {
if (self.presentingViewController != nil) {
[self dismissViewControllerAnimated:YES completion:nil];
}
else {
[self.navigationController popViewControllerAnimated:YES];
}
}
#pragma mark - CNLiveBalanceNavigationBarDelegate
- (void)navigationBar:(CNLiveBalanceNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
if ([actionEvents isEqualToString:@"1"]) {
[self goBack];
}else if ([actionEvents isEqualToString:@"2"]){
}
}
@end