// // PBPersonChooseTableViewCell.m // IphoneBIMe // // Created by zjf on 2020/12/3. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBPersonChooseTableViewCell.h" #import "PBExamineAddModel.h" #import "PBPersonListView.h" #import "PBPersonModel.h" #import "LBKeyWordLayout.h" #import "KeyWordCell.h" #import "PBPersonListCollectionViewCell.h" static NSString *const cellId = @"cellId"; @interface PBPersonChooseTableViewCell() @property (nonatomic,strong) UICollectionView *collection; @property (nonatomic,strong) NSMutableArray *data; //@property (nonatomic,copy) selectedHandler handler; @property (nonatomic, weak) UILabel *titleL; @property (nonatomic, weak) UILabel *personL; @property (nonatomic, weak) UIButton *chooseBtn; @property (nonatomic, weak) UIButton *totalNumberBtn; @property (nonatomic, weak) UIView *collectionBg; @property (nonatomic, assign) BOOL isLayout; @property (nonatomic, assign) CGFloat height; @property (strong, nonatomic) LBKeyWordLayout *layout; @end @implementation PBPersonChooseTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setupUI]; } return self; } - (void)setupUI { // self.contentView.backgroundColor = [UIColor blueColor]; UILabel *titleL = [UILabel z_labelWithText:@"检查人" Color:PBColor(102, 102, 102) isBold:NO Font:15]; [self.contentView addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(15); make.left.equalTo(self.contentView).offset(15); make.width.equalTo(@100); make.height.equalTo(@18); }]; UILabel *personL = [UILabel z_labelWithText:@"请指定检查人" Color:PBColor(79, 40, 58) isBold:NO Font:15]; [self.contentView addSubview:personL]; [personL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(116); make.right.equalTo(self.contentView).offset(-15); make.top.equalTo(titleL); make.height.equalTo(@18); }]; UIButton *chooseBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"set_arrow_right"]]; [chooseBtn addTarget:self action:@selector(chooseTime) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:chooseBtn]; [chooseBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(titleL); make.size.mas_equalTo(CGSizeMake(16, 16)); make.right.equalTo(self.contentView).offset(-15); }]; UIButton *btn = [[UIButton alloc] init]; [btn addTarget:self action:@selector(chooseTime) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:btn]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.bottom.equalTo(self.contentView); }]; self.titleL = titleL; self.personL = personL; self.chooseBtn = chooseBtn; self.layout = [[LBKeyWordLayout alloc] init]; self.layout.estimatedItemSize = CGSizeMake(80, 30); self.layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10); self.collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.layout]; self.collection.backgroundColor = [UIColor whiteColor]; // self.collection.allowsMultipleSelection = YES; self.collection.delegate = self; self.collection.dataSource = self; // self.collection.scrollEnabled = NO; [self.collection registerClass:[KeyWordCell class] forCellWithReuseIdentifier:@"KeyWordCell"]; [self.contentView addSubview:self.collection]; [self.collection mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.left.right.bottom.equalTo(collectionBg); make.top.equalTo(self.contentView).offset(53); make.left.equalTo(self.contentView).offset(100); make.right.equalTo(self.contentView).offset(-20); make.height.equalTo(@1); make.bottom.equalTo(self.contentView).offset(-15); }]; UIButton *totalNumberBtn = [[UIButton alloc] init]; [totalNumberBtn addTarget:self action:@selector(totalNumberBtnAction) forControlEvents:UIControlEventTouchUpInside]; [totalNumberBtn setTitle:@"查看全部" forState:UIControlStateNormal]; [totalNumberBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; totalNumberBtn.backgroundColor = PBColor(0, 122, 255); [self.contentView addSubview:totalNumberBtn]; [totalNumberBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.collection.mas_bottom); make.left.equalTo(personL); make.height.equalTo(@32); }]; totalNumberBtn.layer.cornerRadius = 6; totalNumberBtn.layer.masksToBounds = YES; self.totalNumberBtn = totalNumberBtn; self.totalNumberBtn.hidden = YES; // self.collectionBg = collectionBg; } - (void)totalNumberBtnAction { NSLog(@"查看全部人员"); if (self.LookAllBlock) { self.LookAllBlock(); } } - (void)chooseTime { if (self.ChooseBlock) { self.ChooseBlock(); } } - (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel { _examineAddModel = examineAddModel; self.data = [[NSMutableArray alloc] init]; self.data = examineAddModel.personArr.mutableCopy; [self.collection reloadData]; [self.collection layoutIfNeeded]; if (self.examineAddModel.personArr.count > 0) { [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(70)); }]; }else { [self.collection mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(1)); }]; } self.titleL.text = examineAddModel.title; if (examineAddModel.personArr.count > 0) { self.personL.textColor = PBColor(40, 58, 79); self.personL.text = [NSString stringWithFormat:@"已选择%zd人", examineAddModel.personArr.count]; }else { self.personL.textColor = PBColor(204, 204, 204); self.personL.text = examineAddModel.prompt; } } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.data.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { KeyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KeyWordCell" forIndexPath:indexPath]; cell.maxWidthConstraint.constant = CGRectGetWidth(collectionView.bounds) - self.layout.sectionInset.left - self.layout.sectionInset.right - cell.layoutMargins.left - cell.layoutMargins.right - 10; cell.textLabel.numberOfLines = 1; PBPersonModel *model = self.data[indexPath.item]; cell.textLabel.text = model.RealName; return cell; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end