CatalogModelDetailViewController.m 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. //
  2. // DetailViewController.m
  3. // iShop
  4. //
  5. // Created by Rui Zhang on 12/15/23.
  6. //
  7. #import "CatalogModelDetailViewController.h"
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "DetailSlideImageCell.h"
  11. #import "SliderPage.h"
  12. #import "RTLabel.h"
  13. #import "DetailKVCell.h"
  14. #import "LineView.h"
  15. #import "DetailBasicCell0.h"
  16. #import "FileCache.h"
  17. #import "ColorSelectViewController.h"
  18. #import "CustomPresentationController.h"
  19. #define RTLABEL_FONT_SIZE 15
  20. #define DEF_CELL_HEIGHT 44
  21. #define DEF_TABLE_HEIGHT 44
  22. #define LINE_WIDTH 10
  23. #define CELL_MARGIN 0
  24. #define LABEL_MARGIN 10
  25. @interface CatalogModelDetailViewController ()
  26. @end
  27. @implementation CatalogModelDetailViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.show_navi = true;
  31. // Do any additional setup after loading the view.
  32. }
  33. //- (void)setDetail_data:(NSMutableDictionary *)detail_data
  34. //{
  35. // NSMutableDictionary* data = [NSMutableDictionary new];
  36. //
  37. //
  38. // NSMutableDictionary* img_section=detail_data[@"img_section"];
  39. //// NSMutableDictionary* img=detail_data[@"images"];
  40. //// NSMutableDictionary* video=detail_data[@"videos"];
  41. ////
  42. //// NSMutableDictionary* new_res =[NSMutableDictionary new];
  43. //// int new_count = 0;
  44. //// for(int i=0;i<video.count;i++)
  45. //// {
  46. ////
  47. //// NSMutableDictionary* item =[NSMutableDictionary new];
  48. //// item[@"code"]= video[[NSString stringWithFormat:@"video_%d",i]];
  49. //// item[@"type"]=@"video";
  50. ////
  51. ////
  52. //// new_res[[NSString stringWithFormat:@"res_%d",new_count]]=item;
  53. ////
  54. //// new_count++;
  55. //// }
  56. ////
  57. //
  58. // NSMutableDictionary* images=[img_section[@"images"] mutableCopy];
  59. // NSMutableDictionary* videos=[img_section[@"videos"] mutableCopy];
  60. //
  61. // NSMutableDictionary* contents = [NSMutableDictionary new];
  62. // int count = 0;
  63. //
  64. //
  65. // for(int ic=0;ic<[videos[@"count"] intValue];ic++)
  66. // {
  67. // NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
  68. //
  69. //
  70. //
  71. // NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
  72. //
  73. // contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  74. // count++;
  75. // }
  76. //
  77. //
  78. // for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
  79. // {
  80. // NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
  81. // item[@"type"]=@"image";
  82. // contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  83. // count++;
  84. // }
  85. //
  86. //
  87. //
  88. //
  89. //
  90. // contents[@"count"]=@(count);
  91. // data[@"stack_contents"]=contents;
  92. //}
  93. -(void) add_recent_model:(NSDictionary*) model
  94. {
  95. NSMutableDictionary * newdict = [[NSMutableDictionary alloc]init];
  96. [newdict setObject:model forKey:@"item_0"];
  97. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  98. int count=[appDelegate.recent_model[@"count"] intValue];
  99. for(int i=0;i<count;i++)
  100. {
  101. NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
  102. NSString *mitemProductID = [NSString stringWithFormat:@"%@",mitem[@"product_id"]];
  103. NSString *modelProductID = [NSString stringWithFormat:@"%@",model[@"product_id"]];
  104. if([mitemProductID isEqualToString:modelProductID])
  105. continue;
  106. [newdict setObject:mitem forKey:[NSString stringWithFormat:@"item_%lu",(unsigned long)newdict.allKeys.count]];
  107. }
  108. newdict[@"count"]=[NSString stringWithFormat:@"%lu",(unsigned long)newdict.allKeys.count];
  109. appDelegate.recent_model = newdict;
  110. }
  111. -(void) reload
  112. {
  113. dispatch_async(dispatch_get_main_queue(), ^{
  114. if(self.isrefreshing)
  115. return;
  116. // self.label_net_err.hidden=true;
  117. self.tableView.hidden = true;
  118. self.isrefreshing=true;
  119. // self.mum.center = self.view.center;
  120. // self.mum.hidden = false;
  121. // [self.mum startAnimating];
  122. //self.detailTable.hidden=true;
  123. [RANetwork request_modeldetail:self.product_id model_name:self.model_name upc_code:self.upc_code category_id:self.category_id use_name:self.use_model_name use_upc:self.use_upc_code groupName:self.groupName completionHandler:^(NSMutableDictionary *result) {
  124. NSMutableDictionary* detail_json=result;
  125. // [self.mum stopAnimating];
  126. self.groupName = nil;
  127. if([[detail_json valueForKey:@"result"] intValue]==2)
  128. {
  129. self.detail_data = [detail_json mutableCopy];
  130. self.product_id = [NSString stringWithFormat:@"%d",[[detail_json valueForKey:@"product_id"] intValue] ];
  131. NSMutableDictionary* imgsection = [[detail_json objectForKey:@"img_section"] mutableCopy];
  132. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  133. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/true)
  134. {
  135. self.quantity =[[imgsection valueForKey:@"stockUom"] intValue];
  136. }
  137. if(self.quantity==0)
  138. self.quantity=1;
  139. self.step=self.quantity;
  140. [self.tableView reloadData];
  141. //
  142. self.tableView.hidden = false;
  143. NSString* model_name = self.detail_data[@"img_section"][@"model_name"];
  144. NSString* img_url = self.detail_data[@"img_section"][@"model_s_img"];
  145. NSMutableDictionary* images=[self.detail_data[@"img_section"][@"images"] mutableCopy];
  146. NSMutableDictionary* videos=[self.detail_data[@"img_section"][@"videos"] mutableCopy];
  147. NSMutableDictionary* contents = [NSMutableDictionary new];
  148. int count = 0;
  149. {
  150. for(int ic=0;ic<[videos[@"count"] intValue];ic++)
  151. {
  152. NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
  153. // NSString* path=[[NSBundle mainBundle] pathForResource:@"play" ofType:@"jpg"];
  154. //
  155. // NSMutableDictionary* item =[@{@"type":@"video",@"is_localfile":@(true),@"l":path,@"s":path} mutableCopy];
  156. //
  157. // contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  158. // count++;
  159. NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
  160. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  161. count++;
  162. }
  163. }
  164. {
  165. for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
  166. {
  167. NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
  168. item[@"type"]=@"image";
  169. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  170. count++;
  171. }
  172. }
  173. contents[@"count"]=@(count);
  174. imgsection[@"stack_contents"]=contents;
  175. self.detail_data[@"img_section"]=imgsection;
  176. // self.detail_data[@"img_section"][@"stack_contents"]=contents;
  177. NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
  178. [item setValue:self.product_id forKey:@"product_id"];
  179. [item setValue:self.category_id forKey:@"category"];
  180. [item setValue:model_name forKey:@"fash_name"];
  181. [item setValue:img_url forKey:@"picture_path"];
  182. [self add_recent_model:item];
  183. NSUInteger ii[2] = {0,0};
  184. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndexes:ii length:2] atScrollPosition:UITableViewScrollPositionTop animated:YES];
  185. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  186. // int count=[appDelegate.recent_model[@"count"] intValue];
  187. // bool bexist = false;
  188. // for(int i=0;i<count;i++)
  189. // {
  190. // NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
  191. // if([mitem[@"product_id"] isEqualToString:self.product_id])
  192. // {
  193. // bexist=true;
  194. // break;
  195. // }
  196. // }
  197. //
  198. // if(!bexist)
  199. // {
  200. // [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
  201. // appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
  202. // }
  203. self.groupName = [detail_json objectForKey:@"groupName"];
  204. }
  205. else
  206. if([[detail_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  207. {
  208. self.tableView.hidden = true;
  209. // self.label_net_err.hidden=false;
  210. }
  211. else if([[detail_json valueForKey:@"result"] intValue]==RESULT_NO_MODEL)
  212. {
  213. self.tableView.hidden = true;
  214. [RAUtils message_box:@"Model Detail" message:[detail_json valueForKey:@"err_msg"] completion:nil] ;
  215. if(self.ispush)
  216. [ self.navigationController popViewControllerAnimated:true];
  217. }
  218. else
  219. {
  220. [RAUtils message_box:@"Model Detail" message:[detail_json valueForKey:@"err_msg"] completion:nil] ;
  221. }
  222. self.isrefreshing=false;
  223. }];
  224. return;
  225. });
  226. }
  227. /*
  228. #pragma mark - Navigation
  229. // In a storyboard-based application, you will often want to do a little preparation before navigation
  230. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  231. // Get the new view controller using [segue destinationViewController].
  232. // Pass the selected object to the new view controller.
  233. }
  234. */
  235. #pragma mark - RA_NOTIFICAITON
  236. -(void) refresh_ui
  237. {
  238. [self.tableView reloadData];
  239. }
  240. -(void) reload_data
  241. {
  242. [self reload];
  243. }
  244. -(void) refresh_price
  245. {
  246. [self refresh_ui];
  247. }
  248. #pragma mark - Table view data source
  249. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  250. if(section==0)
  251. return nil;
  252. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  253. if(related_json==nil)
  254. {
  255. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  256. return [section_json valueForKey:@"title"] ;
  257. }
  258. else
  259. {
  260. if(section==1)
  261. return @"related model";
  262. else
  263. {
  264. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  265. return [section_json valueForKey:@"title"] ;
  266. }
  267. }
  268. }
  269. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  270. //{
  271. // return 33;
  272. //}
  273. //-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  274. //{
  275. //
  276. //
  277. //
  278. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  279. //
  280. // if(value==nil)
  281. // value=@"";
  282. // unsigned long color = strtoul([value UTF8String],0,16);
  283. //
  284. // NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
  285. // if (sectionTitle == nil) {
  286. // return nil;
  287. // }
  288. //
  289. //
  290. // DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  291. // // myView.backgroundColor = UIColorFromRGB(0x996633);
  292. // myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  293. // myView.layer.shadowColor = [UIColor blackColor].CGColor;
  294. // myView.layer.shadowOffset = CGSizeMake(0, 0);
  295. // myView.layer.shadowOpacity = 0.5;
  296. // myView.layer.shadowRadius = 2.0;
  297. //
  298. // UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5.5, 90, 22)];
  299. // titlelabel.textColor=UIColorFromRGB(color);
  300. // // titlelabel.backgroundColor = [UIColor clearColor];
  301. // titlelabel.text=sectionTitle;
  302. // [titlelabel sizeToFit];
  303. //
  304. //
  305. //
  306. // NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  307. // bool refresh= [[section_json valueForKey:@"partial_refresh"] boolValue] ;
  308. //
  309. //
  310. // if(refresh)
  311. // {
  312. // NSString* btntitle=@"Refresh" ;
  313. //
  314. //// NSString* value =[DefaultAppearance get_noneappearance_value:@"DetailTableHeaderView" valuename:@"refresh_button_color"];
  315. ////
  316. //// if(value==nil)
  317. //// value=@"";
  318. //// unsigned long color = strtoul([value UTF8String],0,16);
  319. //
  320. //
  321. //
  322. // UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-100-15, 0, 100, 33)];
  323. //
  324. //
  325. // // [btn setTitleColor:UIColorFromRGB(color) forState:UIControlStateNormal];
  326. // btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  327. // btn.tag=section;
  328. // [btn addTarget:self action:@selector(RefreshSection:) forControlEvents:UIControlEventTouchUpInside];
  329. // [btn setTitle:btntitle forState:UIControlStateNormal];
  330. // [myView addSubview:btn];
  331. // }
  332. //
  333. // [myView addSubview:titlelabel];
  334. //
  335. //
  336. // return myView;
  337. //}
  338. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  339. {
  340. int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
  341. if(section_count==0)
  342. return section_count;
  343. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  344. if(related_json==nil)
  345. return section_count+1;
  346. else
  347. return section_count+2;
  348. }
  349. //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  350. //{
  351. // DebugLog(@"canMoveRowAtIndexPath");
  352. //
  353. // if([tableView numberOfRowsInSection:indexPath.section]>1)
  354. // return true;
  355. // else
  356. // return false;
  357. //}
  358. //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  359. //{
  360. // NSMutableArray * from;
  361. // NSMutableArray * to ;
  362. // if(fromIndexPath.section==0)
  363. // from = self.displayfields;
  364. // else
  365. // from = self.hidefields;
  366. // if(toIndexPath.section==0)
  367. // to = self.displayfields;
  368. // else
  369. // to = self.hidefields;
  370. // id content=from[fromIndexPath.row];
  371. // [from removeObjectAtIndex:fromIndexPath.row];
  372. // [to insertObject:content atIndex:toIndexPath.row];
  373. //
  374. // [tableView reloadData];
  375. //
  376. //}
  377. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  378. {
  379. if(section==0)
  380. return 2;
  381. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  382. if(related_json==nil)
  383. {
  384. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-1]];
  385. NSString* type=[section_json valueForKey:@"type"] ;
  386. if([type isEqualToString:@"content"])
  387. return 1;
  388. return [[section_json valueForKey:@"count"] intValue];
  389. }
  390. else
  391. {
  392. if(section==1)
  393. return 1;
  394. else
  395. {
  396. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  397. NSString* type=[section_json valueForKey:@"type"] ;
  398. if([type isEqualToString:@"content"])
  399. return 1;
  400. return [[section_json valueForKey:@"count"] intValue];
  401. }
  402. }
  403. }
  404. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  405. {
  406. if(section ==0)
  407. return 0;
  408. else
  409. return 33;
  410. }
  411. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  412. {
  413. if(indexPath.section ==0)
  414. return 295;
  415. else if(indexPath.section==2||indexPath.section==3)
  416. return 270;
  417. NSDictionary* nsdic = self.detail_data;
  418. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  419. if(related_json==nil)
  420. {
  421. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  422. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  423. NSString* type=[section_json valueForKey:@"type"] ;
  424. if([type isEqualToString:@"kv"])
  425. {
  426. float width = tableView.frame.size.width;
  427. width-=CELL_MARGIN*2;
  428. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  429. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  430. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  431. NSString* key =[item_json valueForKey:@"key"] ;
  432. // [cell.keyLabel sizeToFit];
  433. NSString* val=[item_json valueForKey:@"val"] ;
  434. if([val isEqual:[NSNull null]])
  435. val=@"";
  436. if(val==nil)
  437. val=@"";
  438. if([val isEqualToString:@"null"])
  439. val=@"";
  440. CGRect frame;
  441. frame.size = constraintval;
  442. frame.origin.x=0;
  443. frame.origin.y=0;
  444. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  445. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  446. // rtlabel.lineSpacing = 20.0;
  447. [rtlabel setText: val];
  448. rtlabel.font = [UIFont systemFontOfSize:RTLABEL_FONT_SIZE];
  449. CGSize sizeval=rtlabel.optimumSize;
  450. //
  451. //
  452. // CGSize sizeval0=[RAUtils sizeWithFont:val font:[UIFont systemFontOfSize:RTLABEL_FONT_SIZE] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  453. //
  454. // // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  455. // CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:RTLABEL_FONT_SIZE] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  456. frame.size =constraintkey;
  457. UILabel* label = [[UILabel alloc] initWithFrame:frame];
  458. [label setLineBreakMode:NSLineBreakByWordWrapping];
  459. label.font=[UIFont systemFontOfSize:RTLABEL_FONT_SIZE];
  460. label.text = key;
  461. CGSize sizekey =[label sizeThatFits:label.frame.size];
  462. // rtlabel.text = key;
  463. // CGSize sizekey =rtlabel.optimumSize;
  464. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  465. float height = MAX(sizekey.height,sizeval.height);
  466. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  467. return height;
  468. }
  469. else if([type isEqualToString:@"img"])
  470. {
  471. int img_count = [[item_json valueForKey:@"count"] intValue];
  472. double ret = 0;
  473. for(int j=0;j<img_count;j++)
  474. {
  475. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  476. float width = [[img_json valueForKey:@"width"]floatValue];
  477. float height = [[img_json valueForKey:@"height"]floatValue];
  478. ret+=height*tableView.bounds.size.width / width;
  479. }
  480. return ret;
  481. }
  482. else if([type isEqualToString:@"content"])
  483. return 270;
  484. }
  485. return 44;
  486. }
  487. - (BOOL)isOutofStock {
  488. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  489. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  490. // 2018-01-10 修改通过lowercase判断
  491. if (!qtyStr || !qtyStr.length || [qtyStr.lowercaseString isEqualToString:@"in production"] || [qtyStr isEqualToString:@"0"] || [qtyStr.lowercaseString isEqualToString:@"sold out"] || [qtyStr.lowercaseString isEqualToString:@"out of stock"]) {
  492. return YES;
  493. }
  494. return NO;
  495. }
  496. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  497. {
  498. if(indexPath.section==0)
  499. if(indexPath.item ==0)
  500. {
  501. NSString *CellIdentifier = @"DetailImageCell";
  502. DetailSlideImageCell *slidecell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  503. [slidecell.imgScroll stopTimmer];
  504. [slidecell.imgScroll removeFromSuperview];
  505. NSMutableDictionary* view_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  506. //如果模版有高度就用模版设置值,没有则用默认值。
  507. int i_width = [[view_json valueForKey:@"width"]intValue];
  508. int i_height = [[view_json valueForKey:@"height"]intValue];
  509. if(i_width<=0||i_height<=0)
  510. {
  511. i_width=400;
  512. i_height=300;
  513. }
  514. int ui_height = (tableView.frame.size.width * i_height)/i_width;
  515. CycleScrollViewPlus *imgScroll = [[CycleScrollViewPlus alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, ui_height) animationDuration:5];
  516. imgScroll.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  517. int slide_item_count = [view_json[@"stack_contents"][@"count"] intValue];
  518. //imgScroll.frame =CGRectMake(0, 5, width, 300);
  519. [imgScroll reset];
  520. // [imgScroll animationDuration:5];
  521. // imgScroll.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.1];
  522. for(int i = 0;i<slide_item_count;i++)
  523. {
  524. NSDictionary * slide_itemjson =view_json[@"stack_contents"][[NSString stringWithFormat:@"item_%d",i]] ;
  525. SliderPage * tempview = [[SliderPage alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, ui_height)];
  526. tempview.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin;
  527. NSString* img_url =nil;
  528. if([slide_itemjson[@"type"] isEqualToString:@"image"])
  529. img_url=[slide_itemjson valueForKey:@"s"];
  530. else
  531. img_url=@"";
  532. tempview.contentMode = UIViewContentModeScaleAspectFit;
  533. tempview.img_url = img_url;
  534. // tempview.url =@"";
  535. // tempview.action_type = ;
  536. // tempview.params = ;
  537. [imgScroll addPage:tempview];
  538. }
  539. [imgScroll setTotalPagesCount];
  540. imgScroll.TapActionBlock = ^(NSInteger pageIndex){
  541. DebugLog(@"点击了第%ld个",(long)pageIndex);
  542. NSDictionary * item_json =[view_json objectForKey:[NSString stringWithFormat:@"item_%ld",pageIndex] ];
  543. NSString* action = [item_json valueForKeyPath:@"action"];
  544. };
  545. //
  546. slidecell.imgScroll = imgScroll;
  547. // return cell;
  548. [slidecell.contentView addSubview:imgScroll];
  549. return slidecell;
  550. }
  551. else
  552. {
  553. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  554. NSString *CellIdentifier = @"DetailBasicCell0";
  555. DetailBasicCell0 *basiccell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  556. basiccell.celldelegate=self;
  557. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  558. NSMutableDictionary* dict = [[defaults dictionaryForKey:@"local_list"] mutableCopy];
  559. // NSMutableArray* arr = [[defaults arrayForKey:@"local_list_idx"] mutableCopy];
  560. if(dict[self.product_id])
  561. {
  562. UIImage* img = basiccell.btnAddList.imageView.image;
  563. UIImage* img1 = [img imageWithTintColor:UIColor.redColor];
  564. basiccell.btnAddList.imageView.image = [img imageWithTintColor:UIColor.redColor];
  565. // basiccell.btnAddList.imageView.tintColor= UIColor.redColor;
  566. [basiccell.btnAddList setTitle:@"Remove from list" forState:UIControlStateNormal];
  567. // [basiccell.btnAddList setBackgroundColor:UIColor.redColor];
  568. }
  569. else
  570. {
  571. UIImage* img =basiccell.btnAddList.imageView.image;;
  572. basiccell.btnAddList.imageView.image = [img imageWithTintColor:UIColor.blackColor];
  573. // basiccell.btnAddList.imageView.tintColor= UIColor.blackColor;
  574. [basiccell.btnAddList setTitle:@"Add to list" forState:UIControlStateNormal];
  575. // [basiccell.btnAddList setBackgroundColor:UIColor.blackColor];
  576. }
  577. basiccell.descriptionRTLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  578. basiccell.labelModel.text =[section_json valueForKey:@"model_name"];
  579. self.selector = [section_json objectForKey:@"selector"];
  580. NSString* defaultimg = nil;
  581. if(self.selector!=nil)
  582. {
  583. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  584. basiccell.imageviewSelector.image = [UIImage imageNamed:@"loading_s"];
  585. for(int i=0;i<selector_count;i++)
  586. {
  587. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  588. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  589. {
  590. NSString* selectstr=[NSString stringWithFormat:@"%@: %@",[self.selector valueForKey:@"name"],[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"]];
  591. if([[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"] ==nil)
  592. selectstr=[NSString stringWithFormat:@"%@:",[self.selector valueForKey:@"name"]];
  593. basiccell.labelSelector.text = selectstr;
  594. NSString* img_url = [[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"pic_url"];
  595. if(i==0)
  596. defaultimg = img_url;
  597. NSString* file_name=[img_url lastPathComponent];
  598. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  599. if(img_data!=nil)
  600. {
  601. dispatch_async(dispatch_get_main_queue(), ^{
  602. UIImage * img =[UIImage imageWithData:img_data];
  603. basiccell.imageviewSelector.image=img;
  604. });
  605. }
  606. else
  607. {
  608. NSData* downloadimg_data = nil;
  609. // BOOL offline = NO;
  610. //#ifdef OFFLINE_MODE
  611. // offline = appDelegate.offline_mode;
  612. //#endif
  613. // if (!offline) {
  614. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  615. // }
  616. dispatch_async(dispatch_get_main_queue(), ^{
  617. if(downloadimg_data!=nil)
  618. {
  619. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  620. UIImage * img =[UIImage imageWithData:downloadimg_data];
  621. basiccell.imageviewSelector.image=img;
  622. }
  623. else
  624. basiccell.imageviewSelector.image = [UIImage imageNamed:@"notfound_s"];
  625. });
  626. }
  627. }
  628. }
  629. }
  630. NSDictionary* property_json = [section_json objectForKey:@"property"];
  631. // int pcount = [[property_json valueForKey:@"count"]intValue];
  632. basiccell.labelProperty.text=[[property_json objectForKey:@"item_0"] valueForKey:@"key"];
  633. basiccell.labelPropertyVal.text=[[property_json objectForKey:@"item_0"] valueForKey:@"val"];
  634. basiccell.WatchlistBlock = ^(void){
  635. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  636. NSMutableDictionary* dict = [[defaults dictionaryForKey:@"local_list"] mutableCopy];
  637. NSMutableArray* arr = [[defaults arrayForKey:@"local_list_idx"] mutableCopy];
  638. if(dict ==nil)
  639. dict = [NSMutableDictionary new];
  640. if(arr ==nil)
  641. arr = [NSMutableArray new];
  642. if(dict[self.product_id])
  643. {
  644. [dict removeObjectForKey:self.product_id];
  645. [arr removeObject:self.product_id];
  646. }
  647. else
  648. {
  649. NSMutableDictionary* obj = [NSMutableDictionary new];
  650. obj[@"img_url"]=defaultimg;
  651. obj[@"description"]=[section_json valueForKey:@"model_descrition"];
  652. obj[@"model_name"]=self.model_name;
  653. obj[@"catalog_id"]=self.category_id;
  654. dict[self.product_id]= obj;
  655. [arr insertObject:self.product_id atIndex:0];
  656. }
  657. // [arr insertObject:obj atIndex:0];
  658. [defaults setObject:dict forKey:@"local_list"];
  659. [defaults setObject:arr forKey:@"local_list_idx"];
  660. [defaults synchronize];
  661. [self.tableView reloadData];
  662. [TabViewController Notify:@"LocalListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  663. // self.add_wish=true;
  664. // CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  665. // rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  666. // CGRect headRect = imageView.frame;
  667. // headRect.origin.y = rect.origin.y+headRect.origin.y;
  668. // [self startAnimationWithRect:headRect ImageView:imageView];
  669. };
  670. return basiccell;
  671. }
  672. else
  673. {
  674. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  675. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  676. NSString *CellIdentifier = @"DetailInfoCell";
  677. NSString* type=[section_json valueForKey:@"type"] ;
  678. if([type isEqualToString:@"kv"])
  679. {
  680. float width = tableView.frame.size.width;
  681. width-=CELL_MARGIN*2;
  682. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  683. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  684. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  685. NSString* key =[item_json valueForKey:@"key"] ;
  686. NSString* val=[item_json valueForKey:@"val"] ;
  687. NSString* type=[item_json valueForKey:@"type"] ;
  688. if([val isEqual:[NSNull null]])
  689. val=@"";
  690. if(val==nil)
  691. val=@"";
  692. if([val isEqualToString:@"null"])
  693. val=@"";
  694. CGRect frame;
  695. frame.size = constraintval;
  696. frame.origin.x=0;
  697. frame.origin.y=0;
  698. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  699. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  700. rtlabel.font=[UIFont systemFontOfSize:RTLABEL_FONT_SIZE];
  701. // rtlabel.lineSpacing = 20.0;
  702. [rtlabel setText: val];
  703. CGSize sizeval=rtlabel.optimumSize;
  704. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  705. frame.size =constraintkey;
  706. UILabel* label = [[UILabel alloc] initWithFrame:frame];
  707. [label setLineBreakMode:NSLineBreakByWordWrapping];
  708. label.font=[UIFont systemFontOfSize:RTLABEL_FONT_SIZE];
  709. label.text = key;
  710. CGSize sizekey =[label sizeThatFits:label.frame.size]; // [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:RTLABEL_FONT_SIZE] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  711. float height = MAX(sizekey.height,sizeval.height);
  712. height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  713. sizekey.height = height;
  714. sizekey.width = constraintkey.width;
  715. // sizeval.height = height;
  716. sizeval.width =constraintval.width;
  717. // NSString *CellIdentifier = @"detail_item_kv";
  718. DetailKVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  719. if(cell==nil)
  720. DebugLog(@"cell is nil.........................");
  721. // cell.layer.bo
  722. cell.layer.borderWidth = 0.5;
  723. cell.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  724. // self.btnSelector.layer.cornerRadius = 0;
  725. CGRect framekey = cell.keyLabel.frame;
  726. framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  727. framekey.origin.y=LINE_WIDTH/2;
  728. framekey.size = sizekey;
  729. cell.keyLabel.frame = framekey;
  730. cell.keyLabel.text=key;
  731. cell.keyLabel.font = [UIFont systemFontOfSize:RTLABEL_FONT_SIZE];
  732. CGRect frameval = cell.valLabel.frame;
  733. frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  734. frameval.origin.y=0;
  735. frameval.size = sizeval;
  736. cell.valLabel.frame = frameval;
  737. // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  738. cell.valLabel.text= val;
  739. cell.valLabel.font = [UIFont systemFontOfSize:RTLABEL_FONT_SIZE];
  740. CGPoint rcenter;
  741. rcenter.x = width * 0.4+width * 0.6/2;
  742. rcenter.y = (height+LINE_WIDTH) /2;
  743. cell.valLabel.center=rcenter;
  744. // cell.valLabel.backgroundColor =[UIColor redColor];
  745. // cell.contentView.superview.backgroundColor = [UIColor clearColor];
  746. // cell.backgroundColor = [UIColor whiteColor];
  747. UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  748. lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  749. lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  750. lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  751. [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  752. cell.backgroundColor = [UIColor whiteColor];
  753. return cell;
  754. }
  755. // else if ([type isEqualToString:@"img"])
  756. // {
  757. // DetailImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailImageCell" forIndexPath:indexPath];
  758. //
  759. // int img_count = [[item_json valueForKey:@"count"] intValue];
  760. // double posy = 0;
  761. // for(int j=0;j<img_count;j++)
  762. // {
  763. // NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  764. // float width = [[img_json valueForKey:@"width"]floatValue];
  765. // float height = [[img_json valueForKey:@"height"]floatValue];
  766. // //
  767. // UIImageView * imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, posy, tableView.bounds.size.width , height*tableView.bounds.size.width / width)];
  768. // imgview.contentMode = UIViewContentModeScaleAspectFit;
  769. //
  770. // NSString* img_url = [img_json valueForKey:@"img_url"];
  771. // posy+=height*tableView.bounds.size.width / width;
  772. // NSString* file_name=[img_url lastPathComponent];
  773. // NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  774. // if(img_data!=nil)
  775. // {
  776. //
  777. // UIImage * img =[UIImage imageWithData:img_data];
  778. // imgview.image = img;
  779. // [cell addSubview:imgview];
  780. // }
  781. // else
  782. // {
  783. //
  784. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  785. //
  786. // NSData* downloadimg_data = nil;
  787. //// BOOL offline = NO;
  788. ////#ifdef OFFLINE_MODE
  789. //// offline = appDelegate.offline_mode;
  790. ////#endif
  791. //// if (!offline) {
  792. // downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  793. //// }
  794. // dispatch_async(dispatch_get_main_queue(), ^{
  795. //
  796. //
  797. //
  798. // if(downloadimg_data!=nil)
  799. // {
  800. //
  801. // [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  802. //
  803. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  804. // imgview.image = img;
  805. // [cell addSubview:imgview];
  806. // }
  807. // else
  808. // {
  809. // imgview.image = [UIImage imageNamed:@"notfound_l"];
  810. //
  811. // [cell addSubview:imgview];
  812. //
  813. // }
  814. // });
  815. // });
  816. //
  817. //
  818. // }
  819. //
  820. //
  821. // }
  822. // cell.backgroundColor = [UIColor whiteColor];
  823. // return cell;
  824. // }
  825. else if ([type isEqualToString:@"content"])
  826. {
  827. NSString *CellIdentifier = @"DetailTopicCell";
  828. NSString* data=[section_json valueForKey:@"data"] ;
  829. if([data isEqualToString:@"local"])
  830. {
  831. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  832. [appDelegate.recent_model addEntriesFromDictionary:section_json];
  833. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  834. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  835. cell.itemdelegate = self;
  836. cell.related_data = appDelegate.recent_model;
  837. [cell.topicCollectionView reloadData];
  838. cell.backgroundColor = [UIColor whiteColor];
  839. return cell;
  840. }
  841. else
  842. {
  843. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  844. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  845. cell.itemdelegate = self;
  846. cell.related_data = section_json;
  847. [cell.topicCollectionView reloadData];
  848. cell.backgroundColor = [UIColor whiteColor];
  849. return cell;
  850. }
  851. }
  852. // return nil;
  853. }
  854. static NSString *CellIdentifier = @"Cell";
  855. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  856. if (!cell) {
  857. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  858. }
  859. return cell;
  860. }
  861. //{
  862. // // DebugLog(@"cellForRowAtIndexPath");
  863. //
  864. //
  865. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  866. //
  867. //
  868. // // NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  869. // // if(related_json==nil)
  870. // else
  871. // {
  872. //
  873. //
  874. //
  875. //
  876. // NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  877. //
  878. // NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  879. //
  880. // NSString *CellIdentifier = @"DetailInfoCell";
  881. //
  882. // NSString* type=[section_json valueForKey:@"type"] ;
  883. //
  884. // if([type isEqualToString:@"kv"])
  885. // {
  886. // float width = tableView.frame.size.width;
  887. //
  888. // width-=CELL_MARGIN*2;
  889. // CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  890. // CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  891. // // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  892. // NSString* key =[item_json valueForKey:@"key"] ;
  893. //
  894. // NSString* val=[item_json valueForKey:@"val"] ;
  895. //
  896. //
  897. // NSString* type=[item_json valueForKey:@"type"] ;
  898. //
  899. // if([type isEqualToString:@"price"])
  900. // {
  901. //
  902. // if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  903. // {
  904. //
  905. // }
  906. // else
  907. // {
  908. // val=nil;
  909. // }
  910. // }
  911. //
  912. //
  913. // if([val isEqual:[NSNull null]])
  914. // val=@"";
  915. // if(val==nil)
  916. // val=@"";
  917. // if([val isEqualToString:@"null"])
  918. // val=@"";
  919. //
  920. //
  921. //
  922. //
  923. // CGRect frame;
  924. // frame.size = constraintval;
  925. // frame.origin.x=0;
  926. // frame.origin.y=0;
  927. // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  928. // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  929. // // rtlabel.lineSpacing = 20.0;
  930. // [rtlabel setText: val];
  931. // CGSize sizeval=rtlabel.optimumSize;
  932. //// CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  933. //
  934. // CGSize sizekey = [RAUtils sizeWithFont:key font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  935. //
  936. // float height = MAX(sizekey.height,sizeval.height);
  937. // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  938. // sizekey.height = height;
  939. // sizekey.width = constraintkey.width;
  940. // // sizeval.height = height;
  941. // sizeval.width =constraintval.width;
  942. //
  943. // // NSString *CellIdentifier = @"detail_item_kv";
  944. // DetailKVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  945. // if(cell==nil)
  946. // DebugLog(@"cell is nil.........................");
  947. //
  948. //
  949. //
  950. //
  951. // CGRect framekey = cell.keyLabel.frame;
  952. // framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  953. // framekey.origin.y=LINE_WIDTH;
  954. // framekey.size = sizekey;
  955. // cell.keyLabel.frame = framekey;
  956. // cell.keyLabel.text=key;
  957. // CGRect frameval = cell.valLabel.frame;
  958. // frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  959. // frameval.origin.y=LINE_WIDTH;
  960. // frameval.size = sizeval;
  961. // cell.valLabel.frame = frameval;
  962. // // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  963. // cell.valLabel.text= val;
  964. // CGPoint rcenter;
  965. // rcenter.x = width * 0.4+width * 0.6/2;
  966. // rcenter.y = height /2;
  967. // cell.valLabel.center=rcenter;
  968. // // cell.valLabel.backgroundColor =[UIColor redColor];
  969. //
  970. // // cell.contentView.superview.backgroundColor = [UIColor clearColor];
  971. // // cell.backgroundColor = [UIColor whiteColor];
  972. // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  973. // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  974. // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  975. // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  976. // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  977. //
  978. //
  979. // cell.backgroundColor = [UIColor whiteColor];
  980. // return cell;
  981. // }
  982. // else if ([type isEqualToString:@"img"])
  983. // {
  984. // DetailImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailImageCell" forIndexPath:indexPath];
  985. //
  986. // int img_count = [[item_json valueForKey:@"count"] intValue];
  987. // double posy = 0;
  988. // for(int j=0;j<img_count;j++)
  989. // {
  990. // NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  991. // float width = [[img_json valueForKey:@"width"]floatValue];
  992. // float height = [[img_json valueForKey:@"height"]floatValue];
  993. // //
  994. // UIImageView * imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, posy, tableView.bounds.size.width , height*tableView.bounds.size.width / width)];
  995. // imgview.contentMode = UIViewContentModeScaleAspectFit;
  996. //
  997. // NSString* img_url = [img_json valueForKey:@"img_url"];
  998. // posy+=height*tableView.bounds.size.width / width;
  999. // NSString* file_name=[img_url lastPathComponent];
  1000. // NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  1001. // if(img_data!=nil)
  1002. // {
  1003. //
  1004. // UIImage * img =[UIImage imageWithData:img_data];
  1005. // imgview.image = img;
  1006. // [cell addSubview:imgview];
  1007. // }
  1008. // else
  1009. // {
  1010. //
  1011. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1012. //
  1013. // NSData* downloadimg_data = nil;
  1014. //// BOOL offline = NO;
  1015. ////#ifdef OFFLINE_MODE
  1016. //// offline = appDelegate.offline_mode;
  1017. ////#endif
  1018. //// if (!offline) {
  1019. // downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1020. //// }
  1021. // dispatch_async(dispatch_get_main_queue(), ^{
  1022. //
  1023. //
  1024. //
  1025. // if(downloadimg_data!=nil)
  1026. // {
  1027. //
  1028. // [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1029. //
  1030. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  1031. // imgview.image = img;
  1032. // [cell addSubview:imgview];
  1033. // }
  1034. // else
  1035. // {
  1036. // imgview.image = [UIImage imageNamed:@"notfound_l"];
  1037. //
  1038. // [cell addSubview:imgview];
  1039. //
  1040. // }
  1041. // });
  1042. // });
  1043. //
  1044. //
  1045. // }
  1046. //
  1047. //
  1048. // }
  1049. // cell.backgroundColor = [UIColor whiteColor];
  1050. // return cell;
  1051. // }
  1052. // else if ([type isEqualToString:@"content"])
  1053. // {
  1054. //
  1055. // NSString *CellIdentifier = @"DetailTopicCell";
  1056. //
  1057. // NSString* data=[section_json valueForKey:@"data"] ;
  1058. // if([data isEqualToString:@"local"])
  1059. // {
  1060. // [appDelegate.recent_model addEntriesFromDictionary:section_json];
  1061. //
  1062. // // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1063. // DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1064. // cell.itemdelegate = self;
  1065. // cell.related_data = appDelegate.recent_model;
  1066. // [cell.topicCollectionView reloadData];
  1067. //
  1068. // cell.backgroundColor = [UIColor whiteColor];
  1069. // return cell;
  1070. //
  1071. // }
  1072. // else
  1073. // {
  1074. //
  1075. // // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1076. // DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1077. // cell.itemdelegate = self;
  1078. // cell.related_data = section_json;
  1079. // [cell.topicCollectionView reloadData];
  1080. //
  1081. // cell.backgroundColor = [UIColor whiteColor];
  1082. // return cell;
  1083. // }
  1084. //
  1085. // }
  1086. // return nil;
  1087. //
  1088. // }
  1089. //
  1090. //
  1091. //}
  1092. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
  1093. {
  1094. if([cell isKindOfClass:[DetailSlideImageCell class]])
  1095. {
  1096. DetailSlideImageCell* slidecell=(DetailSlideImageCell*)cell;
  1097. [slidecell.imgScroll stopTimmer];
  1098. }
  1099. }
  1100. #pragma mark - Basic0 cell delegate
  1101. -(void) SelectorClicked:(UIView*) trigger
  1102. {
  1103. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  1104. int current_sel = -1;
  1105. for(int i=0;i<selector_count;i++)
  1106. {
  1107. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  1108. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  1109. {
  1110. current_sel = i;
  1111. }
  1112. }
  1113. ColorSelectViewController* colorSelectVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ColorSelectViewController"];
  1114. colorSelectVC.data = self.selector;
  1115. colorSelectVC.selected =current_sel;
  1116. __block CatalogModelDetailViewController *brself= self;
  1117. colorSelectVC.selectChanged =^(long index){
  1118. NSDictionary* item = [brself.selector objectForKey:[NSString stringWithFormat:@"item_%ld",index]];
  1119. NSDictionary* params = [item objectForKey:@"params"];
  1120. NSString* detail_id=[[[params objectForKey:@"param_0"] valueForKey:@"val" ] stringValue];
  1121. brself.product_id = detail_id;
  1122. brself.use_model_name = false;
  1123. [brself reload];
  1124. };
  1125. //
  1126. // UIModalPresentationFullScreen = 0,
  1127. // UIModalPresentationPageSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
  1128. // UIModalPresentationFormSheet API_AVAILABLE(ios(3.2)) API_UNAVAILABLE(tvos),
  1129. // UIModalPresentationCurrentContext API_AVAILABLE(ios(3.2)),
  1130. // UIModalPresentationCustom API_AVAILABLE(ios(7.0)),
  1131. // UIModalPresentationOverFullScreen API_AVAILABLE(ios(8.0)),
  1132. // UIModalPresentationOverCurrentContext API_AVAILABLE(ios(8.0)),
  1133. // UIModalPresentationPopover API_AVAILABLE(ios(8.0)) API_UNAVAILABLE(tvos),
  1134. // UIModalPresentationBlurOverFullScreen API_AVAILABLE(tvos(11.0)) API_UNAVAILABLE(ios) API_UNAVAILABLE(watchos),
  1135. // UIModalPresentationNone API_AVAILABLE(ios(7.0)) = -1,
  1136. // UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2,
  1137. CustomPresentationController *presentationController NS_VALID_UNTIL_END_OF_SCOPE;
  1138. presentationController = [[CustomPresentationController alloc] initWithPresentedViewController:colorSelectVC presentingViewController:self];
  1139. colorSelectVC.transitioningDelegate = presentationController;
  1140. [self presentViewController:colorSelectVC animated:YES completion:NULL];
  1141. //
  1142. //
  1143. // colorSelectVC.modalPresentationStyle = UIModalPresentationFormSheet;
  1144. //
  1145. //
  1146. //
  1147. //
  1148. //// if (self = [super initWithPresentedViewController:presentedViewController presentingViewController:presentingViewController]) {
  1149. //// _controllerHeight = presentedViewController.controllerHeight == 0 ? [UIScreen mainScreen].bounds.size.height : presentedViewController.controllerHeight;
  1150. //// }
  1151. //
  1152. // [self presentViewController:colorSelectVC animated:YES completion:^{
  1153. //// CGRect frame = self.view.frame;
  1154. //// colorSelectVC.view.superview.frame =CGRectMake(frame.origin.x, frame.origin.y+20, frame.size.width, frame.size.height*0.6);
  1155. //
  1156. // colorSelectVC.preferredContentSize = CGSizeMake(200,200);
  1157. // }];
  1158. //
  1159. //
  1160. //
  1161. //
  1162. //
  1163. // if(self.dropDown == nil)
  1164. // {
  1165. // CGFloat height = 70*selector_count;
  1166. // if (selector_count > 4) {
  1167. // height = 70 * 4.5;
  1168. // }
  1169. // self.dropDown =[[NIDropDown alloc] showDropDown:trigger.superview based:(id)trigger height:height data:self.selector direction:@"up" current_sel:current_sel];
  1170. //
  1171. //
  1172. // //Capturing strongly warring;
  1173. // __block CatalogModelDetailViewController *brself= self;
  1174. // self.dropDown.dropDownTouchOutsideBlk = ^{
  1175. // [brself.dropDown hideDropDown:(id)trigger];
  1176. // brself.dropDown= nil;
  1177. // };
  1178. //
  1179. //
  1180. // }
  1181. // else {
  1182. // [self.dropDown hideDropDown:(id)trigger];
  1183. // self.dropDown= nil;
  1184. // }
  1185. return;
  1186. }
  1187. #pragma mark - Topic cell delegate
  1188. -(void) TopicItemClicked:(NSString*) product_id category:(NSString*) category
  1189. {
  1190. if(true)
  1191. {
  1192. CatalogModelDetailViewController* dvc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CatalogModelDetailViewController" ];
  1193. // dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
  1194. // {
  1195. //
  1196. //
  1197. // NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy];
  1198. //
  1199. // NSMutableDictionary* item = [[items objectForKey:[NSString stringWithFormat:@"item_%ld",index]] mutableCopy];
  1200. // if(add_cart)
  1201. // item[@"cart_exists"]=@"true";
  1202. // if(add_wish)
  1203. // item[@"wish_exists"]=@"true";
  1204. // items[[NSString stringWithFormat:@"item_%ld",index]] = item;
  1205. // self.category_data[@"items"]=items;
  1206. //
  1207. // [self.collectionview reloadData];
  1208. // };
  1209. dvc.product_id = product_id;
  1210. dvc.category_id=category;
  1211. dvc.ispush = true;
  1212. // dvc.model_name = name;
  1213. [dvc reload];
  1214. [self.navigationController pushViewController:dvc animated:true];
  1215. return;
  1216. }
  1217. else
  1218. {
  1219. // self.model_name = value;
  1220. self.product_id = product_id;
  1221. self.category_id=category;
  1222. [self reload];
  1223. DebugLog(@"color selected");
  1224. }
  1225. }
  1226. @end