// // DispatchImageInfoVC.m // IBOSS-HJ // // Created by 关宏厚 on 2021/2/1. // Copyright © 2021 elongtian. All rights reserved. // #import "DispatchImageInfoVC.h" #import "DKUITableViewController.h" #import "DKUICollectionViewCell.h" #import "DKPhoto.h" #import "SignViewController.h" #import "PayTypeModel.h" #import "NewDispatchRequirementModel.h" @interface DispatchImageInfoVC () { // 图片控件 UIView *_vcollectionview; // 内容控件 UIView *_contentView; // 滚动条 UIScrollView *scroll; // 图片 UIView *_vImage; // 分割线背景 UIView *_viewBackgroud; // 高度 CGFloat _titleHeight; UIView *_vSign; UIImageView *_imgView; } /** 照相vc */ @property (strong,nonatomic) DKCameraViewController *cameraVc; /** 上传 后返回照片的路径 */ @property (nonatomic , strong) NSMutableArray *imagePaths; /** 本地存入沙盒照片的路径 */ @property (nonatomic , strong) NSMutableArray *imageLocalPaths; /** 必须输入的项目的字符串 */ @property (copy, nonatomic) NSString* sMustInputItems; @end @implementation DispatchImageInfoVC - (void)viewDidLoad { [super viewDidLoad]; [[PositionTool shareInfo] addDelegate:self]; [[PositionTool shareInfo] getLocation]; [[PositionTool shareInfo] updateLocation]; [self initUI]; } #pragma mark - 属性 /** <#Description#> @return <#return value description#> */ - (NSMutableArray *)assets{ if (!_assets) { _assets = [NSMutableArray array]; } return _assets; } /** <#Description#> @return <#return value description#> */ - (NSMutableArray *)imagePaths{ if (!_imagePaths) { _imagePaths = [NSMutableArray array]; } return _imagePaths; } - (NSMutableArray *)signImgList{ if (!_signImgList) { _signImgList = [NSMutableArray array]; } return _signImgList; } /** <#Description#> @return <#return value description#> */ - (NSMutableArray *)imageLocalPaths{ if (!_imageLocalPaths) { _imageLocalPaths = [NSMutableArray array]; } return _imageLocalPaths; } #pragma mark - 图片回调 /** Section @param pickerBrowser <#pickerBrowser description#> @return <#return value description#> */ - (NSInteger)numberOfSectionInPhotosInPickerBrowser:(DKPhotoPickerBrowserViewController *)pickerBrowser{ return 1; } /** 图片个数 @param photoBrowser <#photoBrowser description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)photoBrowser:(DKPhotoPickerBrowserViewController *)photoBrowser numberOfItemsInSection:(NSUInteger)section{ return [self.assets count]; } /** 单元格图片 @param pickerBrowser <#pickerBrowser description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (DKPhotoPickerBrowserPhoto *)photoBrowser:(DKPhotoPickerBrowserViewController *)pickerBrowser photoAtIndexPath:(NSIndexPath *)indexPath{ id imageObj = [self.assets objectAtIndex:indexPath.item]; DKPhotoPickerBrowserPhoto *photo = [DKPhotoPickerBrowserPhoto photoAnyImageObjWith:imageObj]; // 包装下imageObj 成 DKPhotoPickerBrowserPhoto 传给数据源 DKUICollectionViewCell *cell = (DKUICollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath]; // 缩略图 photo.thumbImage = cell.imageView.image; return photo; } /** 删除图片 @param photoBrowser <#photoBrowser description#> @param indexPath <#indexPath description#> */ - (void)photoBrowser:(DKPhotoPickerBrowserViewController *)photoBrowser removePhotoAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row > [self.assets count]) return; [self.assets removeObjectAtIndex:indexPath.row]; [self.collectionView reloadData]; } /** 代理协议回调函数 @param assets <#assets description#> */ - (void)pickerViewControllerDoneAsstes:(NSArray *)assets{ for (int i=(int)self.assets.count-1;i>=0;i-- ) { if ([self.assets[i] isKindOfClass:[DKPhotoAssets class]]) { [self.assets removeObject:self.assets[i]]; } } for (DKPhotoAssets* asset in assets ) { if ([asset isKindOfClass:[DKPhotoAssets class]]) { [self.assets addObject:asset]; } } [self.collectionView reloadData]; } /** 图片数量-包括照相和相册 @param NSInteger <#NSInteger description#> @return <#return value description#> */ - (NSInteger)cameraCount{ NSInteger count=0; for (int i=0; i @return <#return value description#> */ - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } /** 个数 @param collectionView <#collectionView description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ CGFloat collectionheight=0; if (self.assets.count == 0) { collectionheight=0; }else { NSInteger i=(NSInteger)(self.assets.count-1)/3+1; collectionheight=(85+10)*i; } self.collectionView.frame=CGRectMake(0, 0, Screen_Width, collectionheight); _vcollectionview.frame=CGRectMake(0, 0, Screen_Width, collectionheight); _vSign.frame=CGRectMake(0,CGRectGetMaxY(_vcollectionview.frame), Screen_Width, CGRectGetMaxY(_imgView.frame)); _vImage.frame=CGRectMake(0, CGRectGetMaxY(_vSign.frame), Screen_Width, 35); //btnSave.frame=CGRectMake((Screen_Width-204)*0.5, 51*9+25+collectionheight, 204, 35); scroll.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight); _contentView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight); return [self.assets count]; } /** 单元格cell @param collectionView <#collectionView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ DKUICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DKUICollectionViewCell" forIndexPath:indexPath]; // 判断类型来获取Image DKPhotoAssets *asset = self.assets[indexPath.item]; if ([asset isKindOfClass:[DKPhotoAssets class]]) { cell.imageView.image = asset.originImage; }else if ([asset isKindOfClass:[NSString class]]){ [cell.imageView sd_setImageWithURL:[NSURL URLWithString:(NSString *)asset] placeholderImage:[UIImage imageNamed:@"wallpaper_placeholder"]]; }else if([asset isKindOfClass:[UIImage class]]){ cell.imageView.image = (UIImage *)asset; }else if ([asset isKindOfClass:[DKCamera class]]){ cell.imageView.image = [(DKCamera*)asset thumbImage]; } return cell; } /** 显示图片 @param collectionView <#collectionView description#> @param indexPath <#indexPath description#> */ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ DKUICollectionViewCell *cell = (DKUICollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath]; // 图片游览器 DKPhotoPickerBrowserViewController *pickerBrowser = [[DKPhotoPickerBrowserViewController alloc] init]; // 传入点击图片View的话,会有微信朋友圈照片的风格 pickerBrowser.toView = cell.imageView; // 数据源/delegate pickerBrowser.delegate = self; pickerBrowser.dataSource = self; // 是否可以删除照片 pickerBrowser.editing = YES; // 当前选中的值 pickerBrowser.currentIndexPath = [NSIndexPath indexPathForItem:indexPath.row inSection:0]; // 展示控制器 [pickerBrowser show]; } #pragma mark - 私有函数 -(void)goBack { [self.navigationController popViewControllerAnimated:YES]; } -(void)goBackHome { if([self.refreshDelegate respondsToSelector:@selector(refreshData)]) { [self.refreshDelegate refreshData]; } [self.navigationController popViewControllerAnimated:YES]; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ [self.view setBackgroundColor:[UIColor whiteColor]]; scroll.frame =CGRectMake(0, 0, Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height -40); _btnSave.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, Screen_Width,40) ; [super viewSafeAreaInsetsDidChange]; } /** 初始化UI */ - (void)initUI{ self.navigationItem.title = @"图片信息"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0,15,18); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; _titleHeight = 45; CGFloat fontsize = LabelAndTextFontOfSize; CGFloat lblx = 20; // 滚动条目 scroll = [UIScrollView new]; scroll.frame=self.view.bounds; [self.view addSubview:scroll]; self.view.backgroundColor = [UIColor whiteColor]; // 画面文本显示view _contentView = [[UIView alloc]init]; [scroll addSubview:_contentView]; _contentView.frame=CGRectZero; /////////图片 _vcollectionview = [UIView new]; _vcollectionview.frame=CGRectMake(0,0, Screen_Width, 1); [_contentView addSubview:_vcollectionview]; [self setupCollectionView]; _vSign=[UIView new]; _vSign.frame=CGRectMake(0,CGRectGetMaxY(_vcollectionview.frame), Screen_Width, 1); [_contentView addSubview:_vSign]; _imgView=[[UIImageView alloc]init]; _imgView.frame=CGRectMake(10, 10, 100, 0); [_vSign addSubview:_imgView]; //照相和相册 ————————— _vImage = [UIView new]; _vImage.frame=CGRectMake(0, CGRectGetMaxY(_vSign.frame)+10, Screen_Width, 35); [_contentView addSubview:_vImage]; UIButton *btnCamera = [UIButton buttonWithType:UIButtonTypeCustom]; btnCamera.frame=CGRectMake(20, 6, 16, 13); [btnCamera setBackgroundImage:[UIImage imageNamed:@"icon_takephoto"] forState:UIControlStateNormal]; btnCamera.tag = 1010; [btnCamera addTarget:self action:@selector(selectCamera) forControlEvents:UIControlEventTouchUpInside]; [_vImage addSubview:btnCamera]; UIButton *btnCameraValue = [UIButton buttonWithType:UIButtonTypeCustom]; btnCameraValue.frame=CGRectMake(CGRectGetMaxX(btnCamera.frame)+5, 7, Screen_Width/3-20-13, 13); [btnCameraValue setTitle:@"照相" forState:UIControlStateNormal]; [btnCameraValue setTitleColor:ButtonTitleColor forState:UIControlStateNormal]; btnCameraValue.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; btnCameraValue.titleLabel.font= [UIFont systemFontOfSize:ButtonFontOfSize]; btnCameraValue.tag = 1011; [btnCameraValue addTarget:self action:@selector(selectCamera) forControlEvents:UIControlEventTouchUpInside]; [_vImage addSubview:btnCameraValue]; UIButton *btnPhoto = [UIButton buttonWithType:UIButtonTypeCustom]; btnPhoto.frame=CGRectMake(CGRectGetMaxX(btnCameraValue.frame), 6, 14, 15); [btnPhoto setBackgroundImage:[UIImage imageNamed:@"icon_photo"] forState:UIControlStateNormal]; btnPhoto.tag=1020; [btnPhoto addTarget:self action:@selector(selectPhotos) forControlEvents:UIControlEventTouchUpInside]; [_vImage addSubview:btnPhoto]; UIButton *btnPhotoValue = [UIButton buttonWithType:UIButtonTypeCustom]; btnPhotoValue.frame=CGRectMake(CGRectGetMaxX(btnPhoto.frame)+5, 7, Screen_Width/3-14, 15); [btnPhotoValue setTitle:@"相册" forState:UIControlStateNormal]; [btnPhotoValue setTitleColor:ButtonTitleColor forState:UIControlStateNormal]; btnPhotoValue.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; btnPhotoValue.titleLabel.font= [UIFont systemFontOfSize:ButtonFontOfSize]; btnPhotoValue.tag = 1021; [btnPhotoValue addTarget:self action:@selector(selectPhotos) forControlEvents:UIControlEventTouchUpInside]; [_vImage addSubview:btnPhotoValue]; UIButton *btnSignature = [UIButton buttonWithType:UIButtonTypeCustom]; btnSignature.frame=CGRectMake(CGRectGetMaxX(btnPhotoValue.frame), 6, 14, 15); [btnSignature setBackgroundImage:[UIImage imageNamed:@"icon_photo"] forState:UIControlStateNormal]; btnSignature.tag=1022; [btnSignature addTarget:self action:@selector(selectSignature) forControlEvents:UIControlEventTouchUpInside]; [_vImage addSubview:btnSignature]; UIButton *btnSignatureValue = [UIButton buttonWithType:UIButtonTypeCustom]; btnSignatureValue.frame=CGRectMake(CGRectGetMaxX(btnSignature.frame)+5, 7, Screen_Width/3-14, 15); [btnSignatureValue setTitle:@"签名" forState:UIControlStateNormal]; [btnSignatureValue setTitleColor:ButtonTitleColor forState:UIControlStateNormal]; btnSignatureValue.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; btnSignatureValue.titleLabel.font= [UIFont systemFontOfSize:ButtonFontOfSize]; btnSignatureValue.tag = 1022; [btnSignatureValue addTarget:self action:@selector(selectSignature) forControlEvents:UIControlEventTouchUpInside]; [_vImage addSubview:btnSignatureValue]; _contentView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(_vImage.frame) ); scroll.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_contentView.frame)+rectStatusHeight+rectNavHeight+ 150); //保存按钮 _btnSave = [UIButton buttonWithType:UIButtonTypeCustom]; _btnSave.frame=CGRectMake(0, Screen_Height- 40 - rectStatusHeight-rectNavHeight, Screen_Width,40) ; _btnSave.backgroundColor=NavigationBarColor; [_btnSave setTitle:@"确定" forState:UIControlStateNormal]; [_btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_btnSave addTarget:self action:@selector(saveInfo) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_btnSave]; } /** 保存图片到沙盒 @param currentImage <#currentImage description#> @param imageName <#imageName description#> @return <#return value description#> */ - (DKCamera *) saveImage:(UIImage *)currentImage withName:(NSString *)imageName { if (!currentImage) { return nil; } NSDateFormatter *formater = [[NSDateFormatter alloc] init]; formater.dateFormat = @"yyyyMMddHHmmss"; NSString *currentTimeStr = [[formater stringFromDate:[NSDate date]] stringByAppendingFormat:@"_%d_.jpg" ,arc4random_uniform(10000)]; NSData *imageData= [LeslieAsyncImageDownloader resetSizeOfImageData:currentImage maxSize:500]; // 获取沙盒目录 NSString *fullPath ; if([imageName isEqualToString:@""] || imageName == nil){ fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:currentTimeStr]; } else{ fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName]; } // 将图片写入文件 [imageData writeToFile:fullPath atomically:NO]; UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath]; DKCamera *camera = [[DKCamera alloc] init]; camera.imagePath = fullPath; camera.thumbImage = savedImage;// [UIImage imageWithData:data]; return camera; } /** 保存数据函数 */ - (void)saveInfo{ [self startLoading]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ if(![self savePicsManager]){ return; } if(![self saveSignManager]){ return; } self.mDownManager = [[ASIDownManager alloc] init]; self.mDownManager.delegate = self; self.mDownManager.onRequestSuccess = @selector(onSaveLoadFinish:); self.mDownManager.onRequestFail = @selector(onSaveLoadFail:); NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveInstallationDemandReceiptDataIphone" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [dict setObject:kkLicenseCode forKey:@"LicenseCode"]; [dict setObject:_currentPosition==nil?@"":_currentPosition forKeyedSubscript:@"Position"]; NSMutableDictionary *dicHead = [[NSMutableDictionary alloc] init]; NSMutableArray *arrHead = [[NSMutableArray alloc]init]; [dicHead setObject:_arrangementId forKeyedSubscript:@"ArrangementID"]; [dicHead setObject:_collectDetailId forKeyedSubscript:@"CollectDetailID"]; [dicHead setObject:_customerId forKey:@"CustomerID"]; [dicHead setObject:_receiptAmount forKeyedSubscript:@"ReceivableSum"]; [dicHead setObject:_nextDeliveryDate==nil?@"":_nextDeliveryDate forKeyedSubscript:@"NextDeliveryDate"]; [dicHead setObject:_truckNumber forKeyedSubscript:@"TruckNumber"]; [dicHead setObject:_receiptFlag forKeyedSubscript:@"RequirementType"]; [dicHead setObject:_receivable forKeyedSubscript:@"Receivable"]; [dicHead setObject:_organizationId==nil?@"":_organizationId forKeyedSubscript:@"OrganizationID"]; [dicHead setObject:_organizationCode==nil?@"":_organizationCode forKeyedSubscript:@"OrganizationCode"]; [dicHead setObject:_remarks forKeyedSubscript:@"Remarks"]; [arrHead addObject:dicHead]; [dict setObject:[Util objectToJson:arrHead] forKey:@"ReceiptData"]; //详细列表 NSMutableDictionary *dicDetails; NSMutableArray* arrDetails = [[NSMutableArray alloc]init]; for (NewDispatchRequirementModel* me in _dataList) { dicDetails = [[NSMutableDictionary alloc] init]; [dicDetails setObject:me.detailId forKeyedSubscript:@"DetailID"]; [dicDetails setObject:me.receiptDetailId==nil?@"":me.receiptDetailId forKeyedSubscript:@"ReceiptDetailID"]; [dicDetails setObject:me.deliveryQuantity forKeyedSubscript:@"DeliveryQuantity"]; [dicDetails setObject:me.receiptQuantity forKeyedSubscript:@"DeliveryReceiptQuantity"]; [dicDetails setObject:me.installQuantity forKeyedSubscript:@"InstallationQuantity"]; [dicDetails setObject:me.installReceiptQuantity forKeyedSubscript:@"InstallationFinishQuantity"]; [dicDetails setObject:me.receiptType forKeyedSubscript:@"DeliveryReceiptType"]; [dicDetails setObject:me.installReceiptType forKeyedSubscript:@"InstallationReceiptType"]; [dicDetails setObject:me.invoiceDetailId==nil?@"":me.invoiceDetailId forKeyedSubscript:@"InvoiceDetailID"]; [dicDetails setObject:me.invoiceId==nil?@"":me.invoiceId forKeyedSubscript:@"InvoiceID"]; [dicDetails setObject:me.receiptRemarks forKeyedSubscript:@"Remarks"]; [dicDetails setObject:me.sourceFrom forKeyedSubscript:@"SourceFrom"]; [arrDetails addObject:dicDetails]; } [dict setObject:[Util objectToJson:arrDetails] forKey:@"ReceiptDetailData"]; if(_paymentMethodArray!=nil&&_paymentMethodArray.count>0) { NSMutableArray* arrSettle = [[NSMutableArray alloc]init]; for(int i=0;i<_paymentMethodArray.count;i++) { PayTypeModel *typeModel=[_paymentMethodArray objectAtIndex:i]; NSMutableDictionary *dicSettle = [[NSMutableDictionary alloc] init]; [dicSettle setObject:[typeModel settlementType] forKeyedSubscript:@"SettlementTypeID"]; [dicSettle setObject:_collectDetailId forKeyedSubscript:@"CollectDetailID"]; [dicSettle setObject:[typeModel receivableSum] forKeyedSubscript:@"ReceivableSum"]; [dicSettle setObject:@"0" forKeyedSubscript:@"EarnestFee"]; [dicSettle setObject:[typeModel remarks] forKeyedSubscript:@"Remarks"]; [arrSettle addObject:dicSettle]; } [dict setObject:[Util objectToJson:arrSettle] forKey:@"ReceiptEarnestData"]; } else { [dict setObject:@"" forKey:@"ReceiptEarnestData"]; } /////////图片上传返回的地址 if (self.imagePaths && self.imagePaths.count > 0) { [dict setObject:[self.imagePaths componentsJoinedByString:@"," ] forKey:@"ImagePath"]; } if(self.signImgList!=nil&&self.signImgList.count>0) { [dict setObject:[self.signImgList componentsJoinedByString:@"," ] forKey:@"SignImagePath"]; } [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; }); } /** 保存数据加载完成函数 @param sender <#sender description#> */ - (void)onSaveLoadFinish:(ASIDownManager *)sender { RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; [self stopLoading]; int iStatus =resultModel.status; NSString *message = resultModel.message; if (iStatus == 0) { //[self clearData];//新增后 清除画面的值 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"保存成功!" preferredStyle:UIAlertControllerStyleAlert ]; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ [self goBackHome]; }]]; // 3.显示alertController:presentViewController [self presentViewController:alert animated:YES completion:nil]; } else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [self showReLoginDialog:message]; return; } else { [self showAlertViewText:message]; return; } } -(void)onSaveLoadFail:(ASIDownManager *)sender { [self stopLoading]; [self showAlertViewText:@"网络异常"]; } /** 保存图片函数 @return <#return value description#> */ - (BOOL)savePicsManager{ self.mDownManager = [[ASIDownManager alloc] init]; self.mDownManager.delegate=self; //////////////上传图片 NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveImg" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [self.imagePaths removeAllObjects]; for (int i = 0; i < self.assets.count; i++) { DKPhotoAssets *asset = self.assets[i]; DKCamera * c; if ([asset isKindOfClass:[DKPhotoAssets class]]) { c = [self saveImage:asset.originImage withName:nil]; }else if ([asset isKindOfClass:[NSString class]]){ }else if([asset isKindOfClass:[UIImage class]]){ }else if ([asset isKindOfClass:[DKCamera class]]){ c = (DKCamera *)asset; c = [self saveImage:c.thumbImage withName:nil]; } //延时 [NSThread sleepForTimeInterval:0.5]; NSString* retValue= [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:c.imagePath filename:nil fileType:@"image/jpeg"]; if (retValue == nil || retValue.length == 0){ [self stopLoading]; [self showAlertViewText:@"上传图片失败"]; self.navigationItem.rightBarButtonItem.enabled = YES; return NO; } NSDictionary *dicRetValue = [retValue JSONValue]; if (dicRetValue && [dicRetValue isKindOfClass:[NSDictionary class]]) { int iStatus = [[dicRetValue objectForKey:@"Status"] intValue]; if (iStatus == 0) { NSString * imgPath = [dicRetValue objectForKey:@"Result"]; [self.imagePaths addObject:imgPath]; } else{ [self stopLoading]; return NO; } } } return YES; } - (BOOL)saveSignManager{ self.mDownManager = [[ASIDownManager alloc] init]; self.mDownManager.delegate=self; //////////////上传图片 NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"SaveImg" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [self.signImgList removeAllObjects]; DKCamera * c; if(_signImg!=nil) { c = [self saveImage:_signImg withName:nil]; //延时 [NSThread sleepForTimeInterval:0.5]; NSString* retValue= [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:c.imagePath filename:nil fileType:@"image/jpeg"]; if (retValue == nil || retValue.length == 0){ [self stopLoading]; [self showAlertViewText:@"上传图片失败"]; self.navigationItem.rightBarButtonItem.enabled = YES; return NO; } NSDictionary *dicRetValue = [retValue JSONValue]; if (dicRetValue && [dicRetValue isKindOfClass:[NSDictionary class]]) { int iStatus = [[dicRetValue objectForKey:@"Status"] intValue]; if (iStatus == 0) { NSString * imgPath = [dicRetValue objectForKey:@"Result"]; [self.signImgList addObject:imgPath]; } else{ [self stopLoading]; return NO; } } } return YES; } /** 回调地理位置 */ -(void)noticePositionChanged{ _currentPosition = [NSString stringWithFormat:@"%@%@%@%@",[PositionTool shareInfo].province, [PositionTool shareInfo].city, [PositionTool shareInfo].area,[PositionTool shareInfo].street]; if(_currentPosition==nil||[_currentPosition isEqualToString:@""]) { _currentPosition=_deliveryAddress; } } /** collectionView */ - (void)setupCollectionView{ UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.itemSize = CGSizeMake(85, 85); flowLayout.minimumInteritemSpacing = 5; flowLayout.minimumLineSpacing = 10; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.sectionInset = UIEdgeInsetsMake(7, 20, 0, 20); self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, (85+15)*3) collectionViewLayout:flowLayout]; self.collectionView.backgroundColor = [UIColor clearColor]; self.collectionView.dataSource = self; self.collectionView.delegate = self; [self.collectionView registerNib:[UINib nibWithNibName:@"DKUICollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"DKUICollectionViewCell"]; [_vcollectionview addSubview:self.collectionView]; } /** 照相事件 */ - (void)selectCamera{ DKCameraViewController *cameraVc = [[DKCameraViewController alloc] init]; __weak typeof(self) weakSelf = self; // 多选相册+相机多拍 回调 [cameraVc startCameraOrPhotoFileWithViewController:self complate:^(NSArray *object) { // 选择完照片、拍照完回调 [object enumerateObjectsUsingBlock:^(id asset, NSUInteger idx, BOOL *stop) { if(weakSelf.assets.count < 9) { if ([asset isKindOfClass:[DKCamera class]]) { [weakSelf.assets addObject:asset]; }else{ [weakSelf.assets addObject:asset]; } }else{ [self showAlertViewText:@"最多只能选择9张图片"]; } }]; [weakSelf.collectionView reloadData]; }]; weakSelf.cameraVc=cameraVc; } -(void)selectSignature { SignViewController *signVc=[[SignViewController alloc]init]; signVc.signDelegate=self; [self.navigationController pushViewController:signVc animated:YES]; } -(void)getSignImg:(UIImage *)img { _signImg=img; CGFloat collectionheight=0; if (self.assets.count == 0) { collectionheight=0; }else { NSInteger i=(NSInteger)(self.assets.count-1)/3+1; collectionheight=(85+10)*i; } self.collectionView.frame=CGRectMake(0, 0, Screen_Width, collectionheight); _vcollectionview.frame=CGRectMake(0, 0, Screen_Width, collectionheight); _imgView.frame=CGRectMake(10, 10, 100, 100); _vSign.frame=CGRectMake(0,CGRectGetMaxY(_vcollectionview.frame), Screen_Width, CGRectGetMaxY(_imgView.frame)); _imgView.image=_signImg; _vImage.frame=CGRectMake(0, CGRectGetMaxY(_vSign.frame), Screen_Width, 35); //btnSave.frame=CGRectMake((Screen_Width-204)*0.5, 51*9+25+collectionheight, 204, 35); scroll.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight); _contentView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight); } /** 相册 */ - (void)selectPhotos { // 创建控制器 DKPhotoPickerViewController *pickerVc = [[DKPhotoPickerViewController alloc] init]; // 默认显示相册里面的内容SavePhotos pickerVc.status = PickerViewShowStatusCameraRoll; pickerVc.selectPickers = self.assets; // 最多能选9张图片 pickerVc.minCount = 9; pickerVc.cameraCount = [self cameraCount]; pickerVc.delegate = self; [pickerVc show]; } @end