CategoryViewController.m 93 KB

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