CategoryViewController.m 99 KB

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