DispatchImageInfoVC.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. //
  2. // DispatchImageInfoVC.m
  3. // IBOSS-HJ
  4. //
  5. // Created by 关宏厚 on 2021/2/1.
  6. // Copyright © 2021 elongtian. All rights reserved.
  7. //
  8. #import "DispatchImageInfoVC.h"
  9. #import "DKUITableViewController.h"
  10. #import "DKUICollectionViewCell.h"
  11. #import "DKPhoto.h"
  12. #import "SignViewController.h"
  13. #import "PayTypeModel.h"
  14. #import "NewDispatchRequirementModel.h"
  15. @interface DispatchImageInfoVC ()<UITextViewDelegate,UICollectionViewDataSource, UICollectionViewDelegate,DKPhotoPickerViewControllerDelegate,DKPhotoPickerBrowserViewControllerDataSource,DKPhotoPickerBrowserViewControllerDelegate>
  16. {
  17. // 图片控件
  18. UIView *_vcollectionview;
  19. // 内容控件
  20. UIView *_contentView;
  21. // 滚动条
  22. UIScrollView *scroll;
  23. // 图片
  24. UIView *_vImage;
  25. // 分割线背景
  26. UIView *_viewBackgroud;
  27. // 高度
  28. CGFloat _titleHeight;
  29. UIView *_vSign;
  30. UIImageView *_imgView;
  31. }
  32. /**
  33. 照相vc
  34. */
  35. @property (strong,nonatomic) DKCameraViewController *cameraVc;
  36. /**
  37. 上传 后返回照片的路径
  38. */
  39. @property (nonatomic , strong) NSMutableArray *imagePaths;
  40. /**
  41. 本地存入沙盒照片的路径
  42. */
  43. @property (nonatomic , strong) NSMutableArray *imageLocalPaths;
  44. /**
  45. 必须输入的项目的字符串
  46. */
  47. @property (copy, nonatomic) NSString* sMustInputItems;
  48. @end
  49. @implementation DispatchImageInfoVC
  50. - (void)viewDidLoad {
  51. [super viewDidLoad];
  52. [[PositionTool shareInfo] addDelegate:self];
  53. [[PositionTool shareInfo] getLocation];
  54. [[PositionTool shareInfo] updateLocation];
  55. [self initUI];
  56. }
  57. #pragma mark - 属性
  58. /**
  59. <#Description#>
  60. @return <#return value description#>
  61. */
  62. - (NSMutableArray *)assets{
  63. if (!_assets) {
  64. _assets = [NSMutableArray array];
  65. }
  66. return _assets;
  67. }
  68. /**
  69. <#Description#>
  70. @return <#return value description#>
  71. */
  72. - (NSMutableArray *)imagePaths{
  73. if (!_imagePaths) {
  74. _imagePaths = [NSMutableArray array];
  75. }
  76. return _imagePaths;
  77. }
  78. - (NSMutableArray *)signImgList{
  79. if (!_signImgList) {
  80. _signImgList = [NSMutableArray array];
  81. }
  82. return _signImgList;
  83. }
  84. /**
  85. <#Description#>
  86. @return <#return value description#>
  87. */
  88. - (NSMutableArray *)imageLocalPaths{
  89. if (!_imageLocalPaths) {
  90. _imageLocalPaths = [NSMutableArray array];
  91. }
  92. return _imageLocalPaths;
  93. }
  94. #pragma mark - 图片回调
  95. /**
  96. Section
  97. @param pickerBrowser <#pickerBrowser description#>
  98. @return <#return value description#>
  99. */
  100. - (NSInteger)numberOfSectionInPhotosInPickerBrowser:(DKPhotoPickerBrowserViewController *)pickerBrowser{
  101. return 1;
  102. }
  103. /**
  104. 图片个数
  105. @param photoBrowser <#photoBrowser description#>
  106. @param section <#section description#>
  107. @return <#return value description#>
  108. */
  109. - (NSInteger)photoBrowser:(DKPhotoPickerBrowserViewController *)photoBrowser numberOfItemsInSection:(NSUInteger)section{
  110. return [self.assets count];
  111. }
  112. /**
  113. 单元格图片
  114. @param pickerBrowser <#pickerBrowser description#>
  115. @param indexPath <#indexPath description#>
  116. @return <#return value description#>
  117. */
  118. - (DKPhotoPickerBrowserPhoto *)photoBrowser:(DKPhotoPickerBrowserViewController *)pickerBrowser photoAtIndexPath:(NSIndexPath *)indexPath{
  119. id imageObj = [self.assets objectAtIndex:indexPath.item];
  120. DKPhotoPickerBrowserPhoto *photo = [DKPhotoPickerBrowserPhoto photoAnyImageObjWith:imageObj];
  121. // 包装下imageObj 成 DKPhotoPickerBrowserPhoto 传给数据源
  122. DKUICollectionViewCell *cell = (DKUICollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
  123. // 缩略图
  124. photo.thumbImage = cell.imageView.image;
  125. return photo;
  126. }
  127. /**
  128. 删除图片
  129. @param photoBrowser <#photoBrowser description#>
  130. @param indexPath <#indexPath description#>
  131. */
  132. - (void)photoBrowser:(DKPhotoPickerBrowserViewController *)photoBrowser removePhotoAtIndexPath:(NSIndexPath *)indexPath{
  133. if (indexPath.row > [self.assets count]) return;
  134. [self.assets removeObjectAtIndex:indexPath.row];
  135. [self.collectionView reloadData];
  136. }
  137. /**
  138. 代理协议回调函数
  139. @param assets <#assets description#>
  140. */
  141. - (void)pickerViewControllerDoneAsstes:(NSArray *)assets{
  142. for (int i=(int)self.assets.count-1;i>=0;i-- ) {
  143. if ([self.assets[i] isKindOfClass:[DKPhotoAssets class]]) {
  144. [self.assets removeObject:self.assets[i]];
  145. }
  146. }
  147. for (DKPhotoAssets* asset in assets ) {
  148. if ([asset isKindOfClass:[DKPhotoAssets class]]) {
  149. [self.assets addObject:asset];
  150. }
  151. }
  152. [self.collectionView reloadData];
  153. }
  154. /**
  155. 图片数量-包括照相和相册
  156. @param NSInteger <#NSInteger description#>
  157. @return <#return value description#>
  158. */
  159. - (NSInteger)cameraCount{
  160. NSInteger count=0;
  161. for (int i=0; i<self.assets.count; i++) {
  162. id asset=self.assets[i];
  163. if ([asset isKindOfClass:[DKCamera class]]) {
  164. count++;
  165. }
  166. }
  167. return count;
  168. }
  169. #pragma mark - 图片列表回调
  170. /**
  171. Sections
  172. @param collectionView <#collectionView description#>
  173. @return <#return value description#>
  174. */
  175. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  176. return 1;
  177. }
  178. /**
  179. 个数
  180. @param collectionView <#collectionView description#>
  181. @param section <#section description#>
  182. @return <#return value description#>
  183. */
  184. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  185. CGFloat collectionheight=0;
  186. if (self.assets.count == 0) {
  187. collectionheight=0;
  188. }else {
  189. NSInteger i=(NSInteger)(self.assets.count-1)/3+1;
  190. collectionheight=(85+10)*i;
  191. }
  192. self.collectionView.frame=CGRectMake(0, 0, Screen_Width, collectionheight);
  193. _vcollectionview.frame=CGRectMake(0, 0, Screen_Width, collectionheight);
  194. _vSign.frame=CGRectMake(0,CGRectGetMaxY(_vcollectionview.frame), Screen_Width, CGRectGetMaxY(_imgView.frame));
  195. _vImage.frame=CGRectMake(0, CGRectGetMaxY(_vSign.frame), Screen_Width, 35);
  196. //btnSave.frame=CGRectMake((Screen_Width-204)*0.5, 51*9+25+collectionheight, 204, 35);
  197. scroll.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight);
  198. _contentView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight);
  199. return [self.assets count];
  200. }
  201. /**
  202. 单元格cell
  203. @param collectionView <#collectionView description#>
  204. @param indexPath <#indexPath description#>
  205. @return <#return value description#>
  206. */
  207. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  208. DKUICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DKUICollectionViewCell" forIndexPath:indexPath];
  209. // 判断类型来获取Image
  210. DKPhotoAssets *asset = self.assets[indexPath.item];
  211. if ([asset isKindOfClass:[DKPhotoAssets class]]) {
  212. cell.imageView.image = asset.originImage;
  213. }else if ([asset isKindOfClass:[NSString class]]){
  214. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:(NSString *)asset] placeholderImage:[UIImage imageNamed:@"wallpaper_placeholder"]];
  215. }else if([asset isKindOfClass:[UIImage class]]){
  216. cell.imageView.image = (UIImage *)asset;
  217. }else if ([asset isKindOfClass:[DKCamera class]]){
  218. cell.imageView.image = [(DKCamera*)asset thumbImage];
  219. }
  220. return cell;
  221. }
  222. /**
  223. 显示图片
  224. @param collectionView <#collectionView description#>
  225. @param indexPath <#indexPath description#>
  226. */
  227. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  228. DKUICollectionViewCell *cell = (DKUICollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
  229. // 图片游览器
  230. DKPhotoPickerBrowserViewController *pickerBrowser = [[DKPhotoPickerBrowserViewController alloc] init];
  231. // 传入点击图片View的话,会有微信朋友圈照片的风格
  232. pickerBrowser.toView = cell.imageView;
  233. // 数据源/delegate
  234. pickerBrowser.delegate = self;
  235. pickerBrowser.dataSource = self;
  236. // 是否可以删除照片
  237. pickerBrowser.editing = YES;
  238. // 当前选中的值
  239. pickerBrowser.currentIndexPath = [NSIndexPath indexPathForItem:indexPath.row inSection:0];
  240. // 展示控制器
  241. [pickerBrowser show];
  242. }
  243. #pragma mark - 私有函数
  244. -(void)goBack
  245. {
  246. [self.navigationController popViewControllerAnimated:YES];
  247. }
  248. -(void)goBackHome
  249. {
  250. if([self.refreshDelegate respondsToSelector:@selector(refreshData)])
  251. {
  252. [self.refreshDelegate refreshData];
  253. }
  254. [self.navigationController popViewControllerAnimated:YES];
  255. }
  256. /**
  257. 安全区视图发生变化
  258. */
  259. -(void)viewSafeAreaInsetsDidChange{
  260. [self.view setBackgroundColor:[UIColor whiteColor]];
  261. scroll.frame =CGRectMake(0, 0, Screen_Width, self.view.safeAreaLayoutGuide.layoutFrame.size.height -40);
  262. _btnSave.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-40, Screen_Width,40) ;
  263. [super viewSafeAreaInsetsDidChange];
  264. }
  265. /**
  266. 初始化UI
  267. */
  268. - (void)initUI{
  269. self.navigationItem.title = @"图片信息";
  270. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  271. [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
  272. forState:UIControlStateNormal];
  273. [button addTarget:self action:@selector(goBack)
  274. forControlEvents:UIControlEventTouchUpInside];
  275. button.frame = CGRectMake(0, 0,15,18);
  276. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  277. self.navigationItem.leftBarButtonItem = menuButton;
  278. _titleHeight = 45;
  279. CGFloat fontsize = LabelAndTextFontOfSize;
  280. CGFloat lblx = 20;
  281. // 滚动条目
  282. scroll = [UIScrollView new];
  283. scroll.frame=self.view.bounds;
  284. [self.view addSubview:scroll];
  285. self.view.backgroundColor = [UIColor whiteColor];
  286. // 画面文本显示view
  287. _contentView = [[UIView alloc]init];
  288. [scroll addSubview:_contentView];
  289. _contentView.frame=CGRectZero;
  290. /////////图片
  291. _vcollectionview = [UIView new];
  292. _vcollectionview.frame=CGRectMake(0,0, Screen_Width, 1);
  293. [_contentView addSubview:_vcollectionview];
  294. [self setupCollectionView];
  295. _vSign=[UIView new];
  296. _vSign.frame=CGRectMake(0,CGRectGetMaxY(_vcollectionview.frame), Screen_Width, 1);
  297. [_contentView addSubview:_vSign];
  298. _imgView=[[UIImageView alloc]init];
  299. _imgView.frame=CGRectMake(10, 10, 100, 0);
  300. [_vSign addSubview:_imgView];
  301. //照相和相册 —————————
  302. _vImage = [UIView new];
  303. _vImage.frame=CGRectMake(0, CGRectGetMaxY(_vSign.frame)+10, Screen_Width, 35);
  304. [_contentView addSubview:_vImage];
  305. UIButton *btnCamera = [UIButton buttonWithType:UIButtonTypeCustom];
  306. btnCamera.frame=CGRectMake(20, 6, 16, 13);
  307. [btnCamera setBackgroundImage:[UIImage imageNamed:@"icon_takephoto"] forState:UIControlStateNormal];
  308. btnCamera.tag = 1010;
  309. [btnCamera addTarget:self action:@selector(selectCamera) forControlEvents:UIControlEventTouchUpInside];
  310. [_vImage addSubview:btnCamera];
  311. UIButton *btnCameraValue = [UIButton buttonWithType:UIButtonTypeCustom];
  312. btnCameraValue.frame=CGRectMake(CGRectGetMaxX(btnCamera.frame)+5, 7, Screen_Width/3-20-13, 13);
  313. [btnCameraValue setTitle:@"照相" forState:UIControlStateNormal];
  314. [btnCameraValue setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  315. btnCameraValue.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  316. btnCameraValue.titleLabel.font= [UIFont systemFontOfSize:ButtonFontOfSize];
  317. btnCameraValue.tag = 1011;
  318. [btnCameraValue addTarget:self action:@selector(selectCamera) forControlEvents:UIControlEventTouchUpInside];
  319. [_vImage addSubview:btnCameraValue];
  320. UIButton *btnPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
  321. btnPhoto.frame=CGRectMake(CGRectGetMaxX(btnCameraValue.frame), 6, 14, 15);
  322. [btnPhoto setBackgroundImage:[UIImage imageNamed:@"icon_photo"] forState:UIControlStateNormal];
  323. btnPhoto.tag=1020;
  324. [btnPhoto addTarget:self action:@selector(selectPhotos) forControlEvents:UIControlEventTouchUpInside];
  325. [_vImage addSubview:btnPhoto];
  326. UIButton *btnPhotoValue = [UIButton buttonWithType:UIButtonTypeCustom];
  327. btnPhotoValue.frame=CGRectMake(CGRectGetMaxX(btnPhoto.frame)+5, 7, Screen_Width/3-14, 15);
  328. [btnPhotoValue setTitle:@"相册" forState:UIControlStateNormal];
  329. [btnPhotoValue setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  330. btnPhotoValue.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  331. btnPhotoValue.titleLabel.font= [UIFont systemFontOfSize:ButtonFontOfSize];
  332. btnPhotoValue.tag = 1021;
  333. [btnPhotoValue addTarget:self action:@selector(selectPhotos) forControlEvents:UIControlEventTouchUpInside];
  334. [_vImage addSubview:btnPhotoValue];
  335. UIButton *btnSignature = [UIButton buttonWithType:UIButtonTypeCustom];
  336. btnSignature.frame=CGRectMake(CGRectGetMaxX(btnPhotoValue.frame), 6, 14, 15);
  337. [btnSignature setBackgroundImage:[UIImage imageNamed:@"icon_photo"] forState:UIControlStateNormal];
  338. btnSignature.tag=1022;
  339. [btnSignature addTarget:self action:@selector(selectSignature) forControlEvents:UIControlEventTouchUpInside];
  340. [_vImage addSubview:btnSignature];
  341. UIButton *btnSignatureValue = [UIButton buttonWithType:UIButtonTypeCustom];
  342. btnSignatureValue.frame=CGRectMake(CGRectGetMaxX(btnSignature.frame)+5, 7, Screen_Width/3-14, 15);
  343. [btnSignatureValue setTitle:@"签名" forState:UIControlStateNormal];
  344. [btnSignatureValue setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  345. btnSignatureValue.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  346. btnSignatureValue.titleLabel.font= [UIFont systemFontOfSize:ButtonFontOfSize];
  347. btnSignatureValue.tag = 1022;
  348. [btnSignatureValue addTarget:self action:@selector(selectSignature) forControlEvents:UIControlEventTouchUpInside];
  349. [_vImage addSubview:btnSignatureValue];
  350. _contentView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(_vImage.frame) );
  351. scroll.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_contentView.frame)+rectStatusHeight+rectNavHeight+ 150);
  352. //保存按钮
  353. _btnSave = [UIButton buttonWithType:UIButtonTypeCustom];
  354. _btnSave.frame=CGRectMake(0, Screen_Height- 40 - rectStatusHeight-rectNavHeight, Screen_Width,40) ;
  355. _btnSave.backgroundColor=NavigationBarColor;
  356. [_btnSave setTitle:@"确定" forState:UIControlStateNormal];
  357. [_btnSave setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  358. [_btnSave addTarget:self action:@selector(saveInfo) forControlEvents:UIControlEventTouchUpInside];
  359. [self.view addSubview:_btnSave];
  360. }
  361. /**
  362. 保存图片到沙盒
  363. @param currentImage <#currentImage description#>
  364. @param imageName <#imageName description#>
  365. @return <#return value description#>
  366. */
  367. - (DKCamera *) saveImage:(UIImage *)currentImage withName:(NSString *)imageName
  368. {
  369. if (!currentImage) {
  370. return nil;
  371. }
  372. NSDateFormatter *formater = [[NSDateFormatter alloc] init];
  373. formater.dateFormat = @"yyyyMMddHHmmss";
  374. NSString *currentTimeStr = [[formater stringFromDate:[NSDate date]] stringByAppendingFormat:@"_%d_.jpg" ,arc4random_uniform(10000)];
  375. NSData *imageData= [LeslieAsyncImageDownloader resetSizeOfImageData:currentImage maxSize:500];
  376. // 获取沙盒目录
  377. NSString *fullPath ;
  378. if([imageName isEqualToString:@""] || imageName == nil){
  379. fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:currentTimeStr];
  380. }
  381. else{
  382. fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
  383. }
  384. // 将图片写入文件
  385. [imageData writeToFile:fullPath atomically:NO];
  386. UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];
  387. DKCamera *camera = [[DKCamera alloc] init];
  388. camera.imagePath = fullPath;
  389. camera.thumbImage = savedImage;// [UIImage imageWithData:data];
  390. return camera;
  391. }
  392. /**
  393. 保存数据函数
  394. */
  395. - (void)saveInfo{
  396. [self startLoading];
  397. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  398. if(![self savePicsManager]){
  399. return;
  400. }
  401. if(![self saveSignManager]){
  402. return;
  403. }
  404. self.mDownManager = [[ASIDownManager alloc] init];
  405. self.mDownManager.delegate = self;
  406. self.mDownManager.onRequestSuccess = @selector(onSaveLoadFinish:);
  407. self.mDownManager.onRequestFail = @selector(onSaveLoadFail:);
  408. NSString *urlStr = ServerURL;
  409. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  410. [dict setObject:@"SaveInstallationDemandReceiptDataIphone" forKey:@"Action"];
  411. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  412. [dict setObject:kkUserCode forKey:@"UserCode"];
  413. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  414. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  415. [dict setObject:kkLicenseCode forKey:@"LicenseCode"];
  416. [dict setObject:_currentPosition==nil?@"":_currentPosition forKeyedSubscript:@"Position"];
  417. NSMutableDictionary *dicHead = [[NSMutableDictionary alloc] init];
  418. NSMutableArray *arrHead = [[NSMutableArray alloc]init];
  419. [dicHead setObject:_arrangementId forKeyedSubscript:@"ArrangementID"];
  420. [dicHead setObject:_collectDetailId forKeyedSubscript:@"CollectDetailID"];
  421. [dicHead setObject:_customerId forKey:@"CustomerID"];
  422. [dicHead setObject:_receiptAmount forKeyedSubscript:@"ReceivableSum"];
  423. [dicHead setObject:_nextDeliveryDate==nil?@"":_nextDeliveryDate forKeyedSubscript:@"NextDeliveryDate"];
  424. [dicHead setObject:_truckNumber forKeyedSubscript:@"TruckNumber"];
  425. [dicHead setObject:_receiptFlag forKeyedSubscript:@"RequirementType"];
  426. [dicHead setObject:_receivable forKeyedSubscript:@"Receivable"];
  427. [dicHead setObject:_organizationId==nil?@"":_organizationId forKeyedSubscript:@"OrganizationID"];
  428. [dicHead setObject:_organizationCode==nil?@"":_organizationCode forKeyedSubscript:@"OrganizationCode"];
  429. [dicHead setObject:_remarks forKeyedSubscript:@"Remarks"];
  430. [arrHead addObject:dicHead];
  431. [dict setObject:[Util objectToJson:arrHead] forKey:@"ReceiptData"];
  432. //详细列表
  433. NSMutableDictionary *dicDetails;
  434. NSMutableArray* arrDetails = [[NSMutableArray alloc]init];
  435. for (NewDispatchRequirementModel* me in _dataList) {
  436. dicDetails = [[NSMutableDictionary alloc] init];
  437. [dicDetails setObject:me.detailId forKeyedSubscript:@"DetailID"];
  438. [dicDetails setObject:me.receiptDetailId==nil?@"":me.receiptDetailId forKeyedSubscript:@"ReceiptDetailID"];
  439. [dicDetails setObject:me.deliveryQuantity forKeyedSubscript:@"DeliveryQuantity"];
  440. [dicDetails setObject:me.receiptQuantity forKeyedSubscript:@"DeliveryReceiptQuantity"];
  441. [dicDetails setObject:me.installQuantity forKeyedSubscript:@"InstallationQuantity"];
  442. [dicDetails setObject:me.installReceiptQuantity forKeyedSubscript:@"InstallationFinishQuantity"];
  443. [dicDetails setObject:me.receiptType forKeyedSubscript:@"DeliveryReceiptType"];
  444. [dicDetails setObject:me.installReceiptType forKeyedSubscript:@"InstallationReceiptType"];
  445. [dicDetails setObject:me.invoiceDetailId==nil?@"":me.invoiceDetailId forKeyedSubscript:@"InvoiceDetailID"];
  446. [dicDetails setObject:me.invoiceId==nil?@"":me.invoiceId forKeyedSubscript:@"InvoiceID"];
  447. [dicDetails setObject:me.receiptRemarks forKeyedSubscript:@"Remarks"];
  448. [dicDetails setObject:me.sourceFrom forKeyedSubscript:@"SourceFrom"];
  449. [arrDetails addObject:dicDetails];
  450. }
  451. [dict setObject:[Util objectToJson:arrDetails] forKey:@"ReceiptDetailData"];
  452. if(_paymentMethodArray!=nil&&_paymentMethodArray.count>0)
  453. {
  454. NSMutableArray* arrSettle = [[NSMutableArray alloc]init];
  455. for(int i=0;i<_paymentMethodArray.count;i++)
  456. {
  457. PayTypeModel *typeModel=[_paymentMethodArray objectAtIndex:i];
  458. NSMutableDictionary *dicSettle = [[NSMutableDictionary alloc] init];
  459. [dicSettle setObject:[typeModel settlementType] forKeyedSubscript:@"SettlementTypeID"];
  460. [dicSettle setObject:_collectDetailId forKeyedSubscript:@"CollectDetailID"];
  461. [dicSettle setObject:[typeModel receivableSum] forKeyedSubscript:@"ReceivableSum"];
  462. [dicSettle setObject:@"0" forKeyedSubscript:@"EarnestFee"];
  463. [dicSettle setObject:[typeModel remarks] forKeyedSubscript:@"Remarks"];
  464. [arrSettle addObject:dicSettle];
  465. }
  466. [dict setObject:[Util objectToJson:arrSettle] forKey:@"ReceiptEarnestData"];
  467. }
  468. else
  469. {
  470. [dict setObject:@"" forKey:@"ReceiptEarnestData"];
  471. }
  472. /////////图片上传返回的地址
  473. if (self.imagePaths && self.imagePaths.count > 0) {
  474. [dict setObject:[self.imagePaths componentsJoinedByString:@"," ] forKey:@"ImagePath"];
  475. }
  476. if(self.signImgList!=nil&&self.signImgList.count>0)
  477. {
  478. [dict setObject:[self.signImgList componentsJoinedByString:@"," ] forKey:@"SignImagePath"];
  479. }
  480. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  481. });
  482. }
  483. /**
  484. 保存数据加载完成函数
  485. @param sender <#sender description#>
  486. */
  487. - (void)onSaveLoadFinish:(ASIDownManager *)sender {
  488. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  489. [self stopLoading];
  490. int iStatus =resultModel.status;
  491. NSString *message = resultModel.message;
  492. if (iStatus == 0) {
  493. //[self clearData];//新增后 清除画面的值
  494. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"保存成功!" preferredStyle:UIAlertControllerStyleAlert ];
  495. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  496. [self goBackHome];
  497. }]];
  498. // 3.显示alertController:presentViewController
  499. [self presentViewController:alert animated:YES completion:nil];
  500. }
  501. else if(iStatus == ActionResultStatusAuthError
  502. ||iStatus == ActionResultStatusNoLogin
  503. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  504. [self showReLoginDialog:message];
  505. return;
  506. }
  507. else {
  508. [self showAlertViewText:message];
  509. return;
  510. }
  511. }
  512. -(void)onSaveLoadFail:(ASIDownManager *)sender {
  513. [self stopLoading];
  514. [self showAlertViewText:@"网络异常"];
  515. }
  516. /**
  517. 保存图片函数
  518. @return <#return value description#>
  519. */
  520. - (BOOL)savePicsManager{
  521. self.mDownManager = [[ASIDownManager alloc] init];
  522. self.mDownManager.delegate=self;
  523. //////////////上传图片
  524. NSString *urlStr = ServerURL;
  525. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  526. [dict setObject:@"SaveImg" forKey:@"Action"];
  527. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  528. [dict setObject:kkUserCode forKey:@"UserCode"];
  529. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  530. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  531. [self.imagePaths removeAllObjects];
  532. for (int i = 0; i < self.assets.count; i++) {
  533. DKPhotoAssets *asset = self.assets[i];
  534. DKCamera * c;
  535. if ([asset isKindOfClass:[DKPhotoAssets class]]) {
  536. c = [self saveImage:asset.originImage withName:nil];
  537. }else if ([asset isKindOfClass:[NSString class]]){
  538. }else if([asset isKindOfClass:[UIImage class]]){
  539. }else if ([asset isKindOfClass:[DKCamera class]]){
  540. c = (DKCamera *)asset;
  541. c = [self saveImage:c.thumbImage withName:nil];
  542. }
  543. //延时
  544. [NSThread sleepForTimeInterval:0.5];
  545. NSString* retValue= [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:c.imagePath filename:nil fileType:@"image/jpeg"];
  546. if (retValue == nil || retValue.length == 0){
  547. [self stopLoading];
  548. [self showAlertViewText:@"上传图片失败"];
  549. self.navigationItem.rightBarButtonItem.enabled = YES;
  550. return NO;
  551. }
  552. NSDictionary *dicRetValue = [retValue JSONValue];
  553. if (dicRetValue && [dicRetValue isKindOfClass:[NSDictionary class]]) {
  554. int iStatus = [[dicRetValue objectForKey:@"Status"] intValue];
  555. if (iStatus == 0) {
  556. NSString * imgPath = [dicRetValue objectForKey:@"Result"];
  557. [self.imagePaths addObject:imgPath];
  558. }
  559. else{
  560. [self stopLoading];
  561. return NO;
  562. }
  563. }
  564. }
  565. return YES;
  566. }
  567. - (BOOL)saveSignManager{
  568. self.mDownManager = [[ASIDownManager alloc] init];
  569. self.mDownManager.delegate=self;
  570. //////////////上传图片
  571. NSString *urlStr = ServerURL;
  572. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  573. [dict setObject:@"SaveImg" forKey:@"Action"];
  574. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  575. [dict setObject:kkUserCode forKey:@"UserCode"];
  576. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  577. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  578. [self.signImgList removeAllObjects];
  579. DKCamera * c;
  580. if(_signImg!=nil)
  581. {
  582. c = [self saveImage:_signImg withName:nil];
  583. //延时
  584. [NSThread sleepForTimeInterval:0.5];
  585. NSString* retValue= [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:c.imagePath filename:nil fileType:@"image/jpeg"];
  586. if (retValue == nil || retValue.length == 0){
  587. [self stopLoading];
  588. [self showAlertViewText:@"上传图片失败"];
  589. self.navigationItem.rightBarButtonItem.enabled = YES;
  590. return NO;
  591. }
  592. NSDictionary *dicRetValue = [retValue JSONValue];
  593. if (dicRetValue && [dicRetValue isKindOfClass:[NSDictionary class]]) {
  594. int iStatus = [[dicRetValue objectForKey:@"Status"] intValue];
  595. if (iStatus == 0) {
  596. NSString * imgPath = [dicRetValue objectForKey:@"Result"];
  597. [self.signImgList addObject:imgPath];
  598. }
  599. else{
  600. [self stopLoading];
  601. return NO;
  602. }
  603. }
  604. }
  605. return YES;
  606. }
  607. /**
  608. 回调地理位置
  609. */
  610. -(void)noticePositionChanged{
  611. _currentPosition = [NSString stringWithFormat:@"%@%@%@%@",[PositionTool shareInfo].province, [PositionTool shareInfo].city, [PositionTool shareInfo].area,[PositionTool shareInfo].street];
  612. if(_currentPosition==nil||[_currentPosition isEqualToString:@""])
  613. {
  614. _currentPosition=_deliveryAddress;
  615. }
  616. }
  617. /**
  618. collectionView
  619. */
  620. - (void)setupCollectionView{
  621. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  622. flowLayout.itemSize = CGSizeMake(85, 85);
  623. flowLayout.minimumInteritemSpacing = 5;
  624. flowLayout.minimumLineSpacing = 10;
  625. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  626. flowLayout.sectionInset = UIEdgeInsetsMake(7, 20, 0, 20);
  627. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, (85+15)*3) collectionViewLayout:flowLayout];
  628. self.collectionView.backgroundColor = [UIColor clearColor];
  629. self.collectionView.dataSource = self;
  630. self.collectionView.delegate = self;
  631. [self.collectionView registerNib:[UINib nibWithNibName:@"DKUICollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"DKUICollectionViewCell"];
  632. [_vcollectionview addSubview:self.collectionView];
  633. }
  634. /**
  635. 照相事件
  636. */
  637. - (void)selectCamera{
  638. DKCameraViewController *cameraVc = [[DKCameraViewController alloc] init];
  639. __weak typeof(self) weakSelf = self;
  640. // 多选相册+相机多拍 回调
  641. [cameraVc startCameraOrPhotoFileWithViewController:self
  642. complate:^(NSArray *object)
  643. {
  644. // 选择完照片、拍照完回调
  645. [object enumerateObjectsUsingBlock:^(id asset, NSUInteger idx, BOOL *stop)
  646. {
  647. if(weakSelf.assets.count < 9)
  648. {
  649. if ([asset isKindOfClass:[DKCamera class]]) {
  650. [weakSelf.assets addObject:asset];
  651. }else{
  652. [weakSelf.assets addObject:asset];
  653. }
  654. }else{
  655. [self showAlertViewText:@"最多只能选择9张图片"];
  656. }
  657. }];
  658. [weakSelf.collectionView reloadData];
  659. }];
  660. weakSelf.cameraVc=cameraVc;
  661. }
  662. -(void)selectSignature
  663. {
  664. SignViewController *signVc=[[SignViewController alloc]init];
  665. signVc.signDelegate=self;
  666. [self.navigationController pushViewController:signVc animated:YES];
  667. }
  668. -(void)getSignImg:(UIImage *)img
  669. {
  670. _signImg=img;
  671. CGFloat collectionheight=0;
  672. if (self.assets.count == 0) {
  673. collectionheight=0;
  674. }else {
  675. NSInteger i=(NSInteger)(self.assets.count-1)/3+1;
  676. collectionheight=(85+10)*i;
  677. }
  678. self.collectionView.frame=CGRectMake(0, 0, Screen_Width, collectionheight);
  679. _vcollectionview.frame=CGRectMake(0, 0, Screen_Width, collectionheight);
  680. _imgView.frame=CGRectMake(10, 10, 100, 100);
  681. _vSign.frame=CGRectMake(0,CGRectGetMaxY(_vcollectionview.frame), Screen_Width, CGRectGetMaxY(_imgView.frame));
  682. _imgView.image=_signImg;
  683. _vImage.frame=CGRectMake(0, CGRectGetMaxY(_vSign.frame), Screen_Width, 35);
  684. //btnSave.frame=CGRectMake((Screen_Width-204)*0.5, 51*9+25+collectionheight, 204, 35);
  685. scroll.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight);
  686. _contentView.frame = CGRectMake(0, 0, Screen_Width, CGRectGetMaxY(_vImage.frame)+rectStatusHeight+rectNavHeight);
  687. }
  688. /**
  689. 相册
  690. */
  691. - (void)selectPhotos {
  692. // 创建控制器
  693. DKPhotoPickerViewController *pickerVc = [[DKPhotoPickerViewController alloc] init];
  694. // 默认显示相册里面的内容SavePhotos
  695. pickerVc.status = PickerViewShowStatusCameraRoll;
  696. pickerVc.selectPickers = self.assets;
  697. // 最多能选9张图片
  698. pickerVc.minCount = 9;
  699. pickerVc.cameraCount = [self cameraCount];
  700. pickerVc.delegate = self;
  701. [pickerVc show];
  702. }
  703. @end