DetailViewController.m 54 KB

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