// // CustomerCodeShareViewController.m // IBOSSmini // // Created by guan hong hou on 2018/7/16. // Copyright © 2018年 elongtian. All rights reserved. // #import "CustomerCodeShareVC.h" #import "PrintCell.h" #import "ImageModel.h" @interface CustomerCodeShareVC () @end @implementation CustomerCodeShareVC - (void)viewDidLoad { [super viewDidLoad]; _photoList=[[NSMutableArray alloc]init]; _cellDic=[[NSMutableDictionary alloc]init]; [self loadNavStyle]; [self initUI]; [self loadData]; } /** 导航按钮样式 */ -(void)loadNavStyle { //右边 UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom]; [btnAdd addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside]; btnAdd.frame = CGRectMake(0, 0, 50, 18); [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [btnAdd setTitle:@"分享" forState:UIControlStateNormal]; UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd]; self.navigationItem.rightBarButtonItem = menubtnAdd; self.navigationItem.title=@"客户编码单据"; //返回 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"icon_back"] 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; } -(void)share{ _shareList=[[NSMutableArray alloc]init]; if(_photoList!=nil&&_photoList.count>0){ for(ImageModel *model in _photoList){ if(model.checkFlag){ NSString *serverPath=model.imagePath; NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,serverPath]; LeslieImageCache *imageCache = [LeslieImageCache sharedCache]; NSString *filePath=[imageCache getImageNameFromFileForKey:imageUrl]; UIImage *img=[UIImage imageWithContentsOfFile:filePath]; NSData *imgData=[LeslieAsyncImageDownloader resetSizeOfImageData:img maxSize:500]; img= [UIImage imageWithData: imgData]; [_shareList addObject:img]; } } if(_shareList!=nil&&_shareList.count==0){ [self showAlertViewText:@"请选择客户编码单据"]; return; } if(_shareList.count>9){ [self showAlertViewText:@"最多分享9张客户编码单据"]; return; } UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:_shareList applicationActivities:nil]; activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeSaveToCameraRoll]; [self presentViewController:activityVC animated:YES completion:nil]; } } /** 修改:2017-9-25 适配机型 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ self.view.backgroundColor = [UIColor whiteColor]; _collectionView.frame=CGRectMake(0, (self.view.safeAreaLayoutGuide.layoutFrame.size.height-300-rectNavHeight-rectStatusHeight)/2,self.view.frame.size.width,300); _bottomView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height-50, self.view.frame.size.width, 50); [super viewSafeAreaInsetsDidChange]; } /** 加载订单数据 */ -(void)loadData{ NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetOrderGoodsCodeImagesIphone" 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:_orderId forKey:@"OrderID"]; _downManager = [[ASIDownManager alloc] init]; [self startLoading]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onCustomerCodeLoadFinish:); _downManager.onRequestFail = @selector(onCustomerCodeLoadFail:); [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil]; } /** 加载总数数据成功回调 @param sender <#sender description#> */ - (void)onCustomerCodeLoadFinish:(ASIDownManager *)sender { NSDictionary *dic = [sender.mWebStr JSONValue]; [self stopLoading]; // 服务器返回数据是否正确 if (dic && [dic isKindOfClass:[NSDictionary class]]) { // 服务器返回数据状态值 int iStatus = [[dic objectForKey:@"Status"] intValue]; // 服务器返回数据消息 NSString *message=[dic objectForKey:@"Message"]; // 服务器返回数据状态值正确 if (iStatus == 0) { NSDictionary *resultDic=[dic objectForKey:@"Result"]; NSArray *resultArray=[resultDic objectForKey:@"Table"]; if(resultArray!=nil&&resultArray.count>0){ for(int i=0;i */ - (void)onCustomerCodeLoadFail:(ASIDownManager *)sender { [self stopLoading]; [self showAlertViewText:@"加载失败"]; } -(void)initUI{ //保存 _bottomView=[UIView new]; _bottomView.frame=CGRectMake(0, Screen_Height-110, self.view.frame.size.width, 50); [self.view addSubview:_bottomView]; UIView *bottomSeparatorView = [UIView new]; bottomSeparatorView.frame=CGRectMake(0,0, Screen_Width, 1); bottomSeparatorView.backgroundColor = LineBackgroundColor; [_bottomView addSubview:bottomSeparatorView]; _btnCheckAll=[UIButton buttonWithType:UIButtonTypeCustom]; _btnCheckAll.frame=CGRectMake(15,12, 25, 25); [_btnCheckAll addTarget:self action:@selector(checkAll) forControlEvents:UIControlEventTouchUpInside]; [_bottomView addSubview:_btnCheckAll]; UILabel *lblall=[UILabel new]; lblall.frame=CGRectMake(CGRectGetMaxX(_btnCheckAll.frame)+3,12, 60, 25); lblall.text=@"全选"; [_bottomView addSubview:lblall]; [self.view setBackgroundColor:[UIColor whiteColor]]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.itemSize = CGSizeMake(Screen_Width, 300); flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; flowLayout.minimumLineSpacing = 0; [self.view addSubview:_bottomView]; [self changeCheckALLSelect]; _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,(Screen_Height-300-rectNavHeight-rectStatusHeight)/2,self.view.frame.size.width,300) collectionViewLayout:flowLayout]; _collectionView.delegate = self; _collectionView.dataSource = self; _collectionView.showsHorizontalScrollIndicator = NO; _collectionView.pagingEnabled = YES; _collectionView.backgroundColor = [UIColor clearColor]; [self.view addSubview:_collectionView]; } -(void)checkAll{ [self updateAllCellCheck]; [_collectionView reloadData]; if(_isCheckedAll){ [self changeCheckALLSelect]; } else{ [self changeCheckAllUnSelect]; } } //全部选中 -(void)changeCheckALLSelect { [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal]; } //全部未选中 -(void)changeCheckAllUnSelect { [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal]; } -(void)btnCheckPressed:(PrintCell*)cell{ _clickMode=YES; if(_clickMode){ _clickMode=NO; for(int i=0;i<_photoList.count;i++){ ImageModel *model=[_photoList objectAtIndex:i]; if(i==cell.cellIndex){ model.checkFlag=!model.checkFlag; break; } } [_collectionView reloadData]; //更新全部是否选中 BOOL ischeckedll=YES; for(int i=0;i<_photoList.count;i++){ ImageModel *model=[_photoList objectAtIndex:i]; if( model.checkFlag==NO) { ischeckedll=NO; break; } } _isCheckedAll=ischeckedll; if(_isCheckedAll){ [self changeCheckALLSelect]; } else{ [self changeCheckAllUnSelect]; } } } //全选或者全不选 -(void)updateAllCellCheck { if(!_isCheckedAll){ _isCheckedAll=YES; for(ImageModel *model in _photoList) { model.checkFlag =YES; } } else { _isCheckedAll=NO; for(ImageModel *model in _photoList) { model.checkFlag =NO; } } } #pragma mark- UICollectionViewDataSource -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return _photoList.count; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ // 每次先从字典中根据IndexPath取出唯一标识符 NSString *identifier = [_cellDic objectForKey:[NSString stringWithFormat:@"%@", indexPath]]; // 如果取出的唯一标示符不存在,则初始化唯一标示符,并将其存入字典中,对应唯一标示符注册Cell if (identifier == nil) { identifier = [NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"%@", indexPath]]; [_cellDic setValue:identifier forKey:[NSString stringWithFormat:@"%@", indexPath]]; // 注册Cell [self.collectionView registerClass:[[PrintCell class] class] forCellWithReuseIdentifier:identifier]; } PrintCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; for (UIView *view in cell.contentView.subviews) { [view removeFromSuperview]; } cell.delegate=self; cell.cellIndex=indexPath.row; cell.delegate=self; NSInteger currentIndex= indexPath.row; ImageModel *image =_photoList[currentIndex]; cell.delegate=self; NSString *imagepath=[image imagePath]; if(imagepath!=nil&&[imagepath length]>0){ NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,imagepath]; NSURL *url = [NSURL URLWithString:imageUrl]; NSInteger currentIndex= indexPath.row; NSString *page = [ NSString stringWithFormat:@"%ld/%ld页",currentIndex+1,(unsigned long)_photoList.count]; [cell.imgView downloadImageWithMultipleURL:url]; [cell setPageNumber:page]; [cell setCheckBackground:image.checkFlag]; } return cell; } @end