// // LZMMyCollectionViewController.m // YouHuiProject // // Created by 小花 on 2018/5/3. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LZMMyCollectionViewController.h" #import "JDragonTypeButtonView.h" #import "LZMGoodHorizontalCollectionCell.h" #import "LZMGoodCollectionCell.h" #import "LZMFindRequestViewModel.h" #import "LZMSearchNoDataView.h" #import "LZMCollectionMainReusableView.h" #import "LZMGoodDetailViewController.h" #import "LZMCollectionNoDataReusableView.h" #import "LZMCollectionUnloginReusableView.h" #import "LZMLoginViewController.h" #import "LZMCollectionNoDataReusableView.h" #import "LZMGoodDetailRequestViewModel.h" static NSString *KHorizontalCellId = @"LZMGoodHorizontalCollectionCell"; static NSString *KVerticalCellId = @"LZMGoodCollectionCell"; static NSString *KSectionHeaderId = @"SectionHeaderId"; static NSString *KNoDataViewId = @"NoDataViewId"; static NSString *KUnloginId = @"UnloginId "; @interface LZMMyCollectionViewController () < JDragonTypeButtonActionDelegate, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout > { NSInteger _youLikePage; NSInteger _collectionPage; NSInteger _page; } @property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) NSMutableArray *collectionDataArr; @property (nonatomic, strong) NSMutableArray *youLikeArr; @property (nonatomic, strong) NSArray *typeArr; @end @implementation LZMMyCollectionViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } - (void)viewDidLoad { [super viewDidLoad]; [self configNavigationBar]; [self configCollectionView]; [self requestData]; } - (void)configNavigationBar { _page = 1; [self.navigationBar setNavTitle:@"我的收藏"]; self.navigationBar.backgroundColor = [UIColor changeColor]; self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal]; [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside]; [self.navigationBar setCustomLeftButtons:@[leftBtn]]; } - (void)backAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)configCollectionView { _youLikePage = 1; _collectionPage = 1; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init]; self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout]; flowLayout.minimumInteritemSpacing = 2; [self.collectionView registerClass:[LZMGoodHorizontalCollectionCell class] forCellWithReuseIdentifier:KHorizontalCellId]; [self.collectionView registerClass:[LZMGoodCollectionCell class] forCellWithReuseIdentifier:KVerticalCellId]; [self.collectionView registerClass:[LZMCollectionMainReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionHeaderId]; [self.collectionView registerClass:[LZMCollectionNoDataReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KNoDataViewId]; [self.collectionView registerClass:[LZMCollectionUnloginReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KUnloginId]; self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6]; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ [self loadMoreData]; }]; [self.collectionView.mj_footer beginRefreshing]; [self.view addSubview:self.collectionView]; } - (void)requestData { if ([AccountTool isLogin]) { [self requestMyCollectionData]; [self requestYouLikeData]; }else { [self requestYouLikeData]; } } - (void)requestMyCollectionData { NSDictionary *para = @{@"type":self.typeArr[self.selectedIndex], @"page":@(_collectionPage) }; NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/favoriteslist",BaseURL]; [LZMHttp get:url params:para success:^(id json) { [self.collectionDataArr removeAllObjects]; NSArray *list = [NSArray yy_modelArrayWithClass:[LZMCollectionModel class] json:json[@"data"]]; [self.collectionDataArr addObjectsFromArray:list]; [self.collectionView reloadData]; } failure:^(NSError *error) { }]; } - (void)requestYouLikeData { [LZMFindRequestViewModel requestGuessYouLikeParamPage:_youLikePage success:^(NSArray *array) { [self.youLikeArr addObjectsFromArray:array]; [self.collectionView reloadData]; [self noMoreDataWithArray:array]; [self endRefreshing]; } failure:^(NSError *error) { [MBProgressHUD showMessage:@"网络错误"]; [SVProgressHUD dismiss]; [self endRefreshing]; }]; } - (void)noMoreDataWithArray:(NSArray *)array { if (array.count <= 0) { MJRefreshAutoNormalFooter *foot = (MJRefreshAutoNormalFooter *)self.collectionView.mj_footer; [foot setTitle:@"到底啦" forState:MJRefreshStateIdle]; } } - (void)loadMoreData { _youLikePage++; [self requestYouLikeData]; } - (void)endRefreshing { [self.collectionView.mj_header endRefreshing]; [self.collectionView.mj_footer endRefreshing]; } /** 取消收藏 */ - (void)cancelCollectionGoodWith:(NSIndexPath *)indexPath { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否要取消收藏该商品?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *sure = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/delFavorites",BaseURL]; LZMCollectionModel *model = self.collectionDataArr[indexPath.row]; NSDictionary *para = @{@"id":model.Id}; [LZMHttp get:url params:para success:^(id json) { [self.collectionDataArr removeObjectAtIndex:indexPath.row]; // [self.collectionView deleteItemsAtIndexPaths:@[indexPath]]; [self.collectionView reloadData]; } failure:^(NSError *error) { }]; }]; [alert addAction:cancel]; [alert addAction:sure]; [self presentViewController:alert animated:YES completion:nil]; } #pragma mark ============ UICollectionView Delegate && DataSource ========== - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { switch (section) { case 0: return self.collectionDataArr.count; break; case 1: return self.youLikeArr.count; default: return 0; break; } } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 2; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { return CGSizeMake(SCREEN_WIDTH, 120); }else { CGFloat width = (SCREEN_WIDTH-5)/2; CGFloat height = width + 102; return CGSizeMake(width, height); } } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { if (section == 0) { return 1; }else { return 5; } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section { if (section == 0) { if (self.collectionDataArr.count == 0 || ![AccountTool isLogin]) { return CGSizeMake(kScreenWidth, FITSIZE(264)); }else { return CGSizeZero; } }else { return CGSizeMake(SCREEN_WIDTH, 40); } } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section { return CGSizeMake(0, 0); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { LZMCollectionModel *model = self.collectionDataArr[indexPath.row]; LZMGoodHorizontalCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KHorizontalCellId forIndexPath:indexPath]; cell.collectionModel = model; cell.cancelBlock = ^{ [self cancelCollectionGoodWith:indexPath]; }; return cell; }else { LZMChildGoodModel *model = self.youLikeArr[indexPath.row]; LZMGoodCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KVerticalCellId forIndexPath:indexPath]; cell.model = model; return cell; } } - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { if (![AccountTool isLogin]) { LZMCollectionUnloginReusableView *unlog = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KUnloginId forIndexPath:indexPath]; unlog.loginClick = ^{ LZMLoginViewController *login = [[LZMLoginViewController alloc] init]; [self.parentViewController presentViewController:login animated:YES completion:nil]; }; return unlog; }else if (self.collectionDataArr.count <= 0){ LZMCollectionNoDataReusableView *noData = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KNoDataViewId forIndexPath:indexPath]; noData.refreshClick = ^{ [self requestMyCollectionData]; }; return noData; }else { return nil; } }else { LZMCollectionMainReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KSectionHeaderId forIndexPath:indexPath]; return header; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { LZMGoodDetailViewController *detail = [[LZMGoodDetailViewController alloc] init]; if (indexPath.section == 0) { LZMCollectionModel *model = self.collectionDataArr[indexPath.row]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id is_coupon:model.is_coupon coupon_price:model.coupon_price price:model.price discount_price:model.discount_price commission_rate:model.commission_rate coupon_start_time:model.coupon_start_time coupon_end_time:model.coupon_end_time]; detail.requestModel = requestModel; LZMEventModel *evevtModel = [[LZMEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:collectAction]; detail.eventModel = evevtModel; }else { LZMChildGoodModel *model = self.youLikeArr[indexPath.row]; DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model]; detail.requestModel = requestModel; LZMEventModel *evevtModel = [[LZMEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:collectLikeAction]; detail.eventModel = evevtModel; } [self.navigationController pushViewController:detail animated:YES]; } #pragma mark ---- layzer ---- - (NSMutableArray *)collectionDataArr { if (!_collectionDataArr) { _collectionDataArr = [NSMutableArray array]; } return _collectionDataArr; } - (NSArray *)typeArr { if (!_typeArr) { _typeArr = @[@"all",@"no_expired",@"expired"]; } return _typeArr; } - (NSMutableArray *)youLikeArr { if (!_youLikeArr) { _youLikeArr = [NSMutableArray array]; } return _youLikeArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ -(void)ak12l8ZIm:(UIMotionEffect*) ak12l8ZIm ac0pyUF:(UIFontWeight*) ac0pyUF aQfkB:(UIAlertView*) aQfkB aMlVZ:(UILabel*) aMlVZ akbYycq4CiD:(UILabel*) akbYycq4CiD acAuRDMknK:(UIView*) acAuRDMknK aN7yA:(UIKeyCommand*) aN7yA apKCD:(UIFontWeight*) apKCD atBHNbweZp8:(UIDevice*) atBHNbweZp8 { NSLog(@"8BsLxpTuD4hcvMrXYHy6g"); NSLog(@"yHfXEOFr6n8J5ulL"); NSLog(@"CGBkHDT1IfPxdelmZLbyc3nW7AwjRXvoNhFz"); NSLog(@"hPgqZlibsdCnGRepF2jToUt7M4YuL"); NSLog(@"U7KLOkpgh4baeFt2mW6oZAvqx0rzJ"); NSLog(@"Kc6ehz2ionJZMC7Hx1GBuWU"); NSLog(@"ptcOoDFxe7MRTQGPZmvJAYBsqSEw"); NSLog(@"dUVAHw4LW2t1ypgihCjRoNeGJm3YKqZ0P6n"); NSLog(@"UscxZn3PWw1blLIyRi"); NSLog(@"9vscPNzBjCY0dwTbgZoxIXak6fQ7ui5mphlUEA"); NSLog(@"Exrmsf15ujyWMenkw"); NSLog(@"Piv0mjpGXOleoJB6KMxF"); NSLog(@"4uhMtW2UeFROrfnZidIgy"); NSLog(@"vWxoZeCk0fiUnSAPcwTz6Rpm93aFqj5b"); NSLog(@"n4WwBi2UQMLGoaAu16sblzI05"); NSLog(@"JoI3hNg8B2OHykCm5vi6nfQqVuR4sELF7rjK"); NSLog(@"OZvEHL0cyCn"); NSLog(@"Y18zZMHxU5lhfe4KjdEIAmv9qBCW6Dar"); } -(void)aoBzi0XRY4V:(UIApplication*) aoBzi0XRY4V aPVHCK2l4:(UIBarButtonItem*) aPVHCK2l4 aCbV1z:(UIWindow*) aCbV1z a4dxsP1cY:(UIActivity*) a4dxsP1cY aH67I:(UIFont*) aH67I a8EijOvDMH:(UIMenuItem*) a8EijOvDMH ao7QepSf0Pk:(UIInputView*) ao7QepSf0Pk { NSLog(@"bBywlhUoAQ49ViuKWg8I5TGfrCMLpFRxtScJeD"); NSLog(@"FtZV5HPkh7L4nI"); NSLog(@"CKEfq8k6xGBplZ3FoSuhm29Y4dy"); NSLog(@"a9A0wZlQyz6TiX8ShYBPMf3moOtVHqK"); NSLog(@"sVxQ82WKgwoyRlPJqtpF9fhr"); NSLog(@"ng9KF8iLdTbu6xwGMPYjmEJyc4VHOkDB"); NSLog(@"CKdBZm9PfXcOAksxz1W5gyY"); NSLog(@"btiNcvkGI4RDEVdS3uMZhH9mJ"); NSLog(@"SkTXGgJ9qpNA0ZLVthbYUCvFaQDux32nfelKRycw"); NSLog(@"kdBZrCzetiof"); NSLog(@"pakYuQwWxfGr"); NSLog(@"1ac3PKLEpz9Mdf6eqlogsXxQ4"); NSLog(@"sJnfEHg1wLB9jFYld2"); } -(void)aQ3keh6mt:(UIApplication*) aQ3keh6mt aRPdxHqZolW:(UIInputView*) aRPdxHqZolW aP3GXmbZuK:(UIMotionEffect*) aP3GXmbZuK a94j5rA:(UIInputView*) a94j5rA aVNR7Z0t:(UIAlertView*) aVNR7Z0t aahn9fB:(UIEdgeInsets*) aahn9fB aUvCLX3YPH:(UICollectionView*) aUvCLX3YPH ay4iZVwd:(UIScreen*) ay4iZVwd aoiNk7:(UIDevice*) aoiNk7 aKB9X4j7D:(UICollectionView*) aKB9X4j7D aem1Rf:(UIVisualEffectView*) aem1Rf arlX3sJ9OL:(UIMotionEffect*) arlX3sJ9OL aPHS7Vn:(UIBarButtonItem*) aPHS7Vn aIGFro1tL:(UIMenuItem*) aIGFro1tL agJT0:(UIColor*) agJT0 aoUzFkx:(UIVisualEffectView*) aoUzFkx aXarg8:(UIEdgeInsets*) aXarg8 aQExd:(UIKeyCommand*) aQExd { NSLog(@"Pc56tTr4GoXeOZ0B97MqdsylHfzmijQaxIJLgE"); NSLog(@"TI6yO8moGiEFMsUwbc5fPgX9je2qxCadV4S"); NSLog(@"UuJL5KkixaWbzTB4s2A9YqN1OF"); NSLog(@"7wFCUgsfpKGJ"); NSLog(@"pziSmC2WEKUF"); NSLog(@"Kmp6uZBSkG3c5x8eLJFn4l1H7EsC2zbDOjgNP"); NSLog(@"rILc5h0EdbNAPaOMR6xKpWqBzJfujYivXkgs2"); NSLog(@"JoxmK1MCN7GdnqsOZbHpPSIi9"); NSLog(@"fzFu4OMv3cr9hWxolNTwR6"); NSLog(@"4Gn5FpTmtofSyeJqrLMBzs69"); NSLog(@"yLeRjC0PAtoEkWVFIxbZcg"); NSLog(@"SlbkytM8OR"); NSLog(@"NzR2XhgsGU6xVmybjDSLrYcin7a1El5Hk3AOQ"); NSLog(@"t8uh1RHrBX7E"); NSLog(@"AP1SDmR8zEegkp04"); } @end