CNLiveMineController.m
17.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
//
// CNLiveMineController.m
// CNLiveMineModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveMineController.h"
#import "MJExtension.h"
#import "QMUIKit.h"
#import "CNLiveServices.h"
#import <CNLiveRequestBastKit/CNLiveNetworking.h>
#import "CNUserInfoManager.h"
#import "CNLiveEnvironment.h"
#import "CNLiveCategory.h"
#import "CNLiveMineNavigationBar.h"
#import "CNLiveMineHeaderView.h"
#import "CNLiveMineCell.h"
#import "CNLiveMineModel.h"
#import "CNLiveUserInfoController.h"
#import "CNLiveMineRequest.h"
@interface CNLiveMineController()<UITableViewDelegate, UITableViewDataSource, CNLiveMineHeaderViewDelegate, CNLiveMineCellDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, weak) CNLiveMineHeaderView *headerView;
@property (nonatomic, strong) CNLiveMineNavigationBar *navigationBar;
@property (nonatomic, strong) UIButton *soccerBtn;
@property (nonatomic, strong) NSMutableArray *data;
@end
@implementation CNLiveMineController
static const NSInteger kHEIGHT = 250;
static const CGFloat timeValue = 1.5;
#pragma mark - 加载数据
- (void)loadData {
NSArray *data = @[
@{
@"name":@"我的订单",
@"style":@"1",
@"margin":@"10",
@"titleHeight":@"50",
@"itemHeight":@"60",
@"buttons":@[@{
@"title":@"订单",
@"image":@"mine_order"
},@{
@"title":@"待付款",
@"image":@"mine_pending"
},@{
@"title":@"待收货",
@"image":@"mine_received"
},@{
@"title":@"待评价",
@"image":@"mine_evaluate"
},@{
@"title":@"售后",
@"image":@"mine_refund"
}
]
},
@{
@"name":@"常用工具",
@"style":@"2",
@"margin":@"10",
@"titleHeight":@"50",
@"itemHeight":@"60",
@"buttons":@[@{
@"title":@"收货地址",
@"image":@"mine_address"
},@{
@"title":@"补贴余额",
@"image":@"mine_card"
},@{
@"title":@"我的收藏",
@"image":@"mine_like"
},@{
@"title":@"发布记录",
@"image":@"mine_release"
},@{
@"title":@"邀请好友",
@"image":@"mine_invitation"
},@{
@"title":@"设置",
@"image":@"mine_set"
},@{
@"title":@"小家音响",
@"image":@"mine_home_box"
},@{
@"title":@"我的礼盒",
@"image":@"mine_gift_box"
},@{
@"title":@"路径工具",
@"image":@"mine_tool_map"
}
]
},
@{
@"name":@"购买的商品",
@"pic":@"mine_buy_commodity",
@"style":@"3",
@"margin":@"10",
@"titleHeight":@"50",
@"itemHeight":@"80",
@"buttons":@[@{
@"title":@"电子票",
@"image":@"mine_e-ticket"
}
]
},
@{
@"name":@"大众体育",
@"pic":@"mine_china_sport",
@"style":@"4",
@"margin":@"10",
@"titleHeight":@"50",
@"itemHeight":@"60",
@"buttons":@[@{
@"title":@"我的活动",
@"image":@"mine_activity"
},@{
@"title":@"我的记录",
@"image":@"mine_record"
}
]
}
];
for(NSDictionary *dic in data){
CNLiveMineModel *model = [CNLiveMineModel mj_objectWithKeyValues:dic];
// [model editModel:NO];
[self.data addObject:model];
}
[self.tableView reloadData];
}
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
[self requestCertification];
if(self.headerView){
self.headerView.frame = CGRectMake(0, -kHEIGHT, SCREEN_WIDTH, kHEIGHT);
}
if(self.soccerBtn){
self.soccerBtn.frame = CGRectMake(SCREEN_WIDTH-67-10, SCREEN_HEIGHT-71-10-TabBarHeight, 67, 71);
}
self.headerView.isRefresh = YES;
[self.tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1.0];
if (@available(iOS 11, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
[self createSubViews];
[self loadData];
}
- (void)createSubViews {
[self.view addSubview:self.tableView];
CNLiveMineHeaderView *headerView = [[CNLiveMineHeaderView alloc]initWithFrame:CGRectMake(0, -kHEIGHT, SCREEN_WIDTH, kHEIGHT)];
headerView.delegate = self;
headerView.tag = 666;
[self.tableView addSubview:headerView];
self.headerView = headerView;
[self.view addSubview:self.navigationBar];
[self.view addSubview:self.soccerBtn];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CNLiveMineModel *model = self.data[indexPath.row];
return model.height;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CNLiveMineCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveMineCell];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.delegate = self;
cell.model = self.data[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
#pragma mark - CNLiveMineHeaderViewDelegate
- (void)headerView:(CNLiveMineHeaderView *)headerView pushToController:(CNLiveMineHeaderViewType)type{
switch (type) {
case CNLiveMineHeaderViewTypeUerInfo:
{
CNLiveUserInfoController *vc = [[CNLiveUserInfoController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
break;
case CNLiveMineHeaderViewTypeCode:
{
id<CNLiveQrCodeServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveQrCodeServiceProtocol)];
[service pushToMyQrCodeController:NO];
}
break;
case CNLiveMineHeaderViewTypeSign:
{
[self requestSignIn];
}
break;
case CNLiveMineHeaderViewTypeWintess:
{
}
break;
}
}
#pragma mark - 请求方法
// 请求签到赚积分
- (void)requestSignIn{
self.headerView.interactionEnabled = NO;
[CNLiveMineRequest signIn:^(BOOL isSuccess, NSDictionary * _Nonnull data, NSError * _Nonnull error) {
if (error.code == -1001 || error.code == -1009) {
[QMUITips showError:@"网络连接已断开" inView:self.view hideAfterDelay:timeValue];
return ;
}
if (isSuccess) {
id<CNLiveIntegralServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveIntegralServiceProtocol)];
NSInteger status = [data[@"status"] integerValue];
if (status == 1) {
[service showGoldWhereaboutsViewWithDic:data];
}else{
[service showSignInViewWithDic:data];
}
}else{
[QMUITips showError:@"签到失败" inView:self.view hideAfterDelay:timeValue];
}
self.headerView.interactionEnabled = YES;
}];
}
// 请求用户认证
- (void)requestCertification{
[CNLiveMineRequest certification:^(BOOL isSuccess, NSDictionary * _Nonnull data, NSError * _Nonnull error) {
if (error.code == -1001 || error.code == -1009) {
[QMUITips showError:@"网络连接已断开" inView:self.view hideAfterDelay:timeValue];
return ;
}
if (isSuccess) {
NSString *darenIdentity = [NSString stringWithFormat:@"%@",[data objectForKey:@"darenIdentity"]];
if ([darenIdentity isEqualToString:@"1"]) { //普通用户
CNUserShareModel.isDaren = 0;
self.headerView.certificationImages = @[@"mine_wjj_certification",@"mine_common",@"mine_overbadge"];
} else if ([darenIdentity isEqualToString:@"0"]) { //达人用户
CNUserShareModel.isDaren = 1;
self.headerView.certificationImages = @[@"mine_wjj_certification",@"mine_doyen", @"mine_overbadge"];
}
}
}];
}
#pragma mark - CNLiveMineCellDelegate
- (void)cell:(CNLiveMineCell *)cell didSelectItemAtItem:(NSInteger)item{
switch (cell.model.type) {
case CNLiveMineCellTypeOrder:
{
if(item == 4){
//售后
id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)];
[service pushToRefundViewController:0];
}else{
id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)];
[service pushToOrderViewController:item];
}
}
break;
case CNLiveMineCellTypeTool:
{
if(item == 0){
// 收货地址
id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)];
[service pushToAddressViewController];
}
else if(item == 1){
// 余额
id<CNLiveBalanceServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveBalanceServiceProtocol)];
[service pushToBalanceViewControllerWithType:@"1" ID:CNUserShareModel.uid];
}
else if(item == 2){
// 收藏
id<CNLiveCollectionServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveCollectionServiceProtocol)];
[service pushToCollectionViewController];
}
else if(item == 3){
// 发布记录
// XWOrdersController *vc = [[XWOrdersController alloc]init];
// [self.navigationController pushViewController:vc animated:YES];
}
else if(item == 4){
// 邀请好友
// XWOrdersController *vc = [[XWOrdersController alloc]init];
// [self.navigationController pushViewController:vc animated:YES];
}
else if(item == 5){
// 设置
id<CNLiveSettingServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveSettingServiceProtocol)];
[service pushToSettingViewController];
}
else if(item == 6){
// 小家音响
NSLog(@"小家音响");
}
else if(item == 7){
// 我的礼盒
id<CNLiveOrderServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveOrderServiceProtocol)];
[service pushToGiftBoxViewController];
}
else if(item == 8){
// 路径工具
NSLog(@"路径工具");
}
}
break;
case CNLiveMineCellTypeGoods:
{
}
break;
case CNLiveMineCellTypeSports:
{
if(item == 0){
// 我的活动
NSLog(@"我的活动");
}
else if(item == 1){
// 我的记录
NSLog(@"我的记录");
}
}
break;
default:
break;
}
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint point = scrollView.contentOffset;
if (point.y < -kHEIGHT) {
CGRect rect = [self.tableView viewWithTag:666].frame;
rect.origin.y = point.y;
rect.size.height = -point.y;
[self.tableView viewWithTag:666].frame = rect;
if(point.y < -320){
// XWWitnessController *vc = [[XWWitnessController alloc]init];
// CATransition *transition = [CATransition animation];
// transition.duration = 0.5;
// transition.timingFunction = [CAMediaTimingFunction
// functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
// transition.type = kCATransitionPush;
// transition.subtype = kCATransitionFromBottom;
// [self.view.window.layer addAnimation:transition forKey:nil];
// [self.navigationController pushViewController:vc animated:NO];
}
}
CGFloat offsetToShow = 50.0;//滑动多少就完全显示
CGFloat offsetY = scrollView.contentOffset.y+kHEIGHT;
if (offsetY <= 0) {
_navigationBar.alpha = 0.0;
}
else if (offsetY > offsetToShow) {
_navigationBar.alpha = 1.0;
}
else {
CGFloat alpha = MIN((offsetY / offsetToShow), 1);
_navigationBar.alpha = alpha;
}
}
#pragma mark - 状态栏
- (UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
#pragma mark - 响应方法
- (void)soccerDidClicked:(UIButton *)btn{
id<CNLiveIntegralServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveIntegralServiceProtocol)];
[service pushToTaskListViewController];
}
#pragma mark - 懒加载
- (NSMutableArray *)data {
if (!_data) {
_data = [NSMutableArray array];
}
return _data;
}
- (CNLiveMineNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [[CNLiveMineNavigationBar alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
_navigationBar.backgroundColor = [UIColor colorWithRed:32/255.0 green:31/255.0 blue:36/255.0 alpha:1.0];
_navigationBar.alpha = 0.0;
}
return _navigationBar;
}
- (UITableView *)tableView{
if(!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-TabBarHeight) style:UITableViewStylePlain];
_tableView.showsVerticalScrollIndicator = NO;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1.0];
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
[_tableView registerClass:[CNLiveMineCell class] forCellReuseIdentifier:kCNLiveMineCell];
_tableView.contentInset = UIEdgeInsetsMake(kHEIGHT, 0, 0, 0);
}
return _tableView;
}
- (UIButton *)soccerBtn{
if(!_soccerBtn){
_soccerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_soccerBtn.adjustsImageWhenHighlighted = NO;
_soccerBtn.frame = CGRectMake(SCREEN_WIDTH-67-10, SCREEN_HEIGHT-71-10-TabBarHeight, 67, 71);
UIImage *xw_image = [self getImageWithImageName:@"mine_soccer_task" bundleName:@"CNLiveMineModule" targetClass:[CNLiveMineController class]];
[_soccerBtn setImage:xw_image forState:UIControlStateNormal];
[_soccerBtn addTarget:self action:@selector(soccerDidClicked:) forControlEvents:UIControlEventTouchUpInside];
}
return _soccerBtn;
}
@end