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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
//
//  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 "MSSAutoresizeLabelFlowLayout.h"
#import "PBPersonListCollectionViewCell.h"
#import "MSSAutoresizeLabelFlowConfig.h"
static NSString *const cellId = @"cellId";
@interface PBPersonChooseTableViewCell()<UICollectionViewDataSource,UICollectionViewDelegate, MSSAutoresizeLabelFlowLayoutDataSource,MSSAutoresizeLabelFlowLayoutDelegate>
@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;
@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;
    
//    UIView *collectionBg = [[UIView alloc] init];
//    collectionBg.backgroundColor = [UIColor yellowColor];
//    [self.contentView addSubview:collectionBg];
//    [collectionBg mas_makeConstraints:^(MASConstraintMaker *make) {
//        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);
//    }];
 
    MSSAutoresizeLabelFlowLayout *layout = [[MSSAutoresizeLabelFlowLayout alloc]init];
    layout.delegate = self;
    layout.dataSource = self;
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout: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:[PBPersonListCollectionViewCell class] forCellWithReuseIdentifier:cellId];
    [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(@(76));
//            make.bottom.equalTo(self.contentView).offset(-(bottom));
        }];
    }else {
        [self.collection mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(1));
//            make.bottom.equalTo(self.contentView).offset(-(bottom));
        }];
    }
    
    self.titleL.text = examineAddModel.title;
//    if (examineAddModel.personArr.count > 10) {
//        self.totalNumberBtn.hidden = NO;
//    }else {
//        self.totalNumberBtn.hidden = YES;
//    }
    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;
    }
    
//    if (self.data.count == 0) {
//        [self.collectionBg mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.equalTo(@1);
//        }];
//    }
    
 
//    [self.collection setNeedsLayout];
//    [self.collection layoutIfNeeded];
    
//    if (self.examineAddModel.personArr.count > 0) {
//        NSLog(@"hhhhhhhhhhhhhhhhh-%f-%f",self.collection.contentSize.height,self.height);
//        NSLog(@"wwwwwwwwwwwww-%f",self.collection.collectionViewLayout.collectionViewContentSize.height);
//        [self.collection mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.equalTo(@(self.collection.collectionViewLayout.collectionViewContentSize.height));
////            make.bottom.equalTo(self.contentView).offset(-(bottom));
//        }];
//    }else {
//        [self.collection mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.equalTo(@(1));
////            make.bottom.equalTo(self.contentView).offset(-(bottom));
//        }];
//    }
    
 
}
 
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
 
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
//    if (self.data.count > 10) {
//        return 10;
//    }else {
        return self.data.count;
//    }
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    PBPersonListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    PBPersonModel *model = self.data[indexPath.item];
    [cell configCellWithTitle:model.RealName];
    return cell;
}
 
- (NSString *)titleForLabelAtIndexPath:(NSIndexPath *)indexPath {
    PBPersonModel *model = self.data[indexPath.item];
    return model.RealName;
}
 
- (void)layoutFinishWithNumberOfline:(NSInteger)number {
    NSLog(@"===-=-=-=-=-=-=-=%zd",number);
//    static NSInteger numberCount;
//    if (numberCount == number) {
//        return;
//    }
//    numberCount = number;
    MSSAutoresizeLabelFlowConfig *config = [MSSAutoresizeLabelFlowConfig shareConfig];
    CGFloat h = config.contentInsets.top+config.contentInsets.bottom+config.itemHeight*number+config.lineSpace*(number-1);
    self.height = h;
    NSLog(@"mmmmmmmmmmmmmmmm-%f",h);
   
     //    [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.collection.mas_bottom).offset(15);
//    }];
//    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, h);
//    [UIView animateWithDuration:0.2 animations:^{
//        self.collection.frame = self.bounds;
//    }];
 
//    [self.collection mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.equalTo(@(h));
//    }];
//    [self.contentView layoutIfNeeded];
//    CGFloat botton;
//    if (self.examineAddModel.personArr.count > 10) {
//        botton = 15.f + 32.f;
//        self.totalNumberBtn.hidden = NO;
//        [self.totalNumberBtn setTitle:[NSString stringWithFormat:@"查看全部%zd个%@", self.examineAddModel.personArr.count, self.examineAddModel.title] forState:UIControlStateNormal];
//    }else {
//        botton = 15.f;
//        self.totalNumberBtn.hidden = YES;
//    }
//    [self.collection mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.contentView).offset(-(botton));
//    }];
//    CGFloat bottom;
//    if (self.examineAddModel.personArr.count > 10) {
//        self.totalNumberBtn.hidden = NO;
//        bottom = 32 + 15;
//    }else {
//        self.totalNumberBtn.hidden = YES;
//        bottom = 15;
//    }
//    NSLog(@"======%f",h);
//    if (h <= 0) {
//        h = 1.f;
//    }
//    self.examineAddModel.height = h;
//    [self.collection mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.height.equalTo(@(h));
//        make.bottom.equalTo(self.contentView).offset(-(bottom));
//    }];
//    if (self.examineAddModel.height == 0) {
////        self.examineAddModel.height = h;
//        if (self.ReLoadBlock) {
//            self.ReLoadBlock(h);
//        }
//    }
}
 
- (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