Commit 3d042ba4 authored by Sandy's avatar Sandy

上传图片等功能实现

parent 96921baf
...@@ -18,7 +18,35 @@ ...@@ -18,7 +18,35 @@
- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor; - (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor;
- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode; - (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode;
/**
* 图片压缩到指定大小(具体看图片大小,过大的图片无法压缩到指定大小)
*
* @param kb 压缩后图片大小
*
* @return
*/
- (NSData *)scaledToSpaceMaxSize:(NSInteger)kb;
/**
* 压缩图片到指定高宽
*
* @param newSize 新的图片尺寸
*
* @return
*/
- (UIImage *)scaledToSize:(CGSize)newSize;
/**
* 按比例压缩图片至指定宽度
*
* @param newWidth 指定宽度
*
* @return
*/
- (UIImage *)scaledToWidth:(NSInteger)newWidth;
/** 计算图片大小 */
- (CGFloat)dataSize;
@end @end
@interface UIImage (Color) @interface UIImage (Color)
......
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
// //
#import "UIImage+Helper.h" #import "UIImage+Helper.h"
#ifdef DEBUG
#define CLog(format, ...) NSLog((@"[Line %d] %s " format), __LINE__, __PRETTY_FUNCTION__, ## __VA_ARGS__)
#else
#define CLog(format, ...)
#endif
@implementation UIImage (Helper) @implementation UIImage (Helper)
// if newImage's width or heigth < 1, image will be cliped // if newImage's width or heigth < 1, image will be cliped
...@@ -98,6 +102,49 @@ ...@@ -98,6 +102,49 @@
return tintedImage; return tintedImage;
} }
- (NSData *)scaledToSpaceMaxSize:(NSInteger)kb {
//压缩到指定大小以内
CGFloat compression = 0.5f;
CGFloat maxCompression = 0.1f;
NSUInteger maxlength = kb * 1024;
NSData *imgData = UIImageJPEGRepresentation(self, compression);
CLog(@"处理之前的大小--->%lukB",(unsigned long)imgData.length/1024);
while ([imgData length] > maxlength && compression > maxCompression) {
compression -= 0.1;
imgData = UIImageJPEGRepresentation(self, compression);
}
CLog(@"处理之后的大小--->%lukB",(unsigned long)imgData.length/1024);
return imgData;
}
- (UIImage *)scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, YES, 0);
[self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
- (UIImage *)scaledToWidth:(NSInteger)newWidth {
CLog(@"旧尺寸%@", NSStringFromCGSize(self.size));
CGSize newSize = CGSizeMake(newWidth, newWidth / self.size.width * self.size.height);
UIGraphicsBeginImageContextWithOptions(newSize, YES, 0);
[self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CLog(@"新尺寸%@", NSStringFromCGSize(scaledImage.size));
return scaledImage;
}
/** 计算图片大小 */
- (CGFloat)dataSize {
NSData *data = UIImageJPEGRepresentation(self, 1);
CGFloat size = data.length/1024;
CLog(@"data size=%.0f kB, size=%@", size, NSStringFromCGSize(self.size));
return size;
}
@end @end
......
...@@ -93,8 +93,10 @@ typedef NS_ENUM(NSUInteger, ICRAttachmentType) { ...@@ -93,8 +93,10 @@ typedef NS_ENUM(NSUInteger, ICRAttachmentType) {
failure:(void (^)(id))fail; failure:(void (^)(id))fail;
- (void)postUrl:(NSString *)url params:(id)params success:(void (^)(id data))succ failure:(void (^)(id data))fail; - (void)postUrl:(NSString *)url params:(id)params success:(void (^)(id data))succ failure:(void (^)(id data))fail;
- (void)getUrl:(NSString *)url params:(id)params success:(void (^)(id data))succ failure:(void (^)(id data))fail; - (void)getUrl:(NSString *)url params:(id)params success:(void (^)(id data))succ failure:(void (^)(id data))fail;
- (void)POST:(NSString *)requestUrl pictures:(NSArray *)pictures param:(NSDictionary *)params complete:(void (^)(id responseObject, NSError *error))complete;
@end @end
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#import "VankeCommonModel.h" #import "VankeCommonModel.h"
#import "ICRDataBaseController.h" #import "ICRDataBaseController.h"
#import "VankeConfig.h" #import "VankeConfig.h"
#import "NSData+BeeExtension.h"
#import "UIImage+Helper.h"
//#import "ICRStoreResult.h" //#import "ICRStoreResult.h"
#define MAX_CONCURRENCY_UPLOAD 1 #define MAX_CONCURRENCY_UPLOAD 1
...@@ -731,8 +733,33 @@ acceptTypeJson:YES ...@@ -731,8 +733,33 @@ acceptTypeJson:YES
fail(error); fail(error);
}]; }];
}
- (void)POST:(NSString *)requestUrl pictures:(NSArray *)pictures param:(NSDictionary *)params complete:(void (^)(id responseObject, NSError *error))complete
{
NSString *url = [VANKE_SERVER_BASE_URL stringByAppendingFormat:@"/%@", requestUrl];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFJSONRequestSerializer *requestSerializer =
[self requestNeedToken:YES acceptTypeJson:YES failure:nil];
manager.requestSerializer = requestSerializer;
[manager POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
for (UIImage *image in pictures) {
UIImage *imageScaled = [image scaledToWidth:400];
NSData *data = [imageScaled scaledToSpaceMaxSize:95];
[formData appendPartWithFileData: data//图片data
name:@"file" //接口key值
fileName:[NSString stringWithFormat:@"%@.%@",[data MD5String],@"jpg"] //图片名称,必须有后缀
mimeType:@"image/jpeg"]; //文件类型,后台接受使用
}
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
complete(responseObject, nil);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
complete(nil, error);
}];
} }
@end @end
...@@ -21,19 +21,15 @@ ...@@ -21,19 +21,15 @@
// 百度天气服务地址 // 百度天气服务地址
#define VANKE_BAIDU_WEATHER_SERVER_URL @"http://api.map.baidu.com/telematics/v3/weather" #define VANKE_BAIDU_WEATHER_SERVER_URL @"http://api.map.baidu.com/telematics/v3/weather"
// 正式环境 // //正式环境
#define VANKE_SERVER_BASE_URL @"http://140.206.62.178:8080/wanke-server/rest" //正式 //#define VANKE_SERVER_BASE_URL @"http://140.206.62.178:8080/wanke-server/rest" //正式
// //后台多媒体文件基准地址
//#define VANKE_SERVER_MEDIA_BASE_URL @"http://140.206.62.178:8080" //正式
// 测试环境
//#define VANKE_SERVER_BASE_URL @"http://218.244.151.129:7580/wanke-server/rest"
//#define VANKE_SERVER_BASE_URL @"http://139.196.39.77:8080/wanke-server/rest"
// 后台多媒体文件基准地址
#define VANKE_SERVER_MEDIA_BASE_URL @"http://140.206.62.178:8080" //正式
//#define VANKE_SERVER_MEDIA_BASE_URL @"http://192.168.199.198:8080" //川哥环境
//#define VANKE_SERVER_MEDIA_BASE_URL @"http://218.244.151.129:7580" // 测试环境
#define VANKE_SERVER_BASE_URL @"http://139.196.39.77:8080/wanke-server/rest"
#define VANKE_SERVER_MEDIA_BASE_URL @"http://139.196.39.77:8080"
// 后台服务企业认证码 // 后台服务企业认证码
...@@ -45,4 +41,6 @@ ...@@ -45,4 +41,6 @@
// 后台服务认证用户密码 // 后台服务认证用户密码
#define VANKE_SERVER_PASSWORD @"password" #define VANKE_SERVER_PASSWORD @"password"
#endif /* VankeConfig_h */ #endif /* VankeConfig_h */
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
return; return;
} }
[self http_get:@"/project/queryclassificationby"].PARAM(@"salesDateEquals", self.salesDate).PARAM(@"passengerDateEquals", self.passengerDate).PARAM(@"trafficDateEquals", self.trafficDate).PARAM(@"rentalDateEquals", self.rentalDateEquals).TIMEOUT(10); [self http_get:@"project/queryclassificationby"].PARAM(@"salesDateEquals", self.salesDate).PARAM(@"passengerDateEquals", self.passengerDate).PARAM(@"trafficDateEquals", self.trafficDate).PARAM(@"rentalDateEquals", self.rentalDateEquals).TIMEOUT(10);
} }
else if (self.succeed) else if (self.succeed)
{ {
......
...@@ -135,8 +135,6 @@ ...@@ -135,8 +135,6 @@
} }
- (void)didReceiveMemoryWarning { - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated. // Dispose of any resources that can be recreated.
......
...@@ -129,32 +129,21 @@ ON_SIGNAL3(VankeAffairsBoard_iPhone, btnSaleInput, signal) { ...@@ -129,32 +129,21 @@ ON_SIGNAL3(VankeAffairsBoard_iPhone, btnSaleInput, signal) {
// [GEToast showWithText:@"销售录入正在开发中..." bottomOffset:60.0f duration:1.0f]; // [GEToast showWithText:@"销售录入正在开发中..." bottomOffset:60.0f duration:1.0f];
VankeCommonModel *model = [VankeCommonModel sharedInstance]; VankeCommonModel *model = [VankeCommonModel sharedInstance];
SalesInputViewController *salesVC = [[SalesInputViewController alloc] init]; SalesInputViewController *salesVC = [[SalesInputViewController alloc] init];
WS(weakSelf) WS(weakSelf)
if ([[model getAuthOrgs] count] > 1) { if ([[model getAuthOrgs] count] > 1) {
ChooseProjectTableViewController *chooseVC = [[ChooseProjectTableViewController alloc] init]; ChooseProjectTableViewController *chooseVC = [[ChooseProjectTableViewController alloc] init];
chooseVC.arrAuthorized = [model getAuthOrgs]; chooseVC.arrAuthorized = [model getAuthOrgs];
chooseVC.chooseAuthorized = ^(AuthorizedOrg *author){ chooseVC.chooseAuthorized = ^(AuthorizedOrg *author){
salesVC.authorizedOrg = author; salesVC.authorizedOrg = author;
[weakSelf.navigationController pushViewController:salesVC animated:YES]; [weakSelf.navigationController pushViewController:salesVC animated:YES];
}; };
UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:chooseVC]; UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:chooseVC];
[self.navigationController presentViewController:navc animated:YES completion:nil]; [self.navigationController presentViewController:navc animated:YES completion:nil];
}else{ }else{
salesVC.authorizedOrg = [model getAuthOrgs][0]; salesVC.authorizedOrg = [model getAuthOrgs][0];
[self.navigationController pushViewController:salesVC animated:YES]; [self.navigationController pushViewController:salesVC animated:YES];
} }
} }
ON_SIGNAL3(VankeAffairsBoard_iPhone, btnServiceApply, signal) { ON_SIGNAL3(VankeAffairsBoard_iPhone, btnServiceApply, signal) {
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
} }
.sales-wrapper { .sales-wrapper {
height: 33%; height: 32%;
width: 100%; width: 100%;
} }
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
.row2-wrapper, .row2-wrapper,
.row3-wrapper { .row3-wrapper {
height: 33%; height: 32%;
width: 100%; width: 100%;
} }
......
...@@ -67,7 +67,6 @@ ...@@ -67,7 +67,6 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.chooseAuthorized(self.arrAuthorized[indexPath.row]); self.chooseAuthorized(self.arrAuthorized[indexPath.row]);
[self dismissViewControllerAnimated:YES completion:nil]; [self dismissViewControllerAnimated:YES completion:nil];
......
...@@ -67,7 +67,6 @@ ...@@ -67,7 +67,6 @@
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH, SCREEN_HEIGHT - 150 - 64)]; self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH, SCREEN_HEIGHT - 150 - 64)];
self.scrollView.bounces = NO; self.scrollView.bounces = NO;
self.scrollView.delegate = self; self.scrollView.delegate = self;
[self.view addSubview:self.scrollView]; [self.view addSubview:self.scrollView];
} }
...@@ -98,7 +97,7 @@ ...@@ -98,7 +97,7 @@
label.font = [UIFont systemFontOfSize:19]; label.font = [UIFont systemFontOfSize:19];
label.textAlignment = NSTextAlignmentCenter; label.textAlignment = NSTextAlignmentCenter;
if (i != 0) { if (i != 0) {
[self.scrollView insertSubview:label belowSubview:[self.scrollView viewWithTag:1000 + i -1]];//防止前面的挡住 [self.scrollView insertSubview:label belowSubview:[self.scrollView viewWithTag:1000 + i -1]];//防止前面的挡住
}else{ }else{
[self.scrollView addSubview:label]; [self.scrollView addSubview:label];
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#import "ChooseProjectTableViewController.h" #import "ChooseProjectTableViewController.h"
#import "SaleInputPictureTableViewCell.h" #import "SaleInputPictureTableViewCell.h"
#import "TZImagePickerController.h" #import "TZImagePickerController.h"
#import "UIImage+Helper.h"
#define kCellCount 20 #define kCellCount 20
#define kCellID @"SalesInputTableViewCell.h" #define kCellID @"SalesInputTableViewCell.h"
#define kPicCellId @"SaleInputPictureTableViewCell.h" #define kPicCellId @"SaleInputPictureTableViewCell.h"
...@@ -189,29 +190,10 @@ ON_WILL_APPEAR( signal ) ...@@ -189,29 +190,10 @@ ON_WILL_APPEAR( signal )
#pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置 #pragma mark - 四类个性化设置,这些参数都可以不传,此时会走默认设置
imagePickerVc.isSelectOriginalPhoto = NO; imagePickerVc.isSelectOriginalPhoto = NO;
// 1.如果你需要将拍照按钮放在外面,不要传这个参数
imagePickerVc.selectedAssets = _selectedAssets; // optional, 可选的 imagePickerVc.selectedAssets = _selectedAssets; // optional, 可选的
// imagePickerVc.allowTakePicture = self.showTakePhotoBtnSwitch.isOn; // 在内部显示拍照按钮
// 2. Set the appearance
// 2. 在这里设置imagePickerVc的外观
imagePickerVc.navigationBar.barTintColor = kMainOrangeColor; imagePickerVc.navigationBar.barTintColor = kMainOrangeColor;
// imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor];
imagePickerVc.oKButtonTitleColorNormal = kMainOrangeColor; imagePickerVc.oKButtonTitleColorNormal = kMainOrangeColor;
// 3. Set allow picking video & photo & originalPhoto or not
// 3. 设置是否可以选择视频/图片/原图
// imagePickerVc.allowPickingVideo = self.allowPickingVideoSwitch.isOn;
// imagePickerVc.allowPickingImage = self.allowPickingImageSwitch.isOn;
imagePickerVc.allowPickingOriginalPhoto = NO; imagePickerVc.allowPickingOriginalPhoto = NO;
//
// // 4. 照片排列按修改时间升序
// imagePickerVc.sortAscendingByModificationDate = self.sortAscendingSwitch.isOn;
#pragma mark - 到这里为止
// You can get the photos by block, the same as by delegate.
// 你可以通过block或者代理,来得到用户选择的照片.
[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
_selectedAssets = [NSMutableArray arrayWithArray:assets]; _selectedAssets = [NSMutableArray arrayWithArray:assets];
_arrPics = [NSMutableArray arrayWithArray:photos]; _arrPics = [NSMutableArray arrayWithArray:photos];
...@@ -329,14 +311,10 @@ ON_WILL_APPEAR( signal ) ...@@ -329,14 +311,10 @@ ON_WILL_APPEAR( signal )
ICRHTTPController *httpCtrl = [ICRHTTPController sharedController]; ICRHTTPController *httpCtrl = [ICRHTTPController sharedController];
[httpCtrl getUrl:@"salesinput/query" params:params success:^(id data) { [httpCtrl getUrl:@"salesinput/query" params:params success:^(id data) {
if ([data[@"data"][@"records"] count] > 0) { if ([data[@"data"][@"records"] count] > 0) {
NSNumber *amount = data[@"data"][@"records"][0][@"amount"]; NSNumber *amount = data[@"data"][@"records"][0][@"amount"];
NSString *amountStr = [NSString stringWithFormat:@"%.0f", [amount floatValue]]; NSString *amountStr = [NSString stringWithFormat:@"%.0f", [amount floatValue]];
weakSelf.todayTotalAmount = amountStr; weakSelf.todayTotalAmount = amountStr;
weakSelf.totalView.labelTotalAmount.text = amountStr; weakSelf.totalView.labelTotalAmount.text = amountStr;
}else{ }else{
weakSelf.todayTotalAmount = @"0"; weakSelf.todayTotalAmount = @"0";
weakSelf.totalView.labelTotalAmount.text = @"0"; weakSelf.totalView.labelTotalAmount.text = @"0";
...@@ -425,14 +403,30 @@ ON_WILL_APPEAR( signal ) ...@@ -425,14 +403,30 @@ ON_WILL_APPEAR( signal )
} }
- (void)submit { - (void)submit {
if (self.shop == nil) { if (self.shop == nil) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择店铺!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择店铺!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show]; [alertView show];
}else{ }else{
[self httpPostAttachments];
}
}
- (void)httpPostAttachments {
ICRHTTPController *httpCtrl = [ICRHTTPController sharedController];
NSString *string = [NSString stringWithFormat:@"attachment/upload_by_file?entity_type=%@&entity_uuid=%@",@"salesInput",@"860576037625827160708160529115460847"];
WS(weakSelf);
[httpCtrl POST:string pictures:self.arrPics param:nil complete:^(id responseObject, NSError *error) {
NSMutableArray *arrUuid = [NSMutableArray array];
for (NSDictionary *data in responseObject[@"data"]) {
[arrUuid addObject:data[@"uuid"]];
}
NSString *entityUuid = responseObject[@"data"][0][@"entityUuid"];
ICRHTTPController *httpCtrl = [ICRHTTPController sharedController]; ICRHTTPController *httpCtrl = [ICRHTTPController sharedController];
NSDictionary *params = [self getParams]; NSDictionary *params = [weakSelf getParamsAttachmentUuid:entityUuid pictureUuids:arrUuid];
NSString *url = [NSString stringWithFormat:@"salesinput/submit?time=%@&operId=%@&operName=%@",[[NSDate date] httpParameterString], [[[VankeCommonModel sharedInstance] getLoginInfo] user_uuid], [[[VankeCommonModel sharedInstance] getLoginInfo] user_name]]; NSString *url = [NSString stringWithFormat:@"salesinput/submit?time=%@&operId=%@&operName=%@",[[NSDate date] httpParameterString], [[[VankeCommonModel sharedInstance] getLoginInfo] user_uuid], [[[VankeCommonModel sharedInstance] getLoginInfo] user_name]];
NSString *utf8String = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *utf8String = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
...@@ -444,16 +438,15 @@ ON_WILL_APPEAR( signal ) ...@@ -444,16 +438,15 @@ ON_WILL_APPEAR( signal )
} failure:^(id data) { } failure:^(id data) {
}]; }];
}
}];
} }
- (NSDictionary *)getParams {
- (NSDictionary *)getParamsAttachmentUuid:(NSString *)attachmentUuid pictureUuids:(NSMutableArray *)pictures {
NSMutableArray *lines = [NSMutableArray array]; NSMutableArray *lines = [NSMutableArray array];
for (int i = 0; i < self.arrPaymentType.count; i++) { for (int i = 0; i < self.arrPaymentType.count; i++) {
NSString *bill = [self.cellDataDic objectForKey:[NSIndexPath indexPathForRow:i inSection:0]][1]; NSString *bill = [self.cellDataDic objectForKey:[NSIndexPath indexPathForRow:i inSection:0]][1];
NSString *amount = [self.cellDataDic objectForKey:[NSIndexPath indexPathForRow:i inSection:0]][0]; NSString *amount = [self.cellDataDic objectForKey:[NSIndexPath indexPathForRow:i inSection:0]][0];
PaymentTypeModel *model = self.arrPaymentType[i]; PaymentTypeModel *model = self.arrPaymentType[i];
...@@ -462,14 +455,14 @@ ON_WILL_APPEAR( signal ) ...@@ -462,14 +455,14 @@ ON_WILL_APPEAR( signal )
@"transactions" : [NSNumber numberWithFloat: [bill floatValue]], @"transactions" : [NSNumber numberWithFloat: [bill floatValue]],
@"amount" : [NSNumber numberWithFloat: [amount floatValue]]}; @"amount" : [NSNumber numberWithFloat: [amount floatValue]]};
[lines addObject:pay]; [lines addObject:pay];
} }
NSDictionary *myDictionary = @{@"projectId" : self.authorizedOrg.code, NSDictionary *myDictionary = @{@"projectId" : self.authorizedOrg.code,
@"shopCode" : self.shop.code, @"shopCode" : self.shop.code,
@"shopName" : self.shop.name, @"shopName" : self.shop.name,
@"salesDate" : self.topView.textfieldDate.text, @"salesDate" : self.topView.textfieldDate.text,
@"attachments" : pictures ? pictures : [NSNull null],
@"attachmentUuid" : attachmentUuid ? attachmentUuid : [NSNull null],
@"lines" : lines}; @"lines" : lines};
return myDictionary; return myDictionary;
......
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