DetailViewController.m 92 KB

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