CategoryViewController.m 116 KB

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