SearchViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. //
  2. // SearchViewController.m
  3. // iShop
  4. //
  5. // Created by Rui Zhang on 1/24/24.
  6. //
  7. #import "SearchViewController.h"
  8. #import "RAUtils.h"
  9. #import "RANetwork.h"
  10. #import "CatalogCellSmall.h"
  11. #import "const.h"
  12. #import "FileCache.h"
  13. #import "CatalogModelDetailViewController.h"
  14. #define PAGE_ITEM 30
  15. @interface SearchViewController ()
  16. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  17. @end
  18. @implementation SearchViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.searchBar.backgroundImage = [UIImage new];
  22. // Do any additional setup after loading the view.
  23. }
  24. /*
  25. #pragma mark - Navigation
  26. // In a storyboard-based application, you will often want to do a little preparation before navigation
  27. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  28. // Get the new view controller using [segue destinationViewController].
  29. // Pass the selected object to the new view controller.
  30. }
  31. */
  32. - (NSOperationQueue *)dataOperationQueue {
  33. if (!_dataOperationQueue) {
  34. _dataOperationQueue = [[NSOperationQueue alloc] init];
  35. _dataOperationQueue.maxConcurrentOperationCount = 1;
  36. }
  37. return _dataOperationQueue;
  38. }
  39. -(void) operation_loadMore
  40. {
  41. if (self.dataOperationQueue.operationCount > 1) {
  42. return;
  43. }
  44. dispatch_async(dispatch_get_main_queue(), ^{
  45. if(self.loadall)
  46. {
  47. if(self.showalert)
  48. {
  49. self.showalert=false;
  50. [RAUtils message_box:@"Loading items" message:@"All loaded" completion:nil];
  51. }
  52. return;
  53. }
  54. self.mum.hidden = false;
  55. [self.mum startAnimating];
  56. self.mum.center = self.view.center;
  57. self.isrefreshing=true;
  58. [RANetwork request_search:self.offset limit:PAGE_ITEM keywords:self.keywords matchfull:self.loadmore_matchfull completionHandler:^(NSMutableDictionary *result) {
  59. NSMutableDictionary* category_more=result;
  60. [self.mum stopAnimating];
  61. self.isrefreshing=false;
  62. if (self.dataOperationQueue.operationCount > 1) {
  63. return;
  64. }
  65. NSDictionary* more_items=[category_more objectForKey:@"items"];
  66. if([[category_more valueForKey:@"result"] intValue]==2)
  67. {
  68. // self.category_data = category_data;
  69. NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
  70. int count =[[more_items valueForKey:@"count"] intValue];
  71. for(int i=0;i<count;i++)
  72. {
  73. NSDictionary * item_json = [more_items objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  74. [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
  75. }
  76. long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
  77. [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
  78. [self.category_data setObject:items_json forKey:@"items"];
  79. self.offset+=count;
  80. if(count<PAGE_ITEM)
  81. {
  82. self.loadall=true;
  83. }
  84. // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  85. // DebugLog(@"%@",self.category_data);
  86. [self.collectionview reloadData];
  87. }
  88. else
  89. {
  90. [RAUtils message_box:@"Search" message:[category_more valueForKey:@"err_msg"] completion:nil];
  91. }
  92. self.isrefreshing=false;
  93. }];
  94. return;
  95. });
  96. }
  97. -(void) loadMore {
  98. __weak typeof(self) weakself = self;
  99. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  100. if (weakself) {
  101. __strong typeof(weakself) strongself = weakself;
  102. [strongself operation_loadMore];
  103. }
  104. }];
  105. [self.dataOperationQueue addOperation:operation];
  106. }
  107. -(void) operation_reload
  108. {
  109. if (self.dataOperationQueue.operationCount > 1) {
  110. return;
  111. }
  112. dispatch_async(dispatch_get_main_queue(), ^{
  113. if(self.isrefreshing)
  114. return;
  115. self.showalert=true;
  116. self.isrefreshing=true;
  117. self.loadall = false;
  118. UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
  119. [reF endRefreshing];
  120. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  121. self.label_net_err.hidden=true;
  122. self.collectionview.hidden=true;
  123. self.mum.center = self.view.center;
  124. self.mum.hidden = false;
  125. [self.mum startAnimating];
  126. self.loadmore_matchfull = false;//self.switch_matchfull.isOn;
  127. [RANetwork request_search:0 limit:PAGE_ITEM keywords:self.keywords
  128. matchfull:self.loadmore_matchfull completionHandler:^(NSMutableDictionary *result) {
  129. NSMutableDictionary* category_data=result;
  130. [self.mum stopAnimating];
  131. self.isrefreshing=false;
  132. if (self.dataOperationQueue.operationCount > 1) {
  133. return;
  134. }
  135. self.category_data = [category_data mutableCopy];
  136. [self.collectionview reloadData];
  137. if([[category_data valueForKey:@"result"] intValue]==2)
  138. {
  139. self.collectionview.hidden=false;
  140. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  141. self.offset =[[item_json valueForKey:@"count"] intValue];
  142. int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
  143. }
  144. else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  145. {
  146. self.collectionview.hidden=true;
  147. self.label_net_err.hidden=false;
  148. }
  149. else
  150. {
  151. [RAUtils message_box:@"Search" message:[category_data valueForKey:@"err_msg"] completion:nil];
  152. }
  153. self.isrefreshing=false;
  154. }];
  155. return;
  156. });
  157. }
  158. -(void) reload {
  159. __weak typeof(self) weakself = self;
  160. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  161. if (weakself) {
  162. __strong typeof(weakself) strongself = weakself;
  163. [strongself operation_reload];
  164. }
  165. }];
  166. [self.dataOperationQueue addOperation:operation];
  167. }
  168. - (IBAction)onChangeDisplay:(UIButton *)sender {
  169. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  170. flowLayout.scrollDirection= UICollectionViewScrollDirectionVertical;
  171. if(sender.tag==2&&self.categoryViewType != CATEGORY_VIEWTYPE_SMALL)
  172. {
  173. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  174. // [self.collectionview.collectionViewLayout invalidateLayout];
  175. // DebugLog(@"frame %f",self.collectionview.frame.size.height);
  176. // DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
  177. // DebugLog(@"content %f",self.collectionview.contentSize.height);
  178. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  179. [self.collectionview reloadData];
  180. [self.btnDisplay setImage:[UIImage imageNamed:@"24_layout_list"] forState:UIControlStateNormal];
  181. sender.tag=4;
  182. // CGPoint offset = self.collectionview.contentOffset;
  183. // offset.y=pos*self.collectionview.contentSize.height;
  184. // self.collectionview.contentOffset=offset;
  185. }
  186. else if(sender.tag==4&&self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
  187. {
  188. self.categoryViewType = CATEGORY_VIEWTYPE_LIST;
  189. // DebugLog(@"frame %f",self.collectionview.frame.size.height);
  190. // DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
  191. // DebugLog(@"content %f",self.collectionview.contentSize.height);
  192. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  193. // [self.collectionview reloadData];
  194. // [self.collectionview.collectionViewLayout invalidateLayout];
  195. [self.collectionview reloadData];
  196. [self.btnDisplay setImage:[UIImage imageNamed:@"24_layout_grid"] forState:UIControlStateNormal];
  197. sender.tag=2;
  198. // CGPoint offset = self.collectionview.contentOffset;
  199. // offset.y=pos*self.collectionview.contentSize.height;
  200. // self.collectionview.contentOffset=offset;
  201. //
  202. // self.collectionview move
  203. }
  204. [self showCategory];
  205. // [self showCategory];
  206. }
  207. -(void) showCategory
  208. {
  209. if(self.showDetail==false)
  210. return;
  211. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  212. // int width=175;
  213. // // int height;
  214. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  215. // {
  216. // width = 370;
  217. // // height = 400;
  218. // }
  219. // else
  220. // {
  221. // // height = 300;
  222. // width = 175;
  223. // }
  224. //
  225. CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width
  226. , self.view.bounds.size.height-48);
  227. [UIView animateWithDuration:0.5 animations:^{ self.collectionview.frame=frame;
  228. }];
  229. self.collectionview.autoresizingMask = self.collectionview.autoresizingMask | UIViewAutoresizingFlexibleWidth;
  230. self.showDetail = false;
  231. // self.cagegoryLabel.hidden = false;
  232. }
  233. #pragma mark - searchBar delegate;
  234. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  235. {
  236. self.keywords=searchBar.text;
  237. self.offset = 0;
  238. // [self.content_data removeAllObjects];
  239. [self reload];
  240. DebugLog(@"search");
  241. [self.view endEditing:true];
  242. // [self.searchBar.searchTextField endEditing:true];
  243. }
  244. - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
  245. {
  246. self.maskView.hidden =false;
  247. }
  248. - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
  249. {
  250. self.maskView.hidden =true;
  251. }
  252. // - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  253. // {
  254. //
  255. // if(searchText.length == 0)
  256. // [self.view endEditing:true];
  257. //
  258. // }
  259. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  260. [[self view] endEditing:YES];
  261. }
  262. //- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  263. //{
  264. //
  265. //}
  266. #pragma mark -- UICollectionViewDataSource
  267. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  268. {
  269. // 每个Section的item个数
  270. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  271. int count =[[item_json valueForKey:@"count"] intValue];
  272. return count;
  273. }
  274. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  275. {
  276. return 1;
  277. }
  278. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  279. {
  280. // NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
  281. //
  282. // if(value==nil)
  283. // value=@"";
  284. // unsigned long color = strtoul([value UTF8String],0,16);
  285. if(self.categoryViewType == CATEGORY_VIEWTYPE_SMALL)
  286. {
  287. static NSString * CellIdentifier = @"CatalogCellSmall";
  288. CatalogCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  289. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  290. NSString* description =[item_json valueForKey:@"description"];
  291. NSString* name =[item_json valueForKey:@"fash_name"];
  292. // bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  293. // bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  294. bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
  295. // BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
  296. // cell.mark_moreColor.hidden = !more_color;
  297. // if(wish_exist)
  298. // cell.mark_wish.hidden=false;
  299. // else
  300. // cell.mark_wish.hidden=true;
  301. // if(cart_exists)
  302. // cell.mark_order.hidden=false;
  303. // else
  304. // cell.mark_order.hidden=true;
  305. // if(closeout)
  306. // cell.mark_closeout.hidden=false;
  307. // else
  308. // cell.mark_closeout.hidden=true;
  309. // NSString* old_price =[item_json valueForKey:@"old_price"];
  310. // NSString* price =[item_json valueForKey:@"price"];
  311. if(closeout)
  312. cell.ic_closeout.hidden=false;
  313. else
  314. cell.ic_closeout.hidden=true;
  315. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  316. if(!checked)
  317. {
  318. // cell.checkImageView.hidden = true;
  319. [cell setBackgroundColor:[UIColor whiteColor]/* UIColorFromRGB(0x996633)*/];
  320. }
  321. else
  322. {
  323. // cell.checkImageView.hidden = false;
  324. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  325. }
  326. cell.nameLabel.text = description;
  327. cell.modelNoLabel.text=name;
  328. // cell.cellDescription.text = description;
  329. // cell.oldPrice.text = old_price;
  330. // cell.Price.text = price;
  331. // cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  332. cell.layer.borderWidth = 0.4;
  333. cell.layer.cornerRadius=15;
  334. cell.layer.masksToBounds=true;
  335. #ifdef BUILD_UWAVER
  336. cell.mark_wish.hidden = YES;
  337. cell.mark_order.hidden = YES;
  338. cell.mark_closeout.hidden = YES;
  339. cell.mark_moreColor.hidden = YES;
  340. #endif
  341. return cell;
  342. }
  343. else
  344. {
  345. static NSString * CellIdentifier = @"CatalogCellList";
  346. CatalogCellSmall * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  347. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  348. NSString* description =[item_json valueForKey:@"description"];
  349. NSString* name =[item_json valueForKey:@"fash_name"];
  350. // bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  351. // bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  352. bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
  353. // BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
  354. if(closeout)
  355. cell.ic_closeout.hidden=false;
  356. else
  357. cell.ic_closeout.hidden=true;
  358. // NSString* old_price =[item_json valueForKey:@"old_price"];
  359. // NSString* price =[item_json valueForKey:@"price"];
  360. // bool checked =[[item_json valueForKey:@"checked"] boolValue];
  361. cell.nameLabel.text = description;
  362. cell.modelNoLabel.text=name;
  363. // cell.cellDescription.text = description;
  364. // cell.oldPrice.text = old_price;
  365. // cell.Price.text = price;
  366. // cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  367. cell.layer.borderWidth = 0.2;
  368. //cell.layer.cornerRadius=15;
  369. cell.layer.masksToBounds=true;
  370. #ifdef BUILD_UWAVER
  371. cell.mark_wish.hidden = YES;
  372. cell.mark_order.hidden = YES;
  373. cell.mark_closeout.hidden = YES;
  374. cell.mark_moreColor.hidden = YES;
  375. #endif
  376. return cell;
  377. }
  378. }
  379. - (void)collectionCell:(CatalogCellSmall *)cell setImageForIndexPath:(NSIndexPath *)indexPath {
  380. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  381. NSString* img_url =[item_json valueForKey:@"img"];
  382. NSString *loading = @"loading_l";
  383. NSString *notFound = @"notfound_l";
  384. if (self.categoryViewType == CATEGORY_VIEWTYPE_LARGE) {
  385. loading = @"loading_l";
  386. notFound = @"notfound_l";
  387. img_url =[item_json valueForKey:@"img_big"]; // large 大图
  388. } else if (self.categoryViewType == CATEGORY_VIEWTYPE_SMALL) {
  389. loading = @"loading_s";
  390. notFound = @"notfound_s";
  391. img_url =[item_json valueForKey:@"img"]; // large 大图
  392. }
  393. NSString* file_name=[img_url lastPathComponent];
  394. if (![cell.imageName isEqualToString:img_url]) {
  395. cell.imageName = img_url;
  396. cell.cellImageView.image = [UIImage imageNamed:loading];
  397. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  398. if(img_data!=nil)
  399. {
  400. UIImage * img =[UIImage imageWithData:img_data];
  401. cell.cellImageView.image = img;
  402. }
  403. else
  404. {
  405. DebugLog(@"load image");
  406. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  407. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  408. dispatch_async(dispatch_get_main_queue(), ^{
  409. if(downloadimg_data!=nil)
  410. {
  411. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  412. UIImage * img =[UIImage imageWithData:downloadimg_data];
  413. cell.cellImageView.image = img;
  414. }
  415. else
  416. cell.cellImageView.image = [UIImage imageNamed:notFound];
  417. });
  418. });
  419. }
  420. }
  421. }
  422. - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
  423. CatalogCellSmall * son_cell = (CatalogCellSmall *)cell;
  424. son_cell.imageName = nil;
  425. [self collectionCell:son_cell setImageForIndexPath:indexPath];
  426. }
  427. - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
  428. CatalogCellSmall * son_cell = (CatalogCellSmall *)cell;
  429. NSString *loading = @"loading_l";
  430. if (self.categoryViewType == CATEGORY_VIEWTYPE_LARGE) {
  431. loading = @"loading_l";
  432. } else if (self.categoryViewType == CATEGORY_VIEWTYPE_SMALL) {
  433. loading = @"loading_s";
  434. }
  435. son_cell.cellImageView.image = [UIImage imageNamed:loading];
  436. }
  437. #pragma mark --UICollectionViewDelegateFlowLayout
  438. ////定义每个UICollectionView 的大小
  439. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  440. //{
  441. // return CGSizeMake(96, 100);
  442. //}
  443. //定义每个UICollectionView 的 margin
  444. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  445. {
  446. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  447. return CGSizeMake(self.view.frame.size.width, 80);
  448. return CGSizeMake((self.view.frame.size.width-30)/2, 251);
  449. }
  450. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  451. {
  452. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  453. return 0;
  454. return 10;
  455. }
  456. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  457. {
  458. if(self.showDetail)
  459. return UIEdgeInsetsMake(10, 5, 10, 5);
  460. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  461. return UIEdgeInsetsMake(10, 10, 10, 10);
  462. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  463. return UIEdgeInsetsMake(10, 0, 10, 0);
  464. return UIEdgeInsetsMake(10, 10, 10, 10);
  465. return UIEdgeInsetsMake(10, 10, 10, 10);
  466. }
  467. #pragma mark --UICollectionViewDelegate
  468. -(void) showDetailat:(NSString*) item_id category_id:(NSString*) category_id name:(NSString *)name index:(long)index
  469. {
  470. CatalogModelDetailViewController* dvc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CatalogModelDetailViewController" ];
  471. dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
  472. {
  473. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  474. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",index]] mutableCopy];
  475. if(add_cart)
  476. item[@"cart_exists"]=@"true";
  477. if(add_wish)
  478. item[@"wish_exists"]=@"true";
  479. items[[NSString stringWithFormat:@"item_%ld",index]] = item;
  480. self.category_data[@"items"]=items;
  481. [self.collectionview reloadData];
  482. };
  483. dvc.product_id = item_id;
  484. dvc.category_id=category_id;
  485. dvc.ispush = true;
  486. dvc.model_name = name;
  487. [dvc reload];
  488. [self.navigationController pushViewController:dvc animated:true];
  489. return;
  490. }
  491. //UICollectionView被选中时调用的方法
  492. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  493. {
  494. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  495. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  496. // if(self.isSelectionMode)
  497. // {
  498. // bool checked =[[item valueForKey:@"checked"] boolValue];
  499. //
  500. // CategoryCellNPD *currentSelecteCell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  501. //
  502. //
  503. // if(checked)
  504. // {
  505. // self.select_count--;
  506. // if(self.select_count==0)
  507. // {
  508. // // self.addWishBtn.enabled = false;
  509. // // self.addCartBtn.enabled = false;
  510. // // self.addPortfolioBtn.enabled=false;
  511. // }
  512. // [item setValue:@"false" forKey:@"checked"];
  513. //
  514. // currentSelecteCell.checkImageView.hidden = true;
  515. // if(self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
  516. // [currentSelecteCell setBackgroundColor: [UIColor whiteColor]];
  517. // else
  518. // [currentSelecteCell setBackgroundColor: [UIColor whiteColor]];
  519. // }
  520. // else
  521. // {
  522. // self.select_count++;
  523. // // self.addWishBtn.enabled = true;
  524. // // self.addCartBtn.enabled = true;
  525. // // self.addPortfolioBtn.enabled=true;
  526. // [item setValue:@"true" forKey:@"checked"];
  527. // currentSelecteCell.checkImageView.hidden = false;
  528. // [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x009966)];
  529. // }
  530. // [items setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  531. // [self.category_data setObject:items forKey:@"items"];
  532. //
  533. //
  534. // }
  535. // else
  536. {
  537. NSString* detail_id = [NSString stringWithFormat:@"%@",[item valueForKey:@"product_id"]];
  538. [self showDetailat:detail_id category_id:nil name:[item objectForKey:@"fash_name"] index:indexPath.row];
  539. }
  540. }
  541. @end