CustomerCodeShareVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. //
  2. // CustomerCodeShareViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/7/16.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "CustomerCodeShareVC.h"
  9. #import "PrintCell.h"
  10. #import "ImageModel.h"
  11. @interface CustomerCodeShareVC ()
  12. @end
  13. @implementation CustomerCodeShareVC
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. _photoList=[[NSMutableArray alloc]init];
  17. _cellDic=[[NSMutableDictionary alloc]init];
  18. [self loadNavStyle];
  19. [self initUI];
  20. [self loadData];
  21. }
  22. /**
  23. 导航按钮样式
  24. */
  25. -(void)loadNavStyle
  26. {
  27. //右边
  28. UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom];
  29. [btnAdd addTarget:self action:@selector(share)
  30. forControlEvents:UIControlEventTouchUpInside];
  31. btnAdd.frame = CGRectMake(0, 0, 50, 18);
  32. [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  33. [btnAdd setTitle:@"分享" forState:UIControlStateNormal];
  34. UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
  35. self.navigationItem.rightBarButtonItem = menubtnAdd;
  36. self.navigationItem.title=@"客户编码单据";
  37. //返回
  38. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  39. [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
  40. forState:UIControlStateNormal];
  41. [button addTarget:self action:@selector(goBack)
  42. forControlEvents:UIControlEventTouchUpInside];
  43. button.frame = CGRectMake(0, 0, 15, 18);
  44. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  45. self.navigationItem.leftBarButtonItem = menuButton;
  46. }
  47. -(void)share{
  48. _shareList=[[NSMutableArray alloc]init];
  49. if(_photoList!=nil&&_photoList.count>0){
  50. for(ImageModel *model in _photoList){
  51. if(model.checkFlag){
  52. NSString *serverPath=model.imagePath;
  53. NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,serverPath];
  54. LeslieImageCache *imageCache = [LeslieImageCache sharedCache];
  55. NSString *filePath=[imageCache getImageNameFromFileForKey:imageUrl];
  56. UIImage *img=[UIImage imageWithContentsOfFile:filePath];
  57. NSData *imgData=[LeslieAsyncImageDownloader resetSizeOfImageData:img maxSize:500];
  58. img= [UIImage imageWithData: imgData];
  59. [_shareList addObject:img];
  60. }
  61. }
  62. if(_shareList!=nil&&_shareList.count==0){
  63. [self showAlertViewText:@"请选择客户编码单据"];
  64. return;
  65. }
  66. if(_shareList.count>9){
  67. [self showAlertViewText:@"最多分享9张客户编码单据"];
  68. return;
  69. }
  70. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:_shareList applicationActivities:nil];
  71. activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeSaveToCameraRoll];
  72. [self presentViewController:activityVC animated:YES completion:nil];
  73. }
  74. }
  75. /**
  76. 修改:2017-9-25
  77. 适配机型
  78. 安全区视图发生变化
  79. */
  80. -(void)viewSafeAreaInsetsDidChange{
  81. self.view.backgroundColor = [UIColor whiteColor];
  82. _collectionView.frame=CGRectMake(0, (self.view.safeAreaLayoutGuide.layoutFrame.size.height-300-rectNavHeight-rectStatusHeight)/2,self.view.frame.size.width,300);
  83. _bottomView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-50, self.view.frame.size.width, 50);
  84. [super viewSafeAreaInsetsDidChange];
  85. }
  86. /**
  87. 加载订单数据
  88. */
  89. -(void)loadData{
  90. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  91. [dict setObject:@"GetOrderGoodsCodeImagesIphone" forKey:@"Action"];
  92. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  93. [dict setObject:kkUserCode forKey:@"UserCode"];
  94. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  95. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  96. [dict setObject:_orderId forKey:@"OrderID"];
  97. _downManager = [[ASIDownManager alloc] init];
  98. [self startLoading];
  99. _downManager.delegate = self;
  100. _downManager.onRequestSuccess = @selector(onCustomerCodeLoadFinish:);
  101. _downManager.onRequestFail = @selector(onCustomerCodeLoadFail:);
  102. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  103. }
  104. /**
  105. 加载总数数据成功回调
  106. @param sender <#sender description#>
  107. */
  108. - (void)onCustomerCodeLoadFinish:(ASIDownManager *)sender {
  109. NSDictionary *dic = [sender.mWebStr JSONValue];
  110. [self stopLoading];
  111. // 服务器返回数据是否正确
  112. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  113. // 服务器返回数据状态值
  114. int iStatus = [[dic objectForKey:@"Status"] intValue];
  115. // 服务器返回数据消息
  116. NSString *message=[dic objectForKey:@"Message"];
  117. // 服务器返回数据状态值正确
  118. if (iStatus == 0) {
  119. NSDictionary *resultDic=[dic objectForKey:@"Result"];
  120. NSArray *resultArray=[resultDic objectForKey:@"Table"];
  121. if(resultArray!=nil&&resultArray.count>0){
  122. for(int i=0;i<resultArray.count;i++){
  123. NSDictionary *dic=[resultArray objectAtIndex:i];
  124. int codeId= [[dic objectForKey:@"CodeID"]intValue];
  125. int orderId= [[dic objectForKey:@"OrderID"]intValue];
  126. NSString *orderNo=[dic objectForKey:@"OrderNo"];
  127. NSString *filePath=[dic objectForKey:@"FilePath"];
  128. ImageModel *imgModel=[ImageModel new];
  129. [imgModel setCodeId:[NSString stringWithFormat:@"%d",codeId]];
  130. [imgModel setOrderId:[NSString stringWithFormat:@"%d",orderId]];
  131. [imgModel setOrderNo:orderNo];
  132. [imgModel setCheckFlag:YES];
  133. if(filePath!=nil){
  134. filePath = [filePath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
  135. [imgModel setImagePath:filePath];
  136. }
  137. [_photoList addObject:imgModel];
  138. }
  139. _isCheckedAll=YES;
  140. [_collectionView reloadData];
  141. }
  142. }
  143. // 服务器返回数据状态值异常
  144. else if(iStatus==ActionResultStatusAuthError
  145. ||iStatus==ActionResultStatusNoLogin
  146. ||iStatus==ActionResultStatusLogined){
  147. [self showReLoginDialog:message];
  148. }
  149. else{
  150. [self showAlertViewText:message];
  151. }
  152. }
  153. }
  154. /**
  155. 加载总数数据失败回调
  156. @param sender <#sender description#>
  157. */
  158. - (void)onCustomerCodeLoadFail:(ASIDownManager *)sender {
  159. [self stopLoading];
  160. [self showAlertViewText:@"加载失败"];
  161. }
  162. -(void)initUI{
  163. //保存
  164. _bottomView=[UIView new];
  165. _bottomView.frame=CGRectMake(0, Screen_Height-110, self.view.frame.size.width, 50);
  166. [self.view addSubview:_bottomView];
  167. UIView *bottomSeparatorView = [UIView new];
  168. bottomSeparatorView.frame=CGRectMake(0,0, Screen_Width, 1);
  169. bottomSeparatorView.backgroundColor = LineBackgroundColor;
  170. [_bottomView addSubview:bottomSeparatorView];
  171. _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom];
  172. _btnCheckAll.frame=CGRectMake(15,12, 25, 25);
  173. [_btnCheckAll addTarget:self action:@selector(checkAll)
  174. forControlEvents:UIControlEventTouchUpInside];
  175. [_bottomView addSubview:_btnCheckAll];
  176. UILabel *lblall=[UILabel new];
  177. lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,12, 60, 25);
  178. lblall.text=@"全选";
  179. [_bottomView addSubview:lblall];
  180. [self.view setBackgroundColor:[UIColor whiteColor]];
  181. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  182. flowLayout.itemSize = CGSizeMake(Screen_Width, 300);
  183. flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  184. flowLayout.minimumLineSpacing = 0;
  185. [self.view addSubview:_bottomView];
  186. [self changeCheckALLSelect];
  187. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,(Screen_Height-300-rectNavHeight-rectStatusHeight)/2,self.view.frame.size.width,300) collectionViewLayout:flowLayout];
  188. _collectionView.delegate = self;
  189. _collectionView.dataSource = self;
  190. _collectionView.showsHorizontalScrollIndicator = NO;
  191. _collectionView.pagingEnabled = YES;
  192. _collectionView.backgroundColor = [UIColor clearColor];
  193. [self.view addSubview:_collectionView];
  194. }
  195. -(void)checkAll{
  196. [self updateAllCellCheck];
  197. [_collectionView reloadData];
  198. if(_isCheckedAll){
  199. [self changeCheckALLSelect];
  200. }
  201. else{
  202. [self changeCheckAllUnSelect];
  203. }
  204. }
  205. //全部选中
  206. -(void)changeCheckALLSelect
  207. {
  208. [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal];
  209. }
  210. //全部未选中
  211. -(void)changeCheckAllUnSelect
  212. {
  213. [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal];
  214. }
  215. -(void)btnCheckPressed:(PrintCell*)cell{
  216. _clickMode=YES;
  217. if(_clickMode){
  218. _clickMode=NO;
  219. for(int i=0;i<_photoList.count;i++){
  220. ImageModel *model=[_photoList objectAtIndex:i];
  221. if(i==cell.cellIndex){
  222. model.checkFlag=!model.checkFlag;
  223. break;
  224. }
  225. }
  226. [_collectionView reloadData];
  227. //更新全部是否选中
  228. BOOL ischeckedll=YES;
  229. for(int i=0;i<_photoList.count;i++){
  230. ImageModel *model=[_photoList objectAtIndex:i];
  231. if( model.checkFlag==NO)
  232. {
  233. ischeckedll=NO;
  234. break;
  235. }
  236. }
  237. _isCheckedAll=ischeckedll;
  238. if(_isCheckedAll){
  239. [self changeCheckALLSelect];
  240. }
  241. else{
  242. [self changeCheckAllUnSelect];
  243. }
  244. }
  245. }
  246. //全选或者全不选
  247. -(void)updateAllCellCheck
  248. {
  249. if(!_isCheckedAll){
  250. _isCheckedAll=YES;
  251. for(ImageModel *model in _photoList) {
  252. model.checkFlag =YES;
  253. }
  254. }
  255. else
  256. {
  257. _isCheckedAll=NO;
  258. for(ImageModel *model in _photoList) {
  259. model.checkFlag =NO;
  260. }
  261. }
  262. }
  263. #pragma mark- UICollectionViewDataSource
  264. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  265. return 1;
  266. }
  267. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  268. return _photoList.count;
  269. }
  270. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  271. // 每次先从字典中根据IndexPath取出唯一标识符
  272. NSString *identifier = [_cellDic objectForKey:[NSString stringWithFormat:@"%@", indexPath]];
  273. // 如果取出的唯一标示符不存在,则初始化唯一标示符,并将其存入字典中,对应唯一标示符注册Cell
  274. if (identifier == nil) {
  275. identifier = [NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"%@", indexPath]];
  276. [_cellDic setValue:identifier forKey:[NSString stringWithFormat:@"%@", indexPath]];
  277. // 注册Cell
  278. [self.collectionView registerClass:[[PrintCell class] class] forCellWithReuseIdentifier:identifier];
  279. }
  280. PrintCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
  281. for (UIView *view in cell.contentView.subviews)
  282. {
  283. [view removeFromSuperview];
  284. }
  285. cell.delegate=self;
  286. cell.cellIndex=indexPath.row;
  287. cell.delegate=self;
  288. NSInteger currentIndex= indexPath.row;
  289. ImageModel *image =_photoList[currentIndex];
  290. cell.delegate=self;
  291. NSString *imagepath=[image imagePath];
  292. if(imagepath!=nil&&[imagepath length]>0){
  293. NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,imagepath];
  294. NSURL *url = [NSURL URLWithString:imageUrl];
  295. NSInteger currentIndex= indexPath.row;
  296. NSString *page = [ NSString stringWithFormat:@"%ld/%ld页",currentIndex+1,(unsigned long)_photoList.count];
  297. [cell.imgView downloadImageWithMultipleURL:url];
  298. [cell setPageNumber:page];
  299. [cell setCheckBackground:image.checkFlag];
  300. }
  301. return cell;
  302. }
  303. @end