DetailHeaderCell.m 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  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 (appDelegate.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 = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  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 = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  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 = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  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. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  511. #ifdef MPACK
  512. if(self.cqty>0)
  513. {
  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. int c=self.cqty+count;
  630. int m=c%self.step;
  631. if(m!=0&&appDelegate.alert_sold_in_quantities)
  632. {
  633. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  634. //block代码块取代了delegate
  635. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  636. [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) {
  637. NSDictionary* return_json =result;
  638. if([[return_json valueForKey:@"result"] intValue]==2)
  639. {
  640. #ifdef RA_NOTIFICATION
  641. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  642. #else
  643. // NSString* order_code = [return_json valueForKey:@"order_code"];
  644. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  645. // appDelegate.order_code = order_code;
  646. //
  647. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  648. // appDelegate.order_code = order_code;
  649. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  650. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  651. #endif
  652. if(self.shopCartBlock!=nil)
  653. {
  654. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  655. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  656. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  657. iv.image = img;
  658. // [self.contentView addSubview:iv];
  659. self.shopCartBlock(iv);
  660. self.cqty +=count;
  661. if(self.set_cqty)
  662. self.set_cqty(self.cqty);
  663. }
  664. }
  665. else
  666. {
  667. UIViewController *vc= [RAUtils getViewController:self];
  668. NSString *msg = [return_json valueForKey:@"err_msg"];
  669. NSString *title = @"Add To Cart";
  670. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  671. title = @"Add To Cart: Out of Stock";
  672. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  673. self.btnNotifyMe.enabled = YES;
  674. self.btnaddCart.enabled = NO;
  675. }
  676. [RAUtils message_box:title message:msg completion:nil] ;
  677. }
  678. }];
  679. }];
  680. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  681. DebugLog(@"No");
  682. }];
  683. [alertControl addAction:actionOne];
  684. [alertControl addAction:alertthree];
  685. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  686. UIViewController *vc= [RAUtils getViewController:self];
  687. [vc presentViewController:alertControl animated:YES completion:nil];
  688. }
  689. else
  690. #endif
  691. {
  692. NSString* model_name=self.model_label.text;
  693. [RANetwork request_addto_cart:self.product_id count:count name:model_name completionHandler:^(NSMutableDictionary *result) {
  694. NSDictionary* return_json = result;
  695. if([[return_json valueForKey:@"result"] intValue]==2)
  696. {
  697. #ifdef RA_NOTIFICATION
  698. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  699. #else
  700. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  701. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  702. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  703. #endif
  704. if(self.shopCartBlock!=nil)
  705. {
  706. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  707. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  708. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  709. iv.image = img;
  710. // [self.contentView addSubview:iv];
  711. self.shopCartBlock(iv);
  712. self.cqty +=count;
  713. if(self.set_cqty)
  714. self.set_cqty(self.cqty);
  715. }
  716. }
  717. else
  718. {
  719. UIViewController *vc= [RAUtils getViewController:self];
  720. NSString *msg = [return_json valueForKey:@"err_msg"];
  721. NSString *title = @"Add To Cart";
  722. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  723. title = @"Add To Cart: Out of Stock";
  724. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  725. self.btnNotifyMe.enabled = YES;
  726. self.btnaddCart.enabled = NO;
  727. }
  728. [RAUtils message_box:title message:msg completion:nil] ;
  729. }
  730. }];
  731. }
  732. }
  733. }
  734. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  735. {
  736. [super setSelected:selected animated:animated];
  737. // Configure the view for the selected state
  738. }
  739. - (IBAction)selectorOnClick:(id)sender {
  740. DebugLog(@"select click");
  741. [celldelegate SelectorClicked:(UIButton*) sender];
  742. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  743. }
  744. #pragma mark -
  745. #pragma mark Deck DataSource Protocol Methods
  746. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  747. return [self.photos count];
  748. }
  749. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  750. if(self.photos.count==0)
  751. return nil;
  752. return [self.photos objectAtIndex:index];
  753. }
  754. #pragma mark -
  755. #pragma mark Deck Delegate Protocol Methods
  756. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  757. // User started moving a photo
  758. }
  759. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  760. // User flicked the photo away, revealing the next one in the stack
  761. }
  762. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  763. self.pageControl.currentPage = index;
  764. }
  765. - (UIView *)createVideoView:(NSString*) videoID
  766. {
  767. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
  768. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  769. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  770. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
  771. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  772. titleLabel.text=@"a separated player will show here:";
  773. titleLabel.numberOfLines = 0;
  774. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  775. // titleLabel.textAlignment = NSTextAlignmentRight;
  776. titleLabel.textAlignment = NSTextAlignmentCenter;
  777. CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
  778. // CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  779. CGSize sizetitle = [RAUtils sizeWithFont:@"a separated player will show here:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  780. //[titleLabel sizeToFit];
  781. // titleLabel.center.x = demoView.center.x;
  782. titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
  783. [demoView addSubview:titleLabel];
  784. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
  785. lineLabel.font = [UIFont boldSystemFontOfSize:17];
  786. lineLabel.text=videoID;
  787. lineLabel.numberOfLines = 0;
  788. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  789. // CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  790. CGSize sizemsg = [RAUtils sizeWithFont:videoID font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  791. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
  792. //[lineLabel sizeToFit];
  793. [demoView addSubview:lineLabel];
  794. demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  795. return demoView;
  796. }
  797. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  798. DebugLog(@"selected %lu", (unsigned long)index);
  799. NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
  800. if([item[@"type"] isEqualToString:@"video"])
  801. {
  802. NSString* video_code=item[@"code"];
  803. // [TextUtils expression_varable:video regex:<#(NSString *)#>]
  804. // video_code=@"hqNcj6_lYg0";
  805. // NSString* video_id=[self.playerView Embed2VID:video_code];
  806. //
  807. // NSDictionary *playerVars = @{
  808. // @"playsinline" : @1,
  809. // @"autoplay" : @(1),
  810. // @"rel":@0,
  811. // @"showinfo": @0,
  812. // @"modestbranding":@0,
  813. // @"enablejsapi":@1
  814. // };
  815. //
  816. // [self.playerView loadWithVideoId:video_id playerVars:playerVars];
  817. [self.ytplayerView LoadWithVid:video_code];
  818. for(UIView *v in self.ytplayerView.subviews)
  819. {
  820. if([v isKindOfClass:[UIButton class] ])
  821. [self.ytplayerView bringSubviewToFront:v];
  822. }
  823. self.ytplayerView.hidden=false;
  824. return;
  825. } else {
  826. if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
  827. return;
  828. }
  829. ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
  830. preVC.content = self.stack_contents;
  831. // preVC.currentIndex = index;
  832. [preVC setOffset:index];
  833. UIViewController *superVC= [RAUtils getViewController:self];
  834. [superVC.navigationController pushViewController:preVC animated:true];
  835. return;
  836. }
  837. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  838. // for (int i = 0; i < _data.count; i++) {
  839. // UIImage *imgMod = _data[i];
  840. // [imgList addObject:imgMod];
  841. // }
  842. // 调用展示窗口
  843. // ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  844. //
  845. // UIViewController *vc= [RAUtils getViewController:self];
  846. // [vc.navigationController pushViewController:imgShow animated:true];
  847. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  848. // [self presentViewController:nav animated:YES completion:nil];
  849. // UIDocumentInteractionController
  850. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  851. // preview.delegate = self;
  852. // [preview presentPreviewAnimated:YES];
  853. }
  854. -(void) neworder
  855. {
  856. // __block UIAlertController * waitalert = [RAUtils waiting_alert:[RAUtils getViewController:self] title:@"Create Order" completion:^{
  857. PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
  858. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  859. NSMutableDictionary* return_json = result;
  860. // [waitalert dismissViewControllerAnimated:YES completion:^{
  861. [pop hide];
  862. if([[return_json valueForKey:@"result"] intValue]==2)
  863. {
  864. int result=[[return_json valueForKey:@"result"] intValue];
  865. if(result==2)
  866. {
  867. //successed.
  868. NSString* order_code = [return_json valueForKey:@"orderCode"];
  869. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  870. appDelegate.order_code = order_code;
  871. int count=[self.quantity_text.text intValue];
  872. [self addtocart:count];
  873. }
  874. }
  875. else
  876. {
  877. UIViewController *vc= [RAUtils getViewController:self];
  878. NSString *msg = [return_json valueForKey:@"err_msg"];
  879. NSString *title = @"Add To Cart";
  880. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  881. title = @"Add To Cart: Out of Stock";
  882. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  883. self.btnNotifyMe.enabled = YES;
  884. self.btnaddCart.enabled = NO;
  885. }
  886. [RAUtils message_box:title message:msg completion:nil] ;
  887. }
  888. // }];
  889. }];
  890. // }];
  891. }
  892. - (void)valueChanged:(UIStepper *)sender {
  893. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  894. [celldelegate stepClicked:(int)sender.value];
  895. // -(void) stepClicked:(int) value;
  896. // 检查缺货
  897. // NSString *cartQtyString = nil;
  898. // if (self.cqyt_label.text) {
  899. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  900. // }
  901. //
  902. // int availability = [self.count_Label.text intValue];
  903. // int buyQTY = [self.quantity_text.text intValue];
  904. // int cartQTY = [cartQtyString intValue];
  905. //
  906. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  907. }
  908. #pragma mark -
  909. #pragma mark Actions
  910. -(void)ClearPhotos
  911. {
  912. NSMutableArray *photosMutable = [self.photos mutableCopy];
  913. [photosMutable removeAllObjects];
  914. self.photos = photosMutable;
  915. [self.photoStack reloadData];
  916. }
  917. - (void)AddPhoto :(UIImage*)photo {
  918. NSMutableArray *photosMutable = [self.photos mutableCopy];
  919. [photosMutable addObject:photo];
  920. self.photos = photosMutable;
  921. [self.photoStack reloadData];
  922. self.pageControl.numberOfPages = [self.photos count];
  923. if(self.photos.count<2-1)//1 for qrcode;
  924. self.photoStack.showBorder=false;
  925. else
  926. self.photoStack.showBorder=true;
  927. }
  928. #pragma mark -
  929. #pragma mark Setup
  930. -(void)setup {
  931. // int availability = [self.count_Label.text intValue];
  932. self.stepper.minimumValue= self.step;
  933. self.stepper.maximumValue = INTMAX_MAX;
  934. self.stepper.stepValue= self.step;
  935. self.stepper.value= self.quantity;
  936. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  937. if(true)//(self.photos==nil)
  938. {
  939. self.photos = [NSArray array];
  940. }
  941. if(true)//(self.photoStack==nil)
  942. {
  943. // if(self.photoStack!=nil)
  944. // [self.photoStack removeFromSuperview];
  945. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  946. // self.photoStack.backgroundColor =[UIColor redColor];
  947. // self.photoStack.center = CGPointMake(self.center.x, 220);
  948. self.photoStack.dataSource = self;
  949. self.photoStack.delegate = self;
  950. // [self addSubview:self.photoStack];
  951. self.pageControl.numberOfPages = [self.photos count];
  952. }
  953. }
  954. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  955. if (self.notifyMeBlock) {
  956. self.notifyMeBlock();
  957. }
  958. }
  959. #pragma mark - TextField Delegate
  960. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  961. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  962. // NSString *cartQtyString = nil;
  963. // if (self.cqyt_label.text) {
  964. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  965. // }
  966. // int availability = [self.count_Label.text intValue];
  967. int buyQTY = [newString intValue];
  968. // int cartQTY = [cartQtyString intValue];
  969. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  970. self.stepper.value = buyQTY;
  971. return YES;
  972. }
  973. #pragma mark - Private
  974. /**检查是否缺货*/
  975. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  976. //#if defined(BUILD_NPD) || defined(BUILD_USAI)
  977. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  978. if (!appDelegate.bLogin || buyQty < 1) {
  979. return;
  980. }
  981. #ifdef OFFLINE_MODE
  982. if (appDelegate.offline_mode) {
  983. return;
  984. }
  985. #endif
  986. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  987. if (!appDelegate.order_code) { // 未打开订单状态
  988. if ((buyQty + cartQty) > availability) {
  989. self.btnaddCart.enabled = NO;
  990. self.btnNotifyMe.enabled = YES;
  991. } else {
  992. self.btnaddCart.enabled = YES;
  993. self.btnNotifyMe.enabled = NO;
  994. }
  995. } else {
  996. // 打开订单状态
  997. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  998. // Shop Order
  999. self.btnaddCart.enabled = YES;
  1000. // 默认未缺货
  1001. self.btnNotifyMe.enabled = NO;
  1002. if ((buyQty + cartQty) > availability) { // 缺货
  1003. self.btnNotifyMe.enabled = YES;
  1004. }
  1005. } else {
  1006. // Purchase Order
  1007. if ((buyQty + cartQty) > availability) { // 缺货
  1008. self.btnaddCart.enabled = NO;
  1009. self.btnNotifyMe.enabled = YES;
  1010. } else { // 未缺货
  1011. self.btnNotifyMe.enabled = NO;
  1012. self.btnaddCart.enabled = YES;
  1013. }
  1014. }
  1015. }
  1016. } else { // empoyee
  1017. if ((buyQty + cartQty) > availability) { // 缺货
  1018. self.btnaddCart.enabled = NO;
  1019. self.btnNotifyMe.enabled = YES;
  1020. } else { // 未缺货
  1021. self.btnNotifyMe.enabled = NO;
  1022. self.btnaddCart.enabled = YES;
  1023. }
  1024. }
  1025. //#endif
  1026. }
  1027. - (IBAction)introduceBtnClick:(UIButton *)sender {
  1028. if (self.introduceBlock) {
  1029. self.introduceBlock(sender);
  1030. }
  1031. }
  1032. - (IBAction)descriptionBtnClick:(UIButton *)sender {
  1033. if (self.descriptionBlock) {
  1034. self.descriptionBlock(sender);
  1035. }
  1036. }
  1037. - (IBAction)OnClosePlayer:(id)sender {
  1038. [self.ytplayerView stopVideo];
  1039. self.ytplayerView.hidden=true;
  1040. }
  1041. - (IBAction)noLoginBtnClick:(UIButton *)sender {
  1042. UIApplication * app = [UIApplication sharedApplication];
  1043. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1044. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1045. if(appDelegate.bLogin==false) {
  1046. DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
  1047. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1048. loginvc.returnValue = ^(bool blogin){
  1049. if(blogin) {
  1050. [vc reload];
  1051. [main_vc checklogin:true];
  1052. }
  1053. };
  1054. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1055. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1056. [vc presentViewController:navi animated:YES completion:^{
  1057. }];
  1058. }
  1059. }
  1060. @end