DetailHeaderCell.m 59 KB

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