HomerModelDetailHeaderCell.m 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. //
  2. // HomerModelDetailHeaderCell.m
  3. // iSales-HOMER
  4. //
  5. // Created by Jack on 2017/10/25.
  6. // Copyright © 2017年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "HomerModelDetailHeaderCell.h"
  9. #import "RANetwork.h"
  10. #import "MainViewController.h"
  11. #import "LoginViewController.h"
  12. #import "ContactListViewController.h"
  13. #import "RAUtils.h"
  14. #import "OrderListViewController.h"
  15. #import "ImageScrollerViewController.h"
  16. #import "CartUtils.h"
  17. #import "CustomIOSAlertView.h"
  18. #import "TextUtils.h"
  19. #import "ContentPreviewController.h"
  20. #import "DetailViewController.h"
  21. @implementation HomerModelDetailHeaderCell
  22. @synthesize celldelegate;
  23. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  24. {
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (self) {
  27. // Initialization code
  28. }
  29. return self;
  30. }
  31. - (void)awakeFromNib
  32. {
  33. [super awakeFromNib];
  34. self.quantity_text.delegate = self;
  35. // MDHTMLLabelVerticalAlignmentCenter = 0,
  36. // MDHTMLLabelVerticalAlignmentTop = 1,
  37. self.informationLabel.numberOfLines = 0;
  38. // self.informationLabel.verticalAlignment=MDHTMLLabelVerticalAlignmentTop;
  39. // self.informationLabel.backgroundColor = [UIColor yellowColor];
  40. // self.selector_Button.layer.borderWidth = 0.5;
  41. // self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  42. // self.selector_Button.layer.cornerRadius = 0;
  43. [self.descriptionRTLabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  44. [self.descriptionRTLabel setTextAlignment:RTTextAlignmentCenter];
  45. [self.descriptionRTLabel setFont:[UIFont systemFontOfSize:22]];
  46. [self addObserver:self
  47. forKeyPath:@"stack_contents"
  48. options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
  49. context:@"content changed"];
  50. self.inforframe=self.informationLabel.frame.size;
  51. // [self generate_information];
  52. }
  53. -(void) dealloc
  54. {
  55. [self removeObserver:self forKeyPath:@"stack_contents"];
  56. }
  57. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  58. {
  59. if([keyPath isEqualToString:@"stack_contents"])
  60. {
  61. [self.playerView stopVideo];
  62. self.playerView.hidden=true;
  63. }
  64. }
  65. - (void)layoutSubviews
  66. {
  67. [super layoutSubviews];
  68. // [self generate_information];
  69. }
  70. -(void) generate_information
  71. {
  72. NSMutableArray* arr_addr = [[NSMutableArray alloc] init];
  73. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' ><b>Availability:</b> %@</font>",self.count_Label.text]];
  74. if(self.incomingcount_Label.text.length>0)
  75. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' ><b>Incoming stock:</b> %@</font>",self.incomingcount_Label.text]];
  76. if(self.etaval_label.text.length>0)
  77. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' ><b>Next Arrival Date:</b> %@</font>",self.etaval_label.text]];
  78. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;font-family:Helvetica' ><b>Availability in 7-10 days:</b> %@</font>",self.hmlg_stock_count_lb.text]];
  79. if(self.cqyt_label.text.length>0)
  80. [arr_addr addObject:[NSString stringWithFormat:@"<font style='font-size:16px;color:red';font-family:Helvetica><b>%@</b></font>",self.cqyt_label.text]];
  81. NSString * information_str = [RAConvertor arr2string:arr_addr separator:@"<br>" trim:true];
  82. // UIFont *font=[UIFont systemFontOfSize:14];
  83. //// label.font=font;
  84. NSDictionary *optoins=@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};
  85. NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[information_str dataUsingEncoding:NSUnicodeStringEncoding] options:optoins documentAttributes:nil error:nil];
  86. // self.informationLabel.numberOfLines
  87. // self.informationLabel.lineBreakMode
  88. //
  89. // self.informationLabel.adjustsFontSizeToFitWidth = YES;
  90. // self.informationLabel.minimumFontSize = 0.5;
  91. self.informationLabel.attributedText=attrStr;
  92. // self.informationLabel.text = @"文字在语言学中指书面语的视觉形式,古代把独体字叫做“文”,把合体字叫做“字”,如今联合起来叫做“文字”,文字的基本个体叫做“字”。在日常生活中,";
  93. // [self.informationLabel sizeToFit];
  94. // CGSize inforsize=[self.informationLabel sizeThatFits:self.informationLabel.frame.size];
  95. // CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrStr);
  96. // //计算文本绘制size ,这里300是文字宽度,你可以自己更改为247,但是要记得,在height 方法里的这个位置,也改为247
  97. // CGSize tmpSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(self.informationLabel.frame.size.width, MAXFLOAT), NULL);
  98. //
  99. //
  100. //
  101. // CFRelease(framesetter);
  102. // CGSize lblSize = [self.informationLabel.text boundingRectWithSize:self.informationLabel.frame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
  103. // self.informationLabel.frame = CGRectMake(self.informationLabel.frame.origin.x, self.informationLabel.frame.origin.y, tmpSize.width, tmpSize.height);
  104. // [self.informationLabel sizeToFit];
  105. UILabel* textLabel = [UILabel new];
  106. textLabel.attributedText = attrStr;
  107. textLabel.numberOfLines = 0;
  108. textLabel.lineBreakMode = NSLineBreakByWordWrapping;
  109. // [textLabel sizeToFit];
  110. CGSize newsize = [textLabel sizeThatFits:self.inforframe];
  111. float new_height=newsize.height<self.inforframe.height?newsize.height:self.inforframe.height;
  112. // self.informationLabel.frame = CGRectMake(self.informationLabel_arch.frame.origin.x, CGRectGetMaxY(self.informationLabel.frame)-newsize.height, newsize.width, newsize.height);
  113. self.informationLabel.frame = CGRectMake(self.informationLabel.frame.origin.x, self.informationLabel.frame.origin.y, self.inforframe.width, new_height);
  114. }
  115. - (IBAction)add_toPortfolio:(id)sender {
  116. UIApplication * app = [UIApplication sharedApplication];
  117. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  118. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  119. [[NSNotificationCenter defaultCenter] postNotificationName:No_Rights_Notification object:nil];
  120. return;
  121. }
  122. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  123. if(appDelegate.bLogin==false)
  124. {
  125. UIViewController *vc= [RAUtils getViewController:self];
  126. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  127. loginvc.returnValue = ^(bool blogin){
  128. if(blogin)
  129. {
  130. if(self.set_update_data)
  131. self.set_update_data(true);
  132. [main_vc checklogin:true];
  133. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  134. NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
  135. dispatch_async(dispatch_get_main_queue(), ^{
  136. if([[return_json valueForKey:@"result"] intValue]==2)
  137. {
  138. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  139. if(self.WatchlistBlock!=nil)
  140. {
  141. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  142. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  143. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  144. iv.image = img;
  145. self.PortfolioBlock(iv);
  146. }
  147. }
  148. else
  149. {
  150. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  151. }
  152. });
  153. });
  154. }
  155. };
  156. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  157. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  158. [vc presentViewController:navi animated:YES completion:^{
  159. }];
  160. }
  161. else
  162. {
  163. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  164. NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
  165. dispatch_async(dispatch_get_main_queue(), ^{
  166. if([[return_json valueForKey:@"result"] intValue]==2)
  167. {
  168. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  169. if(self.WatchlistBlock!=nil)
  170. {
  171. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  172. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  173. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  174. iv.image = img;
  175. self.PortfolioBlock(iv);
  176. }
  177. }
  178. else
  179. {
  180. UIViewController *vc= [RAUtils getViewController:self];
  181. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  182. }
  183. });
  184. });
  185. }
  186. }
  187. - (IBAction)add_toWatchList:(id)sender {
  188. UIApplication * app = [UIApplication sharedApplication];
  189. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  190. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  191. if(appDelegate.bLogin==false)
  192. {
  193. UIViewController *vc= [RAUtils getViewController:self];
  194. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  195. loginvc.returnValue = ^(bool blogin){
  196. if(blogin)
  197. {
  198. if(self.set_update_data)
  199. self.set_update_data(true);
  200. [main_vc checklogin:true];
  201. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  202. NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  203. dispatch_async(dispatch_get_main_queue(), ^{
  204. if([[return_json valueForKey:@"result"] intValue]==2)
  205. {
  206. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  207. if(self.WatchlistBlock!=nil)
  208. {
  209. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  210. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  211. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  212. iv.image = img;
  213. self.WatchlistBlock(iv);
  214. }
  215. }
  216. else
  217. {
  218. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  219. }
  220. });
  221. });
  222. }
  223. };
  224. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  225. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  226. [vc presentViewController:navi animated:YES completion:^{
  227. }];
  228. }
  229. else
  230. {
  231. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  232. NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  233. dispatch_async(dispatch_get_main_queue(), ^{
  234. if([[return_json valueForKey:@"result"] intValue]==2)
  235. {
  236. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  237. if(self.WatchlistBlock!=nil)
  238. {
  239. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  240. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  241. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  242. iv.image = img;
  243. self.WatchlistBlock(iv);
  244. }
  245. }
  246. else
  247. {
  248. UIViewController *vc= [RAUtils getViewController:self];
  249. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  250. }
  251. });
  252. });
  253. }
  254. }
  255. - (IBAction)add_toCart:(id)sender {
  256. UIViewController *vc= [RAUtils getViewController:self];
  257. [CartUtils add_to_cart:vc selectorholder:self selector:@selector(addtocart)];
  258. return;
  259. }
  260. -(void) addtocart
  261. {
  262. int count=[self.quantity_text.text intValue];
  263. #ifdef MPACK
  264. if (count % self.step != 0) {
  265. UIViewController *vc= [RAUtils getViewController:self];
  266. [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Add to cart" controller:vc];
  267. return;
  268. }
  269. #endif
  270. int c=[self.count_Label.text intValue];
  271. DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  272. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  273. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  274. if(/*c<count*/!appDelegate.can_create_backorder && c == 0)
  275. {
  276. NSString *msg = nil;
  277. BOOL continueAdd = YES;
  278. // #ifdef BUILD_NPD
  279. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  280. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  281. if ([Singleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
  282. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.",COMPANY_SHORT_NAME];
  283. continueAdd = NO;
  284. } else { // Shop Order购买数量大于库存需要确认
  285. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
  286. continueAdd = YES;
  287. }
  288. }
  289. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
  290. msg = @"Item is OUT OF STOCK and not available to order.";
  291. continueAdd = NO;
  292. }
  293. // #endif
  294. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
  295. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  296. if (continueAdd) {
  297. [self addtocart:count];
  298. }
  299. }];
  300. [alertControl addAction:alertthree];
  301. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  302. }];
  303. if (continueAdd) {
  304. [alertControl addAction:alertcancel];
  305. }
  306. UIViewController *vc= [RAUtils getViewController:self];
  307. [vc presentViewController:alertControl animated:YES completion:nil];
  308. }
  309. else
  310. {
  311. [self addtocart:count];
  312. }
  313. }
  314. -(void)Hide_selector:(bool) bhide
  315. {
  316. // self.selector_Button.hidden=bhide;
  317. // self.selector_dorpdown.hidden=bhide;
  318. // self.selector_imageView.hidden=bhide;
  319. //
  320. }
  321. -(void) addtocart:(int) count
  322. {
  323. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  324. if(self.cqty>0)
  325. {
  326. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  327. //block代码块取代了delegate
  328. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  329. int c=self.cqty+count;
  330. int m=c%self.step;
  331. if(m!=0&&appDelegate.alert_sold_in_quantities)
  332. {
  333. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  334. //block代码块取代了delegate
  335. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  336. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  337. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  338. dispatch_async(dispatch_get_main_queue(), ^{
  339. if([[return_json valueForKey:@"result"] intValue]==2)
  340. {
  341. // NSString* order_code = [return_json valueForKey:@"order_code"];
  342. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  343. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  344. if(self.shopCartBlock!=nil)
  345. {
  346. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  347. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  348. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  349. iv.image = img;
  350. // [self.contentView addSubview:iv];
  351. self.shopCartBlock(iv);
  352. self.cqty +=count;
  353. if(self.set_cqty)
  354. self.set_cqty(self.cqty);
  355. }
  356. }
  357. else
  358. {
  359. UIViewController *vc= [RAUtils getViewController:self];
  360. NSString *msg = [return_json valueForKey:@"err_msg"];
  361. NSString *title = @"Add To Cart";
  362. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  363. title = @"Add To Cart: Out of Stock";
  364. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  365. self.btnNotifyMe.enabled = YES;
  366. self.btnaddCart.enabled = NO;
  367. }
  368. [RAUtils message_alert:msg title:title controller:vc] ;
  369. }
  370. });
  371. });
  372. }];
  373. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  374. DebugLog(@"No");
  375. }];
  376. [alertControl addAction:actionOne];
  377. [alertControl addAction:alertthree];
  378. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  379. UIViewController *vc= [RAUtils getViewController:self];
  380. [vc presentViewController:alertControl animated:YES completion:nil];
  381. }
  382. else
  383. {
  384. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  385. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  386. dispatch_async(dispatch_get_main_queue(), ^{
  387. if([[return_json valueForKey:@"result"] intValue]==2)
  388. {
  389. // NSString* order_code = [return_json valueForKey:@"order_code"];
  390. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  391. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  392. if(self.shopCartBlock!=nil)
  393. {
  394. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  395. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  396. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  397. iv.image = img;
  398. // [self.contentView addSubview:iv];
  399. self.shopCartBlock(iv);
  400. self.cqty +=count;
  401. if(self.set_cqty)
  402. self.set_cqty(self.cqty);
  403. }
  404. }
  405. else
  406. {
  407. UIViewController *vc= [RAUtils getViewController:self];
  408. NSString *msg = [return_json valueForKey:@"err_msg"];
  409. NSString *title = @"Add To Cart";
  410. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  411. title = @"Add To Cart: Out of Stock";
  412. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  413. self.btnNotifyMe.enabled = YES;
  414. self.btnaddCart.enabled = NO;
  415. }
  416. [RAUtils message_alert:msg title:title controller:vc] ;
  417. }
  418. });
  419. });
  420. }
  421. }];
  422. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  423. DebugLog(@"No");
  424. }];
  425. [alertControl addAction:actionOne];
  426. [alertControl addAction:alertthree];
  427. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  428. UIViewController *vc= [RAUtils getViewController:self];
  429. [vc presentViewController:alertControl animated:YES completion:nil];
  430. }
  431. else
  432. {
  433. int c=self.cqty+count;
  434. int m=c%self.step;
  435. if(m!=0&&appDelegate.alert_sold_in_quantities)
  436. {
  437. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  438. //block代码块取代了delegate
  439. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  440. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  441. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  442. dispatch_async(dispatch_get_main_queue(), ^{
  443. if([[return_json valueForKey:@"result"] intValue]==2)
  444. {
  445. // NSString* order_code = [return_json valueForKey:@"order_code"];
  446. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  447. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  448. if(self.shopCartBlock!=nil)
  449. {
  450. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  451. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  452. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  453. iv.image = img;
  454. // [self.contentView addSubview:iv];
  455. self.shopCartBlock(iv);
  456. self.cqty +=count;
  457. if(self.set_cqty)
  458. self.set_cqty(self.cqty);
  459. }
  460. }
  461. else
  462. {
  463. UIViewController *vc= [RAUtils getViewController:self];
  464. NSString *msg = [return_json valueForKey:@"err_msg"];
  465. NSString *title = @"Add To Cart";
  466. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  467. title = @"Add To Cart: Out of Stock";
  468. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  469. self.btnNotifyMe.enabled = YES;
  470. self.btnaddCart.enabled = NO;
  471. }
  472. [RAUtils message_alert:msg title:title controller:vc] ;
  473. }
  474. });
  475. });
  476. }];
  477. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  478. DebugLog(@"No");
  479. }];
  480. [alertControl addAction:actionOne];
  481. [alertControl addAction:alertthree];
  482. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  483. UIViewController *vc= [RAUtils getViewController:self];
  484. [vc presentViewController:alertControl animated:YES completion:nil];
  485. }
  486. else
  487. {
  488. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  489. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  490. dispatch_async(dispatch_get_main_queue(), ^{
  491. if([[return_json valueForKey:@"result"] intValue]==2)
  492. {
  493. // NSString* order_code = [return_json valueForKey:@"order_code"];
  494. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  495. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  496. if(self.shopCartBlock!=nil)
  497. {
  498. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  499. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  500. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  501. iv.image = img;
  502. // [self.contentView addSubview:iv];
  503. self.shopCartBlock(iv);
  504. self.cqty +=count;
  505. if(self.set_cqty)
  506. self.set_cqty(self.cqty);
  507. }
  508. }
  509. else
  510. {
  511. UIViewController *vc= [RAUtils getViewController:self];
  512. NSString *msg = [return_json valueForKey:@"err_msg"];
  513. NSString *title = @"Add To Cart";
  514. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  515. title = @"Add To Cart: Out of Stock";
  516. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  517. self.btnNotifyMe.enabled = YES;
  518. self.btnaddCart.enabled = NO;
  519. }
  520. [RAUtils message_alert:msg title:title controller:vc] ;
  521. }
  522. });
  523. });
  524. }
  525. }
  526. }
  527. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  528. {
  529. [super setSelected:selected animated:animated];
  530. // Configure the view for the selected state
  531. }
  532. - (IBAction)selectorOnClick:(id)sender {
  533. DebugLog(@"select click");
  534. [celldelegate SelectorClicked:(UIButton*) sender];
  535. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  536. }
  537. #pragma mark -
  538. #pragma mark Deck DataSource Protocol Methods
  539. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  540. return [self.photos count];
  541. }
  542. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  543. if(self.photos.count==0)
  544. return nil;
  545. return [self.photos objectAtIndex:index];
  546. }
  547. #pragma mark -
  548. #pragma mark Deck Delegate Protocol Methods
  549. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  550. // User started moving a photo
  551. }
  552. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  553. // User flicked the photo away, revealing the next one in the stack
  554. }
  555. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  556. self.pageControl.currentPage = index;
  557. }
  558. - (UIView *)createVideoView:(NSString*) videoID
  559. {
  560. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
  561. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  562. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  563. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
  564. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  565. titleLabel.text=@"a separated player will show here:";
  566. titleLabel.numberOfLines = 0;
  567. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  568. // titleLabel.textAlignment = NSTextAlignmentRight;
  569. titleLabel.textAlignment = NSTextAlignmentCenter;
  570. CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
  571. CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  572. //[titleLabel sizeToFit];
  573. // titleLabel.center.x = demoView.center.x;
  574. titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
  575. [demoView addSubview:titleLabel];
  576. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
  577. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  578. lineLabel.text=videoID;
  579. lineLabel.numberOfLines = 0;
  580. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  581. CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  582. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
  583. //[lineLabel sizeToFit];
  584. [demoView addSubview:lineLabel];
  585. demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  586. return demoView;
  587. }
  588. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  589. DebugLog(@"selected %lu", (unsigned long)index);
  590. NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
  591. if([item[@"type"] isEqualToString:@"video"])
  592. {
  593. NSString* video_code=item[@"code"];
  594. // [TextUtils expression_varable:video regex:<#(NSString *)#>]
  595. NSString* video_id=[self.playerView Embed2VID:video_code];
  596. NSDictionary *playerVars = @{
  597. @"playsinline" : @1,
  598. @"autoplay" : @(1),
  599. @"rel":@0,
  600. @"showinfo": @0,
  601. @"modestbranding":@0,
  602. @"enablejsapi":@1
  603. };
  604. [self.playerView loadWithVideoId:video_id playerVars:playerVars];
  605. for(UIView *v in self.playerView.subviews)
  606. {
  607. if([v isKindOfClass:[UIButton class] ])
  608. [self.playerView bringSubviewToFront:v];
  609. }
  610. self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
  611. self.playerView.hidden=false;
  612. return;
  613. } else {
  614. if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
  615. return;
  616. }
  617. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  618. preVC.content = self.stack_contents;
  619. // preVC.currentIndex = index;
  620. [preVC setOffset:index];
  621. UIViewController *superVC= [RAUtils getViewController:self];
  622. [superVC.navigationController pushViewController:preVC animated:true];
  623. return;
  624. }
  625. // }
  626. // 调用展示窗口
  627. ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  628. UIViewController *vc= [RAUtils getViewController:self];
  629. [vc.navigationController pushViewController:imgShow animated:true];
  630. }
  631. -(void) neworder
  632. {
  633. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  634. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  635. NSDictionary* return_json = [RANetwork new_Order];
  636. dispatch_async(dispatch_get_main_queue(), ^{
  637. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  638. if([[return_json valueForKey:@"result"] intValue]==2)
  639. {
  640. int result=[[return_json valueForKey:@"result"] intValue];
  641. if(result==2)
  642. {
  643. //successed.
  644. NSString* order_code = [return_json valueForKey:@"orderCode"];
  645. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  646. appDelegate.order_code = order_code;
  647. int count=[self.quantity_text.text intValue];
  648. [self addtocart:count];
  649. }
  650. }
  651. else
  652. {
  653. UIViewController *vc= [RAUtils getViewController:self];
  654. NSString *msg = [return_json valueForKey:@"err_msg"];
  655. NSString *title = @"Add To Cart";
  656. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  657. title = @"Add To Cart: Out of Stock";
  658. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  659. self.btnNotifyMe.enabled = YES;
  660. self.btnaddCart.enabled = NO;
  661. }
  662. [RAUtils message_alert:msg title:title controller:vc] ;
  663. }
  664. });
  665. });
  666. }
  667. #pragma mark - UIAlertViewDelegate
  668. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  669. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  670. {
  671. UIApplication * app = [UIApplication sharedApplication];
  672. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  673. if(alertView.tag==1234)//库存小于0
  674. {
  675. // availability warring;
  676. int count=[self.quantity_text.text intValue];
  677. if(buttonIndex!=alertView.cancelButtonIndex)
  678. {
  679. if(appDelegate.order_code==nil)
  680. {
  681. [self neworder];
  682. }
  683. else
  684. {
  685. [self addtocart:count];
  686. }
  687. }
  688. return;
  689. }
  690. // int count=[self.quantity_text.text intValue];
  691. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  692. if(buttonIndex==alertView.cancelButtonIndex)
  693. {
  694. }
  695. else if(buttonIndex==1)
  696. {
  697. //open exist
  698. UIViewController *vc= [RAUtils getViewController:self];
  699. OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  700. ovc.showNavibar = true;
  701. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  702. if(appDelegate.order_code==nil)
  703. {
  704. [self neworder];
  705. }
  706. else
  707. {
  708. if(self.set_update_data)
  709. self.set_update_data(true);
  710. int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  711. for(int i=0;i<model_count;i++)
  712. {
  713. NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  714. NSString* product_id = [item valueForKey:@"product_id"];
  715. if([product_id isEqualToString:self.product_id])
  716. {
  717. self.cqty = [[item valueForKey:@"QTY"]intValue];
  718. if(self.set_cqty)
  719. self.set_cqty(self.cqty);
  720. break;
  721. }
  722. }
  723. int count=[self.quantity_text.text intValue];
  724. [self addtocart:count];
  725. [main_vc checklogin:true];
  726. }
  727. };
  728. ovc.init_style = OL_OPEN;
  729. ovc.onCancel = ^(){
  730. [main_vc checklogin:true];
  731. };
  732. [vc.navigationController pushViewController:ovc animated:true];
  733. }
  734. else
  735. {
  736. //create new;
  737. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  738. {
  739. UIViewController *vc= [RAUtils getViewController:self];
  740. ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  741. cvc.showNavibar = true;
  742. cvc.contact_type = @"Sales_Order_Customer";
  743. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  744. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  745. appDelegate.customerInfo = value;
  746. if(appDelegate.order_code==nil)
  747. [self neworder];
  748. [main_vc checklogin:true];
  749. };
  750. cvc.onCancel = ^(){
  751. UIViewController *vc= [RAUtils getViewController:self];
  752. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order" controller:vc];
  753. };
  754. cvc.onReset = ^(){
  755. [main_vc checklogin:true];
  756. };
  757. [vc.navigationController pushViewController:cvc animated:true];
  758. }
  759. else
  760. {
  761. [self neworder];
  762. }
  763. }
  764. }
  765. - (void)valueChanged:(UIStepper *)sender {
  766. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  767. [celldelegate stepClicked:(int)sender.value];
  768. }
  769. #pragma mark -
  770. #pragma mark Actions
  771. -(void)ClearPhotos
  772. {
  773. NSMutableArray *photosMutable = [self.photos mutableCopy];
  774. [photosMutable removeAllObjects];
  775. self.photos = photosMutable;
  776. [self.photoStack reloadData];
  777. }
  778. - (void)AddPhoto :(UIImage*)photo {
  779. NSMutableArray *photosMutable = [self.photos mutableCopy];
  780. [photosMutable addObject:photo];
  781. self.photos = photosMutable;
  782. [self.photoStack reloadData];
  783. self.pageControl.numberOfPages = [self.photos count];
  784. if(self.photos.count<2-1)//1 for qrcode;
  785. self.photoStack.showBorder=false;
  786. else
  787. self.photoStack.showBorder=true;
  788. }
  789. #pragma mark -
  790. #pragma mark Setup
  791. -(void)setup {
  792. // int availability = [self.count_Label.text intValue];
  793. self.stepper.minimumValue= self.step;
  794. self.stepper.maximumValue = INTMAX_MAX;
  795. self.stepper.stepValue= self.step;
  796. self.stepper.value= self.quantity;
  797. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  798. if(true)//(self.photos==nil)
  799. {
  800. self.photos = [NSArray array];
  801. }
  802. if(true)//(self.photoStack==nil)
  803. {
  804. self.photoStack.dataSource = self;
  805. self.photoStack.delegate = self;
  806. // [self addSubview:self.photoStack];
  807. self.pageControl.numberOfPages = [self.photos count];
  808. }
  809. }
  810. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  811. if (self.notifyMeBlock) {
  812. self.notifyMeBlock();
  813. }
  814. }
  815. #pragma mark - TextField Delegate
  816. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  817. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  818. int buyQTY = [newString intValue];
  819. self.stepper.value = buyQTY;
  820. return YES;
  821. }
  822. #pragma mark - Private
  823. /**检查是否缺货*/
  824. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  825. //#ifdef BUILD_NPD
  826. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  827. if (!appDelegate.bLogin || buyQty < 1) {
  828. return;
  829. }
  830. #ifdef OFFLINE_MODE
  831. if (appDelegate.offline_mode) {
  832. return;
  833. }
  834. #endif
  835. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  836. if (!appDelegate.order_code) { // 未打开订单状态
  837. if ((buyQty + cartQty) > availability) {
  838. self.btnaddCart.enabled = NO;
  839. self.btnNotifyMe.enabled = YES;
  840. } else {
  841. self.btnaddCart.enabled = YES;
  842. self.btnNotifyMe.enabled = NO;
  843. }
  844. } else {
  845. // 打开订单状态
  846. if (![Singleton sharedInstance].currentOrderIsMerged) {
  847. // Shop Order
  848. self.btnaddCart.enabled = YES;
  849. // 默认未缺货
  850. self.btnNotifyMe.enabled = NO;
  851. if ((buyQty + cartQty) > availability) { // 缺货
  852. self.btnNotifyMe.enabled = YES;
  853. }
  854. } else {
  855. // Purchase Order
  856. if ((buyQty + cartQty) > availability) { // 缺货
  857. self.btnaddCart.enabled = NO;
  858. self.btnNotifyMe.enabled = YES;
  859. } else { // 未缺货
  860. self.btnNotifyMe.enabled = NO;
  861. self.btnaddCart.enabled = YES;
  862. }
  863. }
  864. }
  865. } else { // empoyee
  866. if ((buyQty + cartQty) > availability) { // 缺货
  867. self.btnaddCart.enabled = NO;
  868. self.btnNotifyMe.enabled = YES;
  869. } else { // 未缺货
  870. self.btnNotifyMe.enabled = NO;
  871. self.btnaddCart.enabled = YES;
  872. }
  873. }
  874. //#endif
  875. }
  876. - (IBAction)introduceBtnClick:(UIButton *)sender {
  877. if (self.introduceBlock) {
  878. self.introduceBlock(sender);
  879. }
  880. }
  881. - (IBAction)descriptionBtnClick:(UIButton *)sender {
  882. if (self.descriptionBlock) {
  883. self.descriptionBlock(sender);
  884. }
  885. }
  886. - (IBAction)OnClosePlayer:(id)sender {
  887. [self.playerView stopVideo];
  888. self.playerView.hidden=true;
  889. }
  890. - (IBAction)noLoginBtnClick:(UIButton *)sender {
  891. UIApplication * app = [UIApplication sharedApplication];
  892. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  893. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  894. if(appDelegate.bLogin==false) {
  895. DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  896. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  897. loginvc.returnValue = ^(bool blogin){
  898. if(blogin) {
  899. [vc reload];
  900. [main_vc checklogin:true];
  901. }
  902. };
  903. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  904. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  905. [vc presentViewController:navi animated:YES completion:^{
  906. }];
  907. }
  908. }
  909. @end