DetailViewController.m 69 KB

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