DetailViewController.m 90 KB

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