CategoryViewController.m 69 KB

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