CategoryViewController.m 94 KB

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