SearchViewController.m 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  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. UIApplication * app = [UIApplication sharedApplication];
  419. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  420. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  421. if(appDelegate.bLogin==false)
  422. {
  423. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  424. // loginvc.delegate = self;
  425. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  426. loginvc.returnValue = ^(bool blogin){
  427. // UIApplication * app = [UIApplication sharedApplication];
  428. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  429. if(blogin)
  430. {
  431. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  432. {
  433. [main_vc checklogin:false];
  434. if(appDelegate.can_create_order)
  435. {
  436. NSString* msg =@"Do you want to switch to a pending order or a new order?";
  437. if(appDelegate.contact_id.length>0)
  438. {
  439. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  440. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  441. }
  442. 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];
  443. // alert.
  444. [alert show];
  445. }
  446. else
  447. {
  448. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  449. // alert.
  450. [alert show];
  451. }
  452. }
  453. else
  454. {
  455. [main_vc checklogin:false];
  456. [self addtocart];
  457. }
  458. }
  459. // self.offset = 0;
  460. // [self.content_data removeAllObjects];
  461. // [self loadpage];
  462. //
  463. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  464. };
  465. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  466. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  467. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  468. [self presentViewController:navi animated:YES completion:^{
  469. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  470. NSLog(@"LoginViewController present.........");
  471. // self.btop = false;
  472. // <#code#>
  473. }];
  474. }
  475. else
  476. {
  477. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  478. {
  479. // [main_vc checklogin:false];
  480. if(appDelegate.can_create_order)
  481. {
  482. NSString* msg =@"Do you want to switch to a pending order or a new order?";
  483. if(appDelegate.contact_id.length>0)
  484. {
  485. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  486. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  487. }
  488. 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];
  489. // alert.
  490. [alert show];
  491. }
  492. else
  493. {
  494. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  495. // alert.
  496. [alert show];
  497. }
  498. }
  499. else
  500. {
  501. if(appDelegate.order_code==nil)
  502. [ self neworder];
  503. else
  504. [self addtocart];
  505. }
  506. }
  507. }
  508. -(void) neworder
  509. {
  510. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  511. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  512. NSDictionary* return_json = [iSalesNetwork new_Order];
  513. dispatch_async(dispatch_get_main_queue(), ^{
  514. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  515. if([[return_json valueForKey:@"result"] intValue]==2)
  516. {
  517. int result=[[return_json valueForKey:@"result"] intValue];
  518. if(result==2)
  519. {
  520. //successed.
  521. NSString* order_code = [return_json valueForKey:@"orderCode"];
  522. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  523. appDelegate.order_code = order_code;
  524. [self addtocart];
  525. // [self ReloadData];
  526. // if(self.shopCartBlock!=nil)
  527. // {
  528. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  529. //
  530. //
  531. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  532. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  533. // iv.image = img;
  534. // // [self.contentView addSubview:iv];
  535. // self.shopCartBlock(iv);
  536. //
  537. // }
  538. }
  539. }
  540. else
  541. {
  542. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  543. }
  544. });
  545. });
  546. }
  547. - (IBAction)onAddPortfolioClick:(id)sender {
  548. UIApplication * app = [UIApplication sharedApplication];
  549. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  550. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  551. if(appDelegate.bLogin==false)
  552. {
  553. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  554. // loginvc.delegate = self;
  555. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  556. loginvc.returnValue = ^(bool blogin){
  557. if(blogin)
  558. {
  559. [main_vc checklogin:false];
  560. [self addtoportfolio];
  561. }
  562. };
  563. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  564. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  565. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  566. [self presentViewController:navi animated:YES completion:^{
  567. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  568. NSLog(@"LoginViewController present.........");
  569. // self.btop = false;
  570. // <#code#>
  571. }];
  572. }
  573. else
  574. {
  575. [self addtoportfolio];
  576. }
  577. }
  578. - (IBAction)onAddWishlistClick:(id)sender {
  579. UIApplication * app = [UIApplication sharedApplication];
  580. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  581. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  582. if(appDelegate.bLogin==false)
  583. {
  584. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  585. // loginvc.delegate = self;
  586. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  587. loginvc.returnValue = ^(bool blogin){
  588. if(blogin)
  589. {
  590. [main_vc checklogin:false];
  591. [self addtowish];
  592. }
  593. };
  594. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  595. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  596. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  597. [self presentViewController:navi animated:YES completion:^{
  598. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  599. NSLog(@"LoginViewController present.........");
  600. // self.btop = false;
  601. // <#code#>
  602. }];
  603. }
  604. else
  605. {
  606. [self addtowish];
  607. }
  608. }
  609. -(void) addtocart
  610. {
  611. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  612. int count = [[items valueForKey:@"count"] intValue];
  613. NSMutableArray* checked = [[NSMutableArray alloc] init];
  614. for(int i=0;i<count;i++)
  615. {
  616. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  617. bool check = [[item valueForKey:@"checked"] boolValue];
  618. if(check)
  619. {
  620. // [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  621. [checked addObject:[item valueForKey:@"fash_name"]];
  622. }
  623. }
  624. if(checked.count==0)
  625. {
  626. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to cart." controller:self] ;
  627. return;
  628. }
  629. NSString * ids = [checked componentsJoinedByString:@","];
  630. self.addCartBtn.enabled = false;
  631. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Cart"];
  632. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  633. NSDictionary* return_json = [iSalesNetwork add_toCart_byName:ids ];
  634. dispatch_async(dispatch_get_main_queue(), ^{
  635. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  636. self.addCartBtn.enabled = true;
  637. if([[return_json valueForKey:@"result"] intValue]==2)
  638. {
  639. // int result=[[return_json valueForKey:@"result"] intValue];
  640. // if(result==2)
  641. // {
  642. // //successed.
  643. // NSString* order_code = [return_json valueForKey:@"order_code"];
  644. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  645. // appDelegate.order_code = order_code;
  646. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  647. // appDelegate.order_code = order_code;
  648. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  649. [RAUtils message_alert:nil title:@" Multiple items added to Cart" controller:self] ;
  650. [self end_select:2];
  651. // }
  652. }
  653. else if([[return_json valueForKey:@"result"] intValue]==8)
  654. {
  655. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  656. // appDelegate.order_code = order_code;
  657. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  658. [self end_select:2];
  659. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  660. }
  661. else
  662. {
  663. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  664. }
  665. });
  666. });
  667. }
  668. -(void) addtoportfolio
  669. {
  670. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  671. int count = [[items valueForKey:@"count"] intValue];
  672. NSMutableArray* checked = [[NSMutableArray alloc] init];
  673. for(int i=0;i<count;i++)
  674. {
  675. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  676. bool check = [[item valueForKey:@"checked"] boolValue];
  677. if(check)
  678. {
  679. [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  680. }
  681. }
  682. if(checked.count==0)
  683. {
  684. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to portfolio." controller:self] ;
  685. return;
  686. }
  687. NSString * ids = [checked componentsJoinedByString:@","];
  688. self.addPortfolioBtn.enabled =false;
  689. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Portfolio"];
  690. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  691. NSDictionary* return_json = [iSalesNetwork add_toPortfolio:ids ];
  692. dispatch_async(dispatch_get_main_queue(), ^{
  693. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  694. self.addPortfolioBtn.enabled =true;
  695. if([[return_json valueForKey:@"result"] intValue]==2)
  696. {
  697. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  698. [((MainViewController*)appDelegate.main_vc) reloadPortfolio :true immediately:false];
  699. [RAUtils message_alert:nil title:@" Multiple items added to Portfolio" controller:self] ;
  700. [self end_select:3];
  701. }
  702. else
  703. {
  704. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
  705. }
  706. });
  707. });
  708. }
  709. -(void) addtowish
  710. {
  711. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  712. int count = [[items valueForKey:@"count"] intValue];
  713. NSMutableArray* checked = [[NSMutableArray alloc] init];
  714. for(int i=0;i<count;i++)
  715. {
  716. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  717. bool check = [[item valueForKey:@"checked"] boolValue];
  718. if(check)
  719. {
  720. [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  721. }
  722. }
  723. if(checked.count==0)
  724. {
  725. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to wishlist." controller:self] ;
  726. return;
  727. }
  728. NSString * ids = [checked componentsJoinedByString:@","];
  729. self.addWishBtn.enabled =false;
  730. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Wishlist"];
  731. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  732. NSDictionary* return_json = [iSalesNetwork add_toWatchList:ids ];
  733. dispatch_async(dispatch_get_main_queue(), ^{
  734. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  735. self.addWishBtn.enabled =true;
  736. if([[return_json valueForKey:@"result"] intValue]==2)
  737. {
  738. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  739. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  740. [RAUtils message_alert:nil title:@" Multiple items added to Wishlist" controller:self] ;
  741. [self end_select:1];
  742. }
  743. else
  744. {
  745. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wishlist" controller:self] ;
  746. }
  747. });
  748. });
  749. }
  750. -(void) loadMore
  751. {
  752. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  753. self.isrefreshing=true;
  754. NSDictionary* category_more=[iSalesNetwork Search:self.offset limit:20 keywords:self.keywords];
  755. dispatch_async(dispatch_get_main_queue(), ^{
  756. NSDictionary* more_items=[category_more objectForKey:@"items"];
  757. if([[category_more valueForKey:@"result"] intValue]==2)
  758. {
  759. // self.category_data = category_data;
  760. NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
  761. int count =[[more_items valueForKey:@"count"] intValue];
  762. for(int i=0;i<count;i++)
  763. {
  764. NSDictionary * item_json = [more_items objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  765. [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
  766. }
  767. long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
  768. [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
  769. [self.category_data setObject:items_json forKey:@"items"];
  770. self.offset+=count;
  771. // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  772. NSLog(@"%@",self.category_data);
  773. [self.collectionview reloadData];
  774. }
  775. else
  776. {
  777. [RAUtils message_alert:[category_more valueForKey:@"err_msg"] title:@"Search" controller:self] ;
  778. }
  779. self.isrefreshing=false;
  780. });
  781. // dispatch_async(dispatch_get_main_queue(), ^{
  782. // // self.category_data = category_data;
  783. //
  784. //
  785. // if([[category_more valueForKey:@"result"] intValue]==2)
  786. // {
  787. // NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
  788. //
  789. // int count =[[category_more valueForKey:@"count"] intValue];
  790. // for(int i=0;i<count;i++)
  791. // {
  792. //
  793. // NSDictionary * item_json = [category_more objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  794. // [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
  795. //
  796. //
  797. // }
  798. // long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
  799. // [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
  800. // [self.category_data setObject:items_json forKey:@"items"];
  801. // self.offset+=count;
  802. // // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  803. //
  804. //
  805. //
  806. //
  807. // NSLog(@"%@",self.category_data);
  808. //
  809. // [self.collectionview reloadData];
  810. // }
  811. // else
  812. // {
  813. // [RAUtils error_alert:[category_more valueForKey:@"err_msg"]] ;
  814. // }
  815. //
  816. //
  817. //
  818. //
  819. // });
  820. });
  821. }
  822. -(void) reload
  823. {
  824. dispatch_async(dispatch_get_main_queue(), ^{
  825. if(self.isrefreshing)
  826. return;
  827. self.isrefreshing=true;
  828. UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
  829. [reF endRefreshing];
  830. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  831. self.label_net_err.hidden=true;
  832. self.collectionview.hidden=true;
  833. self.mum.center = self.view.center;
  834. self.mum.hidden = false;
  835. [self.mum startAnimating];
  836. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  837. NSDictionary* category_data=[iSalesNetwork Search:0 limit:20 keywords:self.keywords];
  838. dispatch_async(dispatch_get_main_queue(), ^{
  839. [self.mum stopAnimating];
  840. self.category_data = [category_data mutableCopy];
  841. [self.collectionview reloadData];
  842. if([[category_data valueForKey:@"result"] intValue]==2)
  843. {
  844. self.collectionview.hidden=false;
  845. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  846. self.offset =[[item_json valueForKey:@"count"] intValue];
  847. int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
  848. if(total<2)
  849. {
  850. self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
  851. if(total==1)
  852. {
  853. NSDictionary * detail_item = [item_json objectForKey:@"item_0"];
  854. NSString* detail_id= [detail_item valueForKey:@"product_id"] ;
  855. [self showDetailat:detail_id category_id:nil index:0];
  856. }
  857. }
  858. else
  859. self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
  860. }
  861. else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  862. {
  863. self.collectionview.hidden=true;
  864. self.label_net_err.hidden=false;
  865. }
  866. else
  867. {
  868. [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Search" controller:self] ;
  869. }
  870. self.isrefreshing=false;
  871. });
  872. });
  873. });
  874. }
  875. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  876. {
  877. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  878. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  879. if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  880. {
  881. // self.orientation = orientation;
  882. [self.collectionview.collectionViewLayout invalidateLayout];
  883. NSLog(@"routed");
  884. }
  885. }
  886. /*
  887. #pragma mark - Navigation
  888. // In a storyboard-based application, you will often want to do a little preparation before navigation
  889. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  890. // Get the new view controller using [segue destinationViewController].
  891. // Pass the selected object to the new view controller.
  892. }
  893. */
  894. #pragma mark - searchBar delegate;
  895. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  896. {
  897. self.keywords=searchBar.text;
  898. self.offset = 0;
  899. // [self.content_data removeAllObjects];
  900. [self reload];
  901. NSLog(@"search");
  902. }
  903. /*
  904. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  905. {
  906. if([searchText isEqualToString:@""] && !self.reset)
  907. {
  908. NSLog(@"clear");
  909. self.reset=true;
  910. self.keywords=nil;
  911. self.offset = 0;
  912. [self.content_data removeAllObjects];
  913. [self loadpage];
  914. [self loadpage];
  915. }
  916. else
  917. self.reset = false;
  918. }*/
  919. #pragma mark -- UICollectionViewDataSource
  920. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  921. {
  922. // 每个Section的item个数
  923. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  924. int count =[[item_json valueForKey:@"count"] intValue];
  925. return count;
  926. }
  927. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  928. {
  929. return 1;
  930. }
  931. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  932. {
  933. if(self.categoryViewType == CATEGORY_VIEWTYPE_SMALL)
  934. {
  935. static NSString * CellIdentifier = @"CategoryCellNPD";
  936. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  937. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  938. NSString* img_url =[item_json valueForKey:@"img"];
  939. NSString* description =[item_json valueForKey:@"description"];
  940. NSString* name =[item_json valueForKey:@"fash_name"];
  941. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  942. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  943. if(wish_exist)
  944. cell.mark_wish.hidden=false;
  945. else
  946. cell.mark_wish.hidden=true;
  947. if(cart_exists)
  948. cell.mark_order.hidden=false;
  949. else
  950. cell.mark_order.hidden=true;
  951. // NSString* old_price =[item_json valueForKey:@"old_price"];
  952. // NSString* price =[item_json valueForKey:@"price"];
  953. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  954. if(!checked)
  955. {
  956. cell.checkImageView.hidden = true;
  957. [cell setBackgroundColor: UIColorFromRGB(0x996633)];
  958. }
  959. else
  960. {
  961. cell.checkImageView.hidden = false;
  962. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  963. }
  964. cell.nameLabel.text = description;
  965. cell.modelNoLabel.text=name;
  966. cell.cellImageView.image = [UIImage imageNamed:@"loading_s"];
  967. // cell.cellDescription.text = description;
  968. // cell.oldPrice.text = old_price;
  969. // cell.Price.text = price;
  970. NSString* file_name=[img_url lastPathComponent];
  971. NSData* img_data=[iSalesDB load_cached_img:file_name];
  972. if(img_data!=nil)
  973. {
  974. UIImage * img =[UIImage imageWithData:img_data];
  975. cell.cellImageView.image = img;
  976. }
  977. else
  978. {
  979. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  980. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  981. dispatch_async(dispatch_get_main_queue(), ^{
  982. if(downloadimg_data!=nil)
  983. {
  984. [iSalesDB cache_img:downloadimg_data :file_name ];
  985. UIImage * img =[UIImage imageWithData:downloadimg_data];
  986. cell.cellImageView.image = img;
  987. }
  988. else
  989. {
  990. // UIImage * img=[UIImage imageNamed:@"notfound_s"];
  991. cell.cellImageView.image = [UIImage imageNamed:@"notfound_s"];
  992. }
  993. });
  994. });
  995. }
  996. return cell;
  997. }
  998. else if(self.categoryViewType == CATEGORY_VIEWTYPE_LARGE)
  999. {
  1000. static NSString * CellIdentifier = @"CategoryCellNPDLarge";
  1001. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  1002. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1003. NSString* img_url =[item_json valueForKey:@"img"];
  1004. NSString* description =[item_json valueForKey:@"description"];
  1005. NSString* name =[item_json valueForKey:@"fash_name"];
  1006. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  1007. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  1008. if(wish_exist)
  1009. cell.mark_wish.hidden=false;
  1010. else
  1011. cell.mark_wish.hidden=true;
  1012. if(cart_exists)
  1013. cell.mark_order.hidden=false;
  1014. else
  1015. cell.mark_order.hidden=true;
  1016. // NSString* old_price =[item_json valueForKey:@"old_price"];
  1017. // NSString* price =[item_json valueForKey:@"price"];
  1018. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  1019. if(!checked)
  1020. {
  1021. cell.checkImageView.hidden = true;
  1022. [cell setBackgroundColor: UIColorFromRGB(0x996633)];
  1023. }
  1024. else
  1025. {
  1026. cell.checkImageView.hidden = false;
  1027. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1028. }
  1029. cell.nameLabel.text = description;
  1030. cell.modelNoLabel.text=name;
  1031. cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
  1032. // cell.cellDescription.text = description;
  1033. // cell.oldPrice.text = old_price;
  1034. // cell.Price.text = price;
  1035. NSString* file_name=[img_url lastPathComponent];
  1036. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1037. if(img_data!=nil)
  1038. {
  1039. UIImage * img =[UIImage imageWithData:img_data];
  1040. cell.cellImageView.image = img;
  1041. }
  1042. else
  1043. {
  1044. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1045. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1046. dispatch_async(dispatch_get_main_queue(), ^{
  1047. if(downloadimg_data!=nil)
  1048. {
  1049. [iSalesDB cache_img:downloadimg_data :file_name ];
  1050. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1051. cell.cellImageView.image = img;
  1052. }
  1053. else
  1054. cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
  1055. });
  1056. });
  1057. }
  1058. return cell;
  1059. }
  1060. else
  1061. {
  1062. static NSString * CellIdentifier = @"CategoryCellNPDList";
  1063. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  1064. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1065. NSString* img_url =[item_json valueForKey:@"img"];
  1066. NSString* description =[item_json valueForKey:@"description"];
  1067. NSString* name =[item_json valueForKey:@"fash_name "];
  1068. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  1069. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  1070. if(wish_exist)
  1071. cell.mark_wish.hidden=false;
  1072. else
  1073. cell.mark_wish.hidden=true;
  1074. if(cart_exists)
  1075. cell.mark_order.hidden=false;
  1076. else
  1077. cell.mark_order.hidden=true;
  1078. // NSString* old_price =[item_json valueForKey:@"old_price"];
  1079. // NSString* price =[item_json valueForKey:@"price"];
  1080. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  1081. if(!checked)
  1082. {
  1083. cell.checkImageView.hidden = true;
  1084. [cell setBackgroundColor: UIColorFromRGB(0xF2EEEA)];
  1085. }
  1086. else
  1087. {
  1088. cell.checkImageView.hidden = false;
  1089. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1090. }
  1091. cell.nameLabel.text = description;
  1092. cell.modelNoLabel.text=name;
  1093. cell.cellImageView.image = [UIImage imageNamed:@"loading_l"];
  1094. // cell.cellDescription.text = description;
  1095. // cell.oldPrice.text = old_price;
  1096. // cell.Price.text = price;
  1097. NSString* file_name=[img_url lastPathComponent];
  1098. NSData* img_data=[iSalesDB load_cached_img:file_name];
  1099. if(img_data!=nil)
  1100. {
  1101. UIImage * img =[UIImage imageWithData:img_data];
  1102. cell.cellImageView.image = img;
  1103. }
  1104. else
  1105. {
  1106. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1107. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1108. dispatch_async(dispatch_get_main_queue(), ^{
  1109. if(downloadimg_data!=nil)
  1110. {
  1111. [iSalesDB cache_img:downloadimg_data :file_name ];
  1112. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1113. cell.cellImageView.image = img;
  1114. }
  1115. else
  1116. cell.cellImageView.image = [UIImage imageNamed:@"notfound_l"];
  1117. });
  1118. });
  1119. }
  1120. return cell;
  1121. }
  1122. }
  1123. #pragma mark --UICollectionViewDelegateFlowLayout
  1124. ////定义每个UICollectionView 的大小
  1125. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  1126. //{
  1127. // return CGSizeMake(96, 100);
  1128. //}
  1129. //定义每个UICollectionView 的 margin
  1130. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  1131. {
  1132. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  1133. if (UIInterfaceOrientationIsLandscape(orientation))
  1134. {
  1135. // NSLog(@"横");
  1136. // if(self.showDetail)
  1137. // return CGSizeMake(96, 100);
  1138. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1139. return CGSizeMake(328, 391);
  1140. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1141. return CGSizeMake(1024, 120);
  1142. return CGSizeMake(193, 269);
  1143. }
  1144. else if(UIInterfaceOrientationIsPortrait(orientation))
  1145. {
  1146. // NSLog(@"竖");
  1147. // if(self.showDetail)
  1148. // return CGSizeMake(96, 100);
  1149. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1150. return CGSizeMake(369, 440);
  1151. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1152. return CGSizeMake(768, 120);
  1153. return CGSizeMake(180, 251);
  1154. }
  1155. NSLog(@"error , %ld",(long)orientation );
  1156. return CGSizeMake(96, 100);
  1157. }
  1158. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  1159. {
  1160. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1161. return 1;
  1162. return 15;
  1163. }
  1164. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  1165. {
  1166. if(self.showDetail)
  1167. return UIEdgeInsetsMake(10, 5, 10, 5);
  1168. // if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1169. // return UIEdgeInsetsMake(10, 10, 10, 10);
  1170. return UIEdgeInsetsMake(10, 10, 10, 10);
  1171. }
  1172. #pragma mark --UICollectionViewDelegate
  1173. -(void) showDetailat:(NSString*) item_id category_id:(NSString*) category_id index:(long)index
  1174. {
  1175. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  1176. // dvc
  1177. dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
  1178. {
  1179. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1180. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",index]] mutableCopy];
  1181. if(add_cart)
  1182. item[@"cart_exists"]=@"true";
  1183. if(add_wish)
  1184. item[@"wish_exists"]=@"true";
  1185. items[[NSString stringWithFormat:@"item_%ld",index]] = item;
  1186. self.category_data[@"items"]=items;
  1187. [self.collectionview reloadData];
  1188. };
  1189. // dvc.use_model_name = true;
  1190. // dvc.model_name=[transformed stringValue];
  1191. dvc.product_id = item_id;
  1192. dvc.category_id=category_id;
  1193. dvc.ispush = true;
  1194. [dvc reload];
  1195. [self.navigationController pushViewController:dvc animated:true];
  1196. return;
  1197. //一下为detail嵌入当前窗口的方式
  1198. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  1199. // [self.collectionview.collectionViewLayout invalidateLayout];
  1200. [self.collectionview reloadData];
  1201. UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1202. int width=175;
  1203. // int height;
  1204. if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1205. {
  1206. width = 370;
  1207. // height = 400;
  1208. }
  1209. else
  1210. {
  1211. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  1212. flowLayout.scrollDirection= UICollectionViewScrollDirectionHorizontal;
  1213. // [self.collectionview ] set
  1214. // height = 251;
  1215. width = 180;
  1216. }
  1217. CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width, 271);
  1218. // CGRect framedetail = CGRectMake(0,271 ,self.view.bounds.size.width,self.view.bounds.size.height-271);
  1219. [UIView animateWithDuration:0.5 animations:^{
  1220. self.collectionview.frame=frame;
  1221. // self.detailView.frame = framedetail;
  1222. // self.cagegoryLabel.hidden = true;
  1223. }];
  1224. self.collectionview.autoresizingMask = self.collectionview.autoresizingMask ^ UIViewAutoresizingFlexibleWidth;
  1225. self.showDetail = true;
  1226. NSArray* a= self.childViewControllers;
  1227. for (int i=0;i<a.count;i++)
  1228. {
  1229. if([a[i] isKindOfClass:[DetailViewController class]])
  1230. {
  1231. DetailViewController *detailvc=a[i];
  1232. detailvc.category_id = nil;
  1233. detailvc.product_id = item_id;
  1234. detailvc.ispush=false;
  1235. [detailvc reload];
  1236. }
  1237. }
  1238. }
  1239. //UICollectionView被选中时调用的方法
  1240. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  1241. {
  1242. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1243. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1244. if(self.isSelectionMode)
  1245. {
  1246. bool checked =[[item valueForKey:@"checked"] boolValue];
  1247. CategoryCellNPD *currentSelecteCell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  1248. if(checked)
  1249. {
  1250. self.select_count--;
  1251. if(self.select_count==0)
  1252. {
  1253. self.addWishBtn.enabled = false;
  1254. self.addCartBtn.enabled = false;
  1255. self.addPortfolioBtn.enabled=false;
  1256. }
  1257. [item setValue:@"false" forKey:@"checked"];
  1258. currentSelecteCell.checkImageView.hidden = true;
  1259. if(self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
  1260. [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x996633)];
  1261. else
  1262. [currentSelecteCell setBackgroundColor: UIColorFromRGB(0xF2EEEA)];
  1263. }
  1264. else
  1265. {
  1266. self.select_count++;
  1267. self.addWishBtn.enabled = true;
  1268. self.addCartBtn.enabled = true;
  1269. self.addPortfolioBtn.enabled=true;
  1270. [item setValue:@"true" forKey:@"checked"];
  1271. currentSelecteCell.checkImageView.hidden = false;
  1272. [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x009966)];
  1273. }
  1274. [items setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1275. [self.category_data setObject:items forKey:@"items"];
  1276. }
  1277. else
  1278. {
  1279. NSString* detail_id= [item valueForKey:@"product_id"] ;
  1280. [self showDetailat:detail_id category_id:nil index:indexPath.row];
  1281. }
  1282. }
  1283. #pragma mark Deferred image loading (UIScrollViewDelegate)
  1284. //// Load images for all onscreen rows when scrolling is finished
  1285. //- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  1286. //{
  1287. // if (!decelerate)
  1288. // {
  1289. // NSLog(@"scrollViewDidEndDragging LOADMORE");
  1290. // }
  1291. //}
  1292. //
  1293. //- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  1294. //{
  1295. // NSLog(@"scrollViewDidEndDecelerating LOADMORE");
  1296. //}
  1297. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  1298. // [refreshHeaderViewegoRefreshScrollViewDidScroll:scrollView];//下拉刷新
  1299. CGPoint contentOffsetPoint = self.collectionview.contentOffset;
  1300. CGRect frame =self.collectionview.frame;
  1301. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  1302. if(flowLayout.scrollDirection== UICollectionViewScrollDirectionVertical)
  1303. {
  1304. NSLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
  1305. NSLog(@"frame.size.height %f",frame.size.height);
  1306. NSLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
  1307. if (contentOffsetPoint.y == (self.collectionview.contentSize.height - frame.size.height) || self.collectionview.contentSize.height < frame.size.height)
  1308. {
  1309. if(self.isrefreshing)
  1310. return;
  1311. NSLog(@"scroll to the end,load more......");
  1312. [self loadMore];
  1313. // self.btnLoad.hidden = NO;
  1314. }
  1315. }
  1316. else if(flowLayout.scrollDirection== UICollectionViewScrollDirectionHorizontal)
  1317. {
  1318. NSLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
  1319. NSLog(@"frame.size.height %f",frame.size.height);
  1320. NSLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
  1321. if (contentOffsetPoint.x == (self.collectionview.contentSize.width - frame.size.width) || self.collectionview.contentSize.width < frame.size.width)
  1322. {
  1323. if(self.isrefreshing)
  1324. return;
  1325. NSLog(@"scroll to the end,load more......");
  1326. [self loadMore];
  1327. // self.btnLoad.hidden = NO;
  1328. }
  1329. }
  1330. }
  1331. #pragma mark - UIAlertViewDelegate
  1332. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1333. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1334. {
  1335. UIApplication * app = [UIApplication sharedApplication];
  1336. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1337. // if(alertView.tag==1234)
  1338. // {
  1339. //
  1340. // // availability warring;
  1341. //
  1342. //
  1343. // if(buttonIndex!=alertView.cancelButtonIndex)
  1344. // {
  1345. // if(appDelegate.order_code==nil)
  1346. // {
  1347. // [self neworder];
  1348. // }
  1349. // else
  1350. // {
  1351. // [self addtocart];
  1352. // }
  1353. // }
  1354. // return;
  1355. // }
  1356. // int count=[self.quantity_text.text intValue];
  1357. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1358. if(buttonIndex==alertView.cancelButtonIndex)
  1359. {
  1360. }
  1361. else if(buttonIndex==1)
  1362. {
  1363. //open exist
  1364. self.disable_refresh = true;
  1365. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1366. ovc.showNavibar = true;
  1367. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1368. if(appDelegate.order_code==nil)
  1369. {
  1370. [self neworder];
  1371. }
  1372. else
  1373. {
  1374. [self addtocart];
  1375. // [main_vc checklogin:true];
  1376. }
  1377. };
  1378. ovc.init_style = OL_OPEN;
  1379. ovc.onCancel = ^(){
  1380. self.disable_refresh = false;
  1381. // [main_vc checklogin:true];
  1382. };
  1383. [self.navigationController pushViewController:ovc animated:true];
  1384. }
  1385. else
  1386. {
  1387. //create new;
  1388. self.disable_refresh = true;
  1389. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1390. {
  1391. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1392. cvc.showNavibar = true;
  1393. cvc.contact_type = @"Sales_Order_Customer";
  1394. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1395. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1396. appDelegate.customerInfo = value;
  1397. if(appDelegate.order_code==nil)
  1398. [self neworder];
  1399. // [main_vc checklogin:true];
  1400. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1401. //
  1402. // if(self.returnValue)
  1403. // self.returnValue(value);
  1404. };
  1405. cvc.onCancel = ^(){
  1406. [RAUtils message_alert:@"Can ot create order without cursomer infomation." title:@"" controller:self];
  1407. self.disable_refresh = false;
  1408. };
  1409. cvc.onReset = ^(){
  1410. // [main_vc checklogin:true];
  1411. };
  1412. [self.navigationController pushViewController:cvc animated:true];
  1413. }
  1414. else
  1415. {
  1416. [self neworder];
  1417. }
  1418. }
  1419. }
  1420. #pragma mark - Support scanner
  1421. -(void) onDecodedData:(NSString*) value
  1422. {
  1423. // UIApplication * app = [UIApplication sharedApplication];
  1424. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1425. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1426. //
  1427. self.searchBar.text = value;
  1428. self.keywords=self.searchBar.text;
  1429. self.offset = 0;
  1430. // [self.content_data removeAllObjects];
  1431. [self reload];
  1432. }
  1433. @end