SearchViewController.m 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909
  1. //
  2. // SearchViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 9/1/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "SearchViewController.h"
  9. #import "const.h"
  10. #import "iSalesNetwork.h"
  11. #import "CategoryCellNPD.h"
  12. #import "DetailViewController.h"
  13. #import "ContactListViewController.h"
  14. #import "MainViewController.h"
  15. #define DEF_CELL_HEIGHT 44
  16. #define DEF_TABLE_HEIGHT 44
  17. #define LINE_WIDTH 0
  18. #define CELL_MARGIN 0
  19. #define LABEL_MARGIN 5
  20. @interface SearchViewController ()
  21. @end
  22. @implementation SearchViewController
  23. -(void) reload_container_getdata:(bool)update_data
  24. {
  25. if(self.disable_refresh)
  26. return;
  27. [super reload_container_getdata:update_data];
  28. if(update_data)
  29. {
  30. self.offset = 0;
  31. // [self.content_data removeAllObjects];
  32. [self reload];
  33. }
  34. else
  35. {
  36. [self.collectionview reloadData];
  37. }
  38. return;
  39. // if(!self.showDetail)
  40. // return;
  41. // NSArray* a= self.childViewControllers;
  42. //
  43. // for (int i=0;i<a.count;i++)
  44. // {
  45. // if([a[i] isKindOfClass:[DetailViewController class]])
  46. // {
  47. // DetailViewController *detailvc=a[i];
  48. // [detailvc reload];
  49. // }
  50. // }
  51. }
  52. -(void)begin_select
  53. {
  54. self.addCartBtn.enabled=false;
  55. self.addWishBtn.enabled=false;
  56. self.addPortfolioBtn.enabled=false;
  57. self.selectToolbar.hidden=false;
  58. // self.collectionview.allowsMultipleSelection = YES;
  59. self.isSelectionMode=true;
  60. self.select_count=0;
  61. }
  62. -(void)end_select:(int) type
  63. {
  64. self.select_count=0;
  65. self.selectToolbar.hidden=true;
  66. // self.collectionview.allowsMultipleSelection = NO;
  67. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  68. int count = [[items valueForKey:@"count"] intValue];
  69. for(int i=0;i<count;i++)
  70. {
  71. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  72. bool check = [[item valueForKey:@"checked"] boolValue];
  73. if(check)
  74. {
  75. switch (type) {
  76. case 1:
  77. item[@"wish_exists"]=@"true";
  78. break;
  79. case 2:
  80. item[@"cart_exists"]=@"true";
  81. break;
  82. default:
  83. break;
  84. }
  85. }
  86. [item setValue:@"false" forKey:@"checked"];
  87. [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
  88. }
  89. [self.category_data setObject:items forKey:@"items"];
  90. self.selectallBtn.tag = 0;
  91. [self.selectallBtn setTitle:@"Select all"];
  92. self.isSelectionMode=false;
  93. if(self.disable_refresh)
  94. {
  95. self.disable_refresh = false;
  96. [self reload_container_getdata:true];
  97. }
  98. else
  99. [self.collectionview reloadData];
  100. }
  101. - (IBAction)onSelectClick:(id)sender {
  102. //
  103. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  104. //
  105. // [appDelegate test_onDecodedDataResult:@"108530-HS01"];
  106. // return;
  107. [self begin_select];
  108. }
  109. - (IBAction)onCancelSelectClick:(id)sender {
  110. [self end_select:0];
  111. }
  112. - (void)viewDidLoad {
  113. [super viewDidLoad];
  114. self.mum.hidden = true;
  115. self.selectallBtn.possibleTitles = [NSSet setWithObjects:@"Selece all", @"Deselect all", nil];
  116. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  117. UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
  118. CGSize cellsize = CGSizeMake(175, 250);
  119. layout.itemSize =cellsize;
  120. layout.minimumLineSpacing = 15;
  121. self.collectionview.collectionViewLayout = layout;
  122. //
  123. self.display_type = [[NSMutableDictionary alloc] init];
  124. [self.display_type setValue:@3 forKey:@"count"];
  125. NSMutableDictionary* val_0 = [[NSMutableDictionary alloc] init];
  126. [val_0 setValue:@1 forKey:@"check"];
  127. [val_0 setValue:@"small icon" forKey:@"value"];
  128. [val_0 setValue:@"" forKey:@"img"];
  129. [self.display_type setObject:val_0 forKey:@"val_0"];
  130. NSMutableDictionary* val_1 = [[NSMutableDictionary alloc] init];
  131. [val_1 setValue:@0 forKey:@"check"];
  132. [val_1 setValue:@"large icon" forKey:@"value"];
  133. [val_1 setValue:@"" forKey:@"img"];
  134. [self.display_type setObject:val_1 forKey:@"val_1"];
  135. NSMutableDictionary* val_2 = [[NSMutableDictionary alloc] init];
  136. [val_2 setValue:@2 forKey:@"check"];
  137. [val_2 setValue:@"detail" forKey:@"value"];
  138. [val_2 setValue:@"" forKey:@"img"];
  139. [self.display_type setObject:val_2 forKey:@"val_2"];
  140. // self.collectionview.
  141. // self.cagegoryLabel.text = self.categoryString;
  142. self.showDetail = false;
  143. //添加边框
  144. // CALayer *layer = [self.collectionview layer];
  145. // layer.borderColor = [[UIColor redColor] CGColor];
  146. // layer.borderWidth = 5.0f;
  147. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  148. self.headerView.layer.masksToBounds = false;
  149. //添加四个边阴影
  150. self.headerView.layer.shadowColor = [UIColor grayColor].CGColor;
  151. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  152. self.headerView.layer.shadowOpacity = 0.5;
  153. self.headerView.layer.shadowRadius = 2.0;
  154. //添加两个边阴影
  155. self.collectionview.layer.masksToBounds = false;
  156. self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  157. self.collectionview.layer.shadowColor = [UIColor grayColor].CGColor;
  158. self.collectionview.layer.shadowOffset = CGSizeMake(0, 0);
  159. self.collectionview.layer.shadowOpacity = 0.5;
  160. self.collectionview.layer.shadowRadius = 2.0;
  161. // Do any additional setup after loading the view.
  162. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  163. ref.tag = 200 ;
  164. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  165. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  166. // ref.hidden = true;
  167. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  168. [self.collectionview addSubview:ref];
  169. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  170. self.label_net_err.layer.borderWidth = 2.0;
  171. self.label_net_err.layer.cornerRadius=15;
  172. self.label_net_err.layer.masksToBounds=true;
  173. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  174. // tap.minimumPressDuration = 0.8; //定义按的时间
  175. [self.label_net_err addGestureRecognizer:tap];
  176. self.refresh_type = REFRESH_VIEW;
  177. }
  178. -(void)manually_refresh
  179. {
  180. UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
  181. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  182. [self performSelector:@selector(reload) withObject:nil afterDelay:1];
  183. // DebugLog(@"refresh!!!!!!!!");
  184. }
  185. -(void)viewWillLayoutSubviews
  186. {
  187. // if(self.showDetail==true)
  188. // {
  189. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  190. // int width=175;
  191. // // int height;
  192. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  193. // {
  194. // width = 370;
  195. // // height = 400;
  196. // }
  197. // else
  198. // {
  199. // // height = 300;
  200. // width = 175;
  201. // }
  202. //
  203. //
  204. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  205. //
  206. // self.collectionview.frame=frame;
  207. //
  208. //
  209. //
  210. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  211. // self.detailView.frame = framedetail;
  212. // }
  213. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  214. self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  215. }
  216. - (IBAction)onSelectAllClick:(id)sender {
  217. // int tag =self.selectallBtn.tag;
  218. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  219. int count = [[items valueForKey:@"count"] intValue];
  220. NSString* checked;
  221. if (self.selectallBtn.tag == 0)
  222. {
  223. self.selectallBtn.tag = 1;
  224. [self.selectallBtn setTitle:@"Deselect all"];
  225. if(count>0)
  226. {
  227. self.addWishBtn.enabled = true;
  228. self.addCartBtn.enabled = true;
  229. self.addPortfolioBtn.enabled=true;
  230. }
  231. self.select_count=count;
  232. checked=@"true";
  233. }
  234. else
  235. {
  236. self.selectallBtn.tag = 0;
  237. [self.selectallBtn setTitle:@"Select all"];
  238. self.addWishBtn.enabled = false;
  239. self.addCartBtn.enabled = false;
  240. self.addPortfolioBtn.enabled=false;
  241. checked=@"false";
  242. }
  243. for(int i=0;i<count;i++)
  244. {
  245. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  246. [item setValue:checked forKey:@"checked"];
  247. [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
  248. }
  249. [self.category_data setObject:items forKey:@"items"];
  250. [self.collectionview reloadData];
  251. }
  252. - (IBAction)onChangeDisplay:(UIButton *)sender {
  253. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  254. flowLayout.scrollDirection= UICollectionViewScrollDirectionVertical;
  255. if(sender.tag==2&&self.categoryViewType != CATEGORY_VIEWTYPE_SMALL)
  256. {
  257. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  258. // [self.collectionview.collectionViewLayout invalidateLayout];
  259. NSLog(@"frame %f",self.collectionview.frame.size.height);
  260. NSLog(@"offset %f",self.self.collectionview.contentOffset.y);
  261. NSLog(@"content %f",self.collectionview.contentSize.height);
  262. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  263. [self.collectionview reloadData];
  264. // CGPoint offset = self.collectionview.contentOffset;
  265. // offset.y=pos*self.collectionview.contentSize.height;
  266. // self.collectionview.contentOffset=offset;
  267. }
  268. else if(sender.tag==3&&self.categoryViewType != CATEGORY_VIEWTYPE_LARGE)
  269. {
  270. self.categoryViewType = CATEGORY_VIEWTYPE_LARGE;
  271. NSLog(@"frame %f",self.collectionview.frame.size.height);
  272. NSLog(@"offset %f",self.self.collectionview.contentOffset.y);
  273. NSLog(@"content %f",self.collectionview.contentSize.height);
  274. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  275. // [self.collectionview reloadData];
  276. // [self.collectionview.collectionViewLayout invalidateLayout];
  277. [self.collectionview reloadData];
  278. // CGPoint offset = self.collectionview.contentOffset;
  279. // offset.y=pos*self.collectionview.contentSize.height;
  280. // self.collectionview.contentOffset=offset;
  281. //
  282. // self.collectionview move
  283. }
  284. else if(sender.tag==4&&self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
  285. {
  286. self.categoryViewType = CATEGORY_VIEWTYPE_LIST;
  287. NSLog(@"frame %f",self.collectionview.frame.size.height);
  288. NSLog(@"offset %f",self.self.collectionview.contentOffset.y);
  289. NSLog(@"content %f",self.collectionview.contentSize.height);
  290. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  291. // [self.collectionview reloadData];
  292. // [self.collectionview.collectionViewLayout invalidateLayout];
  293. [self.collectionview reloadData];
  294. // CGPoint offset = self.collectionview.contentOffset;
  295. // offset.y=pos*self.collectionview.contentSize.height;
  296. // self.collectionview.contentOffset=offset;
  297. //
  298. // self.collectionview move
  299. }
  300. // UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
  301. // CGSize cellsize = CGSizeMake(383, 450);
  302. // layout.itemSize =cellsize;
  303. // layout.minimumInteritemSpacing=10;
  304. // layout.minimumLineSpacing = 10;
  305. // self.collectionview.collectionViewLayout = layout;
  306. // [self.collectionview.collectionViewLayout invalidateLayout];
  307. [self showCategory];
  308. // NSMutableDictionary* sort_json = [self.category_data objectForKey:@"sort"];
  309. // EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  310. // enumvc.cadedate = [self.display_type mutableCopy];
  311. // enumvc.single_select =true;
  312. // enumvc.auto_close = true;
  313. // enumvc.title = @"Display";
  314. // enumvc.is_dialog = true;
  315. //
  316. // enumvc.returnValue = ^(NSMutableDictionary* value){
  317. // self.display_type = value;
  318. // for(int i=0;i<[[self.display_type valueForKey:@"count"]intValue];i++)
  319. // {
  320. // NSDictionary * val_json = [self.display_type objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  321. // int check = [[val_json valueForKey:@"check"]intValue];
  322. // if(check)
  323. // {
  324. //
  325. // if(i==0)//small icon;
  326. // { self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  327. //
  328. // UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
  329. // CGSize cellsize = CGSizeMake(175, 250);
  330. // layout.itemSize =cellsize;
  331. // layout.minimumLineSpacing = 15;
  332. // self.collectionview.collectionViewLayout = layout;
  333. // [self.collectionview reloadData];
  334. // [self showCategory];
  335. // break;
  336. // }
  337. // else if(i==1)//large icon
  338. // {
  339. // self.categoryViewType = CATEGORY_VIEWTYPE_LARGE;
  340. // UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
  341. // CGSize cellsize = CGSizeMake(383, 450);
  342. // layout.itemSize =cellsize;
  343. // layout.minimumInteritemSpacing=10;
  344. // layout.minimumLineSpacing = 10;
  345. // self.collectionview.collectionViewLayout = layout;
  346. // [self.collectionview reloadData];
  347. //
  348. // [self showCategory];
  349. // break;
  350. // }
  351. // else
  352. // {
  353. // self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  354. //
  355. // UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
  356. // CGSize cellsize = CGSizeMake(175, 250);
  357. // layout.itemSize =cellsize;
  358. // layout.minimumLineSpacing = 30;
  359. // self.collectionview.collectionViewLayout = layout;
  360. // [self.collectionview reloadData];
  361. // [self showDetailat:0];
  362. //
  363. // // [self showDetail];
  364. // break;
  365. // }
  366. // }
  367. //
  368. // }
  369. // // NSLog(@"点击了第%d个",pageIndex);
  370. // };
  371. //
  372. // enumvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  373. //
  374. // // enumvc.delegate = self;
  375. // [self presentViewController:enumvc animated:YES completion:^{
  376. //
  377. // NSLog(@"login.........");
  378. // // <#code#>
  379. // }];
  380. // [self showCategory];
  381. }
  382. -(void) showCategory
  383. {
  384. if(self.showDetail==false)
  385. return;
  386. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  387. // int width=175;
  388. // // int height;
  389. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  390. // {
  391. // width = 370;
  392. // // height = 400;
  393. // }
  394. // else
  395. // {
  396. // // height = 300;
  397. // width = 175;
  398. // }
  399. //
  400. CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width
  401. , self.view.bounds.size.height-48);
  402. [UIView animateWithDuration:0.5 animations:^{ self.collectionview.frame=frame;
  403. }];
  404. self.collectionview.autoresizingMask = self.collectionview.autoresizingMask | UIViewAutoresizingFlexibleWidth;
  405. self.showDetail = false;
  406. // self.cagegoryLabel.hidden = false;
  407. }
  408. - (void)viewWillAppear:(BOOL)animated
  409. {
  410. [super viewWillAppear:animated];
  411. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  412. }
  413. - (void)didReceiveMemoryWarning {
  414. [super didReceiveMemoryWarning];
  415. // Dispose of any resources that can be recreated.
  416. }
  417. - (IBAction)onAddCartClick:(id)sender {
  418. [RAUtils add_to_cart:self selector:@selector(addtocart)];
  419. return;
  420. UIApplication * app = [UIApplication sharedApplication];
  421. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  422. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  423. if(appDelegate.bLogin==false)
  424. {
  425. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  426. // loginvc.delegate = self;
  427. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  428. loginvc.returnValue = ^(bool blogin){
  429. // UIApplication * app = [UIApplication sharedApplication];
  430. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  431. if(blogin)
  432. {
  433. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  434. {
  435. [main_vc checklogin:false];
  436. if(appDelegate.can_create_order)
  437. {
  438. NSString* msg =@"";
  439. if(appDelegate.contact_id.length>0)
  440. {
  441. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  442. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  443. }
  444. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  445. // alert.
  446. [alert show];
  447. }
  448. else
  449. {
  450. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  451. // alert.
  452. [alert show];
  453. }
  454. }
  455. else
  456. {
  457. [main_vc checklogin:false];
  458. [self addtocart];
  459. }
  460. }
  461. // self.offset = 0;
  462. // [self.content_data removeAllObjects];
  463. // [self loadpage];
  464. //
  465. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  466. };
  467. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  468. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  469. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  470. [self presentViewController:navi animated:YES completion:^{
  471. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  472. NSLog(@"LoginViewController present.........");
  473. // self.btop = false;
  474. // <#code#>
  475. }];
  476. }
  477. else
  478. {
  479. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  480. {
  481. // [main_vc checklogin:false];
  482. if(appDelegate.can_create_order)
  483. {
  484. NSString* msg =@"";
  485. if(appDelegate.contact_id.length>0)
  486. {
  487. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  488. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  489. }
  490. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  491. // alert.
  492. [alert show];
  493. }
  494. else
  495. {
  496. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  497. // alert.
  498. [alert show];
  499. }
  500. }
  501. else
  502. {
  503. if(appDelegate.order_code==nil)
  504. [ self neworder];
  505. else
  506. [self addtocart];
  507. }
  508. }
  509. }
  510. -(void) neworder
  511. {
  512. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  513. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  514. NSDictionary* return_json = [iSalesNetwork new_Order];
  515. dispatch_async(dispatch_get_main_queue(), ^{
  516. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  517. if([[return_json valueForKey:@"result"] intValue]==2)
  518. {
  519. int result=[[return_json valueForKey:@"result"] intValue];
  520. if(result==2)
  521. {
  522. //successed.
  523. NSString* order_code = [return_json valueForKey:@"orderCode"];
  524. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  525. appDelegate.order_code = order_code;
  526. [self addtocart];
  527. // [self ReloadData];
  528. // if(self.shopCartBlock!=nil)
  529. // {
  530. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  531. //
  532. //
  533. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  534. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  535. // iv.image = img;
  536. // // [self.contentView addSubview:iv];
  537. // self.shopCartBlock(iv);
  538. //
  539. // }
  540. }
  541. }
  542. else
  543. {
  544. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  545. }
  546. });
  547. });
  548. }
  549. - (IBAction)onAddPortfolioClick:(id)sender {
  550. UIApplication * app = [UIApplication sharedApplication];
  551. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  552. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  553. if(appDelegate.bLogin==false)
  554. {
  555. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  556. // loginvc.delegate = self;
  557. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  558. loginvc.returnValue = ^(bool blogin){
  559. if(blogin)
  560. {
  561. [main_vc checklogin:false];
  562. [self addtoportfolio];
  563. }
  564. };
  565. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  566. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  567. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  568. [self presentViewController:navi animated:YES completion:^{
  569. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  570. NSLog(@"LoginViewController present.........");
  571. // self.btop = false;
  572. // <#code#>
  573. }];
  574. }
  575. else
  576. {
  577. [self addtoportfolio];
  578. }
  579. }
  580. - (IBAction)onAddWishlistClick:(id)sender {
  581. UIApplication * app = [UIApplication sharedApplication];
  582. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  583. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  584. if(appDelegate.bLogin==false)
  585. {
  586. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  587. // loginvc.delegate = self;
  588. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  589. loginvc.returnValue = ^(bool blogin){
  590. if(blogin)
  591. {
  592. [main_vc checklogin:false];
  593. [self addtowish];
  594. }
  595. };
  596. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  597. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  598. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  599. [self presentViewController:navi animated:YES completion:^{
  600. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  601. NSLog(@"LoginViewController present.........");
  602. // self.btop = false;
  603. // <#code#>
  604. }];
  605. }
  606. else
  607. {
  608. [self addtowish];
  609. }
  610. }
  611. -(void) addtocart
  612. {
  613. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  614. int count = [[items valueForKey:@"count"] intValue];
  615. NSMutableArray* checked = [[NSMutableArray alloc] init];
  616. for(int i=0;i<count;i++)
  617. {
  618. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  619. bool check = [[item valueForKey:@"checked"] boolValue];
  620. if(check)
  621. {
  622. // [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  623. [checked addObject:[item valueForKey:@"fash_name"]];
  624. }
  625. }
  626. if(checked.count==0)
  627. {
  628. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to cart." controller:self] ;
  629. return;
  630. }
  631. NSString * ids = [checked componentsJoinedByString:@","];
  632. self.addCartBtn.enabled = false;
  633. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Cart"];
  634. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  635. NSDictionary* return_json = [iSalesNetwork add_toCart_byName:ids ];
  636. dispatch_async(dispatch_get_main_queue(), ^{
  637. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  638. self.addCartBtn.enabled = true;
  639. if([[return_json valueForKey:@"result"] intValue]==2)
  640. {
  641. // int result=[[return_json valueForKey:@"result"] intValue];
  642. // if(result==2)
  643. // {
  644. // //successed.
  645. // NSString* order_code = [return_json valueForKey:@"order_code"];
  646. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  647. // appDelegate.order_code = order_code;
  648. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  649. // appDelegate.order_code = order_code;
  650. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  651. [RAUtils message_alert:nil title:@" Multiple items added to Cart" controller:self] ;
  652. [self end_select:2];
  653. // }
  654. }
  655. else if([[return_json valueForKey:@"result"] intValue]==8)
  656. {
  657. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  658. // appDelegate.order_code = order_code;
  659. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  660. [self end_select:2];
  661. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  662. }
  663. else
  664. {
  665. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  666. }
  667. });
  668. });
  669. }
  670. -(void) addtoportfolio
  671. {
  672. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  673. int count = [[items valueForKey:@"count"] intValue];
  674. NSMutableArray* checked = [[NSMutableArray alloc] init];
  675. for(int i=0;i<count;i++)
  676. {
  677. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  678. bool check = [[item valueForKey:@"checked"] boolValue];
  679. if(check)
  680. {
  681. [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  682. }
  683. }
  684. if(checked.count==0)
  685. {
  686. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to portfolio." controller:self] ;
  687. return;
  688. }
  689. NSString * ids = [checked componentsJoinedByString:@","];
  690. self.addPortfolioBtn.enabled =false;
  691. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Portfolio"];
  692. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  693. NSDictionary* return_json = [iSalesNetwork add_toPortfolio:ids ];
  694. dispatch_async(dispatch_get_main_queue(), ^{
  695. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  696. self.addPortfolioBtn.enabled =true;
  697. if([[return_json valueForKey:@"result"] intValue]==2)
  698. {
  699. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  700. [((MainViewController*)appDelegate.main_vc) reloadPortfolio :true immediately:false];
  701. [RAUtils message_alert:nil title:@" Multiple items added to Portfolio" controller:self] ;
  702. [self end_select:3];
  703. }
  704. else
  705. {
  706. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
  707. }
  708. });
  709. });
  710. }
  711. -(void) addtowish
  712. {
  713. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  714. int count = [[items valueForKey:@"count"] intValue];
  715. NSMutableArray* checked = [[NSMutableArray alloc] init];
  716. for(int i=0;i<count;i++)
  717. {
  718. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  719. bool check = [[item valueForKey:@"checked"] boolValue];
  720. if(check)
  721. {
  722. [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  723. }
  724. }
  725. if(checked.count==0)
  726. {
  727. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to wishlist." controller:self] ;
  728. return;
  729. }
  730. NSString * ids = [checked componentsJoinedByString:@","];
  731. self.addWishBtn.enabled =false;
  732. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Wishlist"];
  733. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  734. NSDictionary* return_json = [iSalesNetwork add_toWatchList:ids ];
  735. dispatch_async(dispatch_get_main_queue(), ^{
  736. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  737. self.addWishBtn.enabled =true;
  738. if([[return_json valueForKey:@"result"] intValue]==2)
  739. {
  740. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  741. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  742. [RAUtils message_alert:nil title:@" Multiple items added to Wishlist" controller:self] ;
  743. [self end_select:1];
  744. }
  745. else
  746. {
  747. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wishlist" controller:self] ;
  748. }
  749. });
  750. });
  751. }
  752. -(void) loadMore
  753. {
  754. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  755. self.isrefreshing=true;
  756. NSDictionary* category_more=[iSalesNetwork Search:self.offset limit:20 keywords:self.keywords];
  757. dispatch_async(dispatch_get_main_queue(), ^{
  758. NSDictionary* more_items=[category_more objectForKey:@"items"];
  759. if([[category_more valueForKey:@"result"] intValue]==2)
  760. {
  761. // self.category_data = category_data;
  762. NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
  763. int count =[[more_items valueForKey:@"count"] intValue];
  764. for(int i=0;i<count;i++)
  765. {
  766. NSDictionary * item_json = [more_items objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  767. [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
  768. }
  769. long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
  770. [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
  771. [self.category_data setObject:items_json forKey:@"items"];
  772. self.offset+=count;
  773. // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  774. NSLog(@"%@",self.category_data);
  775. [self.collectionview reloadData];
  776. }
  777. else
  778. {
  779. [RAUtils message_alert:[category_more valueForKey:@"err_msg"] title:@"Search" controller:self] ;
  780. }
  781. self.isrefreshing=false;
  782. });
  783. // dispatch_async(dispatch_get_main_queue(), ^{
  784. // // self.category_data = category_data;
  785. //
  786. //
  787. // if([[category_more valueForKey:@"result"] intValue]==2)
  788. // {
  789. // NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
  790. //
  791. // int count =[[category_more valueForKey:@"count"] intValue];
  792. // for(int i=0;i<count;i++)
  793. // {
  794. //
  795. // NSDictionary * item_json = [category_more objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  796. // [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
  797. //
  798. //
  799. // }
  800. // long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
  801. // [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
  802. // [self.category_data setObject:items_json forKey:@"items"];
  803. // self.offset+=count;
  804. // // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  805. //
  806. //
  807. //
  808. //
  809. // NSLog(@"%@",self.category_data);
  810. //
  811. // [self.collectionview reloadData];
  812. // }
  813. // else
  814. // {
  815. // [RAUtils error_alert:[category_more valueForKey:@"err_msg"]] ;
  816. // }
  817. //
  818. //
  819. //
  820. //
  821. // });
  822. });
  823. }
  824. -(void) reload
  825. {
  826. dispatch_async(dispatch_get_main_queue(), ^{
  827. if(self.isrefreshing)
  828. return;
  829. self.isrefreshing=true;
  830. UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
  831. [reF endRefreshing];
  832. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  833. self.label_net_err.hidden=true;
  834. self.collectionview.hidden=true;
  835. self.mum.center = self.view.center;
  836. self.mum.hidden = false;
  837. [self.mum startAnimating];
  838. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  839. NSDictionary* category_data=[iSalesNetwork Search:0 limit:20 keywords:self.keywords];
  840. dispatch_async(dispatch_get_main_queue(), ^{
  841. [self.mum stopAnimating];
  842. self.category_data = [category_data mutableCopy];
  843. [self.collectionview reloadData];
  844. if([[category_data valueForKey:@"result"] intValue]==2)
  845. {
  846. self.collectionview.hidden=false;
  847. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  848. self.offset =[[item_json valueForKey:@"count"] intValue];
  849. int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
  850. if(total<2)
  851. {
  852. self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
  853. if(total==1)
  854. {
  855. NSDictionary * detail_item = [item_json objectForKey:@"item_0"];
  856. NSString* detail_id= [detail_item valueForKey:@"product_id"] ;
  857. [self showDetailat:detail_id category_id:nil index:0];
  858. }
  859. }
  860. else
  861. self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
  862. }
  863. else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  864. {
  865. self.collectionview.hidden=true;
  866. self.label_net_err.hidden=false;
  867. }
  868. else
  869. {
  870. [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Search" controller:self] ;
  871. }
  872. self.isrefreshing=false;
  873. });
  874. });
  875. });
  876. }
  877. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  878. {
  879. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  880. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  881. if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  882. {
  883. // self.orientation = orientation;
  884. [self.collectionview.collectionViewLayout invalidateLayout];
  885. NSLog(@"routed");
  886. }
  887. }
  888. /*
  889. #pragma mark - Navigation
  890. // In a storyboard-based application, you will often want to do a little preparation before navigation
  891. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  892. // Get the new view controller using [segue destinationViewController].
  893. // Pass the selected object to the new view controller.
  894. }
  895. */
  896. #pragma mark - searchBar delegate;
  897. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  898. {
  899. self.keywords=searchBar.text;
  900. self.offset = 0;
  901. // [self.content_data removeAllObjects];
  902. [self reload];
  903. NSLog(@"search");
  904. }
  905. /*
  906. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  907. {
  908. if([searchText isEqualToString:@""] && !self.reset)
  909. {
  910. NSLog(@"clear");
  911. self.reset=true;
  912. self.keywords=nil;
  913. self.offset = 0;
  914. [self.content_data removeAllObjects];
  915. [self loadpage];
  916. [self loadpage];
  917. }
  918. else
  919. self.reset = false;
  920. }*/
  921. #pragma mark -- UICollectionViewDataSource
  922. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  923. {
  924. // 每个Section的item个数
  925. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  926. int count =[[item_json valueForKey:@"count"] intValue];
  927. return count;
  928. }
  929. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  930. {
  931. return 1;
  932. }
  933. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  934. {
  935. if(self.categoryViewType == CATEGORY_VIEWTYPE_SMALL)
  936. {
  937. static NSString * CellIdentifier = @"CategoryCellNPD";
  938. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  939. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  940. NSString* img_url =[item_json valueForKey:@"img"];
  941. NSString* description =[item_json valueForKey:@"description"];
  942. NSString* name =[item_json valueForKey:@"fash_name"];
  943. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  944. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  945. if(wish_exist)
  946. cell.mark_wish.hidden=false;
  947. else
  948. cell.mark_wish.hidden=true;
  949. if(cart_exists)
  950. cell.mark_order.hidden=false;
  951. else
  952. cell.mark_order.hidden=true;
  953. // NSString* old_price =[item_json valueForKey:@"old_price"];
  954. // NSString* price =[item_json valueForKey:@"price"];
  955. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  956. if(!checked)
  957. {
  958. cell.checkImageView.hidden = true;
  959. [cell setBackgroundColor: UIColorFromRGB(0x996633)];
  960. }
  961. else
  962. {
  963. cell.checkImageView.hidden = false;
  964. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  965. }
  966. cell.nameLabel.text = description;
  967. cell.modelNoLabel.text=name;
  968. cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
  969. // cell.cellDescription.text = description;
  970. // cell.oldPrice.text = old_price;
  971. // cell.Price.text = price;
  972. NSString* file_name=[img_url lastPathComponent];
  973. NSData* img_data=[iSalesDB load_cached_img:file_name];
  974. if(img_data!=nil)
  975. {
  976. UIImage * img =[UIImage imageWithData:img_data];
  977. cell.cellImageView.image = img;
  978. }
  979. else
  980. {
  981. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  982. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  983. dispatch_async(dispatch_get_main_queue(), ^{
  984. if(downloadimg_data!=nil)
  985. {
  986. [iSalesDB cache_img:downloadimg_data :file_name ];
  987. UIImage * img =[UIImage imageWithData:downloadimg_data];
  988. cell.cellImageView.image = img;
  989. }
  990. else
  991. {
  992. // UIImage * img=[UIImage imageNamed:@"notfound_s"];
  993. cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
  994. }
  995. });
  996. });
  997. }
  998. return cell;
  999. }
  1000. else if(self.categoryViewType == CATEGORY_VIEWTYPE_LARGE)
  1001. {
  1002. static NSString * CellIdentifier = @"CategoryCellNPDLarge";
  1003. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  1004. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1005. NSString* img_url =[item_json valueForKey:@"img"];
  1006. NSString* description =[item_json valueForKey:@"description"];
  1007. NSString* name =[item_json valueForKey:@"fash_name"];
  1008. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  1009. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  1010. if(wish_exist)
  1011. cell.mark_wish.hidden=false;
  1012. else
  1013. cell.mark_wish.hidden=true;
  1014. if(cart_exists)
  1015. cell.mark_order.hidden=false;
  1016. else
  1017. cell.mark_order.hidden=true;
  1018. // NSString* old_price =[item_json valueForKey:@"old_price"];
  1019. // NSString* price =[item_json valueForKey:@"price"];
  1020. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  1021. if(!checked)
  1022. {
  1023. cell.checkImageView.hidden = true;
  1024. [cell setBackgroundColor: UIColorFromRGB(0x996633)];
  1025. }
  1026. else
  1027. {
  1028. cell.checkImageView.hidden = false;
  1029. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1030. }
  1031. cell.nameLabel.text = description;
  1032. cell.modelNoLabel.text=name;
  1033. cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
  1034. // cell.cellDescription.text = description;
  1035. // cell.oldPrice.text = old_price;
  1036. // cell.Price.text = price;
  1037. NSString* file_name=[img_url lastPathComponent];
  1038. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1039. if(img_data!=nil)
  1040. {
  1041. UIImage * img =[UIImage imageWithData:img_data];
  1042. cell.cellImageView.image = img;
  1043. }
  1044. else
  1045. {
  1046. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1047. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1048. dispatch_async(dispatch_get_main_queue(), ^{
  1049. if(downloadimg_data!=nil)
  1050. {
  1051. [iSalesDB cache_img:downloadimg_data :file_name ];
  1052. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1053. cell.cellImageView.image = img;
  1054. }
  1055. else
  1056. cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
  1057. });
  1058. });
  1059. }
  1060. return cell;
  1061. }
  1062. else
  1063. {
  1064. static NSString * CellIdentifier = @"CategoryCellNPDList";
  1065. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  1066. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1067. NSString* img_url =[item_json valueForKey:@"img"];
  1068. NSString* description =[item_json valueForKey:@"description"];
  1069. NSString* name =[item_json valueForKey:@"fash_name "];
  1070. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  1071. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  1072. if(wish_exist)
  1073. cell.mark_wish.hidden=false;
  1074. else
  1075. cell.mark_wish.hidden=true;
  1076. if(cart_exists)
  1077. cell.mark_order.hidden=false;
  1078. else
  1079. cell.mark_order.hidden=true;
  1080. // NSString* old_price =[item_json valueForKey:@"old_price"];
  1081. // NSString* price =[item_json valueForKey:@"price"];
  1082. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  1083. if(!checked)
  1084. {
  1085. cell.checkImageView.hidden = true;
  1086. [cell setBackgroundColor: UIColorFromRGB(0xF2EEEA)];
  1087. }
  1088. else
  1089. {
  1090. cell.checkImageView.hidden = false;
  1091. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1092. }
  1093. cell.nameLabel.text = description;
  1094. cell.modelNoLabel.text=name;
  1095. cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
  1096. // cell.cellDescription.text = description;
  1097. // cell.oldPrice.text = old_price;
  1098. // cell.Price.text = price;
  1099. NSString* file_name=[img_url lastPathComponent];
  1100. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1101. if(img_data!=nil)
  1102. {
  1103. UIImage * img =[UIImage imageWithData:img_data];
  1104. cell.cellImageView.image = img;
  1105. }
  1106. else
  1107. {
  1108. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1109. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1110. dispatch_async(dispatch_get_main_queue(), ^{
  1111. if(downloadimg_data!=nil)
  1112. {
  1113. [iSalesDB cache_img:downloadimg_data :file_name ];
  1114. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1115. cell.cellImageView.image = img;
  1116. }
  1117. else
  1118. cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
  1119. });
  1120. });
  1121. }
  1122. return cell;
  1123. }
  1124. }
  1125. #pragma mark --UICollectionViewDelegateFlowLayout
  1126. ////定义每个UICollectionView 的大小
  1127. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  1128. //{
  1129. // return CGSizeMake(96, 100);
  1130. //}
  1131. //定义每个UICollectionView 的 margin
  1132. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  1133. {
  1134. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  1135. if (UIInterfaceOrientationIsLandscape(orientation))
  1136. {
  1137. // NSLog(@"横");
  1138. // if(self.showDetail)
  1139. // return CGSizeMake(96, 100);
  1140. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1141. return CGSizeMake(328, 391);
  1142. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1143. return CGSizeMake(1024, 120);
  1144. return CGSizeMake(193, 269);
  1145. }
  1146. else if(UIInterfaceOrientationIsPortrait(orientation))
  1147. {
  1148. // NSLog(@"竖");
  1149. // if(self.showDetail)
  1150. // return CGSizeMake(96, 100);
  1151. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1152. return CGSizeMake(369, 440);
  1153. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1154. return CGSizeMake(768, 120);
  1155. return CGSizeMake(180, 251);
  1156. }
  1157. NSLog(@"error , %ld",(long)orientation );
  1158. return CGSizeMake(96, 100);
  1159. }
  1160. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  1161. {
  1162. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1163. return 1;
  1164. return 15;
  1165. }
  1166. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  1167. {
  1168. if(self.showDetail)
  1169. return UIEdgeInsetsMake(10, 5, 10, 5);
  1170. // if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1171. // return UIEdgeInsetsMake(10, 10, 10, 10);
  1172. return UIEdgeInsetsMake(10, 10, 10, 10);
  1173. }
  1174. #pragma mark --UICollectionViewDelegate
  1175. -(void) showDetailat:(NSString*) item_id category_id:(NSString*) category_id index:(long)index
  1176. {
  1177. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  1178. // dvc
  1179. dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
  1180. {
  1181. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1182. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",index]] mutableCopy];
  1183. if(add_cart)
  1184. item[@"cart_exists"]=@"true";
  1185. if(add_wish)
  1186. item[@"wish_exists"]=@"true";
  1187. items[[NSString stringWithFormat:@"item_%ld",index]] = item;
  1188. self.category_data[@"items"]=items;
  1189. [self.collectionview reloadData];
  1190. };
  1191. // dvc.use_model_name = true;
  1192. // dvc.model_name=[transformed stringValue];
  1193. dvc.product_id = item_id;
  1194. dvc.category_id=category_id;
  1195. dvc.ispush = true;
  1196. [dvc reload];
  1197. [self.navigationController pushViewController:dvc animated:true];
  1198. return;
  1199. //一下为detail嵌入当前窗口的方式
  1200. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  1201. // [self.collectionview.collectionViewLayout invalidateLayout];
  1202. [self.collectionview reloadData];
  1203. UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1204. int width=175;
  1205. // int height;
  1206. if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1207. {
  1208. width = 370;
  1209. // height = 400;
  1210. }
  1211. else
  1212. {
  1213. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  1214. flowLayout.scrollDirection= UICollectionViewScrollDirectionHorizontal;
  1215. // [self.collectionview ] set
  1216. // height = 251;
  1217. width = 180;
  1218. }
  1219. CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width, 271);
  1220. // CGRect framedetail = CGRectMake(0,271 ,self.view.bounds.size.width,self.view.bounds.size.height-271);
  1221. [UIView animateWithDuration:0.5 animations:^{
  1222. self.collectionview.frame=frame;
  1223. // self.detailView.frame = framedetail;
  1224. // self.cagegoryLabel.hidden = true;
  1225. }];
  1226. self.collectionview.autoresizingMask = self.collectionview.autoresizingMask ^ UIViewAutoresizingFlexibleWidth;
  1227. self.showDetail = true;
  1228. NSArray* a= self.childViewControllers;
  1229. for (int i=0;i<a.count;i++)
  1230. {
  1231. if([a[i] isKindOfClass:[DetailViewController class]])
  1232. {
  1233. DetailViewController *detailvc=a[i];
  1234. detailvc.category_id = nil;
  1235. detailvc.product_id = item_id;
  1236. detailvc.ispush=false;
  1237. [detailvc reload];
  1238. }
  1239. }
  1240. }
  1241. //UICollectionView被选中时调用的方法
  1242. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  1243. {
  1244. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1245. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1246. if(self.isSelectionMode)
  1247. {
  1248. bool checked =[[item valueForKey:@"checked"] boolValue];
  1249. CategoryCellNPD *currentSelecteCell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  1250. if(checked)
  1251. {
  1252. self.select_count--;
  1253. if(self.select_count==0)
  1254. {
  1255. self.addWishBtn.enabled = false;
  1256. self.addCartBtn.enabled = false;
  1257. self.addPortfolioBtn.enabled=false;
  1258. }
  1259. [item setValue:@"false" forKey:@"checked"];
  1260. currentSelecteCell.checkImageView.hidden = true;
  1261. if(self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
  1262. [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x996633)];
  1263. else
  1264. [currentSelecteCell setBackgroundColor: UIColorFromRGB(0xF2EEEA)];
  1265. }
  1266. else
  1267. {
  1268. self.select_count++;
  1269. self.addWishBtn.enabled = true;
  1270. self.addCartBtn.enabled = true;
  1271. self.addPortfolioBtn.enabled=true;
  1272. [item setValue:@"true" forKey:@"checked"];
  1273. currentSelecteCell.checkImageView.hidden = false;
  1274. [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x009966)];
  1275. }
  1276. [items setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1277. [self.category_data setObject:items forKey:@"items"];
  1278. }
  1279. else
  1280. {
  1281. NSString* detail_id= [item valueForKey:@"product_id"] ;
  1282. [self showDetailat:detail_id category_id:nil index:indexPath.row];
  1283. }
  1284. }
  1285. #pragma mark Deferred image loading (UIScrollViewDelegate)
  1286. //// Load images for all onscreen rows when scrolling is finished
  1287. //- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  1288. //{
  1289. // if (!decelerate)
  1290. // {
  1291. // NSLog(@"scrollViewDidEndDragging LOADMORE");
  1292. // }
  1293. //}
  1294. //
  1295. //- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  1296. //{
  1297. // NSLog(@"scrollViewDidEndDecelerating LOADMORE");
  1298. //}
  1299. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  1300. // [refreshHeaderViewegoRefreshScrollViewDidScroll:scrollView];//下拉刷新
  1301. CGPoint contentOffsetPoint = self.collectionview.contentOffset;
  1302. CGRect frame =self.collectionview.frame;
  1303. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  1304. if(flowLayout.scrollDirection== UICollectionViewScrollDirectionVertical)
  1305. {
  1306. NSLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
  1307. NSLog(@"frame.size.height %f",frame.size.height);
  1308. NSLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
  1309. if (contentOffsetPoint.y == (self.collectionview.contentSize.height - frame.size.height) /*|| self.collectionview.contentSize.height < frame.size.height*/)
  1310. {
  1311. if(self.isrefreshing)
  1312. return;
  1313. NSLog(@"scroll to the end,load more......");
  1314. [self loadMore];
  1315. // self.btnLoad.hidden = NO;
  1316. }
  1317. }
  1318. else if(flowLayout.scrollDirection== UICollectionViewScrollDirectionHorizontal)
  1319. {
  1320. NSLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
  1321. NSLog(@"frame.size.height %f",frame.size.height);
  1322. NSLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
  1323. if (contentOffsetPoint.x == (self.collectionview.contentSize.width - frame.size.width) /*|| self.collectionview.contentSize.width < frame.size.width*/)
  1324. {
  1325. if(self.isrefreshing)
  1326. return;
  1327. NSLog(@"scroll to the end,load more......");
  1328. [self loadMore];
  1329. // self.btnLoad.hidden = NO;
  1330. }
  1331. }
  1332. }
  1333. #pragma mark - UIAlertViewDelegate
  1334. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1335. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1336. {
  1337. UIApplication * app = [UIApplication sharedApplication];
  1338. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1339. // if(alertView.tag==1234)
  1340. // {
  1341. //
  1342. // // availability warring;
  1343. //
  1344. //
  1345. // if(buttonIndex!=alertView.cancelButtonIndex)
  1346. // {
  1347. // if(appDelegate.order_code==nil)
  1348. // {
  1349. // [self neworder];
  1350. // }
  1351. // else
  1352. // {
  1353. // [self addtocart];
  1354. // }
  1355. // }
  1356. // return;
  1357. // }
  1358. // int count=[self.quantity_text.text intValue];
  1359. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1360. if(buttonIndex==alertView.cancelButtonIndex)
  1361. {
  1362. }
  1363. else if(buttonIndex==1)
  1364. {
  1365. //open exist
  1366. self.disable_refresh = true;
  1367. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1368. ovc.showNavibar = true;
  1369. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1370. if(appDelegate.order_code==nil)
  1371. {
  1372. [self neworder];
  1373. }
  1374. else
  1375. {
  1376. [self addtocart];
  1377. // [main_vc checklogin:true];
  1378. }
  1379. };
  1380. ovc.init_style = OL_OPEN;
  1381. ovc.onCancel = ^(){
  1382. self.disable_refresh = false;
  1383. // [main_vc checklogin:true];
  1384. };
  1385. [self.navigationController pushViewController:ovc animated:true];
  1386. }
  1387. else
  1388. {
  1389. //create new;
  1390. self.disable_refresh = true;
  1391. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1392. {
  1393. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1394. cvc.showNavibar = true;
  1395. cvc.contact_type = @"Sales_Order_Customer";
  1396. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1397. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1398. appDelegate.customerInfo = value;
  1399. if(appDelegate.order_code==nil)
  1400. [self neworder];
  1401. // [main_vc checklogin:true];
  1402. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1403. //
  1404. // if(self.returnValue)
  1405. // self.returnValue(value);
  1406. };
  1407. cvc.onCancel = ^(){
  1408. [RAUtils message_alert:@"Can ot create order without cursomer infomation." title:@"" controller:self];
  1409. self.disable_refresh = false;
  1410. };
  1411. cvc.onReset = ^(){
  1412. // [main_vc checklogin:true];
  1413. };
  1414. [self.navigationController pushViewController:cvc animated:true];
  1415. }
  1416. else
  1417. {
  1418. [self neworder];
  1419. }
  1420. }
  1421. }
  1422. #pragma mark - Support scanner
  1423. -(void) onDecodedData:(NSString*) value
  1424. {
  1425. // UIApplication * app = [UIApplication sharedApplication];
  1426. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1427. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1428. //
  1429. self.searchBar.text = value;
  1430. self.keywords=self.searchBar.text;
  1431. self.offset = 0;
  1432. // [self.content_data removeAllObjects];
  1433. [self reload];
  1434. }
  1435. @end