Commit 8d5eb243 by houweibin

wishlist逻辑调整

parent 050f30f1
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
- (void)reLoadData; - (void)reLoadData;
- (void)loadData; - (void)loadData;
- (BOOL)checkLogin;
- (void)transparentNavigationBar; - (void)transparentNavigationBar;
- (void)unTransparentNavigationBar; - (void)unTransparentNavigationBar;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#import "PSPDFAlertView.h" #import "PSPDFAlertView.h"
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
#import "KWMSuperLoadingView.h" #import "KWMSuperLoadingView.h"
#import "KWMLoginVC.h"
#import "KWMUserModel.h"
@interface KWMBaseVC () @interface KWMBaseVC ()
...@@ -287,6 +289,19 @@ ...@@ -287,6 +289,19 @@
NSAssert(NO, @"调用尚未实现的方法"); NSAssert(NO, @"调用尚未实现的方法");
} }
-(BOOL)checkLogin{
KWMUserModel *user = [KWMUserModel shareUser];
if (user.status != 1) {
//登录
KWMLoginVC *loginVc = (KWMLoginVC *)[KWMBaseVC findControllerBy:[KWMLoginVC kwmTag] fromStoryboard:@"Login"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVc];
[self presentViewController:nav animated:YES completion:nil];
return NO;
}else{
return YES;
}
}
//显示错误信息 //显示错误信息
- (void)showError:(NSError *)error{ - (void)showError:(NSError *)error{
if ([error.domain isEqualToString:NSURLErrorDomain]) { if ([error.domain isEqualToString:NSURLErrorDomain]) {
......
...@@ -164,6 +164,9 @@ typedef enum{ ...@@ -164,6 +164,9 @@ typedef enum{
-(void)kwm_onClickWishMenu{ -(void)kwm_onClickWishMenu{
NSLog(@"wishmenu"); NSLog(@"wishmenu");
if(![self checkLogin]){
return;
}
KWMWishListVC* vc= (KWMWishListVC *)[KWMBaseVC findControllerBy:[KWMWishListVC kwmTag] fromStoryboard:@"NewProduct"]; KWMWishListVC* vc= (KWMWishListVC *)[KWMBaseVC findControllerBy:[KWMWishListVC kwmTag] fromStoryboard:@"NewProduct"];
[self.navigationController pushViewController:vc animated:YES]; [self.navigationController pushViewController:vc animated:YES];
} }
......
...@@ -62,8 +62,8 @@ ...@@ -62,8 +62,8 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.productId = @(7436196294); // self.productId = @(7436196294);
self.product = nil; // self.product = nil;
[self initView]; [self initView];
} }
...@@ -452,7 +452,7 @@ ...@@ -452,7 +452,7 @@
__weak KWMNewProductVC *weakSelf = self; __weak KWMNewProductVC *weakSelf = self;
NSDictionary *customerDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"customer"]; NSDictionary *customerDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"customer"];
BUYCustomer *customer = [[BUYCustomer alloc] initWithModelManager:self.client.modelManager JSONDictionary:customerDict]; BUYCustomer *customer = [[BUYCustomer alloc] initWithModelManager:self.client.modelManager JSONDictionary:customerDict];
BUYProductVariant *variant = self.detailView1.variant; BUYProductVariant *variant = self.variant;
if(!customer || !variant){ if(!customer || !variant){
return; return;
} }
...@@ -521,16 +521,17 @@ ...@@ -521,16 +521,17 @@
if(!customer || !self.variant){ if(!customer || !self.variant){
return; return;
} }
BUYProduct *product = (self.color && self.color.product)?self.color.product:self.product;
NSDictionary *parament = @{ NSDictionary *parament = @{
@"customer_id":customer.identifier.stringValue, @"customer_id":customer.identifier.stringValue,
@"customer_email":customer.email, @"customer_email":customer.email,
@"customer_name":customer.lastName, @"customer_name":customer.lastName,
@"product_title":self.product.title, @"product_title":product.title,
@"product_id":self.product.identifier.stringValue, @"product_id":product.identifier.stringValue,
@"variant_id":self.variant.identifier.stringValue, @"variant_id":self.variant.identifier.stringValue,
@"variant_sku":self.variant.sku, @"variant_sku":self.variant.sku,
@"variant_title":self.variant.title, @"variant_title":self.variant.title,
@"product_handle":self.product.handle, @"product_handle":product.handle,
@"shop":Shopify_SHOP_DOMAIN @"shop":Shopify_SHOP_DOMAIN
}; };
void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){ void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
@property(nonatomic) IBOutlet UILabel *lbCount; @property(nonatomic) IBOutlet UILabel *lbCount;
@property(weak,nonatomic) IBOutlet UIView *vCount;
@property(nonatomic) NSInteger count; @property(nonatomic) NSInteger count;
@property(nonatomic) NSDecimalNumber *totalPrice; @property(nonatomic) NSDecimalNumber *totalPrice;
...@@ -140,6 +142,7 @@ ...@@ -140,6 +142,7 @@
if(self.selectVariant){ if(self.selectVariant){
self.totalPrice = [self.selectVariant.price decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithDecimal:@(self.count).decimalValue]]; self.totalPrice = [self.selectVariant.price decimalNumberByMultiplyingBy:[NSDecimalNumber decimalNumberWithDecimal:@(self.count).decimalValue]];
} }
self.vCount.hidden = self.wish?YES:NO;
self.lbCount.text = [NSString stringWithFormat:@"%ld",(long)self.count]; self.lbCount.text = [NSString stringWithFormat:@"%ld",(long)self.count];
self.lbPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormatted:self.totalPrice]; self.lbPrice.text = [[KWMCurrencyUtil sharedInstance] priceFormatted:self.totalPrice];
} }
...@@ -193,10 +196,13 @@ ...@@ -193,10 +196,13 @@
* @param sender <#sender description#> * @param sender <#sender description#>
*/ */
-(IBAction)onClickComplete:(UIButton *)sender{ -(IBAction)onClickComplete:(UIButton *)sender{
if (self.selectVariant == nil || self.count==0) { if (self.selectVariant == nil) {
[self showToast:@"请选择您想要的规格"]; [self showToast:@"请选择您想要的规格"];
return; return;
} }
if (self.count <= 0 && self.wish){
[self showToast:@"商品数量不能为0"];
}
//购物车页面 //购物车页面
if ([self.delegate respondsToSelector:@selector(kwm_addShopWithVariantId:quantity:variant:buyNow:callback:)]){ if ([self.delegate respondsToSelector:@selector(kwm_addShopWithVariantId:quantity:variant:buyNow:callback:)]){
__weak id this = self; __weak id this = self;
...@@ -387,6 +393,12 @@ ...@@ -387,6 +393,12 @@
if(variant && self.selectVariant){ if(variant && self.selectVariant){
return [variant.identifier isEqualToNumber:self.selectVariant.identifier]; return [variant.identifier isEqualToNumber:self.selectVariant.identifier];
}; };
if(variant && self.wish && !self.selectVariant){
if([variant.identifier isEqualToNumber:self.wish.variantId]){
self.selectVariant = variant;
return YES;
}
}
return NO; return NO;
} }
......
...@@ -44,18 +44,24 @@ ...@@ -44,18 +44,24 @@
- (void)initView{ - (void)initView{
self.title = @"我喜欢的"; self.title = @"我喜欢的";
[self.tbvWish registerNib:[UINib nibWithNibName:NSStringFromClass([KWMWishCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([KWMWishCell class])]; [self.tbvWish registerNib:[UINib nibWithNibName:NSStringFromClass([KWMWishCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([KWMWishCell class])];
self.wishArray = [NSMutableArray array]; self.wishArray = [NSMutableArray array];
self.productArray = [NSMutableArray array]; self.productArray = [NSMutableArray array];
[self setTotalPrice]; [self setTotalPrice];
} }
-(void)removeWish:(NSNumber *)variantId{ -(void)removeWish:(NSNumber *)variantId{
for(KWMWish *wish in self.wishArray){ NSInteger removeIndex = -1;
for(NSInteger i = 0;i < self.wishArray.count;i++){
KWMWish *wish = [self.wishArray objectAtIndex:i];
if([wish.variantId isEqualToNumber:variantId]){ if([wish.variantId isEqualToNumber:variantId]){
[self.wishArray removeObject:wish]; removeIndex = i;
break;
} }
} }
if(removeIndex != -1){
[self.wishArray removeObjectAtIndex:removeIndex];
[self.tbvWish reloadData];
}
} }
//计算总价格 //计算总价格
...@@ -73,7 +79,7 @@ ...@@ -73,7 +79,7 @@
} }
#pragma mark --KWMVariantsVCDelegate #pragma mark --KWMVariantsVCDelegate
-(void)kwm_setVariant:(KWMVariantsVC *)variantsVC variant:(BUYProductVariant *)variant{ -(void)kwm_setVariant:(KWMVariantsVC *)variantsVC variant:(BUYProductVariant *)variant color:(KWMColor *)color count:(NSInteger)count{
for(KWMWish *wish in self.wishArray){ for(KWMWish *wish in self.wishArray){
if([wish.variantId isEqualToNumber:variantsVC.wish.variantId]){ if([wish.variantId isEqualToNumber:variantsVC.wish.variantId]){
wish.variantId = variant.identifier; wish.variantId = variant.identifier;
...@@ -176,11 +182,11 @@ ...@@ -176,11 +182,11 @@
#pragma mark-- KWMAPIManager #pragma mark-- KWMAPIManager
-(void)requestWishList{ -(void)requestWishList{
__weak KWMWishListVC *weakSelf = self; __weak KWMWishListVC *weakSelf = self;
NSDictionary *customerDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"customer"]; if(![self checkLogin]){
BUYCustomer *customer = [[BUYCustomer alloc] initWithModelManager:self.client.modelManager JSONDictionary:customerDict];
if(!customer){
return; return;
} }
NSDictionary *customerDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"customer"];
BUYCustomer *customer = [[BUYCustomer alloc] initWithModelManager:self.client.modelManager JSONDictionary:customerDict];
NSDictionary *parament = @{ NSDictionary *parament = @{
@"customer_id":customer.identifier.stringValue, @"customer_id":customer.identifier.stringValue,
@"customer_email":customer.email, @"customer_email":customer.email,
...@@ -193,8 +199,9 @@ ...@@ -193,8 +199,9 @@
void(^success)(NSURLSessionDataTask *,KWMAdditionalListResult *) = ^(NSURLSessionDataTask *task,KWMAdditionalListResult *result){ void(^success)(NSURLSessionDataTask *,KWMAdditionalListResult *) = ^(NSURLSessionDataTask *task,KWMAdditionalListResult *result){
[weakSelf hideLoading]; [weakSelf hideLoading];
if(result && result.data){ if(result && result.data){
NSMutableArray *wishArray = (NSMutableArray *)result.data; NSArray *wishArray = (NSArray *)result.data;
weakSelf.wishArray = wishArray; [weakSelf.wishArray removeAllObjects];
[weakSelf.wishArray addObjectsFromArray:wishArray];
[weakSelf.tbvWish reloadData]; [weakSelf.tbvWish reloadData];
[weakSelf requestProductsApi]; [weakSelf requestProductsApi];
} }
......
...@@ -509,6 +509,7 @@ ...@@ -509,6 +509,7 @@
<outlet property="lbCount" destination="GZ8-oT-VCl" id="LiQ-6e-76f"/> <outlet property="lbCount" destination="GZ8-oT-VCl" id="LiQ-6e-76f"/>
<outlet property="lbPrice" destination="0UA-fW-OwV" id="ifJ-78-Kc8"/> <outlet property="lbPrice" destination="0UA-fW-OwV" id="ifJ-78-Kc8"/>
<outlet property="vContentHeight" destination="YBc-tS-Vne" id="qU7-CX-T7w"/> <outlet property="vContentHeight" destination="YBc-tS-Vne" id="qU7-CX-T7w"/>
<outlet property="vCount" destination="zhl-Qy-ueI" id="DHl-4S-o3l"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="MKE-1G-zhs" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="MKE-1G-zhs" userLabel="First Responder" sceneMemberID="firstResponder"/>
......
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