CategoryViewController.m 89 KB

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