| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318 |
- //
- // ItemSearchViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 10/26/15.
- // Copyright © 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "ItemSearchViewController.h"
- #import "const.h"
- #import "RANetwork.h"
- #import "CategoryCellNPD.h"
- #import "DetailViewController.h"
- #import "ItemSearchFilterViewController.h"
- #import "ContactListViewController.h"
- #import "MainViewController.h"
- #import "DefaultAppearance.h"
- #import "UIColor+JK_HEX.h"
- #import "CartUtils.h"
- #import "RAConvertor.h"
- #define DEF_CELL_HEIGHT 44
- #define DEF_TABLE_HEIGHT 44
- #define LINE_WIDTH 0
- #define CELL_MARGIN 0
- #define LABEL_MARGIN 5
- #define END_SELECT_PORTFOLIO 5
- #define PAGE_ITEM 30
- @interface ItemSearchViewController ()
- @property (nonatomic,assign) BOOL addAll;
- @property (nonatomic,assign) UIInterfaceOrientation toOrientation;///<屏幕将要旋转到的方向
- @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
- @end
- @implementation ItemSearchViewController
- - (NSOperationQueue *)dataOperationQueue {
- if (!_dataOperationQueue) {
- _dataOperationQueue = [[NSOperationQueue alloc] init];
- _dataOperationQueue.maxConcurrentOperationCount = 1;
- }
- return _dataOperationQueue;
- }
- #ifndef RA_NOTIFICATION
- -(void) reload_container_getdata:(bool)update_data
- {
-
- if(self.disable_refresh)
- return;
- [super reload_container_getdata:update_data];
- // self.keywords=nil;
-
- if(update_data)
- {
- self.offset = 0;
- // [self.content_data removeAllObjects];
- [self reload];
- }
- else
- [self.collectionview reloadData];
-
- return;
- // if(!self.showDetail)
- // return;
- // NSArray* a= self.childViewControllers;
- //
- // for (int i=0;i<a.count;i++)
- // {
- // if([a[i] isKindOfClass:[DetailViewController class]])
- // {
- // DetailViewController *detailvc=a[i];
- // [detailvc reload];
- // }
- // }
-
- }
- #endif
- -(void)begin_select
- {
- // self.addCartBtn.enabled=false;
- // self.addWishBtn.enabled=false;
- // self.addPortfolioBtn.enabled=false;
- self.selectToolbar.hidden=false;
- // self.collectionview.allowsMultipleSelection = YES;
-
- self.isSelectionMode=true;
- self.select_count=0;
- }
- -(void)end_select:(int) type
- {
- self.select_count=0;
- self.selectToolbar.hidden=true;
- // self.collectionview.allowsMultipleSelection = NO;
-
-
- NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
- if (items == nil) {
- items = [NSMutableDictionary dictionary];
- [items setObject:@(0) forKey:@"count"];
- }
-
- int count = [[items valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
-
- bool check = [[item valueForKey:@"checked"] boolValue];
- if(check)
- {
- switch (type) {
- case 1:
- item[@"wish_exists"]=@"true";
- break;
- case 2:
- item[@"cart_exists"]=@"true";
- break;
- default:
- break;
- }
-
- }
- else
- {
- switch (type) {
- case 3:
- item[@"wish_exists"]=@"true";
- break;
- case 4:
- item[@"cart_exists"]=@"true";
- break;
- default:
- break;
- }
- }
- [item setValue:@"false" forKey:@"checked"];
-
-
- [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- }
-
-
- [self.category_data setObject:items forKey:@"items"];
-
-
- self.selectallBtn.tag = 0;
- [self.selectallBtn setTitle:@"Select"];
-
- self.isSelectionMode=false;
-
- if(self.disable_refresh)
- {
- self.disable_refresh = false;
- // [self reload_container_getdata:true];
- [self reload_data];
- }
- else
- [self.collectionview reloadData];
-
- }
- - (IBAction)onSelectClick:(id)sender {
-
- [self begin_select];
- }
- - (IBAction)onCancelSelectClick:(id)sender {
-
- [self end_select:0];
-
- }
- - (IBAction)onSelectAllClick:(id)sender {
-
- // int tag =self.selectallBtn.tag;
-
-
- if(self.category_data==nil)
- return;
-
-
- NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
-
-
- if(items==nil)
- return;
- int count = [[items valueForKey:@"count"] intValue];
-
- NSString* checked;
- if (self.selectallBtn.tag == 0)
- {
- self.selectallBtn.tag = 1;
- [self.selectallBtn setTitle:@"Deselect"];
- if(count>0)
- {
- // self.addWishBtn.enabled = true;
- // self.addCartBtn.enabled = true;
- // self.addPortfolioBtn.enabled=true;
- }
- self.select_count=count;
- checked=@"true";
- }
- else
- {
- self.selectallBtn.tag = 0;
- [self.selectallBtn setTitle:@"Select"];
- // self.addWishBtn.enabled = false;
- // self.addCartBtn.enabled = false;
- // self.addPortfolioBtn.enabled=false;
-
- checked=@"false";
- }
-
-
-
-
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- [item setValue:checked forKey:@"checked"];
- [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- }
- [self.category_data setObject:items forKey:@"items"];
-
- [self.collectionview reloadData];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
- self.label_net_err.layer.borderWidth = 2.0;
- self.label_net_err.layer.cornerRadius=15;
- self.label_net_err.layer.masksToBounds=true;
-
- self.addWishBtn.enabled = true;
- self.addCartBtn.enabled = true;
- self.addPortfolioBtn.enabled=true;
-
- CGPoint center = self.mum.center;
- self.mum.frame = CGRectMake(0, 0, 100, 100);
- self.mum.center = center;
- // self.mum.backgroundColor = [UIColor colorWithHEX:0xA5A5A5 alpha:0.5];
- self.mum.layer.cornerRadius = 5.0f;
- self.mum.layer.masksToBounds = YES;
-
- self.addAll = NO;
- [self.addAllCheckBtn setImage:[[UIImage imageNamed:@"check_0_24"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
- // tap.minimumPressDuration = 0.8; //定义按的时间
- [self.label_net_err addGestureRecognizer:tap];
-
- #ifdef BUILD_UWAVER
- // self.addPortfolioBtn.title = @"Add to Hang Tag";
- self.btn_select.hidden = true;
- #endif
-
-
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- self.categoryViewType = CATEGORY_VIEWTYPE_LARGE;
- #else
- self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
- #endif
- UICollectionViewFlowLayout* layout =(UICollectionViewFlowLayout*)self.collectionview.collectionViewLayout;
- CGSize cellsize = CGSizeMake(175, 250);
- layout.itemSize =cellsize;
- layout.minimumLineSpacing = 15;
- self.collectionview.collectionViewLayout = layout;
- //
- self.display_type = [[NSMutableDictionary alloc] init];
- [self.display_type setValue:@3 forKey:@"count"];
-
- NSMutableDictionary* val_0 = [[NSMutableDictionary alloc] init];
- [val_0 setValue:@1 forKey:@"check"];
- [val_0 setValue:@"small icon" forKey:@"value"];
- [val_0 setValue:@"" forKey:@"img"];
- [self.display_type setObject:val_0 forKey:@"val_0"];
-
- NSMutableDictionary* val_1 = [[NSMutableDictionary alloc] init];
- [val_1 setValue:@0 forKey:@"check"];
- [val_1 setValue:@"large icon" forKey:@"value"];
- [val_1 setValue:@"" forKey:@"img"];
- [self.display_type setObject:val_1 forKey:@"val_1"];
-
- NSMutableDictionary* val_2 = [[NSMutableDictionary alloc] init];
- [val_2 setValue:@2 forKey:@"check"];
- [val_2 setValue:@"detail" forKey:@"value"];
- [val_2 setValue:@"" forKey:@"img"];
- [self.display_type setObject:val_2 forKey:@"val_2"];
-
- // self.collectionview.
- // self.cagegoryLabel.text = self.categoryString;
- self.showDetail = false;
- //添加边框
- // CALayer *layer = [self.collectionview layer];
- // layer.borderColor = [[UIColor redColor] CGColor];
- // layer.borderWidth = 5.0f;
-
-
- self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
- self.headerView.layer.masksToBounds = false;
- //添加四个边阴影
-
- self.headerView.layer.shadowColor = [UIColor grayColor].CGColor;
- self.headerView.layer.shadowOffset = CGSizeMake(0, 0);
- self.headerView.layer.shadowOpacity = 0.5;
- self.headerView.layer.shadowRadius = 2.0;
-
-
- //添加两个边阴影
- self.collectionview.layer.masksToBounds = false;
- self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
- self.collectionview.layer.shadowColor = [UIColor grayColor].CGColor;
- self.collectionview.layer.shadowOffset = CGSizeMake(0, 0);
- self.collectionview.layer.shadowOpacity = 0.5;
- self.collectionview.layer.shadowRadius = 2.0;
- // Do any additional setup after loading the view.
-
-
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
- [self.collectionview addSubview:ref];
-
- self.collectionview.alwaysBounceVertical = YES;
- }
- -(void)manually_refresh
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
- [self performSelector:@selector(reload) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- -(NSMutableDictionary*) resetFilter:(NSMutableDictionary*)filter
- {
- NSString* str= [RAConvertor dict2string:filter];
- str=[str stringByReplacingOccurrencesOfString:@"\"check\":1" withString:@"\"check\":0"];
- str=[str stringByReplacingOccurrencesOfString:@"\"check\":\"1\"" withString:@"\"check\":\"0\""];
- filter=[[RAConvertor string2dict:str]mutableCopy];
- filter[@"model_name"]=@"";
- filter[@"model_description"]=@"";
- filter[@"price"][@"val_0"][@"check"]=@"1";
- filter[@"alert"][@"val_0"][@"check"]=@"1";
- filter[@"qty"][@"val_0"][@"check"]=@"1";
- filter[@"availability"][@"val_0"][@"check"]=@"1";
- filter[@"best_seller"][@"val_1"][@"check"]=@"1";
- return filter;
- }
- - (IBAction)onFilterClicked:(id)sender {
-
- #ifndef BUILD_UWAVER
- ItemSearchFilterViewController * filterVC =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Search" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemSearchFilterViewController"];
- #else
- ItemSearchFilterViewController * filterVC = [[UIStoryboard storyboardWithName:@"UWA_Mobile" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemSearchFilterViewController"];
- #endif
- if(self.default_filter==nil)
- self.default_filter = [self.category_data objectForKey:@"filter"];
-
- filterVC.default_filter = [self.default_filter mutableCopy];
-
- filterVC.categoryMenu = [self.default_filter objectForKey:@"category"];
- filterVC.alert_cadedate =[self.default_filter objectForKey:@"alert"];
- filterVC.modelname=[self.default_filter valueForKey:@"model_name"];
- filterVC.modeldescrip=[self.default_filter valueForKey:@"model_description"];
-
-
- filterVC.qty_cadedate=[self.default_filter objectForKey:@"qty"];
- filterVC.availability_cadedate=[self.default_filter objectForKey:@"availability"];
- filterVC.price_cadedate=[self.default_filter objectForKey:@"price"];
- filterVC.bestseller_cadedate=[self.default_filter objectForKey:@"best_seller"];
-
-
- filterVC.SearchClick =^(NSString* ids,NSString* modelname,NSString* modeldescrip,NSString* alert,NSString* available,NSString* QTY,NSString* price,NSString* bestseller)
- {
-
- self.default_filter= [self resetFilter:self.default_filter];
- self.ctgid = ids;
- self.modelname = modelname;
- self.modeldescrip = modeldescrip;
- self.alert = alert;
- self.covertype = nil;
-
-
- self.p_QTY=QTY;
- self.p_available=available;
- self.p_price=price;
- self.p_bestseller=bestseller;
- self.offset = 0;
- self.offset = 0;
- // [self.content_data removeAllObjects];
- [self reload];
- DebugLog(@"search");
-
- };
-
-
- filterVC.ResetClick =^()
- {
-
-
- self.p_QTY=nil;
- self.p_available=nil;
- self.p_price=nil;
- self.p_bestseller=nil;
-
- self.ctgid = nil;
- self.modelname = nil;
- self.modeldescrip = nil;
- self.alert = nil;
- self.covertype = self.saved_covertype;
- self.offset = 0;
- // [self.content_data removeAllObjects];
- [self reload];
- DebugLog(@"search");
-
- };
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:filterVC] ;
-
-
-
-
-
- // navi.preferredContentSize = CGSizeMake(540, 680);
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"bundle present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- }
- -(void)viewWillLayoutSubviews
- {
-
-
- self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
-
- self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
- }
- - (void) checkToolBar {
-
- // customer 隐藏add to portfolio
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSMutableArray *items = [self.selectToolbar.items mutableCopy];
- if (RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-
- if ([items containsObject:self.addPortfolioBtn]) {
-
- [items removeObject:self.addPortfolioBtn];
- self.selectToolbar.items = items;
- }
-
- } else {
-
- if (![items containsObject:self.addPortfolioBtn]) {
-
- [items insertObject:self.addPortfolioBtn atIndex:4];
- self.selectToolbar.items = items;
- }
-
- }
-
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- [self checkToolBar];
- self.toOrientation = [RAUtils query_orientation:self];[RAUtils query_orientation:self];//[[UIApplication sharedApplication] statusBarOrientation];
- [self.collectionview layoutIfNeeded];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark get data
- -(void) operation_loadMore
- {
- if (self.dataOperationQueue.operationCount > 1) {
- return ;
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- if(self.loadall )
- {
-
- if(self.showalert)
- {
- self.showalert=false;
- [RAUtils message_box:@"Loading items" message:@"All loaded" completion:nil];
- }
- return;
-
- }
-
- self.mum.hidden = false;
- [self.mum startAnimating];
- self.mum.center = self.view.center;
-
- self.isrefreshing=true;
-
- [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) {
- NSDictionary* category_more=result;
- [self.mum stopAnimating];
- self.isrefreshing=false;
- if (self.dataOperationQueue.operationCount > 1) {
- return ;
- }
- NSDictionary* more_items=[category_more objectForKey:@"items"];
- if([[category_more valueForKey:@"result"] intValue]==2)
- {
- // self.category_data = category_data;
- NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy];
-
- int count =[[more_items valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
-
- NSDictionary * item_json = [more_items objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- [items_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",i+self.offset]];
-
-
- }
- long newcount=[[[self.category_data objectForKey:@"items"] valueForKey:@"count"] intValue]+count;
- [items_json setValue: [NSString stringWithFormat:@"%ld",newcount] forKey:@"count"];
- [self.category_data setObject:items_json forKey:@"items"];
- self.offset+=count;
-
- if(count<PAGE_ITEM)
- {
- self.loadall=true;
-
- }
-
- // NSDictionary * item_json = [self.category_data objectForKey:@"items"];
-
-
-
-
- // DebugLog(@"%@",self.category_data);
-
- [self.collectionview reloadData];
-
- }
- else
- {
-
- [RAUtils message_box:@"Search" message:[category_more valueForKey:@"err_msg"] completion:nil];
- }
-
-
- }];
- });
- }
- -(void) loadMore {
- __weak typeof(self) weakself = self;
- NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
-
- if (weakself) {
- __strong typeof(weakself) strongself = weakself;
- [strongself operation_loadMore];
- }
-
- }];
-
- [self.dataOperationQueue addOperation:operation];
- }
- -(void) operation_reload
- {
-
- if (self.dataOperationQueue.operationCount > 1) {
- return ;
- }
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(self.isrefreshing)
- return;
- self.showalert=true;
- self.isrefreshing=true;
- self.loadall = false;
- UIRefreshControl *reF = (UIRefreshControl *)[self.collectionview viewWithTag:200];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
-
- self.label_net_err.hidden=true;
- self.collectionview.hidden = true;
-
- self.mum.center = self.view.center;
- self.mum.hidden = false;
- [self.mum startAnimating];
-
- [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) {
- NSDictionary* category_data=result;
- [self.mum stopAnimating];
- self.isrefreshing=false;
- if (self.dataOperationQueue.operationCount > 1) {
- return ;
- }
-
- self.category_data = [category_data mutableCopy];
- [self.collectionview reloadData];
- if([[category_data valueForKey:@"result"] intValue]==2)
- {
- self.collectionview.hidden = false;
- NSDictionary * item_json = [self.category_data objectForKey:@"items"];
- self.offset =[[item_json valueForKey:@"count"] intValue];
-
- int total = [[self.category_data valueForKey:@"item_total_count"]intValue];
-
- if(total<2)
- self.labelTotal.text = [NSString stringWithFormat:@"Total %d item",total];
- else
- self.labelTotal.text = [NSString stringWithFormat:@"Total %d items",total];
- }
- else if([[category_data valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
- {
- self.label_net_err.hidden=false;
- self.collectionview.hidden = true;
- }
- else
- {
-
- [RAUtils message_box:@"Search" message:[category_data valueForKey:@"err_msg"] completion:nil];
- }
-
-
-
- }];
- });
- }
- -(void) reload {
- __weak typeof(self) weakself = self;
- NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
-
- if (weakself) {
- __strong typeof(weakself) strongself = weakself;
- [strongself operation_reload];
- }
-
- }];
-
- [self.dataOperationQueue addOperation:operation];
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- - (IBAction)onChangeDisplay:(UIButton *)sender {
- UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
-
- flowLayout.scrollDirection= UICollectionViewScrollDirectionVertical;
-
-
- if(sender.tag==2&&self.categoryViewType != CATEGORY_VIEWTYPE_SMALL)
- {
- self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
- // [self.collectionview.collectionViewLayout invalidateLayout];
- DebugLog(@"frame %f",self.collectionview.frame.size.height);
- DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
- DebugLog(@"content %f",self.collectionview.contentSize.height);
- // float pos =self.collectionview.contentOffset.y/self.collectionview.contentSize.height;
- [self.collectionview reloadData];
-
- // CGPoint offset = self.collectionview.contentOffset;
- // offset.y=pos*self.collectionview.contentSize.height;
- // self.collectionview.contentOffset=offset;
-
- }
- else if(sender.tag==3&&self.categoryViewType != CATEGORY_VIEWTYPE_LARGE)
- {
- self.categoryViewType = CATEGORY_VIEWTYPE_LARGE;
-
- DebugLog(@"frame %f",self.collectionview.frame.size.height);
- DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
- DebugLog(@"content %f",self.collectionview.contentSize.height);
-
-
-
- [self.collectionview reloadData];
-
-
- }
- else if(sender.tag==4&&self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
- {
- self.categoryViewType = CATEGORY_VIEWTYPE_LIST;
-
- DebugLog(@"frame %f",self.collectionview.frame.size.height);
- DebugLog(@"offset %f",self.self.collectionview.contentOffset.y);
- DebugLog(@"content %f",self.collectionview.contentSize.height);
-
-
- [self.collectionview reloadData];
-
-
- }
-
-
-
- [self showCategory];
-
-
- }
- - (IBAction)onAddCartClick:(id)sender {
-
- [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
- return;
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- // if(appDelegate.bLogin==false)
- // {
- //
- // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // // loginvc.delegate = self;
- // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- //
- // loginvc.returnValue = ^(bool blogin){
- //
- //
- // // UIApplication * app = [UIApplication sharedApplication];
- // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- //
- //
- //
- // if(blogin)
- // {
- // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/true)
- // {
- //
- // [main_vc checklogin:false];
- //
- // if(appDelegate.can_create_order)
- // {
- // NSString* msg =@"";
- // if(appDelegate.contact_id.length>0)
- // {
- // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
- //
- // }
- // 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];
- //
- //
- //
- // // alert.
- // [alert show];
- // }
- // else
- // {
- // 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];
- //
- // // alert.
- // [alert show];
- // }
- // }
- // else
- // {
- // [main_vc checklogin:false];
- // [self addtocart];
- // }
- // }
- //
- // // self.offset = 0;
- // // [self.content_data removeAllObjects];
- // // [self loadpage];
- // //
- // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
- //
- // };
- //
- // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
- //
- //
- //
- //
- //
- // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
- //
- // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- // [self presentViewController:navi animated:YES completion:^{
- //
- // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
- //
- // DebugLog(@"LoginViewController present.........");
- //
- // // self.btop = false;
- // // <#code#>
- // }];
- // }
- // else
- // {
- //// if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
- // if(appDelegate.order_code==nil)
- // {
- // [main_vc checklogin:false];
- //
- // if(appDelegate.can_create_order)
- // {
- // NSString* msg =@"";
- // if(appDelegate.contact_id.length>0)
- // {
- // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
- //
- // }
- // 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];
- //
- // // alert.
- // [alert show];
- // }
- // else
- // {
- // 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];
- //
- // // alert.
- // [alert show];
- // }
- // }
- // else
- // {
- //
- // if(appDelegate.order_code==nil)
- // [ self neworder];
- // else
- // [self addtocart];
- //
- //
- //
- // }
- // }
- //
- //
- //
- //
- }
- -(void) neworder
- {
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
- [RANetwork request_create_order:^(NSMutableDictionary *result) {
- NSMutableDictionary* return_json = result;
-
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- int result=[[return_json valueForKey:@"result"] intValue];
- if(result==2)
- {
- //successed.
-
- NSString* order_code = [return_json valueForKey:@"orderCode"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = order_code;
-
-
- [self addtocart];
-
- }
- }
- else
- {
- [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- // }];
-
-
-
-
-
-
-
-
- }];
- // }];
- }
- - (IBAction)onAddPortfolioClick:(id)sender {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.bLogin==false)
- {
-
- LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
- loginvc.returnValue = ^(bool blogin){
-
-
-
- if(blogin)
- {
- [main_vc checklogin:false];
-
- [self checkToolBar];
- [self addtoportfolio];
- }
-
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
- [self addtoportfolio];
- }
-
- }
- - (IBAction)onAddWishlistClick:(id)sender {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.bLogin==false)
- {
-
- LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
- loginvc.returnValue = ^(bool blogin){
-
-
-
- if(blogin)
- {
- [main_vc checklogin:false];
-
-
- [self addtowish];
- }
-
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
- [self addtowish];
- }
- }
- -(void) addtocart
- {
-
-
- NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
-
- int count = [[items valueForKey:@"count"] intValue];
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- bool check = [[item valueForKey:@"checked"] boolValue];
- if(check)
- {
- // [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
- [checked addObject:[item valueForKey:@"fash_name"]];
- }
- }
-
- if (!count) {
- [RAUtils message_box:@"Cannot Add to cart." message:@"There is no model." completion:nil] ;
- return;
- }
-
- if(!self.addAll && checked.count==0)
- {
- [RAUtils message_box:@"Cannot Add to cart." message:@"You must select at least one model." completion:nil] ;
- return;
- }
-
- NSString * ids = [checked componentsJoinedByString:@","];
- self.addCartBtn.enabled = false;
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Cart" completion:^{
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Add Models To Cart" completion:nil];
- if (self.addAll) {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [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) {
- NSDictionary* return_json =result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- self.addCartBtn.enabled = true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
-
-
- NSString * msg = nil;
-
- if (self.addAll) {
-
- unsigned long checkedCount = [return_json[@"count"] integerValue];
-
- msg=[NSString stringWithFormat:@"%lu items added to Cart",checkedCount];
- } else {
-
-
- if(checked.count==1)
- {
- msg=@"1 item added to Cart";
- }
- else
- {
- msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
- }
- }
-
-
- [RAUtils message_box:msg message:nil completion:nil] ;
-
- [self end_select:4];
-
-
-
- // }
- }
- else if([[return_json valueForKey:@"result"] intValue]==8)
- {
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- #endif
-
- [self end_select:4];
- [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- else
- {
- [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- // }];
-
-
-
-
-
-
- }];
- } else {
- [RANetwork request_addto_cart_byname:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json =result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- self.addCartBtn.enabled = true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- // int result=[[return_json valueForKey:@"result"] intValue];
- // if(result==2)
- // {
- // //successed.
-
- // NSString* order_code = [return_json valueForKey:@"order_code"];
-
- // appDelegate.order_code = order_code;
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = order_code;
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
-
-
- NSString * msg = nil;
-
- if (self.addAll) {
-
- unsigned long checkedCount = [return_json[@"count"] integerValue];
-
- msg=[NSString stringWithFormat:@"%lu items added to Cart",checkedCount];
- } else {
-
-
- if(checked.count==1)
- {
- msg=@"1 item added to Cart";
- }
- else
- {
- msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
- }
- }
-
-
- [RAUtils message_box:msg message:nil completion:nil] ;
-
- [self end_select:2];
-
-
-
- // }
- }
- else if([[return_json valueForKey:@"result"] intValue]==8)
- {
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- #endif
-
- [self end_select:2];
- [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- else
- {
- [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- // }];
-
-
-
-
-
-
- }];
-
-
- }
- // }];
- }
- -(void) addtoportfolio
- {
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
- [RAUtils message_box:@"Warning" message:@"Cannot Add to portfolio." completion:nil] ;
- return;
- }
-
- NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
-
- int count = [[items valueForKey:@"count"] intValue];
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- bool check = [[item valueForKey:@"checked"] boolValue];
- if(check)
- {
- [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
-
- }
- }
-
-
- if (!count) {
- [RAUtils message_box:@"Cannot Add to portfolio." message:@"There is no model." completion:nil] ;
- return;
- }
-
- if(!self.addAll && checked.count==0)
- {
- [RAUtils message_box:@"Cannot Add to portfolio." message:@"You must select at least one model." completion:nil] ;
- return;
- }
-
- NSString * ids = [checked componentsJoinedByString:@","];
- self.addPortfolioBtn.enabled =false;
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Portfolio" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Add Models To Portfolio" completion:nil];
- if (self.addAll) {
- [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) {
- NSDictionary* return_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- self.addPortfolioBtn.enabled =true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
- #endif
-
- NSString * msg = nil;
-
- if (self.addAll) {
-
- unsigned long checkedCount = [return_json[@"count"] integerValue];
-
- msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
- } else {
-
- if(checked.count==1)
- {
- msg=@"1 item added to Portfolio";
- }
- else
- {
- msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
- }
- }
-
- [RAUtils message_box:msg message:nil completion:nil] ;
-
-
- [self end_select:END_SELECT_PORTFOLIO];
-
- }
- else
- {
- [RAUtils message_box:@"Add To Portfolio" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- // }];
-
-
-
-
-
-
- }];
- } else {
- [RANetwork request_addto_portfolio:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- self.addPortfolioBtn.enabled =true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
- #endif
-
- NSString * msg = nil;
-
- if (self.addAll) {
-
- unsigned long checkedCount = [return_json[@"count"] integerValue];
-
- msg=[NSString stringWithFormat:@"%lu items added to Portfolio",checkedCount];
- } else {
-
- if(checked.count==1)
- {
- msg=@"1 item added to Portfolio";
- }
- else
- {
- msg=[NSString stringWithFormat:@"%lu items added to Portfolio",(unsigned long)checked.count];
- }
- }
-
- [RAUtils message_box:msg message:nil completion:nil] ;
-
-
- [self end_select:END_SELECT_PORTFOLIO];
-
- }
- else
- {
- [RAUtils message_box:@"Add To Portfolio" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- // }];
-
-
-
-
-
-
- }];
-
- }
- // }];
-
-
- }
- -(void) addtowish
- {
-
- NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
-
- int count = [[items valueForKey:@"count"] intValue];
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- bool check = [[item valueForKey:@"checked"] boolValue];
- if(check)
- {
- [checked addObject:[NSNumber numberWithInt:[[item valueForKey:@"product_id"] intValue]]];
-
- }
- }
-
- if (!count) {
- [RAUtils message_box:@"Cannot Add to Wish List." message:@"There is no model." completion:nil] ;
- return;
- }
-
- if(!self.addAll && checked.count==0)
- {
- [RAUtils message_box:@"Cannot Add to Wish List." message:@"You must select at least one model." completion:nil] ;
- return;
- }
-
- NSString * ids = [checked componentsJoinedByString:@","];
- self.addWishBtn.enabled =false;
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Add Models To Wish List" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Add Models To Wish List" completion:nil];
- if (self.addAll) {
-
- [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) {
- NSDictionary* return_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- self.addWishBtn.enabled =true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
-
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
- NSString * msg = nil;
-
- if (self.addAll) {
-
- unsigned long checkedCount = [return_json[@"count"] integerValue];
-
- msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
- } else {
-
-
- if(checked.count==1)
- {
- msg=@"1 item added to \nWish List";
- }
- else
- {
- msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
- }
- }
-
- [RAUtils message_box:msg message:nil completion:nil] ;
-
-
- [self end_select:3];
-
- }
- else
- {
- [RAUtils message_box:@"Add To Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- // }];
-
-
-
-
-
- }];
-
- } else {
-
- [RANetwork request_addto_wishlist:ids withScreen:ScreenCodeParticularCategory completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- self.addWishBtn.enabled =true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
-
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
- NSString * msg = nil;
-
- if (self.addAll) {
-
- unsigned long checkedCount = [return_json[@"count"] integerValue];
-
- msg=[NSString stringWithFormat:@"%lu items added to \nWish List",checkedCount];
- } else {
-
-
- if(checked.count==1)
- {
- msg=@"1 item added to \nWish List";
- }
- else
- {
- msg=[NSString stringWithFormat:@"%lu items added to \nWish List",(unsigned long)checked.count];
- }
- }
-
- [RAUtils message_box:msg message:nil completion:nil] ;
-
-
- [self end_select:1];
-
- }
- else
- {
- [RAUtils message_box:@"Add To Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
- }
- // }];
-
-
-
-
-
- }];
-
- }
- // }];
-
-
-
- }
- -(void) showCategory
- {
- if(self.showDetail==false)
- return;
-
- CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width
- , self.view.bounds.size.height-48);
-
- [UIView animateWithDuration:0.5 animations:^{ self.collectionview.frame=frame;
- }];
- self.collectionview.autoresizingMask = self.collectionview.autoresizingMask | UIViewAutoresizingFlexibleWidth;
-
- self.showDetail = false;
- // self.cagegoryLabel.hidden = false;
-
- }
- //#pragma mark - searchBar delegate;
- //- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- //{
- //
- //
- // // self.keywords=searchBar.text;
- // self.offset = 0;
- // // [self.content_data removeAllObjects];
- // [self reload];
- // DebugLog(@"search");
- //}
- /*
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
-
- if([searchText isEqualToString:@""] && !self.reset)
- {
- DebugLog(@"clear");
- self.reset=true;
- self.keywords=nil;
-
- self.offset = 0;
- [self.content_data removeAllObjects];
- [self loadpage];
- [self loadpage];
- }
- else
- self.reset = false;
-
-
- }*/
- //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
- //
- // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
- // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
- // {
- // // self.orientation = orientation;
- // [self.collectionview.collectionViewLayout invalidateLayout];
- // DebugLog(@"routed");
- // }
- //
- //}
- //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
- //
- // [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
- //
- // self.toOrientation = toInterfaceOrientation;
- // [self.collectionview.collectionViewLayout invalidateLayout];
- //
- //}
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- // what ever you want to prepare
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
-
- self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath;
- self.toOrientation = [RAUtils query_orientation:self];//[UIApplication sharedApplication].statusBarOrientation;
- [self.collectionview.collectionViewLayout invalidateLayout];
- }];
- }
- #pragma mark -- UICollectionViewDataSource
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- // 每个Section的item个数
- NSDictionary * item_json = [self.category_data objectForKey:@"items"];
- int count =[[item_json valueForKey:@"count"] intValue];
- return count;
-
- }
- -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString* value =[DefaultAppearance get_noneappearance_value:@"CategoryViewController" valuename:@"cell_border_color"];
-
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
- if(self.categoryViewType == CATEGORY_VIEWTYPE_SMALL)
- {
- static NSString * CellIdentifier = @"CategoryCellNPD";
- CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- NSString* description =[item_json valueForKey:@"description"];
-
- NSString* name =[item_json valueForKey:@"fash_name"];
-
- bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
- bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
- bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
- BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
- cell.mark_moreColor.hidden = !more_color;
- if(wish_exist)
- cell.mark_wish.hidden=false;
- else
- cell.mark_wish.hidden=true;
- if(cart_exists)
- cell.mark_order.hidden=false;
- else
- cell.mark_order.hidden=true;
- if(closeout)
- cell.mark_closeout.hidden=false;
- else
- cell.mark_closeout.hidden=true;
-
- // NSString* old_price =[item_json valueForKey:@"old_price"];
- // NSString* price =[item_json valueForKey:@"price"];
- bool checked =[[item_json valueForKey:@"checked"] boolValue];
-
-
-
- if(!checked)
- {
-
- cell.checkImageView.hidden = true;
- [cell setBackgroundColor:[UIColor whiteColor]/* UIColorFromRGB(0x996633)*/];
- }
- else
- {
- cell.checkImageView.hidden = false;
- [cell setBackgroundColor: UIColorFromRGB(0x009966)];
- }
-
-
-
- cell.nameLabel.text = description;
- cell.modelNoLabel.text=name;
-
- // cell.cellDescription.text = description;
- // cell.oldPrice.text = old_price;
- // cell.Price.text = price;
-
-
-
-
- cell.layer.borderColor = UIColorFromRGB(color).CGColor;
- cell.layer.borderWidth = 0.5;
- //cell.layer.cornerRadius=15;
- cell.layer.masksToBounds=true;
-
- #ifdef BUILD_UWAVER
-
- cell.mark_wish.hidden = YES;
- cell.mark_order.hidden = YES;
- cell.mark_closeout.hidden = YES;
- cell.mark_moreColor.hidden = YES;
-
- #endif
-
- return cell;
- }
- else if(self.categoryViewType == CATEGORY_VIEWTYPE_LARGE)
- {
- static NSString * CellIdentifier = @"CategoryCellNPDLarge";
- CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- NSString* description =[item_json valueForKey:@"description"];
-
- NSString* modelid =[item_json valueForKey:@"fash_name"];
-
-
- bool checked =[[item_json valueForKey:@"checked"] boolValue];
- bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
- bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
- bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
- BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
- cell.mark_moreColor.hidden = !more_color;
- if(wish_exist)
- cell.mark_wish.hidden=false;
- else
- cell.mark_wish.hidden=true;
- if(cart_exists)
- cell.mark_order.hidden=false;
- else
- cell.mark_order.hidden=true;
- if(closeout)
- cell.mark_closeout.hidden=false;
- else
- cell.mark_closeout.hidden=true;
-
- if(!checked)
- {
-
- cell.checkImageView.hidden = true;
- [cell setBackgroundColor:[UIColor whiteColor]/* UIColorFromRGB(0x996633)*/];
- }
- else
- {
- cell.checkImageView.hidden = false;
- [cell setBackgroundColor: UIColorFromRGB(0x009966)];
- }
- // NSString* name =[item_json valueForKey:@"name"];
- // NSString* old_price =[item_json valueForKey:@"old_price"];
- // NSString* price =[item_json valueForKey:@"price"];
-
-
- cell.nameLabel.text = description;
- cell.modelNoLabel.text=modelid;
-
- // cell.cellDescription.text = description;
- // cell.oldPrice.text = old_price;
- // cell.Price.text = price;
-
-
- cell.layer.borderColor = UIColorFromRGB(color).CGColor;
- cell.layer.borderWidth = 0.5;
- //cell.layer.cornerRadius=15;
- cell.layer.masksToBounds=true;
-
- #ifdef BUILD_UWAVER
-
- cell.mark_wish.hidden = YES;
- cell.mark_order.hidden = YES;
- cell.mark_closeout.hidden = YES;
- cell.mark_moreColor.hidden = YES;
-
- #endif
-
- return cell;
- }
- else
- {
- static NSString * CellIdentifier = @"CategoryCellNPDList";
- CategoryCellNPD * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- NSString* description =[item_json valueForKey:@"description"];
-
- NSString* name =[item_json valueForKey:@"fash_name"];
-
- bool wish_exist = [[item_json valueForKey:@"wish_exists"]boolValue];
- bool cart_exists = [[item_json valueForKey:@"cart_exists"]boolValue];
- bool closeout = [[item_json valueForKey:@"is_closeout"]boolValue];
- BOOL more_color = [[item_json valueForKey:@"more_color"] boolValue];
- cell.mark_moreColor.hidden = !more_color;
- if(wish_exist)
- cell.mark_wish.hidden=false;
- else
- cell.mark_wish.hidden=true;
- if(cart_exists)
- cell.mark_order.hidden=false;
- else
- cell.mark_order.hidden=true;
- if(closeout)
- cell.mark_closeout.hidden=false;
- else
- cell.mark_closeout.hidden=true;
-
- // NSString* old_price =[item_json valueForKey:@"old_price"];
- // NSString* price =[item_json valueForKey:@"price"];
-
-
-
- bool checked =[[item_json valueForKey:@"checked"] boolValue];
-
-
-
- if(!checked)
- {
-
- cell.checkImageView.hidden = true;
- [cell setBackgroundColor: [UIColor whiteColor]];
- }
- else
- {
- cell.checkImageView.hidden = false;
- [cell setBackgroundColor: UIColorFromRGB(0x009966)];
- }
-
- cell.nameLabel.text = description;
- cell.modelNoLabel.text=name;
-
-
- // cell.cellDescription.text = description;
- // cell.oldPrice.text = old_price;
- // cell.Price.text = price;
-
-
- cell.layer.borderColor = UIColorFromRGB(color).CGColor;
- cell.layer.borderWidth = 0.5;
- // cell.layer.cornerRadius=15;
- cell.layer.masksToBounds=true;
-
- #ifdef BUILD_UWAVER
-
- cell.mark_wish.hidden = YES;
- cell.mark_order.hidden = YES;
- cell.mark_closeout.hidden = YES;
- cell.mark_moreColor.hidden = YES;
-
- #endif
-
- return cell;
- }
- }
- - (void)collectionCell:(CategoryCellNPD *)cell setImageForIndexPath:(NSIndexPath *)indexPath {
-
- NSDictionary * item_json =[[self.category_data objectForKey:@"items" ] objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- NSString* img_url =[item_json valueForKey:@"img"];
-
-
- NSString *loading = @"loading_l";
- NSString *notFound = @"notfound_l";
-
- if (self.categoryViewType == CATEGORY_VIEWTYPE_LARGE) {
-
- loading = @"loading_l";
- notFound = @"notfound_l";
- img_url =[item_json valueForKey:@"img_big"]; // large 大图
-
- } else if (self.categoryViewType == CATEGORY_VIEWTYPE_SMALL) {
-
- loading = @"loading_s";
- notFound = @"notfound_s";
- img_url =[item_json valueForKey:@"img"]; // large 大图
-
- }
- NSString* file_name=[img_url lastPathComponent];
- if (![cell.imageName isEqualToString:img_url]) {
- cell.imageName = img_url;
- cell.cellImageView.image = [UIImage imageNamed:loading];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- cell.cellImageView.image = img;
- }
- else
- {
- DebugLog(@"load image");
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if(downloadimg_data!=nil)
- {
-
- [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
-
- UIImage * img =[UIImage imageWithData:downloadimg_data];
- cell.cellImageView.image = img;
- }
- else
- cell.cellImageView.image = [UIImage imageNamed:notFound];
-
- });
- });
-
-
- }
- }
-
- }
- - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
-
- CategoryCellNPD * son_cell = (CategoryCellNPD *)cell;
- son_cell.imageName = nil;
- [self collectionCell:son_cell setImageForIndexPath:indexPath];
- }
- - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
-
- CategoryCellNPD * son_cell = (CategoryCellNPD *)cell;
-
- NSString *loading = @"loading_l";
-
- if (self.categoryViewType == CATEGORY_VIEWTYPE_LARGE) {
-
- loading = @"loading_l";
-
- } else if (self.categoryViewType == CATEGORY_VIEWTYPE_SMALL) {
-
- loading = @"loading_s";
-
- }
-
- son_cell.cellImageView.image = [UIImage imageNamed:loading];
- }
- #pragma mark --UICollectionViewDelegateFlowLayout
- ////定义每个UICollectionView 的大小
- //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- //{
- // return CGSizeMake(96, 100);
- //}
- //定义每个UICollectionView 的 margin
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
-
- UIInterfaceOrientation orientation = [RAUtils query_orientation:self];//[[UIApplication sharedApplication]statusBarOrientation];
-
- orientation = self.toOrientation;
-
- if (UIInterfaceOrientationIsLandscape(orientation))
- {
- // DebugLog(@"横");
- // if(self.showDetail)
- // return CGSizeMake(96, 100);
- if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
- return CGSizeMake(328, 391);
- else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
- return CGSizeMake(1024, 120);
- return CGSizeMake(193, 269);
- }
- else if(UIInterfaceOrientationIsPortrait(orientation))
- {
- // DebugLog(@"竖");
- // if(self.showDetail)
- // return CGSizeMake(96, 100);
- if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
- return CGSizeMake(369, 440);
- else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
- return CGSizeMake(768, 120);
- return CGSizeMake(180, 251);
- }
-
- DebugLog(@"error , %ld",(long)orientation );
- return CGSizeMake(96, 100);
-
-
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
- {
- if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
- return 1;
- return 15;
- }
- -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- if(self.showDetail)
- return UIEdgeInsetsMake(10, 5, 10, 5);
- // if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
- // return UIEdgeInsetsMake(10, 10, 10, 10);
-
- if(self.categoryViewType ==CATEGORY_VIEWTYPE_LARGE)
- return UIEdgeInsetsMake(10, 10, 10, 10);
- else if(self.categoryViewType ==CATEGORY_VIEWTYPE_LIST)
- return UIEdgeInsetsMake(10, 0, 10, 0);
- return UIEdgeInsetsMake(10, 10, 10, 10);
-
- return UIEdgeInsetsMake(10, 10, 10, 10);
- }
- #pragma mark --UICollectionViewDelegate
- -(void) showDetailat:(NSString*) item_id category_id:(NSString*) category_id name:(NSString *)name index:(long)index
- {
- DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
- // dvc
-
- dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
- {
- NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
-
- NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",index]] mutableCopy];
- if(add_cart)
- item[@"cart_exists"]=@"true";
- if(add_wish)
- item[@"wish_exists"]=@"true";
- items[[NSString stringWithFormat:@"item_%ld",index]] = item;
- self.category_data[@"items"]=items;
-
- [self.collectionview reloadData];
- };
- // dvc.use_model_name = true;
- // dvc.model_name=[transformed stringValue];
- dvc.product_id = item_id;
- dvc.category_id=category_id;
- dvc.ispush = true;
- dvc.model_name = name;
-
- [dvc reload];
- [self.navigationController pushViewController:dvc animated:true];
- return;
-
- // //一下为detail嵌入当前窗口的方式
- // self.categoryViewType = CATEGORY_VIEWTYPE_SMALL;
- // //[self.collectionview.collectionViewLayout invalidateLayout];
- // [self.collectionview reloadData];
- // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
- // int width=175;
- // // int height;
- // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
- // {
- // width = 370;
- // // height = 400;
- // }
- // else
- // {
- // UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
- //
- // flowLayout.scrollDirection= UICollectionViewScrollDirectionHorizontal;
- // // [self.collectionview ] set
- // // height = 251;
- // width = 180;
- // }
- //
- //
- // CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width, 271);
- //
- //
- // // CGRect framedetail = CGRectMake(0,271 ,self.view.bounds.size.width,self.view.bounds.size.height-271);
- //
- // [UIView animateWithDuration:0.5 animations:^{
- // self.collectionview.frame=frame;
- //// self.detailView.frame = framedetail;
- // // self.cagegoryLabel.hidden = true;
- // }];
- // self.collectionview.autoresizingMask = self.collectionview.autoresizingMask ^ UIViewAutoresizingFlexibleWidth;
- //
- // self.showDetail = true;
- //
- //
- // NSArray* a= self.childViewControllers;
- //
- // for (int i=0;i<a.count;i++)
- // {
- // if([a[i] isKindOfClass:[DetailViewController class]])
- // {
- // DetailViewController *detailvc=a[i];
- // detailvc.category_id = nil;
- // detailvc.product_id = item_id;
- // detailvc.ispush=false;
- // [detailvc reload];
- // }
- // }
-
-
-
-
- }
- //UICollectionView被选中时调用的方法
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
-
- NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
-
- if(self.isSelectionMode)
- {
- bool checked =[[item valueForKey:@"checked"] boolValue];
-
- CategoryCellNPD *currentSelecteCell = (CategoryCellNPD *)[self.collectionview cellForItemAtIndexPath:indexPath];
-
-
- if(checked)
- {
- self.select_count--;
- if(self.select_count==0)
- {
- // self.addWishBtn.enabled = false;
- // self.addCartBtn.enabled = false;
- // self.addPortfolioBtn.enabled=false;
- }
- [item setValue:@"false" forKey:@"checked"];
-
- currentSelecteCell.checkImageView.hidden = true;
- if(self.categoryViewType != CATEGORY_VIEWTYPE_LIST)
- [currentSelecteCell setBackgroundColor: [UIColor whiteColor]];
- else
- [currentSelecteCell setBackgroundColor: [UIColor whiteColor]];
- }
- else
- {
- self.select_count++;
- // self.addWishBtn.enabled = true;
- // self.addCartBtn.enabled = true;
- // self.addPortfolioBtn.enabled=true;
- [item setValue:@"true" forKey:@"checked"];
- currentSelecteCell.checkImageView.hidden = false;
- [currentSelecteCell setBackgroundColor: UIColorFromRGB(0x009966)];
- }
- [items setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
- [self.category_data setObject:items forKey:@"items"];
-
-
- }
- else
- {
- NSString* detail_id = [NSString stringWithFormat:@"%@",[item valueForKey:@"product_id"]];
-
- [self showDetailat:detail_id category_id:nil name:[item objectForKey:@"fash_name"] index:indexPath.row];
- }
- }
- #pragma mark Deferred image loading (UIScrollViewDelegate)
- //// Load images for all onscreen rows when scrolling is finished
- //- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
- //{
- // if (!decelerate)
- // {
- // DebugLog(@"scrollViewDidEndDragging LOADMORE");
- // }
- //}
- //
- //- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- //{
- // DebugLog(@"scrollViewDidEndDecelerating LOADMORE");
- //}
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
-
- // [refreshHeaderViewegoRefreshScrollViewDidScroll:scrollView];//下拉刷新
-
-
-
- CGPoint contentOffsetPoint = self.collectionview.contentOffset;
-
- CGRect frame =self.collectionview.frame;
-
- UICollectionViewFlowLayout *flowLayout =(UICollectionViewFlowLayout*)[self.collectionview collectionViewLayout];
- if(flowLayout.scrollDirection== UICollectionViewScrollDirectionVertical)
- {
-
-
- DebugLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
- DebugLog(@"frame.size.height %f",frame.size.height);
- DebugLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
-
- // if ((contentOffsetPoint.y >= (self.collectionview.contentSize.height - frame.size.height)) || (self.collectionview.contentSize.height < frame.size.height&& [self.category_data[@"count"] intValue]>=PAGE_ITEM))
- if (contentOffsetPoint.y >= (self.collectionview.contentSize.height - frame.size.height) && self.collectionview.contentSize.height > frame.size.height)
- {
- if(self.isrefreshing)
- return;
- DebugLog(@"scroll to the end,load more......");
-
- [self loadMore];
- // self.btnLoad.hidden = NO;
-
- }
- }
- else if(flowLayout.scrollDirection== UICollectionViewScrollDirectionHorizontal)
- {
-
-
- DebugLog(@"contentOffsetPoint %f",contentOffsetPoint.y);
- DebugLog(@"frame.size.height %f",frame.size.height);
- DebugLog(@"self.collectionview.contentSize.height %f",self.collectionview.contentSize.height);
-
- // if (contentOffsetPoint.x >= (self.collectionview.contentSize.width - frame.size.width) || (self.collectionview.contentSize.width < frame.size.width && [self.category_data[@"count"] intValue]>=PAGE_ITEM))
- if (contentOffsetPoint.x >= (self.collectionview.contentSize.width - frame.size.width) && self.collectionview.contentSize.width > frame.size.width)
- {
- if(self.isrefreshing)
- return;
- DebugLog(@"scroll to the end,load more......");
-
- [self loadMore];
- // self.btnLoad.hidden = NO;
-
- }
- }
-
-
-
-
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark Jack
- - (void)addALlItem {
- self.addAll = !self.addAll;
- if (self.addAll) {
- [self.addAllCheckBtn setImage:[[UIImage imageNamed:@"check_1_24"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
- } else {
- [self.addAllCheckBtn setImage:[[UIImage imageNamed:@"check_0_24"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
- }
-
- }
- - (IBAction)addAllBtnClick:(id)sender {
- [self addALlItem];
- }
- - (IBAction)addAllCheckBtnClick:(id)sender {
- [self addALlItem];
- }
- - (void)reRefreshView {
- [self.collectionview reloadData];
- }
- #pragma mark - RA_NOTIFICAITON
- -(void) refresh_ui
- {
- [self.collectionview reloadData];
- }
- -(void) reload_data
- {
- self.offset = 0;
- [self reload];
- }
- @end
|