DetailViewController.m 53 KB

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