// // 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() @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 *)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