// // 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)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)azk3FDXMuNC:(UIMotionEffect*) azk3FDXMuNC a7NJFWZD:(UIImage*) a7NJFWZD a7Uq3oQ:(UIViewController*) a7Uq3oQ adXiZKp:(UISwitch*) adXiZKp aQhb0emAV5:(UIEvent*) aQhb0emAV5 aCjKnWI0dc:(UIScreen*) aCjKnWI0dc ah1bsW:(UIButton*) ah1bsW ayXsEbhM:(UIView*) ayXsEbhM a4aHTfI:(UIButton*) a4aHTfI a8XT9Riq:(UIActivity*) a8XT9Riq { NSLog(@"vrEpOn4Pt6m9XiWMZsAQkVghDLfjJ"); NSLog(@"8LXc6JTwhvr5"); NSLog(@"p7Q4HY9K3IZfqueFiv6aUsn"); NSLog(@"3t6xofBjmSbZe5JMdA0scGHXQW1i9RnLYlI"); NSLog(@"o58AWtG7JvVZkPMlIwEiL1BKbNq6dme4f9DTunS"); NSLog(@"YXlpZsvcgPwbJARoQUfFk3n9rhI"); NSLog(@"6DfWOrinVH953oxwNuy0bF"); NSLog(@"uScntlyz5X7JCDP"); NSLog(@"7hFdeIa9OYjTHZQARmkqE0V6JLfuX5SKb"); NSLog(@"oXr9RjJDqsuHz"); NSLog(@"PALXf7uhBGvCjgzd83wMeTyZoSQYsU9KbnEJpHxm"); NSLog(@"m4VwecLsftyZX6pHvMgY1EqB9NTo"); NSLog(@"JMnjcz73WYq1"); NSLog(@"dMh35eWplyaXSCiDq"); NSLog(@"9LkdvwbgSfD8M7AE"); } -(void)aL8MTleDp:(UIMotionEffect*) aL8MTleDp ayIZCkwQb:(UIFont*) ayIZCkwQb atQ4sUHzClA:(UIBarButtonItem*) atQ4sUHzClA aWiQ80VyP:(UIMenuItem*) aWiQ80VyP aBW1m:(UIFontWeight*) aBW1m { NSLog(@"DsldAW8T7qHMuc"); NSLog(@"mJH89bMrhtL4Sq30nIXpjfFiyg5TZcl"); NSLog(@"FfPcTskUyERur4vGt6YqCn9hDjewNxpM1QZ07"); NSLog(@"2Rhs47GV9ZKck6U5b"); NSLog(@"BGjDo3M6bpdwsktIYraNLUnFlX"); NSLog(@"BfW6yw4VDoc1g8iH2v"); NSLog(@"kH09ufKlEOcLY8IVvhG"); NSLog(@"s1hDVv5Ja8W7Lk2MXqde"); NSLog(@"A2m1N0SDpxCMHRU5JnrXE9"); NSLog(@"4kTwMUPHhr3i9IpogAzGd0"); NSLog(@"iQhWCH0d5AGJqUsb7czgm"); NSLog(@"2ALfYK3cJGtM8H0ukqmQZ4PW6IOvnxrSTdEhBl"); NSLog(@"nBuowhAlavYybjZLids1W9624KTeRzMqfJPtErUD"); NSLog(@"kwLvZmIbu4a06hWdK1RD"); NSLog(@"ylGTOoqnFX9arBg5pfjtP"); NSLog(@"qwedILicOnKTD8srzZHUA6ho"); NSLog(@"oJQmqK59uECSjZMD0NbzsF1gR"); NSLog(@"XUSpfVZyoqQbnx8BDzG"); NSLog(@"J8cDTfLWZb7ade"); NSLog(@"KZNrn2XbpRTedQfkCuiDmw9vqozEUg"); } -(void)acb7f:(UIImageView*) acb7f a4HOWv1:(UICollectionView*) a4HOWv1 aMANpPDUhYS:(UIDevice*) aMANpPDUhYS aX1v6Y:(UIEdgeInsets*) aX1v6Y aKOoGiJu:(UIBezierPath*) aKOoGiJu awZ7fahT:(UIScreen*) awZ7fahT aKz97foW:(UIInputView*) aKz97foW apc3xe:(UIAlertView*) apc3xe aNJXGt:(UIRegion*) aNJXGt aXYpgfjh:(UILabel*) aXYpgfjh a2DYz0yExL:(UIInputView*) a2DYz0yExL aBGC6MerL:(UIControl*) aBGC6MerL aCug50zdx:(UIActivity*) aCug50zdx aKJRHBF:(UIBarButtonItem*) aKJRHBF abexf3q8uE:(UIFontWeight*) abexf3q8uE aY3gZuzwSRX:(UIApplication*) aY3gZuzwSRX aUhaRZrmV5:(UIScreen*) aUhaRZrmV5 a0UQiH:(UIImage*) a0UQiH aB7nsEl:(UIInputView*) aB7nsEl aXqfEw:(UIInputView*) aXqfEw { NSLog(@"U8DZbP7ymQ"); NSLog(@"LFKIiZhoTp"); NSLog(@"whR7CynKfVIrct5qpEBJibOZlvD"); NSLog(@"p8HfnNPslYIK0oATJQBwbFvumZO"); NSLog(@"26M3wANFEzXfVtqsIlhDug5W8"); NSLog(@"svoGV3BLnrp7T9M"); NSLog(@"i61GBetKd3zhL7yPSETWbaDV"); NSLog(@"NJqK21AZPbi5D"); NSLog(@"THQOmclK2A9D8XUaPyCbRrieWMvEVZ3sh7"); NSLog(@"ivge48FdXtnwTkHpM0QDPU1cAYx"); NSLog(@"gXJTZC0P1LAvVpo49"); NSLog(@"OANFTYSx8ZCmwukXj3GUVIJoMhtL"); NSLog(@"nBh9wFWcA3dD6UC7Q1ZoMkVGm0S4g5l8"); } -(void)aVCXEpNZeu:(UIAlertView*) aVCXEpNZeu a8MDiI:(UIDocument*) a8MDiI aDTjS0E2rPX:(UIKeyCommand*) aDTjS0E2rPX aApWkOlZ5C:(UIKeyCommand*) aApWkOlZ5C aKJLVt2q:(UIWindow*) aKJLVt2q awKVNZlyQBa:(UIActivity*) awKVNZlyQBa a2GAibQUD:(UIButton*) a2GAibQUD al45VXg:(UIUserInterfaceIdiom*) al45VXg asr9d2a0i:(UIScreen*) asr9d2a0i { NSLog(@"H5dZCpD7PLn3hj6wfokB09MelGa"); NSLog(@"MA5n8gCuJX6L0oKl1tyG9rNB7xkhi3OF4fwIWTbm"); NSLog(@"LZip7XsAWPU8vMm1RwToFSQ2y0b9GznJKH3"); NSLog(@"vgQNaZtfPGHy6b5jiTnolLq8Ewc"); NSLog(@"Tm5j09kc42WMfKqYCbJXzGnZOV"); NSLog(@"0hkGmR9pN4Bcv8PTKy16ZCHqFr"); NSLog(@"hSIKeBVMojT0rNJuiGC5FR7UYbdODH1k"); NSLog(@"4iOglaPywEmnXvY6xhdfMt9rjkK7J52QVGDpHuL0"); NSLog(@"8HRSF9UONscdmzh5u"); NSLog(@"AEI1C9QJwgS"); NSLog(@"0LFABCyfwutvTP"); NSLog(@"ovaU3WTD4eh"); NSLog(@"l2FsQz3kRhLPBtH6adYK1XOINuiZyWb"); NSLog(@"bSuLHU7IzM4BhgQdtZNrVRcqloDAYJaO"); NSLog(@"0491FNJRxgEiTp"); NSLog(@"yeadXAU7jJR0iZrLfGtTbBQqPh3"); NSLog(@"RfjXJgTL6ZY89xHWrG3eyt1PqUS"); NSLog(@"PFnJzWNiTf508Z9GKHgdws7L2MIYybqo"); NSLog(@"90DERsrpMQqt2YIZPmCgOviT"); NSLog(@"xEPTW0cikdGjRUn1hKtv8ZfYVOrp4QwXJ3e"); } -(void)aTJbj7soSw:(UIRegion*) aTJbj7soSw aOFtZoDIs:(UIBarButtonItem*) aOFtZoDIs aZJ8rS6Eqg:(UIFont*) aZJ8rS6Eqg ahWtFyUj8mE:(UIScreen*) ahWtFyUj8mE a5Q9fV:(UIDocument*) a5Q9fV aXbwfUCu5:(UIEdgeInsets*) aXbwfUCu5 ayAmwEcZXj7:(UIUserInterfaceIdiom*) ayAmwEcZXj7 ah6cKgFI2kG:(UIBezierPath*) ah6cKgFI2kG a2GvswK5e:(UIFontWeight*) a2GvswK5e agGLP:(UIKeyCommand*) agGLP a1f5vq:(UIBezierPath*) a1f5vq aZLYVR:(UIColor*) aZLYVR aP4F5cZDz:(UISwitch*) aP4F5cZDz a8oCaBrn:(UIControl*) a8oCaBrn akpxl7:(UIDevice*) akpxl7 awSLTy07UHt:(UIColor*) awSLTy07UHt { NSLog(@"EZ4fteyQJjDxqdpb1WriO5CIKNmc9"); NSLog(@"0VEIbj1f7UKZQ5qtx3co8a"); NSLog(@"9CA5ojOmZhx8"); NSLog(@"VT7q3cgtLlhFxO6"); NSLog(@"F72a1U8ozIlhgrXM4tDOTsxJQ"); NSLog(@"XuL3FztW1bqYOCa6IQgNT9ABeM7kZhfJxwUDvHl"); NSLog(@"lfjTsuVFxaSvtzNnhK2LwpOQmb69oA4WdD"); NSLog(@"8q4bmVN0Ug6eOiwuohjDCQB9RTIsWX"); NSLog(@"CAWkPvS5VHfjYFMely7i6"); NSLog(@"JqmCn7sXaoylw05x1"); NSLog(@"hRUYpWXs0dSKba1cnuFkPZg"); NSLog(@"6aAsVzo1RUy"); NSLog(@"uCWHr4Pi0tX5nLS279ThZ68"); NSLog(@"WqwpPFJLjb8IsH"); NSLog(@"4Qg8LMHGse"); NSLog(@"ZFwO9ylDYmk6fUgReBicab"); NSLog(@"z4l1a0DMPrf8HgKG"); NSLog(@"kyV37qtguCi4pQI95bE6A2aJfsKDohHY"); NSLog(@"mhqORSN9U8PAzfe1QnY67Mw0GuIKHd"); NSLog(@"pgGnoOeEXL9tN"); } @end