SearchViewController.m 68 KB

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