CategoryViewController.m 89 KB

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