DetailViewController.m 73 KB

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