// // AddPeopleToGongWenCell.m // smartRhino // // Created by tederen on 2019/11/2. // Copyright © 2019 tederen. All rights reserved. // #import "AddPeopleToGongWenCell.h" #import "MyWordCell.h" #import "MailListDetailVC.h" @interface AddPeopleToGongWenCell() @end @implementation AddPeopleToGongWenCell - (void)awakeFromNib { [super awakeFromNib]; [self.collectView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"]; } - (IBAction)addButton:(UIButton *)sender { if (self.backBlock) { self.backBlock(); } } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } #pragma mark - UICollectionViewDelegate UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.approvalSection.count + 1; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(50.f, 65.f); } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 10.f; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 10.f; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ WS(weakSelf); MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath]; [cell looadDataHiden:(self.approvalSection.count == indexPath.item)]; if (self.approvalSection.count == indexPath.item) { cell.iconImage.image = IMG(@"添加审批人"); cell.nameLbl.text = @""; }else{ SelectModel *model = self.approvalSection[indexPath.item]; WS(weakSelf); [cell.deleteButton setAction:^{ [weakSelf deleteHanderBack:indexPath]; }]; if (model.AvatarUrl.length > 0) { [cell.iconImage setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholder:IMG(@"添加审批人")]; }else { [cell.iconImage setImage:IMG(@"王丽")]; } cell.nameLbl.text = model.UserName; } cell.indexPath = indexPath; [cell.deleteButton setAction:^{ [weakSelf deleteHanderBack:indexPath]; }]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if(self.approvalSection.count == indexPath.item){ if ([self.delegate respondsToSelector:@selector(addLookUpPeopleSuccess:failure:)]) { [self.delegate addLookUpPeopleSuccess:^(id _Nullable responseObject) { } failure:^(NSError * _Nonnull error) { }]; } }else{ [self gotoPeople:indexPath]; } } - (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]; } #pragma mark - MyWordCellDelegate - (void)deleteHanderBack:(NSIndexPath *)indexPath{ NSLog(@"MyWordCell 3"); [self.approvalSection removeObjectAtIndex:indexPath.item]; [self.collectView reloadData]; } - (void)setApprovalSection:(NSMutableArray *)approvalSection { _approvalSection = approvalSection; [self.collectView reloadData]; } @end