DetailViewController.m 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471
  1. //
  2. // DetailViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 7/25/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailViewController.h"
  9. #import "DetailHeaderCell.h"
  10. #import "DetailImageCell.h"
  11. #import "RANetwork.h"
  12. #import "RTLabel.h"
  13. #import "DetailKVCell.h"
  14. #import "LineView.h"
  15. //#import "SelectorViewController.h"
  16. #import "RAUtils.h"
  17. #import "MainViewController.h"
  18. #import "QRCodeGenerator.h"
  19. #import "DefaultTableHeaderView.h"
  20. #import "DefaultAppearance.h"
  21. #import "JKMessageBoxController.h"
  22. #import "CartUtils.h"
  23. #import "ImageUtils.h"
  24. #import "RAPDFViewController.h"
  25. #import "ModelDescriptionController.h"
  26. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  27. #import "HomerModelDetailHeaderCell.h"
  28. #endif
  29. #define DEF_CELL_HEIGHT 44
  30. #define DEF_TABLE_HEIGHT 44
  31. #define LINE_WIDTH 0
  32. #define CELL_MARGIN 0
  33. #define LABEL_MARGIN 10
  34. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
  35. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
  36. #define NavColor ([UIColor colorWithRed:237/255.0 green:20/255.0f blue:91/255.0f alpha:1.0f])
  37. @interface DetailViewController ()
  38. @property (nonatomic,strong) UIBezierPath *path;
  39. @end
  40. @implementation DetailViewController
  41. {
  42. CALayer *_layer;
  43. }
  44. -(void) reload_container_getdata:(bool) update_data
  45. {
  46. [super reload_container_getdata:update_data];
  47. if(update_data)
  48. [self reload];
  49. else
  50. {
  51. [self.detailTable reloadData];
  52. // [self refresh_total];
  53. }
  54. }
  55. -(void)manually_refresh
  56. {
  57. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
  58. if(self.isrefreshing)
  59. {
  60. [reF endRefreshing];
  61. return;
  62. }
  63. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  64. if ([self respondsToSelector:@selector(ReloadData)])
  65. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  66. // DebugLog(@"refresh!!!!!!!!");
  67. }
  68. -(void) ReloadData
  69. {
  70. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
  71. [reF endRefreshing];
  72. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  73. [self reload];
  74. }
  75. -(void) reload
  76. {
  77. dispatch_async(dispatch_get_main_queue(), ^{
  78. if(self.isrefreshing)
  79. return;
  80. self.label_net_err.hidden=true;
  81. self.detailTable.hidden = true;
  82. self.isrefreshing=true;
  83. self.mum.center = self.view.center;
  84. self.mum.hidden = false;
  85. [self.mum startAnimating];
  86. //self.detailTable.hidden=true;
  87. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  88. 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] mutableCopy];
  89. dispatch_async(dispatch_get_main_queue(), ^{
  90. [self.mum stopAnimating];
  91. if([[detail_json valueForKey:@"result"] intValue]==2)
  92. {
  93. self.detail_data = [detail_json mutableCopy];
  94. self.product_id = [NSString stringWithFormat:@"%d",[[detail_json valueForKey:@"product_id"] intValue] ];
  95. NSMutableDictionary* imgsection = [[detail_json objectForKey:@"img_section"] mutableCopy];
  96. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  97. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/true)
  98. self.quantity =[[imgsection valueForKey:@"stockUom"] intValue];
  99. else
  100. self.quantity =1;
  101. if(self.quantity==0)
  102. self.quantity=1;
  103. self.step=self.quantity;
  104. [self.detailTable reloadData];
  105. //
  106. self.detailTable.hidden = false;
  107. NSString* model_name = self.detail_data[@"img_section"][@"model_name"];
  108. NSString* img_url = self.detail_data[@"img_section"][@"model_s_img"];
  109. NSMutableDictionary* images=[self.detail_data[@"img_section"][@"images"] mutableCopy];
  110. NSMutableDictionary* videos=[self.detail_data[@"img_section"][@"videos"] mutableCopy];
  111. NSMutableDictionary* contents = [NSMutableDictionary new];
  112. int count = 0;
  113. {
  114. for(int ic=0;ic<[videos[@"count"] intValue];ic++)
  115. {
  116. NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
  117. // NSString* path=[[NSBundle mainBundle] pathForResource:@"play" ofType:@"jpg"];
  118. //
  119. // NSMutableDictionary* item =[@{@"type":@"video",@"is_localfile":@(true),@"l":path,@"s":path} mutableCopy];
  120. //
  121. // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  122. // count++;
  123. NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
  124. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  125. count++;
  126. }
  127. }
  128. {
  129. for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
  130. {
  131. NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
  132. item[@"type"]=@"image";
  133. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  134. count++;
  135. }
  136. //#ifndef BUILD_HOMER
  137. #if !defined(BUILD_HOMER) && !defined(BUILD_GATIT)
  138. // homer 要求去掉qrcode 2017/12/20
  139. NSString* qrpath = [ImageUtils generateQRCodeFile:model_name width:350 height:350];
  140. // UIImage* qrimg=[QRCodeGenerator qrImageForString:model_name imageSize:350];
  141. if(qrpath!=nil)
  142. {
  143. NSMutableDictionary* item =[@{@"type":@"image",@"is_localfile":@(true),@"l":qrpath,@"s":qrpath} mutableCopy];
  144. contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  145. count++;
  146. }
  147. #endif
  148. }
  149. contents[@"count"]=@(count);
  150. imgsection[@"stack_contents"]=contents;
  151. self.detail_data[@"img_section"]=imgsection;
  152. // self.detail_data[@"img_section"][@"stack_contents"]=contents;
  153. NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
  154. [item setValue:self.product_id forKey:@"product_id"];
  155. [item setValue:self.category_id forKey:@"category"];
  156. [item setValue:model_name forKey:@"fash_name"];
  157. [item setValue:img_url forKey:@"picture_path"];
  158. [CartUtils add_recent_model:item];
  159. NSUInteger ii[2] = {0,0};
  160. [self.detailTable scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndexes:ii length:2] atScrollPosition:UITableViewScrollPositionTop animated:YES];
  161. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  162. // int count=[appDelegate.recent_model[@"count"] intValue];
  163. // bool bexist = false;
  164. // for(int i=0;i<count;i++)
  165. // {
  166. // NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
  167. // if([mitem[@"product_id"] isEqualToString:self.product_id])
  168. // {
  169. // bexist=true;
  170. // break;
  171. // }
  172. // }
  173. //
  174. // if(!bexist)
  175. // {
  176. // [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
  177. // appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
  178. // }
  179. }
  180. else
  181. if([[detail_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  182. {
  183. self.detailTable.hidden = true;
  184. self.label_net_err.hidden=false;
  185. }
  186. else if([[detail_json valueForKey:@"result"] intValue]==RESULT_NO_MODEL)
  187. {
  188. self.detailTable.hidden = true;
  189. [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  190. if(self.ispush)
  191. [ self.navigationController popViewControllerAnimated:true];
  192. }
  193. else
  194. {
  195. [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  196. }
  197. self.isrefreshing=false;
  198. });
  199. });
  200. });
  201. }
  202. - (void)onBackClick:(UIButton *)sender {
  203. if(self.OnBack)
  204. {
  205. self.OnBack(self.add_cart,self.add_wish,self.update_data);
  206. }
  207. [self.navigationController popViewControllerAnimated:(false)];
  208. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  209. // ;
  210. // }];
  211. }
  212. - (void)viewDidLoad {
  213. [super viewDidLoad];
  214. self.support_scanner = true;
  215. [self registeObserver];
  216. self.refresh_type = REFRESH_VIEW;
  217. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  218. style:UIBarButtonItemStylePlain
  219. target:self
  220. action:@selector( onBackClick:)];
  221. self.navigationItem.leftBarButtonItem = backButton;
  222. // self.detailTable.style = UITableViewStylePlain;
  223. self.edgesForExtendedLayout = UIRectEdgeNone;
  224. if(self.ispush)
  225. {
  226. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.000001)];
  227. [line setBackgroundColor:[UIColor clearColor]];
  228. self.detailTable.tableHeaderView = line;
  229. }
  230. //
  231. //
  232. // self.automaticallyAdjustsScrollViewInsets = false;
  233. self.step=1;
  234. self.quantity=1;
  235. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  236. ref.tag = 300 ;
  237. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  238. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  239. // ref.hidden = true;
  240. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  241. [self.detailTable addSubview:ref];
  242. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  243. self.label_net_err.layer.borderWidth = 2.0;
  244. self.label_net_err.layer.cornerRadius=15;
  245. self.label_net_err.layer.masksToBounds=true;
  246. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  247. // tap.minimumPressDuration = 0.8; //定义按的时间
  248. [self.label_net_err addGestureRecognizer:tap];
  249. // Do any additional setup after loading the view.
  250. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  251. [self.detailTable registerNib:[UINib nibWithNibName:@"HomerModelDetailHeaderCell" bundle:nil] forCellReuseIdentifier:@"HomerModelDetailHeaderCell"];
  252. #endif
  253. }
  254. - (void)viewWillAppear:(BOOL)animated
  255. {
  256. if(self.ispush)
  257. {
  258. [super viewWillAppear:animated];
  259. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  260. }
  261. }
  262. - (void) viewWillDisappear:(BOOL)animated
  263. {
  264. [super viewWillDisappear:animated];
  265. if(self.ispush)
  266. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  267. }
  268. - (void)didReceiveMemoryWarning {
  269. [super didReceiveMemoryWarning];
  270. // Dispose of any resources that can be recreated.
  271. }
  272. /*
  273. #pragma mark - Navigation
  274. // In a storyboard-based application, you will often want to do a little preparation before navigation
  275. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  276. // Get the new view controller using [segue destinationViewController].
  277. // Pass the selected object to the new view controller.
  278. }
  279. */
  280. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  281. //将page2设定成Storyboard Segue的目标UIViewController
  282. id page2 = segue.destinationViewController;
  283. //将值透过Storyboard Segue带给页面2的string变数
  284. [page2 setValue: _selector forKey:@"selector"];
  285. [page2 setValue: self forKey:@"selectordelegate"];
  286. }
  287. //- (IBAction)OnAddPortfolio:(id)sender {
  288. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  289. //
  290. // [appDelegate test_onDecodedDataResult:@"371252"];
  291. //// [self onDecodedData:@"3712524-235"];
  292. // return;
  293. //}
  294. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  295. {
  296. // [self.detailTable reloadData];
  297. // return;
  298. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  299. // NSMutableIndexSet *sectionToReload = [[NSMutableIndexSet alloc] init];
  300. // int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
  301. //
  302. // for(int i=0;i<section_count;i++)
  303. // {
  304. // NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)i]];
  305. //
  306. //
  307. //
  308. // NSString* type=[section_json valueForKey:@"type"] ;
  309. //
  310. // if([type isEqualToString:@"kv"])
  311. // {
  312. //
  313. // [sectionToReload addIndex:i+1];
  314. // }
  315. // }
  316. //
  317. //
  318. // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationNone];
  319. //
  320. [self.detailTable reloadData];
  321. }
  322. #pragma mark - Selector delegate
  323. -(void) selected:(NSString*) detail_id category:(NSString*) category
  324. {
  325. self.product_id = detail_id;
  326. self.use_model_name = false;
  327. [self reload];
  328. DebugLog(@"color selected");
  329. }
  330. #pragma mark - Header cell delegate
  331. -(void) SelectorClicked:(UIView*) trigger
  332. {
  333. // int selcount = [[self.selector valueForKey:@"count"] intValue];
  334. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  335. int current_sel = -1;
  336. for(int i=0;i<selector_count;i++)
  337. {
  338. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  339. // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
  340. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  341. {
  342. current_sel = i;
  343. }
  344. }
  345. // NSArray * arr = [[NSArray alloc] init];
  346. // arr = [NSArray arrayWithObjects:@"Hello 0", @"Hello 1", @"Hello 2", @"Hello 3", @"Hello 4", @"Hello 5", @"Hello 6", @"Hello 7", @"Hello 8", @"Hello 9",nil];
  347. // NSArray * arrImage = [[NSArray alloc] init];
  348. // 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];
  349. if(self.dropDown == nil)
  350. {
  351. CGFloat height = 70*selector_count;
  352. self.dropDown =[[NIDropDown alloc] showDropDown:self.detailTable based:(id)trigger height:height data:self.selector direction:@"down" current_sel:current_sel];
  353. //Capturing strongly warring;
  354. __block DetailViewController *brself= self;
  355. self.dropDown.selectChanged =^(long index){
  356. NSDictionary* item = [brself.selector objectForKey:[NSString stringWithFormat:@"item_%ld",index]];
  357. NSDictionary* params = [item objectForKey:@"params"];
  358. NSString* detail_id=[[[params objectForKey:@"param_0"] valueForKey:@"val" ] stringValue];
  359. brself.product_id = detail_id;
  360. brself.use_model_name = false;
  361. [brself reload];
  362. // DebugLog(@"color selected");
  363. brself.dropDown = nil;
  364. };
  365. //[[NIDropDown alloc]showDropDown:(id)trigger :&f :arr :arrImage :@"down"];
  366. // self.dropDown.delegate = self;
  367. }
  368. else {
  369. [self.dropDown hideDropDown:(id)trigger];
  370. self.dropDown= nil;
  371. // [self rel];
  372. }
  373. return;
  374. /*
  375. // CGRect rect = trigger.frame;
  376. //
  377. // DebugLog(@"%@",NSStringFromCGRect(rect));
  378. //
  379. //
  380. //
  381. // DebugLog(@"%@",NSStringFromCGPoint (trigger.center));
  382. //
  383. //
  384. // CGRect new=[trigger convertRect:rect toView:self.view];
  385. //
  386. // DebugLog(@"convert %@",NSStringFromCGRect(new));
  387. //
  388. CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
  389. CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
  390. DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
  391. SelectorViewController *menu = [ self.storyboard instantiateViewControllerWithIdentifier:@"SelectorViewController"];
  392. NSString * name = [self.selector valueForKey:@"name"];
  393. menu.title=name;
  394. menu.selector = self.selector;
  395. menu.selectordelegate = self;
  396. // 1.创建一个UIPopover
  397. UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
  398. // 2.设置尺寸
  399. // popover.popoverContentSize = CGSizeMake(320, 44 * 5);
  400. // 3.从哪里显示出来 --> 指向item
  401. [popover presentPopoverFromRect:rect1 inView:self.view permittedArrowDirections:0 animated:YES];
  402. // [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  403. self.popover = popover;
  404. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  405. */
  406. }
  407. -(void) stepClicked:(int) value
  408. {
  409. self.quantity = value;
  410. }
  411. #pragma mark - Topic cell delegate
  412. -(void) TopicItemClicked:(NSString*) product_id category:(NSString*) category
  413. {
  414. // DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  415. // // dvc
  416. //
  417. //
  418. // dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
  419. // {
  420. //
  421. //
  422. // [self reload_container_getdata:false]
  423. // };
  424. //
  425. //
  426. // dvc.product_id=product_id;
  427. // dvc.category_id=category;
  428. // dvc.ispush=true;
  429. // [dvc reload];
  430. // [self.navigationController pushViewController:dvc animated:true];
  431. // self.model_name = value;
  432. self.product_id = product_id;
  433. self.category_id=category;
  434. [self reload];
  435. DebugLog(@"color selected");
  436. }
  437. #pragma mark - Table view data source
  438. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  439. //{
  440. // return 0;
  441. //}
  442. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  443. //{
  444. // return 0;
  445. //}
  446. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  447. //{
  448. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  449. // return myView;
  450. //
  451. //}
  452. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  453. //{
  454. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  455. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  456. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  457. //// titleLabel.textColor=[UIColor whiteColor];
  458. //// titleLabel.backgroundColor = [UIColor clearColor];
  459. //// if(section==0)
  460. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  461. //// else
  462. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  463. //// [titleLabel sizeToFit];
  464. //// [myView addSubview:titleLabel];
  465. ////
  466. // return myView;
  467. //}
  468. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  469. if(section==0)
  470. return nil;
  471. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  472. if(related_json==nil)
  473. {
  474. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  475. return [section_json valueForKey:@"title"] ;
  476. }
  477. else
  478. {
  479. if(section==1)
  480. return @"related model";
  481. else
  482. {
  483. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  484. return [section_json valueForKey:@"title"] ;
  485. }
  486. }
  487. }
  488. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  489. //{
  490. // return 33;
  491. //}
  492. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  493. {
  494. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  495. if(value==nil)
  496. value=@"";
  497. unsigned long color = strtoul([value UTF8String],0,16);
  498. NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
  499. if (sectionTitle == nil) {
  500. return nil;
  501. }
  502. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  503. // myView.backgroundColor = UIColorFromRGB(0x996633);
  504. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  505. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  506. myView.layer.shadowOffset = CGSizeMake(0, 0);
  507. myView.layer.shadowOpacity = 0.5;
  508. myView.layer.shadowRadius = 2.0;
  509. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5.5, 90, 22)];
  510. titlelabel.textColor=UIColorFromRGB(color);
  511. // titlelabel.backgroundColor = [UIColor clearColor];
  512. titlelabel.text=sectionTitle;
  513. [titlelabel sizeToFit];
  514. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  515. bool refresh= [[section_json valueForKey:@"partial_refresh"] boolValue] ;
  516. if(refresh)
  517. {
  518. NSString* btntitle=@"Refresh" ;
  519. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DetailTableHeaderView" valuename:@"refresh_button_color"];
  520. //
  521. // if(value==nil)
  522. // value=@"";
  523. // unsigned long color = strtoul([value UTF8String],0,16);
  524. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-100-15, 0, 100, 33)];
  525. // [btn setTitleColor:UIColorFromRGB(color) forState:UIControlStateNormal];
  526. btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  527. btn.tag=section;
  528. [btn addTarget:self action:@selector(RefreshSection:) forControlEvents:UIControlEventTouchUpInside];
  529. [btn setTitle:btntitle forState:UIControlStateNormal];
  530. [myView addSubview:btn];
  531. }
  532. [myView addSubview:titlelabel];
  533. return myView;
  534. }
  535. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  536. {
  537. int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
  538. if(section_count==0)
  539. return section_count;
  540. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  541. if(related_json==nil)
  542. return section_count+1;
  543. else
  544. return section_count+2;
  545. }
  546. //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  547. //{
  548. // DebugLog(@"canMoveRowAtIndexPath");
  549. //
  550. // if([tableView numberOfRowsInSection:indexPath.section]>1)
  551. // return true;
  552. // else
  553. // return false;
  554. //}
  555. //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  556. //{
  557. // NSMutableArray * from;
  558. // NSMutableArray * to ;
  559. // if(fromIndexPath.section==0)
  560. // from = self.displayfields;
  561. // else
  562. // from = self.hidefields;
  563. // if(toIndexPath.section==0)
  564. // to = self.displayfields;
  565. // else
  566. // to = self.hidefields;
  567. // id content=from[fromIndexPath.row];
  568. // [from removeObjectAtIndex:fromIndexPath.row];
  569. // [to insertObject:content atIndex:toIndexPath.row];
  570. //
  571. // [tableView reloadData];
  572. //
  573. //}
  574. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  575. {
  576. if(section==0)
  577. return 1;
  578. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  579. if(related_json==nil)
  580. {
  581. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-1]];
  582. NSString* type=[section_json valueForKey:@"type"] ;
  583. if([type isEqualToString:@"content"])
  584. return 1;
  585. return [[section_json valueForKey:@"count"] intValue];
  586. }
  587. else
  588. {
  589. if(section==1)
  590. return 1;
  591. else
  592. {
  593. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  594. NSString* type=[section_json valueForKey:@"type"] ;
  595. if([type isEqualToString:@"content"])
  596. return 1;
  597. return [[section_json valueForKey:@"count"] intValue];
  598. }
  599. }
  600. }
  601. //- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  602. //{
  603. // return UITableViewCellEditingStyleNone;
  604. //}
  605. //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  606. //{
  607. // //如果两次点击的时间间隔小于1秒,则断定为双击事件
  608. //
  609. // if(tableView.editing==false)
  610. // return;
  611. //
  612. //
  613. // if([tableView numberOfRowsInSection:indexPath.section]<=1)
  614. // return;
  615. // // int between = 1;
  616. // NSUInteger curr = [[NSDate date] timeIntervalSince1970];
  617. //
  618. // if(indexPath.row==self.lasttap.row&&indexPath.section==self.lasttap.section)
  619. // {
  620. // if (curr-self.taptime<1) {
  621. // DebugLog(@"double click!");
  622. // self.lasttap =nil;
  623. //
  624. // NSMutableArray * from;
  625. // NSMutableArray * to ;
  626. // int section;
  627. // if(indexPath.section==0)
  628. // {
  629. // from = self.displayfields;
  630. // to = self.hidefields;
  631. // section = 1;
  632. // }
  633. // else
  634. // {
  635. //
  636. // from = self.hidefields;
  637. // to = self.displayfields;
  638. // section = 0;
  639. // }
  640. // NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
  641. // // NSIndexPath * headerIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
  642. // // NSIndexPath * headerIndexPath1 = toIndexPath;
  643. //
  644. // id content=from[indexPath.row];
  645. // [tableView beginUpdates];
  646. // [from removeObjectAtIndex:indexPath.row];
  647. // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  648. //
  649. // [to insertObject:content atIndex:0];
  650. // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  651. // [tableView endUpdates];
  652. //
  653. // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  654. // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
  655. // [tableView reloadData];
  656. //
  657. //
  658. // }
  659. // self.taptime = curr;
  660. //
  661. //
  662. // }
  663. // else
  664. // {
  665. // self.taptime = curr;
  666. // self.lasttap = indexPath;
  667. // }
  668. //}
  669. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  670. {
  671. if(section ==0)
  672. return 0;
  673. else
  674. return 33;
  675. }
  676. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  677. {
  678. if(indexPath.section ==0) {
  679. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  680. CGFloat height = CGRectGetHeight(self.view.bounds);
  681. if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
  682. return height;
  683. }
  684. #endif
  685. return 550;
  686. }
  687. NSDictionary* nsdic = self.detail_data;
  688. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  689. if(related_json==nil)
  690. {
  691. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  692. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  693. NSString* type=[section_json valueForKey:@"type"] ;
  694. if([type isEqualToString:@"kv"])
  695. {
  696. float width = tableView.frame.size.width;
  697. width-=CELL_MARGIN*2;
  698. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  699. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  700. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  701. NSString* key =[item_json valueForKey:@"key"] ;
  702. // [cell.keyLabel sizeToFit];
  703. NSString* val=[item_json valueForKey:@"val"] ;
  704. if([val isEqual:[NSNull null]])
  705. val=@"";
  706. if(val==nil)
  707. val=@"";
  708. if([val isEqualToString:@"null"])
  709. val=@"";
  710. CGRect frame;
  711. frame.size = constraintval;
  712. frame.origin.x=0;
  713. frame.origin.y=0;
  714. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  715. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  716. // rtlabel.lineSpacing = 20.0;
  717. [rtlabel setText: val];
  718. CGSize sizeval=rtlabel.optimumSize;
  719. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  720. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  721. float height = MAX(sizekey.height,sizeval.height);
  722. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  723. return height;
  724. }
  725. else if([type isEqualToString:@"img"])
  726. {
  727. int img_count = [[item_json valueForKey:@"count"] intValue];
  728. double ret = 0;
  729. for(int j=0;j<img_count;j++)
  730. {
  731. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  732. float width = [[img_json valueForKey:@"width"]floatValue];
  733. float height = [[img_json valueForKey:@"height"]floatValue];
  734. ret+=height*tableView.bounds.size.width / width;
  735. }
  736. return ret;
  737. }
  738. else if([type isEqualToString:@"content"])
  739. return 270;
  740. return 44;
  741. }
  742. else
  743. {
  744. if(indexPath.section==1)
  745. return 270;
  746. else
  747. {
  748. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-2]];
  749. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  750. NSString* type=[section_json valueForKey:@"type"] ;
  751. if([type isEqualToString:@"kv"])
  752. {
  753. float width = tableView.frame.size.width;
  754. width-=CELL_MARGIN*2;
  755. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  756. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  757. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  758. NSString* key =[item_json valueForKey:@"key"] ;
  759. // [cell.keyLabel sizeToFit];
  760. NSString* val=[item_json valueForKey:@"val"] ;
  761. if([val isEqual:[NSNull null]])
  762. val=@"";
  763. if(val==nil)
  764. val=@"";
  765. if([val isEqualToString:@"null"])
  766. val=@"";
  767. CGRect frame;
  768. frame.size = constraintval;
  769. frame.origin.x=0;
  770. frame.origin.y=0;
  771. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  772. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  773. // rtlabel.lineSpacing = 20.0;
  774. [rtlabel setText: val];
  775. CGSize sizeval=rtlabel.optimumSize;
  776. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  777. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  778. float height = MAX(sizekey.height,sizeval.height);
  779. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  780. return height;
  781. }
  782. else if([type isEqualToString:@"img"])
  783. {
  784. int img_count = [[item_json valueForKey:@"count"] intValue];
  785. double ret = 0;
  786. for(int j=0;j<img_count;j++)
  787. {
  788. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  789. float width = [[img_json valueForKey:@"width"]floatValue];
  790. float height = [[img_json valueForKey:@"height"]floatValue];
  791. ret+=height*tableView.bounds.size.width / width;
  792. }
  793. return ret;
  794. }
  795. return 44;
  796. }
  797. }
  798. }
  799. - (BOOL)isOutofStock {
  800. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  801. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  802. // 2018-01-10 修改通过lowercase判断
  803. if (!qtyStr || !qtyStr.length || [qtyStr.lowercaseString isEqualToString:@"in production"] || [qtyStr isEqualToString:@"0"] || [qtyStr.lowercaseString isEqualToString:@"sold out"] || [qtyStr.lowercaseString isEqualToString:@"out of stock"]) {
  804. return YES;
  805. }
  806. return NO;
  807. }
  808. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  809. {
  810. // DebugLog(@"cellForRowAtIndexPath");
  811. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  812. if(indexPath.section==0)
  813. {
  814. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  815. NSString *CellIdentifier = @"HomerModelDetailHeaderCell";
  816. HomerModelDetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  817. if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight ) {
  818. CGFloat w = CGRectGetWidth(tableView.bounds);
  819. CGFloat h = CGRectGetHeight(tableView.bounds);
  820. CGFloat space_w = w - 320;
  821. CGFloat photoStackWidth = space_w - (35 * 2);
  822. CGFloat photoStackHeight = h - 102 - 70;
  823. CGFloat a = MIN(photoStackWidth, photoStackHeight);
  824. CGFloat x = (space_w - a) * 0.5, y = 102 + (photoStackHeight - a) * 0.5;
  825. if (x > 50) {
  826. x -= 20;
  827. }
  828. cell.photoStack.frame = CGRectMake(x, y, a, a);
  829. cell.pageControl.frame = CGRectMake((space_w - 319) * 0.5, h - 50, 319, 37);
  830. } else {
  831. cell.photoStack.frame = CGRectMake(35, 107, 349, 348);
  832. cell.pageControl.frame = CGRectMake(50, 466, 319, 37);
  833. }
  834. #else
  835. NSString *CellIdentifier = @"DetailHeaderCell";
  836. DetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  837. #endif
  838. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  839. // Homer添加的View
  840. cell.hmlg_stock_lb.hidden = YES;
  841. cell.hmlg_stock_count_lb.hidden = YES;
  842. cell.on_sale_lb.hidden = YES;
  843. BOOL is_special_model = [[section_json objectForKey:@"is_special_model"] boolValue];
  844. if (!appDelegate.user) { // 没有登录时隐藏add to portfolio,使add to cart与add to wishlist对齐
  845. cell.btnaddPortfolio.hidden = YES;
  846. cell.btnNotifyMe.hidden = YES;
  847. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  848. // cell.hmlg_stock_lb.hidden = NO;
  849. // cell.hmlg_stock_count_lb.hidden = NO;
  850. id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
  851. if (hmlg_stock == nil) {
  852. hmlg_stock = @"";
  853. }
  854. cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
  855. cell.on_sale_lb.hidden = !is_special_model;
  856. #endif
  857. } else {
  858. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  859. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  860. __weak typeof(self) weakself = self;
  861. cell.notifyMeBlock = ^{
  862. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  863. dispatch_async(dispatch_get_global_queue(0,0), ^{
  864. NSDictionary *dic = [RANetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
  865. dispatch_async(dispatch_get_main_queue(), ^{
  866. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  867. NSInteger result = [[dic valueForKey:@"result"] integerValue];
  868. if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  869. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  870. if ([dic valueForKey:@"err_msg"]) {
  871. msg = [dic valueForKey:@"err_msg"];
  872. }
  873. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  874. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  875. }];
  876. [errorAlertVC addAction:action];
  877. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  878. } else if (result == RESULT_TRUE){
  879. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  880. } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  881. [self showEmailAddrBox];
  882. }
  883. });
  884. });
  885. };
  886. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  887. cell.btnaddPortfolio.hidden = YES;
  888. if (!notifyMe_switch) {
  889. cell.btnNotifyMe.hidden = YES;
  890. } else {
  891. cell.btnNotifyMe.hidden = NO;
  892. if (!appDelegate.order_code) { // 未打开订单状态
  893. if ([self isOutofStock]) {
  894. if (!appDelegate.can_create_backorder) {
  895. cell.btnaddCart.enabled = NO;
  896. }
  897. cell.btnNotifyMe.enabled = YES;
  898. } else {
  899. cell.btnaddCart.enabled = YES;
  900. cell.btnNotifyMe.enabled = NO;
  901. }
  902. } else {
  903. // 打开订单状态
  904. if (![Singleton sharedInstance].currentOrderIsMerged) {
  905. // Shop Order
  906. cell.btnaddCart.enabled = YES;
  907. // 默认未缺货
  908. cell.btnNotifyMe.enabled = NO;
  909. if ([self isOutofStock]) { // 缺货
  910. cell.btnNotifyMe.enabled = YES;
  911. }
  912. } else {
  913. // Purchase Order
  914. if ([self isOutofStock]) { // 缺货
  915. if (!appDelegate.can_create_backorder) {
  916. cell.btnaddCart.enabled = NO;
  917. }
  918. cell.btnNotifyMe.enabled = YES;
  919. } else { // 未缺货
  920. cell.btnNotifyMe.enabled = NO;
  921. cell.btnaddCart.enabled = YES;
  922. }
  923. }
  924. }
  925. }
  926. } else { // employee
  927. // online
  928. cell.btnaddPortfolio.hidden = NO;
  929. cell.btnNotifyMe.hidden = NO;
  930. if ([self isOutofStock]) { // 缺货
  931. if (!appDelegate.can_create_backorder) {
  932. cell.btnaddCart.enabled = NO;
  933. }
  934. cell.btnNotifyMe.enabled = YES;
  935. } else { // 未缺货
  936. cell.btnNotifyMe.enabled = NO;
  937. cell.btnaddCart.enabled = YES;
  938. }
  939. // offline
  940. #ifdef OFFLINE_MODE
  941. if (appDelegate.offline_mode) {
  942. cell.btnNotifyMe.hidden = YES;
  943. }
  944. #endif
  945. }
  946. #endif
  947. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  948. // cell.hmlg_stock_lb.hidden = NO;
  949. // cell.hmlg_stock_count_lb.hidden = NO;
  950. id hmlg_stock = [section_json objectForKey:@"hmlg_avalability"];
  951. if (hmlg_stock == nil) {
  952. hmlg_stock = @"";
  953. }
  954. cell.hmlg_stock_count_lb.text = [NSString stringWithFormat:@"%@",hmlg_stock];
  955. cell.on_sale_lb.hidden = !is_special_model;
  956. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  957. __weak typeof(self) weakself = self;
  958. cell.notifyMeBlock = ^{
  959. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  960. dispatch_async(dispatch_get_global_queue(0,0), ^{
  961. NSDictionary *dic = [RANetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
  962. dispatch_async(dispatch_get_main_queue(), ^{
  963. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  964. NSInteger result = [[dic valueForKey:@"result"] integerValue];
  965. if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  966. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  967. if ([dic valueForKey:@"err_msg"]) {
  968. msg = [dic valueForKey:@"err_msg"];
  969. }
  970. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  971. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  972. }];
  973. [errorAlertVC addAction:action];
  974. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  975. } else if (result == RESULT_TRUE){
  976. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  977. } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  978. [self showEmailAddrBox];
  979. }
  980. });
  981. });
  982. };
  983. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  984. cell.btnaddPortfolio.hidden = YES;
  985. if (!notifyMe_switch) {
  986. cell.btnNotifyMe.hidden = YES;
  987. } else {
  988. cell.btnNotifyMe.hidden = NO;
  989. if (!appDelegate.order_code) { // 未打开订单状态
  990. if ([self isOutofStock]) {
  991. if (!appDelegate.can_create_backorder) {
  992. cell.btnaddCart.enabled = NO;
  993. }
  994. cell.btnNotifyMe.enabled = YES;
  995. } else {
  996. cell.btnaddCart.enabled = YES;
  997. cell.btnNotifyMe.enabled = NO;
  998. }
  999. } else {
  1000. // 打开订单状态
  1001. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1002. // Shop Order
  1003. cell.btnaddCart.enabled = YES;
  1004. // 默认未缺货
  1005. cell.btnNotifyMe.enabled = NO;
  1006. if ([self isOutofStock]) { // 缺货
  1007. cell.btnNotifyMe.enabled = YES;
  1008. }
  1009. } else {
  1010. // Purchase Order
  1011. if ([self isOutofStock]) { // 缺货
  1012. if (!appDelegate.can_create_backorder) {
  1013. cell.btnaddCart.enabled = NO;
  1014. }
  1015. cell.btnNotifyMe.enabled = YES;
  1016. } else { // 未缺货
  1017. cell.btnNotifyMe.enabled = NO;
  1018. cell.btnaddCart.enabled = YES;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. } else { // employee
  1024. // online
  1025. cell.btnaddPortfolio.hidden = NO;
  1026. cell.btnNotifyMe.hidden = NO;
  1027. if ([self isOutofStock]) { // 缺货
  1028. if (!appDelegate.can_create_backorder) {
  1029. cell.btnaddCart.enabled = NO;
  1030. }
  1031. cell.btnNotifyMe.enabled = YES;
  1032. } else { // 未缺货
  1033. cell.btnNotifyMe.enabled = NO;
  1034. cell.btnaddCart.enabled = YES;
  1035. }
  1036. // offline
  1037. #ifdef OFFLINE_MODE
  1038. if (appDelegate.offline_mode) {
  1039. cell.btnNotifyMe.hidden = YES;
  1040. }
  1041. #endif
  1042. }
  1043. #endif
  1044. #ifdef BUILD_HMLG
  1045. cell.btnaddPortfolio.hidden = NO;
  1046. cell.btnNotifyMe.hidden = YES;
  1047. #endif
  1048. }
  1049. self.anchor_button.frame=cell.selector_Button.frame;
  1050. cell.celldelegate=self;
  1051. cell.quantity_text.text = [NSString stringWithFormat:@"%d",self.quantity];
  1052. cell.step = self.step;
  1053. cell.quantity = self.quantity;
  1054. // cell.stepper.stepValue = self.step;
  1055. // cell.stepper.value = self.quantity;
  1056. NSString* price = [section_json valueForKey:@"price"];
  1057. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1058. if(appDelegate.contact_id ==nil)
  1059. {
  1060. // appDelegate.bLogin = false;
  1061. // cell.btnaddCart.enabled = false;
  1062. }
  1063. else
  1064. {
  1065. if ([price isEqualToString:@"No Price."]) {
  1066. // cell.btnaddCart.enabled = false;
  1067. }
  1068. else
  1069. {
  1070. // cell.btnaddCart.enabled = true;
  1071. }
  1072. }
  1073. int cqty = [[section_json valueForKey:@"Model QTY in cart"] intValue];
  1074. cell.cqty = cqty;
  1075. cell.set_cqty=^(int cqty)
  1076. {
  1077. [section_json setValue:[NSString stringWithFormat:@"%d",cqty] forKey:@"Model QTY in cart"];
  1078. [self.detail_data setObject:section_json forKey:@"img_section"];
  1079. [self.detailTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  1080. };
  1081. cell.set_update_data=^(bool bupdate)
  1082. {
  1083. //self.update_data = bupdate;
  1084. #ifdef RA_NOTIFICATION
  1085. if(bupdate)
  1086. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1087. else
  1088. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  1089. #else
  1090. if(bupdate)
  1091. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  1092. else
  1093. [((MainViewController*)appDelegate.main_vc) reloadCategory:false immediately:false];
  1094. #endif
  1095. };
  1096. if(cqty>0)
  1097. {
  1098. cell.cqyt_label.hidden=false;
  1099. cell.cqyt_label.text=[NSString stringWithFormat:@"Model QTY in Cart:%d",cqty];
  1100. }
  1101. else
  1102. {
  1103. cell.cqyt_label.hidden=true;
  1104. cell.cqyt_label.text=nil;
  1105. }
  1106. cell.descriptionRTLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  1107. // cell.descriptionLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  1108. cell.model_label.text =[section_json valueForKey:@"model_name"];
  1109. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:80];
  1110. // cell.qrcode_imageview.image = qrimg;
  1111. if(appDelegate.bLogin==true)
  1112. {
  1113. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1114. {
  1115. }
  1116. else
  1117. {
  1118. price=nil;
  1119. }
  1120. }
  1121. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1122. NSString *old_price = [section_json objectForKey:@"old_price"];
  1123. if (appDelegate.user && old_price != nil && old_price.length > 0) {
  1124. cell.priceLabel.text = nil;
  1125. NSString *new_price_str = [NSString stringWithFormat:@"%@ %@",price,old_price];
  1126. NSRange range = [new_price_str rangeOfString:@"$" options:NSBackwardsSearch];
  1127. range = NSMakeRange(range.location,new_price_str.length - range.location);
  1128. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:new_price_str];
  1129. [attrStr addAttributes:@{
  1130. NSStrikethroughStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle]
  1131. }
  1132. range:range];
  1133. cell.priceLabel.attributedText = attrStr;
  1134. } else {
  1135. cell.priceLabel.attributedText = nil;
  1136. cell.priceLabel.text =price;
  1137. }
  1138. #else
  1139. cell.priceLabel.text =price;
  1140. #endif
  1141. // cell.shipLabel.text = [section_json valueForKey:@"ship"];
  1142. cell.count_Label.text =[section_json valueForKey:@"Availability"] ;
  1143. NSString* eta =[section_json valueForKey:@"ETA"] ;
  1144. if(eta.length>0)
  1145. {
  1146. cell.eta_label.hidden = false;
  1147. cell.etaval_label.text = eta;
  1148. cell.etaval_label.hidden = false;
  1149. cell.incoming_stock_label.hidden=false;
  1150. cell.incomingcount_Label.text =[section_json valueForKey:@"incoming_stock"] ;
  1151. cell.incomingcount_Label.hidden = false;
  1152. }
  1153. else
  1154. {
  1155. cell.eta_label.hidden = true;
  1156. cell.etaval_label.text = nil;
  1157. cell.etaval_label.hidden = true;
  1158. cell.incoming_stock_label.hidden = true;
  1159. cell.incomingcount_Label.text = nil;
  1160. cell.incomingcount_Label.hidden = true;
  1161. }
  1162. self.selector = [section_json objectForKey:@"selector"];
  1163. if(self.selector!=nil)
  1164. {
  1165. [cell Hide_selector:false];
  1166. cell.selector_nameLabel.text =[self.selector valueForKey:@"name"];
  1167. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  1168. cell.selector_imageView.image = [UIImage imageNamed:@"loading_s"];
  1169. for(int i=0;i<selector_count;i++)
  1170. {
  1171. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  1172. // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
  1173. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  1174. {
  1175. cell.selector_valLabel.text=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"];
  1176. NSString* selectstr=[NSString stringWithFormat:@"%@: %@",[self.selector valueForKey:@"name"],[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"]];
  1177. if([[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"] ==nil)
  1178. selectstr=[NSString stringWithFormat:@"%@:",[self.selector valueForKey:@"name"]];
  1179. cell.selector_label.text = selectstr;
  1180. NSString* img_url = [[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"pic_url"];
  1181. NSString* file_name=[img_url lastPathComponent];
  1182. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1183. if(img_data!=nil)
  1184. {
  1185. dispatch_async(dispatch_get_main_queue(), ^{
  1186. UIImage * img =[UIImage imageWithData:img_data];
  1187. cell.selector_imageView.image=img;
  1188. });
  1189. }
  1190. else
  1191. {
  1192. NSData* downloadimg_data = nil;
  1193. BOOL offline = NO;
  1194. #ifdef OFFLINE_MODE
  1195. offline = appDelegate.offline_mode;
  1196. #endif
  1197. if (!offline) {
  1198. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1199. }
  1200. dispatch_async(dispatch_get_main_queue(), ^{
  1201. if(downloadimg_data!=nil)
  1202. {
  1203. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1204. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1205. cell.selector_imageView.image=img;
  1206. }
  1207. else
  1208. cell.selector_imageView.image = [UIImage imageNamed:@"notfound_s"];
  1209. });
  1210. }
  1211. }
  1212. }
  1213. }
  1214. else
  1215. {
  1216. [cell Hide_selector:true];
  1217. }
  1218. // cell.selector_valLabel.text =[[section_json objectForKey:@"selector"] valueForKey:@"name"];
  1219. NSDictionary* property_json = [section_json objectForKey:@"property"];
  1220. // int pcount = [[property_json valueForKey:@"count"]intValue];
  1221. cell.property_nameLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"key"];
  1222. cell.property_valLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"val"];
  1223. cell.product_id = self.product_id;
  1224. // cell.itemIDLabel.text = [NSString stringWithFormat:@"Item id:%d",3947105];
  1225. [cell setup];
  1226. [cell ClearPhotos];
  1227. // NSDictionary* imgs_json = [section_json objectForKey:@"images"];
  1228. NSDictionary* contents_json = [section_json objectForKey:@"stack_contents"];
  1229. cell.stack_contents = contents_json;
  1230. int count = [[contents_json valueForKey:@"count"]intValue];
  1231. int hcount=2;
  1232. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1233. hcount=1; //homer 没有qrcode
  1234. #endif
  1235. if(count<hcount)//1 for qrcode;
  1236. cell.pageControl.hidden = true;
  1237. else
  1238. cell.pageControl.hidden = false;
  1239. // NSMutableArray* urls= [[NSMutableArray alloc]init];
  1240. // cell.urls = urls;
  1241. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1242. for(int i=0;i<count;i++)
  1243. {
  1244. NSDictionary* item_json=[contents_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  1245. NSString* type = item_json[@"type"];
  1246. // if([type isEqualToString:@"video"])
  1247. // {
  1248. // [cell AddPhoto:[UIImage imageNamed:@"play"]];
  1249. // ;
  1250. // }
  1251. // else if([type isEqualToString:@"image"])
  1252. {
  1253. NSString* img_url = [item_json valueForKey:@"s"];
  1254. // NSString* img_url_l = [img_json valueForKey:@"l"];
  1255. // if(img_url_l.length>0)
  1256. // [urls addObject:img_url_l];
  1257. NSString* file_name=[img_url lastPathComponent];
  1258. NSData* img_data=nil;
  1259. if([type isEqualToString:@"video"])
  1260. {
  1261. img_data = UIImagePNGRepresentation([UIImage imageNamed:@"play"]);
  1262. }
  1263. else
  1264. {
  1265. if([item_json[@"is_localfile"] boolValue])
  1266. img_data = [NSData dataWithContentsOfFile:img_url];
  1267. else
  1268. img_data = [iSalesDB load_cached_img:file_name loadFrom:img_url];
  1269. }
  1270. if(img_data!=nil)
  1271. {
  1272. dispatch_async(dispatch_get_main_queue(), ^{
  1273. UIImage * img =[UIImage imageWithData:img_data];
  1274. [cell AddPhoto:img];
  1275. // if(i==count-1)
  1276. // {
  1277. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1278. // if(qrimg!=nil)
  1279. // [cell AddPhoto:qrimg];
  1280. // }
  1281. // if(i==0)
  1282. // cell.imageView.image = img;
  1283. });
  1284. }
  1285. else
  1286. {
  1287. NSData* downloadimg_data = nil;
  1288. BOOL offline = NO;
  1289. #ifdef OFFLINE_MODE
  1290. offline = appDelegate.offline_mode;
  1291. #endif
  1292. if (!offline) {
  1293. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1294. }
  1295. dispatch_async(dispatch_get_main_queue(), ^{
  1296. if(downloadimg_data!=nil)
  1297. {
  1298. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1299. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1300. [cell AddPhoto:img];
  1301. // if(i==count-1)
  1302. // {
  1303. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1304. // if(qrimg!=nil)
  1305. // [cell AddPhoto:qrimg];
  1306. // }
  1307. // if(i==0)
  1308. // cell.imageView.image = img;
  1309. }
  1310. else
  1311. {
  1312. UIImage * img =[UIImage imageNamed:@"notfound_l"];
  1313. [cell AddPhoto:img];
  1314. // if(i==count-1)
  1315. // {
  1316. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1317. // if(qrimg!=nil)
  1318. // [cell AddPhoto:qrimg];
  1319. // }
  1320. // if(i==0)
  1321. // cell.imageView.image = img;
  1322. }
  1323. });
  1324. }
  1325. }
  1326. }
  1327. });
  1328. // cell.backgroundColor = [UIColor whiteColor];
  1329. __weak typeof(self) weakself = self;
  1330. cell.shopCartBlock = ^(UIImageView *imageView){
  1331. self.add_cart=true;
  1332. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1333. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1334. CGRect headRect = imageView.frame;
  1335. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1336. [self startAnimationWithRect:headRect ImageView:imageView];
  1337. [self.navigationController popToRootViewControllerAnimated:false];
  1338. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1339. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1340. };
  1341. cell.WatchlistBlock = ^(UIImageView *imageView){
  1342. self.add_wish=true;
  1343. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1344. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1345. CGRect headRect = imageView.frame;
  1346. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1347. [self startAnimationWithRect:headRect ImageView:imageView];
  1348. };
  1349. cell.PortfolioBlock = ^(UIImageView *imageView){
  1350. self.add_portfolio=true;
  1351. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1352. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1353. CGRect headRect = imageView.frame;
  1354. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1355. [self startAnimationWithRect:headRect ImageView:imageView];
  1356. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1357. #ifdef RA_NOTIFICATION
  1358. [ActiveViewController Notify:@"PortfolioViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1359. #else
  1360. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  1361. #endif
  1362. };
  1363. NSString *introduce = [section_json objectForKey:@"assembly_pdf_path"];
  1364. if (introduce == nil || introduce.length == 0) {
  1365. cell.introduceBtn.hidden = YES;
  1366. } else {
  1367. cell.introduceBtn.hidden = NO;
  1368. }
  1369. cell.introduceBlock = ^(UIButton *sender) {
  1370. [weakself showIntroducePDF:introduce];
  1371. };
  1372. NSString *desc = [section_json objectForKey:@"product_content_writing"];
  1373. if (!desc.length) {
  1374. cell.descriptionBtn.hidden = YES;
  1375. } else {
  1376. cell.descriptionBtn.hidden = NO;
  1377. NSDictionary *attrs = @{
  1378. NSFontAttributeName : [UIFont systemFontOfSize:18.0f],
  1379. NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]
  1380. };
  1381. NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:@"Read More" attributes:attrs];
  1382. [cell.descriptionBtn setAttributedTitle:attrTitle forState:UIControlStateNormal];
  1383. }
  1384. cell.descriptionBlock = ^(UIButton *sender) {
  1385. [weakself showModelDescription:desc];
  1386. };
  1387. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  1388. [cell generate_information];
  1389. cell.incoming_stock_label.hidden = YES;
  1390. cell.count_Label.hidden = YES;
  1391. cell.hmlg_stock_lb.hidden = YES;
  1392. cell.hmlg_stock_count_lb.hidden = YES;
  1393. cell.incomingcount_Label.hidden = YES;
  1394. cell.eta_label.hidden = YES;
  1395. cell.etaval_label.hidden = YES;
  1396. cell.cqyt_label.hidden = YES;
  1397. #endif
  1398. return cell;
  1399. }
  1400. // NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1401. // if(related_json==nil)
  1402. else
  1403. {
  1404. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  1405. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1406. NSString *CellIdentifier = @"DetailInfoCell";
  1407. NSString* type=[section_json valueForKey:@"type"] ;
  1408. if([type isEqualToString:@"kv"])
  1409. {
  1410. float width = tableView.frame.size.width;
  1411. width-=CELL_MARGIN*2;
  1412. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  1413. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  1414. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1415. NSString* key =[item_json valueForKey:@"key"] ;
  1416. NSString* val=[item_json valueForKey:@"val"] ;
  1417. NSString* type=[item_json valueForKey:@"type"] ;
  1418. if([type isEqualToString:@"price"])
  1419. {
  1420. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1421. {
  1422. }
  1423. else
  1424. {
  1425. val=nil;
  1426. }
  1427. }
  1428. if([val isEqual:[NSNull null]])
  1429. val=@"";
  1430. if(val==nil)
  1431. val=@"";
  1432. if([val isEqualToString:@"null"])
  1433. val=@"";
  1434. CGRect frame;
  1435. frame.size = constraintval;
  1436. frame.origin.x=0;
  1437. frame.origin.y=0;
  1438. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  1439. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  1440. // rtlabel.lineSpacing = 20.0;
  1441. [rtlabel setText: val];
  1442. CGSize sizeval=rtlabel.optimumSize;
  1443. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1444. float height = MAX(sizekey.height,sizeval.height);
  1445. height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  1446. sizekey.height = height;
  1447. sizekey.width = constraintkey.width;
  1448. // sizeval.height = height;
  1449. sizeval.width =constraintval.width;
  1450. // NSString *CellIdentifier = @"detail_item_kv";
  1451. DetailKVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1452. if(cell==nil)
  1453. DebugLog(@"cell is nil.........................");
  1454. CGRect framekey = cell.keyLabel.frame;
  1455. framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  1456. framekey.origin.y=LINE_WIDTH;
  1457. framekey.size = sizekey;
  1458. cell.keyLabel.frame = framekey;
  1459. cell.keyLabel.text=key;
  1460. CGRect frameval = cell.valLabel.frame;
  1461. frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  1462. frameval.origin.y=LINE_WIDTH;
  1463. frameval.size = sizeval;
  1464. cell.valLabel.frame = frameval;
  1465. // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  1466. cell.valLabel.text= val;
  1467. CGPoint rcenter;
  1468. rcenter.x = width * 0.4+width * 0.6/2;
  1469. rcenter.y = height /2;
  1470. cell.valLabel.center=rcenter;
  1471. // cell.valLabel.backgroundColor =[UIColor redColor];
  1472. // cell.contentView.superview.backgroundColor = [UIColor clearColor];
  1473. // cell.backgroundColor = [UIColor whiteColor];
  1474. UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1475. lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1476. lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1477. lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1478. [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1479. cell.backgroundColor = [UIColor whiteColor];
  1480. return cell;
  1481. }
  1482. else if ([type isEqualToString:@"img"])
  1483. {
  1484. DetailImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailImageCell" forIndexPath:indexPath];
  1485. int img_count = [[item_json valueForKey:@"count"] intValue];
  1486. double posy = 0;
  1487. for(int j=0;j<img_count;j++)
  1488. {
  1489. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  1490. float width = [[img_json valueForKey:@"width"]floatValue];
  1491. float height = [[img_json valueForKey:@"height"]floatValue];
  1492. //
  1493. UIImageView * imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, posy, tableView.bounds.size.width , height*tableView.bounds.size.width / width)];
  1494. imgview.contentMode = UIViewContentModeScaleAspectFit;
  1495. NSString* img_url = [img_json valueForKey:@"img_url"];
  1496. posy+=height*tableView.bounds.size.width / width;
  1497. NSString* file_name=[img_url lastPathComponent];
  1498. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1499. if(img_data!=nil)
  1500. {
  1501. UIImage * img =[UIImage imageWithData:img_data];
  1502. imgview.image = img;
  1503. [cell addSubview:imgview];
  1504. }
  1505. else
  1506. {
  1507. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1508. NSData* downloadimg_data = nil;
  1509. BOOL offline = NO;
  1510. #ifdef OFFLINE_MODE
  1511. offline = appDelegate.offline_mode;
  1512. #endif
  1513. if (!offline) {
  1514. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1515. }
  1516. dispatch_async(dispatch_get_main_queue(), ^{
  1517. if(downloadimg_data!=nil)
  1518. {
  1519. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1520. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1521. imgview.image = img;
  1522. [cell addSubview:imgview];
  1523. }
  1524. else
  1525. {
  1526. imgview.image = [UIImage imageNamed:@"notfound_l"];
  1527. [cell addSubview:imgview];
  1528. }
  1529. });
  1530. });
  1531. }
  1532. }
  1533. cell.backgroundColor = [UIColor whiteColor];
  1534. return cell;
  1535. }
  1536. else if ([type isEqualToString:@"content"])
  1537. {
  1538. NSString *CellIdentifier = @"DetailTopicCell";
  1539. NSString* data=[section_json valueForKey:@"data"] ;
  1540. if([data isEqualToString:@"local"])
  1541. {
  1542. [appDelegate.recent_model addEntriesFromDictionary:section_json];
  1543. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1544. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1545. cell.itemdelegate = self;
  1546. cell.related_data = appDelegate.recent_model;
  1547. [cell.topicCollectionView reloadData];
  1548. cell.backgroundColor = [UIColor whiteColor];
  1549. return cell;
  1550. }
  1551. else
  1552. {
  1553. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1554. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1555. cell.itemdelegate = self;
  1556. cell.related_data = section_json;
  1557. [cell.topicCollectionView reloadData];
  1558. cell.backgroundColor = [UIColor whiteColor];
  1559. return cell;
  1560. }
  1561. }
  1562. return nil;
  1563. }
  1564. }
  1565. -(void)startAnimationWithRect:(CGRect)rect ImageView:(UIImageView *)imageView
  1566. {
  1567. if (!_layer) {
  1568. // _btn.enabled = NO;
  1569. _layer = [CALayer layer];
  1570. _layer.contents = (id)imageView.layer.contents;
  1571. _layer.contentsGravity = kCAGravityResizeAspectFill;
  1572. _layer.bounds = rect;
  1573. [_layer setCornerRadius:CGRectGetHeight([_layer bounds]) / 2];
  1574. _layer.masksToBounds = YES;
  1575. // 导航64
  1576. _layer.position = CGPointMake(imageView.center.x, CGRectGetMidY(rect)+64);
  1577. // [_tableView.layer addSublayer:_layer];
  1578. [self.view.layer addSublayer:_layer];
  1579. self.path = [UIBezierPath bezierPath];
  1580. // [_path moveToPoint:_layer.position];
  1581. [_path moveToPoint:imageView.center];
  1582. [_path addLineToPoint:CGPointMake(imageView.center.x, imageView.center.y-100)];
  1583. // (SCREEN_WIDTH - 60), 0, 50, 50)
  1584. // [_path addQuadCurveToPoint:CGPointMake(SCREEN_WIDTH - 40, SCREEN_HEIGHT-40) controlPoint:CGPointMake(SCREEN_WIDTH/2,rect.origin.y-80)];
  1585. // [_path addLineToPoint:CGPointMake(SCREEN_WIDTH-40, 30)];
  1586. }
  1587. [self groupAnimation];
  1588. }
  1589. -(void)groupAnimation
  1590. {
  1591. self.detailTable.userInteractionEnabled = NO;
  1592. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  1593. animation.path = _path.CGPath;
  1594. // animation.rotationMode = kCAAnimationRotateAuto;
  1595. //
  1596. CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1597. expandAnimation.duration = 0.3f;
  1598. expandAnimation.fromValue = [NSNumber numberWithFloat:1];
  1599. expandAnimation.toValue = [NSNumber numberWithFloat:2.0f];
  1600. expandAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  1601. CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1602. narrowAnimation.beginTime = 0.3;
  1603. narrowAnimation.fromValue = [NSNumber numberWithFloat:2.0f];
  1604. narrowAnimation.duration = 0.9f;
  1605. narrowAnimation.toValue = [NSNumber numberWithFloat:0.3f];
  1606. //
  1607. // narrowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  1608. CAAnimationGroup *groups = [CAAnimationGroup animation];
  1609. groups.animations = @[animation,expandAnimation,narrowAnimation];
  1610. groups.duration = 1.0f;
  1611. groups.removedOnCompletion=NO;
  1612. groups.fillMode=kCAFillModeForwards;
  1613. groups.delegate = self;
  1614. [_layer addAnimation:groups forKey:@"group"];
  1615. }
  1616. -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
  1617. {
  1618. // [anim def];
  1619. if (anim == [_layer animationForKey:@"group"]) {
  1620. self.detailTable.userInteractionEnabled = YES;
  1621. // _btn.enabled = YES;
  1622. [_layer removeFromSuperlayer];
  1623. _layer = nil;
  1624. // _cnt++;
  1625. // if (_cnt) {
  1626. // _cntLabel.hidden = NO;
  1627. // }
  1628. // CATransition *animation = [CATransition animation];
  1629. // animation.duration = 0.25f;
  1630. // _cntLabel.text = [NSString stringWithFormat:@"%d",_cnt];
  1631. // [_cntLabel.layer addAnimation:animation forKey:nil];
  1632. // CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
  1633. // shakeAnimation.duration = 0.25f;
  1634. // shakeAnimation.fromValue = [NSNumber numberWithFloat:-5];
  1635. // shakeAnimation.toValue = [NSNumber numberWithFloat:5];
  1636. // shakeAnimation.autoreverses = YES;
  1637. // [_btn.layer addAnimation:shakeAnimation forKey:nil];
  1638. }
  1639. }
  1640. #pragma mark - hide section button clicked
  1641. - (void)RefreshSection:(UIButton *)sender {
  1642. sender.enabled=false;
  1643. NSDictionary* section_json = nil;
  1644. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1645. if(related_json==nil)
  1646. {
  1647. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(sender.tag-1)]];
  1648. }
  1649. else
  1650. {
  1651. if(sender.tag==1)
  1652. {
  1653. section_json = related_json ;
  1654. }
  1655. else
  1656. {
  1657. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)sender.tag-2]];
  1658. }
  1659. }
  1660. NSString* url = section_json[@"data_interface"];
  1661. NSMutableDictionary* params = [section_json[@"params"] mutableCopy];
  1662. if(params==nil)
  1663. params = [[NSMutableDictionary alloc] init];
  1664. NSUInteger ii[2] = {sender.tag,0};
  1665. NSIndexPath* indexpath= [NSIndexPath indexPathWithIndexes:ii length:2];
  1666. DetailTopicCell * cell=[self.detailTable cellForRowAtIndexPath:indexpath];
  1667. [cell begin_refresh];
  1668. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..."title:@"Refreshing"];
  1669. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1670. NSDictionary* editor_json = [RANetwork commoneditor_partialrefresh:params url:url];
  1671. dispatch_async(dispatch_get_main_queue(), ^{
  1672. [cell end_refresh ];
  1673. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1674. sender.enabled=true;
  1675. if([[editor_json valueForKey:@"result"] intValue]==2)
  1676. {
  1677. [self.detail_data addEntriesFromDictionary:editor_json];
  1678. NSRange range = NSMakeRange(sender.tag, 1);
  1679. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1680. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1681. }
  1682. else
  1683. {
  1684. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  1685. }
  1686. });
  1687. });
  1688. // self.showMore=!self.showMore;
  1689. // NSRange range = NSMakeRange(1, 1);
  1690. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1691. // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1692. }
  1693. #pragma mark - Support scanner
  1694. -(void) onDecodedData:(NSString*) value
  1695. {
  1696. // UIApplication * app = [UIApplication sharedApplication];
  1697. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1698. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1699. //
  1700. self.model_name = value;
  1701. self.product_id = nil;
  1702. self.use_model_name = true;
  1703. [self reload];
  1704. DebugLog(@"color selected");
  1705. }
  1706. #pragma mark - Handle Notification
  1707. - (void)dealloc {
  1708. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1709. }
  1710. - (void)registeObserver {
  1711. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNoRightMsg:) name:No_Rights_Notification object:nil];
  1712. }
  1713. - (void)handleNoRightMsg:(NSNotification *)notification {
  1714. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:@"You have no rights to do that." preferredStyle:UIAlertControllerStyleAlert];
  1715. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1716. [alertController dismissViewControllerAnimated:YES completion:nil];
  1717. }];
  1718. [alertController addAction:action];
  1719. [self presentViewController:alertController animated:YES completion:nil];
  1720. }
  1721. #pragma mark - action
  1722. - (void)showEmailAddrBox {
  1723. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1724. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  1725. emailAddrVC.textFiled.secureTextEntry = NO;
  1726. emailAddrVC.yesButtonTitle = @"send";
  1727. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  1728. __weak typeof(self) weakself = self;
  1729. emailAddrVC.textHandler = ^(NSString *text){
  1730. // 验证邮箱格式是否正确
  1731. // NSString *match = EMAIL_MATCHES;
  1732. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  1733. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  1734. BOOL isEmailAddr = YES;
  1735. if (isEmailAddr) {
  1736. // 验证是邮件地址,发送邮件
  1737. [weakVC dismissViewControllerAnimated:YES completion:^{
  1738. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  1739. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1740. NSDictionary *result = [RANetwork notifyModel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo];
  1741. DebugLog(@"email cart result: %@",result);
  1742. dispatch_async(dispatch_get_main_queue(), ^{
  1743. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1744. int resultStatus = [[result objectForKey:@"result"] intValue];
  1745. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  1746. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1747. if ([result valueForKey:@"err_msg"]) {
  1748. msg = [result valueForKey:@"err_msg"];
  1749. }
  1750. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1751. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1752. }];
  1753. [errorAlertVC addAction:action];
  1754. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1755. }else if(resultStatus == RESULT_TRUE){
  1756. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  1757. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  1758. [weakself showEmailAddrBox];
  1759. }
  1760. });
  1761. });
  1762. }];
  1763. } else {
  1764. // 非邮件地址,警告
  1765. [weakVC warning:@"Please enter right email address"];
  1766. }
  1767. };
  1768. [self presentViewController:emailAddrVC animated:YES completion:nil];
  1769. }
  1770. - (void)showIntroducePDF:(NSString *)link {
  1771. if (link.length == 0) {
  1772. [RAUtils message_alert:@"There is no resource to open" title:@"Warning" controller:self];
  1773. return;
  1774. }
  1775. NSArray *tmpArr = [link componentsSeparatedByString:@"="];
  1776. BOOL isLocalFile = NO;
  1777. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  1778. NSString *name = [section_json valueForKey:@"model_name"];
  1779. NSString *path = [NSString stringWithFormat:@"%@/Introduce/%@.pdf",[RAUtils appCacheDirectory],tmpArr.lastObject];
  1780. if ([RAUtils fileExistsAtPath:path]) { // 检查缓存
  1781. isLocalFile = YES;
  1782. link = path;
  1783. } else {
  1784. // 创建缓存目录
  1785. NSString *dir = [path stringByDeletingLastPathComponent];
  1786. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  1787. }
  1788. name = [NSString stringWithFormat:@"%@ Assembly Instruction",name];
  1789. RAPDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  1790. ViewController.url = link;
  1791. ViewController.canSave = false;
  1792. ViewController.isLocalfile=isLocalFile;
  1793. ViewController.cachePath = path;
  1794. NSString* subject = name;
  1795. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1796. NSString* customer_email = [appDelegate.customerInfo valueForKey:@"customer_email"];
  1797. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  1798. if(customer_email.length>0)
  1799. {
  1800. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  1801. }
  1802. ViewController.mail_to = send_to;
  1803. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",name];
  1804. ViewController.mail_subject = subject;
  1805. ViewController.hidenavi = false;
  1806. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ViewController];
  1807. // nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
  1808. // CGSize size = [UIScreen mainScreen].bounds.size;
  1809. // nav.preferredContentSize = CGSizeMake(size.width * 0.8, size.height * 0.8);
  1810. [self.navigationController pushViewController:ViewController animated:YES];
  1811. }
  1812. - (void)showModelDescription:(NSString *)desc {
  1813. ModelDescriptionController *vc = [[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ModelDescriptionController"];
  1814. vc.model_desc = desc;
  1815. vc.title = [NSString stringWithFormat:@"%@ Description",self.model_name];
  1816. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  1817. nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
  1818. nav.preferredContentSize = CGSizeMake(400, 380);// 只有在 UIModalPresentationFormSheet 的时候起作用
  1819. [self presentViewController:nav animated:YES completion:nil];
  1820. }
  1821. - (void)reRefreshView {
  1822. [self.detailTable reloadData];
  1823. }
  1824. #pragma mark - RA_NOTIFICAITON
  1825. -(void) refresh_ui
  1826. {
  1827. [self.detailTable reloadData];
  1828. }
  1829. -(void) reload_data
  1830. {
  1831. [self reload];
  1832. }
  1833. -(void) refresh_price
  1834. {
  1835. [self refresh_ui];
  1836. }
  1837. @end