DetailViewController.m 80 KB

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