CNLiveCommuntyUserListViewController.m 9.66 KB
//
//  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, 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.userArray.count > 0];
    }];
}

- (instancetype)initWithStyle:(UITableViewStyle)style CompleterBlock:(void(^)(NSArray * userArray))completerBlock
{
    self = [super initWithStyle:style];
    if (self) {
        _completerBlock = completerBlock;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColorHex(#F9F9F9);
    self.title = @"添加参与人";
    
    self.selectArray = [[NSMutableArray alloc] init];
    
    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 (isShow) {
        __weak typeof(self) weakSelf = self;
        UIView * bottemView = [[UIView alloc] init];
        bottemView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview: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.titleLabel.font = [UIFont systemFontOfSize:16];
        payButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [payButton addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventTouchUpInside];
        [bottemView addSubview: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{
        UIView * bottemView = [[UIView alloc] initWithFrame:CGRectZero];
        bottemView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:bottemView];
    }
}
-(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];
    }
}
#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 isAddUser:YES UserDict:self.userArray[indexPath.row]];
    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