DetailViewController.m 76 KB

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