CNLiveMyServicesVC.m
8.02 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
//
// CNLiveMyServicesVC.m
// CNLiveCServiceModule
//
// Created by CNLive on 2021/11/26.
//
#import "CNLiveMyServicesVC.h"
#import "CNLiveServicePresent.h"
#import "CNLiveSearchModel.h"
#import "CNLiveSearchHotsCell.h"
@interface CNLiveMyServicesVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) CNLiveNavigationBar *navigationBar;
@property (nonatomic ,strong) NSArray *dataSource;
@property (nonatomic, strong) UICollectionView *listCollectionView;
@property (nonatomic, assign) NSInteger page;
@end
static NSString *HotListCellID = @"HotListCellID";
@implementation CNLiveMyServicesVC
+ (instancetype)myServiceVC
{
CNLiveMyServicesVC *myService = [[CNLiveMyServicesVC alloc] init];
[[BaseAppDelegate sharedAppDelegate] pushViewController:myService withBackTitle:@""];
return myService;
}
- (void)myServiceData{
if (self.page == 1) {
self.dataSource = @[];
[self.listCollectionView reloadData];
}
if (![CNLiveNetworking isNetworking]) {
self.listCollectionView.mj_footer.hidden = YES;
if (self.dataSource.count > 0) {
return;
}
[self showEmptyViewWithImage:[UIImage loadCServiceBundle:@"service_noNet"] text:@"网络开小差了,刷新试试" detailText:nil buttonTitle:@" 刷新 " buttonAction:@selector(myServiceData)];
self.emptyView.frame = CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop);
[self setCNAPIErrorEmptyView];
return;
}
[QMUITips showLoadingInView:self.view];
weakself
[CNLiveServicePresent loadMyServicepage:[NSString stringWithFormat:@"%ld",_page] result:^(NSArray * _Nonnull dataArray, BOOL isLastPage) {
strongself
[self.listCollectionView.mj_footer endRefreshing];
[QMUITips hideAllTipsInView:self.view];
if (!dataArray||dataArray.count <= 0) {
if (self.dataSource.count > 0) {
return;
}
self.listCollectionView.mj_footer.hidden = YES;
self.navigationBar.right.hidden = YES;
[self showEmptyViewWithImage:[UIImage loadCServiceBundle:@"service_noMsg"] text:@"暂无内容" detailText:nil buttonTitle:NULL buttonAction:NULL];
self.emptyView.frame = CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop);
[self setCNAPIErrorEmptyView];
}else{
self.listCollectionView.mj_footer.hidden = NO;
[self removeEmptyView];
if (isLastPage) {
[self.listCollectionView.mj_footer endRefreshingWithNoMoreData];
}else{
[self.listCollectionView.mj_footer endRefreshing];
}
self.navigationBar.right.hidden = NO;
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:self.dataSource];
for (id object in dataArray) {
[array addObject:object];
}
self.dataSource = array.copy;
[self.listCollectionView reloadData];
}
} error:^{
[QMUITips hideAllTipsInView:self.view];
[self.listCollectionView.mj_footer endRefreshing];
self.listCollectionView.mj_footer.hidden = YES;
strongself
self.navigationBar.right.hidden = YES;
[self showEmptyViewWithImage:[UIImage loadCServiceBundle:@"service_failure"] text:@"加载失败,请点击重试" detailText:nil buttonTitle:@" 重试 " buttonAction:@selector(myServiceData)];
self.emptyView.frame = CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop);
[self setCNAPIErrorEmptyView];
}];
}
-(void)removeEmptyView
{
[self.emptyView removeFromSuperview];
self.emptyView = nil;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = kWhiteColor;
[self.view addSubview:self.navigationBar];
[self.view addSubview:self.listCollectionView];
_page = 1;
[self myServiceData];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.listCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.navigationBar.mas_bottom);
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.mas_bottomLayoutGuide);
}];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.navigationBarHidden = NO;
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
CNLiveSearchModel *model1 = self.dataSource[indexPath.row];
[CNLiveCServiceManagerBridge jumpServiceController:model1.id showAgreement:model1.showAgreement agreementDesc:model1.agreementDesc type:model1.type to:model1.to shopType:model1.shopType controller:self];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataSource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CNLiveSearchHotsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HotListCellID forIndexPath:indexPath];
cell.model = self.dataSource[indexPath.row];
return cell;
}
#pragma mark - Getting
- (UICollectionView *)listCollectionView
{
if (!_listCollectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake((SCREEN_WIDTH-2*15)/4.0, 80);
layout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
layout.minimumInteritemSpacing = 0;
_listCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_listCollectionView.backgroundColor = kWhiteColor;
_listCollectionView.collectionViewLayout = layout;
_listCollectionView.delegate = self;
_listCollectionView.dataSource = self;
_listCollectionView.showsVerticalScrollIndicator = NO;
[_listCollectionView registerClass:[CNLiveSearchHotsCell class] forCellWithReuseIdentifier:HotListCellID];
weakself
MJRefreshAutoNormalFooter *loadFooter = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
strongself
self.page ++;
[self myServiceData];
}];
_listCollectionView.mj_footer = loadFooter;
}
return _listCollectionView;
}
#pragma mark - Navigation
- (CNLiveNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [CNLiveNavigationBar navigationBar];
_navigationBar.title.text = @"我的服务";
weakself
_navigationBar.onClickLeftButton = ^{
strongself
[self.navigationController popViewControllerAnimated:YES];
};
[_navigationBar.right setTitleColor:CNLiveColorWithHexString(@"#F5A623") forState:UIControlStateNormal];
_navigationBar.rightTitle = @"清空";
_navigationBar.onClickRightButton = ^{
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"确认清空所有服务吗?" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:NULL];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[CNLiveServicePresent removeMyServiceResult:^{
strongself
[self myServiceData];
}];
}];
[alertVC addAction:cancel];
[alertVC addAction:sure];
[weakSelf presentViewController:alertVC animated:YES completion:NULL];
};
}
return _navigationBar;
}
@end