zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
//
//  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