| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- //
- // ElectronicInvoiceVCViewController.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2018/3/30.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "ElectronicInvoiceVCViewController.h"
- @interface ElectronicInvoiceVCViewController ()
- @end
- @implementation ElectronicInvoiceVCViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.cellDic = [[NSMutableDictionary alloc] init];
- [self loadNavStyle];
- [self initUI];
-
- }
- /**
- 导航按钮样式
- */
- -(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)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 修改: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)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];
- [self loadData];
-
- }
- //全部选中
- -(void)changeCheckALLSelect
- {
-
- [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_checked"] forState:UIControlStateNormal];
- }
- //全部未选中
- -(void)changeCheckAllUnSelect
- {
- [_btnCheckAll setBackgroundImage:[UIImage imageNamed:@"order_unchecked"] forState:UIControlStateNormal];
- }
- //全选或者全不选
- -(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;
- }
- }
-
- }
- -(void)share{
- _printList=[[NSMutableArray alloc]init];
- if(_photoList!=nil&&_photoList.count>0){
-
- for(ImageModel *model in _photoList){
- if(model.checkFlag){
- NSString *serverPath=model.imageName;
- NSString *imageUrl= [NSString stringWithFormat:@"http://%@:%@/WebService/%@",kkServerUrl,kkServerPort,serverPath];
-
- LeslieImageCache *imageCache = [LeslieImageCache sharedCache];
- NSString *filePath=[imageCache getImageNameFromFileForKey:imageUrl];
-
- if(filePath!=nil){
- NSURL *fileURL = [NSURL fileURLWithPath:filePath]; // 加载本地数据
- [_printList addObject:fileURL];
- }
- }
- }
-
- if(_printList!=nil&&_printList.count==0){
- [self showAlertViewText:@"请选择电子单据"];
- return;
- }
-
- UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:_printList applicationActivities:nil];
- activity.excludedActivityTypes = @[UIActivityTypeAirDrop];
-
- [self presentViewController:activity animated:YES completion:NULL];
- }
- }
- -(void)loadData{
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"PrintInvoice" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- if([_invoiceFlag isEqualToString:@"saleSlip"]){
- [dict setObject:@"SAL001" forKey:@"BusinessType"];
- }
- else{
- [dict setObject:@"ORD001" forKey:@"BusinessType"];
- }
- [dict setObject:_salesId forKey:@"invoiceID"];
- [dict setObject:[NSString stringWithFormat:@"%ld",(long)_invoiceStyleId] forKey:@"layoutID"];
- [self startLoading];
- _downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.OnImageDown = @selector(onLoadFinish:);
- _downManager.OnImageFail = @selector(onLoadFail:);
- [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)checkAll{
- [self updateAllCellCheck];
- [_collectionView reloadData];
- if(_isCheckedAll){
- [self changeCheckALLSelect];
- }
- else{
- [self changeCheckAllUnSelect];
- }
- }
- /**
- 加载总数数据成功回调
-
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
-
- // 服务器返回数据是否正确
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- // 服务器返回数据状态值
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- // 服务器返回数据消息
- NSString *message=[dic objectForKey:@"Message"];
- if(iStatus==0){
- NSArray * infoArr=[dic objectForKey:@"Result"];
- if(infoArr!=nil&&infoArr.count>0){
- _photoList=[[NSMutableArray alloc]init];
- for (int i = 0; i < infoArr.count; i++) {
- NSString *imagePath=infoArr[i];
- ImageModel *imageModel=[ImageModel new];
- [imageModel setCheckFlag:YES];
- if(imagePath!=nil){
- imagePath = [imagePath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
- [imageModel setImageName:imagePath];
- }
- [_photoList addObject:imageModel];
- }
- [self cancel];
- _isCheckedAll=YES;
- [_collectionView reloadData];
- }
- }
- else if(iStatus==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined){
-
- [self showReLoginDialog:message];
- }
- else{
-
- [self showAlertViewText:message];
- }
- }
- }
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self cancel];
- [self showAlertViewText:@"加载失败"];
- }
- -(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)cancel {
- [self stopLoading];
- }
- #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;
- ImageModel *image =_photoList[indexPath.row];
- cell.delegate=self;
- NSString *imagepath=[image imageName];
- 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:@"%d/%ld页",currentIndex+1,(unsigned long)_photoList.count];
- [cell.imgView downloadImageWithURL:url];
- [cell setPageNumber:page];
- [cell setCheckBackground:image.checkFlag];
- return cell;
-
-
- }
- return nil;
-
- }
- @end
|