CategoryViewController.m 116 KB

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