DetailViewController.m 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104
  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. #import "DefaultTableHeaderView.h"
  20. #import "DefaultAppearance.h"
  21. #import "JKMessageBoxController.h"
  22. #import "CartUtils.h"
  23. #import "ImageUtils.h"
  24. #import "PDFViewController.h"
  25. #define DEF_CELL_HEIGHT 44
  26. #define DEF_TABLE_HEIGHT 44
  27. #define LINE_WIDTH 0
  28. #define CELL_MARGIN 0
  29. #define LABEL_MARGIN 10
  30. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
  31. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
  32. #define NavColor ([UIColor colorWithRed:237/255.0 green:20/255.0f blue:91/255.0f alpha:1.0f])
  33. @interface DetailViewController ()
  34. @property (nonatomic,strong) UIBezierPath *path;
  35. @end
  36. @implementation DetailViewController
  37. {
  38. CALayer *_layer;
  39. }
  40. -(void) reload_container_getdata:(bool) update_data
  41. {
  42. [super reload_container_getdata:update_data];
  43. if(update_data)
  44. [self reload];
  45. else
  46. {
  47. [self.detailTable reloadData];
  48. // [self refresh_total];
  49. }
  50. }
  51. -(void)manually_refresh
  52. {
  53. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
  54. if(self.isrefreshing)
  55. {
  56. [reF endRefreshing];
  57. return;
  58. }
  59. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  60. if ([self respondsToSelector:@selector(ReloadData)])
  61. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  62. // DebugLog(@"refresh!!!!!!!!");
  63. }
  64. -(void) ReloadData
  65. {
  66. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:300];
  67. [reF endRefreshing];
  68. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  69. [self reload];
  70. }
  71. -(void) reload
  72. {
  73. dispatch_async(dispatch_get_main_queue(), ^{
  74. if(self.isrefreshing)
  75. return;
  76. self.label_net_err.hidden=true;
  77. self.detailTable.hidden = true;
  78. self.isrefreshing=true;
  79. self.mum.center = self.view.center;
  80. self.mum.hidden = false;
  81. [self.mum startAnimating];
  82. //self.detailTable.hidden=true;
  83. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  84. 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];
  85. dispatch_async(dispatch_get_main_queue(), ^{
  86. [self.mum stopAnimating];
  87. if([[detail_json valueForKey:@"result"] intValue]==2)
  88. {
  89. self.detail_data = [detail_json mutableCopy];
  90. self.product_id = [NSString stringWithFormat:@"%d",[[detail_json valueForKey:@"product_id"] intValue] ];
  91. NSMutableDictionary* imgsection = [[detail_json objectForKey:@"img_section"] mutableCopy];
  92. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  93. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/true)
  94. self.quantity =[[imgsection valueForKey:@"stockUom"] intValue];
  95. else
  96. self.quantity =1;
  97. if(self.quantity==0)
  98. self.quantity=1;
  99. self.step=self.quantity;
  100. [self.detailTable reloadData];
  101. //
  102. self.detailTable.hidden = false;
  103. NSString* model_name = self.detail_data[@"img_section"][@"model_name"];
  104. NSString* img_url = self.detail_data[@"img_section"][@"model_s_img"];
  105. NSMutableDictionary* images=[self.detail_data[@"img_section"][@"images"] mutableCopy];
  106. NSMutableDictionary* videos=[self.detail_data[@"img_section"][@"videos"] mutableCopy];
  107. NSMutableDictionary* contents = [NSMutableDictionary new];
  108. int count = 0;
  109. {
  110. for(int ic=0;ic<[images[@"img_count"] intValue];ic++)
  111. {
  112. NSMutableDictionary* item = [images[[NSString stringWithFormat:@"img_%d",ic]] mutableCopy];
  113. item[@"type"]=@"image";
  114. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  115. count++;
  116. }
  117. NSString* qrpath = [ImageUtils generateQRCodeFile:model_name width:350 height:350];
  118. // UIImage* qrimg=[QRCodeGenerator qrImageForString:model_name imageSize:350];
  119. if(qrpath!=nil)
  120. {
  121. NSMutableDictionary* item =[@{@"type":@"image",@"is_localfile":@(true),@"l":qrpath,@"s":qrpath} mutableCopy];
  122. contents[[NSString stringWithFormat:@"item_%d",count]]=item ;
  123. count++;
  124. }
  125. }
  126. {
  127. for(int ic=0;ic<[videos[@"count"] intValue];ic++)
  128. {
  129. NSString* videocode = videos[[NSString stringWithFormat:@"video_%d",ic]];
  130. NSMutableDictionary* item =[@{@"type":@"video",@"code":videocode} mutableCopy];
  131. contents[[NSString stringWithFormat:@"item_%d",count]]=item;
  132. count++;
  133. }
  134. }
  135. contents[@"count"]=@(count);
  136. imgsection[@"stack_contents"]=contents;
  137. self.detail_data[@"img_section"] = imgsection;
  138. // self.detail_data[@"img_section"][@"stack_contents"]=contents;
  139. NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
  140. [item setValue:self.product_id forKey:@"product_id"];
  141. [item setValue:self.category_id forKey:@"category"];
  142. [item setValue:model_name forKey:@"fash_name"];
  143. [item setValue:img_url forKey:@"picture_path"];
  144. [CartUtils add_recent_model:item];
  145. NSUInteger ii[2] = {0,0};
  146. [self.detailTable scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndexes:ii length:2] atScrollPosition:UITableViewScrollPositionTop animated:YES];
  147. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  148. // int count=[appDelegate.recent_model[@"count"] intValue];
  149. // bool bexist = false;
  150. // for(int i=0;i<count;i++)
  151. // {
  152. // NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
  153. // if([mitem[@"product_id"] isEqualToString:self.product_id])
  154. // {
  155. // bexist=true;
  156. // break;
  157. // }
  158. // }
  159. //
  160. // if(!bexist)
  161. // {
  162. // [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
  163. // appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
  164. // }
  165. }
  166. else
  167. if([[detail_json valueForKey:@"result"] intValue]==RESULT_NET_ERROR)
  168. {
  169. self.detailTable.hidden = true;
  170. self.label_net_err.hidden=false;
  171. }
  172. else if([[detail_json valueForKey:@"result"] intValue]==RESULT_NO_MODEL)
  173. {
  174. self.detailTable.hidden = true;
  175. [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  176. if(self.ispush)
  177. [ self.navigationController popViewControllerAnimated:true];
  178. }
  179. else
  180. {
  181. [RAUtils message_alert:[detail_json valueForKey:@"err_msg"] title:@"Model Detail"/*@"Loading Model Detail Failed."*/ controller:self] ;
  182. }
  183. self.isrefreshing=false;
  184. });
  185. });
  186. });
  187. }
  188. - (void)onBackClick:(UIButton *)sender {
  189. if(self.OnBack)
  190. {
  191. self.OnBack(self.add_cart,self.add_wish,self.update_data);
  192. }
  193. [self.navigationController popViewControllerAnimated:(false)];
  194. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  195. // ;
  196. // }];
  197. }
  198. - (void)viewDidLoad {
  199. [super viewDidLoad];
  200. [self registeObserver];
  201. self.refresh_type = REFRESH_VIEW;
  202. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  203. style:UIBarButtonItemStylePlain
  204. target:self
  205. action:@selector( onBackClick:)];
  206. self.navigationItem.leftBarButtonItem = backButton;
  207. // self.detailTable.style = UITableViewStylePlain;
  208. self.edgesForExtendedLayout = UIRectEdgeNone;
  209. if(self.ispush)
  210. {
  211. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.000001)];
  212. [line setBackgroundColor:[UIColor clearColor]];
  213. self.detailTable.tableHeaderView = line;
  214. }
  215. //
  216. //
  217. // self.automaticallyAdjustsScrollViewInsets = false;
  218. self.step=1;
  219. self.quantity=1;
  220. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  221. ref.tag = 300 ;
  222. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  223. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  224. // ref.hidden = true;
  225. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  226. [self.detailTable addSubview:ref];
  227. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  228. self.label_net_err.layer.borderWidth = 2.0;
  229. self.label_net_err.layer.cornerRadius=15;
  230. self.label_net_err.layer.masksToBounds=true;
  231. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  232. // tap.minimumPressDuration = 0.8; //定义按的时间
  233. [self.label_net_err addGestureRecognizer:tap];
  234. // Do any additional setup after loading the view.
  235. }
  236. - (void)viewWillAppear:(BOOL)animated
  237. {
  238. if(self.ispush)
  239. {
  240. [super viewWillAppear:animated];
  241. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  242. }
  243. }
  244. - (void) viewWillDisappear:(BOOL)animated
  245. {
  246. [super viewWillDisappear:animated];
  247. if(self.ispush)
  248. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  249. }
  250. - (void)didReceiveMemoryWarning {
  251. [super didReceiveMemoryWarning];
  252. // Dispose of any resources that can be recreated.
  253. }
  254. /*
  255. #pragma mark - Navigation
  256. // In a storyboard-based application, you will often want to do a little preparation before navigation
  257. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  258. // Get the new view controller using [segue destinationViewController].
  259. // Pass the selected object to the new view controller.
  260. }
  261. */
  262. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  263. //将page2设定成Storyboard Segue的目标UIViewController
  264. id page2 = segue.destinationViewController;
  265. //将值透过Storyboard Segue带给页面2的string变数
  266. [page2 setValue: _selector forKey:@"selector"];
  267. [page2 setValue: self forKey:@"selectordelegate"];
  268. }
  269. //- (IBAction)OnAddPortfolio:(id)sender {
  270. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  271. ////
  272. //// [appDelegate test_onDecodedDataResult:@"371252"];
  273. //// [self onDecodedData:@"3712524-235"];
  274. // return;
  275. //}
  276. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  277. {
  278. // [self.detailTable reloadData];
  279. // return;
  280. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  281. // NSMutableIndexSet *sectionToReload = [[NSMutableIndexSet alloc] init];
  282. // int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
  283. //
  284. // for(int i=0;i<section_count;i++)
  285. // {
  286. // NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)i]];
  287. //
  288. //
  289. //
  290. // NSString* type=[section_json valueForKey:@"type"] ;
  291. //
  292. // if([type isEqualToString:@"kv"])
  293. // {
  294. //
  295. // [sectionToReload addIndex:i+1];
  296. // }
  297. // }
  298. //
  299. //
  300. // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationNone];
  301. //
  302. [self.detailTable reloadData];
  303. }
  304. #pragma mark - Selector delegate
  305. -(void) selected:(NSString*) detail_id category:(NSString*) category
  306. {
  307. self.product_id = detail_id;
  308. self.use_model_name = false;
  309. [self reload];
  310. DebugLog(@"color selected");
  311. }
  312. #pragma mark - Header cell delegate
  313. -(void) SelectorClicked:(UIView*) trigger
  314. {
  315. // int selcount = [[self.selector valueForKey:@"count"] intValue];
  316. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  317. int current_sel = -1;
  318. for(int i=0;i<selector_count;i++)
  319. {
  320. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  321. // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
  322. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  323. {
  324. current_sel = i;
  325. }
  326. }
  327. // NSArray * arr = [[NSArray alloc] init];
  328. // arr = [NSArray arrayWithObjects:@"Hello 0", @"Hello 1", @"Hello 2", @"Hello 3", @"Hello 4", @"Hello 5", @"Hello 6", @"Hello 7", @"Hello 8", @"Hello 9",nil];
  329. // NSArray * arrImage = [[NSArray alloc] init];
  330. // 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];
  331. if(self.dropDown == nil)
  332. {
  333. CGFloat height = 70*selector_count;
  334. self.dropDown =[[NIDropDown alloc] showDropDown:self.detailTable based:(id)trigger height:height data:self.selector direction:@"down" current_sel:current_sel];
  335. //Capturing strongly warring;
  336. __block DetailViewController *brself= self;
  337. self.dropDown.selectChanged =^(long index){
  338. NSDictionary* item = [brself.selector objectForKey:[NSString stringWithFormat:@"item_%ld",index]];
  339. NSDictionary* params = [item objectForKey:@"params"];
  340. NSString* detail_id=[[[params objectForKey:@"param_0"] valueForKey:@"val" ] stringValue];
  341. brself.product_id = detail_id;
  342. brself.use_model_name = false;
  343. [brself reload];
  344. // DebugLog(@"color selected");
  345. brself.dropDown = nil;
  346. };
  347. //[[NIDropDown alloc]showDropDown:(id)trigger :&f :arr :arrImage :@"down"];
  348. // self.dropDown.delegate = self;
  349. }
  350. else {
  351. [self.dropDown hideDropDown:(id)trigger];
  352. self.dropDown= nil;
  353. // [self rel];
  354. }
  355. return;
  356. /*
  357. // CGRect rect = trigger.frame;
  358. //
  359. // DebugLog(@"%@",NSStringFromCGRect(rect));
  360. //
  361. //
  362. //
  363. // DebugLog(@"%@",NSStringFromCGPoint (trigger.center));
  364. //
  365. //
  366. // CGRect new=[trigger convertRect:rect toView:self.view];
  367. //
  368. // DebugLog(@"convert %@",NSStringFromCGRect(new));
  369. //
  370. CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
  371. CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
  372. DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
  373. SelectorViewController *menu = [ self.storyboard instantiateViewControllerWithIdentifier:@"SelectorViewController"];
  374. NSString * name = [self.selector valueForKey:@"name"];
  375. menu.title=name;
  376. menu.selector = self.selector;
  377. menu.selectordelegate = self;
  378. // 1.创建一个UIPopover
  379. UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
  380. // 2.设置尺寸
  381. // popover.popoverContentSize = CGSizeMake(320, 44 * 5);
  382. // 3.从哪里显示出来 --> 指向item
  383. [popover presentPopoverFromRect:rect1 inView:self.view permittedArrowDirections:0 animated:YES];
  384. // [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  385. self.popover = popover;
  386. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  387. */
  388. }
  389. -(void) stepClicked:(int) value
  390. {
  391. self.quantity = value;
  392. }
  393. #pragma mark - Topic cell delegate
  394. -(void) TopicItemClicked:(NSString*) product_id category:(NSString*) category
  395. {
  396. // DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  397. // // dvc
  398. //
  399. //
  400. // dvc.OnBack=^(bool add_cart,bool add_wish,bool update_data)
  401. // {
  402. //
  403. //
  404. // [self reload_container_getdata:false]
  405. // };
  406. //
  407. //
  408. // dvc.product_id=product_id;
  409. // dvc.category_id=category;
  410. // dvc.ispush=true;
  411. // [dvc reload];
  412. // [self.navigationController pushViewController:dvc animated:true];
  413. // self.model_name = value;
  414. self.product_id = product_id;
  415. self.category_id=category;
  416. [self reload];
  417. DebugLog(@"color selected");
  418. }
  419. #pragma mark - Table view data source
  420. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  421. //{
  422. // return 0;
  423. //}
  424. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  425. //{
  426. // return 0;
  427. //}
  428. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  429. //{
  430. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  431. // return myView;
  432. //
  433. //}
  434. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  435. //{
  436. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  437. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  438. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  439. //// titleLabel.textColor=[UIColor whiteColor];
  440. //// titleLabel.backgroundColor = [UIColor clearColor];
  441. //// if(section==0)
  442. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  443. //// else
  444. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  445. //// [titleLabel sizeToFit];
  446. //// [myView addSubview:titleLabel];
  447. ////
  448. // return myView;
  449. //}
  450. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  451. if(section==0)
  452. return nil;
  453. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  454. if(related_json==nil)
  455. {
  456. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  457. return [section_json valueForKey:@"title"] ;
  458. }
  459. else
  460. {
  461. if(section==1)
  462. return @"related model";
  463. else
  464. {
  465. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  466. return [section_json valueForKey:@"title"] ;
  467. }
  468. }
  469. }
  470. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  471. //{
  472. // return 33;
  473. //}
  474. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  475. {
  476. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  477. if(value==nil)
  478. value=@"";
  479. unsigned long color = strtoul([value UTF8String],0,16);
  480. NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
  481. if (sectionTitle == nil) {
  482. return nil;
  483. }
  484. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  485. // myView.backgroundColor = UIColorFromRGB(0x996633);
  486. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  487. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  488. myView.layer.shadowOffset = CGSizeMake(0, 0);
  489. myView.layer.shadowOpacity = 0.5;
  490. myView.layer.shadowRadius = 2.0;
  491. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5.5, 90, 22)];
  492. titlelabel.textColor=UIColorFromRGB(color);
  493. // titlelabel.backgroundColor = [UIColor clearColor];
  494. titlelabel.text=sectionTitle;
  495. [titlelabel sizeToFit];
  496. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(section-1)]];
  497. bool refresh= [[section_json valueForKey:@"partial_refresh"] boolValue] ;
  498. if(refresh)
  499. {
  500. NSString* btntitle=@"Refresh" ;
  501. // NSString* value =[DefaultAppearance get_noneappearance_value:@"DetailTableHeaderView" valuename:@"refresh_button_color"];
  502. //
  503. // if(value==nil)
  504. // value=@"";
  505. // unsigned long color = strtoul([value UTF8String],0,16);
  506. UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-100-15, 0, 100, 33)];
  507. // [btn setTitleColor:UIColorFromRGB(color) forState:UIControlStateNormal];
  508. btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
  509. btn.tag=section;
  510. [btn addTarget:self action:@selector(RefreshSection:) forControlEvents:UIControlEventTouchUpInside];
  511. [btn setTitle:btntitle forState:UIControlStateNormal];
  512. [myView addSubview:btn];
  513. }
  514. [myView addSubview:titlelabel];
  515. return myView;
  516. }
  517. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  518. {
  519. int section_count =[[self.detail_data valueForKey:@"detail_section_count"] intValue];
  520. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  521. if(related_json==nil)
  522. return section_count+1;
  523. else
  524. return section_count+2;
  525. }
  526. //- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
  527. //{
  528. // DebugLog(@"canMoveRowAtIndexPath");
  529. //
  530. // if([tableView numberOfRowsInSection:indexPath.section]>1)
  531. // return true;
  532. // else
  533. // return false;
  534. //}
  535. //- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
  536. //{
  537. // NSMutableArray * from;
  538. // NSMutableArray * to ;
  539. // if(fromIndexPath.section==0)
  540. // from = self.displayfields;
  541. // else
  542. // from = self.hidefields;
  543. // if(toIndexPath.section==0)
  544. // to = self.displayfields;
  545. // else
  546. // to = self.hidefields;
  547. // id content=from[fromIndexPath.row];
  548. // [from removeObjectAtIndex:fromIndexPath.row];
  549. // [to insertObject:content atIndex:toIndexPath.row];
  550. //
  551. // [tableView reloadData];
  552. //
  553. //}
  554. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  555. {
  556. if(section==0)
  557. return 1;
  558. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  559. if(related_json==nil)
  560. {
  561. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-1]];
  562. NSString* type=[section_json valueForKey:@"type"] ;
  563. if([type isEqualToString:@"content"])
  564. return 1;
  565. return [[section_json valueForKey:@"count"] intValue];
  566. }
  567. else
  568. {
  569. if(section==1)
  570. return 1;
  571. else
  572. {
  573. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)section-2]];
  574. NSString* type=[section_json valueForKey:@"type"] ;
  575. if([type isEqualToString:@"content"])
  576. return 1;
  577. return [[section_json valueForKey:@"count"] intValue];
  578. }
  579. }
  580. }
  581. //- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  582. //{
  583. // return UITableViewCellEditingStyleNone;
  584. //}
  585. //- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  586. //{
  587. // //如果两次点击的时间间隔小于1秒,则断定为双击事件
  588. //
  589. // if(tableView.editing==false)
  590. // return;
  591. //
  592. //
  593. // if([tableView numberOfRowsInSection:indexPath.section]<=1)
  594. // return;
  595. // // int between = 1;
  596. // NSUInteger curr = [[NSDate date] timeIntervalSince1970];
  597. //
  598. // if(indexPath.row==self.lasttap.row&&indexPath.section==self.lasttap.section)
  599. // {
  600. // if (curr-self.taptime<1) {
  601. // DebugLog(@"double click!");
  602. // self.lasttap =nil;
  603. //
  604. // NSMutableArray * from;
  605. // NSMutableArray * to ;
  606. // int section;
  607. // if(indexPath.section==0)
  608. // {
  609. // from = self.displayfields;
  610. // to = self.hidefields;
  611. // section = 1;
  612. // }
  613. // else
  614. // {
  615. //
  616. // from = self.hidefields;
  617. // to = self.displayfields;
  618. // section = 0;
  619. // }
  620. // NSIndexPath * toIndexPath = [NSIndexPath indexPathForRow:0 inSection:section];
  621. // // NSIndexPath * headerIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
  622. // // NSIndexPath * headerIndexPath1 = toIndexPath;
  623. //
  624. // id content=from[indexPath.row];
  625. // [tableView beginUpdates];
  626. // [from removeObjectAtIndex:indexPath.row];
  627. // [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  628. //
  629. // [to insertObject:content atIndex:0];
  630. // [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:toIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  631. // [tableView endUpdates];
  632. //
  633. // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  634. // // [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:headerIndexPath1] withRowAnimation:UITableViewRowAnimationFade];
  635. // [tableView reloadData];
  636. //
  637. //
  638. // }
  639. // self.taptime = curr;
  640. //
  641. //
  642. // }
  643. // else
  644. // {
  645. // self.taptime = curr;
  646. // self.lasttap = indexPath;
  647. // }
  648. //}
  649. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  650. {
  651. if(section ==0)
  652. return 0;
  653. else
  654. return 33;
  655. }
  656. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  657. {
  658. if(indexPath.section ==0)
  659. return 550;
  660. NSDictionary* nsdic = self.detail_data;
  661. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  662. if(related_json==nil)
  663. {
  664. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  665. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  666. NSString* type=[section_json valueForKey:@"type"] ;
  667. if([type isEqualToString:@"kv"])
  668. {
  669. float width = tableView.frame.size.width;
  670. width-=CELL_MARGIN*2;
  671. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  672. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  673. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  674. NSString* key =[item_json valueForKey:@"key"] ;
  675. // [cell.keyLabel sizeToFit];
  676. NSString* val=[item_json valueForKey:@"val"] ;
  677. if([val isEqual:[NSNull null]])
  678. val=@"";
  679. if(val==nil)
  680. val=@"";
  681. if([val isEqualToString:@"null"])
  682. val=@"";
  683. CGRect frame;
  684. frame.size = constraintval;
  685. frame.origin.x=0;
  686. frame.origin.y=0;
  687. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  688. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  689. // rtlabel.lineSpacing = 20.0;
  690. [rtlabel setText: val];
  691. CGSize sizeval=rtlabel.optimumSize;
  692. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  693. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  694. float height = MAX(sizekey.height,sizeval.height);
  695. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  696. return height;
  697. }
  698. else if([type isEqualToString:@"img"])
  699. {
  700. int img_count = [[item_json valueForKey:@"count"] intValue];
  701. double ret = 0;
  702. for(int j=0;j<img_count;j++)
  703. {
  704. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  705. float width = [[img_json valueForKey:@"width"]floatValue];
  706. float height = [[img_json valueForKey:@"height"]floatValue];
  707. ret+=height*tableView.bounds.size.width / width;
  708. }
  709. return ret;
  710. }
  711. else if([type isEqualToString:@"content"])
  712. return 270;
  713. return 44;
  714. }
  715. else
  716. {
  717. if(indexPath.section==1)
  718. return 270;
  719. else
  720. {
  721. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-2]];
  722. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  723. NSString* type=[section_json valueForKey:@"type"] ;
  724. if([type isEqualToString:@"kv"])
  725. {
  726. float width = tableView.frame.size.width;
  727. width-=CELL_MARGIN*2;
  728. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  729. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  730. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  731. NSString* key =[item_json valueForKey:@"key"] ;
  732. // [cell.keyLabel sizeToFit];
  733. NSString* val=[item_json valueForKey:@"val"] ;
  734. if([val isEqual:[NSNull null]])
  735. val=@"";
  736. if(val==nil)
  737. val=@"";
  738. if([val isEqualToString:@"null"])
  739. val=@"";
  740. CGRect frame;
  741. frame.size = constraintval;
  742. frame.origin.x=0;
  743. frame.origin.y=0;
  744. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  745. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  746. // rtlabel.lineSpacing = 20.0;
  747. [rtlabel setText: val];
  748. CGSize sizeval=rtlabel.optimumSize;
  749. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  750. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  751. float height = MAX(sizekey.height,sizeval.height);
  752. height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
  753. return height;
  754. }
  755. else if([type isEqualToString:@"img"])
  756. {
  757. int img_count = [[item_json valueForKey:@"count"] intValue];
  758. double ret = 0;
  759. for(int j=0;j<img_count;j++)
  760. {
  761. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  762. float width = [[img_json valueForKey:@"width"]floatValue];
  763. float height = [[img_json valueForKey:@"height"]floatValue];
  764. ret+=height*tableView.bounds.size.width / width;
  765. }
  766. return ret;
  767. }
  768. return 44;
  769. }
  770. }
  771. }
  772. - (BOOL)isOutofStock {
  773. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  774. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  775. if (!qtyStr || !qtyStr.length || [qtyStr isEqualToString:@"In Production"] || [qtyStr isEqualToString:@"0"] || [qtyStr isEqualToString:@"Sold Out"] || [qtyStr isEqualToString:@"Out of Stock"]) {
  776. return YES;
  777. }
  778. return NO;
  779. }
  780. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  781. {
  782. // DebugLog(@"cellForRowAtIndexPath");
  783. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  784. if(indexPath.section==0)
  785. {
  786. NSString *CellIdentifier = @"DetailHeaderCell";
  787. DetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  788. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  789. if (!appDelegate.user) { // 没有登录时隐藏add to portfolio,使add to cart与add to wishlist对齐
  790. cell.btnaddPortfolio.hidden = YES;
  791. cell.btnNotifyMe.hidden = YES;
  792. } else {
  793. #ifdef BUILD_NPD
  794. NSString *qtyStr = [section_json valueForKey:@"Availability"];
  795. __weak typeof(self) weakself = self;
  796. cell.notifyMeBlock = ^{
  797. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  798. dispatch_async(dispatch_get_global_queue(0,0), ^{
  799. NSDictionary *dic = [iSalesNetwork notifyModel:self.product_id emailAddr:nil withScreen:ScreenCodeModelInfo];
  800. dispatch_async(dispatch_get_main_queue(), ^{
  801. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  802. NSInteger result = [[dic valueForKey:@"result"] integerValue];
  803. if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  804. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  805. if ([dic valueForKey:@"err_msg"]) {
  806. msg = [dic valueForKey:@"err_msg"];
  807. }
  808. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  809. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  810. }];
  811. [errorAlertVC addAction:action];
  812. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  813. } else if (result == RESULT_TRUE){
  814. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  815. } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  816. [self showEmailAddrBox];
  817. }
  818. });
  819. });
  820. };
  821. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  822. cell.btnaddPortfolio.hidden = YES;
  823. if (!notifyMe_switch) {
  824. cell.btnNotifyMe.hidden = YES;
  825. } else {
  826. cell.btnNotifyMe.hidden = NO;
  827. if (!appDelegate.order_code) { // 未打开订单状态
  828. if ([self isOutofStock]) {
  829. if (!appDelegate.can_create_backorder) {
  830. cell.btnaddCart.enabled = NO;
  831. }
  832. cell.btnNotifyMe.enabled = YES;
  833. } else {
  834. cell.btnaddCart.enabled = YES;
  835. cell.btnNotifyMe.enabled = NO;
  836. }
  837. } else {
  838. // 打开订单状态
  839. if (![Singleton sharedInstance].currentOrderIsMerged) {
  840. // Shop Order
  841. cell.btnaddCart.enabled = YES;
  842. // 默认未缺货
  843. cell.btnNotifyMe.enabled = NO;
  844. if ([self isOutofStock]) { // 缺货
  845. cell.btnNotifyMe.enabled = YES;
  846. }
  847. } else {
  848. // Purchase Order
  849. if ([self isOutofStock]) { // 缺货
  850. if (!appDelegate.can_create_backorder) {
  851. cell.btnaddCart.enabled = NO;
  852. }
  853. cell.btnNotifyMe.enabled = YES;
  854. } else { // 未缺货
  855. cell.btnNotifyMe.enabled = NO;
  856. cell.btnaddCart.enabled = YES;
  857. }
  858. }
  859. }
  860. }
  861. } else { // employee
  862. // online
  863. cell.btnaddPortfolio.hidden = NO;
  864. cell.btnNotifyMe.hidden = NO;
  865. if ([self isOutofStock]) { // 缺货
  866. if (!appDelegate.can_create_backorder) {
  867. cell.btnaddCart.enabled = NO;
  868. }
  869. cell.btnNotifyMe.enabled = YES;
  870. } else { // 未缺货
  871. cell.btnNotifyMe.enabled = NO;
  872. cell.btnaddCart.enabled = YES;
  873. }
  874. // offline
  875. if (appDelegate.offline_mode) {
  876. cell.btnNotifyMe.hidden = YES;
  877. }
  878. }
  879. #else
  880. cell.btnaddPortfolio.hidden = NO;
  881. cell.btnNotifyMe.hidden = YES;
  882. #endif
  883. }
  884. self.anchor_button.frame=cell.selector_Button.frame;
  885. cell.celldelegate=self;
  886. cell.quantity_text.text = [NSString stringWithFormat:@"%d",self.quantity];
  887. cell.step = self.step;
  888. cell.quantity = self.quantity;
  889. // cell.stepper.stepValue = self.step;
  890. // cell.stepper.value = self.quantity;
  891. NSString* price = [section_json valueForKey:@"price"];
  892. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  893. if(appDelegate.contact_id ==nil)
  894. {
  895. // appDelegate.bLogin = false;
  896. // cell.btnaddCart.enabled = false;
  897. }
  898. else
  899. {
  900. if ([price isEqualToString:@"No Price."]) {
  901. // cell.btnaddCart.enabled = false;
  902. }
  903. else
  904. {
  905. // cell.btnaddCart.enabled = true;
  906. }
  907. }
  908. int cqty = [[section_json valueForKey:@"Model QTY in cart"] intValue];
  909. cell.cqty = cqty;
  910. cell.set_cqty=^(int cqty)
  911. {
  912. [section_json setValue:[NSString stringWithFormat:@"%d",cqty] forKey:@"Model QTY in cart"];
  913. [self.detail_data setObject:section_json forKey:@"img_section"];
  914. [self.detailTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
  915. };
  916. cell.set_update_data=^(bool bupdate)
  917. {
  918. //self.update_data = bupdate;
  919. if(bupdate)
  920. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  921. else
  922. [((MainViewController*)appDelegate.main_vc) reloadCategory:false immediately:false];
  923. };
  924. if(cqty>0)
  925. {
  926. cell.cqyt_label.hidden=false;
  927. cell.cqyt_label.text=[NSString stringWithFormat:@"Model QTY in Cart:%d",cqty];
  928. }
  929. else
  930. {
  931. cell.cqyt_label.hidden=true;
  932. cell.cqyt_label.text=nil;
  933. }
  934. cell.descriptionRTLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  935. // cell.descriptionLabel.text =[NSString stringWithFormat:@"%@\n\n",[section_json valueForKey:@"model_descrition"]];
  936. cell.model_label.text =[section_json valueForKey:@"model_name"];
  937. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:80];
  938. // cell.qrcode_imageview.image = qrimg;
  939. if(appDelegate.bLogin==true)
  940. {
  941. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  942. {
  943. }
  944. else
  945. {
  946. price=nil;
  947. }
  948. }
  949. cell.priceLabel.text =price;
  950. // cell.shipLabel.text = [section_json valueForKey:@"ship"];
  951. cell.count_Label.text =[section_json valueForKey:@"Availability"] ;
  952. NSString* eta =[section_json valueForKey:@"ETA"] ;
  953. if(eta.length>0)
  954. {
  955. cell.eta_label.hidden = false;
  956. cell.etaval_label.text = eta;
  957. cell.etaval_label.hidden = false;
  958. cell.incoming_stock_label.hidden=false;
  959. cell.incomingcount_Label.text =[section_json valueForKey:@"incoming_stock"] ;
  960. cell.incomingcount_Label.hidden = false;
  961. }
  962. else
  963. {
  964. cell.eta_label.hidden = true;
  965. cell.etaval_label.text = nil;
  966. cell.etaval_label.hidden = true;
  967. cell.incoming_stock_label.hidden = true;
  968. cell.incomingcount_Label.text = nil;
  969. cell.incomingcount_Label.hidden = true;
  970. }
  971. self.selector = [section_json objectForKey:@"selector"];
  972. if(self.selector!=nil)
  973. {
  974. [cell Hide_selector:false];
  975. cell.selector_nameLabel.text =[self.selector valueForKey:@"name"];
  976. int selector_count = [[self.selector valueForKey:@"count"] intValue];
  977. cell.selector_imageView.image = [UIImage imageNamed:@"loading_s"];
  978. for(int i=0;i<selector_count;i++)
  979. {
  980. NSDictionary* params_json=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] objectForKey:@"params"] ;
  981. // NSString* aaa=[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue];
  982. if([[[[params_json objectForKey:@"param_0"] valueForKey:@"val"] stringValue] isEqualToString:self.product_id])
  983. {
  984. cell.selector_valLabel.text=[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"];
  985. NSString* selectstr=[NSString stringWithFormat:@"%@: %@",[self.selector valueForKey:@"name"],[[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"]];
  986. if([[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"title"] ==nil)
  987. selectstr=[NSString stringWithFormat:@"%@:",[self.selector valueForKey:@"name"]];
  988. cell.selector_label.text = selectstr;
  989. NSString* img_url = [[self.selector objectForKey:[NSString stringWithFormat:@"item_%d",i]] valueForKey:@"pic_url"];
  990. NSString* file_name=[img_url lastPathComponent];
  991. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  992. if(img_data!=nil)
  993. {
  994. dispatch_async(dispatch_get_main_queue(), ^{
  995. UIImage * img =[UIImage imageWithData:img_data];
  996. cell.selector_imageView.image=img;
  997. });
  998. }
  999. else
  1000. {
  1001. NSData* downloadimg_data = nil;
  1002. if (!appDelegate.offline_mode) {
  1003. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1004. }
  1005. dispatch_async(dispatch_get_main_queue(), ^{
  1006. if(downloadimg_data!=nil)
  1007. {
  1008. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1009. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1010. cell.selector_imageView.image=img;
  1011. }
  1012. else
  1013. cell.selector_imageView.image = [UIImage imageNamed:@"notfound_s"];
  1014. });
  1015. }
  1016. }
  1017. }
  1018. }
  1019. else
  1020. {
  1021. [cell Hide_selector:true];
  1022. }
  1023. // cell.selector_valLabel.text =[[section_json objectForKey:@"selector"] valueForKey:@"name"];
  1024. NSDictionary* property_json = [section_json objectForKey:@"property"];
  1025. // int pcount = [[property_json valueForKey:@"count"]intValue];
  1026. cell.property_nameLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"key"];
  1027. cell.property_valLabel.text=[[property_json objectForKey:@"item_0"] valueForKey:@"val"];
  1028. cell.product_id = self.product_id;
  1029. // cell.itemIDLabel.text = [NSString stringWithFormat:@"Item id:%d",3947105];
  1030. [cell setup];
  1031. [cell resetStack];
  1032. // NSDictionary* imgs_json = [section_json objectForKey:@"images"];
  1033. NSMutableDictionary* contents_json = [section_json objectForKey:@"stack_contents"];
  1034. int count = [[contents_json valueForKey:@"count"]intValue];
  1035. if(count<2)//1 for qrcode;
  1036. cell.pageControl.hidden = true;
  1037. else
  1038. cell.pageControl.hidden = false;
  1039. // NSMutableArray* urls= [[NSMutableArray alloc]init];
  1040. // cell.urls = urls;
  1041. // cell.stack_content = contents_json;//
  1042. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1043. for(int i=0;i<count;i++)
  1044. {
  1045. NSDictionary* item_json=[contents_json objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  1046. NSString* type = item_json[@"type"];
  1047. if([type isEqualToString:@"video"])
  1048. {
  1049. NSString* code = [item_json valueForKey:@"code"];
  1050. NSString* html=[RAUtils htmlForVideo:code template:nil];
  1051. [cell AddStackContent:html];
  1052. }
  1053. else if([type isEqualToString:@"image"])
  1054. {
  1055. NSString* img_url = [item_json valueForKey:@"s"];
  1056. // NSString* img_url_l = [img_json valueForKey:@"l"];
  1057. // if(img_url_l.length>0)
  1058. // [urls addObject:img_url_l];
  1059. NSString* file_name=[img_url lastPathComponent];
  1060. NSData* img_data=nil;
  1061. if([item_json[@"is_localfile"] boolValue])
  1062. img_data = [NSData dataWithContentsOfFile:img_url];
  1063. else
  1064. [iSalesDB load_cached_img:file_name loadFrom:img_url];
  1065. if(img_data!=nil)
  1066. {
  1067. dispatch_async(dispatch_get_main_queue(), ^{
  1068. UIImage * img =[UIImage imageWithData:img_data];
  1069. NSString* html=[RAUtils htmlForImage:img template:nil];
  1070. [cell AddStackContent:html];
  1071. // if(i==count-1)
  1072. // {
  1073. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1074. // if(qrimg!=nil)
  1075. // [cell AddPhoto:qrimg];
  1076. // }
  1077. // if(i==0)
  1078. // cell.imageView.image = img;
  1079. });
  1080. }
  1081. else
  1082. {
  1083. NSData* downloadimg_data = nil;
  1084. if (!appDelegate.offline_mode) {
  1085. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1086. }
  1087. dispatch_async(dispatch_get_main_queue(), ^{
  1088. if(downloadimg_data!=nil)
  1089. {
  1090. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1091. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1092. NSString* html=[RAUtils htmlForImage:img template:nil];
  1093. [cell AddStackContent:html];
  1094. // if(i==count-1)
  1095. // {
  1096. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1097. // if(qrimg!=nil)
  1098. // [cell AddPhoto:qrimg];
  1099. // }
  1100. // if(i==0)
  1101. // cell.imageView.image = img;
  1102. }
  1103. else
  1104. {
  1105. UIImage * img =[UIImage imageNamed:@"notfound_l"];
  1106. NSString* html=[RAUtils htmlForImage:img template:nil];
  1107. [cell AddStackContent:html];
  1108. // if(i==count-1)
  1109. // {
  1110. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  1111. // if(qrimg!=nil)
  1112. // [cell AddPhoto:qrimg];
  1113. // }
  1114. // if(i==0)
  1115. // cell.imageView.image = img;
  1116. }
  1117. });
  1118. }
  1119. }
  1120. }
  1121. });
  1122. // cell.backgroundColor = [UIColor whiteColor];
  1123. __weak typeof(self) weakself = self;
  1124. cell.shopCartBlock = ^(UIImageView *imageView){
  1125. self.add_cart=true;
  1126. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1127. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1128. CGRect headRect = imageView.frame;
  1129. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1130. [self startAnimationWithRect:headRect ImageView:imageView];
  1131. [self.navigationController popToRootViewControllerAnimated:true];
  1132. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1133. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1134. };
  1135. cell.WatchlistBlock = ^(UIImageView *imageView){
  1136. self.add_wish=true;
  1137. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1138. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1139. CGRect headRect = imageView.frame;
  1140. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1141. [self startAnimationWithRect:headRect ImageView:imageView];
  1142. };
  1143. cell.PortfolioBlock = ^(UIImageView *imageView){
  1144. self.add_portfolio=true;
  1145. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  1146. rect.origin.y = rect.origin.y - [self.detailTable contentOffset].y;
  1147. CGRect headRect = imageView.frame;
  1148. headRect.origin.y = rect.origin.y+headRect.origin.y;
  1149. [self startAnimationWithRect:headRect ImageView:imageView];
  1150. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1151. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  1152. };
  1153. cell.introduceBlock = ^(UIButton *sender) {
  1154. NSString *introduce = [weakself.detail_data objectForKey:@"introduce"];
  1155. // introduce = @"http://127.0.0.1/ios.pdf";
  1156. [weakself showIntroducePDF:introduce];
  1157. };
  1158. return cell;
  1159. }
  1160. // NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1161. // if(related_json==nil)
  1162. else
  1163. {
  1164. NSDictionary* section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)indexPath.section-1]];
  1165. NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row ]];
  1166. NSString *CellIdentifier = @"DetailInfoCell";
  1167. NSString* type=[section_json valueForKey:@"type"] ;
  1168. if([type isEqualToString:@"kv"])
  1169. {
  1170. float width = tableView.frame.size.width;
  1171. width-=CELL_MARGIN*2;
  1172. CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
  1173. CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  1174. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  1175. NSString* key =[item_json valueForKey:@"key"] ;
  1176. NSString* val=[item_json valueForKey:@"val"] ;
  1177. NSString* type=[item_json valueForKey:@"type"] ;
  1178. if([type isEqualToString:@"price"])
  1179. {
  1180. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1181. {
  1182. }
  1183. else
  1184. {
  1185. val=nil;
  1186. }
  1187. }
  1188. if([val isEqual:[NSNull null]])
  1189. val=@"";
  1190. if(val==nil)
  1191. val=@"";
  1192. if([val isEqualToString:@"null"])
  1193. val=@"";
  1194. CGRect frame;
  1195. frame.size = constraintval;
  1196. frame.origin.x=0;
  1197. frame.origin.y=0;
  1198. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  1199. [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  1200. // rtlabel.lineSpacing = 20.0;
  1201. [rtlabel setText: val];
  1202. CGSize sizeval=rtlabel.optimumSize;
  1203. CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  1204. float height = MAX(sizekey.height,sizeval.height);
  1205. height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
  1206. sizekey.height = height;
  1207. sizekey.width = constraintkey.width;
  1208. // sizeval.height = height;
  1209. sizeval.width =constraintval.width;
  1210. // NSString *CellIdentifier = @"detail_item_kv";
  1211. DetailKVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1212. if(cell==nil)
  1213. DebugLog(@"cell is nil.........................");
  1214. CGRect framekey = cell.keyLabel.frame;
  1215. framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
  1216. framekey.origin.y=LINE_WIDTH;
  1217. framekey.size = sizekey;
  1218. cell.keyLabel.frame = framekey;
  1219. cell.keyLabel.text=key;
  1220. CGRect frameval = cell.valLabel.frame;
  1221. frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
  1222. frameval.origin.y=LINE_WIDTH;
  1223. frameval.size = sizeval;
  1224. cell.valLabel.frame = frameval;
  1225. // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
  1226. cell.valLabel.text= val;
  1227. CGPoint rcenter;
  1228. rcenter.x = width * 0.4+width * 0.6/2;
  1229. rcenter.y = height /2;
  1230. cell.valLabel.center=rcenter;
  1231. // cell.valLabel.backgroundColor =[UIColor redColor];
  1232. // cell.contentView.superview.backgroundColor = [UIColor clearColor];
  1233. // cell.backgroundColor = [UIColor whiteColor];
  1234. UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
  1235. lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
  1236. lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
  1237. lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  1238. [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
  1239. cell.backgroundColor = [UIColor whiteColor];
  1240. return cell;
  1241. }
  1242. else if ([type isEqualToString:@"img"])
  1243. {
  1244. DetailImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailImageCell" forIndexPath:indexPath];
  1245. int img_count = [[item_json valueForKey:@"count"] intValue];
  1246. double posy = 0;
  1247. for(int j=0;j<img_count;j++)
  1248. {
  1249. NSDictionary* img_json =[item_json objectForKey:[NSString stringWithFormat:@"image_%d",j ]];
  1250. float width = [[img_json valueForKey:@"width"]floatValue];
  1251. float height = [[img_json valueForKey:@"height"]floatValue];
  1252. //
  1253. UIImageView * imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, posy, tableView.bounds.size.width , height*tableView.bounds.size.width / width)];
  1254. NSString* img_url = [img_json valueForKey:@"img_url"];
  1255. posy+=height*tableView.bounds.size.width / width;
  1256. NSString* file_name=[img_url lastPathComponent];
  1257. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  1258. if(img_data!=nil)
  1259. {
  1260. UIImage * img =[UIImage imageWithData:img_data];
  1261. imgview.image = img;
  1262. [cell addSubview:imgview];
  1263. }
  1264. else
  1265. {
  1266. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1267. NSData* downloadimg_data = nil;
  1268. if (!appDelegate.offline_mode) {
  1269. downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  1270. }
  1271. dispatch_async(dispatch_get_main_queue(), ^{
  1272. if(downloadimg_data!=nil)
  1273. {
  1274. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  1275. UIImage * img =[UIImage imageWithData:downloadimg_data];
  1276. imgview.image = img;
  1277. [cell addSubview:imgview];
  1278. }
  1279. else
  1280. {
  1281. imgview.image = [UIImage imageNamed:@"notfound_l"];
  1282. [cell addSubview:imgview];
  1283. }
  1284. });
  1285. });
  1286. }
  1287. }
  1288. cell.backgroundColor = [UIColor whiteColor];
  1289. return cell;
  1290. }
  1291. else if ([type isEqualToString:@"content"])
  1292. {
  1293. NSString *CellIdentifier = @"DetailTopicCell";
  1294. NSString* data=[section_json valueForKey:@"data"] ;
  1295. if([data isEqualToString:@"local"])
  1296. {
  1297. [appDelegate.recent_model addEntriesFromDictionary:section_json];
  1298. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1299. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1300. cell.itemdelegate = self;
  1301. cell.related_data = appDelegate.recent_model;
  1302. [cell.topicCollectionView reloadData];
  1303. cell.backgroundColor = [UIColor whiteColor];
  1304. return cell;
  1305. }
  1306. else
  1307. {
  1308. // NSDictionary* section_json = [self.detail_data objectForKey:@"related_model"];
  1309. DetailTopicCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1310. cell.itemdelegate = self;
  1311. cell.related_data = section_json;
  1312. [cell.topicCollectionView reloadData];
  1313. cell.backgroundColor = [UIColor whiteColor];
  1314. return cell;
  1315. }
  1316. }
  1317. return nil;
  1318. }
  1319. }
  1320. -(void)startAnimationWithRect:(CGRect)rect ImageView:(UIImageView *)imageView
  1321. {
  1322. if (!_layer) {
  1323. // _btn.enabled = NO;
  1324. _layer = [CALayer layer];
  1325. _layer.contents = (id)imageView.layer.contents;
  1326. _layer.contentsGravity = kCAGravityResizeAspectFill;
  1327. _layer.bounds = rect;
  1328. [_layer setCornerRadius:CGRectGetHeight([_layer bounds]) / 2];
  1329. _layer.masksToBounds = YES;
  1330. // 导航64
  1331. _layer.position = CGPointMake(imageView.center.x, CGRectGetMidY(rect)+64);
  1332. // [_tableView.layer addSublayer:_layer];
  1333. [self.view.layer addSublayer:_layer];
  1334. self.path = [UIBezierPath bezierPath];
  1335. // [_path moveToPoint:_layer.position];
  1336. [_path moveToPoint:imageView.center];
  1337. [_path addLineToPoint:CGPointMake(imageView.center.x, imageView.center.y-100)];
  1338. // (SCREEN_WIDTH - 60), 0, 50, 50)
  1339. // [_path addQuadCurveToPoint:CGPointMake(SCREEN_WIDTH - 40, SCREEN_HEIGHT-40) controlPoint:CGPointMake(SCREEN_WIDTH/2,rect.origin.y-80)];
  1340. // [_path addLineToPoint:CGPointMake(SCREEN_WIDTH-40, 30)];
  1341. }
  1342. [self groupAnimation];
  1343. }
  1344. -(void)groupAnimation
  1345. {
  1346. self.detailTable.userInteractionEnabled = NO;
  1347. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  1348. animation.path = _path.CGPath;
  1349. // animation.rotationMode = kCAAnimationRotateAuto;
  1350. //
  1351. CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1352. expandAnimation.duration = 0.3f;
  1353. expandAnimation.fromValue = [NSNumber numberWithFloat:1];
  1354. expandAnimation.toValue = [NSNumber numberWithFloat:2.0f];
  1355. expandAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
  1356. CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
  1357. narrowAnimation.beginTime = 0.3;
  1358. narrowAnimation.fromValue = [NSNumber numberWithFloat:2.0f];
  1359. narrowAnimation.duration = 0.9f;
  1360. narrowAnimation.toValue = [NSNumber numberWithFloat:0.3f];
  1361. //
  1362. // narrowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  1363. CAAnimationGroup *groups = [CAAnimationGroup animation];
  1364. groups.animations = @[animation,expandAnimation,narrowAnimation];
  1365. groups.duration = 1.0f;
  1366. groups.removedOnCompletion=NO;
  1367. groups.fillMode=kCAFillModeForwards;
  1368. groups.delegate = self;
  1369. [_layer addAnimation:groups forKey:@"group"];
  1370. }
  1371. -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
  1372. {
  1373. // [anim def];
  1374. if (anim == [_layer animationForKey:@"group"]) {
  1375. self.detailTable.userInteractionEnabled = YES;
  1376. // _btn.enabled = YES;
  1377. [_layer removeFromSuperlayer];
  1378. _layer = nil;
  1379. // _cnt++;
  1380. // if (_cnt) {
  1381. // _cntLabel.hidden = NO;
  1382. // }
  1383. // CATransition *animation = [CATransition animation];
  1384. // animation.duration = 0.25f;
  1385. // _cntLabel.text = [NSString stringWithFormat:@"%d",_cnt];
  1386. // [_cntLabel.layer addAnimation:animation forKey:nil];
  1387. // CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
  1388. // shakeAnimation.duration = 0.25f;
  1389. // shakeAnimation.fromValue = [NSNumber numberWithFloat:-5];
  1390. // shakeAnimation.toValue = [NSNumber numberWithFloat:5];
  1391. // shakeAnimation.autoreverses = YES;
  1392. // [_btn.layer addAnimation:shakeAnimation forKey:nil];
  1393. }
  1394. }
  1395. #pragma mark - hide section button clicked
  1396. - (void)RefreshSection:(UIButton *)sender {
  1397. sender.enabled=false;
  1398. NSDictionary* section_json = nil;
  1399. NSDictionary* related_json = [self.detail_data objectForKey:@"related_model"];
  1400. if(related_json==nil)
  1401. {
  1402. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)(sender.tag-1)]];
  1403. }
  1404. else
  1405. {
  1406. if(sender.tag==1)
  1407. {
  1408. section_json = related_json ;
  1409. }
  1410. else
  1411. {
  1412. section_json = [self.detail_data objectForKey:[NSString stringWithFormat:@"detail_%ld",(long)sender.tag-2]];
  1413. }
  1414. }
  1415. NSString* url = section_json[@"data_interface"];
  1416. NSMutableDictionary* params = [section_json[@"params"] mutableCopy];
  1417. if(params==nil)
  1418. params = [[NSMutableDictionary alloc] init];
  1419. NSUInteger ii[2] = {sender.tag,0};
  1420. NSIndexPath* indexpath= [NSIndexPath indexPathWithIndexes:ii length:2];
  1421. DetailTopicCell * cell=[self.detailTable cellForRowAtIndexPath:indexpath];
  1422. [cell begin_refresh];
  1423. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..."title:@"Refreshing"];
  1424. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1425. NSDictionary* editor_json = [iSalesNetwork commoneditor_partialrefresh:params url:url];
  1426. dispatch_async(dispatch_get_main_queue(), ^{
  1427. [cell end_refresh ];
  1428. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1429. sender.enabled=true;
  1430. if([[editor_json valueForKey:@"result"] intValue]==2)
  1431. {
  1432. [self.detail_data addEntriesFromDictionary:editor_json];
  1433. NSRange range = NSMakeRange(sender.tag, 1);
  1434. NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1435. [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1436. }
  1437. else
  1438. {
  1439. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:nil controller:self] ;
  1440. }
  1441. });
  1442. });
  1443. // self.showMore=!self.showMore;
  1444. // NSRange range = NSMakeRange(1, 1);
  1445. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  1446. // [self.detailTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  1447. }
  1448. #pragma mark - Support scanner
  1449. -(void) onDecodedData:(NSString*) value
  1450. {
  1451. // UIApplication * app = [UIApplication sharedApplication];
  1452. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1453. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1454. //
  1455. self.model_name = value;
  1456. self.product_id = nil;
  1457. self.use_model_name = true;
  1458. [self reload];
  1459. DebugLog(@"color selected");
  1460. }
  1461. #pragma mark - Handle Notification
  1462. - (void)dealloc {
  1463. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1464. }
  1465. - (void)registeObserver {
  1466. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNoRightMsg:) name:No_Rights_Notification object:nil];
  1467. }
  1468. - (void)handleNoRightMsg:(NSNotification *)notification {
  1469. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning" message:@"You have no rights to do that." preferredStyle:UIAlertControllerStyleAlert];
  1470. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1471. [alertController dismissViewControllerAnimated:YES completion:nil];
  1472. }];
  1473. [alertController addAction:action];
  1474. [self presentViewController:alertController animated:YES completion:nil];
  1475. }
  1476. #pragma mark - action
  1477. - (void)showEmailAddrBox {
  1478. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  1479. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  1480. emailAddrVC.textFiled.secureTextEntry = NO;
  1481. emailAddrVC.yesButtonTitle = @"send";
  1482. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  1483. __weak typeof(self) weakself = self;
  1484. emailAddrVC.textHandler = ^(NSString *text){
  1485. // 验证邮箱格式是否正确
  1486. // NSString *match = EMAIL_MATCHES;
  1487. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  1488. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  1489. BOOL isEmailAddr = YES;
  1490. if (isEmailAddr) {
  1491. // 验证是邮件地址,发送邮件
  1492. [weakVC dismissViewControllerAnimated:YES completion:^{
  1493. UIAlertView *waitting_alert = [RAUtils waiting_alert:@"Sending Email" title:@"Waiting"];
  1494. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1495. NSDictionary *result = [iSalesNetwork notifyModel:weakself.product_id emailAddr:text withScreen:ScreenCodeModelInfo];
  1496. DebugLog(@"email cart result: %@",result);
  1497. dispatch_async(dispatch_get_main_queue(), ^{
  1498. [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  1499. int resultStatus = [[result objectForKey:@"result"] intValue];
  1500. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  1501. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  1502. if ([result valueForKey:@"err_msg"]) {
  1503. msg = [result valueForKey:@"err_msg"];
  1504. }
  1505. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  1506. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1507. }];
  1508. [errorAlertVC addAction:action];
  1509. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  1510. }else if(resultStatus == RESULT_TRUE){
  1511. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  1512. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  1513. [weakself showEmailAddrBox];
  1514. }
  1515. });
  1516. });
  1517. }];
  1518. } else {
  1519. // 非邮件地址,警告
  1520. [weakVC warning:@"Please enter right email address"];
  1521. }
  1522. };
  1523. [self presentViewController:emailAddrVC animated:YES completion:nil];
  1524. }
  1525. - (void)showIntroducePDF:(NSString *)link {
  1526. if (link.length == 0) {
  1527. [RAUtils message_alert:@"There is no resource to open" title:@"Warning" controller:self];
  1528. return;
  1529. }
  1530. BOOL isLocalFile = NO;
  1531. NSMutableDictionary* section_json = [[self.detail_data objectForKey:@"img_section"] mutableCopy];
  1532. NSString *name = [section_json valueForKey:@"model_name"];
  1533. NSString *path = [NSString stringWithFormat:@"%@/Introduce/%@/%@",[RAUtils appCacheDirectory],name,link.lastPathComponent];
  1534. if ([RAUtils fileExistsAtPath:path]) { // 检查缓存
  1535. isLocalFile = YES;
  1536. link = path;
  1537. } else {
  1538. // 创建缓存目录
  1539. NSString *dir = [path stringByDeletingLastPathComponent];
  1540. [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
  1541. }
  1542. name = [NSString stringWithFormat:@"%@ Assembly Instruction",name];
  1543. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  1544. ViewController.url = link;
  1545. ViewController.canSave = false;
  1546. ViewController.isLocalfile=isLocalFile;
  1547. ViewController.cachePath = path;
  1548. NSString* subject = name;
  1549. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1550. NSString* customer_email = [appDelegate.customerInfo valueForKey:@"customer_email"];
  1551. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  1552. if(customer_email.length>0)
  1553. {
  1554. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  1555. }
  1556. ViewController.mail_to = send_to;
  1557. ViewController.attachment_name = [NSString stringWithFormat:@"%@.pdf",name];
  1558. ViewController.mail_subject = subject;
  1559. ViewController.hidenavi = false;
  1560. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ViewController];
  1561. // nav.modalPresentationStyle = UIModalPresentationFormSheet;// 只在iPad起作用
  1562. // CGSize size = [UIScreen mainScreen].bounds.size;
  1563. // nav.preferredContentSize = CGSizeMake(size.width * 0.8, size.height * 0.8);
  1564. [self.navigationController pushViewController:ViewController animated:YES];
  1565. }
  1566. @end