DetailViewController.m 70 KB

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