Commit 6d9aca66 by houweibin

- [x] 1,订单页支付宝和微信支付位置调整

- [x] 2,订单页修改优惠码位置调整
- [x] 3,添加下单成功后的推荐
- [x] 4,添加购物车为空时的推荐
parent ea19ed6d
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_choose_nor@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_choose_nor@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_choose_sel@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_choose_sel@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/> <adaptation id="fullscreen"/>
</device> </device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<customFonts key="customFonts"> <customFonts key="customFonts">
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#import <CHTCollectionViewWaterfallLayout.h> #import <CHTCollectionViewWaterfallLayout.h>
#import "KWMAdHeader.h" #import "KWMAdHeader.h"
#import "KWMMenuHeader.h" #import "KWMMenuHeader.h"
#import "KWMRecommendHeader.h" #import "KWMRecommendView.h"
#import "KWMClothingSetsHeader.h" #import "KWMClothingSetsHeader.h"
#import "KWMHotSalesHeader.h" #import "KWMHotSalesHeader.h"
......
...@@ -45,7 +45,7 @@ typedef enum{ ...@@ -45,7 +45,7 @@ typedef enum{
@property(nonatomic,strong) KWMMenuHeader *menuHeader; @property(nonatomic,strong) KWMMenuHeader *menuHeader;
@property(nonatomic,strong) KWMRecommendHeader *recommendHeader; @property(nonatomic,strong) KWMRecommendView *recommendHeader;
@property(nonatomic,strong) KWMClothingSetsHeader *clothingSetsHeader; @property(nonatomic,strong) KWMClothingSetsHeader *clothingSetsHeader;
...@@ -110,7 +110,7 @@ typedef enum{ ...@@ -110,7 +110,7 @@ typedef enum{
heightHotSale = UI_SCREEN_WIDTH * 190 / 375 + 60;//60为图片外的布局高度 heightHotSale = UI_SCREEN_WIDTH * 190 / 375 + 60;//60为图片外的布局高度
self.adHeader = [[KWMAdHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightAdHeader)]; self.adHeader = [[KWMAdHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightAdHeader)];
self.menuHeader = [[KWMMenuHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 100)]; self.menuHeader = [[KWMMenuHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 100)];
self.recommendHeader = [[KWMRecommendHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 230)]; self.recommendHeader = [[KWMRecommendView alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 230)];
self.clothingSetsHeader = [[KWMClothingSetsHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightClothingSets)]; self.clothingSetsHeader = [[KWMClothingSetsHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightClothingSets)];
self.hotSalesHeader = [[KWMHotSalesHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightHotSale)]; self.hotSalesHeader = [[KWMHotSalesHeader alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, heightHotSale)];
...@@ -145,7 +145,7 @@ typedef enum{ ...@@ -145,7 +145,7 @@ typedef enum{
[self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMAdHeader kwmTag]]; [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMAdHeader kwmTag]];
[self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMHotSalesHeader kwmTag]]; [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMHotSalesHeader kwmTag]];
[self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMRecommendHeader kwmTag]]; [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMRecommendView kwmTag]];
[self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMClothingSetsHeader kwmTag]]; [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMClothingSetsHeader kwmTag]];
[self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMMenuHeader kwmTag]]; [self.cvHome registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMMenuHeader kwmTag]];
...@@ -194,7 +194,7 @@ typedef enum{ ...@@ -194,7 +194,7 @@ typedef enum{
} }
#pragma mark - KWMRecommendDelegate #pragma mark - KWMRecommendDelegate
-(void)kwm_gotoRecommendPage{ -(void)kwm_gotoRecommendPage:(KWMRecommendView *)recommendView{
[self openURLWithString:@"https://cemarose.myshopify.com/collections/hot-sell-app?title=主推单品"]; [self openURLWithString:@"https://cemarose.myshopify.com/collections/hot-sell-app?title=主推单品"];
} }
...@@ -264,7 +264,7 @@ typedef enum{ ...@@ -264,7 +264,7 @@ typedef enum{
} }
break; break;
case HeaderRecommend: case HeaderRecommend:
headerView = [collectionView dequeueReusableSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMRecommendHeader kwmTag] forIndexPath:indexPath]; headerView = [collectionView dequeueReusableSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:[KWMRecommendView kwmTag] forIndexPath:indexPath];
if(headerView.subviews.count == 0){ if(headerView.subviews.count == 0){
[headerView addSubview:self.recommendHeader]; [headerView addSubview:self.recommendHeader];
} }
...@@ -341,7 +341,7 @@ typedef enum{ ...@@ -341,7 +341,7 @@ typedef enum{
- (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(NSString *) valueKeyPath { - (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(NSString *) valueKeyPath {
BOOL isHome = [handle isEqualToString:@"products-list-app-homepage"]; BOOL isHome = [handle isEqualToString:@"products-list-app-homepage"];
NSInteger cpage = isHome ? self.page : 1; NSInteger cpage = isHome ? self.page : 1;
NSDictionary *parameters = [self getProductCacheKeyDictionary:cpage tags:tags handle:handle]; NSDictionary *parameters = [KWMPPCacheUtil getProductCacheKeyDictionary:cpage tags:tags handle:handle];
if(!self.isRefreshUI){ if(!self.isRefreshUI){
BOOL useProductDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:cpage isHome:isHome]; BOOL useProductDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:cpage isHome:isHome];
} }
...@@ -439,23 +439,6 @@ typedef enum{ ...@@ -439,23 +439,6 @@ typedef enum{
} }
} }
//初始化缓存parameters key
- (NSDictionary *)getProductCacheKeyDictionary:(NSUInteger)page
tags:(nullable NSArray <NSString *> *)tags
handle:(nullable NSString *)handle{
NSMutableDictionary *params = @{
@"limit" : @(self.client.pageSize),
@"page" : @(page)
}.mutableCopy;
if (tags) {
params[@"tag"] = [tags componentsJoinedByString:@","];
}
if (handle) {
params[@"handle"] = handle;
}
return params;
}
//缓存规则:网络请求数据照常,如果没网络,并且缓存有数据,会拿缓存的数据显示。 //缓存规则:网络请求数据照常,如果没网络,并且缓存有数据,会拿缓存的数据显示。
-(BOOL)useProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page isHome:(BOOL)isHome{ -(BOOL)useProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page isHome:(BOOL)isHome{
if(!kIsNetwork || page == 1){ if(!kIsNetwork || page == 1){
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#import "KWMPayTypeVC.h" #import "KWMPayTypeVC.h"
#import "KWMBeforePayData.h" #import "KWMBeforePayData.h"
@interface KWMBeforePayVC : KWMBaseVC<KWMGiftCardDelegate,KWMDiscountDelegate,KWMSelectAddressDelegate,KWMSelectShippingRateDelegate,KWMPayTypeDelegate> @interface KWMBeforePayVC : KWMBaseVC<KWMGiftCardDelegate,KWMSelectAddressDelegate,KWMSelectShippingRateDelegate,UITextFieldDelegate>
//沒有默認地址時,高度為37,有地址時,高度為90 //沒有默認地址時,高度為37,有地址時,高度為90
@property(nonatomic,weak) IBOutlet NSLayoutConstraint *vAddressHeight; @property(nonatomic,weak) IBOutlet NSLayoutConstraint *vAddressHeight;
...@@ -33,13 +33,28 @@ ...@@ -33,13 +33,28 @@
@property (weak, nonatomic) IBOutlet UIView *vHasAddress; @property (weak, nonatomic) IBOutlet UIView *vHasAddress;
@property (weak, nonatomic) IBOutlet UILabel *lbPayType; //支付方式
@property (weak, nonatomic) IBOutlet UIView *vPayType;
//折扣 @property (weak, nonatomic) IBOutlet UIImageView *ivAliPay;
@property (weak, nonatomic) IBOutlet UILabel *lbDiscount;
@property (weak, nonatomic) IBOutlet UIImageView *ivWechatPay;
//折扣
@property (weak, nonatomic) IBOutlet UILabel *lbGiftCard; @property (weak, nonatomic) IBOutlet UILabel *lbGiftCard;
@property (weak, nonatomic) IBOutlet UIButton *btnDiscountCancel;
@property (weak, nonatomic) IBOutlet UIButton *btnDiscountConfirm;
@property (weak, nonatomic) IBOutlet UIButton *btnDiscountEdit;
@property (weak, nonatomic) IBOutlet UITextField *tfDiscount;
@property (weak, nonatomic) IBOutlet UIButton *btnBg;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *marginTopContent;
//价格
@property (weak, nonatomic) IBOutlet UILabel *lbTotalPrice; @property (weak, nonatomic) IBOutlet UILabel *lbTotalPrice;
@property (weak, nonatomic) IBOutlet UILabel *lbShippingRate; @property (weak, nonatomic) IBOutlet UILabel *lbShippingRate;
...@@ -47,8 +62,6 @@ ...@@ -47,8 +62,6 @@
//清关信息 //清关信息
@property (weak, nonatomic) IBOutlet UILabel *lbCustomsClearance; @property (weak, nonatomic) IBOutlet UILabel *lbCustomsClearance;
@property (weak, nonatomic) IBOutlet UIView *vPayType;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightPayType; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightPayType;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightCustomsClearance; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightCustomsClearance;
...@@ -87,6 +100,9 @@ ...@@ -87,6 +100,9 @@
- (IBAction)onClickCustomsClearance:(id)sender; - (IBAction)onClickCustomsClearance:(id)sender;
- (IBAction)onClickDiscountConfirm:(id)sender;
- (IBAction)onClickDiscountCancel:(id)sender;
@end @end
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
#import "KWMShoppingCart.h" #import "KWMShoppingCart.h"
@interface KWMBeforePayVC () @interface KWMBeforePayVC ()
@property (nonatomic) BOOL isEditingDiscount;
@property (nonatomic) BUYCustomer *customer; @property (nonatomic) BUYCustomer *customer;
@property (weak, nonatomic) IBOutlet UIButton *submit; @property (weak, nonatomic) IBOutlet UIButton *submit;
@end @end
@implementation KWMBeforePayVC @implementation KWMBeforePayVC
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self initDiscountHintText];
self.title = @"提交订单"; self.title = @"提交订单";
self.payType = [self.userDao.currencyCode isEqualToString:@"EUR"]?TypeWebpay:TypeAlipay; self.payType = [self.userDao.currencyCode isEqualToString:@"EUR"]?TypeWebpay:TypeAlipay;
self.beforePayData = [KWMBeforePayData new]; self.beforePayData = [KWMBeforePayData new];
...@@ -77,8 +78,6 @@ ...@@ -77,8 +78,6 @@
if(payType == TypeWebpay){ if(payType == TypeWebpay){
self.heightPayType.constant = 0; self.heightPayType.constant = 0;
self.vPayType.hidden = YES; self.vPayType.hidden = YES;
}else{
self.lbPayType.text = [KWMPayUtil payTypeString:payType];
} }
} }
...@@ -118,6 +117,7 @@ ...@@ -118,6 +117,7 @@
if (error == nil && checkout) { if (error == nil && checkout) {
this.address = address; this.address = address;
this.checkout = checkout; this.checkout = checkout;
[this showToast:@"更新地址成功"]; [this showToast:@"更新地址成功"];
[this flushCheckout:dictionary]; [this flushCheckout:dictionary];
// [this initData]; // [this initData];
...@@ -150,11 +150,6 @@ ...@@ -150,11 +150,6 @@
[self initData]; [self initData];
} }
- (void)kwm_addedDiscount:(BUYCheckout *)checkout{
self.checkout = checkout;
[self initData];
}
- (void)kwm_addedGiftCard:(BUYCheckout *)checkout{ - (void)kwm_addedGiftCard:(BUYCheckout *)checkout{
self.checkout = checkout; self.checkout = checkout;
[self initData]; [self initData];
...@@ -167,6 +162,22 @@ ...@@ -167,6 +162,22 @@
-(void)kwm_onSelectPayType:(KWMPayType)payType{ -(void)kwm_onSelectPayType:(KWMPayType)payType{
self.payType = payType; self.payType = payType;
if(payType == TypeWechatPay){
self.ivAliPay.image = [UIImage imageNamed:@"ic_choose_nor"];
self.ivWechatPay.image = [UIImage imageNamed:@"ic_choose_sel"];
}else if(payType == TypeAlipay){
self.ivAliPay.image = [UIImage imageNamed:@"ic_choose_sel"];
self.ivWechatPay.image = [UIImage imageNamed:@"ic_choose_nor"];
}
}
-(void)initDiscountHintText{
NSString *holderText = @"请输入优惠码";
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
[placeholder addAttribute:NSForegroundColorAttributeName
value:[UIColor sam_colorWithHex:@"393939"]
range:NSMakeRange(0, holderText.length)];
self.tfDiscount.attributedPlaceholder = placeholder;
} }
- (void)initData{ - (void)initData{
...@@ -201,11 +212,17 @@ ...@@ -201,11 +212,17 @@
} }
//优惠码 //优惠码
if(self.checkout.discount!=nil){ if(self.checkout.discount){
self.lbDiscount.text = self.checkout.discount.code; self.tfDiscount.text = self.checkout.discount.code;
}else{ }else{
self.lbDiscount.text = @"请输入优惠码"; self.tfDiscount.text = @"";
} }
//优惠码编辑相关
self.tfDiscount.enabled = self.isEditingDiscount;
[self.tfDiscount endEditing:!self.isEditingDiscount];
[self.btnDiscountCancel setHidden:!self.isEditingDiscount];
[self.btnDiscountConfirm setHidden:!self.isEditingDiscount];
[self.btnDiscountEdit setHidden:self.isEditingDiscount];
//礼品卡 //礼品卡
if(self.checkout.giftCardsArray!=nil && self.checkout.giftCardsArray.count>0){ if(self.checkout.giftCardsArray!=nil && self.checkout.giftCardsArray.count>0){
BUYGiftCard *giftCard = [self.checkout.giftCardsArray objectAtIndex:0]; BUYGiftCard *giftCard = [self.checkout.giftCardsArray objectAtIndex:0];
...@@ -375,9 +392,13 @@ ...@@ -375,9 +392,13 @@
[self showToast:@"未成功创建订单"]; [self showToast:@"未成功创建订单"];
return; return;
} }
KWMPayTypeVC *typeVC = (KWMPayTypeVC *)[KWMBaseVC findControllerBy:[KWMPayTypeVC kwmTag] fromStoryboard:@"ShopCart"]; UITapGestureRecognizer *tapType = sender;
typeVC.delegate = self; UIView *vType = tapType.view;
[self.navigationController pushViewController:typeVC animated:YES]; if(vType.tag == 1){
[self kwm_onSelectPayType:TypeAlipay];
}else if(vType.tag == 2){
[self kwm_onSelectPayType:TypeWechatPay];
}
} }
//优惠码页面 //优惠码页面
...@@ -386,10 +407,42 @@ ...@@ -386,10 +407,42 @@
[self showToast:@"未成功创建订单"]; [self showToast:@"未成功创建订单"];
return; return;
} }
KWMDiscountVC *discountVC = (KWMDiscountVC *)[KWMBaseVC findControllerBy:[KWMDiscountVC kwmTag] fromStoryboard:@"ShopCart"]; self.isEditingDiscount = YES;
discountVC.checkout = self.checkout; [self initData];
discountVC.delegate = self; [self.tfDiscount becomeFirstResponder];
[self.navigationController pushViewController:discountVC animated:YES]; }
-(void)onClickDiscountCancel:(id)sender{
self.isEditingDiscount = NO;
[self initData];
[self.tfDiscount resignFirstResponder];
}
-(void)onClickDiscountConfirm:(id)sender{
if(self.checkout == nil){
[self showToast:@"未成功创建订单"];
return;
}
if([KWMStringUtil isBlank:self.tfDiscount.text]){
[self showToast:@"优惠码不能为空"];
return;
}
[self.tfDiscount resignFirstResponder];
[self showLoading];
__weak typeof(self) this = self;
[self.client updateCheckout:self.checkout completion:^(NSDictionary *dictionary, BUYCheckout *checkout, NSError *error) {
[this hideLoading];
if (error == nil && checkout && checkout.discount) {
this.checkout = checkout;
[this showToast:@"添加优惠码成功"];
[this flushCheckout:dictionary];
this.isEditingDiscount = NO;
[this initData];
}else {
[this showToast:@"添加优惠码失败"];
[this showError:error];
}
}];
} }
//礼品卡页面 //礼品卡页面
...@@ -429,6 +482,24 @@ ...@@ -429,6 +482,24 @@
[self startCheckout]; [self startCheckout];
} }
#pragma mark - UITextFieldDelegate
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
self.marginTopContent.constant = 22 - 200;
[UIView animateWithDuration:0.5 animations:^{
[self.view layoutIfNeeded];
}];
return YES;
}
//键盘弹出
-(void)keyboardWillHide:(NSNotification *)notification{
self.marginTopContent.constant = 22;
[UIView animateWithDuration:0.5 animations:^{
[self.view layoutIfNeeded];
}];
}
-(void)startCheckout{ -(void)startCheckout{
if(self.checkout == nil){ if(self.checkout == nil){
[self showToast:@"未成功初始化订单"]; [self showToast:@"未成功初始化订单"];
...@@ -485,23 +556,6 @@ ...@@ -485,23 +556,6 @@
[self showToast:errorMsg]; [self showToast:errorMsg];
} }
return errorMsg != nil; return errorMsg != nil;
// if(address == nil){
// [self showToast:@"您的地址尚未有任何地址,请前往选择地址"];
// return YES;
// }else if([KWMStringUtil isEmpty:address.firstName] && [KWMStringUtil isEmpty:address.lastName]){
// [self showToast:@"您的地址缺少收件人姓名,请前往完善地址"];
// return YES;
// }else if([KWMStringUtil isEmpty:address.city]){
// [self showToast:@"您的地址缺少所在城市,请前往完善地址"];
// return YES;
// }else if([KWMStringUtil isEmpty:address.zip]){
// [self showToast:@"您的地址缺少邮政编码,请前往完善地址"];
// return YES;
// }else if([KWMStringUtil isEmpty:address.phone]){
// [self showToast:@"您的地址缺少收件人电话号码,请前往完善地址"];
// return YES;
// }
// return NO;
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
// //
#import "KWMBaseVC.h" #import "KWMBaseVC.h"
#import "KWMRecommendView.h"
#import "KWMPPCacheUtil.h"
@interface KWMPaySuccessVC : KWMBaseVC @interface KWMPaySuccessVC : KWMBaseVC
...@@ -16,12 +18,19 @@ ...@@ -16,12 +18,19 @@
@property (weak, nonatomic) IBOutlet UIButton *btnMyOrder; @property (weak, nonatomic) IBOutlet UIButton *btnMyOrder;
@property (weak, nonatomic) IBOutlet UIButton *btnBackHome;
@property (weak, nonatomic) IBOutlet KWMRecommendView *hotRecommendView;
- (IBAction)onClickStartTime:(id)sender; - (IBAction)onClickStartTime:(id)sender;
- (IBAction)onClickGetTime:(id)sender; - (IBAction)onClickGetTime:(id)sender;
- (IBAction)onClickMyOrder:(id)sender; - (IBAction)onClickMyOrder:(id)sender;
- (IBAction)onClickBackHome:(id)sender;
//用于在跳转后的订单列表页面生成即时订单(支付后的订单需要一定时间后才能从订单列表获取) //用于在跳转后的订单列表页面生成即时订单(支付后的订单需要一定时间后才能从订单列表获取)
@property (nonatomic) BUYCheckout *paidCheckout; @property (nonatomic) BUYCheckout *paidCheckout;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#import "UIViewController+BackButtonHandler.h" #import "UIViewController+BackButtonHandler.h"
#import "KWMOrderVC.h" #import "KWMOrderVC.h"
@interface KWMPaySuccessVC () @interface KWMPaySuccessVC ()<KWMRecommendDelegate>
@end @end
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
self.title = @"支付成功"; self.title = @"支付成功";
[self initButton]; [self initButton];
[self requestProductWithHandle:@"products-list-app-homepage" tags:nil valueKeyPath:@"productArray"];
self.hotRecommendView.title = @"热卖单品";
self.hotRecommendView.delegate = self;
} }
+(NSString *)kwmTag{ +(NSString *)kwmTag{
...@@ -45,6 +48,9 @@ ...@@ -45,6 +48,9 @@
self.btnMyOrder.layer.masksToBounds = YES; self.btnMyOrder.layer.masksToBounds = YES;
self.btnMyOrder.layer.borderColor = [UIColor sam_colorWithHex:@"979797"].CGColor; //要设置的颜色 self.btnMyOrder.layer.borderColor = [UIColor sam_colorWithHex:@"979797"].CGColor; //要设置的颜色
self.btnMyOrder.layer.borderWidth = 1; //要设置的描边宽 self.btnMyOrder.layer.borderWidth = 1; //要设置的描边宽
self.btnBackHome.layer.masksToBounds = YES;
self.btnBackHome.layer.borderColor = [UIColor sam_colorWithHex:@"979797"].CGColor; //要设置的颜色
self.btnBackHome.layer.borderWidth = 1; //要设置的描边宽
} }
...@@ -70,11 +76,80 @@ ...@@ -70,11 +76,80 @@
[self.navigationController pushViewController:orderVC animated:YES]; [self.navigationController pushViewController:orderVC animated:YES];
} }
-(void)onClickBackHome:(id)sender{
[self.navigationController popToRootViewControllerAnimated:YES];
}
-(BOOL) navigationShouldPopOnBackButton { -(BOOL) navigationShouldPopOnBackButton {
[self.navigationController popToRootViewControllerAnimated:YES]; [self.navigationController popToRootViewControllerAnimated:YES];
return NO; // Ignore 'Back' button this time return NO; // Ignore 'Back' button this time
} }
#pragma mark KWMRecommendDelegate
-(void)kwm_gotoRecommendPage:(KWMRecommendView *)recommendView{
[self openURLWithString:@"https://cemarose.myshopify.com/collections/products-list-app-homepage?title=热卖单品"];
}
-(void)kwm_onClickProduct:(BUYProduct *)product{
[self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/products/%@",product.handle]];
}
#pragma makr - api
- (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(nonnull NSString *) valueKeyPath {
NSDictionary *parameters = [KWMPPCacheUtil getProductCacheKeyDictionary:1 tags:tags handle:handle];
BOOL useProductDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:1];
__weak KWMPaySuccessVC *weakSelf = self;
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
if (!error) {
[weakSelf.client getProductsPage:1 inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
if (!error) {
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage products:products];
if(products){
NSArray *productIds;
@try {
if(self.paidCheckout && self.paidCheckout.lineItemsArray){
productIds = [[self.paidCheckout.lineItems array] rx_mapWithBlock:^id(BUYLineItem* each) {
NSNumber *a = each.productId ?: @(0);
return a;
}];
}
}
@catch (NSException *exception) {
// 捕获到的异常exception
}
self.hotRecommendView.productArray = products;
self.hotRecommendView.boughtProductIdArray = productIds;
}
}
}];
}
}];
}
-(BOOL)useProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page{
if(!kIsNetwork || page == 1){
NSArray *productIds;
NSArray *products = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage];
if(products && products.count > 0){
@try {
if(self.paidCheckout && self.paidCheckout.lineItemsArray){
productIds = [[self.paidCheckout.lineItems array] rx_mapWithBlock:^id(BUYLineItem* each) {
NSNumber *a = each.productId ?: @(0);
return a;
}];
}
}
@catch (NSException *exception) {
// 捕获到的异常exception
}
self.hotRecommendView.productArray = products;
self.hotRecommendView.boughtProductIdArray = productIds;
}else{
return false;
}
}
return !kIsNetwork;
}
@end @end
...@@ -17,8 +17,12 @@ ...@@ -17,8 +17,12 @@
#import "KWMCategoryVC.h" #import "KWMCategoryVC.h"
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
#import "KWMShoppingCart.h" #import "KWMShoppingCart.h"
#import "KWMRecommendView.h"
#import "KWMPPCacheUtil.h"
@interface KWMShopCartVC ()<UIAlertViewDelegate> @interface KWMShopCartVC ()<UIAlertViewDelegate,KWMRecommendDelegate>
@property (nonatomic, weak) IBOutlet KWMRecommendView *newestRecommendView;
@property (nonatomic, weak) IBOutlet KWMRecommendView *mainRecommendView;
@property (nonatomic) NSMutableArray *shopCartList; @property (nonatomic) NSMutableArray *shopCartList;
@property (nonatomic, strong) NSMutableArray *soldout; @property (nonatomic, strong) NSMutableArray *soldout;
@end @end
...@@ -53,6 +57,10 @@ ...@@ -53,6 +57,10 @@
[self setTotalPrice]; [self setTotalPrice];
[self checkInStockAndRefresh]; [self checkInStockAndRefresh];
self.newestRecommendView.title = @"最新单品";
self.mainRecommendView.title = @"主推单品";
self.newestRecommendView.delegate = self;
self.mainRecommendView.delegate = self;
} }
- (void) checkInStockAndRefresh { - (void) checkInStockAndRefresh {
...@@ -165,13 +173,9 @@ ...@@ -165,13 +173,9 @@
} }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSInteger count = self.shopCartList ? self.shopCartList.count : 0;
if (_shopCartList.count == 0) { self.vBackground.hidden = count != 0;
self.vBackground.hidden = NO; return count;
}else{
self.vBackground.hidden = YES;
}
return _shopCartList.count;
} }
#pragma mark UITableViewDelegate #pragma mark UITableViewDelegate
...@@ -225,6 +229,19 @@ ...@@ -225,6 +229,19 @@
} }
} }
#pragma mark KWMRecommendDelegate
-(void)kwm_gotoRecommendPage:(KWMRecommendView *)recommendView{
if(recommendView.tag == 1){
[self openURLWithString:@"https://cemarose.myshopify.com/collections/new?title=最新单品"];
}else{
[self openURLWithString:@"https://cemarose.myshopify.com/collections/hot-sell-app?title=主推单品"];
}
}
-(void)kwm_onClickProduct:(BUYProduct *)product{
[self openURLWithString:[NSString stringWithFormat:@"https://cemarose.myshopify.com/products/%@",product.handle]];
}
- (void)kwm_onClickDelete:(KWMShopCartModel *)shopCartModel{ - (void)kwm_onClickDelete:(KWMShopCartModel *)shopCartModel{
self.vDelete.hidden = NO; self.vDelete.hidden = NO;
self.vDelete.delegate = self; self.vDelete.delegate = self;
...@@ -356,6 +373,11 @@ ...@@ -356,6 +373,11 @@
self.shopCartList = [[KWMShoppingCart sharedInstance] items]; self.shopCartList = [[KWMShoppingCart sharedInstance] items];
[self.tbvCart reloadData]; [self.tbvCart reloadData];
[self setTotalPrice]; [self setTotalPrice];
if(! self.shopCartList || self.shopCartList.count == 0){
//请求推荐商品数据
[self requestProductWithHandle:@"new" tags:nil valueKeyPath:@"newestRecommendView"];
[self requestProductWithHandle:@"hot-sell-app" tags:nil valueKeyPath:@"mainRecommendView"];
}
// [self.client getProductsByIds:[self.shopCartList rx_mapWithBlock:^id(KWMShopCartModel *each) { // [self.client getProductsByIds:[self.shopCartList rx_mapWithBlock:^id(KWMShopCartModel *each) {
// return each.product_id; // return each.product_id;
// }] completion:^(NSArray<BUYProduct *> * _Nullable products, NSError * _Nullable error) { // }] completion:^(NSArray<BUYProduct *> * _Nullable products, NSError * _Nullable error) {
...@@ -380,4 +402,44 @@ ...@@ -380,4 +402,44 @@
_lbTotalPrice.text = total.priceFormatted; _lbTotalPrice.text = total.priceFormatted;
} }
#pragma makr - api
- (void) requestProductWithHandle:(NSString *) handle tags:(NSArray *) tags valueKeyPath:(nonnull NSString *) valueKeyPath {
NSDictionary *parameters = [KWMPPCacheUtil getProductCacheKeyDictionary:1 tags:tags handle:handle];
BOOL useProductDataCache = [self useProductDataCache:parameters valueKeyPath:valueKeyPath page:1];
__weak KWMShopCartVC *weakSelf = self;
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
if (!error) {
[weakSelf.client getProductsPage:1 inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
if (!error) {
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage products:products];
if(products){
if([valueKeyPath isEqualToString:@"newestRecommendView"]){
weakSelf.newestRecommendView.productArray = products;
}else{
weakSelf.mainRecommendView.productArray = products;
}
}
}
}];
}
}];
}
-(BOOL)useProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page{
if(!kIsNetwork || page == 1){
NSArray *products = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage];
if(products && products.count > 0){
if([valueKeyPath isEqualToString:@"newestRecommendView"]){
self.newestRecommendView.productArray = products;
}else{
self.mainRecommendView.productArray = products;
}
}else{
return false;
}
}
return !kIsNetwork;
}
@end @end
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
tags:(nullable NSArray <NSString *> *)tags tags:(nullable NSArray <NSString *> *)tags
inCollection:(nullable NSNumber *)collectionId; inCollection:(nullable NSNumber *)collectionId;
//初始化缓存parameters key
+ (NSDictionary *)getProductCacheKeyDictionary:(NSUInteger)page
tags:(nullable NSArray <NSString *> *)tags
handle:(nullable NSString *)handle;
+ (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products; + (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products;
+ (NSArray *)getProductDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey; + (NSArray *)getProductDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey;
......
...@@ -33,6 +33,23 @@ ...@@ -33,6 +33,23 @@
return params; return params;
} }
//初始化缓存parameters key
+ (NSDictionary *)getProductCacheKeyDictionary:(NSUInteger)page
tags:(nullable NSArray <NSString *> *)tags
handle:(nullable NSString *)handle{
NSMutableDictionary *params = @{
// @"limit" : @(self.client.pageSize),
@"page" : @(page)
}.mutableCopy;
if (tags) {
params[@"tag"] = [tags componentsJoinedByString:@","];
}
if (handle) {
params[@"handle"] = handle;
}
return params;
}
+ (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products{ + (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products{
NSMutableArray *dictArray = [NSMutableArray array]; NSMutableArray *dictArray = [NSMutableArray array];
......
...@@ -8,15 +8,16 @@ ...@@ -8,15 +8,16 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <Buy/Buy.h> #import <Buy/Buy.h>
@class KWMRecommendView;
@protocol KWMRecommendDelegate <NSObject> @protocol KWMRecommendDelegate <NSObject>
- (void)kwm_onClickProduct:(BUYProduct *)product; - (void)kwm_onClickProduct:(BUYProduct *)product;
- (void)kwm_gotoRecommendPage; - (void)kwm_gotoRecommendPage:(KWMRecommendView *)recommendView;
@end @end
@interface KWMRecommendHeader : UIView<UICollectionViewDataSource,UICollectionViewDelegate> @interface KWMRecommendView : UIView<UICollectionViewDataSource,UICollectionViewDelegate>
+ (NSString *)kwmTag; + (NSString *)kwmTag;
...@@ -24,4 +25,9 @@ ...@@ -24,4 +25,9 @@
@property(nonatomic) NSArray *productArray; @property(nonatomic) NSArray *productArray;
@property(nonatomic) NSString *title;
//已购买商品,用于去重
@property(nonatomic) NSArray *boughtProductIdArray;
@end @end
...@@ -6,21 +6,23 @@ ...@@ -6,21 +6,23 @@
// Copyright © 2017年 kollway. All rights reserved. // Copyright © 2017年 kollway. All rights reserved.
// //
#import "KWMRecommendHeader.h" #import "KWMRecommendView.h"
#import "KWMCollectionCell.h" #import "KWMCollectionCell.h"
@interface KWMRecommendHeader() @interface KWMRecommendView()
@property (nonatomic,weak) IBOutlet UIView *vView; @property (nonatomic,weak) IBOutlet UIView *vView;
@property (nonatomic,weak) IBOutlet UICollectionView *cvRecommend; @property (nonatomic,weak) IBOutlet UICollectionView *cvRecommend;
@property (nonatomic,weak) IBOutlet UILabel *lbTitle;
@end @end
@implementation KWMRecommendHeader @implementation KWMRecommendView
+(NSString *)kwmTag{ +(NSString *)kwmTag{
return @"KWMRecommendHeader"; return @"KWMRecommendView";
} }
- (id)init{ - (id)init{
...@@ -68,11 +70,33 @@ ...@@ -68,11 +70,33 @@
self.cvRecommend.collectionViewLayout = layout; self.cvRecommend.collectionViewLayout = layout;
} }
-(void)setTitle:(NSString *)title{
_title = title;
if(self.lbTitle){
[self.lbTitle setText:title];
}
}
-(void)setProductArray:(NSArray *)productArray{ -(void)setProductArray:(NSArray *)productArray{
_productArray = productArray; _productArray = productArray;
[self removeSameProduct];
[self.cvRecommend reloadData]; [self.cvRecommend reloadData];
} }
-(void)setBoughtProductIdArray:(NSArray *)boughtProductIdArray{
_boughtProductIdArray = boughtProductIdArray;
[self removeSameProduct];
[self.cvRecommend reloadData];
}
-(void)removeSameProduct{
if(self.productArray && self.boughtProductIdArray){
_productArray = [self.productArray rx_filterWithBlock:^BOOL(BUYProduct *each){
return (![self.boughtProductIdArray containsObject:each.identifier]);
}];
}
}
#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];
...@@ -93,17 +117,26 @@ ...@@ -93,17 +117,26 @@
} }
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if(self.productArray && self.productArray.count > 9){ NSInteger productCount = self.productArray?self.productArray.count:0;
NSInteger boughtCount = self.boughtProductIdArray?self.boughtProductIdArray.count:0;
if(productCount > 9){
return 10; return 10;
} }
if(productCount + boughtCount > 9){
return productCount+1;
}
return self.productArray?self.productArray.count:0; return self.productArray?self.productArray.count:0;
} }
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[collectionView deselectItemAtIndexPath:indexPath animated:YES]; [collectionView deselectItemAtIndexPath:indexPath animated:YES];
if(indexPath.row == 9){ NSInteger productCount = self.productArray?self.productArray.count:0;
NSInteger boughtCount = self.boughtProductIdArray?self.boughtProductIdArray.count:0;
BOOL hasMore = (productCount > 9) || (productCount + boughtCount > 9);
if([self collectionView:self.cvRecommend numberOfItemsInSection:0] == indexPath.row + 1
&& hasMore){
if(self.delegate){ if(self.delegate){
[self.delegate kwm_gotoRecommendPage]; [self.delegate kwm_gotoRecommendPage:self];
} }
}else{ }else{
BUYProduct *product = [self.productArray objectAtIndex:indexPath.row]; BUYProduct *product = [self.productArray objectAtIndex:indexPath.row];
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/> <adaptation id="fullscreen"/>
</device> </device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<customFonts key="customFonts"> <customFonts key="customFonts">
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
</array> </array>
</customFonts> </customFonts>
<objects> <objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="KWMRecommendHeader"> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="KWMRecommendView">
<connections> <connections>
<outlet property="cvRecommend" destination="YkQ-i0-Pi8" id="k1I-3x-9pe"/> <outlet property="cvRecommend" destination="YkQ-i0-Pi8" id="k1I-3x-9pe"/>
<outlet property="lbTitle" destination="7Fq-VX-XvA" id="643-OU-gbL"/>
<outlet property="vView" destination="iN0-l3-epB" id="4mj-ET-3eS"/> <outlet property="vView" destination="iN0-l3-epB" id="4mj-ET-3eS"/>
</connections> </connections>
</placeholder> </placeholder>
......
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