CNLiveCommuntListViewController.m
12.3 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
//
// CNLiveCommuntListViewController.m
// CNLiveCommunitModule
//
// Created by open on 2022/2/1.
//
#import "CNLiveCommuntListViewController.h"
#import "CNLiveCommuntPaycostViewController.h"
#import "CNLiveCommuntSignUpViewController.h"
@interface CNLiveCommuntListViewController ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic, assign) CNLiveCommuntListShowType showType;
@property (nonatomic, strong) MJRefreshAutoNormalFooter * footerView;
@property (nonatomic, strong) NSMutableArray * dataArray;
@property (nonatomic, strong) NSIndexPath * selectIndexPath;
@property (nonatomic, copy) NSString * nbhdId;
@property (nonatomic, assign) NSInteger index;
@property (nonatomic, assign) NSInteger page;
@end
@implementation CNLiveCommuntListViewController
- (instancetype)initWithShowType:(CNLiveCommuntListShowType)showType Index:(NSInteger)index NBhdId:(NSString *)nbhdId
{
self = [super init];
if (self) {
_nbhdId = nbhdId;
_index = index;
_showType = showType;
}
return self;
}
/// 初始化界面显示
/// @param nbhdId 小区id
- (instancetype)initWithShowType:(CNLiveCommuntListShowType)showType NBhdId:(NSString *)nbhdId
{
self = [super init];
if (self) {
_nbhdId = nbhdId;
_page = 1;
_showType = showType;
}
return self;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.page = 1;
[self loadDataSourceWithPage:1 nbhdId:self.nbhdId index:self.index CompleterBlock:NULL];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColorHex(#F9F9F9);
self.dataArray = [[NSMutableArray alloc] init];
[self addRefreshMainView];
if (self.showType == CNLiveCommuntListShowTypePayCost) self.title = @"缴费记录";
}
-(void)addRefreshMainView
{
__weak typeof(self) weakSelf = self;
self.tableView.mj_header = [CNLiveRefreshHeader headerWithRefreshingBlock:^{
weakSelf.page = 1;
[weakSelf loadDataSourceWithPage:1 nbhdId:weakSelf.nbhdId index:weakSelf.index CompleterBlock:NULL];
}];
self.footerView = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
weakSelf.page ++;
[weakSelf loadDataSourceWithPage:weakSelf.page nbhdId:weakSelf.nbhdId index:weakSelf.index CompleterBlock:NULL];
}];
}
-(void)loadDataSourceWithPage:(NSInteger)page nbhdId:(NSString *)nbhdId index:(NSInteger)index CompleterBlock:(void(^)(void))completerBlock
{
__weak typeof(self) weakSelf = self;
[CNLiveCommuntViewModel requestWithCommuntyHomeActivityForNBHdId:nbhdId ShowType:self.showType Index:index Page:page completerBlock:^(NSArray * _Nonnull dataArray, BOOL isLastPage) {
if (dataArray.count > 0 && page == 1 && !weakSelf.tableView.mj_footer) weakSelf.tableView.mj_footer = weakSelf.footerView;
if (page == 1) [weakSelf.dataArray removeAllObjects];
[weakSelf.dataArray addObjectsFromArray:dataArray];
[weakSelf.tableView reloadData];
[weakSelf.tableView.mj_header endRefreshing];
[weakSelf.tableView.mj_footer endRefreshing];
if (isLastPage) [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
if (page == 1 && weakSelf.dataArray.count == 0 && weakSelf.tableView.mj_footer) weakSelf.tableView.mj_footer = nil;
// if (weakSelf.selectIndexPath) {
// BOOL isEnough = weakSelf.dataArray.count <= weakSelf.selectIndexPath.row;
// if (!isEnough) weakSelf.selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
// [weakSelf.tableView scrollToRowAtIndexPath:weakSelf.selectIndexPath atScrollPosition:isEnough?UITableViewScrollPositionNone:UITableViewScrollPositionTop animated:NO];
// }
}];
}
- (void)initTableView
{
[super initTableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.backgroundColor = UIColorHex(#f9f9f9);
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// __weak typeof(self) weakSelf = self;
// [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.mas_equalTo(weakSelf.view).offset(kNavigationBarHeight+44);
// make.left.right.bottom.mas_equalTo(weakSelf.view);
// }];
}
-(void)initSubviews
{
[super initSubviews];
}
-(void)layoutTableView
{
[super layoutTableView];
if (self.showType == CNLiveCommuntListShowTypePayCost) {
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kNavigationBarHeight);
}else{
__weak typeof(self) weakSelf = self;
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(weakSelf.view).offset(kNavigationBarHeight+44);
make.left.right.bottom.mas_equalTo(weakSelf.view);
}];
}
}
-(void)dealloc
{
self.selectIndexPath = nil;
}
#pragma mark - DZNEmptyDataSetSource Methods
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
NSString * string = @"";
if (self.showType == CNLiveCommuntListShowTypeHome) string = @"暂无内容";
if (self.showType == CNLiveCommuntListShowTypeRecord) string = @"亲,您还没有活动记录哦~";
if (self.showType == CNLiveCommuntListShowTypeRepair) string = @"亲,您还没有报修记录哦~";
if (self.showType == CNLiveCommuntListShowTypePayCost) string = @"亲,您还没有缴费记录哦~";
return [[NSAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}];
}
-(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
return [CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_content_empty"];
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
{
return [UIColor whiteColor];
}
- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state
{
NSString * nb_info = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"kCNLiveCommuntyNBhdInfoIdentifier%@",[CNUserInfoManager manager].userInfoModel.uid]];
NSString * idStr = [[nb_info mj_JSONObject] stringValueForKey:@"id" default:@""];
if (self.showType == CNLiveCommuntListShowTypeRepair && [idStr isNotBlank]) {
return [[NSAttributedString alloc] initWithString:@"我要报修" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:UIColorHex(#CD0302)}];
}else{
return nil;
}
}
- (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button
{
NSString * nb_info = (NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"kCNLiveCommuntyNBhdInfoIdentifier%@",[CNUserInfoManager manager].userInfoModel.uid]];
NSString * idStr = [[nb_info mj_JSONObject] stringValueForKey:@"id" default:@""];
if (self.showType == CNLiveCommuntListShowTypeRepair && [idStr isNotBlank]) {
NSLog(@"点击界面了");
CNLiveCommuntInformViewController * informView = [[CNLiveCommuntInformViewController alloc] initWithNBhdId:idStr];
[self.navigationController pushViewController:informView animated:YES];
}
}
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
{
return 0;
}
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
{
return YES;
}
- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView
{
return YES;
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
return NO;
}
#pragma mark =
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.showType == CNLiveCommuntListShowTypeRecord) {
CNLiveCommuntyActivityRecordListModel * recordModel = self.dataArray[indexPath.row];
recordModel.index = [NSString stringWithFormat:@"%ld",(long)self.index];
return [CNLiveCommuntSubRecordTableView setTableView:tableView RecordModel:recordModel];
}
if (self.showType == CNLiveCommuntListShowTypeHome) {
CNLiveCommuntyActivityHomeListModel * listModel = self.dataArray[indexPath.row];
return [CNLiveCommuntSubHomeTableView setTableView:tableView ListModel:listModel];
}
if (self.showType == CNLiveCommuntListShowTypeRepair) {
CNLiveCommuntyActivityRepairListModel * repairModel = self.dataArray[indexPath.row];
return [CNLiveCommuntSubRepairTableView setTableView:tableView RepairModel:repairModel];
}
if (self.showType == CNLiveCommuntListShowTypePayCost) {
CNLiveCommuntyActivityPaycostListModel * paycostModel = self.dataArray[indexPath.row];
return [CNLiveCommuntPayCostListViewCell setTableView:tableView payCostModel:paycostModel];
}
return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.showType == CNLiveCommuntListShowTypeRecord) {
return 110.0;
}
if (self.showType == CNLiveCommuntListShowTypeHome) {
return 190.0;
}
if (self.showType == CNLiveCommuntListShowTypeRepair) {
CNLiveCommuntyActivityRepairListModel * repairModel = self.dataArray[indexPath.row];
CGFloat itemW = repairModel.imgs.count > 0 ? (kScreenWidth - 60)/3 + 20 : 0;
return ([repairModel.status isEqualToString:@"3"] && [repairModel.totalFee integerValue] > 0?110.0:70.0) + itemW;
}
if (self.showType == CNLiveCommuntListShowTypePayCost) {
CNLiveCommuntyActivityPaycostListModel * paycostModel = self.dataArray[indexPath.row];
return [paycostModel.payStatus isEqualToString:@"0"] || [paycostModel.payType isEqualToString:@"2"] ? 120.0 : 80.0;
}
return 0.001;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.showType == CNLiveCommuntListShowTypeRepair) {
self.selectIndexPath = indexPath;
CNLiveCommuntyActivityRepairListModel * repairModel = self.dataArray[indexPath.row];
if (self.index == 3) {
CNLiveCommuntyOrderViewController * orderView = [[CNLiveCommuntyOrderViewController alloc] initWithShowType:CNLiveCommuntyOrderShowTypeListCompletOrder MaintenId:repairModel.idStr];
[self.navigationController pushViewController:orderView animated:YES];
}else if (self.index == 2) {
CNLiveCommuntyOrderViewController * orderView = [[CNLiveCommuntyOrderViewController alloc] initWithShowType:CNLiveCommuntyOrderShowTypeListFailureOrder MaintenId:repairModel.idStr];
[self.navigationController pushViewController:orderView animated:YES];
}else {
CNLiveCommuntyOrderViewController * orderView = [[CNLiveCommuntyOrderViewController alloc] initWithShowType:self.index MaintenId:repairModel.idStr];
[self.navigationController pushViewController:orderView animated:YES];
}
}
if (self.showType == CNLiveCommuntListShowTypeRecord) {
self.selectIndexPath = indexPath;
CNLiveCommuntyActivityRecordListModel * repairModel = self.dataArray[indexPath.row];
[[CNLiveCommuntyModule shareInstance].protocol pushWebViewWithMainProjectWithActivityId:repairModel.handworkId];
}
if (self.showType == CNLiveCommuntListShowTypeHome) {
self.selectIndexPath = indexPath;
CNLiveCommuntyActivityHomeListModel * listModel = self.dataArray[indexPath.row];
[[CNLiveCommuntyModule shareInstance].protocol pushWebViewWithMainProjectWithActivityId:listModel.idStr];
}
if (self.showType == CNLiveCommuntListShowTypePayCost) {
CNLiveCommuntyActivityPaycostListModel * paycostModel = self.dataArray[indexPath.row];
CNLiveCommuntPaycostViewController * paycostView = [[CNLiveCommuntPaycostViewController alloc] initWithPayCostId:paycostModel.idStr];
[self.navigationController pushViewController:paycostView animated:YES];
}
}
- (UIView *)listView {
return self.view;
}
@end