DetailViewController.m 96 KB

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