DetailViewController.m 93 KB

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