DetailViewController.m 94 KB

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