CNLiveMineVC.m
20.6 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
//
// CNLiveMineVC.m
// CNLiveCMineModule
//
// Created by CNLive on 2022/1/14.
//
#import "CNLiveMineVC.h"
#import "CNTopImageView.h"
#import "CNMinePresent.h"
#import "CNListCollectionView.h"
#import "CNActivityView.h"
#import "CNToolView.h"
#import "CNEvaluaveView.h"
#import "CNRecommendView.h"
#import "CNMineEvaAlertView.h"
#import "CNRevisionInstructionView.h"
#import <CNLiveBaseTools/UIImage+EditIcon.h>
#import <DSBaseModule/DSBaseModule.h>
#import "CNWalletPresent.h"
//有新客服消息
static NSString *const CNSobotNotification_NewMessage = @"CNSobotNotification_NewMessage";
@interface CNLiveMineVC ()<UIScrollViewDelegate>
@property (nonatomic, assign) CGFloat ratio;
@property (nonatomic, strong) UIScrollView *bgScrollView;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) CNTopImageView *topImageView;
@property (nonatomic, strong) UIImageView *topSmallView;
@property (nonatomic, strong) CNListCollectionView *orderView;
@property (nonatomic, strong) CNListCollectionView *packageView;
@property (nonatomic, strong) CNActivityView *activityView;
@property (nonatomic, strong) CNToolView *toolView;
@property (nonatomic, strong) UILabel *versionLabel;
@property (nonatomic, strong) CNEvaluaveView *evaluateView;
@property (nonatomic, strong) CNRecommendView *recommend;
@property (nonatomic, strong) NSString *carCount;
@end
@implementation CNLiveMineVC
- (void)loadData{
weakself
[CNMinePresent requestMineDataSourceWithBlock:^(CNScoreModel * _Nonnull model) {
[weakSelf.bgScrollView.mj_header endRefreshing];
if (model) {
weakSelf.carCount = model.cart_count;
weakSelf.orderView.model = [CNMinePresent dataSourceOrdersModel:model.pay_order_count willShip:model.send_order_count willReceipt:model.confirm_order_count];
weakSelf.packageView.integral = model.integral;
weakSelf.toolView.model = [CNMinePresent datasourceToolModel:CNToolDatasourceTypeFirst carNum:model.cart_count];
}
[CNWalletPresent requestBalanceWithType:@"1" responseBlock:^(NSString * _Nonnull balance) {
weakSelf.packageView.money = balance;
weakSelf.packageView.model = [CNMinePresent dataSourceWalletModel:weakSelf.packageView.integral couponNum:model.coupon_count balance:weakSelf.packageView.money];
}];
}];
[CNWalletPresent requestActivityListBlock:^(NSArray * _Nonnull activities) {
weakSelf.activityView.dataSource = activities;
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.carCount = @"0";
self.ratio = RATIO;
[self.view addSubview:self.bgScrollView];
[self.bgScrollView addSubview:self.bgView];
[self.bgScrollView addSubview:self.topImageView];
[self.view addSubview:self.topSmallView];
[self.view bringSubviewToFront:self.topSmallView];
[self.bgScrollView addSubview:self.orderView];
[self.bgScrollView addSubview:self.packageView];
[self.bgScrollView addSubview:self.activityView];
[self.bgScrollView addSubview:self.toolView];
[self.bgScrollView addSubview:self.versionLabel];
NSString *hiddenDate = [[NSUserDefaults standardUserDefaults] objectForKey:HIDDENDETE];
if (![hiddenDate isEqualToString:@"down"]) {
[self.view addSubview:self.evaluateView];
[self.evaluateView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view);
make.bottom.equalTo(self.view).offset(-DS_adapt_length(20)-kVerticalTabBarTotalHeight);
make.width.mas_equalTo(DS_adapt_length(79));
make.height.mas_equalTo(DS_adapt_length(75.5));
}];
}
if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 11.0) {
self.bgScrollView.frame = CGRectMake(0, -kStatusHeight, kScreenWidth, kScreenHeight + kStatusHeight);
} else {
self.bgScrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
}
self.topSmallView.frame = CGRectMake(0, 0, kScreenWidth, kNavigationBarHeight);
self.topImageView.frame = CGRectMake(0, 0, kScreenWidth, DS_adapt_length(273));
self.orderView.frame = CGRectMake(DS_adapt_length(10), self.topImageView.bottom -DS_adapt_length(55), kScreenWidth - DS_adapt_length( 20), DS_adapt_length(80));
self.packageView.frame = CGRectMake(self.orderView.left, self.orderView.bottom +DS_adapt_length(16), self.orderView.width , DS_adapt_length(106*RATIO));
self.activityView.frame = CGRectMake(self.orderView.left, self.packageView.bottom + DS_adapt_length(16), self.orderView.width, DS_adapt_length(24+138 + 38 *RATIO + 10));
self.toolView.frame = CGRectMake(self.orderView.left, self.activityView.bottom + DS_adapt_length(16), self.orderView.width, DS_adapt_length(145 + 42*RATIO));
self.versionLabel.frame = CGRectMake(self.orderView.left, self.toolView.bottom + DS_adapt_length(16), kScreenWidth, DS_adapt_length(16));
self.bgScrollView.contentSize = CGSizeMake(kScreenWidth, self.versionLabel.bottom + DS_adapt_length(8));
[self getTaskList];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addTolks) name:CNSobotNotification_NewMessage object:nil];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (self.ratio != RATIO) {
self.ratio = RATIO;
_versionLabel.font = UIFontCNMake(14);
[self.topImageView uploadViews];
[self.packageView uploadViews];
[self.activityView uploadViews];
[self.toolView uploadViews];
self.packageView.height = DS_adapt_length(106*RATIO);
self.activityView.top = self.packageView.bottom + DS_adapt_length(16);
self.activityView.height = DS_adapt_length(24+138 + 38 *RATIO+ 10);
self.toolView.top = self.activityView.bottom + DS_adapt_length(16);
self.versionLabel.top = self.toolView.bottom + DS_adapt_length(16);
self.bgScrollView.contentSize = CGSizeMake(kScreenWidth, self.versionLabel.bottom + DS_adapt_length(8));
}else{
[self.topImageView uploadViews];
}
[self loadData];
NSString *currentDate = [[NSString stringWithFormat:@"%@",[NSDate date]] substringToIndex:10];
NSString *hiddenDate = [[NSUserDefaults standardUserDefaults] objectForKey:HIDDENDETE];
if (![hiddenDate isEqualToString:@"down"]&&![currentDate isEqualToString:hiddenDate]) {
self.evaluateView.hidden = NO;
}else{
self.evaluateView.hidden = YES;
}
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"showEvaliate"]&&![hiddenDate isEqualToString:@"down"]) {
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"showTimes"] == 1) {
[[NSUserDefaults standardUserDefaults] setInteger:2 forKey:@"showTimes"];
}else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"showTimes"] == 2){
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"showTimes"];
[CNMineEvaAlertView setUpShowEvaluateAlertViewDoneBlock:^(NSString * _Nonnull chooseStr) {
[QMUITips showLoadingInView:AppKeyWindow];
[CNMinePresent requestFeedback:chooseStr secceedBlock:^{
[QMUITips hideAllTips];
[[NSUserDefaults standardUserDefaults] setObject:@"down" forKey:HIDDENDETE];
[self.evaluateView removeFromSuperview];
}];
} cancelBlock:^{
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"showRem"]) {
if (self.evaluateView.showRecommend) self.evaluateView.showRecommend();
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showRem"];
}
}];
}
}
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"instruShown"]) {
CNRevisionInstructionView *visinView = [[CNRevisionInstructionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, self.view.height)];
visinView.removeBlock = ^{
[self setNeedsStatusBarAppearanceUpdate];
};
[self.view addSubview:visinView];
[self.view bringSubviewToFront:visinView];
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"showTimes"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"instruShown"];
}
}
- (BOOL)preferredNavigationBarHidden
{
return YES;
}
- (void)getTaskList{
[CNMinePresent getTaskList];
}
- (void)addTolks{
if ([[CNLiveCMineService shareMineProtocol] haveUnreadMessage]) {
self.topImageView.codesView.model = [CNMinePresent dataSourceCodesModel:@"."];
}else{
self.topImageView.codesView.model = [CNMinePresent dataSourceCodesModel:@"0"];
}
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat contentOffetY = scrollView.offsetY;
if ([[[UIDevice currentDevice]systemVersion] floatValue] >= 11.0) {
contentOffetY = scrollView.offsetY + kStatusHeight;
}
if (contentOffetY <= DS_adapt_length(35) && contentOffetY > 0) {
self.topSmallView.alpha = contentOffetY/DS_adapt_length(35) ;
[self.view addSubview:self.topImageView.codesView];
[self.view addSubview:self.topImageView.backBtn];
[self.view addSubview:self.topImageView.iconImage];
self.topImageView.iconImage.layer.mask = [self maskLayerWithWidth:DS_adapt_length(60) - self.topSmallView.alpha * DS_adapt_length(28)];
if ([CNLiveEnvironmentManager manager].isNewHomePage) {
[self.topImageView.iconImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight+DS_adapt_length(35) - contentOffetY);
make.left.equalTo(self.topImageView.backBtn).offset(DS_adapt_length( 12));
make.width.height.mas_equalTo(DS_adapt_length(60) - self.topSmallView.alpha * DS_adapt_length(28));
}];
[self.topImageView.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight);
make.right.equalTo(self.view).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(30));
make.width.mas_equalTo(DS_adapt_length(70));
}];
[self.topImageView.backBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(DS_adapt_length(16));
make.centerY.equalTo(self.topImageView.codesView);
make.width.mas_equalTo(DS_adapt_length(11));
make.height.mas_equalTo(DS_adapt_length(18));
}];
}else{
[self.topImageView.iconImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight+DS_adapt_length(35) - contentOffetY);
make.left.equalTo(self.view).offset(DS_adapt_length( 12));
make.width.height.mas_equalTo(DS_adapt_length(60) - self.topSmallView.alpha * DS_adapt_length(28));
}];
[self.topImageView.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight);
make.right.equalTo(self.view).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(30));
make.width.mas_equalTo(DS_adapt_length(105));
}];
}
}else if (contentOffetY > DS_adapt_length(35)){
self.topSmallView.alpha = 1;
[self.topSmallView addSubview:self.topImageView.codesView];
[self.topSmallView addSubview:self.topImageView.backBtn];
[self.topSmallView addSubview:self.topImageView.iconImage];
self.topImageView.iconImage.layer.mask = [self maskLayerWithWidth:DS_adapt_length(32)];
if ([CNLiveEnvironmentManager manager].isNewHomePage) {
[self.topImageView.iconImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight);
make.left.equalTo(self.topImageView.backBtn.mas_right).offset(DS_adapt_length(12));
make.width.height.mas_equalTo(DS_adapt_length(32));
}];
[self.topImageView.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight);
make.right.equalTo(self.view).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(30));
make.width.mas_equalTo(DS_adapt_length(70));
}];
[self.topImageView.backBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(DS_adapt_length(16));
make.centerY.equalTo(self.topImageView.codesView);
make.width.mas_equalTo(DS_adapt_length(11));
make.height.mas_equalTo(DS_adapt_length(18));
}];
}else{
[self.topImageView.iconImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight);
make.left.equalTo(self.view).offset(DS_adapt_length(12));
make.width.height.mas_equalTo(DS_adapt_length(32));
}];
[self.topImageView.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(kStatusHeight);
make.right.equalTo(self.view).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(30));
make.width.mas_equalTo(DS_adapt_length(105));
}];
}
}else{
self.topSmallView.alpha = 0;
[self.topImageView addSubview:self.topImageView.codesView];
[self.topImageView addSubview:self.topImageView.backBtn];
[self.topImageView addSubview:self.topImageView.iconImage];
[self.topImageView.iconImage mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.topImageView).offset(kStatusHeight+DS_adapt_length(35));
make.left.equalTo(self.topImageView).offset(DS_adapt_length(12));
make.width.height.mas_equalTo(DS_adapt_length(60));
}];
self.topImageView.iconImage.layer.mask = [self maskLayerWithWidth:DS_adapt_length(60)];
if ([CNLiveEnvironmentManager manager].isNewHomePage) {
[self.topImageView.codesView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.topImageView.mas_top).offset(kStatusHeight);
make.right.equalTo(self.topImageView).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(30));
make.width.mas_equalTo(DS_adapt_length(70));
}];
[self.topImageView.backBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(DS_adapt_length(16));
make.centerY.equalTo(self.topImageView.codesView);
make.width.mas_equalTo(DS_adapt_length(11));
make.height.mas_equalTo(DS_adapt_length(18));
}];
}else{
[self.topImageView.codesView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.topImageView.mas_top).offset(kStatusHeight);
make.right.equalTo(self.topImageView).offset(-DS_adapt_length(10));
make.height.mas_equalTo(DS_adapt_length(30));
make.width.mas_equalTo(DS_adapt_length(105));
}];
}
}
}
-(CAShapeLayer *)maskLayerWithWidth:(CGFloat)width{
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, width, width) cornerRadius:(width)/2];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.path = path.CGPath;
return maskLayer;
}
#pragma mark - Getting
- (UIScrollView *)bgScrollView
{
if (!_bgScrollView) {
_bgScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
_bgScrollView.backgroundColor = RGB(32, 31, 36);
_bgScrollView.showsVerticalScrollIndicator = NO;
_bgScrollView.showsHorizontalScrollIndicator = NO;
_bgScrollView.delegate = self;
CNLiveRefreshHeader *header = [CNLiveRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
header.isShowWhite = NO;
_bgScrollView.mj_header = header;
}
return _bgScrollView;
}
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] initWithFrame:CGRectMake(0, KScreenWidth*200.0/375.0, KScreenWidth, 2*KScreenHeight)];
_bgView.backgroundColor = UIColorHex(F6F6F6);
}
return _bgView;
}
- (CNTopImageView *)topImageView
{
if (!_topImageView) {
_topImageView = [[CNTopImageView alloc] init];
_topImageView.contentMode = UIViewContentModeScaleAspectFill;
_topImageView.backgroundColor = UIColorHex(#F6F6F6);
_topImageView.userInteractionEnabled = YES;
UIImage *image = [UIImage getEditIconWithName:@"mine_bgImage"];
if (!image) {
image = [UIImage imageNamed:@"mine_bgImage"];
}
_topImageView.image = image;
}
return _topImageView;
}
- (UIImageView *)topSmallView
{
if (!_topSmallView) {
_topSmallView = [[UIImageView alloc] init];
_topSmallView.contentMode = UIViewContentModeScaleAspectFill;
_topSmallView.backgroundColor = UIColorHex(#F6F6F6);
_topSmallView.userInteractionEnabled = YES;
UIImage *image = [UIImage getEditIconWithName:@"mine_bgImage_small"];
if (!image) {
image = [UIImage imageNamed:@"mine_bgImage_small"];
}
_topSmallView.image = image;
_topSmallView.alpha = 0;
}
return _topSmallView;
}
- (CNListCollectionView *)orderView
{
if (!_orderView) {
_orderView = [[CNListCollectionView alloc] init];
_orderView.layer.cornerRadius = 8;
_orderView.backgroundColor = kWhiteColor;
_orderView.model = [CNMinePresent dataSourceOrdersModel:@"0" willShip:@"0" willReceipt:@"0"];
[_orderView.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_orderView).offset(5);
}];
_orderView.showdivideImage = YES;
}
return _orderView;
}
- (CNListCollectionView *)packageView
{
if (!_packageView) {
_packageView = [[CNListCollectionView alloc] initWithFrame:CGRectZero];
_packageView.layer.cornerRadius = 8;
_packageView.layer.masksToBounds = YES;
_packageView.backgroundColor = kWhiteColor;
_packageView.model = [CNMinePresent dataSourceWalletModel:@"0" couponNum:@"0" balance:@"0"];
}
return _packageView;
}
- (CNActivityView *)activityView
{
if (!_activityView) {
_activityView = [[CNActivityView alloc] init];
_activityView.layer.cornerRadius = 8;
_activityView.backgroundColor = kWhiteColor;
}
return _activityView;
}
- (CNToolView *)toolView
{
if (!_toolView) {
_toolView = [[CNToolView alloc] init];
_toolView.layer.cornerRadius = 8;
_toolView.backgroundColor = kWhiteColor;
_toolView.model = [CNMinePresent datasourceToolModel:CNToolDatasourceTypeFirst carNum:self.carCount];
}
return _toolView;
}
- (UILabel *)versionLabel
{
if (!_versionLabel) {
_versionLabel = [[UILabel alloc] init];
_versionLabel.backgroundColor = kClearColor;
_versionLabel.textColor = UIColorHex(#999999);
_versionLabel.font = UIFontCNMake(14);
_versionLabel.textAlignment = NSTextAlignmentCenter;
_versionLabel.text = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
}
return _versionLabel;
}
- (CNEvaluaveView *)evaluateView
{
if (!_evaluateView) {
_evaluateView = [[CNEvaluaveView alloc] init];
weakself;
_evaluateView.showRecommend = ^{
strongself;
if (!self->_evaluateView.hidden) {
[self.view addSubview:self.recommend];
[self.recommend mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.evaluateView.mas_left);
make.centerY.equalTo(self.evaluateView).offset(-5);
make.width.mas_equalTo(103);
make.height.mas_equalTo(27);
}];
[self performBlock:^(id _Nonnull selfPtr) {
[self.recommend removeFromSuperview];
} afterDelay:3];
}
};
}
return _evaluateView;
}
- (CNRecommendView *)recommend
{
if (!_recommend) {
_recommend = [[CNRecommendView alloc] init];
[_recommend setImage:[UIImage imageNamed:@"recommend_bg"]];
}
return _recommend;
}
@end