ItemSearchViewController.m 107 KB

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