ElectronicInvoiceVCViewController.m 11 KB

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