// // AIyuYanXuanViewController.m // Ifish // // Created by imac on 2017/4/25. // Copyright © 2017年 lianlian. All rights reserved. // #import "AIyuYanXuanViewController.h" #import "IfishGoodsData.h" #import "IfishBCShopItemCell.h" #import #import "IfishAlibcWebViewController.h" @interface AIyuYanXuanViewController () @property(nonatomic,strong) UICollectionView *collectionView; @property (nonatomic,strong)NSMutableArray *goodsdataArr; @end static NSString * const cellIdenti = @"IfishBCShopItemCell"; @implementation AIyuYanXuanViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self addTitleViewWithTitle:@"爱鱼严选"]; _goodsdataArr = [[NSMutableArray alloc] init]; [self creatCollection]; [self loadGoodsData]; } -(void)creatCollection{ UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.minimumLineSpacing = 1; flowLayout.minimumInteritemSpacing = .1; CGFloat width = (kScreenSize.width-1)/2; CGFloat itemH = width *1.38; flowLayout.itemSize = CGSizeMake(width,itemH); _collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0,10,kScreenSize.width, self.view.frame.size.height-10) collectionViewLayout:flowLayout]; _collectionView.delegate=self; _collectionView.dataSource=self; _collectionView.bounces=NO; _collectionView.showsVerticalScrollIndicator=NO; _collectionView.backgroundColor = RGB(242, 242, 242); [self.view addSubview:_collectionView]; [self.collectionView registerClass:[IfishBCShopItemCell class] forCellWithReuseIdentifier:cellIdenti]; UINib *cellNib=[UINib nibWithNibName:@"IfishBCShopItemCell" bundle:nil]; [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:cellIdenti]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _goodsdataArr.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { IfishBCShopItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdenti forIndexPath:indexPath]; IfishGoodsData *data = _goodsdataArr[indexPath.row];; [cell loadCellData:data]; return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat width = (kScreenSize.width-1)/2; CGFloat itemH = width *1.38; CGSize itemSize = CGSizeMake(width,itemH); return itemSize; } //距离上下左右的间距 -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0,0,0, 0); } -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { //设置最小的列间距 return 1.0f; } -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { //设置最小的行间距 return 1.0f; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ IfishGoodsData *data = _goodsdataArr[indexPath.row]; [self openAliBCWithLink:data.goodsLink]; } #pragma mark - 商品列表加载 -(void)loadGoodsData{ __weak typeof (self)weskSelf=self; [AFHttpTool getIfishGoodsListWith:IfishGoodsTypeAiYuYanXuan success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; if ([reDic[@"result"] isEqualToString:@"100"]){ NSLog(@"商品列表加载100"); NSArray*goodsArr=reDic[@"data"]; for (NSDictionary *goodsDic in goodsArr) { IfishGoodsData *goodsData=[[IfishGoodsData alloc] initWithDict:goodsDic]; [weskSelf.goodsdataArr addObject:goodsData]; } [weskSelf.collectionView reloadData]; }else{ [weskSelf.view makeToast:@"请求异常"]; } } failure:^(NSError *err) { NSLog(@"%@errrrrr",err); }]; } -(void)openAliBCWithLink:(NSString *)linkUrl{ //查看商品 加金币 [[IfishUserObsever sharedInstance] addGoldWith:OPENGOODSLINK addType:IFISHADDGOLDTYPE0]; //535991514644 //根据商品ID //id page = [AlibcTradePageFactory itemDetailPage: @"535991514644"]; //根据链接打开页面 id page = [AlibcTradePageFactory page:linkUrl]; AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init]; //app 内闭环交易 强制H5 打开 showParam.openType = AlibcOpenTypeH5; //AlibcWebViewController* myView = [[AlibcWebViewController alloc] init]; //自定义web IfishAlibcWebViewController* myView = [[IfishAlibcWebViewController alloc] init]; NSInteger ret = [[AlibcTradeSDK sharedInstance].tradeService show:self.navigationController webView:myView.webView page:page showParams:showParam taoKeParams:nil trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) { } tradeProcessFailedCallback:^(NSError * _Nullable error) { }]; //返回1,说明h5打开,否则不应该展示页面 if (ret == 1) { self.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:myView animated:YES]; } } /* #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. } */ @end