DetailHeaderCell.m 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487
  1. //
  2. // DetailHeaderCell.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-5.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailHeaderCell.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. #import "RAPDFViewController.h"
  22. @implementation DetailHeaderCell
  23. @synthesize celldelegate;
  24. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  25. {
  26. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  27. if (self) {
  28. // Initialization code
  29. }
  30. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  31. // self.selector_imageView.layer.borderWidth = 1;
  32. return self;
  33. }
  34. - (void)awakeFromNib
  35. {
  36. [super awakeFromNib];
  37. #ifdef BUILD_UWAVER
  38. // self.addPortfolioBtn.title = @"Add to Hang Tag";
  39. self.btn_hangtag.hidden=false;
  40. #else
  41. self.btn_hangtag.hidden=true;
  42. #endif
  43. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  44. // self.selector_imageView.layer.borderWidth = 1;
  45. self.quantity_text.delegate = self;
  46. self.selector_Button.layer.borderWidth = 0.5;
  47. self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  48. self.selector_Button.layer.cornerRadius = 0;
  49. [self.descriptionRTLabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  50. [self.descriptionRTLabel setTextAlignment:RTTextAlignmentCenter];
  51. [self.descriptionRTLabel setFont:[UIFont systemFontOfSize:22]];
  52. // self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  53. // self.label_net_err.layer.borderWidth = 2.0;
  54. // self.label_net_err.layer.cornerRadius=15;
  55. // self.label_net_err.layer.masksToBounds=true;
  56. // Initialization code
  57. [self addObserver:self
  58. forKeyPath:@"stack_contents"
  59. options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
  60. context:@"content changed"];
  61. }
  62. -(void) dealloc
  63. {
  64. [self removeObserver:self forKeyPath:@"stack_contents"];
  65. }
  66. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  67. {
  68. if([keyPath isEqualToString:@"stack_contents"])
  69. {
  70. [self.ytplayerView stopVideo];
  71. self.ytplayerView.hidden=true;
  72. }
  73. }
  74. - (IBAction)create_HangTag:(id)sender {
  75. }
  76. - (IBAction)add_toPortfolio:(id)sender {
  77. // int count=[self.quantity_text.text intValue];
  78. UIApplication * app = [UIApplication sharedApplication];
  79. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  80. if (RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  81. [[NSNotificationCenter defaultCenter] postNotificationName:No_Rights_Notification object:nil];
  82. return;
  83. }
  84. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  85. if(appDelegate.bLogin==false)
  86. {
  87. UIViewController *vc= [RAUtils getViewController:self];
  88. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  89. // loginvc.delegate = self;
  90. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  91. loginvc.returnValue = ^(bool blogin){
  92. // UIApplication * app = [UIApplication sharedApplication];
  93. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  94. if(blogin)
  95. {
  96. if(self.set_update_data)
  97. self.set_update_data(true);
  98. [main_vc checklogin:true];
  99. [RANetwork request_addto_portfolio:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  100. NSDictionary* return_json =result;
  101. if([[return_json valueForKey:@"result"] intValue]==2)
  102. {
  103. // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  104. #ifdef RA_NOTIFICATION
  105. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  106. #else
  107. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  108. #endif
  109. if(self.WatchlistBlock!=nil)
  110. {
  111. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  112. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  113. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  114. iv.image = img;
  115. // [self.contentView addSubview:iv];
  116. self.PortfolioBlock(iv);
  117. }
  118. }
  119. else
  120. {
  121. [RAUtils message_box:@"Add to portfolio" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  122. }
  123. }];
  124. }
  125. // self.offset = 0;
  126. // [self.content_data removeAllObjects];
  127. // [self loadpage];
  128. //
  129. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  130. };
  131. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  132. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  133. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  134. [vc presentViewController:navi animated:YES completion:^{
  135. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  136. DebugLog(@"LoginViewController present.........");
  137. // self.btop = false;
  138. // <#code#>
  139. }];
  140. }
  141. else
  142. {
  143. [RANetwork request_addto_portfolio:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  144. NSDictionary* return_json =result;
  145. if([[return_json valueForKey:@"result"] intValue]==2)
  146. {
  147. #ifdef RA_NOTIFICATION
  148. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  149. #else
  150. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  151. #endif
  152. if(self.WatchlistBlock!=nil)
  153. {
  154. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  155. CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
  156. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  157. iv.image = img;
  158. // [self.contentView addSubview:iv];
  159. self.PortfolioBlock(iv);
  160. }
  161. }
  162. else
  163. {
  164. // UIViewController *vc= [RAUtils getViewController:self];
  165. [RAUtils message_box:@"Add to portfolio" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  166. }
  167. }];
  168. }
  169. }
  170. - (IBAction)add_toWatchList:(id)sender {
  171. // int count=[self.quantity_text.text intValue];
  172. UIApplication * app = [UIApplication sharedApplication];
  173. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  174. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  175. if(appDelegate.bLogin==false)
  176. {
  177. UIViewController *vc= [RAUtils getViewController:self];
  178. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  179. // loginvc.delegate = self;
  180. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  181. loginvc.returnValue = ^(bool blogin){
  182. // UIApplication * app = [UIApplication sharedApplication];
  183. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  184. if(blogin)
  185. {
  186. if(self.set_update_data)
  187. self.set_update_data(true);
  188. [main_vc checklogin:true];
  189. [RANetwork request_addto_wishlist:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  190. NSDictionary* return_json =result;
  191. if([[return_json valueForKey:@"result"] intValue]==2)
  192. {
  193. // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  194. #ifdef RA_NOTIFICATION
  195. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  196. #else
  197. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  198. #endif
  199. if(self.WatchlistBlock!=nil)
  200. {
  201. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  202. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  203. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  204. iv.image = img;
  205. // [self.contentView addSubview:iv];
  206. self.WatchlistBlock(iv);
  207. }
  208. }
  209. else
  210. {
  211. [RAUtils message_box:@"Add Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  212. }
  213. }];
  214. }
  215. // self.offset = 0;
  216. // [self.content_data removeAllObjects];
  217. // [self loadpage];
  218. //
  219. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  220. };
  221. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  222. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  223. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  224. [vc presentViewController:navi animated:YES completion:^{
  225. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  226. DebugLog(@"LoginViewController present.........");
  227. // self.btop = false;
  228. // <#code#>
  229. }];
  230. }
  231. else
  232. {
  233. [RANetwork request_addto_wishlist:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) {
  234. NSDictionary* return_json =result;
  235. if([[return_json valueForKey:@"result"] intValue]==2)
  236. {
  237. #ifdef RA_NOTIFICATION
  238. [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  239. #else
  240. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  241. #endif
  242. if(self.WatchlistBlock!=nil)
  243. {
  244. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  245. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  246. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  247. iv.image = img;
  248. // [self.contentView addSubview:iv];
  249. self.WatchlistBlock(iv);
  250. }
  251. }
  252. else
  253. {
  254. // UIViewController *vc= [RAUtils getViewController:self];
  255. [RAUtils message_box:@"Add Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ;
  256. }
  257. }];
  258. }
  259. }
  260. - (IBAction)add_toCart:(id)sender {
  261. [CartUtils add_to_cart:[RAUtils getViewController:self] selectorholder:self selector:@selector(addtocart)];
  262. return;
  263. //
  264. //
  265. // int count=[self.quantity_text.text intValue];
  266. //
  267. // UIApplication * app = [UIApplication sharedApplication];
  268. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  269. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  270. // if(appDelegate.bLogin==false)
  271. // {
  272. // UIViewController *vc= [RAUtils getViewController:self];
  273. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  274. // // loginvc.delegate = self;
  275. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  276. //
  277. // loginvc.returnValue = ^(bool blogin){
  278. //
  279. //
  280. // // UIApplication * app = [UIApplication sharedApplication];
  281. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  282. //
  283. //
  284. //
  285. //
  286. // if(blogin)
  287. // {
  288. // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true)
  289. // {
  290. // if(self.set_update_data)
  291. // self.set_update_data(true);
  292. // [main_vc checklogin:false];
  293. //
  294. //
  295. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to pending a order or a new order", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  296. //
  297. //
  298. //
  299. // // alert.
  300. // [alert show];
  301. // }
  302. // else
  303. // {
  304. // [main_vc checklogin:true];
  305. //
  306. // int c=[self.count_Label.text intValue];
  307. // DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  308. //
  309. // NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  310. //
  311. //
  312. //
  313. // if(!appDelegate.can_create_backorder && c<count)
  314. // {
  315. //
  316. // NSString *msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
  317. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"No", nil) otherButtonTitles:NSLocalizedString(@"Yes", nil), nil];
  318. //
  319. // // alert.
  320. //
  321. // alert.tag = 1234;
  322. // [alert show];
  323. // }
  324. // else
  325. // {
  326. // if(appDelegate.order_code==nil)
  327. // [ self neworder];
  328. // else
  329. // [self addtocart:count];
  330. // }
  331. //
  332. //
  333. // }
  334. // }
  335. //
  336. // // self.offset = 0;
  337. // // [self.content_data removeAllObjects];
  338. // // [self loadpage];
  339. // //
  340. // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  341. //
  342. // };
  343. //
  344. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  345. //
  346. //
  347. //
  348. //
  349. //
  350. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  351. //
  352. // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  353. // [vc presentViewController:navi animated:YES completion:^{
  354. //
  355. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  356. //
  357. // DebugLog(@"LoginViewController present.........");
  358. //
  359. // // self.btop = false;
  360. // // <#code#>
  361. // }];
  362. // }
  363. // else
  364. // {
  365. //
  366. //// if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&appDelegate.order_code==nil)
  367. // if(appDelegate.order_code==nil)
  368. // {
  369. // [main_vc checklogin:false];
  370. //
  371. // if(appDelegate.can_create_order)
  372. // {
  373. // NSString* msg =@"";
  374. // if(appDelegate.contact_id.length>0)
  375. // {
  376. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  377. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  378. //
  379. // }
  380. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  381. //
  382. // // alert.
  383. // [alert show];
  384. // }
  385. // else
  386. // {
  387. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  388. //
  389. // // alert.
  390. // [alert show];
  391. // }
  392. // }
  393. // else
  394. // {
  395. //
  396. //// if ([self.priceLabel.text isEqualToString:@"No Price."])
  397. //// {
  398. ////// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Model No Price" message:@"Cannot add model without price." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  399. //////
  400. //////
  401. //////
  402. ////// [alert show];
  403. ////
  404. ////
  405. ////
  406. //// [RAUtils alert_view:@"Cannot add model without price." title:@"Model No Price."];
  407. //// }
  408. //// else
  409. // {
  410. //
  411. // int c=[self.count_Label.text intValue];
  412. // DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  413. //
  414. // NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  415. //
  416. //
  417. //
  418. // if(c<count)
  419. // {
  420. //
  421. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:NSLocalizedString(@"Confirm add to cart. ", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Confirm", nil), nil];
  422. //
  423. // // alert.
  424. //
  425. // alert.tag = 1234;
  426. // [alert show];
  427. // }
  428. // else
  429. // {
  430. // if(appDelegate.order_code==nil)
  431. // [ self neworder];
  432. // else
  433. // [self addtocart:count];
  434. // }
  435. // }
  436. //
  437. // }
  438. // }
  439. //
  440. //
  441. //
  442. //
  443. //
  444. //
  445. //
  446. //
  447. }
  448. -(void) addtocart
  449. {
  450. int count=[self.quantity_text.text intValue];
  451. #ifdef MPACK
  452. if (count % self.step != 0) {
  453. UIViewController *vc= [RAUtils getViewController:self];
  454. [RAUtils message_box:@"Add to cart" message:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] completion:nil];
  455. return;
  456. }
  457. #endif
  458. int c=[self.count_Label.text intValue];
  459. DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  460. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  461. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  462. if(/*c<count*/!appDelegate.can_create_backorder && c == 0)
  463. {
  464. NSString *msg = nil;
  465. BOOL continueAdd = YES;
  466. // #if defined(BUILD_NPD) || defined(BUILD_USAI)
  467. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  468. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  469. if ([RASingleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
  470. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.",COMPANY_SHORT_NAME];
  471. continueAdd = NO;
  472. } else { // Shop Order购买数量大于库存需要确认
  473. msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
  474. continueAdd = YES;
  475. }
  476. }
  477. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
  478. msg = @"Item is OUT OF STOCK and not available to order.";
  479. continueAdd = NO;
  480. }
  481. // #endif
  482. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
  483. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  484. if (continueAdd) {
  485. [self addtocart:count];
  486. }
  487. }];
  488. [alertControl addAction:alertthree];
  489. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  490. }];
  491. if (continueAdd) {
  492. [alertControl addAction:alertcancel];
  493. }
  494. UIViewController *vc= [RAUtils getViewController:self];
  495. [vc presentViewController:alertControl animated:YES completion:nil];
  496. }
  497. else
  498. {
  499. [self addtocart:count];
  500. }
  501. }
  502. -(void)Hide_selector:(bool) bhide
  503. {
  504. self.selector_Button.hidden=bhide;
  505. self.selector_dorpdown.hidden=bhide;
  506. self.selector_imageView.hidden=bhide;
  507. }
  508. -(void) addtocart:(int) count
  509. {
  510. #ifdef MPACK
  511. if(self.cqty>0)
  512. {
  513. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  514. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  515. //block代码块取代了delegate
  516. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  517. int c=self.cqty+count;
  518. int m=c%self.step;
  519. if(m!=0&&appDelegate.alert_sold_in_quantities)
  520. {
  521. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  522. //block代码块取代了delegate
  523. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  524. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  525. NSDictionary* return_json = result;
  526. if([[return_json valueForKey:@"result"] intValue]==2)
  527. {
  528. // NSString* order_code = [return_json valueForKey:@"order_code"];
  529. #ifdef RA_NOTIFICATION
  530. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  531. #else
  532. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  533. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  534. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  535. #endif
  536. if(self.shopCartBlock!=nil)
  537. {
  538. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  539. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  540. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  541. iv.image = img;
  542. // [self.contentView addSubview:iv];
  543. self.shopCartBlock(iv);
  544. self.cqty +=count;
  545. if(self.set_cqty)
  546. self.set_cqty(self.cqty);
  547. }
  548. }
  549. else
  550. {
  551. UIViewController *vc= [RAUtils getViewController:self];
  552. NSString *msg = [return_json valueForKey:@"err_msg"];
  553. NSString *title = @"Add To Cart";
  554. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  555. title = @"Add To Cart: Out of Stock";
  556. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  557. self.btnNotifyMe.enabled = YES;
  558. self.btnaddCart.enabled = NO;
  559. }
  560. [RAUtils message_box:title message:msg completion:nil] ;
  561. }
  562. }];
  563. }];
  564. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  565. DebugLog(@"No");
  566. }];
  567. [alertControl addAction:actionOne];
  568. [alertControl addAction:alertthree];
  569. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  570. UIViewController *vc= [RAUtils getViewController:self];
  571. [vc presentViewController:alertControl animated:YES completion:nil];
  572. }
  573. else
  574. {
  575. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  576. NSDictionary* return_json = result;
  577. if([[return_json valueForKey:@"result"] intValue]==2)
  578. {
  579. // NSString* order_code = [return_json valueForKey:@"order_code"];
  580. #ifdef RA_NOTIFICATION
  581. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  582. #else
  583. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  584. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  585. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  586. #endif
  587. if(self.shopCartBlock!=nil)
  588. {
  589. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  590. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  591. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  592. iv.image = img;
  593. // [self.contentView addSubview:iv];
  594. self.shopCartBlock(iv);
  595. self.cqty +=count;
  596. if(self.set_cqty)
  597. self.set_cqty(self.cqty);
  598. }
  599. }
  600. else
  601. {
  602. UIViewController *vc= [RAUtils getViewController:self];
  603. NSString *msg = [return_json valueForKey:@"err_msg"];
  604. NSString *title = @"Add To Cart";
  605. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  606. title = @"Add To Cart: Out of Stock";
  607. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  608. self.btnNotifyMe.enabled = YES;
  609. self.btnaddCart.enabled = NO;
  610. }
  611. [RAUtils message_box:title message:msg completion:nil] ;
  612. }
  613. }];
  614. }
  615. }];
  616. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  617. DebugLog(@"No");
  618. }];
  619. [alertControl addAction:actionOne];
  620. [alertControl addAction:alertthree];
  621. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  622. UIViewController *vc= [RAUtils getViewController:self];
  623. [vc presentViewController:alertControl animated:YES completion:nil];
  624. }
  625. else
  626. #endif
  627. {
  628. #ifdef MPACK
  629. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  630. int c=self.cqty+count;
  631. int m=c%self.step;
  632. if(m!=0&&appDelegate.alert_sold_in_quantities)
  633. {
  634. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  635. //block代码块取代了delegate
  636. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  637. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  638. NSDictionary* return_json =result;
  639. if([[return_json valueForKey:@"result"] intValue]==2)
  640. {
  641. #ifdef RA_NOTIFICATION
  642. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  643. #else
  644. // NSString* order_code = [return_json valueForKey:@"order_code"];
  645. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  646. // appDelegate.order_code = order_code;
  647. //
  648. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  649. // appDelegate.order_code = order_code;
  650. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  651. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  652. #endif
  653. if(self.shopCartBlock!=nil)
  654. {
  655. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  656. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  657. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  658. iv.image = img;
  659. // [self.contentView addSubview:iv];
  660. self.shopCartBlock(iv);
  661. self.cqty +=count;
  662. if(self.set_cqty)
  663. self.set_cqty(self.cqty);
  664. }
  665. }
  666. else
  667. {
  668. UIViewController *vc= [RAUtils getViewController:self];
  669. NSString *msg = [return_json valueForKey:@"err_msg"];
  670. NSString *title = @"Add To Cart";
  671. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  672. title = @"Add To Cart: Out of Stock";
  673. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  674. self.btnNotifyMe.enabled = YES;
  675. self.btnaddCart.enabled = NO;
  676. }
  677. [RAUtils message_box:title message:msg completion:nil] ;
  678. }
  679. }];
  680. }];
  681. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  682. DebugLog(@"No");
  683. }];
  684. [alertControl addAction:actionOne];
  685. [alertControl addAction:alertthree];
  686. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  687. UIViewController *vc= [RAUtils getViewController:self];
  688. [vc presentViewController:alertControl animated:YES completion:nil];
  689. }
  690. else
  691. #endif
  692. {
  693. NSString* model_name=self.model_label.text;
  694. [RANetwork request_addto_cart:self.product_id count:count name:model_name completionHandler:^(NSMutableDictionary *result) {
  695. NSDictionary* return_json = result;
  696. if([[return_json valueForKey:@"result"] intValue]==2)
  697. {
  698. #ifdef RA_NOTIFICATION
  699. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  700. #else
  701. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  702. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  703. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  704. #endif
  705. if(self.shopCartBlock!=nil)
  706. {
  707. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  708. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  709. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  710. iv.image = img;
  711. // [self.contentView addSubview:iv];
  712. self.shopCartBlock(iv);
  713. self.cqty +=count;
  714. if(self.set_cqty)
  715. self.set_cqty(self.cqty);
  716. }
  717. }
  718. else
  719. {
  720. // UIViewController *vc= [RAUtils getViewController:self];
  721. NSString *msg = [return_json valueForKey:@"err_msg"];
  722. NSString *title = @"Add To Cart";
  723. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  724. title = @"Add To Cart: Out of Stock";
  725. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  726. self.btnNotifyMe.enabled = YES;
  727. self.btnaddCart.enabled = NO;
  728. }
  729. [RAUtils message_box:title message:msg completion:nil] ;
  730. }
  731. }];
  732. }
  733. }
  734. }
  735. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  736. {
  737. [super setSelected:selected animated:animated];
  738. // Configure the view for the selected state
  739. }
  740. - (IBAction)selectorOnClick:(id)sender {
  741. DebugLog(@"select click");
  742. [celldelegate SelectorClicked:(UIButton*) sender];
  743. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  744. }
  745. #pragma mark -
  746. #pragma mark Deck DataSource Protocol Methods
  747. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  748. return [self.photos count];
  749. }
  750. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  751. if(self.photos.count==0)
  752. return nil;
  753. return [self.photos objectAtIndex:index];
  754. }
  755. #pragma mark -
  756. #pragma mark Deck Delegate Protocol Methods
  757. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  758. // User started moving a photo
  759. }
  760. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  761. // User flicked the photo away, revealing the next one in the stack
  762. }
  763. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  764. self.pageControl.currentPage = index;
  765. }
  766. - (UIView *)createVideoView:(NSString*) videoID
  767. {
  768. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
  769. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  770. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  771. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
  772. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  773. titleLabel.text=@"a separated player will show here:";
  774. titleLabel.numberOfLines = 0;
  775. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  776. // titleLabel.textAlignment = NSTextAlignmentRight;
  777. titleLabel.textAlignment = NSTextAlignmentCenter;
  778. CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
  779. // CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  780. CGSize sizetitle = [RAUtils sizeWithFont:@"a separated player will show here:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  781. //[titleLabel sizeToFit];
  782. // titleLabel.center.x = demoView.center.x;
  783. titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
  784. [demoView addSubview:titleLabel];
  785. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
  786. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  787. lineLabel.text=videoID;
  788. lineLabel.numberOfLines = 0;
  789. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  790. // CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  791. CGSize sizemsg = [RAUtils sizeWithFont:videoID font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  792. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
  793. //[lineLabel sizeToFit];
  794. [demoView addSubview:lineLabel];
  795. demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  796. return demoView;
  797. }
  798. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  799. DebugLog(@"selected %lu", (unsigned long)index);
  800. NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
  801. if([item[@"type"] isEqualToString:@"video"])
  802. {
  803. NSString* video_code=item[@"code"];
  804. // [TextUtils expression_varable:video regex:<#(NSString *)#>]
  805. // video_code=@"hqNcj6_lYg0";
  806. // NSString* video_id=[self.playerView Embed2VID:video_code];
  807. //
  808. // NSDictionary *playerVars = @{
  809. // @"playsinline" : @1,
  810. // @"autoplay" : @(1),
  811. // @"rel":@0,
  812. // @"showinfo": @0,
  813. // @"modestbranding":@0,
  814. // @"enablejsapi":@1
  815. // };
  816. //
  817. // [self.playerView loadWithVideoId:video_id playerVars:playerVars];
  818. [self.ytplayerView LoadWithVid:video_code];
  819. for(UIView *v in self.ytplayerView.subviews)
  820. {
  821. if([v isKindOfClass:[UIButton class] ])
  822. [self.ytplayerView bringSubviewToFront:v];
  823. }
  824. self.ytplayerView.hidden=false;
  825. return;
  826. } else {
  827. if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
  828. return;
  829. }
  830. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  831. preVC.content = self.stack_contents;
  832. // preVC.currentIndex = index;
  833. [preVC setOffset:index];
  834. UIViewController *superVC= [RAUtils getViewController:self];
  835. [superVC.navigationController pushViewController:preVC animated:true];
  836. return;
  837. }
  838. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  839. // for (int i = 0; i < _data.count; i++) {
  840. // UIImage *imgMod = _data[i];
  841. // [imgList addObject:imgMod];
  842. // }
  843. // 调用展示窗口
  844. // ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  845. //
  846. // UIViewController *vc= [RAUtils getViewController:self];
  847. // [vc.navigationController pushViewController:imgShow animated:true];
  848. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  849. // [self presentViewController:nav animated:YES completion:nil];
  850. // UIDocumentInteractionController
  851. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  852. // preview.delegate = self;
  853. // [preview presentPreviewAnimated:YES];
  854. }
  855. -(void) neworder
  856. {
  857. // __block UIAlertController * waitalert = [RAUtils waiting_alert:[RAUtils getViewController:self] title:@"Create Order" completion:^{
  858. PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
  859. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  860. NSMutableDictionary* return_json = result;
  861. // [waitalert dismissViewControllerAnimated:YES completion:^{
  862. [pop hide];
  863. if([[return_json valueForKey:@"result"] intValue]==2)
  864. {
  865. int result=[[return_json valueForKey:@"result"] intValue];
  866. if(result==2)
  867. {
  868. //successed.
  869. NSString* order_code = [return_json valueForKey:@"orderCode"];
  870. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  871. appDelegate.order_code = order_code;
  872. int count=[self.quantity_text.text intValue];
  873. [self addtocart:count];
  874. }
  875. }
  876. else
  877. {
  878. // UIViewController *vc= [RAUtils getViewController:self];
  879. NSString *msg = [return_json valueForKey:@"err_msg"];
  880. NSString *title = @"Add To Cart";
  881. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  882. title = @"Add To Cart: Out of Stock";
  883. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  884. self.btnNotifyMe.enabled = YES;
  885. self.btnaddCart.enabled = NO;
  886. }
  887. [RAUtils message_box:title message:msg completion:nil] ;
  888. }
  889. // }];
  890. }];
  891. // }];
  892. }
  893. - (void)valueChanged:(UIStepper *)sender {
  894. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  895. [celldelegate stepClicked:(int)sender.value];
  896. // -(void) stepClicked:(int) value;
  897. // 检查缺货
  898. // NSString *cartQtyString = nil;
  899. // if (self.cqyt_label.text) {
  900. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  901. // }
  902. //
  903. // int availability = [self.count_Label.text intValue];
  904. // int buyQTY = [self.quantity_text.text intValue];
  905. // int cartQTY = [cartQtyString intValue];
  906. //
  907. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  908. }
  909. #pragma mark -
  910. #pragma mark Actions
  911. -(void)ClearPhotos
  912. {
  913. NSMutableArray *photosMutable = [self.photos mutableCopy];
  914. [photosMutable removeAllObjects];
  915. self.photos = photosMutable;
  916. [self.photoStack reloadData];
  917. }
  918. - (void)AddPhoto :(UIImage*)photo {
  919. NSMutableArray *photosMutable = [self.photos mutableCopy];
  920. [photosMutable addObject:photo];
  921. self.photos = photosMutable;
  922. [self.photoStack reloadData];
  923. self.pageControl.numberOfPages = [self.photos count];
  924. if(self.photos.count<2-1)//1 for qrcode;
  925. self.photoStack.showBorder=false;
  926. else
  927. self.photoStack.showBorder=true;
  928. }
  929. #pragma mark -
  930. #pragma mark Setup
  931. -(void)setup {
  932. // int availability = [self.count_Label.text intValue];
  933. self.stepper.minimumValue= self.step;
  934. self.stepper.maximumValue = INTMAX_MAX;
  935. self.stepper.stepValue= self.step;
  936. self.stepper.value= self.quantity;
  937. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  938. if(true)//(self.photos==nil)
  939. {
  940. self.photos = [NSArray array];
  941. }
  942. if(true)//(self.photoStack==nil)
  943. {
  944. // if(self.photoStack!=nil)
  945. // [self.photoStack removeFromSuperview];
  946. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  947. // self.photoStack.backgroundColor =[UIColor redColor];
  948. // self.photoStack.center = CGPointMake(self.center.x, 220);
  949. self.photoStack.dataSource = self;
  950. self.photoStack.delegate = self;
  951. // [self addSubview:self.photoStack];
  952. self.pageControl.numberOfPages = [self.photos count];
  953. }
  954. }
  955. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  956. if (self.notifyMeBlock) {
  957. self.notifyMeBlock();
  958. }
  959. }
  960. #pragma mark - TextField Delegate
  961. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  962. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  963. // NSString *cartQtyString = nil;
  964. // if (self.cqyt_label.text) {
  965. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  966. // }
  967. // int availability = [self.count_Label.text intValue];
  968. int buyQTY = [newString intValue];
  969. // int cartQTY = [cartQtyString intValue];
  970. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  971. self.stepper.value = buyQTY;
  972. return YES;
  973. }
  974. #pragma mark - Private
  975. /**检查是否缺货*/
  976. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  977. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  978. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  979. if (!appDelegate.bLogin || buyQty < 1) {
  980. return;
  981. }
  982. #ifdef OFFLINE_MODE
  983. if (appDelegate.offline_mode) {
  984. return;
  985. }
  986. #endif
  987. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  988. if (!appDelegate.order_code) { // 未打开订单状态
  989. if ((buyQty + cartQty) > availability) {
  990. self.btnaddCart.enabled = NO;
  991. self.btnNotifyMe.enabled = YES;
  992. } else {
  993. self.btnaddCart.enabled = YES;
  994. self.btnNotifyMe.enabled = NO;
  995. }
  996. } else {
  997. // 打开订单状态
  998. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  999. // Shop Order
  1000. self.btnaddCart.enabled = YES;
  1001. // 默认未缺货
  1002. self.btnNotifyMe.enabled = NO;
  1003. if ((buyQty + cartQty) > availability) { // 缺货
  1004. self.btnNotifyMe.enabled = YES;
  1005. }
  1006. } else {
  1007. // Purchase Order
  1008. if ((buyQty + cartQty) > availability) { // 缺货
  1009. self.btnaddCart.enabled = NO;
  1010. self.btnNotifyMe.enabled = YES;
  1011. } else { // 未缺货
  1012. self.btnNotifyMe.enabled = NO;
  1013. self.btnaddCart.enabled = YES;
  1014. }
  1015. }
  1016. }
  1017. } else { // empoyee
  1018. if ((buyQty + cartQty) > availability) { // 缺货
  1019. self.btnaddCart.enabled = NO;
  1020. self.btnNotifyMe.enabled = YES;
  1021. } else { // 未缺货
  1022. self.btnNotifyMe.enabled = NO;
  1023. self.btnaddCart.enabled = YES;
  1024. }
  1025. }
  1026. //#endif
  1027. }
  1028. - (IBAction)introduceBtnClick:(UIButton *)sender {
  1029. if (self.introduceBlock) {
  1030. self.introduceBlock(sender);
  1031. }
  1032. }
  1033. - (IBAction)descriptionBtnClick:(UIButton *)sender {
  1034. if (self.descriptionBlock) {
  1035. self.descriptionBlock(sender);
  1036. }
  1037. }
  1038. - (IBAction)OnClosePlayer:(id)sender {
  1039. [self.ytplayerView stopVideo];
  1040. self.ytplayerView.hidden=true;
  1041. }
  1042. - (IBAction)noLoginBtnClick:(UIButton *)sender {
  1043. UIApplication * app = [UIApplication sharedApplication];
  1044. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1045. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1046. if(appDelegate.bLogin==false) {
  1047. DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  1048. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1049. loginvc.returnValue = ^(bool blogin){
  1050. if(blogin) {
  1051. [vc reload];
  1052. [main_vc checklogin:true];
  1053. }
  1054. };
  1055. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1056. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1057. [vc presentViewController:navi animated:YES completion:^{
  1058. }];
  1059. }
  1060. }
  1061. @end