CategoryViewController.m 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555
  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 "CategorySearchFilterViewController.h"
  10. #import "DetailHeaderCell.h"
  11. #import "DetailImageCell.h"
  12. #import "RANetwork.h"
  13. #import "DetailTopicCell.h"
  14. #import "RTLabel.h"
  15. #import "DetailKVCell.h"
  16. #import "LineView.h"
  17. #import "PopupNavigationController.h"
  18. #import "RAViewController.h"
  19. #import "LoginViewController.h"
  20. #import "ContactListViewController.h"
  21. //#import "RAUtils.h"
  22. #import "OrderListViewController.h"
  23. //#import "CategoryCellLarge.h"
  24. //#import "CategoryCellSmall.h"
  25. #import "DetailViewController.h"
  26. #import "CategoryCellNPD.h"
  27. #import "DefaultAppearance.h"
  28. #import "MainViewController.h"
  29. //#import "ScannerViewController.h"
  30. #import "UIColor+JK_HEX.h"
  31. #import "CartUtils.h"
  32. #define DEF_CELL_HEIGHT 44
  33. #define DEF_TABLE_HEIGHT 44
  34. #define LINE_WIDTH 0
  35. #define CELL_MARGIN 0
  36. #define LABEL_MARGIN 5
  37. @interface CategoryViewController ()
  38. @property (nonatomic,assign) BOOL addAll;
  39. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  40. @property (nonatomic,assign) UIInterfaceOrientation toOrientation;///<屏幕将要旋转到的方向
  41. @end
  42. @implementation CategoryViewController
  43. - (NSOperationQueue *)dataOperationQueue {
  44. if (!_dataOperationQueue) {
  45. _dataOperationQueue = [[NSOperationQueue alloc] init];
  46. _dataOperationQueue.maxConcurrentOperationCount = 1;
  47. }
  48. return _dataOperationQueue;
  49. }
  50. -(void) logout
  51. {
  52. self.offset = 0;
  53. self.category_data=nil;
  54. }
  55. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  56. {
  57. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  58. if (self) {
  59. // Custom initialization
  60. }
  61. return self;
  62. }
  63. -(void)begin_select
  64. {
  65. // self.addCartBtn.enabled=false;
  66. // self.addWishBtn.enabled=false;
  67. // self.addPortfolioBtn.enabled=false;
  68. self.selectToolbar.hidden=false;
  69. // self.collectionview.allowsMultipleSelection = YES;
  70. self.isSelectionMode=true;
  71. self.select_count=0;
  72. }
  73. -(void)end_select:(int) type
  74. {
  75. self.select_count=0;
  76. self.selectToolbar.hidden=true;
  77. // self.collectionview.allowsMultipleSelection = NO;
  78. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  79. int count = [[items valueForKey:@"count"] intValue];
  80. for(int i=0;i<count;i++)
  81. {
  82. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  83. bool check = [[item valueForKey:@"checked"] boolValue];
  84. if(check)
  85. {
  86. switch (type) {
  87. case 1:
  88. item[@"wish_exists"]=@"true";
  89. break;
  90. case 2:
  91. item[@"cart_exists"]=@"true";
  92. break;
  93. default:
  94. break;
  95. }
  96. }
  97. [item setValue:@"false" forKey:@"checked"];
  98. [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
  99. }
  100. [self.category_data setObject:items forKey:@"items"];
  101. self.selectallBtn.tag = 0;
  102. [self.selectallBtn setTitle:@"Select"];
  103. self.isSelectionMode=false;
  104. if(self.disable_refresh)
  105. {
  106. self.disable_refresh = false;
  107. [self reload_container_getdata:true];
  108. }
  109. else
  110. [self.collectionview reloadData];
  111. // self.disable_refresh = false;
  112. }
  113. //- (void) changeSelectStateWithIndexPath: (NSIndexPath *) indexPath{
  114. // //获取当前变化的Cell
  115. // CategoryCellNPD *currentSelecteCell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  116. //
  117. // currentSelecteCell.selectButton.selected = currentSelecteCell.selected;
  118. //
  119. // if (currentSelecteCell.selected == YES){
  120. // DebugLog(@"第%ld个Section上第%ld个Cell被选中了",indexPath.section ,indexPath.row);
  121. // return;
  122. // }
  123. //
  124. // if (currentSelecteCell.selected == NO){
  125. // //DebugLog(@"第%ld个Section上第%ld个Cell取消选中",indexPath.section ,indexPath.row);
  126. // }
  127. //
  128. // }
  129. - (IBAction)onFilterClicked:(id)sender {
  130. UIApplication * app = [UIApplication sharedApplication];
  131. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  132. // if(appDelegate.offline_mode)
  133. // {
  134. // [RAUtils message_alert:@"offline mode does not support this function." title:@"Category Filter" controller:self] ;
  135. //
  136. // return;
  137. // }
  138. NSMutableDictionary* menu = [appDelegate.categoryMenu mutableCopy];
  139. CategorySearchFilterViewController * filterVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CategorySearchFilterViewController"];
  140. filterVC.categoryid = self.categoryid;
  141. filterVC.default_filter = [[self.category_data objectForKey:@"filter"] mutableCopy];
  142. filterVC.ids = self.categoryid;
  143. //----------fake category filter----------------
  144. // NSData* json =nil;
  145. // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"debug_category_filter" ofType:@"json" ]];
  146. // NSError *error=nil;
  147. // NSMutableDictionary* filter = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  148. // [self.category_data setObject:filter forKey:@"filter"];
  149. //----------fake category filter----------------
  150. filterVC.modelname=[[self.category_data objectForKey:@"filter"] valueForKey:@"model_name"];
  151. filterVC.modeldescrip=[[self.category_data objectForKey:@"filter"] valueForKey:@"model_description"];
  152. filterVC.categoryMenu = menu;
  153. filterVC.alert_cadedate =[[self.category_data objectForKey:@"filter"] objectForKey:@"alert"];
  154. filterVC.qty_cadedate=[[self.category_data objectForKey:@"filter"] objectForKey:@"qty"];
  155. filterVC.availability_cadedate=[[self.category_data objectForKey:@"filter"] objectForKey:@"availability"];
  156. filterVC.price_cadedate=[[self.category_data objectForKey:@"filter"] objectForKey:@"price"];
  157. filterVC.bestseller_cadedate=[[self.category_data objectForKey:@"filter"] objectForKey:@"best_seller"];
  158. filterVC.OkClick =^(NSString *ids,NSString* modelname,NSString* modeldescrip,NSString* available,NSString* QTY,NSString* alert,NSString* price,NSString* bestseller)
  159. {
  160. #ifdef BUILD_NPD
  161. NSArray *idArr = [ids componentsSeparatedByString:@","];
  162. if (idArr.count == 1) {
  163. self.categoryString = [@"Category" stringByAppendingString:[self categoryString:ids node:menu level:0]];
  164. } else {
  165. self.categoryString = @"Category>Multiple Category>";
  166. }
  167. // idArr = [idArr sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
  168. //
  169. // NSString *id0 = (NSString *)obj1;
  170. // NSString *id1 = (NSString *)obj2;
  171. //
  172. // if (id1.length > id0.length && [id1 hasPrefix:id0]) {
  173. // return NSOrderedAscending;
  174. // }
  175. //
  176. // return NSOrderedDescending;
  177. // return NSOrderedAscending;
  178. // }];
  179. //
  180. self.cagegoryLabel.text =self.categoryString;
  181. self.categoryid = ids;
  182. #endif
  183. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  184. NSArray *idArr = [ids componentsSeparatedByString:@","];
  185. if (idArr.count == 1) {
  186. self.categoryString = [@"Category" stringByAppendingString:[self categoryString:ids node:menu level:0]];
  187. } else {
  188. self.categoryString = @"Category>Multiple Category>";
  189. }
  190. self.cagegoryLabel.text =self.categoryString;
  191. self.categoryid = ids;
  192. #endif
  193. self.modelname = modelname;
  194. self.modeldescrip = modeldescrip;
  195. self.p_alert=alert;
  196. self.p_QTY=QTY;
  197. self.p_available=available;
  198. self.p_price=price;
  199. self.p_bestseller=bestseller;
  200. self.offset = 0;
  201. [self reload];
  202. };
  203. filterVC.ResetClick =^()
  204. {
  205. self.modelname = nil;
  206. self.modeldescrip = nil;
  207. self.p_alert=nil;
  208. self.p_QTY=nil;
  209. self.p_available=nil;
  210. self.p_price=nil;
  211. self.p_bestseller=nil;
  212. self.offset = 0;
  213. [self reload];
  214. };
  215. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:filterVC] ;
  216. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  217. [self presentViewController:navi animated:YES completion:^{
  218. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  219. DebugLog(@"bundle present.........");
  220. // self.btop = false;
  221. // <#code#>
  222. }];
  223. }
  224. - (IBAction)onSelectClick:(id)sender {
  225. [self begin_select];
  226. }
  227. - (IBAction)onCancelSelectClick:(id)sender {
  228. [self end_select:0];
  229. }
  230. - (IBAction)onSelectAllClick:(id)sender {
  231. // int tag =self.selectallBtn.tag;
  232. if(self.category_data==nil)
  233. return;
  234. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  235. if(items==nil)
  236. return;
  237. int count = [[items valueForKey:@"count"] intValue];
  238. NSString* checked;
  239. if (self.selectallBtn.tag == 0)
  240. {
  241. self.selectallBtn.tag = 1;
  242. [self.selectallBtn setTitle:@"Deselect"];
  243. if(count>0)
  244. {
  245. // self.addWishBtn.enabled = true;
  246. // self.addCartBtn.enabled = true;
  247. // self.addPortfolioBtn.enabled=true;
  248. }
  249. self.select_count=count;
  250. checked=@"true";
  251. }
  252. else
  253. {
  254. self.selectallBtn.tag = 0;
  255. [self.selectallBtn setTitle:@"Select"];
  256. // self.addWishBtn.enabled = false;
  257. // self.addCartBtn.enabled = false;
  258. // self.addPortfolioBtn.enabled=false;
  259. checked=@"false";
  260. }
  261. for(int i=0;i<count;i++)
  262. {
  263. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  264. [item setValue:checked forKey:@"checked"];
  265. [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
  266. }
  267. [self.category_data setObject:items forKey:@"items"];
  268. [self.collectionview reloadData];
  269. }
  270. - (IBAction)onAddCartClick:(id)sender {
  271. // self.add_to_cart_Handler();
  272. // self.handler = [self addtocart];
  273. //
  274. //
  275. //
  276. //
  277. [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
  278. return;
  279. UIApplication * app = [UIApplication sharedApplication];
  280. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  281. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  282. if(appDelegate.bLogin==false)
  283. {
  284. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  285. // loginvc.delegate = self;
  286. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  287. loginvc.returnValue = ^(bool blogin){
  288. // UIApplication * app = [UIApplication sharedApplication];
  289. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  290. if(blogin)
  291. {
  292. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
  293. {
  294. [main_vc checklogin:false];
  295. if(appDelegate.can_create_order)
  296. {
  297. NSString* msg =@"";
  298. if(appDelegate.contact_id.length>0)
  299. {
  300. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  301. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  302. }
  303. 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];
  304. // alert.
  305. [alert show];
  306. }
  307. else
  308. {
  309. 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];
  310. // alert.
  311. [alert show];
  312. }
  313. }
  314. else
  315. {
  316. [main_vc checklogin:false];
  317. [self addtocart];
  318. }
  319. }
  320. // self.offset = 0;
  321. // [self.content_data removeAllObjects];
  322. // [self loadpage];
  323. //
  324. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  325. };
  326. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  327. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  328. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  329. [self presentViewController:navi animated:YES completion:^{
  330. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  331. DebugLog(@"LoginViewController present.........");
  332. // self.btop = false;
  333. // <#code#>
  334. }];
  335. }
  336. else
  337. {
  338. if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&*//*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  339. {
  340. // [main_vc checklogin:false];
  341. if(appDelegate.can_create_order)
  342. {
  343. NSString* msg =@"";
  344. if(appDelegate.contact_id.length>0)
  345. {
  346. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  347. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  348. }
  349. 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];
  350. // alert.
  351. [alert show];
  352. }
  353. else
  354. {
  355. 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];
  356. // alert.
  357. [alert show];
  358. }
  359. }
  360. else
  361. {
  362. if(appDelegate.order_code==nil)
  363. [ self neworder];
  364. else
  365. [self addtocart];
  366. }
  367. }
  368. }
  369. -(void) neworder
  370. {
  371. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  372. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  373. NSDictionary* return_json = [RANetwork new_Order];
  374. dispatch_async(dispatch_get_main_queue(), ^{
  375. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  376. if([[return_json valueForKey:@"result"] intValue]==2)
  377. {
  378. int result=[[return_json valueForKey:@"result"] intValue];
  379. if(result==2)
  380. {
  381. //successed.
  382. NSString* order_code = [return_json valueForKey:@"orderCode"];
  383. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  384. appDelegate.order_code = order_code;
  385. [self addtocart];
  386. }
  387. }
  388. else
  389. {
  390. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  391. }
  392. });
  393. });
  394. }
  395. - (IBAction)onAddPortfolioClick:(id)sender {
  396. UIApplication * app = [UIApplication sharedApplication];
  397. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  398. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  399. if(appDelegate.bLogin==false)
  400. {
  401. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  402. // loginvc.delegate = self;
  403. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  404. loginvc.returnValue = ^(bool blogin){
  405. if(blogin)
  406. {
  407. [main_vc checklogin:false];
  408. [self checkToolBar];
  409. [self addtoportfolio];
  410. }
  411. };
  412. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  413. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  414. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  415. [self presentViewController:navi animated:YES completion:^{
  416. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  417. DebugLog(@"LoginViewController present.........");
  418. // self.btop = false;
  419. // <#code#>
  420. }];
  421. }
  422. else
  423. {
  424. [self addtoportfolio];
  425. }
  426. }
  427. - (IBAction)onAddWishlistClick:(id)sender {
  428. UIApplication * app = [UIApplication sharedApplication];
  429. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  430. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  431. if(appDelegate.bLogin==false)
  432. {
  433. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  434. // loginvc.delegate = self;
  435. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  436. loginvc.returnValue = ^(bool blogin){
  437. if(blogin)
  438. {
  439. [main_vc checklogin:false];
  440. [self addtowish];
  441. }
  442. };
  443. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  444. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  445. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  446. [self presentViewController:navi animated:YES completion:^{
  447. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  448. DebugLog(@"LoginViewController present.........");
  449. // self.btop = false;
  450. // <#code#>
  451. }];
  452. }
  453. else
  454. {
  455. [self addtowish];
  456. }
  457. }
  458. -(void) addtocart
  459. {
  460. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  461. int count = [[items valueForKey:@"count"] intValue];
  462. NSMutableArray* checked = [[NSMutableArray alloc] init];
  463. for(int i=0;i<count;i++)
  464. {
  465. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  466. bool check = [[item valueForKey:@"checked"] boolValue];
  467. if(check)
  468. {
  469. // [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  470. [checked addObject:[item valueForKey:@"name"]];
  471. }
  472. }
  473. //debug
  474. //[checked addObject:@"-123"];
  475. if (!count) {
  476. [RAUtils message_alert:@"There is no model." title:@"Cannot Add to cart." controller:self] ;
  477. return;
  478. }
  479. if(!self.addAll && checked.count==0)
  480. {
  481. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to cart." controller:self] ;
  482. return;
  483. }
  484. NSString * ids = [checked componentsJoinedByString:@","];
  485. self.addCartBtn.enabled = false;
  486. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Cart"];
  487. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  488. NSDictionary* return_json = nil;
  489. if (self.addAll) {
  490. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  491. return_json = [RANetwork Category_addall:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip orderCode:appDelegate.order_code addTo:@"cart"];
  492. } else {
  493. return_json = [RANetwork add_toCart_byName:ids withScreen:ScreenCodeCategory];
  494. }
  495. dispatch_async(dispatch_get_main_queue(), ^{
  496. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  497. self.addCartBtn.enabled = true;
  498. if([[return_json valueForKey:@"result"] intValue]==2)
  499. {
  500. int result=[[return_json valueForKey:@"result"] intValue];
  501. if(result==2)
  502. {
  503. //successed.
  504. // NSString* order_code = [return_json valueForKey:@"order_code"];
  505. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  506. // appDelegate.order_code = order_code;
  507. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  508. NSString * msg = nil;
  509. if (self.addAll) {
  510. unsigned long checkedCount = [return_json[@"count"] integerValue];
  511. msg=[NSString stringWithFormat:@"%lu items added to Cart",checkedCount];
  512. } else {
  513. if(checked.count==1)
  514. {
  515. msg=@"1 item added to Cart";
  516. }
  517. else
  518. {
  519. msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
  520. }
  521. }
  522. [RAUtils message_alert:nil title:msg controller:self] ;
  523. [self end_select:2];
  524. }
  525. }
  526. else if([[return_json valueForKey:@"result"] intValue]==8)
  527. {
  528. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  529. // appDelegate.order_code = order_code;
  530. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  531. [self end_select:2];
  532. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  533. }
  534. else
  535. {
  536. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  537. }
  538. });
  539. });
  540. }
  541. -(void) addtoportfolio
  542. {
  543. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  544. // if (appDelegate.offline_mode) {
  545. //
  546. // [RAUtils message_alert:@"offline mode does not support this function." title:@"Add to Portfolio" controller:self] ;
  547. // return;
  548. // }
  549. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  550. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  551. [RAUtils message_alert:@"Cannot Add to portfolio." title:@"Warning" controller:self] ;
  552. return;
  553. }
  554. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  555. int count = [[items valueForKey:@"count"] intValue];
  556. NSMutableArray* checked = [[NSMutableArray alloc] init];
  557. for(int i=0;i<count;i++)
  558. {
  559. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  560. bool check = [[item valueForKey:@"checked"] boolValue];
  561. if(check)
  562. {
  563. [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  564. }
  565. }
  566. if (!count) {
  567. [RAUtils message_alert:@"There is no model." title:@"Cannot Add to portfolio." controller:self] ;
  568. return;
  569. }
  570. if(!self.addAll && checked.count==0)
  571. {
  572. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to portfolio." controller:self] ;
  573. return;
  574. }
  575. NSString * ids = [checked componentsJoinedByString:@","];
  576. self.addPortfolioBtn.enabled =false;
  577. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Portfolio"];
  578. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  579. NSDictionary* return_json = nil;
  580. if (self.addAll) {
  581. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  582. return_json = [RANetwork Category_addall:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip orderCode:nil addTo:@"portfolio"];
  583. } else {
  584. return_json = [RANetwork add_toPortfolio:ids withScreen:ScreenCodeCategory];
  585. }
  586. dispatch_async(dispatch_get_main_queue(), ^{
  587. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  588. self.addPortfolioBtn.enabled =true;
  589. if([[return_json valueForKey:@"result"] intValue]==2)
  590. {
  591. // int result=[[return_json valueForKey:@"result"] intValue];
  592. // if(result==2)
  593. // {
  594. // //successed.
  595. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  596. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  597. NSString * msg = nil;
  598. if (self.addAll) {
  599. unsigned long checkedCount = [return_json[@"count"] integerValue];
  600. msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
  601. } else {
  602. if(checked.count==1)
  603. {
  604. msg=@"1 item added to Portfolio";
  605. }
  606. else
  607. {
  608. msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
  609. }
  610. }
  611. [RAUtils message_alert:nil title:msg controller:self] ;
  612. [self end_select:3 ];
  613. }
  614. else
  615. {
  616. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Portfolio" controller:self] ;
  617. }
  618. });
  619. });
  620. }
  621. -(void) addtowish
  622. {
  623. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  624. int count = [[items valueForKey:@"count"] intValue];
  625. NSMutableArray* checked = [[NSMutableArray alloc] init];
  626. for(int i=0;i<count;i++)
  627. {
  628. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  629. bool check = [[item valueForKey:@"checked"] boolValue];
  630. if(check)
  631. {
  632. [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
  633. }
  634. }
  635. if (!count) {
  636. [RAUtils message_alert:@"There is no model." title:@"Cannot Add to Wish List." controller:self] ;
  637. return;
  638. }
  639. if(!self.addAll && checked.count==0)
  640. {
  641. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to Wish List." controller:self] ;
  642. return;
  643. }
  644. NSString * ids = [checked componentsJoinedByString:@","];
  645. self.addWishBtn.enabled =false;
  646. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Add Models To Wish List"];
  647. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  648. NSDictionary* return_json = nil;
  649. if (self.addAll) {
  650. return_json = [RANetwork Category_addall:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip orderCode:nil addTo:@"wishlist"];
  651. } else {
  652. return_json = [RANetwork add_toWatchList:ids withScreen:ScreenCodeCategory];
  653. }
  654. dispatch_async(dispatch_get_main_queue(), ^{
  655. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  656. self.addWishBtn.enabled =true;
  657. if([[return_json valueForKey:@"result"] intValue]==2)
  658. {
  659. //successed.
  660. // NSString* order_code = [return_json valueForKey:@"order_code"];
  661. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  662. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  663. NSString * msg = nil;
  664. if (self.addAll) {
  665. unsigned long checkedCount = [return_json[@"count"] integerValue];
  666. msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
  667. } else {
  668. if(checked.count==1)
  669. {
  670. msg=@"1 item added to \nWish List";
  671. }
  672. else
  673. {
  674. msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
  675. }
  676. }
  677. [RAUtils message_alert:nil title:msg controller:self] ;
  678. [self end_select:1];
  679. }
  680. else
  681. {
  682. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Wish List" controller:self] ;
  683. }
  684. });
  685. });
  686. }
  687. #pragma mark get data
  688. -(void)operation_loadMore
  689. {
  690. if (self.dataOperationQueue.operationCount > 1) {
  691. return ;
  692. }
  693. dispatch_async(dispatch_get_main_queue(), ^{
  694. if(self.loadall)
  695. {
  696. if(self.showalert)
  697. {
  698. self.showalert=false;
  699. [RAUtils message_alert:@"All loaded" title:@"Loading Category" controller:self] ;
  700. }
  701. return;
  702. }
  703. self.mum.hidden = false;
  704. [self.mum startAnimating];
  705. self.mum.center = self.view.center;
  706. self.isrefreshing=true;
  707. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  708. NSDictionary* category_more=[RANetwork Category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip] ;
  709. dispatch_async(dispatch_get_main_queue(), ^{
  710. [self.mum stopAnimating];
  711. self.isrefreshing=false;
  712. if (self.dataOperationQueue.operationCount > 1) {
  713. return ;
  714. }
  715. NSDictionary* more_items=[category_more objectForKey:@"items"];
  716. if([[category_more valueForKey:@"result"] intValue]==2)
  717. {
  718. // self.category_data = category_data;
  719. NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
  720. int count =[[more_items valueForKey:@"count"] intValue];
  721. for(int i=0;i<count;i++)
  722. {
  723. NSDictionary * item_json = [more_items objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  724. [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
  725. }
  726. long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
  727. [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
  728. [self.category_data setObject:items_json forKey:@"items"];
  729. self.offset+=count;
  730. if(count<20)
  731. {
  732. self.loadall=true;
  733. }
  734. // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  735. // DebugLog(@"%@",self.category_data);
  736. [self.collectionview reloadData];
  737. }
  738. else
  739. {
  740. [RAUtils message_alert:[category_more valueForKey:@"err_msg"] title:@"Loading Category" controller:self] ;
  741. }
  742. // self.isrefreshing=false;
  743. });
  744. });
  745. });
  746. }
  747. - (void)loadMore {
  748. __weak typeof(self) weakself = self;
  749. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  750. if (weakself) {
  751. __strong typeof(weakself) strongself = weakself;
  752. [strongself operation_loadMore];
  753. }
  754. }];
  755. [self.dataOperationQueue addOperation:operation];
  756. }
  757. - (void)operation_reload {
  758. {
  759. if (self.dataOperationQueue.operationCount > 1) {
  760. return;
  761. }
  762. dispatch_async(dispatch_get_main_queue(), ^{
  763. if(self.isrefreshing)
  764. return;
  765. self.showalert=true;
  766. self.isrefreshing=true;
  767. self.loadall = false;
  768. // UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
  769. // UICollectionViewFlowLayout *flowLayout =[self.collectionview collectionViewLayout];
  770. // layout.scrollDirection= UICollectionViewScrollDirectionVertical;
  771. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  772. [reF endRefreshing];
  773. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  774. //
  775. //
  776. self.mum.hidden = false;
  777. [self.mum startAnimating];
  778. self.mum.center = self.view.center;
  779. self.label_net_err.hidden=true;
  780. self.collectionview.hidden=true;
  781. // self.collectionview.userInteractionEnabled = false;
  782. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  783. NSDictionary* category_data=[RANetwork Category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:0 limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price bestseller:self.p_bestseller modelname:self.modelname modeldescrip:self.modeldescrip];
  784. dispatch_async(dispatch_get_main_queue(), ^{
  785. [self.mum stopAnimating];
  786. self.isrefreshing=false;
  787. if (self.dataOperationQueue.operationCount > 1) {
  788. return ;
  789. }
  790. // self.collectionview.userInteractionEnabled = true;
  791. self.category_data = [category_data mutableCopy];
  792. [self.collectionview reloadData];
  793. if([[category_data valueForKey:@"result"] intValue]==2)
  794. {
  795. self.collectionview.hidden=false;
  796. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  797. self.offset =[[item_json valueForKey:@"count"] intValue];
  798. int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
  799. if(total<2)
  800. self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
  801. else
  802. self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
  803. }
  804. else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  805. {
  806. self.collectionview.hidden=true;
  807. self.label_net_err.hidden=false;
  808. }
  809. else
  810. {
  811. [RAUtils message_alert:[category_data valueForKey:@"err_msg"] title:@"Loading Category" controller:self] ;
  812. }
  813. });
  814. });
  815. });
  816. }
  817. }
  818. -(void) reload
  819. {
  820. __weak typeof(self) weakself = self;
  821. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  822. if (weakself) {
  823. __strong typeof(weakself) strongself = weakself;
  824. [strongself operation_reload];
  825. }
  826. }];
  827. [self.dataOperationQueue addOperation:operation];
  828. }
  829. #pragma mark - CategoryMenuDelegate
  830. -(void)SelectCategory:(NSString *)category
  831. {
  832. //[self switchToCagegory:category];
  833. }
  834. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  835. {
  836. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  837. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  838. if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  839. {
  840. self.orientation = orientation;
  841. [self.collectionview.collectionViewLayout invalidateLayout];
  842. DebugLog(@"routed");
  843. }
  844. }
  845. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  846. [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  847. self.toOrientation = toInterfaceOrientation;
  848. [self.collectionview.collectionViewLayout invalidateLayout];
  849. }
  850. - (IBAction)onCategoryClick:(id)sender {
  851. RAViewController * categorymenuVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"RAViewController"];
  852. // categorymenuVC.rootViewController = self;
  853. categorymenuVC.CateMenu_delegate = self;
  854. categorymenuVC.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  855. [self presentViewController:categorymenuVC animated:YES completion:^{
  856. DebugLog(@"login.........");
  857. // <#code#>
  858. }];
  859. [categorymenuVC SetMenu:self.categoryMenu];
  860. }
  861. //
  862. //- (IBAction)onSortClick:(id)sender {
  863. //
  864. //
  865. // NSMutableDictionary* sort_json = [self.category_data objectForKey:@"sort"];
  866. // // NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row ]];
  867. // // NSString* control = [item_json valueForKey:@"control"];
  868. // // if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"])
  869. // // {
  870. //
  871. // // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]];
  872. // // NSDictionary* cadedate_json = [sort_json objectForKey:@"cadedate"];
  873. // // NSDictionary* value_json = [item_json objectForKey:@"value"];
  874. // // NSString* single_select = [item_json valueForKey:@"single_select"];
  875. // // NSString* required =[item_json valueForKey:@"required"];
  876. //
  877. //
  878. //
  879. // EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  880. // // if([[required lowercaseString] isEqualToString:@"true"])
  881. // // enumvc.canbeEmpty = false;
  882. // // else
  883. // // enumvc.canbeEmpty =true;
  884. // enumvc.cadedate = [sort_json mutableCopy];
  885. // // enumvc.value = [value_json mutableCopy];
  886. // enumvc.single_select =true;
  887. // enumvc.auto_close = true;
  888. // enumvc.title = @"sort";
  889. // enumvc.is_dialog = true;
  890. //
  891. //
  892. // enumvc.returnValue = ^(NSMutableDictionary* value, int idx){
  893. // [self.category_data setObject:value forKey:@"sort"];
  894. // // DebugLog(@"点击了第%d个",pageIndex);
  895. // };
  896. //
  897. // /// PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:enumvc];
  898. //
  899. // // self.aBNewPersonNav = [[UINavigationController alloc] initWithRootViewController:enumvc] ;
  900. //
  901. // enumvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  902. //
  903. // // enumvc.delegate = self;
  904. // [self presentViewController:enumvc animated:YES completion:^{
  905. //
  906. // DebugLog(@"login.........");
  907. // // <#code#>
  908. // }];
  909. // // [self.navigationController pushViewController:enumvc animated:true];
  910. //
  911. //}
  912. -(void)viewWillLayoutSubviews
  913. {
  914. // if(self.showDetail==true)
  915. // {
  916. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  917. // int width=175;
  918. // // int height;
  919. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  920. // {
  921. // width = 370;
  922. // // height = 400;
  923. // }
  924. // else
  925. // {
  926. // // height = 300;
  927. // width = 175;
  928. // }
  929. //
  930. //
  931. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  932. //
  933. // self.collectionview.frame=frame;
  934. //
  935. //
  936. //
  937. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  938. // self.detailView.frame = framedetail;
  939. // }
  940. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  941. self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  942. }
  943. -(void) showCategory
  944. {
  945. if(self.showDetail==false)
  946. return;
  947. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  948. // int width=175;
  949. // // int height;
  950. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  951. // {
  952. // width = 370;
  953. // // height = 400;
  954. // }
  955. // else
  956. // {
  957. // // height = 300;
  958. // width = 175;
  959. // }
  960. //
  961. CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width
  962. , self.view.bounds.size.height-48);
  963. [UIView animateWithDuration:0.5 animations:^{ self.collectionview.frame=frame;
  964. }];
  965. self.collectionview.autoresizingMask = self.collectionview.autoresizingMask | UIViewAutoresizingFlexibleWidth;
  966. self.showDetail = false;
  967. self.cagegoryLabel.hidden = false;
  968. }
  969. - (IBAction)onChangeDisplay:(UIButton *)sender {
  970. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  971. flowLayout.scrollDirection= UICollectionViewScrollDirectionVertical;
  972. if(sender.tag==2&&self.categoryViewType != CATEGORY_VIEWTYPE_SMALL)
  973. {
  974. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  975. // [self.collectionview.collectionViewLayout invalidateLayout];
  976. // DebugLog(@"frame %f",self.collectionview.frame.size.height);
  977. // DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
  978. // DebugLog(@"content %f",self.collectionview.contentSize.height);
  979. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  980. [self.collectionview reloadData];
  981. // CGPoint offset = self.collectionview.contentOffset;
  982. // offset.y=pos*self.collectionview.contentSize.height;
  983. // self.collectionview.contentOffset=offset;
  984. }
  985. else if(sender.tag==3&&self.categoryViewType != CATEGORY_VIEWTYPE_LARGE)
  986. {
  987. self.categoryViewType = CATEGORY_VIEWTYPE_LARGE;
  988. // DebugLog(@"frame %f",self.collectionview.frame.size.height);
  989. // DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
  990. // DebugLog(@"content %f",self.collectionview.contentSize.height);
  991. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  992. // [self.collectionview reloadData];
  993. // [self.collectionview.collectionViewLayout invalidateLayout];
  994. [self.collectionview reloadData];
  995. // CGPoint offset = self.collectionview.contentOffset;
  996. // offset.y=pos*self.collectionview.contentSize.height;
  997. // self.collectionview.contentOffset=offset;
  998. //
  999. // self.collectionview move
  1000. }
  1001. else if(sender.tag==4&&self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
  1002. {
  1003. self.categoryViewType = CATEGORY_VIEWTYPE_LIST;
  1004. // DebugLog(@"frame %f",self.collectionview.frame.size.height);
  1005. // DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
  1006. // DebugLog(@"content %f",self.collectionview.contentSize.height);
  1007. // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
  1008. // [self.collectionview reloadData];
  1009. // [self.collectionview.collectionViewLayout invalidateLayout];
  1010. [self.collectionview reloadData];
  1011. // CGPoint offset = self.collectionview.contentOffset;
  1012. // offset.y=pos*self.collectionview.contentSize.height;
  1013. // self.collectionview.contentOffset=offset;
  1014. //
  1015. // self.collectionview move
  1016. }
  1017. [self showCategory];
  1018. // [self showCategory];
  1019. }
  1020. - (void)checkToolBar {
  1021. // customer 隐藏add to portfolio
  1022. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1023. NSMutableArray *items = [self.selectToolbar.items mutableCopy];
  1024. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1025. if ([items containsObject:self.addPortfolioBtn]) {
  1026. [items removeObject:self.addPortfolioBtn];
  1027. self.selectToolbar.items = items;
  1028. }
  1029. } else {
  1030. if (![items containsObject:self.addPortfolioBtn]) {
  1031. [items insertObject:self.addPortfolioBtn atIndex:4];
  1032. self.selectToolbar.items = items;
  1033. }
  1034. }
  1035. }
  1036. - (void)viewWillAppear:(BOOL)animated
  1037. {
  1038. [super viewWillAppear:animated];
  1039. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  1040. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1041. //
  1042. // [appDelegate test_onDecodedDataResult:@"371252"];
  1043. [self checkToolBar];
  1044. self.toOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1045. // [self.collectionview scrollToItemAtIndexPath:self.selectedIndexPath atScrollPosition:16 animated:YES];
  1046. [self.collectionview layoutIfNeeded];
  1047. }
  1048. - (void)viewWillDisappear:(BOOL)animated {
  1049. [super viewWillDisappear:animated];
  1050. }
  1051. - (void)viewDidLoad
  1052. {
  1053. [super viewDidLoad];
  1054. self.toOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1055. self.refresh_type = REFRESH_NONE;
  1056. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  1057. self.label_net_err.layer.borderWidth = 2.0;
  1058. self.label_net_err.layer.cornerRadius=15;
  1059. self.label_net_err.layer.masksToBounds=true;
  1060. self.addWishBtn.enabled = true;
  1061. self.addCartBtn.enabled = true;
  1062. self.addPortfolioBtn.enabled=true;
  1063. CGPoint center = self.mum.center;
  1064. self.mum.frame = CGRectMake(0, 0, 100, 100);
  1065. self.mum.center = center;
  1066. self.mum.backgroundColor = [UIColor colorWithHEX:0xA5A5A5 alpha:0.5];
  1067. self.mum.layer.cornerRadius = 5.0f;
  1068. self.mum.layer.masksToBounds = YES;
  1069. self.addAll = NO;
  1070. [self.addAllCheckBtn setImage:[[UIImage imageNamed:@"check_0_24"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1071. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  1072. // tap.minimumPressDuration = 0.8; //定义按的时间
  1073. [self.label_net_err addGestureRecognizer:tap];
  1074. // self.detailView.hidden = true;
  1075. self.selectallBtn.possibleTitles = [NSSet setWithObjects:@"Selece", @"Deselect", nil];
  1076. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  1077. UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
  1078. CGSize cellsize = CGSizeMake(175, 250);
  1079. layout.itemSize =cellsize;
  1080. layout.minimumLineSpacing = 15;
  1081. self.collectionview.collectionViewLayout = layout;
  1082. //
  1083. self.display_type = [[NSMutableDictionary alloc] init];
  1084. [self.display_type setValue:@3 forKey:@"count"];
  1085. NSMutableDictionary* val_0 = [[NSMutableDictionary alloc] init];
  1086. [val_0 setValue:@1 forKey:@"check"];
  1087. [val_0 setValue:@"small icon" forKey:@"value"];
  1088. [val_0 setValue:@"" forKey:@"img"];
  1089. [self.display_type setObject:val_0 forKey:@"val_0"];
  1090. NSMutableDictionary* val_1 = [[NSMutableDictionary alloc] init];
  1091. [val_1 setValue:@0 forKey:@"check"];
  1092. [val_1 setValue:@"large icon" forKey:@"value"];
  1093. [val_1 setValue:@"" forKey:@"img"];
  1094. [self.display_type setObject:val_1 forKey:@"val_1"];
  1095. NSMutableDictionary* val_2 = [[NSMutableDictionary alloc] init];
  1096. [val_2 setValue:@2 forKey:@"check"];
  1097. [val_2 setValue:@"detail" forKey:@"value"];
  1098. [val_2 setValue:@"" forKey:@"img"];
  1099. [self.display_type setObject:val_2 forKey:@"val_2"];
  1100. // self.collectionview.
  1101. self.cagegoryLabel.text = self.categoryString;
  1102. self.showDetail = false;
  1103. //添加边框
  1104. // CALayer *layer = [self.collectionview layer];
  1105. // layer.borderColor = [[UIColor redColor] CGColor];
  1106. // layer.borderWidth = 5.0f;
  1107. self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
  1108. self.headerView.layer.masksToBounds = false;
  1109. //添加四个边阴影
  1110. self.headerView.layer.shadowColor = [UIColor grayColor].CGColor;
  1111. self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
  1112. self.headerView.layer.shadowOpacity = 0.5;
  1113. self.headerView.layer.shadowRadius = 2.0;
  1114. //添加两个边阴影
  1115. self.collectionview.layer.masksToBounds = false;
  1116. self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  1117. self.collectionview.layer.shadowColor = [UIColor grayColor].CGColor;
  1118. self.collectionview.layer.shadowOffset = CGSizeMake(0, 0);
  1119. self.collectionview.layer.shadowOpacity = 0.5;
  1120. self.collectionview.layer.shadowRadius = 2.0;
  1121. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  1122. ref.tag = 200 ;
  1123. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  1124. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  1125. // ref.hidden = true;
  1126. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  1127. [self.collectionview addSubview:ref];
  1128. //
  1129. // self.detailTable.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.detailTable.bounds.size.width, 0.0001)];
  1130. // // self.detailTable.sectionHeaderHeight = 0.0001;
  1131. // self.detailTable.sectionFooterHeight = 0.0001;
  1132. // self.detailTable.dis
  1133. // self.detailTable.tableHeaderView
  1134. //self.automaticallyAdjustsScrollViewInsets = false;
  1135. //self.edgesForExtendedLayout = UIRectEdgeNone;
  1136. //detailview
  1137. //
  1138. // self.photoStack = [self.storyboard instantiateViewControllerWithIdentifier:@"PhotoStackViewController"];
  1139. //
  1140. // self.photoStack.view.frame =CGRectMake(0, 0, self.detailView.frame.size.width, 400);
  1141. // //view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  1142. //// [self.photoStack itemCount:8];
  1143. //// self.photoStack.view.frame = CGRectMake(0, 330, width, 2 * 230+29+20+20);
  1144. //// self.photoStack.TopicCollection.frame =CGRectMake(0, 20+29, width, 2 * 230);
  1145. //// self.photoStack.topicTitle.text = @"New!";
  1146. //
  1147. // [self.detailView addSubview:self.photoStack.view];
  1148. //
  1149. // Do any additional setup after loading the view.
  1150. }
  1151. -(void)manually_refresh
  1152. {
  1153. UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
  1154. // UIRefreshControl *reF1 = (UIRefreshControl *)[self.view viewWithTag:200];
  1155. //
  1156. //
  1157. // UIViewController* vc1=[RAUtils getViewController:reF];
  1158. // UIViewController* vc2=[RAUtils getViewController:reF1];
  1159. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  1160. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  1161. // DebugLog(@"refresh!!!!!!!!");
  1162. }
  1163. -(void) ReloadData
  1164. {
  1165. UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
  1166. [reF endRefreshing];
  1167. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  1168. [self reload];
  1169. }
  1170. - (void)didReceiveMemoryWarning
  1171. {
  1172. [super didReceiveMemoryWarning];
  1173. // Dispose of any resources that can be recreated.
  1174. }
  1175. #pragma mark -- UICollectionViewDataSource
  1176. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  1177. {
  1178. // 每个Section的item个数
  1179. NSDictionary * item_json = [self.category_data objectForKey:@"items"];
  1180. int count =[[item_json valueForKey:@"count"] intValue];
  1181. return count;
  1182. }
  1183. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  1184. {
  1185. return 1;
  1186. }
  1187. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  1188. {
  1189. NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
  1190. if(value==nil)
  1191. value=@"";
  1192. unsigned long color = strtoul([value UTF8String],0,16);
  1193. if(self.categoryViewType == CATEGORY_VIEWTYPE_SMALL)
  1194. {
  1195. static NSString * CellIdentifier = @"CategoryCellNPD";
  1196. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  1197. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1198. // NSString* img_url =[item_json valueForKey:@"img"];
  1199. NSString* description =[item_json valueForKey:@"description"];
  1200. NSString* name =[item_json valueForKey:@"name"];
  1201. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  1202. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  1203. bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
  1204. BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
  1205. cell.mark_moreColor.hidden = !more_color;
  1206. if(wish_exist)
  1207. cell.mark_wish.hidden=false;
  1208. else
  1209. cell.mark_wish.hidden=true;
  1210. if(cart_exists)
  1211. cell.mark_order.hidden=false;
  1212. else
  1213. cell.mark_order.hidden=true;
  1214. if(closeout)
  1215. cell.mark_closeout.hidden=false;
  1216. else
  1217. cell.mark_closeout.hidden=true;
  1218. // NSString* old_price =[item_json valueForKey:@"old_price"];
  1219. // NSString* price =[item_json valueForKey:@"price"];
  1220. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  1221. if(!checked)
  1222. {
  1223. cell.checkImageView.hidden = true;
  1224. [cell setBackgroundColor:[UIColor whiteColor]/* UIColorFromRGB(0x996633)*/];
  1225. }
  1226. else
  1227. {
  1228. cell.checkImageView.hidden = false;
  1229. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1230. }
  1231. cell.nameLabel.text = description;
  1232. cell.modelNoLabel.text=name;
  1233. // cell.cellDescription.text = description;
  1234. // cell.oldPrice.text = old_price;
  1235. // cell.Price.text = price;
  1236. cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  1237. cell.layer.borderWidth = 0.5;
  1238. //cell.layer.cornerRadius=15;
  1239. cell.layer.masksToBounds=true;
  1240. return cell;
  1241. }
  1242. else if(self.categoryViewType == CATEGORY_VIEWTYPE_LARGE)
  1243. {
  1244. static NSString * CellIdentifier = @"CategoryCellNPDLarge";
  1245. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  1246. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1247. // NSString* img_url =[item_json valueForKey:@"img_big"];
  1248. NSString* description =[item_json valueForKey:@"description"];
  1249. NSString* name =[item_json valueForKey:@"name"];
  1250. // NSString* old_price =[item_json valueForKey:@"old_price"];
  1251. // NSString* price =[item_json valueForKey:@"price"];
  1252. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  1253. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  1254. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  1255. bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
  1256. BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
  1257. cell.mark_moreColor.hidden = !more_color;
  1258. if(wish_exist)
  1259. cell.mark_wish.hidden=false;
  1260. else
  1261. cell.mark_wish.hidden=true;
  1262. if(cart_exists)
  1263. cell.mark_order.hidden=false;
  1264. else
  1265. cell.mark_order.hidden=true;
  1266. if(closeout)
  1267. cell.mark_closeout.hidden=false;
  1268. else
  1269. cell.mark_closeout.hidden=true;
  1270. if(!checked)
  1271. {
  1272. cell.checkImageView.hidden = true;
  1273. [cell setBackgroundColor: /*UIColorFromRGB(0x996633)*/[UIColor whiteColor]];
  1274. }
  1275. else
  1276. {
  1277. cell.checkImageView.hidden = false;
  1278. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1279. }
  1280. cell.nameLabel.text = description;
  1281. cell.modelNoLabel.text=name;
  1282. // cell.cellDescription.text = description;
  1283. // cell.oldPrice.text = old_price;
  1284. // cell.Price.text = price;
  1285. cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  1286. cell.layer.borderWidth = 0.5;
  1287. //cell.layer.cornerRadius=15;
  1288. cell.layer.masksToBounds=true;
  1289. return cell;
  1290. }
  1291. else
  1292. {
  1293. static NSString * CellIdentifier = @"CategoryCellNPDList";
  1294. CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  1295. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1296. // NSString* img_url =[item_json valueForKey:@"img"];
  1297. NSString* description =[item_json valueForKey:@"description"];
  1298. NSString* name =[item_json valueForKey:@"name"];
  1299. bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
  1300. bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
  1301. bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
  1302. BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
  1303. cell.mark_moreColor.hidden = !more_color;
  1304. if(wish_exist)
  1305. cell.mark_wish.hidden=false;
  1306. else
  1307. cell.mark_wish.hidden=true;
  1308. if(cart_exists)
  1309. cell.mark_order.hidden=false;
  1310. else
  1311. cell.mark_order.hidden=true;
  1312. if(closeout)
  1313. cell.mark_closeout.hidden=false;
  1314. else
  1315. cell.mark_closeout.hidden=true;
  1316. // NSString* old_price =[item_json valueForKey:@"old_price"];
  1317. // NSString* price =[item_json valueForKey:@"price"];
  1318. bool checked =[[item_json valueForKey:@"checked"] boolValue];
  1319. if(!checked)
  1320. {
  1321. cell.checkImageView.hidden = true;
  1322. [cell setBackgroundColor: [UIColor whiteColor]];
  1323. }
  1324. else
  1325. {
  1326. cell.checkImageView.hidden = false;
  1327. [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1328. }
  1329. cell.nameLabel.text = description;
  1330. cell.modelNoLabel.text=name;
  1331. // cell.cellDescription.text = description;
  1332. // cell.oldPrice.text = old_price;
  1333. // cell.Price.text = price;
  1334. cell.layer.borderColor = UIColorFromRGB(color).CGColor;
  1335. cell.layer.borderWidth = 0.5;
  1336. // cell.layer.cornerRadius=15;
  1337. cell.layer.masksToBounds=true;
  1338. return cell;
  1339. }
  1340. }
  1341. - (void)collectionCell:(CategoryCellNPD *)cell setImageForIndexPath:(NSIndexPath *)indexPath {
  1342. NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1343. NSString* img_url =[item_json valueForKey:@"img"];
  1344. NSString* file_name=[img_url lastPathComponent];
  1345. NSString *loading = @"loading_l";
  1346. NSString *notFound = @"notfound_l";
  1347. if (self.categoryViewType == CATEGORY_VIEWTYPE_LARGE) {
  1348. loading = @"loading_l";
  1349. notFound = @"notfound_l";
  1350. } else if (self.categoryViewType == CATEGORY_VIEWTYPE_SMALL) {
  1351. loading = @"loading_s";
  1352. notFound = @"notfound_s";
  1353. }
  1354. if (![cell.imageName isEqualToString:img_url]) {
  1355. cell.imageName = img_url;
  1356. cell.cellImageView.image = [UIImage imageNamed:loading];
  1357. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1358. if(img_data!=nil)
  1359. {
  1360. UIImage * img =[UIImage imageWithData:img_data];
  1361. cell.cellImageView.image = img;
  1362. }
  1363. else
  1364. {
  1365. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1366. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1367. NSData* downloadimg_data = nil;
  1368. BOOL offline = NO;
  1369. #ifdef OFFLINE_MODE
  1370. offline = appDelegate.offline_mode;
  1371. #endif
  1372. if (!offline) {
  1373. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1374. }
  1375. dispatch_async(dispatch_get_main_queue(), ^{
  1376. if(downloadimg_data!=nil)
  1377. {
  1378. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1379. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1380. cell.cellImageView.image = img;
  1381. }
  1382. else
  1383. cell.cellImageView.image = [UIImage imageNamed:notFound];
  1384. });
  1385. });
  1386. }
  1387. }
  1388. }
  1389. - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
  1390. CategoryCellNPD * son_cell = (CategoryCellNPD *)cell;
  1391. son_cell.imageName = nil;
  1392. [self collectionCell:son_cell setImageForIndexPath:indexPath];
  1393. }
  1394. - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
  1395. CategoryCellNPD * son_cell = (CategoryCellNPD *)cell;
  1396. NSString *loading = @"loading_l";
  1397. if (self.categoryViewType == CATEGORY_VIEWTYPE_LARGE) {
  1398. loading = @"loading_l";
  1399. } else if (self.categoryViewType == CATEGORY_VIEWTYPE_SMALL) {
  1400. loading = @"loading_s";
  1401. }
  1402. son_cell.cellImageView.image = [UIImage imageNamed:loading];
  1403. }
  1404. #pragma mark --UICollectionViewDelegateFlowLayout
  1405. ////定义每个UICollectionView 的大小
  1406. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  1407. //{
  1408. // return CGSizeMake(96, 100);
  1409. //}
  1410. //定义每个UICollectionView 的 margin
  1411. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  1412. {
  1413. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  1414. orientation = self.toOrientation; // 避免横排转竖屏时UICollectionViewFlowLayoutBreakForInvalidSizes警告
  1415. if (UIInterfaceOrientationIsLandscape(orientation))
  1416. {
  1417. // DebugLog(@"横");
  1418. // if(self.showDetail)
  1419. // return CGSizeMake(96, 100);
  1420. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1421. return CGSizeMake(328, 391);
  1422. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1423. return CGSizeMake(1024, 120);
  1424. return CGSizeMake(193, 269);
  1425. }
  1426. else if(UIInterfaceOrientationIsPortrait(orientation))
  1427. {
  1428. // DebugLog(@"竖");
  1429. // if(self.showDetail)
  1430. // return CGSizeMake(96, 100);
  1431. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1432. return CGSizeMake(369, 440);
  1433. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1434. return CGSizeMake(768, 120);
  1435. return CGSizeMake(180, 251);
  1436. }
  1437. DebugLog(@"error , %ld",(long)orientation );
  1438. return CGSizeMake(96, 100);
  1439. }
  1440. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  1441. {
  1442. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1443. return 1;
  1444. return 15;
  1445. }
  1446. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  1447. {
  1448. if(self.showDetail)
  1449. return UIEdgeInsetsMake(10, 5, 10, 5);
  1450. // if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1451. // return UIEdgeInsetsMake(1, 1, 1, 1);
  1452. if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
  1453. return UIEdgeInsetsMake(10, 10, 10, 10);
  1454. else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
  1455. return UIEdgeInsetsMake(10, 0, 10, 0);
  1456. return UIEdgeInsetsMake(10, 10, 10, 10);
  1457. return UIEdgeInsetsMake(10, 10, 10, 10);
  1458. }
  1459. -(void) reload_container_getdata:(bool) update_data
  1460. {
  1461. if(self.disable_refresh)
  1462. return;
  1463. [super reload_container_getdata:update_data];
  1464. if(update_data)
  1465. {
  1466. [self reload];
  1467. }
  1468. else
  1469. {
  1470. [self.collectionview reloadData];
  1471. }
  1472. // if(!self.showDetail)
  1473. // return;
  1474. // NSArray* a= self.childViewControllers;
  1475. //
  1476. // for (int i=0;i<a.count;i++)
  1477. // {
  1478. // if([a[i] isKindOfClass:[DetailViewController class]])
  1479. // {
  1480. // DetailViewController *detailvc=a[i];
  1481. // [detailvc reload];
  1482. // }
  1483. // }
  1484. }
  1485. #pragma mark --UICollectionViewDelegate
  1486. -(void) showDetailat:(NSString*) item_id category_id:(NSString*) category_id name:(NSString *)name index:(long)index
  1487. {
  1488. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  1489. // dvc
  1490. dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
  1491. {
  1492. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1493. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",index]] mutableCopy];
  1494. if(add_cart)
  1495. item[@"cart_exists"]=@"true";
  1496. if(add_wish)
  1497. item[@"wish_exists"]=@"true";
  1498. items[[NSString stringWithFormat:@"item_%ld",index]] = item;
  1499. self.category_data[@"items"]=items;
  1500. // [self reload_container:update_data];
  1501. [self.collectionview reloadData];
  1502. };
  1503. // dvc.use_model_name = true;
  1504. // dvc.model_name=[transformed stringValue];
  1505. dvc.product_id = item_id;
  1506. dvc.category_id=category_id;
  1507. dvc.ispush = true;
  1508. dvc.model_name = name;
  1509. [dvc reload];
  1510. [self.navigationController pushViewController:dvc animated:true];
  1511. return;
  1512. //一下为detail嵌入当前窗口的方式
  1513. /*
  1514. self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
  1515. //[self.collectionview.collectionViewLayout invalidateLayout];
  1516. [self.collectionview reloadData];
  1517. UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  1518. int width=175;
  1519. // int height;
  1520. if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  1521. {
  1522. width = 370;
  1523. // height = 400;
  1524. }
  1525. else
  1526. {
  1527. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  1528. flowLayout.scrollDirection= UICollectionViewScrollDirectionHorizontal;
  1529. // [self.collectionview ] set
  1530. // height = 251;
  1531. width = 180;
  1532. }
  1533. CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width, 271);
  1534. CGRect framedetail = CGRectMake(0,271 ,self.view.bounds.size.width,self.view.bounds.size.height-271);
  1535. [UIView animateWithDuration:0.5 animations:^{
  1536. self.collectionview.frame=frame;
  1537. self.detailView.frame = framedetail;
  1538. // self.cagegoryLabel.hidden = true;
  1539. }];
  1540. self.collectionview.autoresizingMask = self.collectionview.autoresizingMask ^ UIViewAutoresizingFlexibleWidth;
  1541. self.showDetail = true;
  1542. NSArray* a= self.childViewControllers;
  1543. for (int i=0;i<a.count;i++)
  1544. {
  1545. if([a[i] isKindOfClass:[DetailViewController class]])
  1546. {
  1547. DetailViewController *detailvc=a[i];
  1548. detailvc.category_id = self.categoryid;
  1549. detailvc.product_id = item_id;
  1550. detailvc.ispush=false;
  1551. [detailvc reload];
  1552. }
  1553. }
  1554. */
  1555. }
  1556. //UICollectionView被选中时调用的方法
  1557. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  1558. {
  1559. // [self.collectionview cellForItemAtIndexPath:indexPath];
  1560. // self showdetail
  1561. NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1562. NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1563. if(self.isSelectionMode)
  1564. {
  1565. bool checked =[[item valueForKey:@"checked"] boolValue];
  1566. CategoryCellNPD *currentSelecteCell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  1567. if(checked)
  1568. {
  1569. self.select_count--;
  1570. if(self.select_count==0)
  1571. {
  1572. // self.addWishBtn.enabled = false;
  1573. // self.addCartBtn.enabled = false;
  1574. // self.addPortfolioBtn.enabled = false;
  1575. }
  1576. [item setValue:@"false" forKey:@"checked"];
  1577. currentSelecteCell.checkImageView.hidden = true;
  1578. if(self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
  1579. [currentSelecteCell setBackgroundColor: /*UIColorFromRGB(0x996633)*/[UIColor whiteColor]];
  1580. else
  1581. [currentSelecteCell setBackgroundColor: [UIColor whiteColor]];
  1582. }
  1583. else
  1584. {
  1585. self.select_count++;
  1586. // self.addWishBtn.enabled = true;
  1587. // self.addCartBtn.enabled = true;
  1588. // self.addPortfolioBtn.enabled = true;
  1589. [item setValue:@"true" forKey:@"checked"];
  1590. currentSelecteCell.checkImageView.hidden = false;
  1591. [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x009966)];
  1592. }
  1593. [items setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1594. [self.category_data setObject:items forKey:@"items"];
  1595. }
  1596. else
  1597. {
  1598. NSString* detail_id= [NSString stringWithFormat:@"%@", [item valueForKey:@"product_id"] ] ;
  1599. NSString *item_category_id = [item valueForKey:@"item_category_id"];
  1600. #ifndef BUILD_NPD
  1601. item_category_id = self.categoryid;
  1602. #endif
  1603. #ifndef BUILD_HOMER
  1604. item_category_id = self.categoryid;
  1605. #endif
  1606. #ifndef BUILD_GATIT
  1607. item_category_id = self.categoryid;
  1608. #endif
  1609. [self showDetailat:detail_id category_id:item_category_id name:[item valueForKey:@"name"] index:indexPath.row];
  1610. }
  1611. // UICollectionViewCell * cell = (UICollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
  1612. // cell.backgroundColor = [UIColor whiteColor];
  1613. }
  1614. //
  1615. //- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
  1616. //{
  1617. // NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1618. //
  1619. // NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1620. //
  1621. // if(self.isSelectionMode)
  1622. // {
  1623. // bool checked =[[item valueForKey:@"checked"] boolValue];
  1624. //
  1625. // CategoryCellNPD *currentSelecteCell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  1626. //
  1627. //
  1628. // // if(checked)
  1629. // {
  1630. // [item setValue:@"false" forKey:@"checked"];
  1631. //
  1632. // currentSelecteCell.checkImageView.hidden = true;
  1633. // }
  1634. // // else
  1635. // // {
  1636. // // [item setValue:@"true" forKey:@"checked"];
  1637. // // currentSelecteCell.checkImageView.hidden = false;
  1638. // // }
  1639. // [items setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1640. // [self.category_data setObject:items forKey:@"items"];
  1641. //
  1642. //
  1643. // }
  1644. // else
  1645. // {
  1646. // NSString* detail_id= [item valueForKey:@"product_id"] ;
  1647. //
  1648. // [self showDetailat:detail_id category_id:nil];
  1649. // }
  1650. //}
  1651. //
  1652. ////- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
  1653. ////{
  1654. //// if(self.isSelectionMode)
  1655. //// {
  1656. //// bool checked= [[[[self.category_data objectForKey:@"items"] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]valueForKey:@"checked"] boolValue] ;
  1657. //// return checked;
  1658. //// }
  1659. //// return true;
  1660. ////}
  1661. //- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
  1662. //{
  1663. //
  1664. // NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1665. //
  1666. // NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1667. //
  1668. // if(self.isSelectionMode)
  1669. // {
  1670. // bool checked =[[item valueForKey:@"checked"] boolValue];
  1671. //
  1672. // CategoryCellNPD *cell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  1673. //
  1674. //
  1675. // if(!checked)
  1676. // {
  1677. // [cell setBackgroundColor: UIColorFromRGB(0x009966)];
  1678. // }
  1679. // else
  1680. // {
  1681. //[cell setBackgroundColor: UIColorFromRGB(0x996633)];
  1682. // }
  1683. //
  1684. //
  1685. //
  1686. // }
  1687. //
  1688. //// CategoryCellNPD *cell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  1689. //// DebugLog(@"%d,%d",indexPath.section,indexPath.row);
  1690. //// [cell setBackgroundColor: [UIColor redColor]];//UIColorFromRGB(0xf2f2f2)];
  1691. //}
  1692. //- (void)collectionView:(UICollectionView *)colView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
  1693. //{
  1694. // CategoryCellNPD *cell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
  1695. //
  1696. // DebugLog(@"%d,%d",indexPath.section,indexPath.row);
  1697. // //设置(Nomal)正常状态下的颜色
  1698. // [cell setBackgroundColor: UIColorFromRGB(0x996633)];
  1699. //}
  1700. #pragma mark SearchFilterDelegate
  1701. -(void) SearchFilterReturn:(NSMutableDictionary *)value
  1702. {
  1703. self.filter_val = value;
  1704. }
  1705. #pragma mark Deferred image loading (UIScrollViewDelegate)
  1706. //// Load images for all onscreen rows when scrolling is finished
  1707. //- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  1708. //{
  1709. // if (!decelerate)
  1710. // {
  1711. // DebugLog(@"scrollViewDidEndDragging LOADMORE");
  1712. // }
  1713. //}
  1714. //
  1715. //- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  1716. //{
  1717. // DebugLog(@"scrollViewDidEndDecelerating LOADMORE");
  1718. //}
  1719. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  1720. // [refreshHeaderViewegoRefreshScrollViewDidScroll:scrollView];//下拉刷新
  1721. CGPoint contentOffsetPoint = self.collectionview.contentOffset;
  1722. CGRect frame =self.collectionview.frame;
  1723. CGSize size123 =self.collectionview.contentSize;
  1724. UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
  1725. if(flowLayout.scrollDirection== UICollectionViewScrollDirectionVertical)
  1726. {
  1727. // DebugLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
  1728. // DebugLog(@"frame.size.height %f",frame.size.height);
  1729. // DebugLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
  1730. if (contentOffsetPoint.y == (self.collectionview.contentSize.height - frame.size.height) /*|| self.collectionview.contentSize.height < frame.size.height*/)
  1731. {
  1732. if(self.isrefreshing)
  1733. return;
  1734. DebugLog(@"scroll to the end,load more......");
  1735. [self loadMore];
  1736. // self.btnLoad.hidden = NO;
  1737. }
  1738. }
  1739. else if(flowLayout.scrollDirection== UICollectionViewScrollDirectionHorizontal)
  1740. {
  1741. // DebugLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
  1742. // DebugLog(@"frame.size.height %f",frame.size.height);
  1743. // DebugLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
  1744. if (contentOffsetPoint.x == (self.collectionview.contentSize.width - frame.size.width) /*|| self.collectionview.contentSize.width < frame.size.width*/)
  1745. {
  1746. if(self.isrefreshing)
  1747. return;
  1748. DebugLog(@"scroll to the end,load more......");
  1749. [self loadMore];
  1750. // self.btnLoad.hidden = NO;
  1751. }
  1752. }
  1753. }
  1754. #pragma mark - UIAlertViewDelegate
  1755. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  1756. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1757. {
  1758. UIApplication * app = [UIApplication sharedApplication];
  1759. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1760. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1761. if(buttonIndex==alertView.cancelButtonIndex)
  1762. {
  1763. }
  1764. else if(buttonIndex==1)
  1765. {
  1766. //open exist
  1767. self.disable_refresh = true;
  1768. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  1769. ovc.showNavibar = true;
  1770. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  1771. if(appDelegate.order_code==nil)
  1772. {
  1773. [self neworder];
  1774. }
  1775. else
  1776. {
  1777. [self addtocart];
  1778. // [main_vc checklogin:true];
  1779. }
  1780. };
  1781. ovc.init_style = OL_OPEN;
  1782. ovc.onCancel = ^(){
  1783. self.disable_refresh = false;
  1784. // [main_vc checklogin:true];
  1785. };
  1786. [self.navigationController pushViewController:ovc animated:true];
  1787. }
  1788. else
  1789. {
  1790. //create new;
  1791. self.disable_refresh = true;
  1792. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1793. {
  1794. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1795. cvc.showNavibar = true;
  1796. cvc.contact_type = @"Sales_Order_Customer";
  1797. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1798. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1799. appDelegate.customerInfo = value;
  1800. if(appDelegate.order_code==nil)
  1801. [self neworder];
  1802. // [main_vc checklogin:true];
  1803. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1804. //
  1805. // if(self.returnValue)
  1806. // self.returnValue(value);
  1807. };
  1808. cvc.onCancel = ^(){
  1809. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:self];
  1810. self.disable_refresh = false;
  1811. };
  1812. cvc.onReset = ^(){
  1813. // [main_vc checklogin:true];
  1814. };
  1815. [self.navigationController pushViewController:cvc animated:true];
  1816. }
  1817. else
  1818. {
  1819. [self neworder];
  1820. }
  1821. }
  1822. }
  1823. #pragma mark - Support scanner
  1824. -(void) onDecodedData:(NSString*) value
  1825. {
  1826. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  1827. // dvc
  1828. dvc.use_model_name = true;
  1829. dvc.model_name=value;
  1830. dvc.category_id=nil;
  1831. dvc.ispush = true;
  1832. [dvc reload];
  1833. [self.navigationController pushViewController:dvc animated:true];
  1834. }
  1835. #pragma mark Jack
  1836. - (void)addALlModel {
  1837. self.addAll = !self.addAll;
  1838. if (self.addAll) {
  1839. [self.addAllCheckBtn setImage:[[UIImage imageNamed:@"check_1_24"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1840. // self.addWishBtn.enabled = true;
  1841. // self.addCartBtn.enabled = true;
  1842. // self.addPortfolioBtn.enabled=true;
  1843. } else {
  1844. [self.addAllCheckBtn setImage:[[UIImage imageNamed:@"check_0_24"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  1845. // if (!self.select_count) {
  1846. // self.addWishBtn.enabled = false;
  1847. // self.addCartBtn.enabled = false;
  1848. // self.addPortfolioBtn.enabled=false;
  1849. // }
  1850. }
  1851. }
  1852. - (IBAction)addAllBtnClick:(id)sender {
  1853. [self addALlModel];
  1854. }
  1855. - (IBAction)allAllCheckBtnClick:(id)sender {
  1856. [self addALlModel];
  1857. }
  1858. #pragma mark - Private
  1859. -(NSString*) categoryString:(NSString*) categoryid node:(NSDictionary*) json level:(int) level {
  1860. if(categoryid.length==0)
  1861. return @">All Products>";
  1862. //NSString* idString = [NSString stringWithFormat:@"%d",categoryid];
  1863. NSString* categoryString =@">";
  1864. int count = [[json valueForKey:@"count"] intValue];
  1865. for(int i=0;i<count;i++)
  1866. {
  1867. NSDictionary * category_json = [json objectForKey:[NSString stringWithFormat:@"category_%d",i]];
  1868. NSString* cid = [category_json valueForKey:@"id"] ;
  1869. // NSString* ttt =[categoryid substringToIndex:2+level*2];
  1870. // NSString * qqq =[cid substringToIndex:2+level*2];
  1871. // NSString *ds1=[categoryid substringToIndex:3+level*3];
  1872. // NSString*ds2 = [cid substringToIndex:3+level*3];
  1873. if(cid.length<3+level*3)
  1874. continue;
  1875. if(categoryid.length<3+level*3)
  1876. continue;
  1877. if([[categoryid substringToIndex:3+level*3] isEqualToString: [cid substringToIndex:3+level*3]])
  1878. {
  1879. //categoryString = [categoryString stringByAppendingString:@">"];
  1880. categoryString =[categoryString stringByAppendingString: [category_json valueForKey:@"title" ] ];
  1881. categoryString = [categoryString stringByAppendingString:[ self categoryString:categoryid node:category_json level:level+1]];
  1882. break;
  1883. }
  1884. }
  1885. return categoryString;
  1886. }
  1887. @end