Commit b29db6be by lee

Merge branch 'master' of git.oschina.net:kollway-kollway/newcemarose

parents 5835f419 53469421
......@@ -23,6 +23,6 @@
@property (nonatomic) NSString<Optional> *message;
//数据--存放解析后的model。
@property (nonatomic) id<Ignore> data;
@property (nonatomic) NSArray<Ignore> *data;
@end
......@@ -23,8 +23,8 @@
return self;
}
- (id)buildData:(NSDictionary *)jsonDictionary {
id result = nil;
- (NSArray *)buildData:(NSDictionary *)jsonDictionary {
NSArray *result = nil;
if(jsonDictionary){
@try{
NSArray *array = (NSArray *)jsonDictionary;
......
......@@ -24,5 +24,7 @@
@property (nonatomic) CGFloat offsetY;
//切换分类后,如果原来有选中筛选规则的需要清除并重新刷新,以此字段标识
@property (nonatomic) BOOL isNeedReload;
//是否滑到底
@property (nonatomic) BOOL reachedEnd;
@end
......@@ -365,6 +365,10 @@ static NSString *idStr = @"KWMBrandCaramelCell";
if([self isUseCacheProduct:parameters page:tagetPage]){
return;
};
if([collectionId.stringValue isEqualToString:@"171614726"]){
[self getAdminProducts:parameters];
return;
}
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
if (!error){
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:products];
......@@ -394,6 +398,53 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}];
}
-(void)getAdminProducts:(NSDictionary *)parameters{
__weak KWMBrandCaramelVC *weakSelf = self;
NSInteger tagetPage = self.currentPage.integerValue + 1;
//初始化排序及筛选tag
NSString *apiPath = [[NSString alloc] initWithFormat:@"https://%@/admin/product_listings.json",Shopify_SHOP_DOMAIN];
AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
[sessionManager.requestSerializer setValue:@"Basic YWRlMDgzZGU2YWJjYjljYjk0ODY5NDg1ZWUwZGQyNmE6MWYyYzVlM2I4N2YyZGJlMTkwZGEzMzU4NmMyMmY3YzQ=" forHTTPHeaderField:@"Authorization"];
[sessionManager GET:apiPath parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSArray *result = nil;
[weakSelf hideLoading];
if(responseObject){
id jsonDictionary = responseObject[@"product_listings"];
if(jsonDictionary){
@try{
NSArray *array = (NSArray *)jsonDictionary;
if(array){
BUYModelManager *modelManager = [[BUYModelManager alloc]init];
result = [modelManager buy_objectsWithEntityName:[BUYProduct entityName] JSONArray:array];
}
}
@catch (NSException *exception){
NSLog( @"exception Name: %@", exception.name);
NSLog( @"exception Reason: %@", exception.reason );
}
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:result];
if(!result || result.count == 0){
weakSelf.vNoneGoods.hidden = NO;
[weakSelf.dataList removeAllObjects];
[self.tbvBrandCaramel reloadData];
weakSelf.hasNextPage = NO;
}else{
if(tagetPage == 1){
[weakSelf.dataList removeAllObjects];
}
weakSelf.hasNextPage = YES;
[weakSelf appendDataList:result setPage:tagetPage];
weakSelf.vNoneGoods.hidden = YES;
[self.tbvBrandCaramel reloadData];
}
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf hideLoading];
[weakSelf showError:error];
}];
}
#pragma mark -cache
//缓存规则:第一页数据默认先从缓存拿,然后再更新,后面的根据网络判断从缓存拿数据还是从api拿数据
- (BOOL)isUseCacheProduct:(NSDictionary *)cacheKeyDictionary page:(NSUInteger)page{
......@@ -430,4 +481,5 @@ static NSString *idStr = @"KWMBrandCaramelCell";
@end
......@@ -39,12 +39,6 @@
@property (nonatomic) NSArray *allBrands;
//@property(nonatomic) BUYCollectionSort sort;
//@property(nonatomic) NSMutableArray<KWMFilter *> *selectFilters;
//@property(nonatomic) NSString *selectBrands;
@property(nonatomic) NSArray<KWMCategoryModel *>* categories;
@property (nonatomic) KWMCategoryModel *selectedCategory;
......@@ -398,8 +392,8 @@
}
[self.client getProductsPage:cpage inCollection:cmodel.collection_id withTags:tags sortOrder:cmodel.sort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
weakSelf.cvRightProduct.mj_footer.hidden = false;
weakSelf.filterTab.userInteractionEnabled = true;
if (cmodel == self.selectedCategory) {
// [weakSelf.refreshUtil hideLoading];
if ([weakSelf.cvRightProduct.mj_header isRefreshing]) {
[weakSelf.cvRightProduct.mj_header endRefreshing];
}
......@@ -407,21 +401,14 @@
[weakSelf.cvRightProduct.mj_footer endRefreshing];
}
}
if(reachedEnd){
[weakSelf.cvRightProduct.mj_footer endRefreshingWithNoMoreData];
}
weakSelf.filterTab.userInteractionEnabled = true;
if(error){
[weakSelf showError:error];
}
else{
}else{
//保存缓存
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:products];
// weakSelf.refreshUtil.page = page;
cmodel.page = page;
// weakSelf.refreshUtil.hasNextPage = !reachedEnd;
// [weakSelf.refreshUtil appendDataList:products];
cmodel.reachedEnd = reachedEnd;
weakSelf.cvRightProduct.mj_footer.hidden = reachedEnd;
if (cpage == 1) {
[cmodel.products removeAllObjects];
}
......@@ -447,9 +434,9 @@
self.refreshUtil.hasNextPage = YES;
self.refreshUtil.dataList = _selectedCategory.products;
[self.cvRightProduct reloadData];
self.refreshUtil.hasNextPage = _selectedCategory.reachedEnd;
self.cvRightProduct.mj_footer.hidden = _selectedCategory.reachedEnd;
if (_selectedCategory.products.count == 0) {
// [self requestProducts:1];
// [self.refreshUtil reLoadData];
if ([self.cvRightProduct.mj_header isRefreshing]) {
[self requestProducts:1];
}else{
......@@ -460,7 +447,6 @@
}else if([self.cvRightProduct.mj_header isRefreshing]) {
[self.cvRightProduct.mj_header endRefreshing];
}
// [self.cvRightProduct reloadData];
}
#pragma mark -cache
......@@ -476,6 +462,8 @@
[self.cvRightProduct.mj_footer endRefreshing];
}
cmodel.page = page;
cmodel.reachedEnd = NO;
self.cvRightProduct.mj_footer.hidden = NO;
if (page == 1) {
[cmodel.products removeAllObjects];
}
......
......@@ -216,16 +216,13 @@
if (result!= nil && result.count > 0) {
[self.dataList addObjectsFromArray:result];
}else{
[self removeFooterView];
}
if ([self hasNextPage]) {
tableView.mj_footer.hidden = NO;
[tableView.mj_footer resetNoMoreData];
}else{
tableView.mj_footer.hidden = NO;
// tableView.mj_footer.hidden = YES;
tableView.mj_footer.hidden = YES;
[tableView.mj_footer endRefreshingWithNoMoreData];
}
[tableView reloadData];
......
......@@ -231,19 +231,13 @@
}
return;
}
weakSelf.hasNextPage = result.data && result.data.count > 0;
if (result.data) {
NSMutableArray *showOrders = [NSMutableArray arrayWithArray:result.data];
BUYOrder *paidOrder = [self getPaidOrder];
if(paidOrder && targetPage ==1){
[showOrders insertObject:paidOrder atIndex:0];
}
// if(showOrders.count <= 50){
// weakSelf.hasNextPage = false;
// weakSelf.tbvOrder.mj_footer.hidden = YES;
// }else{
// weakSelf.hasNextPage = true;
// weakSelf.tbvOrder.mj_footer.hidden = NO;
// }
if(targetPage == 1){
[weakSelf.dataList removeAllObjects];
[self.expandOrderId removeAllObjects];
......
......@@ -234,6 +234,7 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}
_vSearchFB.lbGoodsNum.hidden = NO;
} failure:^(NSURLSessionDataTask *task, NSError *error) {
[weakSelf hideLoading];
_vSearchFB.lbGoodsNum.hidden = NO;
[weakSelf showError:error];
NSLog(@"error = %@",error);
......
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