CategoryViewController.m 99 KB

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