DetailViewController.m 93 KB

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