AddPictureCell.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // AddPictureCell.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/11/26.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "AddPictureCell.h"
  9. #import "MyWordCell.h"
  10. #import "DownFileViewController.h"
  11. @interface AddPictureCell() <UICollectionViewDelegate,UICollectionViewDataSource>
  12. @property (copy, nonatomic)NSURL *fileURL;
  13. @end
  14. @implementation AddPictureCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. [self.mycollectionView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"];
  18. }
  19. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  20. [super setSelected:selected animated:animated];
  21. // Configure the view for the selected state
  22. }
  23. #pragma mark - UICollectionViewDelegate UICollectionViewDataSource
  24. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  25. return 1;
  26. }
  27. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  28. return self.approvalSection.count + 1;
  29. }
  30. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  31. WS(weakSelf);
  32. if (self.approvalSection.count == indexPath.item) {
  33. MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath];
  34. [cell looadDataHiden:(self.approvalSection.count == indexPath.item)];
  35. cell.iconImage.image = self.placeholderImg.length > 0 ? IMG(self.placeholderImg) : IMG(@"添加审批人");
  36. [cell.deleteButton setAction:^{
  37. [weakSelf deleteHanderBack:indexPath];
  38. }];
  39. return cell;
  40. }else{
  41. MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath];
  42. [cell looadDataHiden:(self.approvalSection.count == indexPath.item)];
  43. FlowAttachmentsModel * model = self.approvalSection[indexPath.item];
  44. NSString * imageStr = [ZYCTool getFileNameImage:model.Title];
  45. switch (model.SoureTypeId) {
  46. case CollectModel_Aritle:
  47. {
  48. cell.iconImage.image = IMG(@"文章");
  49. }
  50. break;
  51. case CollectModel_Toipc:
  52. {
  53. cell.iconImage.image = IMG(@"话题");
  54. }
  55. break;
  56. case CollectModel_NewTopic:
  57. {
  58. cell.iconImage.image = IMG(@"话题");
  59. }
  60. break;
  61. case CollectModel_Collect:
  62. {
  63. cell.iconImage.image = IMG(@"收藏");
  64. }
  65. break;
  66. case CollectModel_NoteBook:
  67. {
  68. cell.iconImage.image = IMG(@"noteBook_icon");
  69. }
  70. break;
  71. case CollectModel_Notice:
  72. {
  73. cell.iconImage.image = IMG(@"通知图标");
  74. }
  75. break;
  76. case CollectModel_InterMail:
  77. {
  78. cell.iconImage.image = IMG(@"站内信");
  79. }
  80. break;
  81. case CollectModel_Group:
  82. {
  83. cell.iconImage.image = IMG(@"笔记小组");
  84. }
  85. break;
  86. case CollectModel_meetMian:
  87. {
  88. cell.iconImage.image = IMG(@"会议");
  89. }
  90. break;
  91. case CollectModel_work:
  92. {
  93. cell.iconImage.image = IMG(@"审批");
  94. }
  95. break;
  96. case CollectModel_financeCount:
  97. {
  98. cell.iconImage.image = IMG(@"报表");
  99. }
  100. break;
  101. case CollectModel_affairsCount:
  102. {
  103. cell.iconImage.image = IMG(@"报表");
  104. }
  105. break;
  106. case CollectModel_publishCount:
  107. {
  108. cell.iconImage.image = IMG(@"报表");
  109. }
  110. break;
  111. default:
  112. {
  113. if (imageStr.length > 0) {
  114. cell.iconImage.image = IMG(imageStr);
  115. }else{
  116. [cell.iconImage sd_setImageWithURL:[NSURL URLWithString:model.MinUrl]];
  117. }
  118. }
  119. break;
  120. }
  121. WS(weakSelf);
  122. [cell.deleteButton setAction:^{
  123. [weakSelf deleteHanderBack:indexPath];
  124. }];
  125. cell.indexPath = indexPath;
  126. return cell;
  127. }
  128. }
  129. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  130. // if(self.approvalSection.count == indexPath.item){
  131. // if (self.placeholderImg.length > 0) {
  132. // return CGSizeMake(50, 50);
  133. // }
  134. // return CGSizeMake(110, 50);
  135. // }else{
  136. // return CGSizeMake(50, 50);
  137. // }
  138. //}
  139. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  140. if(self.approvalSection.count == indexPath.item){
  141. if ([self.delegate respondsToSelector:@selector(addPictureWith:WithSuccess:failure:)]) {
  142. [self.delegate addPictureWith:self.index WithSuccess:^(id _Nullable responseObject) {
  143. } failure:^(NSError * _Nonnull error) {
  144. }];
  145. }
  146. }else{
  147. [self checkUpHanderBack:indexPath];
  148. }
  149. }
  150. #pragma mark - MyWordCellDelegate
  151. - (void)deleteHanderBack:(NSIndexPath *)indexPath{
  152. NSLog(@"MyWordCell 3");
  153. [self.approvalSection removeObjectAtIndex:indexPath.item];
  154. [self.mycollectionView reloadData];
  155. if ([self.delegate respondsToSelector:@selector(deletePictureWithCell:SuperViewCellIndexPath:WithSuccess:failure:)]) {
  156. [self.delegate deletePictureWithCell:indexPath SuperViewCellIndexPath:self.index WithSuccess:^(id _Nullable responseObject) {
  157. } failure:^(NSError * _Nonnull error) {
  158. }];
  159. }
  160. }
  161. - (void)checkUpHanderBack:(NSIndexPath *)indexPath{
  162. if (self.ClickCellBlock) {
  163. self.ClickCellBlock(indexPath.item);
  164. }
  165. // NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  166. // AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
  167. // NSString *urlStr = self.approvalSection[indexPath.item].AbsolutePath;
  168. // NSString *fileName = [urlStr lastPathComponent]; //获取文件名称
  169. // NSURL *URL = [NSURL URLWithString:urlStr];
  170. // NSLog(@"上传文件地址%@",URL.absoluteString);
  171. // NSURLRequest *request = [NSURLRequest requestWithURL:URL];
  172. // WS(weakSelf);
  173. // SHOWLOADING
  174. // NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress){
  175. // } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
  176. // NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
  177. // NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName];
  178. // return url;
  179. // } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
  180. // REMOVESHOW
  181. // NSLog(@"%@",response);
  182. // if (weakSelf.ClickCellBlock) {
  183. // weakSelf.ClickCellBlock(filePath.absoluteString);
  184. // }
  185. // }];
  186. // [downloadTask resume];
  187. }
  188. - (NSMutableArray<FlowAttachmentsModel *> *)approvalSection{
  189. if (!_approvalSection) {
  190. _approvalSection = [NSMutableArray array];
  191. }
  192. return _approvalSection;
  193. }
  194. ////判断文件是否已经在沙盒中存在
  195. //-(BOOL) isFileExist:(NSString *)fileName
  196. //{
  197. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  198. // NSString *path = [paths objectAtIndex:0];
  199. // NSString *filePath = [path stringByAppendingPathComponent:fileName];
  200. // NSFileManager *fileManager = [NSFileManager defaultManager];
  201. // BOOL result = [fileManager fileExistsAtPath:filePath];
  202. // return result;
  203. //}
  204. @end