| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925 |
- //
- // DetailViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 7/25/15.
- // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "DetailViewController.h"
- #import "DetailHeaderCell.h"
- #import "DetailImageCell.h"
- #import "RANetwork.h"
- #import "RTLabel.h"
- #import "DetailKVCell.h"
- #import "LineView.h"
- //#import "SelectorViewController.h"
- #import "RAUtils.h"
- #import "MainViewController.h"
- #import "QRCodeGenerator.h"
- #import "DefaultTableHeaderView.h"
- #import "DefaultAppearance.h"
- #import "JKMessageBoxController.h"
- #import "CartUtils.h"
- #import "ImageUtils.h"
- #import "RAPDFViewController.h"
- #import "ModelDescriptionController.h"
- #import "TextUtils.h"
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- #import "HomerModelDetailHeaderCell.h"
- #endif
- #define DEF_CELL_HEIGHT 44
- #define DEF_TABLE_HEIGHT 44
- #define LINE_WIDTH 0
- #define CELL_MARGIN 0
- #define LABEL_MARGIN 10
- #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
- #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
- #define NavColor ([UIColor colorWithRed:237/255.0 green:20/255.0f blue:91/255.0f alpha:1.0f])
- @interface DetailViewController ()
- @property (nonatomic,strong) UIBezierPath *path;
- @end
- @implementation DetailViewController
- {
- CALayer *_layer;
- }
- #ifndef RA_NOTIFICATION
- -(void) reload_container_getdata:(bool) update_data
- {
-
- [super reload_container_getdata:update_data];
- if(update_data)
- [self reload];
- else
- {
- [self.detailTable reloadData];
- // [self refresh_total];
- }
- }
- #endif
- -(void)manually_refresh
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
-
- if(self.isrefreshing)
- {
- [reF endRefreshing];
- return;
- }
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
- if ([self respondsToSelector:@selector(ReloadData)])
- [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void) ReloadData
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
-
- [reF endRefreshing];
-
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
- [self reload];
-
-
- }
- -(void) reload
- {
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
-
-
- if(self.isrefreshing)
- return;
- #ifdef BUILD_UWAVER
- self.navigationItem.rightBarButtonItem.enabled = false;
- #endif
- self.label_net_err.hidden=true;
- self.detailTable.hidden = true;
- self.isrefreshing=true;
- self.mum.center = self.view.center;
- self.mum.hidden = false;
- [self.mum startAnimating];
-
- //self.detailTable.hidden=true;
-
-
- [RANetwork request_modeldetail:self.product_id model_name:self.model_name upc_code:self.upc_code category_id:self.category_id use_name:self.use_model_name use_upc:self.use_upc_code groupName:self.groupName completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* detail_json=result;
-
- [self.mum stopAnimating];
- #ifdef BUILD_UWAVER
- self.navigationItem.rightBarButtonItem.enabled = true;
- #endif
- self.groupName = nil;
- if([[detail_json valueForKey:@"result"] intValue]==2)
- {
-
- self.detail_data = [detail_json mutableCopy];
- self.product_id = [NSString stringWithFormat:@"%d",[[detail_json valueForKey:@"product_id"] intValue] ];
- NSMutableDictionary* imgsection = [[detail_json objectForKey:@"img_section"] mutableCopy];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/true)
- {
- #ifdef BUILD_CONTRAST
- self.quantity = [[imgsection valueForKey:@"stockUom"] intValue];
- #else
-
- self.quantity =[[imgsection valueForKey:@"stockUom"] intValue];
- #endif
- // else
- // self.quantity =1;
- }
- if(self.quantity==0)
- self.quantity=1;
- self.step=self.quantity;
- [self.detailTable reloadData];
-
- //
- self.detailTable.hidden = false;
-
- NSString* model_name = self.detail_data[@"img_section"][@"model_name"];
-
- NSString* img_url = self.detail_data[@"img_section"][@"model_s_img"];
-
- NSMutableDictionary* images=[self.detail_data[@"img_section"][@"images"] mutableCopy];
- NSMutableDictionary* videos=[self.detail_data[@"img_section"][@"videos"] mutableCopy];
-
- NSMutableDictionary* contents = [NSMutableDictionary new];
- int count = 0;
-
- {
- for(int ic=0;ic<[videos[@"count"] intValue];ic++)
- {
- NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
-
-
- // NSString* path=[[NSBundle mainBundle] pathForResource:@"play" ofType:@"jpg"];
- //
- // NSMutableDictionary* item =[@{@"type":@"video",@"is_localfile":@(true),@"l":path,@"s":path} mutableCopy];
- //
- // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
- // count++;
-
- NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
-
- contents[[NSString stringWithFormat:@"item_%d",count]]=item;
- count++;
- }
- }
-
- {
- for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
- {
- NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
- item[@"type"]=@"image";
- contents[[NSString stringWithFormat:@"item_%d",count]]=item;
- count++;
- }
- //#ifndef BUILD_HOMER
- #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
- // homer 要求去掉qrcode 2017/12/20
- NSString* qrpath = [ImageUtils generateQRCodeFile:model_name width:350 height:350];
- // UIImage* qrimg=[QRCodeGenerator qrImageForString:model_name imageSize:350];
- if(qrpath!=nil)
- {
- NSMutableDictionary* item =[@{@"type":@"image",@"is_localfile":@(true),@"l":qrpath,@"s":qrpath} mutableCopy];
-
- contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
- count++;
- }
- #endif
- }
-
-
-
-
- contents[@"count"]=@(count);
- imgsection[@"stack_contents"]=contents;
- self.detail_data[@"img_section"]=imgsection;
- // self.detail_data[@"img_section"][@"stack_contents"]=contents;
-
- NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
- [item setValue:self.product_id forKey:@"product_id"];
- [item setValue:self.category_id forKey:@"category"];
- [item setValue:model_name forKey:@"fash_name"];
- [item setValue:img_url forKey:@"picture_path"];
-
- [CartUtils add_recent_model:item];
-
- NSUInteger ii[2] = {0,0};
-
- [self.detailTable scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndexes:ii length:2] atScrollPosition:UITableViewScrollPositionTop animated:YES];
-
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // int count=[appDelegate.recent_model[@"count"] intValue];
- // bool bexist = false;
- // for(int i=0;i<count;i++)
- // {
- // NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
- // if([mitem[@"product_id"] isEqualToString:self.product_id])
- // {
- // bexist=true;
- // break;
- // }
- // }
- //
- // if(!bexist)
- // {
- // [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
- // appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
- // }
-
- self.groupName = [detail_json objectForKey:@"groupName"];
- }
- else
- if([[detail_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
- {
- self.detailTable.hidden = true;
- self.label_net_err.hidden=false;
- }
- else if([[detail_json valueForKey:@"result"] intValue]==RESULT_NO_MODEL)
- {
- self.detailTable.hidden = true;
- [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
- if(self.ispush)
- [ self.navigationController popViewControllerAnimated:true];
- }
- else
- {
- [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
- }
-
- self.isrefreshing=false;
-
-
- }];
-
- return;
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSMutableDictionary* detail_json = [[RANetwork request_ItemDetail:self.product_id model_name:self.model_name category_id:self.category_id use_name:self.use_model_name groupName:self.groupName] mutableCopy];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [self.mum stopAnimating];
- //#ifdef BUILD_UWAVER
- // self.navigationItem.rightBarButtonItem.enabled = true;
- //#endif
- // self.groupName = nil;
- // if([[detail_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // self.detail_data = [detail_json mutableCopy];
- // self.product_id = [NSString stringWithFormat:@"%d",[[detail_json valueForKey:@"product_id"] intValue] ];
- // NSMutableDictionary* imgsection = [[detail_json objectForKey:@"img_section"] mutableCopy];
- // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/true)
- // self.quantity =[[imgsection valueForKey:@"stockUom"] intValue];
- // else
- // self.quantity =1;
- //
- // if(self.quantity==0)
- // self.quantity=1;
- // self.step=self.quantity;
- // [self.detailTable reloadData];
- //
- // //
- // self.detailTable.hidden = false;
- //
- // NSString* model_name = self.detail_data[@"img_section"][@"model_name"];
- //
- // NSString* img_url = self.detail_data[@"img_section"][@"model_s_img"];
- //
- // NSMutableDictionary* images=[self.detail_data[@"img_section"][@"images"] mutableCopy];
- // NSMutableDictionary* videos=[self.detail_data[@"img_section"][@"videos"] mutableCopy];
- //
- // NSMutableDictionary* contents = [NSMutableDictionary new];
- // int count = 0;
- //
- // {
- // for(int ic=0;ic<[videos[@"count"] intValue];ic++)
- // {
- // NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
- //
- //
- // // NSString* path=[[NSBundle mainBundle] pathForResource:@"play" ofType:@"jpg"];
- // //
- // // NSMutableDictionary* item =[@{@"type":@"video",@"is_localfile":@(true),@"l":path,@"s":path} mutableCopy];
- // //
- // // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
- // // count++;
- //
- // NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
- //
- // contents[[NSString stringWithFormat:@"item_%d",count]]=item;
- // count++;
- // }
- // }
- //
- // {
- // for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
- // {
- // NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
- // item[@"type"]=@"image";
- // contents[[NSString stringWithFormat:@"item_%d",count]]=item;
- // count++;
- // }
- ////#ifndef BUILD_HOMER
- //#if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
- // // homer 要求去掉qrcode 2017/12/20
- // NSString* qrpath = [ImageUtils generateQRCodeFile:model_name width:350 height:350];
- //// UIImage* qrimg=[QRCodeGenerator qrImageForString:model_name imageSize:350];
- // if(qrpath!=nil)
- // {
- // NSMutableDictionary* item =[@{@"type":@"image",@"is_localfile":@(true),@"l":qrpath,@"s":qrpath} mutableCopy];
- //
- // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
- // count++;
- // }
- //#endif
- // }
- //
- //
- //
- //
- // contents[@"count"]=@(count);
- // imgsection[@"stack_contents"]=contents;
- // self.detail_data[@"img_section"]=imgsection;
- //// self.detail_data[@"img_section"][@"stack_contents"]=contents;
- //
- // NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
- // [item setValue:self.product_id forKey:@"product_id"];
- // [item setValue:self.category_id forKey:@"category"];
- // [item setValue:model_name forKey:@"fash_name"];
- // [item setValue:img_url forKey:@"picture_path"];
- //
- // [CartUtils add_recent_model:item];
- //
- // NSUInteger ii[2] = {0,0};
- //
- // [self.detailTable scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndexes:ii length:2] atScrollPosition:UITableViewScrollPositionTop animated:YES];
- //
- //
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //// int count=[appDelegate.recent_model[@"count"] intValue];
- //// bool bexist = false;
- //// for(int i=0;i<count;i++)
- //// {
- //// NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
- //// if([mitem[@"product_id"] isEqualToString:self.product_id])
- //// {
- //// bexist=true;
- //// break;
- //// }
- //// }
- ////
- //// if(!bexist)
- //// {
- //// [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
- //// appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
- //// }
- //
- // self.groupName = [detail_json objectForKey:@"groupName"];
- // }
- // else
- // if([[detail_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
- // {
- // self.detailTable.hidden = true;
- // self.label_net_err.hidden=false;
- // }
- // else if([[detail_json valueForKey:@"result"] intValue]==RESULT_NO_MODEL)
- // {
- // self.detailTable.hidden = true;
- // [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
- // if(self.ispush)
- // [ self.navigationController popViewControllerAnimated:true];
- // }
- // else
- // {
- // [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
- // }
- //
- //self.isrefreshing=false;
- //
- // });
- // });
- });
- }
- - (void)onBackClick:(UIButton *)sender {
-
- if(self.OnBack)
- {
- self.OnBack(self.add_cart,self.add_wish,self.update_data);
- }
- [self.navigationController popViewControllerAnimated:(false)];
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- // ;
- // }];
- }
- - (void)viewDidLoad {
-
-
- [super viewDidLoad];
- if(self.ispush)
- {
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
- }
- [self setupNavigationBar];
-
-
- #ifdef RA_NOTIFICATION
- self.support_scanner = true;
- #endif
- [self registeObserver];
- self.refresh_type = REFRESH_VIEW;
-
- [self registNotification];
-
-
- // self.detailTable.style = UITableViewStylePlain;
- // return;
- // self.edgesForExtendedLayout = UIRectEdgeNone;
-
-
- if(self.ispush)
- {
- UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.000001)];
- [line setBackgroundColor:[UIColor clearColor]];
- self.detailTable.tableHeaderView = line;
- }
- //
- //
- // self.automaticallyAdjustsScrollViewInsets = false;
- self.step=1;
- self.quantity=1;
-
-
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 300 ;
- 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.detailTable addSubview:ref];
-
-
- 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;
-
-
-
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
- // tap.minimumPressDuration = 0.8; //定义按的时间
- [self.label_net_err addGestureRecognizer:tap];
-
- // Do any additional setup after loading the view.
-
-
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- [self.detailTable registerNib:[UINib nibWithNibName:@"HomerModelDetailHeaderCell" bundle:nil] forCellReuseIdentifier:@"HomerModelDetailHeaderCell"];
- #endif
-
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- if(self.ispush)
- {
-
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
- }
- }
- - (void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- if(self.ispush)
- [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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.
- }
- */
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
-
- //将page2设定成Storyboard Segue的目标UIViewController
- id page2 = segue.destinationViewController;
-
- //将值透过Storyboard Segue带给页面2的string变数
- [page2 setValue: _selector forKey:@"selector"];
- [page2 setValue: self forKey:@"selectordelegate"];
-
-
-
- }
- //- (IBAction)OnAddPortfolio:(id)sender {
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- // [appDelegate test_onDecodedDataResult:@"371252"];
- //// [self onDecodedData:@"3712524-235"];
- // return;
- //}
- //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- //// [self.detailTable reloadData];
- //// return;
- // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
- //
- //// NSMutableIndexSet *sectionToReload = [[NSMutableIndexSet alloc] init];
- //// int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
- ////
- //// for(int i=0;i<section_count;i++)
- //// {
- //// NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)i]];
- ////
- ////
- ////
- //// NSString* type=[section_json valueForKey:@"type"] ;
- ////
- //// if([type isEqualToString:@"kv"])
- //// {
- ////
- //// [sectionToReload addIndex:i+1];
- //// }
- //// }
- ////
- ////
- //// [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationNone];
- ////
- //
- // [self.detailTable reloadData];
- //
- //
- //
- //}
- - (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.detailTable reloadData];
- }];
- }
- #pragma mark - Notification
- - (void)registNotification {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserLoginNotification:) name:User_LoginOK_Notification object:nil];
- }
- - (void)unregistNotification {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:User_LoginOK_Notification object:nil];
- }
- #pragma mark - Nav Bar
- - (void)setupNavigationBar {
-
-
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
-
- self.navigationItem.leftBarButtonItem = backButton;
-
-
- #ifdef BUILD_UWAVER
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (appDelegate.bLogin) {
- // UIBarButtonItem *hangTagItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(hanTagBtnClick:)];
-
- UIBarButtonItem *hangTagItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btn_print_order"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(hanTagBtnClick:)];
-
- hangTagItem.enabled = false;
- self.navigationItem.rightBarButtonItem = hangTagItem;
- }
- #endif
-
- }
- #pragma mark - Action
- - (void)handleUserLoginNotification:(NSNotification *)notification {
-
- [self setupNavigationBar];
- }
- - (void)hanTagBtnClick:(id)sender {
-
- DetailViewController *vc = self;
-
- NSString *catelog_name = [NSString stringWithFormat:@"%@ Hang Tag",vc.groupName];
-
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
- [RANetwork request_hangtag:vc.groupName completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* editor_json =result;
-
- [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSString* url = [editor_json valueForKey:@"pdf_path"];
- bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
- RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- ViewController.url = url;
- ViewController.canSave = false;
- ViewController.isLocalfile=isLocalFile;
-
- ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
-
-
- NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
-
- if(company==nil)
- company=@"";
-
- NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
-
-
- NSMutableArray* send_to = [[NSMutableArray alloc]init];
- if(customer_email.length>0)
- {
- send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
- }
- ViewController.mail_to = send_to;
-
- NSString* subject;
-
- subject =catelog_name;
-
- ViewController.mail_subject = subject;
-
- ViewController.hidenavi = false;
- [vc.navigationController pushViewController:ViewController animated:YES];
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
- }
- }];
-
-
-
-
-
- }];
- }];
-
- return;
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [RANetwork request_hangTag:vc.groupName];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- // NSString* url = [editor_json valueForKey:@"pdf_path"];
- // bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
- // RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- // ViewController.url = url;
- // ViewController.canSave = false;
- // ViewController.isLocalfile=isLocalFile;
- //
- // ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
- //
- //
- // NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
- //
- // if(company==nil)
- // company=@"";
- //
- // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
- //
- //
- // NSMutableArray* send_to = [[NSMutableArray alloc]init];
- // if(customer_email.length>0)
- // {
- // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
- // }
- // ViewController.mail_to = send_to;
- //
- // NSString* subject;
- //
- // subject =catelog_name;
- //
- // ViewController.mail_subject = subject;
- //
- // ViewController.hidenavi = false;
- // [vc.navigationController pushViewController:ViewController animated:YES];
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
- // }
- //
- // });
- // });
-
- }
- #pragma mark - Selector delegate
- -(void) selected:(NSString*) detail_id category:(NSString*) category
- {
- self.product_id = detail_id;
- self.use_model_name = false;
- [self reload];
- DebugLog(@"color selected");
- }
- #pragma mark - Header cell delegate
- -(void) SelectorClicked:(UIView*) trigger
- {
- // int selcount = [[self.selector valueForKey:@"count"] intValue];
-
-
-
-
- int selector_count = [[self.selector valueForKey:@"count"] intValue];
-
-
- int current_sel = -1;
- for(int i=0;i<selector_count;i++)
- {
- NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
-
- // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
-
-
-
- if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
- {
-
- current_sel = i;
- }
- }
-
-
- // NSArray * arr = [[NSArray alloc] init];
- // arr = [NSArray arrayWithObjects:@"Hello 0", @"Hello 1", @"Hello 2", @"Hello 3", @"Hello 4", @"Hello 5", @"Hello 6", @"Hello 7", @"Hello 8", @"Hello 9",nil];
- // NSArray * arrImage = [[NSArray alloc] init];
- // arrImage = [NSArray arrayWithObjects:[UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], [UIImage imageNamed:@"apple.png"], [UIImage imageNamed:@"apple2.png"], nil];
- if(self.dropDown == nil)
- {
- CGFloat height = 70*selector_count;
- if (selector_count > 4) {
- height = 70 * 4.5;
- }
- self.dropDown =[[NIDropDown alloc] showDropDown:self.detailTable based:(id)trigger height:height data:self.selector direction:@"down" current_sel:current_sel];
-
-
- //Capturing strongly warring;
- __block DetailViewController *brself= self;
- self.dropDown.dropDownTouchOutsideBlk = ^{
- [brself.dropDown hideDropDown:(id)trigger];
- brself.dropDown= nil;
- };
- self.dropDown.selectChanged =^(long index){
-
-
- NSDictionary* item = [brself.selector objectForKey:[NSString stringWithFormat:@"item_%ld",index]];
-
- NSDictionary* params = [item objectForKey:@"params"];
-
- NSString* detail_id=[[[params objectForKey:@"param_0"] valueForKey:@"val" ] stringValue];
-
-
- brself.product_id = detail_id;
- brself.use_model_name = false;
- [brself reload];
- // DebugLog(@"color selected");
- brself.dropDown = nil;
-
-
-
- };
- //[[NIDropDown alloc]showDropDown:(id)trigger :&f :arr :arrImage :@"down"];
- // self.dropDown.delegate = self;
- }
- else {
- [self.dropDown hideDropDown:(id)trigger];
- self.dropDown= nil;
- // [self rel];
- }
-
- return;
-
-
- }
- -(void) stepClicked:(int) value
- {
- self.quantity = value;
- }
- #pragma mark - Topic cell delegate
- -(void) TopicItemClicked:(NSString*) product_id category:(NSString*) category
- {
-
- // self.model_name = value;
- self.product_id = product_id;
- self.category_id=category;
- [self reload];
- DebugLog(@"color selected");
- }
- #pragma mark - Table view data source
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 0;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // return myView;
- //
- //}
- //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
- //// titleLabel.textColor=[UIColor whiteColor];
- //// titleLabel.backgroundColor = [UIColor clearColor];
- //// if(section==0)
- //// titleLabel.text=NSLocalizedString(@"display_items", nil);
- //// else
- //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
- //// [titleLabel sizeToFit];
- //// [myView addSubview:titleLabel];
- ////
- // return myView;
- //}
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- if(section==0)
- return nil;
-
- NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
- if(related_json==nil)
- {
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
- return [section_json valueForKey:@"title"] ;
- }
- else
- {
- if(section==1)
- return @"related model";
- else
- {
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
- return [section_json valueForKey:@"title"] ;
- }
- }
- }
- //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- //{
- // return 33;
- //}
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
-
-
- NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
-
- if(value==nil)
- value=@"";
- unsigned long color = strtoul([value UTF8String],0,16);
-
- NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
- if (sectionTitle == nil) {
- return nil;
- }
-
-
- DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
- // myView.backgroundColor = UIColorFromRGB(0x996633);
- myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
- myView.layer.shadowColor = [UIColor blackColor].CGColor;
- myView.layer.shadowOffset = CGSizeMake(0, 0);
- myView.layer.shadowOpacity = 0.5;
- myView.layer.shadowRadius = 2.0;
-
- UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5.5, 90, 22)];
- titlelabel.textColor=UIColorFromRGB(color);
- // titlelabel.backgroundColor = [UIColor clearColor];
- titlelabel.text=sectionTitle;
- [titlelabel sizeToFit];
-
-
-
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
- bool refresh= [[section_json valueForKey:@"partial_refresh"] boolValue] ;
-
-
- if(refresh)
- {
- NSString* btntitle=@"Refresh" ;
- // NSString* value =[DefaultAppearance get_noneappearance_value:@"DetailTableHeaderView" valuename:@"refresh_button_color"];
- //
- // if(value==nil)
- // value=@"";
- // unsigned long color = strtoul([value UTF8String],0,16);
-
-
-
- UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-100-15, 0, 100, 33)];
-
-
- // [btn setTitleColor:UIColorFromRGB(color) forState:UIControlStateNormal];
- btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
- btn.tag=section;
- [btn addTarget:self action:@selector(RefreshSection:) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitle:btntitle forState:UIControlStateNormal];
- [myView addSubview:btn];
- }
-
- [myView addSubview:titlelabel];
-
- return myView;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
- if(section_count==0)
- return section_count;
- NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
- if(related_json==nil)
- return section_count+1;
- else
- return section_count+2;
- }
- //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- // DebugLog(@"canMoveRowAtIndexPath");
- //
- // if([tableView numberOfRowsInSection:indexPath.section]>1)
- // return true;
- // else
- // return false;
- //}
- //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
- //{
- // NSMutableArray * from;
- // NSMutableArray * to ;
- // if(fromIndexPath.section==0)
- // from = self.displayfields;
- // else
- // from = self.hidefields;
- // if(toIndexPath.section==0)
- // to = self.displayfields;
- // else
- // to = self.hidefields;
- // id content=from[fromIndexPath.row];
- // [from removeObjectAtIndex:fromIndexPath.row];
- // [to insertObject:content atIndex:toIndexPath.row];
- //
- // [tableView reloadData];
- //
- //}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- if(section==0)
- return 1;
- NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
- if(related_json==nil)
- {
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-1]];
- NSString* type=[section_json valueForKey:@"type"] ;
- if([type isEqualToString:@"content"])
- return 1;
- return [[section_json valueForKey:@"count"] intValue];
- }
- else
- {
- if(section==1)
- return 1;
- else
- {
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
- NSString* type=[section_json valueForKey:@"type"] ;
- if([type isEqualToString:@"content"])
- return 1;
- return [[section_json valueForKey:@"count"] intValue];
- }
- }
-
-
-
- }
- //- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- // return UITableViewCellEditingStyleNone;
- //}
- //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- // //如果两次点击的时间间隔小于1秒,则断定为双击事件
- //
- // if(tableView.editing==false)
- // return;
- //
- //
- // if([tableView numberOfRowsInSection:indexPath.section]<=1)
- // return;
- // // int between = 1;
- // NSUInteger curr = [[NSDate date] timeIntervalSince1970];
- //
- // if(indexPath.row==self.lasttap.row&&indexPath.section==self.lasttap.section)
- // {
- // if (curr-self.taptime<1) {
- // DebugLog(@"double click!");
- // self.lasttap =nil;
- //
- // NSMutableArray * from;
- // NSMutableArray * to ;
- // int section;
- // if(indexPath.section==0)
- // {
- // from = self.displayfields;
- // to = self.hidefields;
- // section = 1;
- // }
- // else
- // {
- //
- // from = self.hidefields;
- // to = self.displayfields;
- // section = 0;
- // }
- // NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
- // // NSIndexPath * headerIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
- // // NSIndexPath * headerIndexPath1 = toIndexPath;
- //
- // id content=from[indexPath.row];
- // [tableView beginUpdates];
- // [from removeObjectAtIndex:indexPath.row];
- // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- //
- // [to insertObject:content atIndex:0];
- // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- // [tableView endUpdates];
- //
- // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
- // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
- // [tableView reloadData];
- //
- //
- // }
- // self.taptime = curr;
- //
- //
- // }
- // else
- // {
- // self.taptime = curr;
- // self.lasttap = indexPath;
- // }
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if(section ==0)
- return 0;
- else
- return 33;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
- if(indexPath.section ==0) {
-
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- CGFloat height = CGRectGetHeight(self.view.bounds);
- if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
- return height;
- }
- #endif
- return 550;
- }
-
-
- // NSDictionary* nsdic = self.detail_data;
- NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
- if(related_json==nil)
- {
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
-
- NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- NSString* type=[section_json valueForKey:@"type"] ;
-
- if([type isEqualToString:@"kv"])
- {
- float width = tableView.frame.size.width;
- width-=CELL_MARGIN*2;
- CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
- CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
-
-
-
- // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- NSString* key =[item_json valueForKey:@"key"] ;
-
- // [cell.keyLabel sizeToFit];
- NSString* val=[item_json valueForKey:@"val"] ;
-
- if([val isEqual:[NSNull null]])
- val=@"";
- if(val==nil)
- val=@"";
- if([val isEqualToString:@"null"])
- val=@"";
-
-
-
- CGRect frame;
- frame.size = constraintval;
- frame.origin.x=0;
- frame.origin.y=0;
- RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
- [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
- // rtlabel.lineSpacing = 20.0;
- [rtlabel setText: val];
- CGSize sizeval=rtlabel.optimumSize;
-
-
- // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
- CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
- float height = MAX(sizekey.height,sizeval.height);
- height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
-
-
- return height;
- }
- else if([type isEqualToString:@"img"])
- {
- int img_count = [[item_json valueForKey:@"count"] intValue];
- double ret = 0;
- for(int j=0;j<img_count;j++)
- {
- NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
- float width = [[img_json valueForKey:@"width"]floatValue];
- float height = [[img_json valueForKey:@"height"]floatValue];
- ret+=height*tableView.bounds.size.width / width;
- }
-
- return ret;
- }
- else if([type isEqualToString:@"content"])
- return 270;
- return 44;
- }
- else
- {
- if(indexPath.section==1)
- return 270;
- else
- {
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-2]];
-
- NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- NSString* type=[section_json valueForKey:@"type"] ;
-
- if([type isEqualToString:@"kv"])
- {
- float width = tableView.frame.size.width;
- width-=CELL_MARGIN*2;
- CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
- CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
-
-
-
- // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- NSString* key =[item_json valueForKey:@"key"] ;
-
- // [cell.keyLabel sizeToFit];
- NSString* val=[item_json valueForKey:@"val"] ;
-
- if([val isEqual:[NSNull null]])
- val=@"";
- if(val==nil)
- val=@"";
- if([val isEqualToString:@"null"])
- val=@"";
-
-
-
- CGRect frame;
- frame.size = constraintval;
- frame.origin.x=0;
- frame.origin.y=0;
- RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
- [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
- // rtlabel.lineSpacing = 20.0;
- [rtlabel setText: val];
- CGSize sizeval=rtlabel.optimumSize;
-
-
- // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
- float height = MAX(sizekey.height,sizeval.height);
- height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
-
-
- return height;
- }
- else if([type isEqualToString:@"img"])
- {
- int img_count = [[item_json valueForKey:@"count"] intValue];
- double ret = 0;
- for(int j=0;j<img_count;j++)
- {
- NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
- float width = [[img_json valueForKey:@"width"]floatValue];
- float height = [[img_json valueForKey:@"height"]floatValue];
- ret+=height*tableView.bounds.size.width / width;
- }
-
- return ret;
- }
- return 44;
- }
- }
-
- }
- - (BOOL)isOutofStock {
- NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
- NSString *qtyStr = [section_json valueForKey:@"Availability"];
-
- // 2018-01-10 修改通过lowercase判断
- if (!qtyStr || !qtyStr.length || [qtyStr.lowercaseString isEqualToString:@"in production"] || [qtyStr isEqualToString:@"0"] || [qtyStr.lowercaseString isEqualToString:@"sold out"] || [qtyStr.lowercaseString isEqualToString:@"out of stock"]) {
- return YES;
- }
- return NO;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // DebugLog(@"cellForRowAtIndexPath");
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- if(indexPath.section==0)
- {
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- NSString *CellIdentifier = @"HomerModelDetailHeaderCell";
- HomerModelDetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
-
- CGFloat w = CGRectGetWidth(tableView.bounds);
- CGFloat h = CGRectGetHeight(tableView.bounds);
- CGFloat space_w = w - 320;
- CGFloat photoStackWidth = space_w - (35 * 2);
- CGFloat photoStackHeight = h - 102 - 70;
- CGFloat a = MIN(photoStackWidth, photoStackHeight);
-
- CGFloat x = (space_w - a) * 0.5, y = 102 + (photoStackHeight - a) * 0.5;
- if (x > 50) {
- x -= 20;
- }
-
- cell.photoStack.frame = CGRectMake(x, y, a, a);
- cell.pageControl.frame = CGRectMake((space_w - 319) * 0.5, h - 50, 319, 37);
-
- } else {
-
- cell.photoStack.frame = CGRectMake(35, 107, 349, 348);
- cell.pageControl.frame = CGRectMake(50, 466, 319, 37);
-
- }
-
- #else
- NSString *CellIdentifier = @"DetailHeaderCell";
- DetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.btn_hangtag.hidden = YES;
- #endif
-
-
- NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
-
- // Homer添加的View
- cell.hmlg_stock_lb.hidden = YES;
- cell.hmlg_stock_count_lb.hidden = YES;
- cell.on_sale_lb.hidden = YES;
-
- if (!appDelegate.user) { // 没有登录时隐藏add to portfolio,使add to cart与add to wishlist对齐
-
- cell.btnaddPortfolio.hidden = YES;
- cell.btnNotifyMe.hidden = YES;
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- // cell.hmlg_stock_lb.hidden = NO;
- // cell.hmlg_stock_count_lb.hidden = NO;
- BOOL is_special_model = [[section_json objectForKey:@"is_special_model"] boolValue];
- id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
- if (hmlg_stock == nil) {
- hmlg_stock = @"";
- }
- cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
-
- cell.on_sale_lb.hidden = !is_special_model;
- #endif
- } else {
-
- #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
- // NSString *qtyStr = [section_json valueForKey:@"Availability"];
-
- __weak typeof(self) weakself = self;
- cell.notifyMeBlock = ^{
-
- __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
- [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary *dic =result;
-
-
- [waitting_alert dismissViewControllerAnimated:YES completion:^{
- int result_code = [[dic valueForKey:@"result"] intValue];
-
- if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS) {
-
- NSString *msg = [NSString stringWithFormat:@"The email send failed"];
-
- if ([dic valueForKey:@"err_msg"]) {
- msg = [dic valueForKey:@"err_msg"];
- }
-
-
- UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- [errorAlertVC addAction:action];
- [weakself presentViewController:errorAlertVC animated:YES completion:nil];
-
- } else if (result_code == RESULT_TRUE){
-
- [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
-
- } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
-
- [self showEmailAddrBox];
-
- }
- }];
- // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
-
-
-
- }];
- }];
-
-
- // dispatch_async(dispatch_get_global_queue(0,0), ^{
- //
- // NSDictionary *dic = [RANetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
- //
- // NSInteger result = [[dic valueForKey:@"result"] integerValue];
- //
- // if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
- //
- // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
- //
- // if ([dic valueForKey:@"err_msg"]) {
- // msg = [dic valueForKey:@"err_msg"];
- // }
- //
- //
- // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
- // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- //
- // }];
- //
- // [errorAlertVC addAction:action];
- // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
- //
- // } else if (result == RESULT_TRUE){
- //
- // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
- //
- // } else if (result == RESULT_NO_EMAIL_ADDRESS) {
- //
- // [self showEmailAddrBox];
- //
- // }
- // });
- //
- //
- // });
-
-
- };
-
-
- if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-
- cell.btnaddPortfolio.hidden = YES;
-
- if (!notifyMe_switch) {
-
- cell.btnNotifyMe.hidden = YES;
-
- } else {
-
-
- cell.btnNotifyMe.hidden = NO;
-
-
- if (!appDelegate.order_code) { // 未打开订单状态
-
- if ([self isOutofStock]) {
-
- if (!appDelegate.can_create_backorder) {
- cell.btnaddCart.enabled = NO;
- }
- cell.btnNotifyMe.enabled = YES;
-
- } else {
-
- cell.btnaddCart.enabled = YES;
- cell.btnNotifyMe.enabled = NO;
- }
-
- } else {
- // 打开订单状态
- if (![RASingleton sharedInstance].currentOrderIsMerged) {
- // Shop Order
- cell.btnaddCart.enabled = YES;
- // 默认未缺货
- cell.btnNotifyMe.enabled = NO;
-
- if ([self isOutofStock]) { // 缺货
-
- cell.btnNotifyMe.enabled = YES;
-
- }
-
- } else {
- // Purchase Order
- if ([self isOutofStock]) { // 缺货
- if (!appDelegate.can_create_backorder) {
- cell.btnaddCart.enabled = NO;
- }
- cell.btnNotifyMe.enabled = YES;
- } else { // 未缺货
- cell.btnNotifyMe.enabled = NO;
- cell.btnaddCart.enabled = YES;
- }
-
- }
-
-
- }
-
-
- }
-
- } else { // employee
-
- // online
- cell.btnaddPortfolio.hidden = NO;
- cell.btnNotifyMe.hidden = NO;
-
- if ([self isOutofStock]) { // 缺货
- if (!appDelegate.can_create_backorder) {
- cell.btnaddCart.enabled = NO;
- }
- cell.btnNotifyMe.enabled = YES;
- } else { // 未缺货
- cell.btnNotifyMe.enabled = NO;
- cell.btnaddCart.enabled = YES;
-
- }
-
- // offline
- #ifdef OFFLINE_MODE
- if (appDelegate.offline_mode) {
- cell.btnNotifyMe.hidden = YES;
- }
- #endif
-
- }
- #endif
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
-
- // cell.hmlg_stock_lb.hidden = NO;
- // cell.hmlg_stock_count_lb.hidden = NO;
- id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
- if (hmlg_stock == nil) {
- hmlg_stock = @"";
- }
- cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
- cell.on_sale_lb.hidden = !is_special_model;
-
- NSString *qtyStr = [section_json valueForKey:@"Availability"];
-
- __weak typeof(self) weakself = self;
-
-
- cell.notifyMeBlock = ^{
-
- UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
-
-
- [RANetwork request_notifymodel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary *dic =result;
-
-
-
- [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
-
- NSInteger result = [[dic valueForKey:@"result"] integerValue];
-
- if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
-
- NSString *msg = [NSString stringWithFormat:@"The email send failed"];
-
- if ([dic valueForKey:@"err_msg"]) {
- msg = [dic valueForKey:@"err_msg"];
- }
-
-
- UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- [errorAlertVC addAction:action];
- [weakself presentViewController:errorAlertVC animated:YES completion:nil];
-
- } else if (result == RESULT_TRUE){
-
- [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
-
- } else if (result == RESULT_NO_EMAIL_ADDRESS) {
-
- [self showEmailAddrBox];
-
- }
-
-
-
- }];
-
-
- // dispatch_async(dispatch_get_global_queue(0,0), ^{
- //
- // NSDictionary *dic = [RANetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
- //
- // NSInteger result = [[dic valueForKey:@"result"] integerValue];
- //
- // if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
- //
- // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
- //
- // if ([dic valueForKey:@"err_msg"]) {
- // msg = [dic valueForKey:@"err_msg"];
- // }
- //
- //
- // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
- // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- //
- // }];
- //
- // [errorAlertVC addAction:action];
- // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
- //
- // } else if (result == RESULT_TRUE){
- //
- // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
- //
- // } else if (result == RESULT_NO_EMAIL_ADDRESS) {
- //
- // [self showEmailAddrBox];
- //
- // }
- // });
- //
- //
- // });
-
-
- };
-
-
- if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-
- cell.btnaddPortfolio.hidden = YES;
-
- if (!notifyMe_switch) {
-
- cell.btnNotifyMe.hidden = YES;
-
- } else {
-
-
- cell.btnNotifyMe.hidden = NO;
-
-
- if (!appDelegate.order_code) { // 未打开订单状态
-
- if ([self isOutofStock]) {
-
- if (!appDelegate.can_create_backorder) {
- cell.btnaddCart.enabled = NO;
- }
- cell.btnNotifyMe.enabled = YES;
-
- } else {
-
- cell.btnaddCart.enabled = YES;
- cell.btnNotifyMe.enabled = NO;
- }
-
- } else {
- // 打开订单状态
- if (![Singleton sharedInstance].currentOrderIsMerged) {
- // Shop Order
- cell.btnaddCart.enabled = YES;
- // 默认未缺货
- cell.btnNotifyMe.enabled = NO;
-
- if ([self isOutofStock]) { // 缺货
-
- cell.btnNotifyMe.enabled = YES;
-
- }
-
- } else {
- // Purchase Order
- if ([self isOutofStock]) { // 缺货
- if (!appDelegate.can_create_backorder) {
- cell.btnaddCart.enabled = NO;
- }
- cell.btnNotifyMe.enabled = YES;
- } else { // 未缺货
- cell.btnNotifyMe.enabled = NO;
- cell.btnaddCart.enabled = YES;
- }
-
- }
-
-
- }
-
-
- }
-
- } else { // employee
-
- // online
- cell.btnaddPortfolio.hidden = NO;
- cell.btnNotifyMe.hidden = NO;
-
- if ([self isOutofStock]) { // 缺货
- if (!appDelegate.can_create_backorder) {
- cell.btnaddCart.enabled = NO;
- }
- cell.btnNotifyMe.enabled = YES;
- } else { // 未缺货
- cell.btnNotifyMe.enabled = NO;
- cell.btnaddCart.enabled = YES;
-
- }
-
- // offline
- #ifdef OFFLINE_MODE
- if (appDelegate.offline_mode) {
- cell.btnNotifyMe.hidden = YES;
- }
- #endif
-
- }
- #endif
-
-
- #ifdef BUILD_HMLG
- cell.btnaddPortfolio.hidden = NO;
- cell.btnNotifyMe.hidden = YES;
- #endif
-
- }
-
-
- // self.anchor_button.frame=cell.selector_Button.frame;
- cell.celldelegate=self;
- cell.quantity_text.text = [NSString stringWithFormat:@"%d",self.quantity];
- cell.step = self.step;
- cell.quantity = self.quantity;
-
- // cell.stepper.stepValue = self.step;
- // cell.stepper.value = self.quantity;
-
- NSString* price = [section_json valueForKey:@"price"];
-
-
-
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.contact_id ==nil)
- {
- // appDelegate.bLogin = false;
- // cell.btnaddCart.enabled = false;
- }
- else
- {
- if ([price isEqualToString:@"No Price."]) {
- // cell.btnaddCart.enabled = false;
- }
- else
- {
- // cell.btnaddCart.enabled = true;
- }
- }
-
-
- int cqty = [[section_json valueForKey:@"Model QTY in cart"] intValue];
-
- cell.cqty = cqty;
- cell.set_cqty=^(int cqty)
- {
- [section_json setValue:[NSString stringWithFormat:@"%d",cqty] forKey:@"Model QTY in cart"];
-
- [self.detail_data setObject:section_json forKey:@"img_section"];
-
- [self.detailTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
-
- };
- cell.set_update_data=^(bool bupdate)
- {
- //self.update_data = bupdate;
-
- #ifdef RA_NOTIFICATION
- if(bupdate)
- [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- else
- [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
- #else
- if(bupdate)
- [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- else
- [((MainViewController*)appDelegate.main_vc) reloadCategory:false immediately:false];
- #endif
-
- };
- if(cqty>0)
- {
- cell.cqyt_label.hidden=false;
- cell.cqyt_label.text=[NSString stringWithFormat:@"Model QTY in Cart:%d",cqty];
- }
- else
- {
- cell.cqyt_label.hidden=true;
- cell.cqyt_label.text=nil;
- }
-
-
- cell.descriptionRTLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
-
- // cell.descriptionLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
- cell.model_label.text =[section_json valueForKey:@"model_name"];
-
-
- // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:80];
- // cell.qrcode_imageview.image = qrimg;
- if(appDelegate.bLogin==true)
- {
-
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- price=nil;
- }
- }
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- NSString *old_price = [section_json objectForKey:@"old_price"];
- if (appDelegate.user && old_price != nil && old_price.length > 0) {
- cell.priceLabel.text = nil;
- NSString *new_price_str = [NSString stringWithFormat:@"%@ %@",price,old_price];
- NSRange range = [new_price_str rangeOfString:@"$" options:NSBackwardsSearch];
- range = NSMakeRange(range.location,new_price_str.length - range.location);
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:new_price_str];
- [attrStr addAttributes:@{
- NSStrikethroughStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle]
- }
- range:range];
- cell.priceLabel.attributedText = attrStr;
-
- } else {
- cell.priceLabel.attributedText = nil;
- cell.priceLabel.text =price;
- }
- #else
- cell.priceLabel.text =price;
- #endif
-
-
-
- // cell.shipLabel.text = [section_json valueForKey:@"ship"];
- cell.count_Label.text =[section_json valueForKey:@"Availability"] ;
-
-
- NSString* eta =[section_json valueForKey:@"ETA"] ;
- if(eta.length>0)
- {
-
- cell.eta_label.hidden = false;
- cell.etaval_label.text = eta;
- cell.etaval_label.hidden = false;
-
-
- cell.incoming_stock_label.hidden=false;
- cell.incomingcount_Label.text =[section_json valueForKey:@"incoming_stock"] ;
- cell.incomingcount_Label.hidden = false;
-
-
- }
- else
- {
- cell.eta_label.hidden = true;
- cell.etaval_label.text = nil;
- cell.etaval_label.hidden = true;
-
- cell.incoming_stock_label.hidden = true;
- cell.incomingcount_Label.text = nil;
- cell.incomingcount_Label.hidden = true;
- }
- self.selector = [section_json objectForKey:@"selector"];
-
- if(self.selector!=nil)
- {
-
- [cell Hide_selector:false];
- cell.selector_nameLabel.text =[self.selector valueForKey:@"name"];
-
- int selector_count = [[self.selector valueForKey:@"count"] intValue];
-
- cell.selector_imageView.image = [UIImage imageNamed:@"loading_s"];
-
- for(int i=0;i<selector_count;i++)
- {
- NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
-
- // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
-
-
-
- if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
- {
- cell.selector_valLabel.text=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"];
-
- NSString* selectstr=[NSString stringWithFormat:@"%@: %@",[self.selector valueForKey:@"name"],[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"]];
- if([[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"] ==nil)
- selectstr=[NSString stringWithFormat:@"%@:",[self.selector valueForKey:@"name"]];
- cell.selector_label.text = selectstr;
-
- NSString* img_url = [[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"pic_url"];
-
-
-
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIImage * img =[UIImage imageWithData:img_data];
- cell.selector_imageView.image=img;
-
-
-
- });
- }
- else
- {
- NSData* downloadimg_data = nil;
- // BOOL offline = NO;
- //#ifdef OFFLINE_MODE
- // offline = appDelegate.offline_mode;
- //#endif
- // if (!offline) {
- 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.selector_imageView.image=img;
- }
- else
- cell.selector_imageView.image = [UIImage imageNamed:@"notfound_s"];
-
- });
- }
-
- }
- }
- }
- else
- {
- [cell Hide_selector:true];
- }
- // cell.selector_valLabel.text =[[section_json objectForKey:@"selector"] valueForKey:@"name"];
-
-
- NSDictionary* property_json = [section_json objectForKey:@"property"];
- // int pcount = [[property_json valueForKey:@"count"]intValue];
- cell.property_nameLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"key"];
- cell.property_valLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"val"];
-
- cell.product_id = self.product_id;
- // cell.itemIDLabel.text = [NSString stringWithFormat:@"Item id:%d",3947105];
- [cell setup];
- [cell ClearPhotos];
- // NSDictionary* imgs_json = [section_json objectForKey:@"images"];
- NSDictionary* contents_json = [section_json objectForKey:@"stack_contents"];
- cell.stack_contents = contents_json;
- int count = [[contents_json valueForKey:@"count"]intValue];
- int hcount=2;
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- hcount=1; //homer 没有qrcode
- #endif
- if(count<hcount)//1 for qrcode;
- cell.pageControl.hidden = true;
- else
- cell.pageControl.hidden = false;
-
- // NSMutableArray* urls= [[NSMutableArray alloc]init];
-
- // cell.urls = urls;
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- for(int i=0;i<count;i++)
- {
-
- NSDictionary* item_json=[contents_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
-
- NSString* type = item_json[@"type"];
- // if([type isEqualToString:@"video"])
- // {
- // [cell AddPhoto:[UIImage imageNamed:@"play"]];
- // ;
- // }
- // else if([type isEqualToString:@"image"])
- {
- NSString* img_url = [item_json valueForKey:@"s"];
-
-
- // NSString* img_url_l = [img_json valueForKey:@"l"];
- // if(img_url_l.length>0)
- // [urls addObject:img_url_l];
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=nil;
-
- if([type isEqualToString:@"video"])
- {
- img_data = UIImagePNGRepresentation([UIImage imageNamed:@"play"]);
- }
- else
- {
- if([item_json[@"is_localfile"] boolValue])
- img_data = [NSData dataWithContentsOfFile:img_url];
- else
- img_data = [iSalesDB load_cached_img:file_name loadFrom:img_url];
- }
-
- if(img_data!=nil)
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIImage * img =[UIImage imageWithData:img_data];
- [cell AddPhoto:img];
-
-
- // if(i==count-1)
- // {
- // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
- // if(qrimg!=nil)
- // [cell AddPhoto:qrimg];
- // }
- // if(i==0)
- // cell.imageView.image = img;
- });
- }
- else
- {
- NSData* downloadimg_data = nil;
-
- // BOOL offline = NO;
- //#ifdef OFFLINE_MODE
- // offline = appDelegate.offline_mode;
- //#endif
- // if (!offline) {
- 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 AddPhoto:img];
-
- // if(i==count-1)
- // {
- // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
- // if(qrimg!=nil)
- // [cell AddPhoto:qrimg];
- // }
- // if(i==0)
- // cell.imageView.image = img;
- }
- else
- {
-
-
- UIImage * img =[UIImage imageNamed:@"notfound_l"];
- [cell AddPhoto:img];
-
- // if(i==count-1)
- // {
- // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
- // if(qrimg!=nil)
- // [cell AddPhoto:qrimg];
- // }
- // if(i==0)
- // cell.imageView.image = img;
- }
-
- });
- }
- }
-
-
-
-
-
- }
-
-
-
-
- });
- // cell.backgroundColor = [UIColor whiteColor];
-
- __weak typeof(self) weakself = self;
- cell.shopCartBlock = ^(UIImageView *imageView){
- self.add_cart=true;
- CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
- rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
- CGRect headRect = imageView.frame;
- headRect.origin.y = rect.origin.y+headRect.origin.y;
- [self startAnimationWithRect:headRect ImageView:imageView];
-
- [self.navigationController popToRootViewControllerAnimated:false];
-
- // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) switchToCart];
-
-
- };
-
- cell.WatchlistBlock = ^(UIImageView *imageView){
- self.add_wish=true;
- CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
- rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
- CGRect headRect = imageView.frame;
- headRect.origin.y = rect.origin.y+headRect.origin.y;
- [self startAnimationWithRect:headRect ImageView:imageView];
- };
-
- cell.PortfolioBlock = ^(UIImageView *imageView){
- self.add_portfolio=true;
- CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
- rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
- CGRect headRect = imageView.frame;
- headRect.origin.y = rect.origin.y+headRect.origin.y;
- [self startAnimationWithRect:headRect ImageView:imageView];
-
-
-
-
- #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 *introduce = [section_json objectForKey:@"assembly_pdf_path"];
- if (introduce == nil || introduce.length == 0) {
- cell.introduceBtn.hidden = YES;
- } else {
- cell.introduceBtn.hidden = NO;
- }
- cell.introduceBlock = ^(UIButton *sender) {
-
- [weakself showIntroducePDF:introduce];
- };
-
- NSString *desc = [section_json objectForKey:@"product_content_writing"];
- if (!desc.length) {
- cell.descriptionBtn.hidden = YES;
- } else {
- cell.descriptionBtn.hidden = NO;
-
- NSDictionary *attrs = @{
- NSFontAttributeName : [UIFont systemFontOfSize:18.0f],
- NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]
- };
- NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:@"Read More" attributes:attrs];
- [cell.descriptionBtn setAttributedTitle:attrTitle forState:UIControlStateNormal];
- }
- cell.descriptionBlock = ^(UIButton *sender) {
- [weakself showModelDescription:desc];
- };
-
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- [cell generate_information];
-
- cell.incoming_stock_label.hidden = YES;
- cell.count_Label.hidden = YES;
- cell.hmlg_stock_lb.hidden = YES;
- cell.hmlg_stock_count_lb.hidden = YES;
- cell.incomingcount_Label.hidden = YES;
- cell.eta_label.hidden = YES;
- cell.etaval_label.hidden = YES;
- cell.cqyt_label.hidden = YES;
- #endif
- return cell;
- }
- // NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
- // if(related_json==nil)
- else
- {
-
-
-
-
- NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
-
- NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
-
- NSString *CellIdentifier = @"DetailInfoCell";
-
- NSString* type=[section_json valueForKey:@"type"] ;
-
- if([type isEqualToString:@"kv"])
- {
- float width = tableView.frame.size.width;
-
- width-=CELL_MARGIN*2;
- CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
- CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
- // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- NSString* key =[item_json valueForKey:@"key"] ;
-
- NSString* val=[item_json valueForKey:@"val"] ;
-
-
- NSString* type=[item_json valueForKey:@"type"] ;
-
- if([type isEqualToString:@"price"])
- {
-
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- val=nil;
- }
- }
-
-
- if([val isEqual:[NSNull null]])
- val=@"";
- if(val==nil)
- val=@"";
- if([val isEqualToString:@"null"])
- val=@"";
-
-
-
-
- CGRect frame;
- frame.size = constraintval;
- frame.origin.x=0;
- frame.origin.y=0;
- RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
- [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
- // rtlabel.lineSpacing = 20.0;
- [rtlabel setText: val];
- CGSize sizeval=rtlabel.optimumSize;
- // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- float height = MAX(sizekey.height,sizeval.height);
- height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
- sizekey.height = height;
- sizekey.width = constraintkey.width;
- // sizeval.height = height;
- sizeval.width =constraintval.width;
-
- // NSString *CellIdentifier = @"detail_item_kv";
- DetailKVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- if(cell==nil)
- DebugLog(@"cell is nil.........................");
-
-
-
-
- CGRect framekey = cell.keyLabel.frame;
- framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
- framekey.origin.y=LINE_WIDTH;
- framekey.size = sizekey;
- cell.keyLabel.frame = framekey;
- cell.keyLabel.text=key;
- CGRect frameval = cell.valLabel.frame;
- frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
- frameval.origin.y=LINE_WIDTH;
- frameval.size = sizeval;
- cell.valLabel.frame = frameval;
- // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
- cell.valLabel.text= val;
- CGPoint rcenter;
- rcenter.x = width * 0.4+width * 0.6/2;
- rcenter.y = height /2;
- cell.valLabel.center=rcenter;
- // cell.valLabel.backgroundColor =[UIColor redColor];
-
- // cell.contentView.superview.backgroundColor = [UIColor clearColor];
- // cell.backgroundColor = [UIColor whiteColor];
- UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
- lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
- lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
- lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
-
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if ([type isEqualToString:@"img"])
- {
- DetailImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailImageCell" forIndexPath:indexPath];
-
- int img_count = [[item_json valueForKey:@"count"] intValue];
- double posy = 0;
- for(int j=0;j<img_count;j++)
- {
- NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
- float width = [[img_json valueForKey:@"width"]floatValue];
- float height = [[img_json valueForKey:@"height"]floatValue];
- //
- UIImageView * imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, posy, tableView.bounds.size.width , height*tableView.bounds.size.width / width)];
- imgview.contentMode = UIViewContentModeScaleAspectFit;
-
- NSString* img_url = [img_json valueForKey:@"img_url"];
- posy+=height*tableView.bounds.size.width / width;
- NSString* file_name=[img_url lastPathComponent];
- NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
- if(img_data!=nil)
- {
-
- UIImage * img =[UIImage imageWithData:img_data];
- imgview.image = img;
- [cell addSubview:imgview];
- }
- else
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSData* downloadimg_data = nil;
- // BOOL offline = NO;
- //#ifdef OFFLINE_MODE
- // offline = appDelegate.offline_mode;
- //#endif
- // if (!offline) {
- 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];
- imgview.image = img;
- [cell addSubview:imgview];
- }
- else
- {
- imgview.image = [UIImage imageNamed:@"notfound_l"];
-
- [cell addSubview:imgview];
-
- }
- });
- });
-
-
- }
-
-
- }
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
- else if ([type isEqualToString:@"content"])
- {
-
- NSString *CellIdentifier = @"DetailTopicCell";
-
- NSString* data=[section_json valueForKey:@"data"] ;
- if([data isEqualToString:@"local"])
- {
- [appDelegate.recent_model addEntriesFromDictionary:section_json];
-
- // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
- DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.itemdelegate = self;
- cell.related_data = appDelegate.recent_model;
- [cell.topicCollectionView reloadData];
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
-
- }
- else
- {
-
- // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
- DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.itemdelegate = self;
- cell.related_data = section_json;
- [cell.topicCollectionView reloadData];
-
- cell.backgroundColor = [UIColor whiteColor];
- return cell;
- }
-
- }
- return nil;
-
- }
-
-
- }
- -(void)startAnimationWithRect:(CGRect)rect ImageView:(UIImageView *)imageView
- {
- if (!_layer) {
- // _btn.enabled = NO;
- _layer = [CALayer layer];
- _layer.contents = (id)imageView.layer.contents;
-
- _layer.contentsGravity = kCAGravityResizeAspectFill;
- _layer.bounds = rect;
- [_layer setCornerRadius:CGRectGetHeight([_layer bounds]) / 2];
- _layer.masksToBounds = YES;
- // 导航64
- _layer.position = CGPointMake(imageView.center.x, CGRectGetMidY(rect)+64);
- // [_tableView.layer addSublayer:_layer];
- [self.view.layer addSublayer:_layer];
- self.path = [UIBezierPath bezierPath];
- // [_path moveToPoint:_layer.position];
- [_path moveToPoint:imageView.center];
- [_path addLineToPoint:CGPointMake(imageView.center.x, imageView.center.y-100)];
-
- // (SCREEN_WIDTH - 60), 0, 50, 50)
- // [_path addQuadCurveToPoint:CGPointMake(SCREEN_WIDTH - 40, SCREEN_HEIGHT-40) controlPoint:CGPointMake(SCREEN_WIDTH/2,rect.origin.y-80)];
- // [_path addLineToPoint:CGPointMake(SCREEN_WIDTH-40, 30)];
- }
- [self groupAnimation];
- }
- -(void)groupAnimation
- {
- self.detailTable.userInteractionEnabled = NO;
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
- animation.path = _path.CGPath;
- // animation.rotationMode = kCAAnimationRotateAuto;
- //
- CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- expandAnimation.duration = 0.3f;
- expandAnimation.fromValue = [NSNumber numberWithFloat:1];
- expandAnimation.toValue = [NSNumber numberWithFloat:2.0f];
- expandAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
-
- CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
- narrowAnimation.beginTime = 0.3;
- narrowAnimation.fromValue = [NSNumber numberWithFloat:2.0f];
- narrowAnimation.duration = 0.9f;
- narrowAnimation.toValue = [NSNumber numberWithFloat:0.3f];
- //
- // narrowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
-
- CAAnimationGroup *groups = [CAAnimationGroup animation];
- groups.animations = @[animation,expandAnimation,narrowAnimation];
- groups.duration = 1.0f;
- groups.removedOnCompletion=NO;
- groups.fillMode=kCAFillModeForwards;
- groups.delegate = self;
- [_layer addAnimation:groups forKey:@"group"];
- }
- -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
- {
- // [anim def];
- if (anim == [_layer animationForKey:@"group"]) {
- self.detailTable.userInteractionEnabled = YES;
- // _btn.enabled = YES;
- [_layer removeFromSuperlayer];
- _layer = nil;
-
-
- // _cnt++;
- // if (_cnt) {
- // _cntLabel.hidden = NO;
- // }
- // CATransition *animation = [CATransition animation];
- // animation.duration = 0.25f;
- // _cntLabel.text = [NSString stringWithFormat:@"%d",_cnt];
- // [_cntLabel.layer addAnimation:animation forKey:nil];
- // CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
- // shakeAnimation.duration = 0.25f;
- // shakeAnimation.fromValue = [NSNumber numberWithFloat:-5];
- // shakeAnimation.toValue = [NSNumber numberWithFloat:5];
- // shakeAnimation.autoreverses = YES;
- // [_btn.layer addAnimation:shakeAnimation forKey:nil];
- }
- }
- #pragma mark - hide section button clicked
- - (void)RefreshSection:(UIButton *)sender {
-
-
- sender.enabled=false;
- NSDictionary* section_json = nil;
-
-
- NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
- if(related_json==nil)
- {
-
- section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(sender.tag-1)]];
-
- }
- else
- {
- if(sender.tag==1)
- {
- section_json = related_json ;
- }
- else
- {
- section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)sender.tag-2]];
- }
- }
-
-
- NSString* url = section_json[@"data_interface"];
- NSMutableDictionary* params = [section_json[@"params"] mutableCopy];
-
-
- if(params==nil)
- params = [[NSMutableDictionary alloc] init];
-
-
- NSUInteger ii[2] = {sender.tag,0};
- NSIndexPath* indexpath= [NSIndexPath indexPathWithIndexes:ii length:2];
-
- DetailTopicCell * cell=[self.detailTable cellForRowAtIndexPath:indexpath];
- [cell begin_refresh];
- // UIAlertController * waitalert = [RAUtils waiting_alert:selftitle:@"Refreshing"];
- [RADataProvider request_commoneditor_partialrefresh:params url:url completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* editor_json =result;
- [cell end_refresh ];
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- sender.enabled=true;
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- [self.detail_data addEntriesFromDictionary:editor_json];
-
- NSRange range = NSMakeRange(sender.tag, 1);
- NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- }
-
-
- }];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [cell end_refresh ];
- //// [waitalert dismissViewControllerAnimated:YES completion:nil];
- // sender.enabled=true;
- //
- // if([[editor_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // [self.detail_data addEntriesFromDictionary:editor_json];
- //
- // NSRange range = NSMakeRange(sender.tag, 1);
- // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
- //
- // }
- // else
- // {
- // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
- // }
- //
- //
- // });
- // });
-
-
-
- // self.showMore=!self.showMore;
- // NSRange range = NSMakeRange(1, 1);
- // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
- // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
-
-
-
- }
- #pragma mark - Support scanner
- -(void) onDecodedData:(NSString*) value
- {
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- //
- self.model_name = value;
- self.product_id = nil;
- self.use_model_name = true;
- [self reload];
- DebugLog(@"color selected");
-
-
- }
- #pragma mark - Handle Notification
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)registeObserver {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNoRightMsg:) name:No_Rights_Notification object:nil];
- }
- - (void)handleNoRightMsg:(NSNotification *)notification {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:@"You have no rights to do that." preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- [alertController dismissViewControllerAnimated:YES completion:nil];
-
- }];
-
- [alertController addAction:action];
-
- [self presentViewController:alertController animated:YES completion:nil];
- }
- #pragma mark - action
- - (void)showEmailAddrBox {
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
- emailAddrVC.textFiled.secureTextEntry = NO;
- emailAddrVC.yesButtonTitle = @"send";
-
- __weak typeof(emailAddrVC) weakVC = emailAddrVC;
- __weak typeof(self) weakself = self;
-
- emailAddrVC.textHandler = ^(NSString *text){
-
- // 验证邮箱格式是否正确
- // NSString *match = EMAIL_MATCHES;
- // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
- // BOOL isEmailAddr = [predicate evaluateWithObject:text];
- BOOL isEmailAddr = YES;
- if (isEmailAddr) {
-
- // 验证是邮件地址,发送邮件
- [weakVC dismissViewControllerAnimated:YES completion:^{
-
- __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
- [RANetwork request_notifymodel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
- DebugLog(@"email cart result: %@",result);
-
-
- [waitting_alert dismissViewControllerAnimated:YES completion:^{
- int resultStatus = [[result objectForKey:@"result"] intValue];
- if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
-
- NSString *msg = [NSString stringWithFormat:@"The email send failed"];
- if ([result valueForKey:@"err_msg"]) {
- msg = [result valueForKey:@"err_msg"];
- }
-
-
- UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- [errorAlertVC addAction:action];
- [weakself presentViewController:errorAlertVC animated:YES completion:nil];
-
- }else if(resultStatus == RESULT_TRUE){
-
- [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
-
- } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
-
- [weakself showEmailAddrBox];
-
- }
- }];
- // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
-
-
-
-
- }];
- }];
-
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- //
- // NSDictionary *result = [RANetwork notifyModel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo];
- // DebugLog(@"email cart result: %@",result);
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
- //
- // int resultStatus = [[result objectForKey:@"result"] intValue];
- // if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
- //
- // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
- // if ([result valueForKey:@"err_msg"]) {
- // msg = [result valueForKey:@"err_msg"];
- // }
- //
- //
- // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
- // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- //
- // }];
- //
- // [errorAlertVC addAction:action];
- // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
- //
- // }else if(resultStatus == RESULT_TRUE){
- //
- // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
- //
- // } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
- //
- // [weakself showEmailAddrBox];
- //
- // }
- //
- // });
- //
- // });
-
- }];
-
- } else {
-
- // 非邮件地址,警告
- [weakVC warning:@"Please enter right email address"];
-
- }
-
- };
-
- [self presentViewController:emailAddrVC animated:YES completion:nil];
- }
- - (void)showIntroducePDF:(NSString *)link {
-
- if (link.length == 0) {
- [RAUtils message_alert:@"There is no resource to open" title:@"Warning" controller:self];
- return;
- }
-
- NSArray *tmpArr = [link componentsSeparatedByString:@"="];
-
- BOOL isLocalFile = NO;
- NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
- NSString *name = [section_json valueForKey:@"model_name"];
- NSString *path = [NSString stringWithFormat:@"%@/Introduce/%@.pdf",[RAUtils appCacheDirectory],tmpArr.lastObject];
- if ([RAUtils fileExistsAtPath:path]) { // 检查缓存
- isLocalFile = YES;
- link = path;
- } else {
- // 创建缓存目录
- NSString *dir = [path stringByDeletingLastPathComponent];
- [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
- }
-
-
- name = [NSString stringWithFormat:@"%@ Assembly Instruction",name];
-
- RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- ViewController.url = link;
- ViewController.canSave = false;
- ViewController.isLocalfile=isLocalFile;
- ViewController.cachePath = path;
- NSString* subject = name;
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* customer_email = [appDelegate.customerInfo valueForKey:@"customer_email"];
-
-
- NSMutableArray* send_to = [[NSMutableArray alloc]init];
- if(customer_email.length>0)
- {
- send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
-
- }
- ViewController.mail_to = send_to;
-
- ViewController.filename = [NSString stringWithFormat:@"%@.pdf",name];
- ViewController.mail_subject = subject;
-
- ViewController.hidenavi = false;
-
-
- // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ViewController];
- // nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
- // CGSize size = [UIScreen mainScreen].bounds.size;
- // nav.preferredContentSize = CGSizeMake(size.width * 0.8, size.height * 0.8);
-
- [self.navigationController pushViewController:ViewController animated:YES];
- }
- - (void)showModelDescription:(NSString *)desc {
-
- ModelDescriptionController *vc = [[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ModelDescriptionController"];
- vc.model_desc = desc;
-
- vc.title = [NSString stringWithFormat:@"%@ Description",self.model_name];
-
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
- nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
- nav.preferredContentSize = CGSizeMake(400, 380);// 只有在 UIModalPresentationFormSheet 的时候起作用
-
- [self presentViewController:nav animated:YES completion:nil];
-
-
- }
- - (void)reRefreshView {
- [self.detailTable reloadData];
- }
- #pragma mark - RA_NOTIFICAITON
- -(void) refresh_ui
- {
- [self.detailTable reloadData];
- }
- -(void) reload_data
- {
- [self reload];
- }
- -(void) refresh_price
- {
- [self refresh_ui];
- }
-
- @end
|