InputGongwenFileCell.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // InputGongwenFileCell.m
  3. // smartRhino
  4. //
  5. // Created by Android on 2020/1/14.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "InputGongwenFileCell.h"
  9. #import "MyWordCell.h"
  10. #import "DownFileViewController.h"
  11. @interface InputGongwenFileCell() <UICollectionViewDelegate,UICollectionViewDataSource>
  12. @property (copy, nonatomic)NSURL *fileURL;
  13. @end
  14. @implementation InputGongwenFileCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. self.gongwenContent.placeholder = @"请输入";
  18. self.gongwenContent.placeholderColor = RGB(153, 153, 153);
  19. self.gongwenContent.font = [UIFont systemFontOfSize:16];
  20. self.mycollectionView.delegate = self;
  21. self.mycollectionView.dataSource = self;
  22. [self.mycollectionView registerNib:[UINib nibWithNibName:@"MyWordCell" bundle:nil] forCellWithReuseIdentifier:@"MyWordCell"];
  23. }
  24. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  25. [super setSelected:selected animated:animated];
  26. }
  27. - (void)setApprovalSection:(NSMutableArray<SelectImageModel *> *)approvalSection {
  28. _approvalSection = approvalSection;
  29. [self.mycollectionView reloadData];
  30. }
  31. #pragma mark - UICollectionViewDelegate UICollectionViewDataSource
  32. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  33. return 1;
  34. }
  35. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  36. return self.approvalSection.count + 1;
  37. }
  38. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  39. WS(weakSelf);
  40. MyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyWordCell" forIndexPath:indexPath];
  41. [cell looadDataHiden:(self.approvalSection.count == indexPath.item)];
  42. if (self.approvalSection.count == indexPath.item) {
  43. cell.iconImage.image = self.placeholderImg.length > 0 ? IMG(self.placeholderImg) : IMG(@"添加审批人");
  44. }else{
  45. SelectImageModel * model = self.approvalSection[indexPath.item];
  46. if([self.approvalSection[indexPath.item].FileType isEqualToString:@"image"]){
  47. cell.iconImage.image = self.approvalSection[indexPath.item].image;
  48. }else{
  49. cell.iconImage.image = IMG([ZYCTool getFileNameImage:model.FileName]);
  50. }
  51. WS(weakSelf);
  52. [cell.deleteButton setAction:^{
  53. [weakSelf deleteHanderBack:indexPath];
  54. }];
  55. }
  56. cell.indexPath = indexPath;
  57. [cell.deleteButton setAction:^{
  58. [weakSelf deleteHanderBack:indexPath];
  59. }];
  60. return cell;
  61. }
  62. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  63. if(self.approvalSection.count == indexPath.item){
  64. if ([self.delegate respondsToSelector:@selector(addPictureWith:WithSuccess:failure:)]) {
  65. [self.delegate addPictureWith:self.index WithSuccess:^(id _Nullable responseObject) {
  66. } failure:^(NSError * _Nonnull error) {
  67. }];
  68. }
  69. }else{
  70. [self checkUpHanderBack:indexPath];
  71. }
  72. }
  73. #pragma mark - MyWordCellDelegate
  74. - (void)deleteHanderBack:(NSIndexPath *)indexPath{
  75. NSLog(@"MyWordCell 3");
  76. [self.approvalSection removeObjectAtIndex:indexPath.item];
  77. [self.mycollectionView reloadData];
  78. if ([self.delegate respondsToSelector:@selector(deletePictureWithCell:SuperViewCellIndexPath:WithSuccess:failure:)]) {
  79. [self.delegate deletePictureWithCell:indexPath SuperViewCellIndexPath:self.index WithSuccess:^(id _Nullable responseObject) {
  80. } failure:^(NSError * _Nonnull error) {
  81. }];
  82. }
  83. }
  84. - (void)checkUpHanderBack:(NSIndexPath *)indexPath{
  85. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  86. AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
  87. NSString *urlStr = self.approvalSection[indexPath.item].AbsolutePath;
  88. NSString *fileName = [urlStr lastPathComponent]; //获取文件名称
  89. NSURL *URL = [NSURL URLWithString:urlStr];
  90. NSLog(@"上传文件地址%@",URL.absoluteString);
  91. NSURLRequest *request = [NSURLRequest requestWithURL:URL];
  92. WS(weakSelf);
  93. //判断是否存在
  94. // if([self isFileExist:fileName]) {
  95. // NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
  96. // NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName];
  97. // WorkFlowFileModel *mdoel = [[WorkFlowFileModel alloc]init];
  98. // mdoel.PreviewUrl = url.absoluteString;
  99. // mdoel.DownloadUrl = url.absoluteString;
  100. // DownFileViewController *vc = [[DownFileViewController alloc]init];
  101. // vc.model = mdoel;
  102. // vc.modalPresentationStyle = UIModalPresentationFullScreen;
  103. // [[UIApplication sharedApplication].windows.firstObject.rootViewController presentViewController:vc animated:YES completion:nil];
  104. // }else {
  105. SHOWLOADING
  106. NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress){
  107. } destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
  108. NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
  109. NSURL *url = [documentsDirectoryURL URLByAppendingPathComponent:fileName];
  110. return url;
  111. } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
  112. REMOVESHOW
  113. NSLog(@"%@",response);
  114. if (weakSelf.ClickCellBlock) {
  115. weakSelf.ClickCellBlock(indexPath.item);
  116. }
  117. }];
  118. [downloadTask resume];
  119. // }
  120. }
  121. //判断文件是否已经在沙盒中存在
  122. -(BOOL) isFileExist:(NSString *)fileName
  123. {
  124. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  125. NSString *path = [paths objectAtIndex:0];
  126. NSString *filePath = [path stringByAppendingPathComponent:fileName];
  127. NSFileManager *fileManager = [NSFileManager defaultManager];
  128. BOOL result = [fileManager fileExistsAtPath:filePath];
  129. return result;
  130. }
  131. @end