Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ios1x
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cemarose
ios1x
Commits
0fc3663b
Commit
0fc3663b
authored
May 26, 2017
by
lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完结版本
parent
729052aa
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
18 deletions
+66
-18
KWMShoppingCart.h
iCemarose/Class/Model/KWMShoppingCart.h
+2
-0
KWMShoppingCart.m
iCemarose/Class/Model/KWMShoppingCart.m
+53
-4
KWMBrandCaramelVC.m
iCemarose/Class/UI/Brand/KWMBrandCaramelVC.m
+2
-2
KWMBrandVC.m
iCemarose/Class/UI/Brand/KWMBrandVC.m
+2
-2
KWMHomeVC.m
iCemarose/Class/UI/Home/KWMHomeVC.m
+2
-2
KWMNewVC.m
iCemarose/Class/UI/Product/KWMNewVC.m
+3
-2
KWMProductDetailVC.m
iCemarose/Class/UI/Product/KWMProductDetailVC.m
+2
-3
KWMShopCartVC.m
iCemarose/Class/UI/ShopCart/KWMShopCartVC.m
+0
-3
No files found.
iCemarose/Class/Model/KWMShoppingCart.h
View file @
0fc3663b
...
@@ -16,6 +16,8 @@ typedef void(^ShoppingCartCallBack) (NSError *error,KWMCartResult *cart);
...
@@ -16,6 +16,8 @@ typedef void(^ShoppingCartCallBack) (NSError *error,KWMCartResult *cart);
@property
(
nonatomic
,
strong
)
NSMutableArray
<
KWMShopCartModel
*>
*
items
;
@property
(
nonatomic
,
strong
)
NSMutableArray
<
KWMShopCartModel
*>
*
items
;
@property
(
nonatomic
,
strong
)
NSNumber
*
count
;
+
(
instancetype
)
sharedInstance
;
+
(
instancetype
)
sharedInstance
;
-
(
void
)
allItemsWithCallback
:(
ShoppingCartCallBack
)
callback
;
-
(
void
)
allItemsWithCallback
:(
ShoppingCartCallBack
)
callback
;
...
...
iCemarose/Class/Model/KWMShoppingCart.m
View file @
0fc3663b
...
@@ -22,6 +22,10 @@
...
@@ -22,6 +22,10 @@
return
(
NSMutableArray
*
)
_result
.
items
;
return
(
NSMutableArray
*
)
_result
.
items
;
}
}
-
(
NSNumber
*
)
count
{
return
_result
.
item_count
;
}
-
(
void
)
setResult
:
(
KWMCartResult
*
)
result
{
-
(
void
)
setResult
:
(
KWMCartResult
*
)
result
{
_result
=
result
;
_result
=
result
;
[[
KWMShopCartData
alloc
]
syncCartProducts
:
result
.
items
];
[[
KWMShopCartData
alloc
]
syncCartProducts
:
result
.
items
];
...
@@ -33,6 +37,15 @@
...
@@ -33,6 +37,15 @@
dispatch_once
(
&
onceToken
,
^
{
dispatch_once
(
&
onceToken
,
^
{
instance
=
[[
super
allocWithZone
:
NULL
]
init
];
instance
=
[[
super
allocWithZone
:
NULL
]
init
];
});
});
if
(
!
instance
.
result
)
{
instance
.
result
=
[[
KWMCartResult
alloc
]
init
];
instance
.
result
.
items
=
[[[
KWMShopCartData
alloc
]
getALLItems
]
mutableCopy
];
NSInteger
count
=
0
;
for
(
KWMShopCartModel
*
item
in
instance
.
items
)
{
count
+=
item
.
quantity
;
}
instance
.
result
.
item_count
=
@
(
count
);
}
return
instance
;
return
instance
;
}
}
...
@@ -46,21 +59,23 @@
...
@@ -46,21 +59,23 @@
}
}
-
(
void
)
increaseProductWithVariantId
:
(
NSNumber
*
)
variantId
quantity
:
(
NSInteger
)
quantity
callback
:
(
ShoppingCartCallBack
)
callback
{
-
(
void
)
increaseProductWithVariantId
:
(
NSNumber
*
)
variantId
quantity
:
(
NSInteger
)
quantity
callback
:
(
ShoppingCartCallBack
)
callback
{
callback
(
nil
,[
self
changeLocalCartWithVariantId
:
variantId
quantity
:
quantity
flag
:
1
]);
[[
KWMAPIManager
sharedManager
]
addProductWithVariantId
:
variantId
quantity
:
quantity
success
:^
(
NSURLSessionDataTask
*
task
,
KWMRequestResult
*
result
)
{
[[
KWMAPIManager
sharedManager
]
addProductWithVariantId
:
variantId
quantity
:
quantity
success
:^
(
NSURLSessionDataTask
*
task
,
KWMRequestResult
*
result
)
{
[[
KWMShoppingCart
sharedInstance
]
allItemsWithCallback
:
^
(
NSError
*
error
,
KWMCartResult
*
cart
)
{
[[
KWMShoppingCart
sharedInstance
]
allItemsWithCallback
:
^
(
NSError
*
error
,
KWMCartResult
*
cart
)
{
callback
(
error
,
cart
);
//
callback(error,cart);
}];
}];
}
failure
:^
(
NSURLSessionDataTask
*
task
,
NSError
*
error
)
{
}
failure
:^
(
NSURLSessionDataTask
*
task
,
NSError
*
error
)
{
callback
(
error
,
nil
);
//
callback(error,nil);
}];
}];
}
}
-
(
void
)
updateProductWithVariantId
:
(
NSNumber
*
)
variantId
quantity
:
(
NSInteger
)
quantity
callback
:
(
ShoppingCartCallBack
)
callback
{
-
(
void
)
updateProductWithVariantId
:
(
NSNumber
*
)
variantId
quantity
:
(
NSInteger
)
quantity
callback
:
(
ShoppingCartCallBack
)
callback
{
callback
(
nil
,[
self
changeLocalCartWithVariantId
:
variantId
quantity
:
quantity
flag
:
quantity
?
2
:
0
]);
[[
KWMAPIManager
sharedManager
]
updateProductWithVariantId
:
variantId
quantity
:
quantity
success
:^
(
NSURLSessionDataTask
*
task
,
KWMCartResult
*
result
)
{
[[
KWMAPIManager
sharedManager
]
updateProductWithVariantId
:
variantId
quantity
:
quantity
success
:^
(
NSURLSessionDataTask
*
task
,
KWMCartResult
*
result
)
{
[[
KWMShoppingCart
sharedInstance
]
setResult
:
result
];
[[
KWMShoppingCart
sharedInstance
]
setResult
:
result
];
callback
(
nil
,
result
);
//
callback(nil,result);
}
failure
:^
(
NSURLSessionDataTask
*
task
,
NSError
*
error
)
{
}
failure
:^
(
NSURLSessionDataTask
*
task
,
NSError
*
error
)
{
callback
(
error
,
nil
);
//
callback(error,nil);
}];
}];
}
}
...
@@ -68,6 +83,40 @@
...
@@ -68,6 +83,40 @@
[
self
updateProductWithVariantId
:
variantId
quantity
:
0
callback
:
callback
];
[
self
updateProductWithVariantId
:
variantId
quantity
:
0
callback
:
callback
];
}
}
-
(
KWMCartResult
*
)
changeLocalCartWithVariantId
:
(
NSNumber
*
)
variantId
quantity
:
(
NSInteger
)
quantity
flag
:
(
NSInteger
)
flag
{
NSMutableArray
<
KWMShopCartModel
*>
*
items
=
self
.
items
;
NSInteger
count
=
self
.
result
.
item_count
.
integerValue
;
BOOL
processed
=
NO
;
for
(
KWMShopCartModel
*
item
in
items
)
{
if
(
item
.
identifier
.
integerValue
==
variantId
.
integerValue
)
{
switch
(
flag
)
{
case
0
:
count
-=
item
.
quantity
;
[
items
removeObject
:
item
];
break
;
case
1
:
count
+=
quantity
;
item
.
quantity
+=
quantity
;
break
;
default
:
count
-=
item
.
quantity
-
quantity
;
item
.
quantity
=
quantity
;
}
processed
=
YES
;
break
;
}
}
if
(
!
processed
)
{
KWMShopCartModel
*
model
=
[[
KWMShopCartModel
alloc
]
init
];
model
.
identifier
=
variantId
.
stringValue
;
model
.
quantity
=
quantity
;
count
+=
quantity
;
[
items
addObject
:
model
];
}
self
.
result
.
item_count
=
@
(
count
);
return
self
.
result
;
}
+
(
id
)
allocWithZone
:
(
struct
_NSZone
*
)
zone
{
+
(
id
)
allocWithZone
:
(
struct
_NSZone
*
)
zone
{
return
[
KWMShoppingCart
sharedInstance
];
return
[
KWMShoppingCart
sharedInstance
];
}
}
...
...
iCemarose/Class/UI/Brand/KWMBrandCaramelVC.m
View file @
0fc3663b
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#import "UIColor+SAMAdditions.h"
#import "UIColor+SAMAdditions.h"
#import "KWMFilterVC.h"
#import "KWMFilterVC.h"
#import "KWMImageBlurUtil.h"
#import "KWMImageBlurUtil.h"
#import "KWMShoppingCart.h"
@interface
KWMBrandCaramelVC
()
<
UITableViewDelegate
,
UITableViewDataSource
,
KWMBrandCaramelCellDelegate
>
@interface
KWMBrandCaramelVC
()
<
UITableViewDelegate
,
UITableViewDataSource
,
KWMBrandCaramelCellDelegate
>
@property
(
nonatomic
)
KWMBarandSelectView
*
barandSelectView
;
@property
(
nonatomic
)
KWMBarandSelectView
*
barandSelectView
;
...
@@ -135,8 +136,7 @@
...
@@ -135,8 +136,7 @@
-
(
void
)
initHeaderView
{
-
(
void
)
initHeaderView
{
_barandSelectView
=
[[
KWMBarandSelectView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
UI_SCREEN_WIDTH
,
64
)];
_barandSelectView
=
[[
KWMBarandSelectView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
UI_SCREEN_WIDTH
,
64
)];
NSArray
*
arr
=
[[
KWMShopCartData
alloc
]
getALLItems
];
_barandSelectView
.
count
=
[[
KWMShoppingCart
sharedInstance
]
count
].
integerValue
;
_barandSelectView
.
count
=
arr
.
count
;
_barandSelectView
.
lbBrand
.
text
=
[
_brand
uppercaseString
];
_barandSelectView
.
lbBrand
.
text
=
[
_brand
uppercaseString
];
...
...
iCemarose/Class/UI/Brand/KWMBrandVC.m
View file @
0fc3663b
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/UIImageView+WebCache.h>
#import "KWMBrandsTypeModel.h"
#import "KWMBrandsTypeModel.h"
#import "UIColor+SAMAdditions.h"
#import "UIColor+SAMAdditions.h"
#import "KWMShoppingCart.h"
@interface
KWMBrandVC
()
<
KWMCarCountViewDelegate
>
@interface
KWMBrandVC
()
<
KWMCarCountViewDelegate
>
...
@@ -79,8 +80,7 @@ static NSString *cellId = @"KWMBrandCell";
...
@@ -79,8 +80,7 @@ static NSString *cellId = @"KWMBrandCell";
-
(
void
)
initHeardView
{
-
(
void
)
initHeardView
{
_vCartCount
=
[[
KWMCarCountView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
UI_SCREEN_WIDTH
,
64
)];
_vCartCount
=
[[
KWMCarCountView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
UI_SCREEN_WIDTH
,
64
)];
NSArray
*
arr
=
[[
KWMShopCartData
alloc
]
getALLItems
];
_vCartCount
.
count
=
[[
KWMShoppingCart
sharedInstance
]
count
].
integerValue
;
_vCartCount
.
count
=
arr
.
count
;
_vCartCount
.
delegate
=
self
;
_vCartCount
.
delegate
=
self
;
[
self
.
view
addSubview
:
_vCartCount
];
[
self
.
view
addSubview
:
_vCartCount
];
}
}
...
...
iCemarose/Class/UI/Home/KWMHomeVC.m
View file @
0fc3663b
...
@@ -73,8 +73,8 @@
...
@@ -73,8 +73,8 @@
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
[
self
initHeaderView
];
[
self
initHeaderView
];
if
(
_searchBar
)
{
if
(
_searchBar
)
{
NS
Array
*
arr
=
[[
KWMShopCartData
alloc
]
getALLItems
]
;
NS
Integer
count
=
[[
KWMShoppingCart
sharedInstance
]
count
].
integerValue
;
_searchBar
.
count
=
arr
.
count
;
_searchBar
.
count
=
count
;
}
}
[
_searchBar
resumeView
];
[
_searchBar
resumeView
];
}
}
...
...
iCemarose/Class/UI/Product/KWMNewVC.m
View file @
0fc3663b
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#import "KWMBrandCaramelVC.h"
#import "KWMBrandCaramelVC.h"
#import "UIColor+SAMAdditions.h"
#import "UIColor+SAMAdditions.h"
#import "KWMProductDetailVC.h"
#import "KWMProductDetailVC.h"
#import "KWMShoppingCart.h"
@interface
KWMNewVC
()
@interface
KWMNewVC
()
...
@@ -93,8 +94,8 @@ static NSString * idStr = @"KWMNewGoodsCell";
...
@@ -93,8 +94,8 @@ static NSString * idStr = @"KWMNewGoodsCell";
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
[
self
.
navigationController
setNavigationBarHidden
:
YES
];
[
self
.
tabBarController
setHidesBottomBarWhenPushed
:
NO
];
[
self
.
tabBarController
setHidesBottomBarWhenPushed
:
NO
];
if
(
_searchBar
)
{
if
(
_searchBar
)
{
NS
Array
*
arr
=
[[
KWMShopCartData
alloc
]
getALLItems
]
;
NS
Integer
count
=
[[
KWMShoppingCart
sharedInstance
]
count
].
integerValue
;
_searchBar
.
count
=
arr
.
count
;
_searchBar
.
count
=
count
;
}
}
[
_searchBar
resumeView
];
[
_searchBar
resumeView
];
_vBackground
.
hidden
=
YES
;
_vBackground
.
hidden
=
YES
;
...
...
iCemarose/Class/UI/Product/KWMProductDetailVC.m
View file @
0fc3663b
...
@@ -126,9 +126,8 @@
...
@@ -126,9 +126,8 @@
}
}
-
(
void
)
initShopCartCount
{
-
(
void
)
initShopCartCount
{
NSArray
*
shopCarArray
=
[[
KWMShopCartData
alloc
]
getALLItems
];
NSNumber
*
count
=
[[
KWMShoppingCart
sharedInstance
]
count
];
NSInteger
count
=
shopCarArray
==
0
?
0
:
shopCarArray
.
count
;
[
self
.
btnShopCart
setTitle
:
count
.
stringValue
forState
:
UIControlStateNormal
];
[
self
.
btnShopCart
setTitle
:
@
(
count
).
stringValue
forState
:
UIControlStateNormal
];
}
}
-
(
void
)
setProductId
:
(
NSNumber
*
)
productId
{
-
(
void
)
setProductId
:
(
NSNumber
*
)
productId
{
...
...
iCemarose/Class/UI/ShopCart/KWMShopCartVC.m
View file @
0fc3663b
...
@@ -40,9 +40,6 @@
...
@@ -40,9 +40,6 @@
self
.
title
=
@"购物车"
;
self
.
title
=
@"购物车"
;
// self.vBackground.hidden = NO;
// self.vBackground.hidden = NO;
_shopCartList
=
(
NSMutableArray
*
)[[
KWMShoppingCart
sharedInstance
]
items
];
_shopCartList
=
(
NSMutableArray
*
)[[
KWMShoppingCart
sharedInstance
]
items
];
if
(
!
_shopCartList
)
{
_shopCartList
=
[
NSMutableArray
arrayWithArray
:[[
KWMShopCartData
alloc
]
getALLItems
]];
}
if
(
_shopCartList
.
count
==
0
)
{
if
(
_shopCartList
.
count
==
0
)
{
self
.
vBackground
.
hidden
=
NO
;
self
.
vBackground
.
hidden
=
NO
;
}
else
{
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment