CategoryViewController.m 88 KB

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