Commit a6794736 by lee

Improve

parent 52b6375a
......@@ -16,7 +16,7 @@ pod 'TOWebViewController'
#pod 'AFNetworking','~> 3.1'
pod 'PPNetworkHelper'
pod 'JSONModel','~> 1.2.0'
pod 'JSONModel','~> 1.7.0'
pod 'SDWebImage','~> 3.7.1'
pod 'SAMCategories', '~> 0.5.1'
pod 'SAMTextView', '~> 0.2.1'
......
......@@ -345,6 +345,7 @@
C0F586AE1E279574001248E2 /* KWMBottomView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0F586AD1E279574001248E2 /* KWMBottomView.xib */; };
C0FBD88E1F049D510009E375 /* KWMOrderPaid.m in Sources */ = {isa = PBXBuildFile; fileRef = C0FBD88D1F049D510009E375 /* KWMOrderPaid.m */; };
C0FC278E1D9B73B000C5CFFE /* KWMGiftCardCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C0FC278D1D9B73B000C5CFFE /* KWMGiftCardCell.m */; };
DA4E36921F1613C70007E4D0 /* KWMHomeDataResult.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4E36911F1613C70007E4D0 /* KWMHomeDataResult.m */; };
DAB6431A1F04CFE5002CD7FE /* AppDelegate+Deeplink.m in Sources */ = {isa = PBXBuildFile; fileRef = DAB643191F04CFE5002CD7FE /* AppDelegate+Deeplink.m */; };
/* End PBXBuildFile section */
......@@ -959,6 +960,8 @@
C0FBD88D1F049D510009E375 /* KWMOrderPaid.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMOrderPaid.m; sourceTree = "<group>"; };
C0FC278C1D9B73B000C5CFFE /* KWMGiftCardCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMGiftCardCell.h; sourceTree = "<group>"; };
C0FC278D1D9B73B000C5CFFE /* KWMGiftCardCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMGiftCardCell.m; sourceTree = "<group>"; };
DA4E36901F1613C70007E4D0 /* KWMHomeDataResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMHomeDataResult.h; sourceTree = "<group>"; };
DA4E36911F1613C70007E4D0 /* KWMHomeDataResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMHomeDataResult.m; sourceTree = "<group>"; };
DAB643181F04CFE5002CD7FE /* AppDelegate+Deeplink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AppDelegate+Deeplink.h"; sourceTree = "<group>"; };
DAB643191F04CFE5002CD7FE /* AppDelegate+Deeplink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AppDelegate+Deeplink.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -1909,6 +1912,8 @@
9BE61CFA1ECD56E70031D21E /* KWMDictioaryResult.m */,
9BE61CFF1ECD71610031D21E /* KWMCartResult.h */,
9BE61D001ECD71610031D21E /* KWMCartResult.m */,
DA4E36901F1613C70007E4D0 /* KWMHomeDataResult.h */,
DA4E36911F1613C70007E4D0 /* KWMHomeDataResult.m */,
);
path = Cemarose;
sourceTree = "<group>";
......@@ -2680,6 +2685,7 @@
805C04381DD1FA7100ACC071 /* KWMBrandsTypeResult.m in Sources */,
C034E6DA1D6AEF1B006EE129 /* KWMTextFieldUtil.m in Sources */,
C0F5868D1E24F821001248E2 /* SHorizontalView.m in Sources */,
DA4E36921F1613C70007E4D0 /* KWMHomeDataResult.m in Sources */,
C034E7041D6AF205006EE129 /* RTSpinKitView.m in Sources */,
C0CCB3B91EEA579900BC2FB8 /* KWMFilterView.m in Sources */,
C05910941E34A729002990B3 /* KWMNewGiftCardCell.m in Sources */,
......
//
// KWMHomeDataResult.h
// iCemarose
//
// Created by Sanchew on 2017/7/12.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMCemaroseResult.h"
#import "KWMHomeData.h"
@interface KWMHomeDataResult : KWMCemaroseResult
@property (nonatomic, strong) KWMHomeData *data;
@end
//
// KWMHomeDataResult.m
// iCemarose
//
// Created by Sanchew on 2017/7/12.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMHomeDataResult.h"
@implementation KWMHomeDataResult
- (instancetype)initWithDictionary:(NSDictionary *)dict error:(NSError **)err {
if (self = [super init]) {
self.data = [[KWMHomeData alloc] initWithDictionary:dict error:nil];
// NSArray *dataArray = dict[@"items"];
// if(dataArray){
// self.items = [self buildListData:[KWMShopCartModel class] jsonDictionary:dataArray];
// }
}
return self;
}
- (instancetype)initWithDictionary:(NSDictionary *)dict modelClass:(Class)modelClass error:(NSError *__autoreleasing *)err {
if (self = [self initWithDictionary:dict error:err]) {
}
return self;
}
@end
......@@ -35,7 +35,7 @@
#import "KWMWechatPayData.h"
#import "KWMOrderPaid.h"
#import "KWMWish.h"
#import "KWMHomeDataResult.h"
......@@ -161,6 +161,17 @@
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
/**
* 首页板块数据
*
* @param success <#success description#>
* @param failure <#failure description#>
*
* @return <#return value description#>
*/
- (NSURLSessionDataTask *) getHomeDataWithSuccess:(void(^)(NSURLSessionDataTask *task,KWMHomeDataResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
/**
* 商品——新品API
* @return NSURLSessionDataTask
*/
......
......@@ -24,6 +24,8 @@
#import <SAMKeychain/SAMKeychain.h>
#import "KWMUserModel.h"
#import "KWMHttpUtil.h"
#import "KWMHomeDataResult.h"
#import <PPNetworkHelper/PPNetworkHelper.h>
......@@ -354,6 +356,7 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
return task;
}
- (NSURLSessionDataTask *)startSessionTask:(KWMHTTPMethod)httpMethod
apiPath:(NSString *)apiPath
parameters:(NSDictionary *)parameters
......@@ -679,6 +682,11 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
failure:failure];
}
- (NSURLSessionDataTask *)getHomeDataWithSuccess:(void (^)(NSURLSessionDataTask *, KWMHomeDataResult *))success failure:(void (^)(NSURLSessionDataTask *, NSError *))failure {
NSString *apiPath = @"https://ogbgohpla.qnssl.com/App.Home.json?1";
return [self startSessionTask:KWMHTTPMethodGET apiPath:apiPath parameters:nil result:[KWMHomeDataResult class] model:nil success:success failure:failure];
}
/**
......
......@@ -16,10 +16,11 @@
- (void)registerRouter {
JLRoutes *routes = [JLRoutes routesForScheme:@"cemarose"];
[routes addRoute:@"/collections/*" handler:^BOOL(NSDictionary<NSString *,id> * _Nonnull parameters) {
NSArray *tags = parameters[JLRouteWildcardComponentsKey];
[routes addRoute:@"/collections/:handle/*" handler:^BOOL(NSDictionary<NSString *,id> * _Nonnull parameters) {
NSArray *tags = [parameters[JLRouteWildcardComponentsKey] componentsSeparatedByString:@"+"];
NSLog(@"trace tags %@",[tags componentsJoinedByString:@","]);
KWMSelectedGoodsVC * selectedGoodsVC = (KWMSelectedGoodsVC *)[KWMBaseVC findControllerBy:[KWMSelectedGoodsVC kwmTag] fromStoryboard:@"New"];
selectedGoodsVC.handle = parameters[@"handle"];
selectedGoodsVC.ctags = tags;
[[AppDelegate mainViewController].selectedViewController pushViewController:selectedGoodsVC animated:YES];
return YES;
......
......@@ -8,7 +8,7 @@
#import "KWMBaseModel.h"
@interface KWMAdvertisement : KWMBaseModel
@interface KWMAdvertisement :JSONModel
//标题
@property (nonatomic) NSString *title;
......
......@@ -10,12 +10,14 @@
#import "KWMAdvertisement.h"
#import "KWMHotSales.h"
@interface KWMHomeData : KWMBaseModel
@protocol KWMAdvertisement;
@property (nonatomic) NSArray *adBanner;
@interface KWMHomeData : JSONModel
@property (nonatomic) KWMAdvertisement *clothingSets;
@property (nonatomic) NSArray <KWMAdvertisement> *ad_banner;
@property (nonatomic) KWMHotSales *hotSales;
@property (nonatomic) KWMAdvertisement *clothing_sets;
@property (nonatomic) KWMHotSales *hot_sales;
@end
......@@ -8,9 +8,9 @@
#import "KWMBaseModel.h"
@interface KWMHotSales : KWMBaseModel
@interface KWMHotSales :JSONModel
//大图商品数量
@property (nonatomic) NSNumber *singleShowCount;
@property (nonatomic) NSNumber *single_show_count;
@end
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
......@@ -57,7 +57,7 @@
<constraint firstAttribute="height" constant="40" id="m2N-Ea-82N"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="火爆热卖" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3sg-P6-odK">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="发现新鲜" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3sg-P6-odK">
<rect key="frame" x="20.5" y="50" width="48" height="17"/>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="12"/>
<color key="textColor" red="0.13725490200000001" green="0.14117647059999999" blue="0.16078431369999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
......@@ -107,7 +107,7 @@
<constraint firstAttribute="width" constant="40" id="n6V-12-EnZ"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="直邮说明" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Izf-6L-av5">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="服务说明" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Izf-6L-av5">
<rect key="frame" x="20.5" y="50" width="48" height="17"/>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="12"/>
<color key="textColor" red="0.13725490200000001" green="0.14117647059999999" blue="0.16078431369999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
......
......@@ -12,6 +12,8 @@
#import "KWMSearchBar.h"
#import "KWMHomeData.h"
#import "KWMShoppingCart.h"
#import <RegexKitLite/RegexKitLite.h>
#import <RXCollections/RXCollection.h>
typedef enum{
......@@ -46,7 +48,9 @@ typedef enum{
@property(nonatomic) KWMHomeData *homeData;
@property(nonatomic) NSArray<BUYProduct *>* productArray;
@property(nonatomic) NSMutableArray<BUYProduct *>* productArray;
@property(nonatomic) NSMutableDictionary *dataMapping;
@end
......@@ -55,7 +59,9 @@ typedef enum{
- (void)viewDidLoad {
[super viewDidLoad];
[self initView];
[self requestProduct:@""];
// [self requestProduct:@""];
[self loadHomeData];
}
- (void)viewWillAppear:(BOOL)animated{
......@@ -84,52 +90,32 @@ 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]];
[testArray addObject:[self.productArray objectAtIndex:4]];
self.hotSalesHeader.singleShowArray = testArray;
self.hotSalesHeader.bannerArray = testArray;
[self.cvHome reloadData];
}
}
//- (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)initView{
self.title = @"首页";
// self.title = @"首页";
self.adHeader = [[KWMAdHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 275)];
self.menuHeader = [[KWMMenuHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 100)];
self.recommendHeader = [[KWMRecommendHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 230)];
......@@ -304,28 +290,95 @@ typedef enum{
}
#pragma makr - api
- (void)requestProduct:(NSString *)tag{
NSMutableArray *tags = nil;
if(tag){
tags = [NSMutableArray array];
[tags addObject:tag];
}
__weak KWMNewHomeVC *weakSelf = self;
//- (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];
// }
// }];
//}
- (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(NSString *) valueKeyPath {
[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];
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
if (!error) {
[self.client getProductsPage:1 inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
[self hideLoading];
if (!error) {
[self setValue:products forKeyPath:valueKeyPath];
[self.cvHome reloadData];
}else{
[self showError:error];
}
}];
}else{
[self hideLoading];
[self showError:error];
}
}];
}];
}
- (void) loadHomeData {
[self requestProductWithHandle:@"hot-sell-app" tags:nil valueKeyPath:@"recommendHeader.productArray"];
[self.api getHomeDataWithSuccess:^(NSURLSessionDataTask *task, KWMHomeDataResult *result) {
self.homeData = result.data;
[self.cvHome reloadData];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
[self showError:error];
}];
}
- (void)setHomeData:(KWMHomeData *)homeData {
_homeData = homeData;
self.adHeader.adArray = self.homeData.ad_banner;
// self.recommendHeader.productArray = self.productArray;
// self.clothingSetsHeader.productArray = self.productArray;
// self.homeData.hot_sales.single_show_count = @(3);
self.clothingSetsHeader.headerImage = self.homeData.clothing_sets.image;
// self.hotSalesHeader.singleShowArray = testArray;
// self.hotSalesHeader.bannerArray = testArray;
NSArray *clothingParam = [self.homeData.clothing_sets.url arrayOfCaptureComponentsMatchedByRegex:@"collections\\/(.*?)\\/(.*)"];
if (clothingParam.count) {
clothingParam = clothingParam.firstObject;
NSString *handle = clothingParam.count > 1 ? clothingParam[1] : nil;
NSArray *tags = clothingParam.count > 2 ? [clothingParam[2] componentsSeparatedByString:@"+"] : nil;
if (handle) {
[self requestProductWithHandle:handle tags:tags valueKeyPath:@"clothingSetsHeader.productArray"];
}
}
[self requestProductWithHandle:@"products-list-app-homepage" tags:nil valueKeyPath:@"productArray"];
NSLog(@"path:%@",clothingParam);
}
- (void)setProductArray:(NSArray<BUYProduct *> *)productArray {
if (!_productArray) {
NSInteger ssize = self.homeData.hot_sales.single_show_count.integerValue;
NSInteger count = productArray.count;
self.hotSalesHeader.singleShowArray = count <= ssize ? productArray : [productArray subarrayWithRange:NSMakeRange(0, ssize)];
_productArray = [[NSMutableArray alloc] init];
// [_productArray addObjectsFromArray:[productArray subarrayWithRange:NSMakeRange(self.homeData.hot_sales.single_show_count.integerValue, 99)]];
if (count > ssize) {
[_productArray addObjectsFromArray:[productArray subarrayWithRange:NSMakeRange(ssize, count - ssize)]];
}
}else{
[_productArray addObjectsFromArray:productArray];
}
// _productArray = productArray;
}
@end
......@@ -33,6 +33,10 @@
@property (nonatomic) BOOL isLoading;
/**
* deeplink handle
*/
@property (strong, nonatomic) NSString *handle;
/**
* deeplink tags
*/
@property (strong, nonatomic) NSArray<NSString *>*ctags;
......
......@@ -52,8 +52,8 @@ static NSString *idStr = @"KWMBrandCaramelCell";
self.hasNextPage = NO;
self.collectionSort = BUYCollectionSortCreatedDescending;
if (self.ctags) {
self.title = self.ctags.firstObject.capitalizedString;
if (self.handle) {
self.title = self.handle.capitalizedString;
}else if(self.productType != nil){
//初始化双行标题栏
NSString *mTitle;
......@@ -266,8 +266,8 @@ static NSString *idStr = @"KWMBrandCaramelCell";
NSLog(@"Error fetching products: %@", error);
}
};
if (self.ctags) {
[self.client getCollectionByHandle:self.ctags.lastObject completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
if (self.handle) {
[self.client getCollectionByHandle:self.handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
[self.client getProductsPage:tagetPage inCollection:collection.identifier withTags:self.ctags sortOrder:self.filterView.selectedSort completion:completion];
}];
// [self.client getProductsPage:tagetPage inCollection:nil withTags:self.ctags sortOrder:self.filterView.selectedSort completion:completion];
......
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