Commit 52b1c54f by houweibin

1,fix error

2,加入新首页test数据
parent 71db7491
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
[self initTbvLeft]; [self initTbvLeft];
[self initCvRight]; [self initCvRight];
self.sort = BUYCollectionSortCreatedAscending; self.sort = BUYCollectionSortCreatedDescending;
self.selectBrands = @""; self.selectBrands = @"";
} }
...@@ -215,20 +215,18 @@ ...@@ -215,20 +215,18 @@
[tags addObject:self.selectBrands]; [tags addObject:self.selectBrands];
} }
[self.client getProductsPage:page inCollection:@(171596038) withTags:tags sortOrder:self.sort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){ [self.client getProductsPage:page inCollection:@(Collection_All_ID) withTags:tags sortOrder:self.sort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
[weakSelf.refreshUtil hideLoading]; [weakSelf.refreshUtil hideLoading];
weakSelf.filterTab.userInteractionEnabled = true; weakSelf.filterTab.userInteractionEnabled = true;
if(error){ if(error){
[weakSelf showError:error]; [weakSelf showError:error];
} }
else{ else{
weakSelf.refreshUtil.page = page; weakSelf.refreshUtil.page = page;
weakSelf.refreshUtil.hasNextPage = !reachedEnd; weakSelf.refreshUtil.hasNextPage = !reachedEnd;
[weakSelf.refreshUtil appendDataList:products]; [weakSelf.refreshUtil appendDataList:products];
} }
}]; }];
} }
......
...@@ -35,13 +35,13 @@ ...@@ -35,13 +35,13 @@
-(NSInteger)getSelectSortPosition:(BUYCollectionSort)sort{ -(NSInteger)getSelectSortPosition:(BUYCollectionSort)sort{
switch (sort) { switch (sort) {
case BUYCollectionSortCreatedAscending:
return 0;
case BUYCollectionSortCreatedDescending: case BUYCollectionSortCreatedDescending:
return 0;
case BUYCollectionSortCreatedAscending:
return 1; return 1;
case BUYCollectionSortPriceAscending:
return 2;
case BUYCollectionSortPriceDescending: case BUYCollectionSortPriceDescending:
return 2;
case BUYCollectionSortPriceAscending:
return 3; return 3;
default: default:
return 0; return 0;
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
return self.filterView.selectedTags; return self.filterView.selectedTags;
} }
-(void)kwm_onClickFilter:(KWMFilterView *)filterView{ -(void)kwm_onFilterFinish:(KWMFilterView *)filterView{
if(self.delegate){ if(self.delegate){
[self.delegate kwm_onCompleProductFilter:filterView]; [self.delegate kwm_onCompleProductFilter:filterView];
} }
......
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
#import "KWMBaseModel.h" #import "KWMBaseModel.h"
#import "KWMBannerView.h" #import "KWMBannerView.h"
#import "KWMAdvertisement.h"
@protocol KWMAdDelegate <NSObject>
- (void)kwm_gotoWebView:(NSString *)url;
@end
@interface KWMAdHeader : UIView<KWMBannerViewDelegate> @interface KWMAdHeader : UIView<KWMBannerViewDelegate>
...@@ -17,4 +25,8 @@ ...@@ -17,4 +25,8 @@
-(void)endBannerTimer; -(void)endBannerTimer;
@property (nonatomic) NSArray<KWMAdvertisement *> *adArray;
@property(nonatomic,weak) id<KWMAdDelegate> delegate;
@end @end
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
// //
#import "KWMAdHeader.h" #import "KWMAdHeader.h"
#import "UIImageView+WebCache.h"
@interface KWMAdHeader() @interface KWMAdHeader()
...@@ -56,6 +58,11 @@ ...@@ -56,6 +58,11 @@
[self.bannerView removeTimer]; [self.bannerView removeTimer];
} }
-(void)setAdArray:(NSArray<KWMAdvertisement *> *)adArray{
_adArray = adArray;
[self.bannerView reloadData];
}
#pragma mark - KWMBannerViewDelegate #pragma mark - KWMBannerViewDelegate
-(UIView *)bannerView:(KWMBannerView *)bannerView reusingView:(UIView *)reusingView pageAtIndex:(NSInteger)index{ -(UIView *)bannerView:(KWMBannerView *)bannerView reusingView:(UIView *)reusingView pageAtIndex:(NSInteger)index{
UIView *itemView = reusingView?reusingView:nil; UIView *itemView = reusingView?reusingView:nil;
...@@ -65,7 +72,12 @@ ...@@ -65,7 +72,12 @@
}else{ }else{
topBannerItem = (UIImageView *)itemView; topBannerItem = (UIImageView *)itemView;
} }
topBannerItem.image = [UIImage imageNamed:@"test_banner_1"];
KWMAdvertisement *ad = [self.adArray objectAtIndex:index];
NSURL *imageURL = [NSURL URLWithString:ad.image];
[topBannerItem sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
//topBannerItem.image = [UIImage imageNamed:@"test_banner_1"];
topBannerItem.contentMode=UIViewContentModeScaleAspectFill; topBannerItem.contentMode=UIViewContentModeScaleAspectFill;
itemView = topBannerItem; itemView = topBannerItem;
...@@ -73,10 +85,14 @@ ...@@ -73,10 +85,14 @@
} }
-(NSInteger)numberOfPagesForBanner:(KWMBannerView *)bannerView{ -(NSInteger)numberOfPagesForBanner:(KWMBannerView *)bannerView{
return 4; return self.adArray?self.adArray.count:0;
} }
-(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{ -(void)bannerView:(KWMBannerView *)bannerView onClickPage:(NSInteger)index{
KWMAdvertisement *ad = [self.adArray objectAtIndex:index];
if(self.delegate){
[self.delegate kwm_gotoWebView:ad.url];
}
} }
@end @end
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <Buy/Buy.h>
@interface KWMClothingSetsCell : UICollectionViewCell @interface KWMClothingSetsCell : UICollectionViewCell
@property(nonatomic) BUYProduct *product;
@end @end
...@@ -7,6 +7,20 @@ ...@@ -7,6 +7,20 @@
// //
#import "KWMClothingSetsCell.h" #import "KWMClothingSetsCell.h"
#import "KWMStringUtil.h"
#import "KWMImageUtil.h"
#import "UIImageView+WebCache.h"
@interface KWMClothingSetsCell()
@property(nonatomic,weak) IBOutlet UILabel *lbName;
@property(nonatomic,weak) IBOutlet UILabel *lbPrice;
@property(nonatomic,weak) IBOutlet UIImageView *ivProduct;
@end
@implementation KWMClothingSetsCell @implementation KWMClothingSetsCell
...@@ -14,4 +28,18 @@ ...@@ -14,4 +28,18 @@
[super awakeFromNib]; [super awakeFromNib];
} }
-(void)setProduct:(BUYProduct *)product{
_product = product;
if(product){
NSString *imageUrl = [KWMImageUtil getProductImageUrl:product ImageSize:SmallImage];
NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivProduct sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
self.lbName.text = product.title;
if(product.variantsArray.count>0){
BUYProductVariant *variant = product.variantsArray.firstObject;
self.lbPrice.text = [KWMStringUtil price:variant.price];
}
}
}
@end @end
...@@ -70,6 +70,11 @@ ...@@ -70,6 +70,11 @@
<constraint firstItem="HJW-BD-Yxt" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="yXo-lP-ZkK"/> <constraint firstItem="HJW-BD-Yxt" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="yXo-lP-ZkK"/>
</constraints> </constraints>
<size key="customSize" width="84" height="78"/> <size key="customSize" width="84" height="78"/>
<connections>
<outlet property="ivProduct" destination="9za-nW-9Xw" id="o4P-wq-5gE"/>
<outlet property="lbName" destination="yLu-gy-qUp" id="EyX-Dv-lZp"/>
<outlet property="lbPrice" destination="ETG-Ir-uXq" id="gGI-mJ-6Ms"/>
</connections>
<point key="canvasLocation" x="75" y="122"/> <point key="canvasLocation" x="75" y="122"/>
</collectionViewCell> </collectionViewCell>
</objects> </objects>
......
...@@ -7,9 +7,22 @@ ...@@ -7,9 +7,22 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <Buy/Buy.h>
@protocol KWMClothingSetsDelegate <NSObject>
- (void)kwm_onClickProduct:(BUYProduct *)product;
@end
@interface KWMClothingSetsHeader : UIView<UICollectionViewDataSource,UICollectionViewDelegate> @interface KWMClothingSetsHeader : UIView<UICollectionViewDataSource,UICollectionViewDelegate>
+ (NSString *)kwmTag; + (NSString *)kwmTag;
@property(nonatomic,weak) id<KWMClothingSetsDelegate> delegate;
@property(nonatomic) NSArray *productArray;
@property(nonatomic) NSString *headerImage;
@end @end
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "KWMClothingSetsHeader.h" #import "KWMClothingSetsHeader.h"
#import "KWMClothingSetsCell.h" #import "KWMClothingSetsCell.h"
#import "UIImageView+WebCache.h"
@interface KWMClothingSetsHeader() @interface KWMClothingSetsHeader()
...@@ -15,6 +16,8 @@ ...@@ -15,6 +16,8 @@
@property (nonatomic,weak) IBOutlet UICollectionView *cvSets; @property (nonatomic,weak) IBOutlet UICollectionView *cvSets;
@property (nonatomic,weak) IBOutlet UIImageView *ivHeader;
@end @end
@implementation KWMClothingSetsHeader @implementation KWMClothingSetsHeader
...@@ -70,9 +73,25 @@ ...@@ -70,9 +73,25 @@
} }
-(void)setProductArray:(NSArray *)productArray{
_productArray = productArray;
[self.cvSets reloadData];
}
-(void)setHeaderImage:(NSString *)headerImage{
_headerImage = headerImage;
NSURL *imageURL = [NSURL URLWithString:headerImage];
[self.ivHeader sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
}
#pragma mark - UICollectionViewDataSource #pragma mark - UICollectionViewDataSource
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
KWMClothingSetsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KWMClothingSetsCell class]) forIndexPath:indexPath]; KWMClothingSetsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KWMClothingSetsCell class]) forIndexPath:indexPath];
BUYProduct *product = [self.productArray objectAtIndex:indexPath.row];
cell.product = product;
return cell; return cell;
} }
...@@ -86,7 +105,7 @@ ...@@ -86,7 +105,7 @@
} }
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 20; return self.productArray?self.productArray.count:0;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="KWMClothingSetsHeader"> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="KWMClothingSetsHeader">
<connections> <connections>
<outlet property="cvSets" destination="Vrm-Ee-B8d" id="Gd3-Qy-Yyl"/> <outlet property="cvSets" destination="Vrm-Ee-B8d" id="Gd3-Qy-Yyl"/>
<outlet property="ivHeader" destination="Xzr-zM-E25" id="Baj-uk-PJK"/>
<outlet property="vView" destination="iN0-l3-epB" id="lK1-FX-gaB"/> <outlet property="vView" destination="iN0-l3-epB" id="lK1-FX-gaB"/>
</connections> </connections>
</placeholder> </placeholder>
...@@ -85,6 +86,6 @@ ...@@ -85,6 +86,6 @@
</objects> </objects>
<resources> <resources>
<image name="ic_triangle" width="16" height="16"/> <image name="ic_triangle" width="16" height="16"/>
<image name="test_suit" width="16" height="16"/> <image name="test_suit" width="375" height="212"/>
</resources> </resources>
</document> </document>
...@@ -8,6 +8,15 @@ ...@@ -8,6 +8,15 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "KWMBannerView.h" #import "KWMBannerView.h"
#import <Buy/Buy.h>
@protocol KWMHotSalesDelegate <NSObject>
- (void)kwm_onClickProduct:(BUYProduct *)product;
@end
@interface KWMHotSalesHeader : UIView<KWMBannerViewDelegate> @interface KWMHotSalesHeader : UIView<KWMBannerViewDelegate>
...@@ -17,4 +26,10 @@ ...@@ -17,4 +26,10 @@
-(void)endBannerTimer; -(void)endBannerTimer;
@property(nonatomic,weak) id<KWMHotSalesDelegate> delegate;
@property(nonatomic) NSArray *singleShowArray;
@property(nonatomic) NSArray *bannerArray;
@end @end
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "KWMHotSalesHeader.h" #import "KWMHotSalesHeader.h"
#import "KWMProductBannerItemView.h" #import "KWMProductBannerItemView.h"
#import "UIImageView+WebCache.h"
@interface KWMHotSalesHeader() @interface KWMHotSalesHeader()
......
...@@ -8,8 +8,22 @@ ...@@ -8,8 +8,22 @@
#import "KWMBaseModel.h" #import "KWMBaseModel.h"
@protocol KWMMenuDelegate <NSObject>
- (void)kwm_onClickNewMenu;
- (void)kwm_onClickHotMenu;
- (void)kwm_onClickWishMenu;
- (void)kwm_onClickDeliveryMenu;
@end
@interface KWMMenuHeader : UIView @interface KWMMenuHeader : UIView
+ (NSString *)kwmTag; + (NSString *)kwmTag;
@property(nonatomic,weak) id<KWMMenuDelegate> delegate;
@end @end
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <Buy/Buy.h>
@interface KWMNewHomeCell : UICollectionViewCell @interface KWMNewHomeCell : UICollectionViewCell
...@@ -16,4 +17,8 @@ ...@@ -16,4 +17,8 @@
//文本是否居中 //文本是否居中
@property(nonatomic) BOOL textAlignCenter; @property(nonatomic) BOOL textAlignCenter;
@property(nonatomic) BUYProduct *product;
+(NSInteger)acturlHeight:(BUYProduct *)product width:(NSInteger)width;
@end @end
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#import "KWMNewHomeCell.h" #import "KWMNewHomeCell.h"
#import "UIView+Prettify.h" #import "UIView+Prettify.h"
#import "KWMStringUtil.h"
#import "KWMImageUtil.h"
#import "UIImageView+WebCache.h"
@interface KWMNewHomeCell() @interface KWMNewHomeCell()
...@@ -17,6 +20,8 @@ ...@@ -17,6 +20,8 @@
@property(nonatomic,weak) IBOutlet UILabel *lbPrice; @property(nonatomic,weak) IBOutlet UILabel *lbPrice;
@property(nonatomic,weak) IBOutlet UIImageView *ivProduct;
@end @end
@implementation KWMNewHomeCell @implementation KWMNewHomeCell
...@@ -27,10 +32,40 @@ ...@@ -27,10 +32,40 @@
} }
-(void)setTextAlignCenter:(BOOL)textAlignCenter{ -(void)setTextAlignCenter:(BOOL)textAlignCenter{
if(textAlignCenter){
NSTextAlignment textAlignment = textAlignCenter?NSTextAlignmentCenter:NSTextAlignmentLeft; NSTextAlignment textAlignment = textAlignCenter?NSTextAlignmentCenter:NSTextAlignmentLeft;
self.lbBrand.textAlignment = textAlignment; self.lbBrand.textAlignment = textAlignment;
self.lbName.textAlignment = textAlignment; self.lbName.textAlignment = textAlignment;
self.lbPrice.textAlignment = textAlignment; self.lbPrice.textAlignment = textAlignment;
self.lbName.numberOfLines = 1;
self.lbBrand.numberOfLines = 1;
}
}
-(void)setProduct:(BUYProduct *)product{
_product = product;
if(product){
NSString *imageUrl = [KWMImageUtil getProductImageUrl:product ImageSize:SmallImage];
NSURL *imageURL = [NSURL URLWithString:imageUrl];
[self.ivProduct sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading"]];
self.lbBrand.text = product.vendor;
self.lbName.text = product.title;
if(product.variantsArray.count>0){
BUYProductVariant *variant = product.variantsArray.firstObject;
self.lbPrice.text = [KWMStringUtil price:variant.price];
}
}
}
+(NSInteger)acturlHeight:(BUYProduct *)product width:(NSInteger)width{
NSInteger lbNameWidth = width - 60;
UIFont *font = [UIFont systemFontOfSize:12];
if(SYSTEM_VERSION_LESS_THAN(@"9.0")){
[UIFont fontWithName:@"PingFang SC" size:12];
}
NSInteger lbNameHeight = [KWMStringUtil getLabelHeight:product.title labelFont:font textWidth:lbNameWidth].height;
return 250 - 13 + lbNameHeight;
} }
@end @end
...@@ -13,17 +13,17 @@ ...@@ -13,17 +13,17 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" tag="1111" contentMode="center" id="gTV-IL-0wX" customClass="KWMNewHomeCell"> <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" tag="1111" contentMode="center" id="gTV-IL-0wX" customClass="KWMNewHomeCell">
<rect key="frame" x="0.0" y="0.0" width="184" height="300"/> <rect key="frame" x="0.0" y="0.0" width="184" height="250"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="184" height="300"/> <rect key="frame" x="0.0" y="0.0" width="184" height="250"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews> <subviews>
<view tag="999" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eUm-tt-XRm"> <view tag="999" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eUm-tt-XRm">
<rect key="frame" x="0.0" y="0.0" width="184" height="300"/> <rect key="frame" x="0.0" y="0.0" width="184" height="250"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PUL-8B-4lT"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PUL-8B-4lT">
<rect key="frame" x="10" y="10" width="164" height="280"/> <rect key="frame" x="10" y="10" width="164" height="230"/>
<subviews> <subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="test_home_cloth_2" translatesAutoresizingMaskIntoConstraints="NO" id="Yw1-oo-Px9"> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="test_home_cloth_2" translatesAutoresizingMaskIntoConstraints="NO" id="Yw1-oo-Px9">
<rect key="frame" x="10" y="10" width="144" height="144"/> <rect key="frame" x="10" y="10" width="144" height="144"/>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<color key="textColor" red="0.3411764705882353" green="0.3411764705882353" blue="0.3411764705882353" alpha="1" colorSpace="calibratedRGB"/> <color key="textColor" red="0.3411764705882353" green="0.3411764705882353" blue="0.3411764705882353" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Baby Girls Pink Cotton Dress" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VtC-9N-HwV"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Baby Girls Pink Cotton Dress" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VtC-9N-HwV">
<rect key="frame" x="20" y="191" width="124" height="13"/> <rect key="frame" x="20" y="191" width="124" height="13"/>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="9"/> <fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="9"/>
<color key="textColor" red="0.3411764705882353" green="0.3411764705882353" blue="0.3411764705882353" alpha="1" colorSpace="calibratedRGB"/> <color key="textColor" red="0.3411764705882353" green="0.3411764705882353" blue="0.3411764705882353" alpha="1" colorSpace="calibratedRGB"/>
......
...@@ -11,5 +11,4 @@ ...@@ -11,5 +11,4 @@
@interface KWMProductBannerItemView : UIView @interface KWMProductBannerItemView : UIView
@end @end
...@@ -7,9 +7,19 @@ ...@@ -7,9 +7,19 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <Buy/Buy.h>
@protocol KWMRecommendDelegate <NSObject>
- (void)kwm_onClickProduct:(BUYProduct *)product;
@end
@interface KWMRecommendHeader : UIView<UICollectionViewDataSource,UICollectionViewDelegate> @interface KWMRecommendHeader : UIView<UICollectionViewDataSource,UICollectionViewDelegate>
+ (NSString *)kwmTag; + (NSString *)kwmTag;
@property(nonatomic,weak) id<KWMRecommendDelegate> delegate;
@property(nonatomic) NSArray *productArray;
@end @end
...@@ -68,9 +68,18 @@ ...@@ -68,9 +68,18 @@
self.cvRecommend.collectionViewLayout = layout; self.cvRecommend.collectionViewLayout = layout;
} }
-(void)setProductArray:(NSArray *)productArray{
_productArray = productArray;
[self.cvRecommend reloadData];
}
#pragma mark - UICollectionViewDataSource #pragma mark - UICollectionViewDataSource
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
KWMCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KWMCollectionCell class]) forIndexPath:indexPath]; KWMCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KWMCollectionCell class]) forIndexPath:indexPath];
BUYProduct *product = [self.productArray objectAtIndex:indexPath.row];
[cell setData:product];
return cell; return cell;
} }
...@@ -84,7 +93,15 @@ ...@@ -84,7 +93,15 @@
} }
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 20; return self.productArray?self.productArray.count:0;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
BUYProduct *product = [self.productArray objectAtIndex:indexPath.row];
if(self.delegate){
[self.delegate kwm_onClickProduct:product];
}
} }
@end @end
...@@ -9,7 +9,12 @@ ...@@ -9,7 +9,12 @@
#import "KWMBaseVC.h" #import "KWMBaseVC.h"
#import "KWMSearchBar.h" #import "KWMSearchBar.h"
#import <CHTCollectionViewWaterfallLayout.h> #import <CHTCollectionViewWaterfallLayout.h>
#import "KWMAdHeader.h"
#import "KWMMenuHeader.h"
#import "KWMRecommendHeader.h"
#import "KWMClothingSetsHeader.h"
#import "KWMHotSalesHeader.h"
@interface KWMNewHomeVC : KWMBaseVC<CHTCollectionViewDelegateWaterfallLayout,UICollectionViewDataSource,KWMSearchBarDelegate> @interface KWMNewHomeVC : KWMBaseVC<CHTCollectionViewDelegateWaterfallLayout,UICollectionViewDataSource,KWMSearchBarDelegate,KWMAdDelegate,KWMMenuDelegate,KWMRecommendDelegate,KWMClothingSetsDelegate,KWMHotSalesDelegate>
@end @end
...@@ -8,13 +8,9 @@ ...@@ -8,13 +8,9 @@
#import "KWMNewHomeVC.h" #import "KWMNewHomeVC.h"
#import "KWMShopCartVC.h" #import "KWMShopCartVC.h"
#import "KWMAdHeader.h"
#import "KWMMenuHeader.h"
#import "KWMRecommendHeader.h"
#import "KWMClothingSetsHeader.h"
#import "KWMHotSalesHeader.h"
#import "KWMNewHomeCell.h" #import "KWMNewHomeCell.h"
#import "KWMSearchBar.h" #import "KWMSearchBar.h"
#import "KWMHomeData.h"
#import "KWMShoppingCart.h" #import "KWMShoppingCart.h"
typedef enum{ typedef enum{
...@@ -48,6 +44,9 @@ typedef enum{ ...@@ -48,6 +44,9 @@ typedef enum{
@property(nonatomic,strong) KWMSearchBar *titleView; @property(nonatomic,strong) KWMSearchBar *titleView;
@property(nonatomic) KWMHomeData *homeData;
@property(nonatomic) NSArray<BUYProduct *>* productArray;
@end @end
...@@ -56,6 +55,7 @@ typedef enum{ ...@@ -56,6 +55,7 @@ typedef enum{
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self initView]; [self initView];
[self requestProduct:@""];
} }
- (void)viewWillAppear:(BOOL)animated{ - (void)viewWillAppear:(BOOL)animated{
...@@ -84,6 +84,49 @@ typedef enum{ ...@@ -84,6 +84,49 @@ typedef enum{
} }
} }
- (void)initTestData{
KWMHomeData *homeData = [KWMHomeData new];
KWMHotSales *hotSales = [KWMHotSales new];
hotSales.singleShowCount = @(3);
KWMAdvertisement *clothingSets = [KWMAdvertisement new];
clothingSets.image = @"http://o42yton8r.qnssl.com/s/files/1/1089/5284/collections/b_8d773a6f-6a70-4d15-a280-e4dd13a7a744_large.jpg?v=1464083899";
clothingSets.url = @"http://www.baidu.com";
clothingSets.title = @"boy";
NSMutableArray *adBanner = [NSMutableArray array];
[adBanner addObject:[clothingSets copy]];
[adBanner addObject:[clothingSets copy]];
[adBanner addObject:[clothingSets copy]];
homeData.hotSales = hotSales;
homeData.clothingSets = clothingSets;
homeData.adBanner = adBanner;
self.homeData = homeData;
[self initData];
}
- (void)initData{
if(self.homeData){
self.adHeader.adArray = self.homeData.adBanner;
self.recommendHeader.productArray = self.productArray;
self.clothingSetsHeader.productArray = self.productArray;
self.clothingSetsHeader.headerImage = self.homeData.clothingSets.image;
NSMutableArray *testArray = [NSMutableArray array];
[testArray addObject:[self.productArray objectAtIndex:0]];
[testArray addObject:[self.productArray objectAtIndex:1]];
[testArray addObject:[self.productArray objectAtIndex:2]];
self.hotSalesHeader.singleShowArray = testArray;
self.hotSalesHeader.bannerArray = testArray;
[self.cvHome reloadData];
}
}
- (void)initView{ - (void)initView{
self.title = @"首页"; self.title = @"首页";
self.adHeader = [[KWMAdHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 275)]; self.adHeader = [[KWMAdHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 275)];
...@@ -91,6 +134,13 @@ typedef enum{ ...@@ -91,6 +134,13 @@ typedef enum{
self.recommendHeader = [[KWMRecommendHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 230)]; self.recommendHeader = [[KWMRecommendHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 230)];
self.clothingSetsHeader = [[KWMClothingSetsHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 310)]; self.clothingSetsHeader = [[KWMClothingSetsHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 310)];
self.hotSalesHeader = [[KWMHotSalesHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 250)]; self.hotSalesHeader = [[KWMHotSalesHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 250)];
self.adHeader.delegate = self;
self.menuHeader.delegate = self;
self.recommendHeader.delegate = self;
self.clothingSetsHeader.delegate = self;
self.hotSalesHeader.delegate = self;
[self initTitleView]; [self initTitleView];
[self initCollectionView]; [self initCollectionView];
} }
...@@ -120,6 +170,33 @@ typedef enum{ ...@@ -120,6 +170,33 @@ typedef enum{
[self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMMenuHeader kwmTag]]; [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMMenuHeader kwmTag]];
} }
#pragma mark - KWMAdDelegate
-(void)kwm_gotoWebView:(NSString *)url{
}
#pragma mark - KWMMenuDelegate
-(void)kwm_onClickHotMenu{
}
-(void)kwm_onClickNewMenu{
}
-(void)kwm_onClickWishMenu{
}
-(void)kwm_onClickDeliveryMenu{
}
#pragma makr - KWMRecommendDelegate KWMClothingSetsDelegate KWMHotSalesDelegate
-(void)kwm_onClickProduct:(BUYProduct *)product{
}
#pragma mark - UICollectionViewDataSource #pragma mark - UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
...@@ -128,7 +205,7 @@ typedef enum{ ...@@ -128,7 +205,7 @@ typedef enum{
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if(section == HeaderHotSales){ if(section == HeaderHotSales){
return 10; return self.productArray ? self.productArray.count:0;
} }
return 0; return 0;
} }
...@@ -221,5 +298,29 @@ typedef enum{ ...@@ -221,5 +298,29 @@ typedef enum{
[self.navigationController pushViewController:contactVC animated:YES]; [self.navigationController pushViewController:contactVC animated:YES];
} }
#pragma makr - api
- (void)requestProduct:(NSString *)tag{
NSMutableArray *tags = nil;
if(tag){
tags = [NSMutableArray array];
[tags addObject:tag];
}
__weak KWMNewHomeVC *weakSelf = self;
[self showLoading];
[self.client getProductsPage:1 inCollection:@(Collection_All_ID) withTags:tags sortOrder:BUYCollectionSortBestSelling completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
[weakSelf hideLoading];
if(error){
[weakSelf showError:error];
}
else if(products && products.count>0){
weakSelf.productArray = products;
[weakSelf.cvHome reloadData];
[weakSelf initTestData];
}
}];
}
@end @end
...@@ -353,4 +353,8 @@ ...@@ -353,4 +353,8 @@
} }
@end @end
...@@ -104,6 +104,9 @@ ...@@ -104,6 +104,9 @@
#define BigImage 3 #define BigImage 3
//collection all的id
#define Collection_All_ID 191372166
//默认欧元汇率,如果安装后第一次请求最新汇率数据失败,会使用该汇率显示价格 //默认欧元汇率,如果安装后第一次请求最新汇率数据失败,会使用该汇率显示价格
//#define ExchangeRate 7.6625 //#define ExchangeRate 7.6625
//#define ExchangeRateString @"7.6625" //#define ExchangeRateString @"7.6625"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment