Commit c32525ec authored by Sandy's avatar Sandy

文件上传类封装

parent e07121cd
......@@ -69,6 +69,7 @@
8F4BFD071F2F3314003EA16B /* GalleryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F4BFD031F2F3314003EA16B /* GalleryViewController.m */; };
8F4BFD081F2F3314003EA16B /* SingleScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F4BFD051F2F3314003EA16B /* SingleScrollView.m */; };
8F4BFD0A1F2F3596003EA16B /* ZJPicture.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8F4BFD091F2F3596003EA16B /* ZJPicture.storyboard */; };
8F4BFD0D1F3019AC003EA16B /* SalesInputTotalVIew.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F4BFD0C1F3019AC003EA16B /* SalesInputTotalVIew.m */; };
8F6C92381F2ADF4F0060E983 /* HomeWeatherBoard.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F6C92371F2ADF4F0060E983 /* HomeWeatherBoard.m */; };
8F6C923B1F2ADFEC0060E983 /* WeatherModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F6C923A1F2ADFEC0060E983 /* WeatherModel.m */; };
8F6C923E1F2AE3430060E983 /* HomeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F6C923D1F2AE3430060E983 /* HomeViewController.m */; };
......@@ -229,6 +230,8 @@
8F4BFD041F2F3314003EA16B /* SingleScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SingleScrollView.h; sourceTree = "<group>"; };
8F4BFD051F2F3314003EA16B /* SingleScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SingleScrollView.m; sourceTree = "<group>"; };
8F4BFD091F2F3596003EA16B /* ZJPicture.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = ZJPicture.storyboard; sourceTree = "<group>"; };
8F4BFD0B1F3019AC003EA16B /* SalesInputTotalVIew.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SalesInputTotalVIew.h; sourceTree = "<group>"; };
8F4BFD0C1F3019AC003EA16B /* SalesInputTotalVIew.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SalesInputTotalVIew.m; sourceTree = "<group>"; };
8F6C92361F2ADF4F0060E983 /* HomeWeatherBoard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HomeWeatherBoard.h; sourceTree = "<group>"; };
8F6C92371F2ADF4F0060E983 /* HomeWeatherBoard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HomeWeatherBoard.m; sourceTree = "<group>"; };
8F6C92391F2ADFEC0060E983 /* WeatherModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeatherModel.h; sourceTree = "<group>"; };
......@@ -631,6 +634,8 @@
8F4BFCCE1F2EF508003EA16B /* Views */ = {
isa = PBXGroup;
children = (
8F4BFD0B1F3019AC003EA16B /* SalesInputTotalVIew.h */,
8F4BFD0C1F3019AC003EA16B /* SalesInputTotalVIew.m */,
8F4BFCEC1F2F0F16003EA16B /* SaleInputAmountCollectionViewCell.h */,
8F4BFCED1F2F0F16003EA16B /* SaleInputAmountCollectionViewCell.m */,
8F4BFCE01F2F02CB003EA16B /* SaleInputTopView.h */,
......@@ -1150,6 +1155,7 @@
8F973C1F1F21FD54003D3ADB /* ViewController.m in Sources */,
8F4BFCC51F2EDCAF003EA16B /* BusinessFunctionModel.m in Sources */,
8F250D451F297DA80031B4BC /* XWFilterAnimator+XWBarSwipe.m in Sources */,
8F4BFD0D1F3019AC003EA16B /* SalesInputTotalVIew.m in Sources */,
8F4BFCFA1F2F32D5003EA16B /* InspectRepairAddPicTableViewCell.m in Sources */,
8F250D841F29C14F0031B4BC /* LoginViewModel.m in Sources */,
8FEF5E7E1F285E56001496E3 /* UIViewController+Additions.m in Sources */,
......
......@@ -10,14 +10,16 @@
#import "SaleInputViewModel.h"
#import "SaleInputAmountCollectionViewCell.h"
#import "SaleInputAddAmountCell.h"
#import "PicViewModel.h"
#import "InspectRepairAddPicTableViewCell.h"
#import "CalculateHelper.h"
#import "SalesInputTotalVIew.h"
@interface SaleInputAddViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
/** 计算本单合计、输入总笔数 */
@property (nonatomic, weak) IBOutlet SalesInputTotalVIew *totalView;
@property (weak, nonatomic) IBOutlet UIButton *btnBottom;
@property (strong, nonatomic) SaleInputViewModel *viewModel;
@property (strong, nonatomic) NSMutableArray *arrData;
@property (strong, nonatomic) PicViewModel *picVM;
@end
@implementation SaleInputAddViewController
......@@ -45,11 +47,24 @@
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0) {
return 0;
}else{
return 50;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"header"];
return cell.contentView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return 50;
}else{
return self.picVM.cellHeight;
return self.viewModel.picVM.cellHeight;
}
}
......@@ -59,31 +74,45 @@
SaleInputAddAmountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SaleInputAddAmountCell" forIndexPath:indexPath];
cell.isEdit = self.viewModel.type != SaleInputTypeReadOnly;
[cell configCellWithArray:self.arrData indexPath:indexPath];
// WS(weakSelf);
WS(weakSelf);
cell.blockNumberChanged = ^{
// [weakSelf allInputMoney];
[weakSelf allInputMoney];
};
return cell;
}else{
InspectRepairAddPicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InspectRepairAddPicTableViewCell" forIndexPath:indexPath];
[cell configCellWithViewModel:self.picVM
[cell configCellWithViewModel:self.viewModel.picVM
indexPath:indexPath
target:self];
WS(weakSelf);
cell.blockReloadData = ^{
[weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]
withRowAnimation:UITableViewRowAnimationAutomatic];
[weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
};
return cell;
}
}
- (void)allInputMoney {
NSDecimalNumber *allInputMoney = nil;
for (HMSaleInputDetail_payments *cellModel in self.arrData) {
allInputMoney = [CalculateHelper calculateNum1:allInputMoney num2:cellModel.total type:CalculateTypeAdd];
}
//本单合计
self.totalView.labelTotal.text = [CalculateHelper getMoneyStringFrom:allInputMoney];
}
- (void)httpPayments {
}
#pragma mark - actions
- (IBAction)actionSubmit:(id)sender {
[self.viewModel httpUpload];
}
ZJLazy(SaleInputViewModel, viewModel);
ZJLazy(NSMutableArray, arrData);
ZJLazy(PicViewModel, picVM);
@end
......@@ -39,7 +39,7 @@
self.query.dateRange.beginDate = @"2016-07-12";
self.query.dateRange.endDate = @"2017-07-13";
WS(weakSelf);
[ZJHttpManager POST:@"hdmall/api/sale/getList" parameters:self.query.toDictionary complete:^(id responseObject, NSError *error) {
[ZJHttpManager POST:@"hdmall/salesinput/query" parameters:self.query.toDictionary complete:^(id responseObject, NSError *error) {
if (kIsResponse) {
}else{
......
......@@ -8,6 +8,8 @@
#import <Foundation/Foundation.h>
#import "HMSaleInputDetail.h"
#import "PicViewModel.h"
typedef NS_ENUM(NSInteger, SaleInputType) {
SaleInputTypeCreate,
SaleInputTypeEdit,
......@@ -15,6 +17,7 @@ typedef NS_ENUM(NSInteger, SaleInputType) {
};
@interface SaleInputViewModel : NSObject
@property (assign, nonatomic) SaleInputType type;
@property (strong, nonatomic) PicViewModel *picVM;
/**
获取全部支付方式
......@@ -22,4 +25,6 @@ typedef NS_ENUM(NSInteger, SaleInputType) {
@param callBack 获取到支付方式的回调(如果arrPayments = nil, 则代表请求失败)
*/
- (void)httpAllPayments:(void (^)(NSMutableArray<HMSaleInputDetail_payments *> *arrPayments))callBack;
- (void)httpUpload;
@end
......@@ -34,4 +34,22 @@
}
}];
}
- (void)httpUpload {
NSMutableArray *arrImage = [NSMutableArray array];
for (UIImage *img in self.picVM.arrPics) {
ZJBaseFileModel *file = [ZJBaseFileModel new];
file.data = [img imageDataForUpload];
file.name = [file.data md5String];
file.keyName = @"file";
file.mimeType = @"image/jpeg";
[arrImage addObject:file];
}
[ZJHttpManager upLoadFiles:arrImage params:nil commplete:^(NSMutableArray *attachments) {
}];
}
ZJLazy(PicViewModel, picVM);
@end
//
// SalesInputTotalVIew.h
// vanke
//
// Created by Z on 16/4/20.
// Copyright © 2016年 gomore. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SalesInputTotalVIew : UIView
@property (weak, nonatomic) IBOutlet UILabel *labelTotal;
@property (weak, nonatomic) IBOutlet UITextField *textFieldBillCount;
@end
//
// SalesInputTotalVIew.m
// vanke
//
// Created by Z on 16/4/20.
// Copyright © 2016年 gomore. All rights reserved.
//
#import "SalesInputTotalVIew.h"
@interface SalesInputTotalVIew ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIView *viewRedBac;
@end
@implementation SalesInputTotalVIew
- (void)awakeFromNib {
[super awakeFromNib];
self.viewRedBac.layer.cornerRadius = 7;
self.textFieldBillCount.delegate = self;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSArray *valideInput = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"-",@""];
if ([valideInput containsObject:string]) {
if (textField.text.length > 0 && [string isEqualToString:@"-"]) {
return NO;
}
NSMutableString * futureString = [NSMutableString stringWithString:textField.text];
[futureString insertString:string atIndex:range.location];
if ([futureString hasPrefix:@"0."] ||
[futureString hasPrefix:@"00"] ||
[futureString hasPrefix:@"-0"] ||
futureString.length > 6) {
return NO;
}
NSInteger flag = 0;
NSInteger pointNum = 0;//用于标记-的数量,只能有一个-
const NSInteger limited = 20;//限制小数点后面的位数
for (int i = (int)futureString.length - 1; i>=0; i--) {
if ([futureString characterAtIndex:i] == '-') {
pointNum++;
if (pointNum == 2) {
return NO;
}
}
}
for (int i = (int)futureString.length - 1; i>=0; i--) {
if ([futureString characterAtIndex:i] == '-') {
if (flag > limited) {
return NO;
}
break;
}
flag++;
}
return YES;
}else{
return NO;
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
......@@ -27,10 +27,32 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
......@@ -39,37 +61,9 @@
<array>
<string>armv7</string>
</array>
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>App需要您的同意,才能访问蓝牙</string>
<key>NSCalendarsUsageDescription</key>
<string>App需要您的同意,才能访问日历</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App需要您的同意,才能在使用期间访问位置</string>
<key>NSMicrophoneUsageDescription</key>
<string>App需要您的同意,才能访问麦克风</string>
<key>NSMotionUsageDescription</key>
<string>App需要您的同意,才能访问运动与健身</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
{
"images" : [
{
"idiom" : "universal",
"filename" : "list_nodata.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "list_nodata@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "list_nodata@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@
//BaseClass
#import "BaseViewController.h"
#import "ZJBaseModel.h"
#import "ZJBaseFileModel.h"
#import "ZJBaseHttpManager.h"
//third
......@@ -35,6 +36,7 @@
#import "NSNumber+Addtions.h"
#import "NSString+Additions.h"
#import "NSDate+Additions.h"
#import "NSData+EncodeAdditions.h"
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
......
......@@ -22,7 +22,6 @@
self.pageSize = 15;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.estimatedRowHeight = 159;
self.tableView.rowHeight = UITableViewAutomaticDimension;
if (!self.tableView.tableFooterView) {
......@@ -66,7 +65,7 @@
- (void)paggingMode {
WS(weakSelf);
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
weakSelf.page = 0;
weakSelf.page = 1;
[weakSelf.arrData removeAllObjects];
/**
* 子类里面要重写httpRequest方法
......@@ -108,6 +107,15 @@
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
[self.tableView.mj_header beginRefreshing];
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
return YES;
}
- (void)emptyDataSetWillAppear:(UIScrollView *)scrollView {
scrollView.contentOffset = CGPointZero;
}
- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
......
......@@ -15,12 +15,21 @@
@property (nonatomic, strong) NSString <Optional> * name;
/** 文件上传时的文件类型 */
@property (nonatomic, strong) NSString <Ignore> * mimeType;
/** 文件上传时的key(与后台约定) */
@property (nonatomic, strong) NSString <Ignore> * keyName;
@property (nonatomic, strong) NSString <Ignore> * localPath;
@property (strong, nonatomic) UIImage <Ignore> * image;
@property (strong, nonatomic) NSData <Ignore> * data;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
/**
* 显示附件的图片
*
......
......@@ -41,7 +41,8 @@
*
*/
- (UIImage *)scaledToWidth:(NSInteger)newWidth;
/** 获取用于图片上传的图片data */
- (NSData *)imageDataForUpload;
/** 计算图片大小 */
- (CGFloat)dataSize;
@end
......
......@@ -135,6 +135,12 @@
return scaledImage;
}
- (NSData *)imageDataForUpload {
UIImage *imageScaled = [self scaledToWidth:400];
NSData *data = [imageScaled scaledToSpaceMaxSize:80];
return data;
}
/** 计算图片大小 */
- (CGFloat)dataSize {
NSData *data = UIImageJPEGRepresentation(self, 1);
......
......@@ -110,8 +110,8 @@
WS(weakSelf);
[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
[weakSelf.viewModel.arrPics addObjectsFromArray:photos];
[weakSelf.collectionView reloadData];
weakSelf.blockReloadData();
// [weakSelf.collectionView reloadData];
}];
[self.vc presentViewController:imagePickerVc animated:YES completion:nil];
......
......@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
@class ZJBaseFileModel;
#define ZJHttpManager [ZJBaseHttpManager shareCilent]
@interface ZJBaseHttpManager : NSObject
@property (assign, nonatomic) BOOL debugLogEnabled;
......@@ -27,5 +28,8 @@
- (void)DELETE:(NSString *)URLString
parameters:(id)parameters
complete:(void (^)(id responseObject, NSError *error))complete;
/** 上传文件 */
- (void)upLoadFiles:(NSArray<ZJBaseFileModel *> *)files
params:(NSDictionary *)params
commplete:(void (^__nullable)(NSMutableArray *attachments))complete;
@end
......@@ -10,6 +10,7 @@
#import "AFNetworking.h"
#import "ZJShowLogView.h"
#import "JSONKit.h"
#import "ZJBaseFileModel.h"
@interface ZJBaseHttpManager ()
@property (nonatomic, strong) AFHTTPSessionManager *manager;
......@@ -144,6 +145,41 @@
}];
}
/** 上传文件 */
- (void)upLoadFiles:(NSArray<ZJBaseFileModel *> *)files
params:(NSDictionary *)params
commplete:(void (^__nullable)(NSMutableArray *attachments))complete{
if (files.count == 0) {
complete(nil);
return;
}
WS(weakSelf);
[self.manager POST:@"hdmall/media/upload" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
for (ZJBaseFileModel *file in files) {
[formData appendPartWithFileData:file.data //data
name:file.keyName //接口key值
fileName:file.name //文件名称,必须有后缀
mimeType:file.mimeType]; //文件类型,后台接受使用
}
} progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
if (kIsResponse) {
} else {
kFalseHttpTips;
}
[weakSelf logWithUrl:@"hdmall/media/upload" Method:@"UPLOAD" param:params respones:responseObject];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[MBProgressHUD j_error:@"上传失败" complete:nil];
[weakSelf logWithUrl:@"hdmall/media/upload" Method:@"UPLOAD" param:params respones:error];
}];
}
/**
打印网络请求的详情
*/
......
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