Commit 5e2b2364 authored by admin's avatar admin

口碑标准 附件功能完成

parent b3e1d946
...@@ -153,6 +153,7 @@ ...@@ -153,6 +153,7 @@
84ECCF181C01FA2600EA4960 /* QuestionDetailModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84ECCF171C01FA2600EA4960 /* QuestionDetailModel.m */; }; 84ECCF181C01FA2600EA4960 /* QuestionDetailModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84ECCF171C01FA2600EA4960 /* QuestionDetailModel.m */; };
84ECCF1B1C0210F000EA4960 /* CommentModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84ECCF1A1C0210F000EA4960 /* CommentModel.m */; }; 84ECCF1B1C0210F000EA4960 /* CommentModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84ECCF1A1C0210F000EA4960 /* CommentModel.m */; };
84ED5DD81BF2E64300A1BB6D /* ScreenView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84ED5DD71BF2E64300A1BB6D /* ScreenView.m */; }; 84ED5DD81BF2E64300A1BB6D /* ScreenView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84ED5DD71BF2E64300A1BB6D /* ScreenView.m */; };
84EE92771C2FFDEB000EF5BF /* AttachmentModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84EE92761C2FFDEB000EF5BF /* AttachmentModel.m */; };
84F1669B1BE715E40061D350 /* ZanButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F1669A1BE715E40061D350 /* ZanButton.m */; }; 84F1669B1BE715E40061D350 /* ZanButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F1669A1BE715E40061D350 /* ZanButton.m */; };
84F30DA41BFC19F200CBAD13 /* RankListModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F30DA31BFC19F200CBAD13 /* RankListModel.m */; }; 84F30DA41BFC19F200CBAD13 /* RankListModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F30DA31BFC19F200CBAD13 /* RankListModel.m */; };
84F57C461BEC388A00DDEEB1 /* CommentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F57C451BEC388A00DDEEB1 /* CommentView.m */; }; 84F57C461BEC388A00DDEEB1 /* CommentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F57C451BEC388A00DDEEB1 /* CommentView.m */; };
...@@ -477,6 +478,8 @@ ...@@ -477,6 +478,8 @@
84ECCF1A1C0210F000EA4960 /* CommentModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommentModel.m; sourceTree = "<group>"; }; 84ECCF1A1C0210F000EA4960 /* CommentModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommentModel.m; sourceTree = "<group>"; };
84ED5DD61BF2E64300A1BB6D /* ScreenView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenView.h; sourceTree = "<group>"; }; 84ED5DD61BF2E64300A1BB6D /* ScreenView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScreenView.h; sourceTree = "<group>"; };
84ED5DD71BF2E64300A1BB6D /* ScreenView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScreenView.m; sourceTree = "<group>"; }; 84ED5DD71BF2E64300A1BB6D /* ScreenView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScreenView.m; sourceTree = "<group>"; };
84EE92751C2FFDEB000EF5BF /* AttachmentModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AttachmentModel.h; sourceTree = "<group>"; };
84EE92761C2FFDEB000EF5BF /* AttachmentModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AttachmentModel.m; sourceTree = "<group>"; };
84F166991BE715E40061D350 /* ZanButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZanButton.h; sourceTree = "<group>"; }; 84F166991BE715E40061D350 /* ZanButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZanButton.h; sourceTree = "<group>"; };
84F1669A1BE715E40061D350 /* ZanButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZanButton.m; sourceTree = "<group>"; }; 84F1669A1BE715E40061D350 /* ZanButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZanButton.m; sourceTree = "<group>"; };
84F30DA21BFC19F200CBAD13 /* RankListModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RankListModel.h; sourceTree = "<group>"; }; 84F30DA21BFC19F200CBAD13 /* RankListModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RankListModel.h; sourceTree = "<group>"; };
...@@ -1477,6 +1480,8 @@ ...@@ -1477,6 +1480,8 @@
children = ( children = (
849B2F751C0CABE6005D809F /* AnnounceDetailModel.h */, 849B2F751C0CABE6005D809F /* AnnounceDetailModel.h */,
849B2F761C0CABE6005D809F /* AnnounceDetailModel.m */, 849B2F761C0CABE6005D809F /* AnnounceDetailModel.m */,
84EE92751C2FFDEB000EF5BF /* AttachmentModel.h */,
84EE92761C2FFDEB000EF5BF /* AttachmentModel.m */,
); );
path = Model; path = Model;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -2419,6 +2424,7 @@ ...@@ -2419,6 +2424,7 @@
8473E3881C1BBFF600960257 /* InspectTaskDetailCell.m in Sources */, 8473E3881C1BBFF600960257 /* InspectTaskDetailCell.m in Sources */,
84F57C9C1BECA73800DDEEB1 /* StarBar.m in Sources */, 84F57C9C1BECA73800DDEEB1 /* StarBar.m in Sources */,
84F57C4C1BEC785E00DDEEB1 /* AddQuestionViewController.m in Sources */, 84F57C4C1BEC785E00DDEEB1 /* AddQuestionViewController.m in Sources */,
84EE92771C2FFDEB000EF5BF /* AttachmentModel.m in Sources */,
84D2F5201C2D213400651EFB /* AttachmentTableViewCell.m in Sources */, 84D2F5201C2D213400651EFB /* AttachmentTableViewCell.m in Sources */,
84C9729F1C1ADD17003A3276 /* PictureCommentTableCell.m in Sources */, 84C9729F1C1ADD17003A3276 /* PictureCommentTableCell.m in Sources */,
849A18461C152EBA00071600 /* AddPictureTableCell.m in Sources */, 849A18461C152EBA00071600 /* AddPictureTableCell.m in Sources */,
......
...@@ -14,21 +14,23 @@ ...@@ -14,21 +14,23 @@
{ {
if (!_nameBtn) { if (!_nameBtn) {
_nameBtn = [[UIButton alloc] init]; _nameBtn = [[UIButton alloc] init];
_nameBtn.backgroundColor = [UIColor grayColor];
_nameBtn.translatesAutoresizingMaskIntoConstraints = NO; _nameBtn.translatesAutoresizingMaskIntoConstraints = NO;
[_nameBtn setTitleColor:kNavigationBarColor forState:UIControlStateNormal];
_nameBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
_nameBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft ;
_nameBtn.layer.cornerRadius = 4.0; _nameBtn.layer.cornerRadius = 4.0;
[self.contentView addSubview:_nameBtn]; [self.contentView addSubview:_nameBtn];
NSLayoutConstraint *lineViewTop = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5]; NSLayoutConstraint *lineViewTop = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
[self.contentView addConstraint:lineViewTop]; [self.contentView addConstraint:lineViewTop];
NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:-20]; NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.downloadBtn attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-10];
[self.contentView addConstraint:lineViewRight]; [self.contentView addConstraint:lineViewRight];
NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-5]; NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-5];
[self.contentView addConstraint:lineViewBottom]; [self.contentView addConstraint:lineViewBottom];
NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10]; NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.contentView addConstraint:lineViewLeft]; [self.contentView addConstraint:lineViewLeft];
NSLayoutConstraint *lineViewHeight = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35]; NSLayoutConstraint *lineViewHeight = [NSLayoutConstraint constraintWithItem:_nameBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35];
...@@ -42,22 +44,24 @@ ...@@ -42,22 +44,24 @@
{ {
if (!_downloadBtn) { if (!_downloadBtn) {
_downloadBtn = [[UIButton alloc] init]; _downloadBtn = [[UIButton alloc] init];
_downloadBtn.backgroundColor = [UIColor grayColor]; _downloadBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
_downloadBtn.translatesAutoresizingMaskIntoConstraints = NO; _downloadBtn.translatesAutoresizingMaskIntoConstraints = NO;
[_downloadBtn setTitle:@"下载" forState:UIControlStateNormal];
[_downloadBtn setTitle:@"已下载" forState:UIControlStateSelected];
_downloadBtn.layer.cornerRadius = 4.0; _downloadBtn.layer.cornerRadius = 4.0;
[self.contentView addSubview:_downloadBtn]; [self.contentView addSubview:_downloadBtn];
NSLayoutConstraint *lineViewTop = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:5]; NSLayoutConstraint *lineViewTop = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:8];
[self.contentView addConstraint:lineViewTop]; [self.contentView addConstraint:lineViewTop];
NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20]; NSLayoutConstraint *lineViewRight = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.contentView addConstraint:lineViewRight]; [self.contentView addConstraint:lineViewRight];
NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-5]; NSLayoutConstraint *lineViewBottom = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-8];
[self.contentView addConstraint:lineViewBottom]; [self.contentView addConstraint:lineViewBottom];
NSLayoutConstraint *lineViewLeft = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:10]; NSLayoutConstraint *lineViewWidth = [NSLayoutConstraint constraintWithItem:_downloadBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:80];
[self.contentView addConstraint:lineViewLeft]; [self.contentView addConstraint:lineViewWidth];
} }
return _downloadBtn; return _downloadBtn;
} }
......
//
// AttachmentModel.h
// redstar
//
// Created by admin on 15/12/27.
// Copyright © 2015年 ZWF. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface AttachmentModel : NSObject
@property (nonatomic, strong) NSString *fileName;
@property (nonatomic, strong) NSString *fileUrl;
@end
//
// AttachmentModel.m
// redstar
//
// Created by admin on 15/12/27.
// Copyright © 2015年 ZWF. All rights reserved.
//
#import "AttachmentModel.h"
@implementation AttachmentModel
@end
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "AnnounceDetailHeadView.h" #import "AnnounceDetailHeadView.h"
#import "AnnoContentTableViewCell.h" #import "AnnoContentTableViewCell.h"
#import "AnnounceDetailFootView.h" #import "AnnounceDetailFootView.h"
#import "AttachmentModel.h"
#import "HttpClient.h" #import "HttpClient.h"
...@@ -17,14 +18,18 @@ ...@@ -17,14 +18,18 @@
#import "AttachmentTableViewCell.h" #import "AttachmentTableViewCell.h"
#import <AFNetworking.h>
#define kAnnounceContentCell @"AnnoContentTableViewCell" #define kAnnounceContentCell @"AnnoContentTableViewCell"
#define kAttachmentTableViewCell @"AttachmentTableViewCell" #define kAttachmentTableViewCell @"AttachmentTableViewCell"
@interface AnnoDetailViewController ()<UITableViewDataSource, UITableViewDelegate> @interface AnnoDetailViewController ()<UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate>
@property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) AnnounceDetailHeadView *headerView; @property (nonatomic, strong) AnnounceDetailHeadView *headerView;
@property (nonatomic, strong) AnnounceDetailFootView *footerView; @property (nonatomic, strong) AnnounceDetailFootView *footerView;
@property (nonatomic, strong) AnnounceDetailModel *annoDetail; @property (nonatomic, strong) AnnounceDetailModel *annoDetail;
@property (nonatomic, strong) NSMutableArray *attachmentArray;
@end @end
@implementation AnnoDetailViewController @implementation AnnoDetailViewController
...@@ -33,6 +38,8 @@ ...@@ -33,6 +38,8 @@
{ {
[super viewDidLoad]; [super viewDidLoad];
self.attachmentArray = [NSMutableArray array];
[self setNav]; [self setNav];
[self requestAnnoDetail]; [self requestAnnoDetail];
...@@ -50,6 +57,12 @@ ...@@ -50,6 +57,12 @@
AnnounceDetailModel *annoDetail = [AnnounceDetailModel announceDetailModelWithDict:dict]; AnnounceDetailModel *annoDetail = [AnnounceDetailModel announceDetailModelWithDict:dict];
_annoDetail = annoDetail; _annoDetail = annoDetail;
for (NSDictionary *attachmentDict in _annoDetail.attachmentUrls) {
AttachmentModel *atta = [[AttachmentModel alloc] init];
[atta setValuesForKeysWithDictionary:attachmentDict];
[_attachmentArray addObject:atta];
}
self.tableView.delegate = self; self.tableView.delegate = self;
self.tableView.dataSource = self; self.tableView.dataSource = self;
}]; }];
...@@ -98,12 +111,80 @@ ...@@ -98,12 +111,80 @@
- (void)showFile:(UIButton *)sender - (void)showFile:(UIButton *)sender
{ {
NSInteger row = sender.tag - 998473;
AttachmentModel *atta = _attachmentArray[row];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = paths.lastObject;
NSString *url = [NSString stringWithFormat:@"%@/%@", path, atta.fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:url]) {
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:url]];//为该对象初始化一个加载路径
docController.delegate = self;//设置代理
[docController presentPreviewAnimated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"文件不存在,请先下载在查看!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
} }
- (void)downloadFile:(UIButton *)sender - (void)downloadFile:(UIButton *)sender
{ {
NSInteger row = sender.tag - 998473;
AttachmentModel *atta = _attachmentArray[row];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = paths.lastObject;
[self downloadFileURL:[NSString stringWithFormat:@"%@%@", kRedStarURL, atta.fileUrl] savePath:path fileName:atta.fileName];
}
- (void)downloadFileURL:(NSString *)aUrl savePath:(NSString *)aSavePath fileName:(NSString *)aFileName
{
NSFileManager *fileManager = [NSFileManager defaultManager];
//检查本地文件是否已存在
NSString *fileName = [NSString stringWithFormat:@"%@/%@", aSavePath, aFileName];
//检查附件是否存在
if ([fileManager fileExistsAtPath:fileName]) {
NSLog(@"存在了");
}else{
NSLog(@"不存在");
//创建附件存储目录
if (![fileManager fileExistsAtPath:aSavePath]) {
[fileManager createDirectoryAtPath:aSavePath withIntermediateDirectories:YES attributes:nil error:nil];
}
//下载附件
NSURL *url = [[NSURL alloc] initWithString:aUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.inputStream = [NSInputStream inputStreamWithURL:url];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:fileName append:NO];
//下载进度控制
//已完成下载
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"下载成功");
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"下载失败");
}];
[operation start];
}
} }
- (void)didReceiveMemoryWarning { - (void)didReceiveMemoryWarning {
...@@ -112,15 +193,24 @@ ...@@ -112,15 +193,24 @@
} }
#pragma mark - UITableView Delegate/DataSource #pragma mark - UITableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ {
return 1 + _annoDetail.attachmentUrls.count; if (section == 0) {
return 1;
} else {
return _attachmentArray.count;
}
} }
// cell显示的内容 // cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
if (indexPath.row == 0) { if (indexPath.section == 0) {
AnnoContentTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kAnnounceContentCell]; AnnoContentTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kAnnounceContentCell];
if (!cell) { if (!cell) {
cell = [[AnnoContentTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAnnounceContentCell]; cell = [[AnnoContentTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAnnounceContentCell];
...@@ -139,21 +229,34 @@ ...@@ -139,21 +229,34 @@
if (!cell) { if (!cell) {
cell = [[AttachmentTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAttachmentTableViewCell]; cell = [[AttachmentTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAttachmentTableViewCell];
} }
NSDictionary *dict = _annoDetail.attachmentUrls[indexPath.row - 1]; AttachmentModel *atta = _attachmentArray[indexPath.row];
NSString *name = dict[@"fileName"]; NSString *name = atta.fileName;
[cell.nameBtn setTitle:name forState:UIControlStateNormal]; [cell.nameBtn setTitle:name forState:UIControlStateNormal];
[cell.downloadBtn setTitle:@"下载" forState:UIControlStateNormal];
[cell.nameBtn addTarget:self action:@selector(showFile:) forControlEvents:UIControlEventTouchUpInside]; [cell.nameBtn addTarget:self action:@selector(showFile:) forControlEvents:UIControlEventTouchUpInside];
[cell.downloadBtn addTarget:self action:@selector(downloadFile:) forControlEvents:UIControlEventTouchUpInside]; [cell.downloadBtn addTarget:self action:@selector(downloadFile:) forControlEvents:UIControlEventTouchUpInside];
cell.downloadBtn.tag = 998473 + indexPath.row;
cell.nameBtn.tag = 998473 + indexPath.row;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = paths.lastObject;
NSString *url = [NSString stringWithFormat:@"%@/%@", path, atta.fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:url]) {
cell.downloadBtn.selected = YES;
cell.downloadBtn.backgroundColor = [UIColor grayColor];
} else {
cell.downloadBtn.selected = NO;
cell.downloadBtn.backgroundColor = [UIColor colorWithRed:47 / 255.0 green:209/ 255.0 blue:92 / 255.0 alpha:1.0];
}
return cell; return cell;
} }
} }
- (UITableView *)tableView - (UITableView *)tableView
{ {
if (!_tableView) { if (!_tableView) {
...@@ -165,7 +268,6 @@ ...@@ -165,7 +268,6 @@
_tableView.rowHeight = UITableViewAutomaticDimension; _tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.estimatedRowHeight = 100.0; _tableView.estimatedRowHeight = 100.0;
_tableView.tableHeaderView = self.headerView; _tableView.tableHeaderView = self.headerView;
_tableView.tableFooterView = self.footerView;
[_tableView registerClass:[AnnoContentTableViewCell class] forCellReuseIdentifier:kAnnounceContentCell]; [_tableView registerClass:[AnnoContentTableViewCell class] forCellReuseIdentifier:kAnnounceContentCell];
[_tableView registerClass:[AttachmentTableViewCell class] forCellReuseIdentifier:kAttachmentTableViewCell]; [_tableView registerClass:[AttachmentTableViewCell class] forCellReuseIdentifier:kAttachmentTableViewCell];
[self.view addSubview:_tableView]; [self.view addSubview:_tableView];
...@@ -198,8 +300,7 @@ ...@@ -198,8 +300,7 @@
- (AnnounceDetailFootView *)footerView - (AnnounceDetailFootView *)footerView
{ {
if (!_footerView) { if (!_footerView) {
_footerView = [[AnnounceDetailFootView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 120)]; _footerView = [[AnnounceDetailFootView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
_footerView.backgroundColor = [UIColor whiteColor];
} }
return _footerView; return _footerView;
} }
......
...@@ -134,6 +134,8 @@ ...@@ -134,6 +134,8 @@
_praiseUuid = response[@"data"]; _praiseUuid = response[@"data"];
}]; }];
} }
_rowNumber++;
[self.tableView reloadData];
} else { } else {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(_rowNumber - 2) inSection:0]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(_rowNumber - 2) inSection:0];
...@@ -143,22 +145,29 @@ ...@@ -143,22 +145,29 @@
url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
HttpClient *http1 = [[HttpClient alloc] initWithUrl:url]; HttpClient *http1 = [[HttpClient alloc] initWithUrl:url];
NSString *imageName = _imageNameArray[_rowNumber - 3]; if ((_imageNameArray.count == _rowNumber - 2) && cell.titleTextView.text.length != 0 ) {
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName]; NSString *imageName = _imageNameArray[_rowNumber - 3];
UIImage *image = [UIImage imageWithContentsOfFile:fullPath]; NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
NSData *imageData = UIImageJPEGRepresentation(image, 0.5); UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
NSString *imageBase64 = [imageData base64EncodedStringWithOptions:0]; NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
NSDictionary *parameters = @{ NSString *imageBase64 = [imageData base64EncodedStringWithOptions:0];
@"description":cell.titleTextView.text, NSDictionary *parameters = @{
@"fileName":imageName, @"description":cell.titleTextView.text,
@"fileContent":imageBase64 @"fileName":imageName,
}; @"fileContent":imageBase64
[http1 upLoadPraisePictureWithParameters:parameters completion:^(id response, NSError *error) { };
NSLog(@"6.2上传口碑图片 resp = %@, error = %@", response, error); [http1 upLoadPraisePictureWithParameters:parameters completion:^(id response, NSError *error) {
}]; NSLog(@"6.2上传口碑图片 resp = %@, error = %@", response, error);
}];
_rowNumber++;
[self.tableView reloadData];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"必须有图片和图片说明!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
} }
_rowNumber++;
[self.tableView reloadData];
} }
- (void)saveImage:(UIImage *)currentImage { - (void)saveImage:(UIImage *)currentImage {
...@@ -382,8 +391,6 @@ ...@@ -382,8 +391,6 @@
[cell.photoButton removeTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside]; [cell.photoButton removeTarget:self action:@selector(createImagePicker:) forControlEvents:UIControlEventTouchUpInside];
[cell.photoButton addTarget:self action:@selector(showBigPic:) forControlEvents:UIControlEventTouchUpInside]; [cell.photoButton addTarget:self action:@selector(showBigPic:) forControlEvents:UIControlEventTouchUpInside];
cell.titleTextView.userInteractionEnabled = NO; cell.titleTextView.userInteractionEnabled = NO;
} }
} }
cell.titleTextView.delegate = self; cell.titleTextView.delegate = self;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
[self.contentView addConstraint:titleRight]; [self.contentView addConstraint:titleRight];
// 高度 // 高度
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_bigImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:150]; NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_bigImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:170];
[self.contentView addConstraint:titleHeight]; [self.contentView addConstraint:titleHeight];
} }
return _bigImageView; return _bigImageView;
......
...@@ -306,7 +306,6 @@ ...@@ -306,7 +306,6 @@
PicTextModel *picText = _picTextArray[indexPath.row]; PicTextModel *picText = _picTextArray[indexPath.row];
NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL ,picText.fileUrl]]; NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL ,picText.fileUrl]];
[cell.bigImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"default_pic"]]; [cell.bigImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"default_pic"]];
cell.descriptionLabel.text = [NSString stringWithFormat:@"%@", picText.descriptionText]; cell.descriptionLabel.text = [NSString stringWithFormat:@"%@", picText.descriptionText];
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell; return cell;
...@@ -321,6 +320,31 @@ ...@@ -321,6 +320,31 @@
} }
} }
//裁剪图片
- (UIImage *)cutImage:(UIImage*)image
{
//压缩图片
CGSize newSize;
CGImageRef imageRef = nil;
if ((image.size.width / image.size.height) < (((kScreenWidth - 20 * 3) / 2) / 90)) {
newSize.width = image.size.width;
newSize.height = image.size.width * 90 / ((kScreenWidth - 20 * 3) / 2);
imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(0, fabs(image.size.height - newSize.height) / 2, newSize.width, newSize.height));
} else {
newSize.height = image.size.height;
newSize.width = image.size.height * ((kScreenWidth - 20 * 3) / 2) / 90;
imageRef = CGImageCreateWithImageInRect([image CGImage], CGRectMake(fabs(image.size.width - newSize.width) / 2, 0, newSize.width, newSize.height));
}
return [UIImage imageWithCGImage:imageRef];
}
// 自定义section // 自定义section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{ {
......
...@@ -11,10 +11,14 @@ ...@@ -11,10 +11,14 @@
#import "GroupItems.h" #import "GroupItems.h"
#import "SOPTableView.h" #import "SOPTableView.h"
#import "HttpClient.h" #import "HttpClient.h"
#import "AttachmentTableViewCell.h"
#import "AttachmentModel.h"
#define kAttachmentTableCell @"sopAttachmentCell"
#define SELECTED_VIEW_CONTROLLER_TAG 39998 #define SELECTED_VIEW_CONTROLLER_TAG 39998
@interface SOPViewController () <GroupTabBarDelegate, SOPTableViewDelegate> @interface SOPViewController () <GroupTabBarDelegate, SOPTableViewDelegate, UITableViewDelegate, UITableViewDataSource, UIDocumentInteractionControllerDelegate>
@property (nonatomic, strong) GroupTabBar *groupTabBar; @property (nonatomic, strong) GroupTabBar *groupTabBar;
@property (nonatomic, strong) NSArray *titleArray; @property (nonatomic, strong) NSArray *titleArray;
...@@ -33,6 +37,10 @@ ...@@ -33,6 +37,10 @@
@property (nonatomic, strong) UIButton *resetBtn; @property (nonatomic, strong) UIButton *resetBtn;
@property (nonatomic, strong) UIButton *queryBtn; @property (nonatomic, strong) UIButton *queryBtn;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *attachmentArray;
@end @end
...@@ -49,6 +57,8 @@ ...@@ -49,6 +57,8 @@
self.navigationController.navigationBar.translucent = NO; self.navigationController.navigationBar.translucent = NO;
} }
self.attachmentArray = [NSMutableArray array];
self.titleArray = [NSArray arrayWithObjects:@"质量管理",@"价格管理",@"现场服务",@"售后服务",@"环境管理",@"现场管理", @"400呼叫管理",@"单品管理",nil]; self.titleArray = [NSArray arrayWithObjects:@"质量管理",@"价格管理",@"现场服务",@"售后服务",@"环境管理",@"现场管理", @"400呼叫管理",@"单品管理",nil];
...@@ -79,16 +89,140 @@ ...@@ -79,16 +89,140 @@
NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kGetAttachmentsURL]; NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kGetAttachmentsURL];
HttpClient *http = [[HttpClient alloc] initWithUrl:url]; HttpClient *http = [[HttpClient alloc] initWithUrl:url];
NSDictionary *parameters = @{@"type":@"sop", NSDictionary *parameters = @{@"type":@"sop",
// @"category1":_titleArray[_groupTabBar.selectNumber], @"encode":@"123"
// @"category2":_detailTitle
@"category1":@"11",
@"category2":@"22"
}; };
[http getAttachmentsWithParameters:parameters completion:^(id response, NSError *error) { [http getAttachmentsWithParameters:parameters completion:^(id response, NSError *error) {
NSLog(@"7.1 口碑标注附件列表 = %@, error = %@", response, error); NSLog(@"7.1 口碑标注附件列表 = %@, error = %@", response, error);
NSArray *dataArray = response[@"data"];
for (NSDictionary *attaDict in dataArray) {
AttachmentModel *atta = [[AttachmentModel alloc] init];
[atta setValuesForKeysWithDictionary:attaDict];
[_attachmentArray addObject:atta];
}
CGFloat tableH = _attachmentArray.count * 45;
if (!_bgView) {
_bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeRedView)];
[_bgView addGestureRecognizer:tapGR];
}
CGRect toFrame = CGRectMake(0, 0, kScreenWidth - 50, tableH + 40);
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:toFrame style:UITableViewStyleGrouped];
_tableView.backgroundColor = [UIColor whiteColor];
}
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_bgView];
[self.view insertSubview:_tableView aboveSubview:_bgView];
_bgView.alpha = 0;
_bgView.backgroundColor = [UIColor blackColor];
_tableView.alpha = 0.0;
_tableView.center = CGPointMake( _bgView.center.x, _bgView.center.y - 74);
[UIView animateWithDuration:0.3 animations:^{
_bgView.alpha = 0.6;
_tableView.alpha = 1.0;
}];
}];
}
- (void)closeRedView
{
[UIView animateWithDuration:0.3 animations:^{
_bgView.alpha = .0f;
_tableView.alpha = 0.0;
} completion:^(BOOL finished) {
[_bgView removeFromSuperview];
[_tableView removeFromSuperview];
}]; }];
} }
- (void)showFile:(UIButton *)sender
{
NSInteger row = sender.tag - 998473;
AttachmentModel *atta = _attachmentArray[row];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = paths.lastObject;
NSString *url = [NSString stringWithFormat:@"%@/%@", path, atta.fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:url]) {
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:url]];//为该对象初始化一个加载路径
docController.delegate = self;//设置代理
[docController presentPreviewAnimated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"文件不存在,请先下载在查看!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
}
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
return self;
}
- (void)downloadFile:(UIButton *)sender
{
NSInteger row = sender.tag - 998473;
AttachmentModel *atta = _attachmentArray[row];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = paths.lastObject;
[self downloadFileURL:[NSString stringWithFormat:@"%@%@", kRedStarURL, atta.fileUrl] savePath:path fileName:atta.fileName];
}
- (void)downloadFileURL:(NSString *)aUrl savePath:(NSString *)aSavePath fileName:(NSString *)aFileName
{
NSFileManager *fileManager = [NSFileManager defaultManager];
//检查本地文件是否已存在
NSString *fileName = [NSString stringWithFormat:@"%@/%@", aSavePath, aFileName];
//检查附件是否存在
if ([fileManager fileExistsAtPath:fileName]) {
NSLog(@"存在了");
}else{
NSLog(@"不存在");
//创建附件存储目录
if (![fileManager fileExistsAtPath:aSavePath]) {
[fileManager createDirectoryAtPath:aSavePath withIntermediateDirectories:YES attributes:nil error:nil];
}
//下载附件
NSURL *url = [[NSURL alloc] initWithString:aUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.inputStream = [NSInputStream inputStreamWithURL:url];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:fileName append:NO];
//下载进度控制
//已完成下载
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"下载成功");
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"下载失败");
}];
[operation start];
}
}
- (void)setupNav - (void)setupNav
{ {
UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)]; UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
...@@ -177,7 +311,68 @@ ...@@ -177,7 +311,68 @@
{ {
[self.navigationController dismissViewControllerAnimated:YES completion:nil]; [self.navigationController dismissViewControllerAnimated:YES completion:nil];
} }
#pragma mark - UITableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _attachmentArray.count;
}
// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AttachmentTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:kAttachmentTableCell];
if (!cell) {
cell = [[AttachmentTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kAttachmentTableCell];
}
AttachmentModel *atta = _attachmentArray[indexPath.row];
NSString *name = atta.fileName;
[cell.nameBtn setTitle:name forState:UIControlStateNormal];
[cell.nameBtn addTarget:self action:@selector(showFile:) forControlEvents:UIControlEventTouchUpInside];
[cell.downloadBtn addTarget:self action:@selector(downloadFile:) forControlEvents:UIControlEventTouchUpInside];
cell.downloadBtn.tag = 998473 + indexPath.row;
cell.nameBtn.tag = 998473 + indexPath.row;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = paths.lastObject;
NSString *url = [NSString stringWithFormat:@"%@/%@", path, atta.fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:url]) {
cell.downloadBtn.selected = YES;
cell.downloadBtn.backgroundColor = [UIColor grayColor];
} else {
cell.downloadBtn.selected = NO;
cell.downloadBtn.backgroundColor = [UIColor colorWithRed:47 / 255.0 green:209/ 255.0 blue:92 / 255.0 alpha:1.0];
}
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, kScreenWidth - 20, 40)];
label.text = @"附件";
label.textColor = kNavigationBarColor;
label.font = [UIFont systemFontOfSize:14.0];
[view addSubview:label];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 40;
}
#pragma mark - SOPTableViewDelegate #pragma mark - SOPTableViewDelegate
- (void)selectRowWithDetailTitle:(NSString *)detailTitle - (void)selectRowWithDetailTitle:(NSString *)detailTitle
......
...@@ -116,7 +116,6 @@ ...@@ -116,7 +116,6 @@
- (void)requestMoreList - (void)requestMoreList
{ {
_page++; _page++;
NSLog(@"_page = %d", (int)_page);
NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL]; NSString *url = [NSString stringWithFormat:@"%@%@", kRedStarURL, kInspectListURL];
HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url]; HttpClient *httpCilent = [[HttpClient alloc] initWithUrl:url];
NSDictionary *parameters = @{ NSDictionary *parameters = @{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment