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
//
//  PBEditLableView.m
//  IphoneBIMe
//
//  Created by ZJF on 2020/3/10.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBEditLableView.h"
#import "PBEditPersonCollectionViewCell.h"
#import "PBRoleTableViewCell.h"
#import "PBIssueAddModel.h"
#import "PBPersonModel.h"
#import "PBProjectModel.h"
#import "PBExamineAddModel.h"
#import "PBTagModel.h"
#define ItemWidth 110
#define ItemHeight 34
#define LineSpacing 6
#define InteritemSpacing 6
static NSString *const cellID = @"cellID";
static NSString *const roleCellID = @"roleCellID";
@interface PBEditLableView()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong)  UIView *bgView;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionView *bottomCollectionView;
@property (nonatomic, assign) NSInteger aLineCount;
@property (nonatomic, strong) NSArray *projectTags;
@property (nonatomic, strong) NSMutableArray *labelListM;
@end
@implementation PBEditLableView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
        [self addSubview:self.bgView];
        [self setupUI];
    }
    return self;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    CGPoint point=[[touches anyObject]locationInView:self];
    CALayer *layer=[self.layer hitTest:point];
    if (layer ==self.layer) {
        [self hidden];
    }
}
- (void)hidden {
    [UIView animateWithDuration:0.3 animations:^{
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
        self.bgView.y = PBScreenHeight;
    }completion:^(BOOL finished) {
        for (UIView *cover in PBKeyWindow.subviews) {
            if ([cover isKindOfClass:[PBEditLableView class]]) {
                [cover removeFromSuperview];
            }
        }
    }];
}
- (void)show {
    [UIView animateWithDuration:0.3 animations:^{
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
        self.bgView.y = PBScreenHeight - self.visualViewHeight;
    }];
}
#pragma mark - 懒加载
- (UIView *)bgView {
    if (_bgView ==  nil) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, PBScreenHeight)];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}
- (void)setVisualViewHeight:(NSInteger)visualViewHeight {
    _visualViewHeight = visualViewHeight;
}
 
- (void)setupUI {
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, 3)];
    topView.backgroundColor = WarningColor;
    [self.bgView addSubview:topView];
    UILabel *titleL = [UILabel z_labelWithText:@"请选择标签" Color:IgnoreColor isBold:NO Font:TitleFontSize];
    [self.bgView addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(14);
        make.centerX.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(120, 22));
    }];
    UIButton *determineBtn = [UIButton z_textButton:@"确定" fontSize:MarkedFontSize normalColor:WarningColor];
    [determineBtn addTarget:self action:@selector(determineBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:determineBtn];
    [determineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(13);
        make.right.equalTo(topView).offset(-24);
    }];
    
    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:[PBEditPersonCollectionViewCell class] forCellWithReuseIdentifier:cellID];
    self.collectionView.dataSource = self;
    [self.bgView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(63);
        make.left.equalTo(self.bgView).offset(margin);
        make.right.equalTo(self.bgView).offset(-margin);
        make.height.equalTo(@114);
    }];
 
    UILabel *roleTitleL = [UILabel z_labelWithText:@"标签" Color:IgnoreColor isBold:NO Font:CommentsSize];
    [self.bgView addSubview:roleTitleL];
    [roleTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collectionView.mas_bottom).offset(30);
        make.left.equalTo(self.bgView).offset(16);
        make.height.equalTo(@21);
    }];
    UIView *linView = [[UIView alloc] init];
    linView.backgroundColor = [UIColor z_colorWithR:235 G:235 B:237];
    [self.bgView addSubview:linView];
    [linView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(roleTitleL.mas_bottom).offset(10);
        make.left.equalTo(self.bgView).offset(15);
        make.right.equalTo(self.bgView).offset(17);
        make.height.equalTo(@1);
    }];
    UICollectionViewFlowLayout *layout1 = [[UICollectionViewFlowLayout alloc] init];
    layout1.itemSize = CGSizeMake(ItemWidth, ItemHeight);
    layout1.minimumLineSpacing = LineSpacing;
    layout1.minimumInteritemSpacing = InteritemSpacing;
    layout1.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.bottomCollectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout1];
    self.bottomCollectionView.backgroundColor = [UIColor clearColor];
    [self.bottomCollectionView registerClass:[PBEditPersonCollectionViewCell class] forCellWithReuseIdentifier:cellID];
    self.bottomCollectionView.dataSource = self;
    self.bottomCollectionView.delegate = self;
    [self.bgView addSubview:self.bottomCollectionView];
    [self.bottomCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(linView.mas_bottom).offset(16);
        make.left.equalTo(self.bgView).offset(margin);
        make.right.equalTo(self.bgView).offset(-margin);
        make.height.equalTo(@215);
    }];
}
 
- (void)determineBtnAction {
    self.issueAddModel.labelArr = self.labelListM.copy;
    [self hidden];
    if (self.EditCompleteBlock) {
        self.EditCompleteBlock();
    }
}
- (void)allSelectBtnAction {
//    NSMutableArray *personArrM = [[NSMutableArray alloc] init];
//    for (NSDictionary *dict in self.rightArr) {
//        BOOL isAdd = NO;
//        PBPersonModel *rightPersonModel = [PBPersonModel yy_modelWithDictionary:dict];
//        for (PBPersonModel *personModel in self.personListM) {
//            if ([rightPersonModel.UserId isEqualToString:personModel.UserId]) {
//                isAdd = YES;
//                break;
//            }
//        }
//        if (!isAdd) {
//            [personArrM addObject:rightPersonModel];
//        }
//    }
//    [self.personListM addObjectsFromArray:personArrM.copy];
//    [self.collectionView reloadData];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (collectionView == self.collectionView) {
        return self.labelListM.count;
    }else {
        return self.projectTags.count;
    }
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    PBEditPersonCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    PBTagModel *tagModel;
    if (collectionView == self.collectionView) {
        tagModel = self.labelListM[indexPath.row];
        cell.deletePersonBlock = ^{
            NSLog(@"=====%zd",indexPath.row);
            [self.labelListM removeObjectAtIndex:indexPath.row];
            [self.collectionView reloadData];
        };
    }else {
        tagModel =  self.projectTags[indexPath.row];
        cell.isHiddenDelete = YES;
    }
    cell.name = tagModel.it_name;
    return cell;
}
#pragma mark - UICollectionViewDelegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    PBTagModel *tagModel = self.projectTags[indexPath.row];
    for (PBTagModel *model in self.labelListM) {
        if ([model.it_guid isEqualToString:tagModel.it_guid]) {
            return;
        }
    }
    [self.labelListM addObject:tagModel];
    [self.collectionView reloadData];
 
}
- (void)loadPersonData {
    [[PBNetworkTools sharedTools] RequestGetIssueOrganizeTags:self.projectModel.organizeid andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if (networkModel.Ret == 1) {
            self.projectTags = networkModel.Data;
 
            self.projectTags = [NSArray yy_modelArrayWithClass:[PBTagModel class] json:networkModel.Data];
            [self.bottomCollectionView reloadData];
        }else {
            [YJProgressHUD showMessage:@"加载项目标签失败" inView:self];
        }
    }];
}
 
- (void)setIssueAddModel:(PBIssueAddModel *)issueAddModel {
    _issueAddModel = issueAddModel;
    self.labelListM = issueAddModel.labelArr.mutableCopy;
    [self.collectionView reloadData];
    [self loadPersonData];
}
 
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
 
 
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
 
@end