HomerModelDetailHeaderCell.m 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  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' >&emsp;Incoming stock: %@</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' >&emsp;Arrival Date: %@</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. #ifdef RA_NOTIFICATION
  139. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  140. #else
  141. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  142. #endif
  143. if(self.WatchlistBlock!=nil)
  144. {
  145. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  146. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  147. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  148. iv.image = img;
  149. self.PortfolioBlock(iv);
  150. }
  151. }
  152. else
  153. {
  154. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  155. }
  156. });
  157. });
  158. }
  159. };
  160. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  161. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  162. [vc presentViewController:navi animated:YES completion:^{
  163. }];
  164. }
  165. else
  166. {
  167. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  168. NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
  169. dispatch_async(dispatch_get_main_queue(), ^{
  170. if([[return_json valueForKey:@"result"] intValue]==2)
  171. {
  172. #ifdef RA_NOTIFICATION
  173. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  174. #else
  175. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  176. #endif
  177. if(self.WatchlistBlock!=nil)
  178. {
  179. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  180. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  181. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  182. iv.image = img;
  183. self.PortfolioBlock(iv);
  184. }
  185. }
  186. else
  187. {
  188. UIViewController *vc= [RAUtils getViewController:self];
  189. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
  190. }
  191. });
  192. });
  193. }
  194. }
  195. - (IBAction)add_toWatchList:(id)sender {
  196. UIApplication * app = [UIApplication sharedApplication];
  197. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  198. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  199. if(appDelegate.bLogin==false)
  200. {
  201. UIViewController *vc= [RAUtils getViewController:self];
  202. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  203. loginvc.returnValue = ^(bool blogin){
  204. if(blogin)
  205. {
  206. if(self.set_update_data)
  207. self.set_update_data(true);
  208. [main_vc checklogin:true];
  209. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  210. NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  211. dispatch_async(dispatch_get_main_queue(), ^{
  212. if([[return_json valueForKey:@"result"] intValue]==2)
  213. {
  214. #ifdef RA_NOTIFICATION
  215. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  216. #else
  217. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  218. #endif
  219. if(self.WatchlistBlock!=nil)
  220. {
  221. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  222. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  223. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  224. iv.image = img;
  225. self.WatchlistBlock(iv);
  226. }
  227. }
  228. else
  229. {
  230. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  231. }
  232. });
  233. });
  234. }
  235. };
  236. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  237. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  238. [vc presentViewController:navi animated:YES completion:^{
  239. }];
  240. }
  241. else
  242. {
  243. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  244. NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
  245. dispatch_async(dispatch_get_main_queue(), ^{
  246. if([[return_json valueForKey:@"result"] intValue]==2)
  247. {
  248. #ifdef RA_NOTIFICATION
  249. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  250. #else
  251. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  252. #endif
  253. if(self.WatchlistBlock!=nil)
  254. {
  255. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  256. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  257. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  258. iv.image = img;
  259. self.WatchlistBlock(iv);
  260. }
  261. }
  262. else
  263. {
  264. UIViewController *vc= [RAUtils getViewController:self];
  265. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
  266. }
  267. });
  268. });
  269. }
  270. }
  271. - (IBAction)add_toCart:(id)sender {
  272. UIViewController *vc= [RAUtils getViewController:self];
  273. [CartUtils add_to_cart:vc selectorholder:self selector:@selector(addtocart)];
  274. return;
  275. }
  276. -(void) addtocart
  277. {
  278. int count=[self.quantity_text.text intValue];
  279. #ifdef MPACK
  280. if (count % self.step != 0) {
  281. UIViewController *vc= [RAUtils getViewController:self];
  282. [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Add to cart" controller:vc];
  283. return;
  284. }
  285. #endif
  286. int c=[self.count_Label.text intValue];
  287. DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  288. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  289. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  290. if(/*c<count*/!appDelegate.can_create_backorder && c == 0)
  291. {
  292. NSString *msg = nil;
  293. BOOL continueAdd = YES;
  294. // #if defined(BUILD_NPD) || defined(BUILD_USAI)
  295. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  296. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  297. if ([Singleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
  298. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.",COMPANY_SHORT_NAME];
  299. continueAdd = NO;
  300. } else { // Shop Order购买数量大于库存需要确认
  301. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
  302. continueAdd = YES;
  303. }
  304. }
  305. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
  306. msg = @"Item is OUT OF STOCK and not available to order.";
  307. continueAdd = NO;
  308. }
  309. // #endif
  310. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
  311. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  312. if (continueAdd) {
  313. [self addtocart:count];
  314. }
  315. }];
  316. [alertControl addAction:alertthree];
  317. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  318. }];
  319. if (continueAdd) {
  320. [alertControl addAction:alertcancel];
  321. }
  322. UIViewController *vc= [RAUtils getViewController:self];
  323. [vc presentViewController:alertControl animated:YES completion:nil];
  324. }
  325. else
  326. {
  327. [self addtocart:count];
  328. }
  329. }
  330. -(void)Hide_selector:(bool) bhide
  331. {
  332. // self.selector_Button.hidden=bhide;
  333. // self.selector_dorpdown.hidden=bhide;
  334. // self.selector_imageView.hidden=bhide;
  335. //
  336. }
  337. -(void) addtocart:(int) count
  338. {
  339. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  340. if(self.cqty>0)
  341. {
  342. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  343. //block代码块取代了delegate
  344. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  345. int c=self.cqty+count;
  346. int m=c%self.step;
  347. if(m!=0&&appDelegate.alert_sold_in_quantities)
  348. {
  349. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  350. //block代码块取代了delegate
  351. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  352. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  353. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  354. dispatch_async(dispatch_get_main_queue(), ^{
  355. if([[return_json valueForKey:@"result"] intValue]==2)
  356. {
  357. // NSString* order_code = [return_json valueForKey:@"order_code"];
  358. #ifdef RA_NOTIFICATION
  359. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  360. #else
  361. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  362. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  363. #endif
  364. if(self.shopCartBlock!=nil)
  365. {
  366. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  367. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  368. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  369. iv.image = img;
  370. // [self.contentView addSubview:iv];
  371. self.shopCartBlock(iv);
  372. self.cqty +=count;
  373. if(self.set_cqty)
  374. self.set_cqty(self.cqty);
  375. }
  376. }
  377. else
  378. {
  379. UIViewController *vc= [RAUtils getViewController:self];
  380. NSString *msg = [return_json valueForKey:@"err_msg"];
  381. NSString *title = @"Add To Cart";
  382. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  383. title = @"Add To Cart: Out of Stock";
  384. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  385. self.btnNotifyMe.enabled = YES;
  386. self.btnaddCart.enabled = NO;
  387. }
  388. [RAUtils message_alert:msg title:title controller:vc] ;
  389. }
  390. });
  391. });
  392. }];
  393. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  394. DebugLog(@"No");
  395. }];
  396. [alertControl addAction:actionOne];
  397. [alertControl addAction:alertthree];
  398. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  399. UIViewController *vc= [RAUtils getViewController:self];
  400. [vc presentViewController:alertControl animated:YES completion:nil];
  401. }
  402. else
  403. {
  404. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  405. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  406. dispatch_async(dispatch_get_main_queue(), ^{
  407. if([[return_json valueForKey:@"result"] intValue]==2)
  408. {
  409. // NSString* order_code = [return_json valueForKey:@"order_code"];
  410. #ifdef RA_NOTIFICATION
  411. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  412. #else
  413. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  414. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  415. #endif
  416. if(self.shopCartBlock!=nil)
  417. {
  418. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  419. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  420. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  421. iv.image = img;
  422. // [self.contentView addSubview:iv];
  423. self.shopCartBlock(iv);
  424. self.cqty +=count;
  425. if(self.set_cqty)
  426. self.set_cqty(self.cqty);
  427. }
  428. }
  429. else
  430. {
  431. UIViewController *vc= [RAUtils getViewController:self];
  432. NSString *msg = [return_json valueForKey:@"err_msg"];
  433. NSString *title = @"Add To Cart";
  434. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  435. title = @"Add To Cart: Out of Stock";
  436. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  437. self.btnNotifyMe.enabled = YES;
  438. self.btnaddCart.enabled = NO;
  439. }
  440. [RAUtils message_alert:msg title:title controller:vc] ;
  441. }
  442. });
  443. });
  444. }
  445. }];
  446. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  447. DebugLog(@"No");
  448. }];
  449. [alertControl addAction:actionOne];
  450. [alertControl addAction:alertthree];
  451. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  452. UIViewController *vc= [RAUtils getViewController:self];
  453. [vc presentViewController:alertControl animated:YES completion:nil];
  454. }
  455. else
  456. {
  457. int c=self.cqty+count;
  458. int m=c%self.step;
  459. if(m!=0&&appDelegate.alert_sold_in_quantities)
  460. {
  461. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  462. //block代码块取代了delegate
  463. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  464. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  465. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  466. dispatch_async(dispatch_get_main_queue(), ^{
  467. if([[return_json valueForKey:@"result"] intValue]==2)
  468. {
  469. // NSString* order_code = [return_json valueForKey:@"order_code"];
  470. #ifdef RA_NOTIFICATION
  471. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  472. #else
  473. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  474. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  475. #endif
  476. if(self.shopCartBlock!=nil)
  477. {
  478. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  479. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  480. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  481. iv.image = img;
  482. // [self.contentView addSubview:iv];
  483. self.shopCartBlock(iv);
  484. self.cqty +=count;
  485. if(self.set_cqty)
  486. self.set_cqty(self.cqty);
  487. }
  488. }
  489. else
  490. {
  491. UIViewController *vc= [RAUtils getViewController:self];
  492. NSString *msg = [return_json valueForKey:@"err_msg"];
  493. NSString *title = @"Add To Cart";
  494. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  495. title = @"Add To Cart: Out of Stock";
  496. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  497. self.btnNotifyMe.enabled = YES;
  498. self.btnaddCart.enabled = NO;
  499. }
  500. [RAUtils message_alert:msg title:title controller:vc] ;
  501. }
  502. });
  503. });
  504. }];
  505. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  506. DebugLog(@"No");
  507. }];
  508. [alertControl addAction:actionOne];
  509. [alertControl addAction:alertthree];
  510. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  511. UIViewController *vc= [RAUtils getViewController:self];
  512. [vc presentViewController:alertControl animated:YES completion:nil];
  513. }
  514. else
  515. {
  516. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  517. NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
  518. dispatch_async(dispatch_get_main_queue(), ^{
  519. if([[return_json valueForKey:@"result"] intValue]==2)
  520. {
  521. // NSString* order_code = [return_json valueForKey:@"order_code"];
  522. #ifdef RA_NOTIFICATION
  523. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  524. #else
  525. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  526. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  527. #endif
  528. if(self.shopCartBlock!=nil)
  529. {
  530. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  531. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  532. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  533. iv.image = img;
  534. // [self.contentView addSubview:iv];
  535. self.shopCartBlock(iv);
  536. self.cqty +=count;
  537. if(self.set_cqty)
  538. self.set_cqty(self.cqty);
  539. }
  540. }
  541. else
  542. {
  543. UIViewController *vc= [RAUtils getViewController:self];
  544. NSString *msg = [return_json valueForKey:@"err_msg"];
  545. NSString *title = @"Add To Cart";
  546. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  547. title = @"Add To Cart: Out of Stock";
  548. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  549. self.btnNotifyMe.enabled = YES;
  550. self.btnaddCart.enabled = NO;
  551. }
  552. [RAUtils message_alert:msg title:title controller:vc] ;
  553. }
  554. });
  555. });
  556. }
  557. }
  558. }
  559. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  560. {
  561. [super setSelected:selected animated:animated];
  562. // Configure the view for the selected state
  563. }
  564. - (IBAction)selectorOnClick:(id)sender {
  565. DebugLog(@"select click");
  566. [celldelegate SelectorClicked:(UIButton*) sender];
  567. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  568. }
  569. #pragma mark -
  570. #pragma mark Deck DataSource Protocol Methods
  571. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  572. return [self.photos count];
  573. }
  574. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  575. if(self.photos.count==0)
  576. return nil;
  577. return [self.photos objectAtIndex:index];
  578. }
  579. #pragma mark -
  580. #pragma mark Deck Delegate Protocol Methods
  581. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  582. // User started moving a photo
  583. }
  584. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  585. // User flicked the photo away, revealing the next one in the stack
  586. }
  587. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  588. self.pageControl.currentPage = index;
  589. }
  590. - (UIView *)createVideoView:(NSString*) videoID
  591. {
  592. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
  593. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  594. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  595. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
  596. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  597. titleLabel.text=@"a separated player will show here:";
  598. titleLabel.numberOfLines = 0;
  599. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  600. // titleLabel.textAlignment = NSTextAlignmentRight;
  601. titleLabel.textAlignment = NSTextAlignmentCenter;
  602. CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
  603. CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  604. //[titleLabel sizeToFit];
  605. // titleLabel.center.x = demoView.center.x;
  606. titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
  607. [demoView addSubview:titleLabel];
  608. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
  609. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  610. lineLabel.text=videoID;
  611. lineLabel.numberOfLines = 0;
  612. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  613. CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  614. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
  615. //[lineLabel sizeToFit];
  616. [demoView addSubview:lineLabel];
  617. demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  618. return demoView;
  619. }
  620. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  621. DebugLog(@"selected %lu", (unsigned long)index);
  622. NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
  623. if([item[@"type"] isEqualToString:@"video"])
  624. {
  625. NSString* video_code=item[@"code"];
  626. // [TextUtils expression_varable:video regex:<#(NSString *)#>]
  627. NSString* video_id=[self.playerView Embed2VID:video_code];
  628. NSDictionary *playerVars = @{
  629. @"playsinline" : @1,
  630. @"autoplay" : @(1),
  631. @"rel":@0,
  632. @"showinfo": @0,
  633. @"modestbranding":@0,
  634. @"enablejsapi":@1
  635. };
  636. [self.playerView loadWithVideoId:video_id playerVars:playerVars];
  637. for(UIView *v in self.playerView.subviews)
  638. {
  639. if([v isKindOfClass:[UIButton class] ])
  640. [self.playerView bringSubviewToFront:v];
  641. }
  642. self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
  643. self.playerView.hidden=false;
  644. return;
  645. } else {
  646. if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
  647. return;
  648. }
  649. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  650. preVC.content = self.stack_contents;
  651. // preVC.currentIndex = index;
  652. [preVC setOffset:index];
  653. UIViewController *superVC= [RAUtils getViewController:self];
  654. [superVC.navigationController pushViewController:preVC animated:true];
  655. return;
  656. }
  657. // }
  658. // 调用展示窗口
  659. ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  660. UIViewController *vc= [RAUtils getViewController:self];
  661. [vc.navigationController pushViewController:imgShow animated:true];
  662. }
  663. -(void) neworder
  664. {
  665. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  666. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  667. NSDictionary* return_json = [RANetwork new_Order];
  668. dispatch_async(dispatch_get_main_queue(), ^{
  669. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  670. if([[return_json valueForKey:@"result"] intValue]==2)
  671. {
  672. int result=[[return_json valueForKey:@"result"] intValue];
  673. if(result==2)
  674. {
  675. //successed.
  676. NSString* order_code = [return_json valueForKey:@"orderCode"];
  677. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  678. appDelegate.order_code = order_code;
  679. int count=[self.quantity_text.text intValue];
  680. [self addtocart:count];
  681. }
  682. }
  683. else
  684. {
  685. UIViewController *vc= [RAUtils getViewController:self];
  686. NSString *msg = [return_json valueForKey:@"err_msg"];
  687. NSString *title = @"Add To Cart";
  688. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  689. title = @"Add To Cart: Out of Stock";
  690. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  691. self.btnNotifyMe.enabled = YES;
  692. self.btnaddCart.enabled = NO;
  693. }
  694. [RAUtils message_alert:msg title:title controller:vc] ;
  695. }
  696. });
  697. });
  698. }
  699. #pragma mark - UIAlertViewDelegate
  700. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  701. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  702. {
  703. UIApplication * app = [UIApplication sharedApplication];
  704. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  705. if(alertView.tag==1234)//库存小于0
  706. {
  707. // availability warring;
  708. int count=[self.quantity_text.text intValue];
  709. if(buttonIndex!=alertView.cancelButtonIndex)
  710. {
  711. if(appDelegate.order_code==nil)
  712. {
  713. [self neworder];
  714. }
  715. else
  716. {
  717. [self addtocart:count];
  718. }
  719. }
  720. return;
  721. }
  722. // int count=[self.quantity_text.text intValue];
  723. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  724. if(buttonIndex==alertView.cancelButtonIndex)
  725. {
  726. }
  727. else if(buttonIndex==1)
  728. {
  729. //open exist
  730. UIViewController *vc= [RAUtils getViewController:self];
  731. OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  732. ovc.showNavibar = true;
  733. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  734. if(appDelegate.order_code==nil)
  735. {
  736. [self neworder];
  737. }
  738. else
  739. {
  740. if(self.set_update_data)
  741. self.set_update_data(true);
  742. int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  743. for(int i=0;i<model_count;i++)
  744. {
  745. NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  746. NSString* product_id = [item valueForKey:@"product_id"];
  747. if([product_id isEqualToString:self.product_id])
  748. {
  749. self.cqty = [[item valueForKey:@"QTY"]intValue];
  750. if(self.set_cqty)
  751. self.set_cqty(self.cqty);
  752. break;
  753. }
  754. }
  755. int count=[self.quantity_text.text intValue];
  756. [self addtocart:count];
  757. [main_vc checklogin:true];
  758. }
  759. };
  760. ovc.init_style = OL_OPEN;
  761. ovc.onCancel = ^(){
  762. [main_vc checklogin:true];
  763. };
  764. [vc.navigationController pushViewController:ovc animated:true];
  765. }
  766. else
  767. {
  768. //create new;
  769. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  770. {
  771. UIViewController *vc= [RAUtils getViewController:self];
  772. ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  773. cvc.showNavibar = true;
  774. cvc.contact_type = @"Sales_Order_Customer";
  775. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  776. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  777. appDelegate.customerInfo = value;
  778. if(appDelegate.order_code==nil)
  779. [self neworder];
  780. [main_vc checklogin:true];
  781. };
  782. cvc.onCancel = ^(){
  783. UIViewController *vc= [RAUtils getViewController:self];
  784. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order" controller:vc];
  785. };
  786. cvc.onReset = ^(){
  787. [main_vc checklogin:true];
  788. };
  789. [vc.navigationController pushViewController:cvc animated:true];
  790. }
  791. else
  792. {
  793. [self neworder];
  794. }
  795. }
  796. }
  797. - (void)valueChanged:(UIStepper *)sender {
  798. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  799. [celldelegate stepClicked:(int)sender.value];
  800. }
  801. #pragma mark -
  802. #pragma mark Actions
  803. -(void)ClearPhotos
  804. {
  805. NSMutableArray *photosMutable = [self.photos mutableCopy];
  806. [photosMutable removeAllObjects];
  807. self.photos = photosMutable;
  808. [self.photoStack reloadData];
  809. }
  810. - (void)AddPhoto :(UIImage*)photo {
  811. NSMutableArray *photosMutable = [self.photos mutableCopy];
  812. [photosMutable addObject:photo];
  813. self.photos = photosMutable;
  814. [self.photoStack reloadData];
  815. self.pageControl.numberOfPages = [self.photos count];
  816. if(self.photos.count<2-1)//1 for qrcode;
  817. self.photoStack.showBorder=false;
  818. else
  819. self.photoStack.showBorder=true;
  820. }
  821. #pragma mark -
  822. #pragma mark Setup
  823. -(void)setup {
  824. // int availability = [self.count_Label.text intValue];
  825. self.stepper.minimumValue= self.step;
  826. self.stepper.maximumValue = INTMAX_MAX;
  827. self.stepper.stepValue= self.step;
  828. self.stepper.value= self.quantity;
  829. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  830. if(true)//(self.photos==nil)
  831. {
  832. self.photos = [NSArray array];
  833. }
  834. if(true)//(self.photoStack==nil)
  835. {
  836. self.photoStack.dataSource = self;
  837. self.photoStack.delegate = self;
  838. // [self addSubview:self.photoStack];
  839. self.pageControl.numberOfPages = [self.photos count];
  840. }
  841. }
  842. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  843. if (self.notifyMeBlock) {
  844. self.notifyMeBlock();
  845. }
  846. }
  847. #pragma mark - TextField Delegate
  848. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  849. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  850. int buyQTY = [newString intValue];
  851. self.stepper.value = buyQTY;
  852. return YES;
  853. }
  854. #pragma mark - Private
  855. /**检查是否缺货*/
  856. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  857. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  858. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  859. if (!appDelegate.bLogin || buyQty < 1) {
  860. return;
  861. }
  862. #ifdef OFFLINE_MODE
  863. if (appDelegate.offline_mode) {
  864. return;
  865. }
  866. #endif
  867. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  868. if (!appDelegate.order_code) { // 未打开订单状态
  869. if ((buyQty + cartQty) > availability) {
  870. self.btnaddCart.enabled = NO;
  871. self.btnNotifyMe.enabled = YES;
  872. } else {
  873. self.btnaddCart.enabled = YES;
  874. self.btnNotifyMe.enabled = NO;
  875. }
  876. } else {
  877. // 打开订单状态
  878. if (![Singleton sharedInstance].currentOrderIsMerged) {
  879. // Shop Order
  880. self.btnaddCart.enabled = YES;
  881. // 默认未缺货
  882. self.btnNotifyMe.enabled = NO;
  883. if ((buyQty + cartQty) > availability) { // 缺货
  884. self.btnNotifyMe.enabled = YES;
  885. }
  886. } else {
  887. // Purchase Order
  888. if ((buyQty + cartQty) > availability) { // 缺货
  889. self.btnaddCart.enabled = NO;
  890. self.btnNotifyMe.enabled = YES;
  891. } else { // 未缺货
  892. self.btnNotifyMe.enabled = NO;
  893. self.btnaddCart.enabled = YES;
  894. }
  895. }
  896. }
  897. } else { // empoyee
  898. if ((buyQty + cartQty) > availability) { // 缺货
  899. self.btnaddCart.enabled = NO;
  900. self.btnNotifyMe.enabled = YES;
  901. } else { // 未缺货
  902. self.btnNotifyMe.enabled = NO;
  903. self.btnaddCart.enabled = YES;
  904. }
  905. }
  906. //#endif
  907. }
  908. - (IBAction)introduceBtnClick:(UIButton *)sender {
  909. if (self.introduceBlock) {
  910. self.introduceBlock(sender);
  911. }
  912. }
  913. - (IBAction)descriptionBtnClick:(UIButton *)sender {
  914. if (self.descriptionBlock) {
  915. self.descriptionBlock(sender);
  916. }
  917. }
  918. - (IBAction)OnClosePlayer:(id)sender {
  919. [self.playerView stopVideo];
  920. self.playerView.hidden=true;
  921. }
  922. - (IBAction)noLoginBtnClick:(UIButton *)sender {
  923. UIApplication * app = [UIApplication sharedApplication];
  924. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  925. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  926. if(appDelegate.bLogin==false) {
  927. DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  928. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  929. loginvc.returnValue = ^(bool blogin){
  930. if(blogin) {
  931. [vc reload];
  932. [main_vc checklogin:true];
  933. }
  934. };
  935. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  936. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  937. [vc presentViewController:navi animated:YES completion:^{
  938. }];
  939. }
  940. }
  941. @end