DetailViewController.m 52 KB

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