|
|
@@ -39,13 +39,22 @@
|
|
|
#define CELL_MARGIN 0
|
|
|
#define LABEL_MARGIN 5
|
|
|
|
|
|
+
|
|
|
@interface CategoryViewController ()
|
|
|
|
|
|
@property (nonatomic,assign) BOOL addAll;
|
|
|
+@property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@implementation CategoryViewController
|
|
|
+- (NSOperationQueue *)dataOperationQueue {
|
|
|
+ if (!_dataOperationQueue) {
|
|
|
+ _dataOperationQueue = [[NSOperationQueue alloc] init];
|
|
|
+ _dataOperationQueue.maxConcurrentOperationCount = 1;
|
|
|
+ }
|
|
|
+ return _dataOperationQueue;
|
|
|
+}
|
|
|
-(void) logout
|
|
|
{
|
|
|
self.offset = 0;
|
|
|
@@ -918,8 +927,11 @@
|
|
|
});
|
|
|
}
|
|
|
#pragma mark get data
|
|
|
--(void) loadMore
|
|
|
+-(void)operation_loadMore
|
|
|
{
|
|
|
+ if (self.dataOperationQueue.operationCount > 1) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
if(self.loadall)
|
|
|
{
|
|
|
@@ -943,6 +955,10 @@
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
[self.mum stopAnimating];
|
|
|
+ self.isrefreshing=false;
|
|
|
+ if (self.dataOperationQueue.operationCount > 1) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
|
|
|
NSDictionary* more_items=[category_more objectForKey:@"items"];
|
|
|
if([[category_more valueForKey:@"result"] intValue]==2)
|
|
|
@@ -983,90 +999,126 @@
|
|
|
{
|
|
|
[RAUtils message_alert:[category_more valueForKey:@"err_msg"] title:@"Loading Category" controller:self] ;
|
|
|
}
|
|
|
- self.isrefreshing=false;
|
|
|
+// self.isrefreshing=false;
|
|
|
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
--(void) reload
|
|
|
-{
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- if(self.isrefreshing)
|
|
|
- return;
|
|
|
- self.showalert=true;
|
|
|
- self.isrefreshing=true;
|
|
|
-
|
|
|
- self.loadall = false;
|
|
|
- // UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
|
|
|
-
|
|
|
-
|
|
|
- // UICollectionViewFlowLayout *flowLayout =[self.collectionview collectionViewLayout];
|
|
|
-
|
|
|
- // layout.scrollDirection= UICollectionViewScrollDirectionVertical;
|
|
|
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
|
|
|
-
|
|
|
- [reF endRefreshing];
|
|
|
-
|
|
|
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
|
|
|
- //
|
|
|
- //
|
|
|
-
|
|
|
- self.mum.hidden = false;
|
|
|
- [self.mum startAnimating];
|
|
|
- self.mum.center = self.view.center;
|
|
|
-
|
|
|
- self.label_net_err.hidden=true;
|
|
|
+
|
|
|
+- (void)loadMore {
|
|
|
+ __weak typeof(self) weakself = self;
|
|
|
+ NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
|
|
|
|
|
|
- self.collectionview.hidden=true;
|
|
|
+ if (weakself) {
|
|
|
+ __strong typeof(weakself) strongself = weakself;
|
|
|
+ [strongself operation_loadMore];
|
|
|
+ }
|
|
|
|
|
|
- // self.collectionview.userInteractionEnabled = false;
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.dataOperationQueue addOperation:operation];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)operation_reload {
|
|
|
+ {
|
|
|
+ if (self.dataOperationQueue.operationCount > 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if(self.isrefreshing)
|
|
|
+ return;
|
|
|
+ self.showalert=true;
|
|
|
+ self.isrefreshing=true;
|
|
|
|
|
|
- NSDictionary* category_data=[iSalesNetwork Category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:0 limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip];
|
|
|
+ self.loadall = false;
|
|
|
+ // UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
- [self.mum stopAnimating];
|
|
|
+
|
|
|
+ // UICollectionViewFlowLayout *flowLayout =[self.collectionview collectionViewLayout];
|
|
|
+
|
|
|
+ // layout.scrollDirection= UICollectionViewScrollDirectionVertical;
|
|
|
+ UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
|
|
|
+
|
|
|
+ [reF endRefreshing];
|
|
|
+
|
|
|
+ reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
|
|
|
+ //
|
|
|
+ //
|
|
|
+
|
|
|
+ self.mum.hidden = false;
|
|
|
+ [self.mum startAnimating];
|
|
|
+ self.mum.center = self.view.center;
|
|
|
+
|
|
|
+ self.label_net_err.hidden=true;
|
|
|
+
|
|
|
+ self.collectionview.hidden=true;
|
|
|
+
|
|
|
+ // self.collectionview.userInteractionEnabled = false;
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
+ NSDictionary* category_data=[iSalesNetwork Category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:0 limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip];
|
|
|
|
|
|
- // self.collectionview.userInteractionEnabled = true;
|
|
|
- self.category_data = [category_data mutableCopy];
|
|
|
- [self.collectionview reloadData];
|
|
|
- if([[category_data valueForKey:@"result"] intValue]==2)
|
|
|
- {
|
|
|
-
|
|
|
- self.collectionview.hidden=false;
|
|
|
- NSDictionary * item_json = [self.category_data objectForKey:@"items"];
|
|
|
- self.offset =[[item_json valueForKey:@"count"] intValue];
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
- int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
|
|
|
+ [self.mum stopAnimating];
|
|
|
+ self.isrefreshing=false;
|
|
|
+ if (self.dataOperationQueue.operationCount > 1) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
|
|
|
- if(total<2)
|
|
|
- self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
|
|
|
+ // self.collectionview.userInteractionEnabled = true;
|
|
|
+ self.category_data = [category_data mutableCopy];
|
|
|
+ [self.collectionview reloadData];
|
|
|
+ if([[category_data valueForKey:@"result"] intValue]==2)
|
|
|
+ {
|
|
|
+
|
|
|
+ self.collectionview.hidden=false;
|
|
|
+ NSDictionary * item_json = [self.category_data objectForKey:@"items"];
|
|
|
+ self.offset =[[item_json valueForKey:@"count"] intValue];
|
|
|
+
|
|
|
+ int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
|
|
|
+
|
|
|
+ if(total<2)
|
|
|
+ self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
|
|
|
+ else
|
|
|
+ self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
|
|
|
+
|
|
|
+ }
|
|
|
+ else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
|
|
|
+ {
|
|
|
+ self.collectionview.hidden=true;
|
|
|
+ self.label_net_err.hidden=false;
|
|
|
+ }
|
|
|
else
|
|
|
- self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
|
|
|
+ {
|
|
|
+ [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Loading Category" controller:self] ;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
|
|
|
- {
|
|
|
- self.collectionview.hidden=true;
|
|
|
- self.label_net_err.hidden=false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Loading Category" controller:self] ;
|
|
|
- }
|
|
|
- self.isrefreshing=false;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
});
|
|
|
+
|
|
|
});
|
|
|
+ }
|
|
|
+}
|
|
|
+-(void) reload
|
|
|
+{
|
|
|
+ __weak typeof(self) weakself = self;
|
|
|
+ NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
|
|
|
|
|
|
- });
|
|
|
+ if (weakself) {
|
|
|
+ __strong typeof(weakself) strongself = weakself;
|
|
|
+ [strongself operation_reload];
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.dataOperationQueue addOperation:operation];
|
|
|
}
|
|
|
#pragma mark - CategoryMenuDelegate
|
|
|
-(void)SelectCategory:(NSString *)category
|
|
|
@@ -1309,6 +1361,26 @@
|
|
|
//
|
|
|
// [appDelegate test_onDecodedDataResult:@"371252"];
|
|
|
|
|
|
+ // customer 隐藏add to portfolio
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+ NSMutableArray *items = [self.selectToolbar.items mutableCopy];
|
|
|
+ if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
|
|
|
+
|
|
|
+ if ([items containsObject:self.addPortfolioBtn]) {
|
|
|
+
|
|
|
+ [items removeObject:self.addPortfolioBtn];
|
|
|
+ self.selectToolbar.items = items;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (![items containsObject:self.addPortfolioBtn]) {
|
|
|
+
|
|
|
+ [items insertObject:self.addPortfolioBtn atIndex:4];
|
|
|
+ self.selectToolbar.items = items;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- (void)viewDidLoad
|
|
|
@@ -1559,50 +1631,55 @@
|
|
|
cell.nameLabel.text = description;
|
|
|
cell.modelNoLabel.text=name;
|
|
|
|
|
|
- cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
|
|
|
+
|
|
|
|
|
|
// cell.cellDescription.text = description;
|
|
|
// cell.oldPrice.text = old_price;
|
|
|
// cell.Price.text = price;
|
|
|
|
|
|
NSString* file_name=[img_url lastPathComponent];
|
|
|
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
|
|
|
- if(img_data!=nil)
|
|
|
- {
|
|
|
-
|
|
|
- UIImage * img =[UIImage imageWithData:img_data];
|
|
|
- cell.cellImageView.image = img;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+
|
|
|
+ if (![cell.imageName isEqualToString:img_url]) {
|
|
|
+ cell.imageName = img_url;
|
|
|
+ cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
|
|
|
+ NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
|
|
|
+ if(img_data!=nil)
|
|
|
+ {
|
|
|
|
|
|
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
|
|
|
+ UIImage * img =[UIImage imageWithData:img_data];
|
|
|
+ cell.cellImageView.image = img;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
-
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
+ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
|
|
|
|
|
|
- if(downloadimg_data!=nil)
|
|
|
- {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
|
|
|
- UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
- cell.cellImageView.image = img;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
|
|
|
- // UIImage * img=[UIImage imageNamed:@"notfound_s"];
|
|
|
- cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
|
|
|
- }
|
|
|
-
|
|
|
+ if(downloadimg_data!=nil)
|
|
|
+ {
|
|
|
+
|
|
|
+ [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
+
|
|
|
+ UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
+ cell.cellImageView.image = img;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ // UIImage * img=[UIImage imageNamed:@"notfound_s"];
|
|
|
+ cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
cell.layer.borderColor = UIColorFromRGB(color).CGColor;
|
|
|
@@ -1659,46 +1736,50 @@
|
|
|
|
|
|
cell.nameLabel.text = description;
|
|
|
cell.modelNoLabel.text=name;
|
|
|
- cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
|
|
|
+
|
|
|
|
|
|
// cell.cellDescription.text = description;
|
|
|
// cell.oldPrice.text = old_price;
|
|
|
// cell.Price.text = price;
|
|
|
|
|
|
NSString* file_name=[img_url lastPathComponent];
|
|
|
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
|
|
|
- if(img_data!=nil)
|
|
|
- {
|
|
|
-
|
|
|
- UIImage * img =[UIImage imageWithData:img_data];
|
|
|
- cell.cellImageView.image = img;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+ if (![cell.imageName isEqualToString:img_url]) {
|
|
|
+ cell.imageName = img_url;
|
|
|
+ cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
|
|
|
+ NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
|
|
|
+ if(img_data!=nil)
|
|
|
+ {
|
|
|
|
|
|
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
|
|
|
+ UIImage * img =[UIImage imageWithData:img_data];
|
|
|
+ cell.cellImageView.image = img;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
+ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
|
|
|
|
|
|
-
|
|
|
- if(downloadimg_data!=nil)
|
|
|
- {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
|
|
|
- UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
- cell.cellImageView.image = img;
|
|
|
- }
|
|
|
- else
|
|
|
- cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
|
|
|
-
|
|
|
+
|
|
|
+ if(downloadimg_data!=nil)
|
|
|
+ {
|
|
|
+
|
|
|
+ [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
+
|
|
|
+ UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
+ cell.cellImageView.image = img;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
|
|
|
+
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
cell.layer.borderColor = UIColorFromRGB(color).CGColor;
|
|
|
cell.layer.borderWidth = 0.5;
|
|
|
@@ -1756,46 +1837,50 @@
|
|
|
|
|
|
cell.nameLabel.text = description;
|
|
|
cell.modelNoLabel.text=name;
|
|
|
- cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
|
|
|
+
|
|
|
|
|
|
// cell.cellDescription.text = description;
|
|
|
// cell.oldPrice.text = old_price;
|
|
|
// cell.Price.text = price;
|
|
|
|
|
|
NSString* file_name=[img_url lastPathComponent];
|
|
|
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
|
|
|
- if(img_data!=nil)
|
|
|
- {
|
|
|
-
|
|
|
- UIImage * img =[UIImage imageWithData:img_data];
|
|
|
- cell.cellImageView.image = img;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
+ if (![cell.imageName isEqualToString:img_url]) {
|
|
|
+ cell.imageName = img_url;
|
|
|
+ cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
|
|
|
+ NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
|
|
|
+ if(img_data!=nil)
|
|
|
+ {
|
|
|
|
|
|
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
|
|
|
+ UIImage * img =[UIImage imageWithData:img_data];
|
|
|
+ cell.cellImageView.image = img;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
+ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
|
|
|
|
|
|
-
|
|
|
- if(downloadimg_data!=nil)
|
|
|
- {
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
|
|
|
- UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
- cell.cellImageView.image = img;
|
|
|
- }
|
|
|
- else
|
|
|
- cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
|
|
|
-
|
|
|
+
|
|
|
+ if(downloadimg_data!=nil)
|
|
|
+ {
|
|
|
+
|
|
|
+ [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
|
|
|
+
|
|
|
+ UIImage * img =[UIImage imageWithData:downloadimg_data];
|
|
|
+ cell.cellImageView.image = img;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
|
|
|
+
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
cell.layer.borderColor = UIColorFromRGB(color).CGColor;
|
|
|
cell.layer.borderWidth = 0.5;
|