//
|
// PBPersonTableViewCell.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2018/8/16.
|
// Copyright © 2018年 ProBIM. All rights reserved.
|
//
|
|
#import "PBPersonTableViewCell.h"
|
#import "PBPersonCollectionViewCell.h"
|
#import "PBIssueAddModel.h"
|
#import "PBPersonModel.h"
|
#import "PBExamineAddModel.h"
|
#import "PBTagModel.h"
|
#define ItemWidth 120
|
#define ItemHeight 34
|
#define LineSpacing 6
|
#define InteritemSpacing 6
|
static NSString *cellID = @"cellID";
|
|
@interface PBPersonTableViewCell()<UICollectionViewDataSource>
|
@property (nonatomic, weak) UILabel *titleL;
|
@property (nonatomic, weak) UILabel *promteL;
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
@property (nonatomic, assign) NSInteger aLineCount;
|
@property (nonatomic, assign) BOOL isIssue;
|
@end
|
@implementation PBPersonTableViewCell
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
[self setupUI];
|
}
|
return self;
|
}
|
|
- (void)setupUI {
|
UILabel *titleL = [UILabel z_labelWithText:@"负责人" Color:PromptColor isBold:NO Font:DescFontSize];
|
titleL.textAlignment = NSTextAlignmentCenter;
|
[self.contentView addSubview:titleL];
|
[titleL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.contentView).offset(10);
|
make.left.right.equalTo(self.contentView);
|
make.height.equalTo(@20);
|
}];
|
|
if (PBScreenWidth > 320) {
|
_aLineCount = 3;
|
}else {
|
_aLineCount = 2;
|
}
|
CGFloat margin = (PBScreenWidth - ((ItemWidth * _aLineCount) + ((_aLineCount - 1) * LineSpacing))) / 2;
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
layout.itemSize = CGSizeMake(ItemWidth, ItemHeight);
|
layout.minimumLineSpacing = LineSpacing;
|
layout.minimumInteritemSpacing = InteritemSpacing;
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
self.collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
|
self.collectionView.backgroundColor = [UIColor clearColor];
|
[self.collectionView registerClass:[PBPersonCollectionViewCell class] forCellWithReuseIdentifier:cellID];
|
self.collectionView.dataSource = self;
|
[self.contentView addSubview:self.collectionView];
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(titleL.mas_bottom).offset(16);
|
make.left.equalTo(self.contentView).offset(margin);
|
make.right.equalTo(self.contentView).offset(-margin);
|
make.height.equalTo(@25);
|
make.bottom.equalTo(self.contentView).offset(-16);
|
}];
|
|
UILabel *promteL = [UILabel z_labelWithText:@"请选择负责人" Color:TitleColor isBold:NO Font:TitleFontSize];
|
[self.contentView addSubview:promteL];
|
[promteL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(titleL.mas_bottom).offset(16);
|
make.centerX.equalTo(titleL);
|
make.height.equalTo(@25);
|
}];
|
|
UIButton *selectBtn = [[UIButton alloc] init];
|
[selectBtn addTarget:self action:@selector(selectBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.contentView addSubview:selectBtn];
|
[selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.bottom.left.right.equalTo(self.contentView);
|
}];
|
self.titleL = titleL;
|
self.promteL = promteL;
|
}
|
|
- (void)selectBtnAction {
|
if (_isIssue) {
|
if (self.issueAddModel.isAddIssue || self.issueAddModel.isIssueManager) {
|
if(self.EditPersonBlock) {
|
self.EditPersonBlock();
|
}
|
}
|
}else {
|
if (self.examineAddModel.isAddExamine || self.examineAddModel.isIssueManage){
|
if(self.EditPersonBlock) {
|
self.EditPersonBlock();
|
}
|
}
|
}
|
}
|
#pragma mark - UICollectionViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
if (_isIssue) {
|
if (self.isLabel) {
|
return self.issueAddModel.labelArr.count;
|
}else {
|
return self.issueAddModel.personArr.count;
|
}
|
}else {
|
return self.examineAddModel.personArr.count;
|
}
|
}
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
PBPersonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
|
PBPersonModel *personModel;
|
RoleType roleType;
|
if (_isIssue) {
|
if (self.isLabel) {
|
PBTagModel *tagModel = self.issueAddModel.labelArr[indexPath.row];
|
roleType = self.issueAddModel.roleType;
|
cell.name = tagModel.it_name;
|
}else {
|
personModel = self.issueAddModel.personArr[indexPath.row];
|
roleType = self.issueAddModel.roleType;
|
cell.name = personModel.RealName;
|
}
|
}else {
|
id data = self.examineAddModel.personArr[indexPath.row];
|
if ([data isKindOfClass:[PBPersonModel class]]) {
|
personModel = data;
|
}else {
|
personModel = [PBPersonModel yy_modelWithDictionary:data];
|
}
|
roleType = self.examineAddModel.roleType;
|
cell.name = personModel.RealName;
|
}
|
cell.roleType = roleType;
|
return cell;
|
}
|
|
- (void)setIssueAddModel:(PBIssueAddModel *)issueAddModel {
|
_issueAddModel = issueAddModel;
|
_isIssue = YES;
|
self.titleL.text = issueAddModel.title;
|
self.promteL.text = issueAddModel.prompt;
|
NSArray *arr;
|
if (self.isLabel) {
|
arr = self.issueAddModel.labelArr;
|
}else {
|
arr = self.issueAddModel.personArr;
|
}
|
if (arr.count == 0) {
|
self.promteL.hidden = NO;
|
if (issueAddModel.isIssueManager || issueAddModel.isAddIssue) {
|
self.promteL.textColor = TitleColor;
|
}else {
|
self.promteL.textColor = PromptColor;
|
}
|
}else {
|
self.promteL.hidden = YES;
|
}
|
NSInteger more = arr.count % _aLineCount == 0? 0 : 1;
|
NSInteger rowNumber = (arr.count / _aLineCount) + more;
|
CGFloat height = (ItemHeight *rowNumber) + (rowNumber - 1) * InteritemSpacing;
|
height = height < 25.0 ? 25.0 : height;
|
[self.collectionView reloadData];
|
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
|
make.height.equalTo(@(height));
|
}];
|
}
|
|
- (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel {
|
_examineAddModel = examineAddModel;
|
_isIssue = NO;
|
self.titleL.text = examineAddModel.title;
|
self.promteL.text = examineAddModel.prompt;
|
if (examineAddModel.personArr.count == 0) {
|
self.promteL.hidden = NO;
|
}else {
|
self.promteL.hidden = YES;
|
}
|
NSArray *arr = examineAddModel.personArr;
|
NSInteger more = arr.count % _aLineCount == 0? 0 : 1;
|
NSInteger rowNumber = (arr.count / _aLineCount) + more;
|
CGFloat height = (ItemHeight *rowNumber) + (rowNumber - 1) * InteritemSpacing;
|
height = height < 25.0 ? 25.0 : height;
|
[self.collectionView reloadData];
|
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
|
make.height.equalTo(@(height));
|
}];
|
}
|
- (void)setIsLabel:(BOOL)isLabel {
|
_isLabel = isLabel;
|
}
|
|
@end
|