DetailViewController.m 52 KB

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