HomerModelDetailHeaderCell.m 53 KB

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