//
|
// PBSelectedPersonController.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2021/1/8.
|
// Copyright © 2021 ProBIM. All rights reserved.
|
//
|
|
#import "PBSelectedPersonController.h"
|
#import "PBPersonVCTableViewCell.h"
|
#import "PBUserModel.h"
|
#import "PBAddExamineViewController.h"
|
static NSString *const cellID = @"cellID";
|
@interface PBSelectedPersonController ()<UITableViewDelegate, UITableViewDataSource>
|
@property (nonatomic, strong) UITableView *tableView;
|
@property (nonatomic, weak) UIButton *determineBtn;
|
@end
|
|
@implementation PBSelectedPersonController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self setupNav];
|
[self setupUI];
|
}
|
- (void)setupNav {
|
self.title = [NSString stringWithFormat:@"整改人 (%zd)",self.selectList.count];
|
UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Doc_preview_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)];
|
self.navigationItem.leftBarButtonItem = backNavItem;
|
}
|
- (void)backItemAction {
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
- (void)setupUI {
|
self.view.backgroundColor = PBColor(244, 245, 246);
|
self.tableView = [[UITableView alloc] init];
|
self.tableView.backgroundColor = PBColor(244, 245, 246);
|
self.tableView.dataSource = self;
|
self.tableView.delegate = self;
|
self.tableView.bounces = NO;
|
self.tableView.rowHeight = 56;
|
self.tableView.sectionIndexColor = PBColor(97, 111, 125);
|
UITableView *footerV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
if (@available(iOS 15.0, *)) {
|
footerV.sectionHeaderTopPadding = 0;
|
};
|
self.tableView.tableFooterView = footerV;
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
[self.tableView registerClass:[PBPersonVCTableViewCell class] forCellReuseIdentifier:cellID];
|
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 56, 0);
|
[self.view addSubview:self.tableView];
|
CGFloat bottomH = 0.f;
|
if (IS_IPHONE_X) {
|
bottomH = 0.f + IPHONE_X_BOTTOM;
|
}
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.view);
|
make.left.right.equalTo(self.view);
|
make.bottom.equalTo(self.view).offset(-(bottomH));
|
}];
|
|
UIView *bottomV = [[UIView alloc] init];
|
bottomV.backgroundColor = [UIColor whiteColor];
|
[self.view addSubview:bottomV];
|
[bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.left.bottom.right.equalTo(self.tableView);
|
make.height.equalTo(@54);
|
}];
|
|
UIButton *determineBtn = [UIButton z_textButton:[NSString stringWithFormat:@"确定(%zd)",self.selectList.count] boldFontSize:14 normalColor:[UIColor whiteColor]];
|
[determineBtn addTarget:self action:@selector(determineBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
determineBtn.backgroundColor = PBColor(0, 122, 255);
|
[self.view addSubview:determineBtn];
|
[determineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bottomV).offset(9);
|
make.right.equalTo(bottomV).offset(-20);
|
make.size.mas_equalTo(CGSizeMake(89, 34));
|
}];
|
[determineBtn circleViewWithRadius:6];
|
self.determineBtn = determineBtn;
|
}
|
- (void)determineBtnAction {
|
[PBNoteCenter postNotificationName:PBNoteCenterUpdatePerson object:self.selectList.copy];
|
[self backAction];
|
}
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.selectList.count;
|
}
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
PBPersonVCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
PBUserModel *userModel = self.selectList[indexPath.row];
|
cell.userModel = userModel;
|
return cell;
|
}
|
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
return YES;
|
}
|
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
|
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
|
//先删数据 再删UI
|
[self.selectList removeObjectAtIndex:indexPath.row];
|
self.title = [NSString stringWithFormat:@"整改人 (%zd)",self.selectList.count];
|
[self.determineBtn setTitle:[NSString stringWithFormat:@"确定(%zd)",self.selectList.count] forState:UIControlStateNormal];
|
if (self.selectList.count == 0) {
|
self.determineBtn.enabled = NO;
|
}
|
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
[tableView reloadData];
|
}];
|
return @[deleteAction];
|
}
|
-(void)backAction{
|
UINavigationController *navVC = self.navigationController;
|
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
|
for (UIViewController *vc in [navVC viewControllers]) {
|
[viewControllers addObject:vc];
|
if ([vc isKindOfClass:[PBAddExamineViewController class]]) {
|
break;
|
}
|
}
|
[navVC setViewControllers:viewControllers animated:YES];
|
}
|
- (void)setSelectList:(NSMutableArray *)selectList {
|
_selectList = selectList;
|
if (selectList == nil) {
|
_selectList = [[NSMutableArray alloc] init];
|
}
|
}
|
/*
|
#pragma mark - Navigation
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
// Get the new view controller using [segue destinationViewController].
|
// Pass the selected object to the new view controller.
|
}
|
*/
|
|
@end
|