CNBPerAuthSuccessController.m
11.2 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
//
// CNBPerAuthSuccessController.m
// CNLiveBPersonalVerificationModule
//
// Created by 殷巧娟 on 2020/4/14.
//
#import "CNBPerAuthSuccessController.h"
#import "CNBPersonalInfoCell.h"
#import "UIColor+CNLiveExtension.h"
#import "CNLiveBaseKit.h"
#import "CNBPerAuthHeaderView.h"
#import "CNBPerAuthViewModel.h"
#import "CNBPerCertificationSuccessModel.h"
#import "CNEmptyView.h"
#import "CNLivePerAuthGetImage.h"
#import "MJExtension.h"
typedef NS_ENUM(NSUInteger,CNBPerAuthErrorType) {
CNBPerAuthErrorTypeNoNet, //没网
CNBPerAuthErrorTypeFail, //请求失败
CNBPerAuthErrorTypeNoData //没数据
};
static NSString *infoIdentifier = @"CNBPersonalInfoCell";
static NSString *normalIdentifier = @"CNBInstitutionsInfoCell";
static NSString *groupIdentifier = @"CNBGroupInfoCell";
@interface CNBPerAuthSuccessController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *institutionArray;
@property (nonatomic, strong) CNBUserInfoModel *infoModel;
@property (nonatomic, strong) NSMutableArray *circleArray;
@property (nonatomic, strong) CNEmptyView *successEmptyView;
@property (nonatomic, strong) NSDictionary *data; //后台返回的数据
@end
@implementation CNBPerAuthSuccessController
- (instancetype)initControllerWithParam:(NSDictionary *)param {
self = [super init];
if (self) {
_data = param;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.tableView];
self.title = @"身份校验";
if (self.data && [self.data isKindOfClass:[NSDictionary class]] && self.data.count > 0) {
if ([[self.data allKeys] containsObject:@"institution"]) {
NSArray *array = self.data[@"institution"];
if (array.count > 0 ) {
CNBPerCertificationSuccessModel *successModel = [CNBPerCertificationSuccessModel mj_objectWithKeyValues:self.data];
self.infoModel = successModel.bUserIdentity;
for (CNBInstitutionModel *model in successModel.institution) {
[self.institutionArray addObject:model];
}
[self.institutionArray insertObject:successModel.bUserIdentity atIndex:0];
[self.tableView reloadData];
}else {
[self requestPerAuthSuccessData];
}
}else {
[self requestPerAuthSuccessData];
}
}else {
[self requestPerAuthSuccessData];
}
}
#pragma mark - 请求数据
- (void)requestPerAuthSuccessData {
__weak typeof(self) weakSelf = self;
[CNBPerAuthViewModel getPerAuthSuccessList:^(NSMutableArray * _Nonnull dataArray) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
return ;
}
if (dataArray.count > 0) {
CNBPerCertificationSuccessModel *successModel = dataArray[0];
if (successModel.bUserIdentity && successModel.institution.count > 0) {
strongSelf.infoModel = successModel.bUserIdentity;
for (CNBInstitutionModel *model in successModel.institution) {
[strongSelf.institutionArray addObject:model];
}
[strongSelf.emptyView removeFromSuperview ];
strongSelf.tableView.tableFooterView = [UIView new];
[strongSelf.institutionArray insertObject:successModel.bUserIdentity atIndex:0];
[strongSelf.tableView reloadData];
}else {
[strongSelf showEmptyView:CNBPerAuthErrorTypeNoData];
}
}else {
[strongSelf showEmptyView:CNBPerAuthErrorTypeNoData];
}
} failureBlock:^(NSError * _Nonnull error) {
if (error.code == -1009 || error.code == -1001) {
[weakSelf showEmptyView:CNBPerAuthErrorTypeNoNet];
}else {
[weakSelf showEmptyView:CNBPerAuthErrorTypeFail];
}
}];
}
#pragma mark - 重试
- (void)retryloadData {
[self requestPerAuthSuccessData];
}
#pragma mark - 展示空视图
- (void)showEmptyView:(CNBPerAuthErrorType)errorType {
NSString *titleName = @"";
NSString *imageName = @"";
NSString *retryName = @"";
if (errorType == CNBPerAuthErrorTypeNoNet) {
imageName = @"dd_wlcw";
titleName = @"网络开小差了,刷新试试";
retryName = @"刷新";
}else if (errorType == CNBPerAuthErrorTypeFail) {
imageName = @"wufalianjie";
titleName = @"接口开小差了,试试重新请求";
retryName = @"重试";
}else if (errorType == CNBPerAuthErrorTypeNoData) {
imageName = @"zhuangtai_kong";
titleName = @"暂无您的身份内容";
retryName = @"";
}
[self.successEmptyView showImage:[CNLivePerAuthGetImage cnLivePerAuth_getImageName:imageName bundle:@"CNLiveBPersonalVerificationModule.bundle/CNLiveBPersonalVerificationModule" targetClass:[self class]] title:titleName detailTitle:@"" retryBtnTitle:retryName];
BOOL isHidden = errorType == CNBPerAuthErrorTypeNoData;
self.successEmptyView.retryBtn.hidden = isHidden;
self.successEmptyView.retryBtn.backgroundColor = kWhiteColor;
self.successEmptyView.retryBtn.layer.masksToBounds = YES;
self.successEmptyView.retryBtn.layer.cornerRadius = 14;
self.successEmptyView.retryBtn.layer.borderWidth = 1;
self.successEmptyView.retryBtn.layer.borderColor = CNLiveColorWithHexString(@"48A7F9").CGColor;
[self.successEmptyView.retryBtn setTitleColor:CNLiveColorWithHexString(@"48A7F9") forState:UIControlStateNormal];
[self.successEmptyView.retryBtn setTitleColor:CNLiveColorWithHexString(@"48A7F9") forState:UIControlStateHighlighted];
errorType == CNBPerAuthErrorTypeNoData ? self.tableView.tableFooterView = self.successEmptyView :[self.view addSubview:self.successEmptyView];
[self.successEmptyView.retryBtn addTarget:self action:@selector(retryloadData) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark - tableViewDelegateAndDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.institutionArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
CNBInstitutionModel *model = [[CNBInstitutionModel alloc]init];
if (self.institutionArray.count > 0) {
model = self.institutionArray[section];
}
if (section == 0) {
return 1;
}else {
return model.quanziItem.count > 0 ? (model.quanziItem.count + 1):2;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
CNBPersonalInfoCell *infoCell = [tableView dequeueReusableCellWithIdentifier:infoIdentifier];
if (!infoCell) {
infoCell = [[CNBPersonalInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:infoIdentifier];
}
infoCell.infoModel = self.infoModel;
return infoCell;
}else {
if (indexPath.row == 0) {
CNBInstitutionsInfoCell *normalCell = [tableView dequeueReusableCellWithIdentifier:normalIdentifier];
if (!normalCell) {
normalCell = [[CNBInstitutionsInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:normalIdentifier];
}
normalCell.institutionModel = self.institutionArray[indexPath.section];
return normalCell;
}else {
CNBGroupInfoCell *groupCell = [tableView dequeueReusableCellWithIdentifier:groupIdentifier];
if (!groupCell) {
groupCell = [[CNBGroupInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:groupIdentifier];
}
CNBInstitutionModel *model = self.institutionArray[indexPath.section];
NSArray *circleArray = model.quanziItem;
if (circleArray.count > 0) {
groupCell.circleModel = circleArray[indexPath.row -1];
}else {
CNBCirccleModel *circleModel = [[CNBCirccleModel alloc]init];
circleModel.quanziName = @"无";
NSMutableArray *groupArray = [NSMutableArray array];
NSArray *noneArray = @[@{@"groupId":@"",@"groupName":@"无"},
];
for (NSDictionary *dic in noneArray) {
CNBGroupModel *model = [CNBGroupModel mj_objectWithKeyValues:dic];
[groupArray addObject:model];
}
circleModel.groupItem = groupArray;
groupCell.circleModel = circleModel;
}
return groupCell;
}
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return 232;
}else {
if (indexPath.row == 0) {
return 40;
}else {
return UITableViewAutomaticDimension;
}
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0) {
return [UIView new];
}else {
CNBPerAuthHeaderView *headerView = [[CNBPerAuthHeaderView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 41)];
headerView.backgroundColor = [UIColor whiteColor];
return headerView;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0) {
return 0.01;
}else {
return 41;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 10)];
view.backgroundColor = CNLiveColorWithHexString(@"F2F2F2");
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 10;
}
#pragma mark - Lazy
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,kNavigationBarHeight , KScreenWidth, KScreenHeight - kNavigationBarHeight) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = CNLiveColorWithHexString(@"F2F2F2");
_tableView.estimatedRowHeight = 70;
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
}
return _tableView;
}
- (NSMutableArray *)institutionArray {
if (!_institutionArray) {
_institutionArray = [NSMutableArray array];
}
return _institutionArray;
}
- (NSMutableArray *)circleArray {
if (!_circleArray) {
_circleArray = [NSMutableArray array];
}
return _circleArray;
}
- (CNEmptyView *)successEmptyView {
if (!_successEmptyView) {
_successEmptyView= [[CNEmptyView alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, KScreenWidth, KScreenHeight - kNavigationBarHeight) type:0];
_successEmptyView.backgroundColor = [UIColor whiteColor];
}
return _successEmptyView;
}
@end