// // AddPictureCell.m // smartRhino // // Created by tederen on 2019/11/26. // Copyright © 2019 tederen. All rights reserved. // #import "AddPictureCell.h" #import "MyWordCell.h" #import "DownFileViewController.h" @interface AddPictureCell() @property (copy, nonatomic)NSURL *fileURL; @end @implementation AddPictureCell - (void)awakeFromNib { [super awakeFromNib]; [self.mycollectionView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"]; } - (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{ return self.approvalSection.count + 1; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ WS(weakSelf); if (self.approvalSection.count == indexPath.item) { MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath]; [cell looadDataHiden:(self.approvalSection.count == indexPath.item)]; cell.iconImage.image = self.placeholderImg.length > 0 ? IMG(self.placeholderImg) : IMG(@"添加审批人"); [cell.deleteButton setAction:^{ [weakSelf deleteHanderBack:indexPath]; }]; return cell; }else{ MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath]; [cell looadDataHiden:(self.approvalSection.count == indexPath.item)]; FlowAttachmentsModel * model = self.approvalSection[indexPath.item]; NSString * imageStr = [ZYCTool getFileNameImage:model.Title]; switch (model.SoureTypeId) { case CollectModel_Aritle: { cell.iconImage.image = IMG(@"文章"); } break; case CollectModel_Toipc: { cell.iconImage.image = IMG(@"话题"); } break; case CollectModel_NewTopic: { cell.iconImage.image = IMG(@"话题"); } break; case CollectModel_Collect: { cell.iconImage.image = IMG(@"收藏"); } break; case CollectModel_NoteBook: { cell.iconImage.image = IMG(@"noteBook_icon"); } break; case CollectModel_Notice: { cell.iconImage.image = IMG(@"通知图标"); } break; case CollectModel_InterMail: { cell.iconImage.image = IMG(@"站内信"); } break; case CollectModel_Group: { cell.iconImage.image = IMG(@"笔记小组"); } break; case CollectModel_meetMian: { cell.iconImage.image = IMG(@"会议"); } break; case CollectModel_work: { cell.iconImage.image = IMG(@"审批"); } break; case CollectModel_financeCount: { cell.iconImage.image = IMG(@"报表"); } break; case CollectModel_affairsCount: { cell.iconImage.image = IMG(@"报表"); } break; case CollectModel_publishCount: { cell.iconImage.image = IMG(@"报表"); } break; default: { if (imageStr.length > 0) { cell.iconImage.image = IMG(imageStr); }else{ [cell.iconImage sd_setImageWithURL:[NSURL URLWithString:model.MinUrl]]; } } break; } WS(weakSelf); [cell.deleteButton setAction:^{ [weakSelf deleteHanderBack:indexPath]; }]; cell.indexPath = indexPath; return cell; } } //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { // if(self.approvalSection.count == indexPath.item){ // if (self.placeholderImg.length > 0) { // return CGSizeMake(50, 50); // } // return CGSizeMake(110, 50); // }else{ // return CGSizeMake(50, 50); // } //} - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if(self.approvalSection.count == indexPath.item){ if ([self.delegate respondsToSelector:@selector(addPictureWith:WithSuccess:failure:)]) { [self.delegate addPictureWith:self.index WithSuccess:^(id _Nullable responseObject) { } failure:^(NSError * _Nonnull error) { }]; } }else{ [self checkUpHanderBack:indexPath]; } } #pragma mark - MyWordCellDelegate - (void)deleteHanderBack:(NSIndexPath *)indexPath{ NSLog(@"MyWordCell 3"); [self.approvalSection removeObjectAtIndex:indexPath.item]; [self.mycollectionView reloadData]; if ([self.delegate respondsToSelector:@selector(deletePictureWithCell:SuperViewCellIndexPath:WithSuccess:failure:)]) { [self.delegate deletePictureWithCell:indexPath SuperViewCellIndexPath:self.index WithSuccess:^(id _Nullable responseObject) { } failure:^(NSError * _Nonnull error) { }]; } } - (void)checkUpHanderBack:(NSIndexPath *)indexPath{ if (self.ClickCellBlock) { self.ClickCellBlock(indexPath.item); } // NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; // NSString *urlStr = self.approvalSection[indexPath.item].AbsolutePath; // NSString *fileName = [urlStr lastPathComponent]; //获取文件名称 // NSURL *URL = [NSURL URLWithString:urlStr]; // NSLog(@"上传文件地址%@",URL.absoluteString); // NSURLRequest *request = [NSURLRequest requestWithURL:URL]; // WS(weakSelf); // SHOWLOADING // NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress){ // } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { // NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; // NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName]; // return url; // } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) { // REMOVESHOW // NSLog(@"%@",response); // if (weakSelf.ClickCellBlock) { // weakSelf.ClickCellBlock(filePath.absoluteString); // } // }]; // [downloadTask resume]; } - (NSMutableArray *)approvalSection{ if (!_approvalSection) { _approvalSection = [NSMutableArray array]; } return _approvalSection; } ////判断文件是否已经在沙盒中存在 //-(BOOL) isFileExist:(NSString *)fileName //{ // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *path = [paths objectAtIndex:0]; // NSString *filePath = [path stringByAppendingPathComponent:fileName]; // NSFileManager *fileManager = [NSFileManager defaultManager]; // BOOL result = [fileManager fileExistsAtPath:filePath]; // return result; //} @end