CategoryViewController.m 91 KB

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