DetailViewController.m 73 KB

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