DetailHeaderCell.m 70 KB

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