CategoryViewController.m 89 KB

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