// // MyWorkAppApprovalCell.m // smartRhino // // Created by tederen on 2019/11/23. // Copyright © 2019 tederen. All rights reserved. // #import "MyWorkAppApprovalCell.h" #import "MyWordCell.h" #import "MyWorkSpaceCell.h" #import "MailListDetailVC.h" @interface MyWorkAppApprovalCell() @end @implementation MyWorkAppApprovalCell - (void)awakeFromNib { [super awakeFromNib]; [self.collectView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"]; [self.collectView registerNib:[UINib nibWithNibName:@"MyWorkSpaceCell" bundle:nil] forCellWithReuseIdentifier:@"MyWorkSpaceCell"]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } #pragma mark - UICollectionViewDelegate UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (self.approvalSection.count == 0) { return 1 ; }else{ return self.approvalSection.count * 2 + 1 ; } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if ((indexPath.item % 2 ) == 1) { return CGSizeMake(30.f, 65.f); } return CGSizeMake(50.f, 65.f); } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 0.f; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 0.f; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ WS(weakSelf); if (self.approvalSection.count == 0 ) { MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath]; [cell looadDataHiden:YES]; cell.indexPath = indexPath; cell.nameLbl.text = @""; [cell.deleteButton setAction:^{ [weakSelf deleteHanderBack:indexPath]; }]; cell.iconImage.image = IMG(@"添加审批人"); return cell; }else{ if((self.approvalSection.count * 2 + 1) == (indexPath.item + 1)) { MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath]; [cell looadDataHiden:YES]; cell.indexPath = indexPath; cell.nameLbl.text = @""; cell.iconImage.image = IMG(@"添加审批人"); [cell.deleteButton setAction:^{ [weakSelf deleteHanderBack:indexPath]; }]; return cell; }else if ((indexPath.item % 2 ) == 1) { MyWorkSpaceCell *sapceCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWorkSpaceCell" forIndexPath:indexPath]; return sapceCell; }else { MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath]; [cell looadDataHiden:NO]; NSInteger item = indexPath.item / 2; SelectModel *model = self.approvalSection[item]; cell.nameLbl.text = model.UserName; WS(weakSelf); [cell.deleteButton setAction:^{ [weakSelf deleteHanderBack:indexPath]; }]; [cell.iconImage sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"王丽")]; cell.indexPath = indexPath; return cell; } } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if ((self.approvalSection.count == 0) || (self.approvalSection.count * 2 + 1) == (indexPath.item + 1)) { if ([self.delegate respondsToSelector:@selector(addApprovalPeopleSuccess:failure:)]) { [self.delegate addApprovalPeopleSuccess:^(id _Nullable responseObject) { } failure:^(NSError * _Nonnull error) { }]; } }else{ if (self.approvalSection.count == indexPath.item) { }else{ [self gotoPeople:indexPath]; } } } #pragma mark - MyWordCellDelegate - (void)deleteHanderBack:(NSIndexPath *)indexPath{ NSLog(@"MyWordCell 3"); [self.approvalSection removeObjectAtIndex:(indexPath.item / 2)]; [self.collectView reloadData]; } - (void)gotoPeople:(NSIndexPath *)indexPath{ // SelectModel *model = self.approvalSection[indexPath.item]; // MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC]; // vc.indexId = model.Id; // vc.modalPresentationStyle = UIModalPresentationFullScreen; // [[UIApplication sharedApplication].windows.firstObject.rootViewController presentViewController:vc animated:YES completion:nil]; } -(NSMutableArray *)approvalSection{ if (!_approvalSection) { _approvalSection = [NSMutableArray array]; } return _approvalSection; } @end