CNLiveOrderListCommonView.m
11.7 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
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
//
// CNLiveOrderListCommonView.m
// CNLiveMyOrderModule
//
// Created by 殷巧娟 on 2019/11/15.
//
#import "CNLiveOrderListCommonView.h"
#import "CNLiveOrderModel.h"
#import "CNLiveMineOrderTableViewCell.h"
#import "CNLiveNoOrderView.h"
#import "CNLiveBaseKit.h"
#import <QMUIKit/QMUIKit.h>
#import "MJRefresh.h"
#import "CNLiveErrorOrNoNetView.h"
#import "CNLiveOrderEventHandle.h"
#import "CNLiveMineOrderItem.h"
#import "MJExtension.h"
#import "CNUserInfoManager.h"
//#import "TIMAdapter.h"
#import "HUDHelper.h"
#import "CNLiveCommonCategory.h"
#import "CNLiveOrderViewModel.h"
#import "CNLiveOrderList.h"
#import "CNLiveRefreshHeader.h"
static const CGFloat KCategoryViewHeight = 44;
@interface CNLiveOrderListCommonView ()<UITableViewDelegate,UITableViewDataSource,CNLiveMineOrderTableViewCellDelegate>
@property (nonatomic, strong) NSMutableArray *listArr; //数据源
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) CNLiveNoOrderView *noDataView;
@property (nonatomic, assign) NSInteger status; //订单状态 0-全部,1-代付款,2-待收货,3-待评价,4-全部退款 ,5退款中(全部只返回123数据)
@property (nonatomic, assign) NSInteger page;
@property (nonatomic, assign) BOOL isHaveNext;
@end
@implementation CNLiveOrderListCommonView
- (instancetype)initWithFrame:(CGRect)frame orderStatus:(NSInteger )status
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = kWeChatBgColor;
_status = status;
_page = 1;
[self setNODataViewByStatus:status];
[self addSubview:self.tableView];
}
return self;
}
#pragma mark -请求订单列表
- (void)requestDataWithPage:(NSInteger)page isClick:(BOOL)isClick {
__weak typeof(self) weakSelf = self;
[QMUITips showLoadingInView:self];
[CNLiveOrderViewModel requestDataWithPage:page status:_status success:^(NSMutableArray * _Nonnull dataSource, BOOL isHaveNet) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[QMUITips hideAllToastInView:self animated:YES];
if (!strongSelf) {
return ;
}
if ([strongSelf.tableView.mj_header isRefreshing]) {
[strongSelf.tableView.mj_header endRefreshing];
}
if ([strongSelf.tableView.mj_footer isRefreshing]) {
[strongSelf.tableView.mj_footer endRefreshing];
}
if (isClick) {
strongSelf.page = 1;
[strongSelf.listArr removeAllObjects];
}
if (dataSource.count > 0) {
[strongSelf.noDataView removeFromSuperview];
strongSelf.isHaveNext = isHaveNet;
strongSelf.tableView.mj_footer.hidden = !strongSelf.isHaveNext;
[self.listArr addObjectsFromArray:dataSource];
if (strongSelf.isHaveNext) {
strongSelf.page ++;
} else {
[strongSelf.tableView.mj_footer endRefreshingWithNoMoreData];
}
} else {
[strongSelf.tableView addSubview:strongSelf.noDataView];
}
strongSelf.tableView.mj_footer.hidden = !strongSelf.isHaveNext;
[strongSelf.tableView reloadData];
} failure:^(NSError * _Nonnull error) {
[weakSelf.tableView.mj_header endRefreshing];
[weakSelf.tableView.mj_header endRefreshing];
if (weakSelf.listArr.count > 0) {
[QMUITips showError:error.localizedDescription inView:self hideAfterDelay:1.5f];
} else {
if (error.code == -1009 || error.code == -1001) {
[weakSelf showErrorRetryType:OrderRetryTypeNoNet];
}else {
[weakSelf showErrorRetryType:OrderRetryTypeError];
}
}
}];
}
#pragma mark -重试
- (void)loadMoreData {
_page = 1;
if (self.listArr.count > 0) {
[self.listArr removeAllObjects];
}
[self requestDataWithPage:_page isClick:NO];
}
#pragma mark -下拉刷新
- (void)refreshList {
_page = 1;
if (self.listArr.count > 0) {
[self.listArr removeAllObjects];
}
[self requestDataWithPage:_page isClick:NO];
}
#pragma mark -上拉加载更多
- (void)refreshMoreData {
[self requestDataWithPage:_page isClick:NO];
}
#pragma mark -刷新数据
- (void)refreshData:(NSInteger)status {
_status = status;
_page = 1;
if (self.listArr.count > 0) {
[self.listArr removeAllObjects];
}
[self requestDataWithPage:_page isClick:NO];
}
- (void)setNODataViewByStatus:(NSInteger)status {
switch (status) {
case 0:
[self.noDataView setImageName:[UIImage cnliveImageInBundleWithImageName:@"dd_quanbumeiyou" bundle:@"CNLiveMyOrderModule.bundle/CNLiveMyOrderModule" targetClass:[self class]] title:@"目前没有订单" customTopH:0];
break;
case 1:
[self.noDataView setImageName:[UIImage cnliveImageInBundleWithImageName:@"dd_wufukuan" bundle:@"CNLiveMyOrderModule.bundle/CNLiveMyOrderModule" targetClass:[self class]] title:@"目前没有订单需要付款" customTopH:0];
break;
case 2:
[self.noDataView setImageName:[UIImage cnliveImageInBundleWithImageName:@"dd_wushouhuo" bundle:@"CNLiveMyOrderModule.bundle/CNLiveMyOrderModule" targetClass:[self class]] title:@"目前没有订单需要收获" customTopH:0];
break;
case 3:
[self.noDataView setImageName:[UIImage cnliveImageInBundleWithImageName:@"dd_wupingjia" bundle:@"CNLiveMyOrderModule.bundle/CNLiveMyOrderModule" targetClass:[self class]] title:@"目前没有订单需要评价" customTopH:0];
break;
default:
break;
}
}
#pragma mark - 展示错误页
- (void)showErrorRetryType:(OrderRetryType)type {
__weak typeof(self) weakSelf = self;
[CNLiveErrorOrNoNetView showErrorByType:type view:self hidenRetry:self.listArr.count > 0 handle:^{
[weakSelf loadMoreData];
}];
}
#pragma mark - CNMineOrderTableViewCellDelegate
- (void)cellWithOrderModel:(CNLiveOrderList *)model type:(CNLiveMineOrderButtonItemType)type {
switch (type) {
case CNLiveMineOrderButtonItemTypeCancel: { //取消订单
[CNLiveOrderEventHandle cancelOrder:model superView:self complete:^(BOOL ret) {
if (ret) {
[self refreshData:self.status];
}
}];
}
break;
case CNLiveMineOrderButtonItemTypeEvaluate: { //评价订单
// [CNLiveOrderEventHandle evaluateOrder:model];
[CNLiveOrderEventHandle evaluateOrder:model jumpBlock:^(CNLiveOrderList * _Nonnull orderList) {
if (self.evaluateOrderBlock) {
self.evaluateOrderBlock(orderList);
}
}];
}
break;
case CNLiveMineOrderButtonItemTypeDelete: { //删除订单
[CNLiveOrderEventHandle deleteOrder:model itemId:@"" superView:self complete:^(BOOL ret) {
if (ret == YES) {
[self refreshData:self.status];
}
}];
}
break;
case CNLiveMineOrderButtonItemTypeContactDaRen: { //联系达人
// [CNOrderEventHandle contactUser:model pop:NO];
[CNLiveOrderEventHandle contactUser:model pop:NO jumpBlock:^(BOOL isPop) {
if (self.contactUserBlock) {
self.contactUserBlock(NO);
}
}];
}
break;
case CNLiveMineOrderButtonItemTypePay: { //去付款
// weakself
// [CNOrderEventHandle pay:model payBlock:^(int code) {
// if (code == 0) {
// //支付成功
// [weakSelf refreshData];
// }
// }];
}
break;
case CNLiveMineOrderButtonItemTypeReminder: { //催单
[CNLiveOrderEventHandle reminderOrder:model superView:self complete:^(NSString *msg) {
[[HUDHelper sharedInstance] tipMessage:msg];
}];
}
break;
case CNLiveMineOrderButtonItemTypeRefund: { //申请退款
// [CNOrderEventHandle applyForRefund:model];
[CNLiveOrderEventHandle applyForRefund:model jumpBlock:^(CNLiveOrderList * _Nonnull orderList) {
if (self.applyForRefundBlock) {
self.applyForRefundBlock(orderList);
}
}];
}
break;
case CNLiveMineOrderButtonItemTypeRefundDetail: { //退款详情
// [CNLiveOrderEventHandle refundDetail:model jumpBlock:^(NSString * _Nonnull orderId) {
// if (self.refundDetailBlock) {
// self.refundDetailBlock(orderId);
// }
// }];
}
break;
case CNLiveMineOrderButtonItemTypeConfirmReceipt: { //确认收货
[CNLiveOrderEventHandle confirmRecv:model itemId:@"" superView:self complete:^(BOOL ret) {
if (ret) {
[self refreshData:self.status];
}
}];
}
break;
case CNLiveMineOrderButtonItemTypeConfirmLogistics: { //查看物流
}
break;
default:
break;
}
}
#pragma mark - UITableViewDeleagte,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.listArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"CNMineOrderTableViewCell";
CNLiveMineOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[CNLiveMineOrderTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
CNLiveOrderList *model = _listArr[indexPath.row];
cell.delegate = self;
[cell configOrderList:model delegate:self];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CNLiveOrderList *model = _listArr[indexPath.row];
return [model.orderItem cellHeight];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView qmui_clearsSelection];
CNLiveMineOrderTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[CNLiveOrderEventHandle orderDetail:cell.list orderBlock:^(NSString * _Nonnull orderId) {
if (self.orderDetaielCellDidSelectedBlock) {
self.orderDetaielCellDidSelectedBlock(indexPath, orderId);
}
}];
}
#pragma mark - 懒加载
- (UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight - kNavigationBarHeight - KCategoryViewHeight ) style:UITableViewStylePlain];
_tableView.backgroundColor = kWeChatBgColor;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.mj_header = [CNLiveRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshList)];
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(refreshMoreData)];
}
return _tableView;
}
- (CNLiveNoOrderView *)noDataView
{
if (!_noDataView) {
_noDataView = [[CNLiveNoOrderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, self.height)];
}
return _noDataView;
}
- (NSMutableArray *)listArr
{
if (!_listArr) {
_listArr = [[NSMutableArray alloc] init];
}
return _listArr;
}
@end