CNLiveCommuntyUserListViewController.m
10 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
//
// CNLiveCommuntyUserListViewController.m
// CNLiveCommunitModule
//
// Created by open on 2022/2/7.
//
#import "CNLiveCommuntyUserListViewController.h"
@interface CNLiveCommuntyUserListViewController ()<CNLiveCommuntSignUpUserViewDelegate,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic, strong) NSMutableArray *userArray;
@property (nonatomic, strong) NSMutableArray *selectArray;
@property (nonatomic, strong) UIButton * payButton;
@property (nonatomic, strong) UIView * bottemView;
@property (nonatomic, copy) void(^completerBlock)(NSArray * userArray);
@end
@implementation CNLiveCommuntyUserListViewController
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
__weak typeof(self) weakSelf = self;
[CNLiveCommuntViewModel requestWithCommuntySaveInfoUsersMentUserDict:@{} isSave:NO isNew:NO CompleterBlock:^(NSArray * _Nonnull userArray, BOOL isSave) {
weakSelf.userArray = [[NSMutableArray alloc] initWithArray:userArray];
[weakSelf.tableView reloadData];
[weakSelf setupWithBottemView:weakSelf.selectArray.count > 0];
}];
}
- (instancetype)initWithStyle:(UITableViewStyle)style selectArray:(NSMutableArray *)selectArray CompleterBlock:(void(^)(NSArray * userArray))completerBlock
{
self = [super initWithStyle:style];
if (self) {
_selectArray = selectArray;
_completerBlock = completerBlock;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColorHex(#F9F9F9);
self.title = @"添加参与人";
UIButton * submiteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
submiteBtn.frame = CGRectMake(0, 0, 50, 14);
[submiteBtn setTitle:@"新增参与人" forState:UIControlStateNormal];
[submiteBtn setTitleColor:UIColorHex(#FD862E) forState:UIControlStateNormal];
submiteBtn.backgroundColor = [UIColor whiteColor];
submiteBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[submiteBtn addTarget:self action:@selector(rightBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:submiteBtn];
}
-(void)rightBarButtonAction:(UIButton *)button
{
CNLiveCommuntyUserEditViewController * editVC = [[CNLiveCommuntyUserEditViewController alloc] initWithUser:@{}];
[self.navigationController pushViewController:editVC animated:YES];
}
-(void)setupWithBottemView:(BOOL)isShow
{
if (!self.bottemView && !self.payButton) {
__weak typeof(self) weakSelf = self;
UIView * bottemView = [[UIView alloc] init];
bottemView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:bottemView];
bottemView.hidden = !isShow;
self.bottemView = bottemView;
[bottemView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(weakSelf.view);
make.height.mas_equalTo(50+kVerticalBottomSafeHeight);
}];
UIButton * payButton = [UIButton buttonWithType:UIButtonTypeCustom];
[payButton setTitle:@"确定" forState:UIControlStateNormal];
[payButton setTitle:@"确定" forState:UIControlStateHighlighted];
[payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
payButton.backgroundColor = UIColorHex(#CD0302);
payButton.layer.masksToBounds = YES;
payButton.layer.cornerRadius = 18;
payButton.hidden = !isShow;
payButton.titleLabel.font = [UIFont systemFontOfSize:16];
payButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[payButton addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventTouchUpInside];
[bottemView addSubview:payButton];
self.payButton = payButton;
[payButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(bottemView.mas_top).offset(7);
make.right.mas_equalTo(bottemView.mas_right).offset(-10);
make.height.mas_equalTo(36);
make.width.mas_equalTo(kScreenWidth - 30);
}];
}else{
self.bottemView.hidden = !isShow;
self.payButton.hidden = !isShow;
}
}
-(void)doneAction:(UIButton *)button
{
if (self.completerBlock) self.completerBlock(self.selectArray);
[self.navigationController popViewControllerAnimated:YES];
}
- (void)initTableView
{
[super initTableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.backgroundColor = UIColorHex(#F9F9F9);
self.tableView.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kNavigationBarHeight);
self.tableView.contentInset = UIEdgeInsetsMake(kNavigationBarHeight + 10, 0, 60 + kVerticalBottomSafeHeight, 0);
}
-(void)layoutTableView
{
[super layoutTableView];
}
/// 跳转删除人员
/// @param subDict 显示信息
-(void)setCommuntPushAddWithDelectUserViewController:(NSDictionary *)subDict{}
/// 跳转到编辑或添加人员界面
/// @param subDict 显示信息
-(void)setCommuntPushAddWithEditUserViewController:(NSDictionary *)subDict
{
CNLiveCommuntyUserEditViewController * editVC = [[CNLiveCommuntyUserEditViewController alloc] initWithUser:subDict];
[self.navigationController pushViewController:editVC animated:YES];
}
/// 选中相关参与人
/// @param subDict 显示信息
-(void)setCommuntSelectAddWithEditUserViewController:(NSDictionary *)subDict isSelect:(BOOL)isSelect
{
if (isSelect) {
[self.selectArray addObject:subDict];
}else{
if ([self.selectArray containsObject:subDict]) [self.selectArray removeObject:subDict];
}
[self setupWithBottemView:self.selectArray.count > 0];
}
#pragma mark - DZNEmptyDataSetSource Methods
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
return [[NSAttributedString alloc] initWithString:@"暂无参与人" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}];
}
-(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
return [CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_content_empty"];
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
{
return [UIColor whiteColor];
}
- (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.userArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CNLiveCommuntSignUpUserViewCell * userView = [CNLiveCommuntSignUpUserViewCell setTableView:tableView selectArray:self.selectArray isAddUser:YES UserDict:self.userArray[indexPath.row]];
userView.bottemLineLabel.hidden = (indexPath.row == self.userArray.count - 1);
userView.delegate = self;
return userView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return self.userArray.count == 0 ? 0 : 10;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (self.userArray.count > 0) {
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
view.backgroundColor = [UIColor clearColor];
UIView * radiusView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 10)];
radiusView.backgroundColor = [UIColor whiteColor];
radiusView.layer.shadowColor = [UIColor blackColor].CGColor;
radiusView.layer.shadowOffset = CGSizeMake(0, 0);
radiusView.layer.shadowOpacity = 0.3;
radiusView.layer.shadowRadius = 10;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 10) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.path = maskPath.CGPath;
radiusView.layer.mask = maskLayer;
[view insertSubview:radiusView belowSubview:view];
return view;
}else{
return nil;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return self.userArray.count == 0 ? 0 : 10;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (self.userArray.count > 0) {
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
view.backgroundColor = [UIColor clearColor];
UIView * radiusView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 10)];
radiusView.backgroundColor = [UIColor whiteColor];
radiusView.layer.shadowColor = [UIColor blackColor].CGColor;
radiusView.layer.shadowOffset = CGSizeMake(0, 0);
radiusView.layer.shadowOpacity = 0.3;
radiusView.layer.shadowRadius = 10;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 10) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.path = maskPath.CGPath;
radiusView.layer.mask = maskLayer;
[view insertSubview:radiusView belowSubview:view];
return view;
}else{
return [UIView new];
}
}
@end