DetailHeaderCell.m 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  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(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. if(/*c<count*/c == 0)
  356. {
  357. NSString *msg = nil;
  358. BOOL continueAdd = YES;
  359. #ifdef BUILD_NPD
  360. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  361. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  362. if ([Singleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
  363. msg = @"Item is OUT OF STOCK and not available to order from NPD.";
  364. continueAdd = NO;
  365. } else { // Shop Order购买数量大于库存需要确认
  366. msg = @"Item is OUT OF STOCK and not available to order from NPD.\nAdd to cart anyway?";
  367. continueAdd = YES;
  368. }
  369. }
  370. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
  371. msg = @"Item is OUT OF STOCK and not available to order.";
  372. continueAdd = NO;
  373. }
  374. #endif
  375. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
  376. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  377. if (continueAdd) {
  378. [self addtocart:count];
  379. }
  380. }];
  381. [alertControl addAction:alertthree];
  382. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  383. }];
  384. if (continueAdd) {
  385. [alertControl addAction:alertcancel];
  386. }
  387. UIViewController *vc= [RAUtils getViewController:self];
  388. [vc presentViewController:alertControl animated:YES completion:nil];
  389. }
  390. else
  391. {
  392. [self addtocart:count];
  393. }
  394. }
  395. -(void)Hide_selector:(bool) bhide
  396. {
  397. self.selector_Button.hidden=bhide;
  398. self.selector_dorpdown.hidden=bhide;
  399. self.selector_imageView.hidden=bhide;
  400. }
  401. -(void) addtocart:(int) count
  402. {
  403. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  404. if(self.cqty>0)
  405. {
  406. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  407. //block代码块取代了delegate
  408. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  409. int c=self.cqty+count;
  410. int m=c%self.step;
  411. if(m!=0&&appDelegate.alert_sold_in_quantities)
  412. {
  413. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  414. //block代码块取代了delegate
  415. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  416. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  417. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count name:self.model_label.text];
  418. dispatch_async(dispatch_get_main_queue(), ^{
  419. if([[return_json valueForKey:@"result"] intValue]==2)
  420. {
  421. // NSString* order_code = [return_json valueForKey:@"order_code"];
  422. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  423. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  424. if(self.shopCartBlock!=nil)
  425. {
  426. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  427. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  428. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  429. iv.image = img;
  430. // [self.contentView addSubview:iv];
  431. self.shopCartBlock(iv);
  432. self.cqty +=count;
  433. if(self.set_cqty)
  434. self.set_cqty(self.cqty);
  435. }
  436. }
  437. else
  438. {
  439. UIViewController *vc= [RAUtils getViewController:self];
  440. NSString *msg = [return_json valueForKey:@"err_msg"];
  441. NSString *title = @"Add To Cart";
  442. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  443. title = @"Add To Cart: Out of Stock";
  444. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  445. self.btnNotifyMe.enabled = YES;
  446. self.btnaddCart.enabled = NO;
  447. }
  448. [RAUtils message_alert:msg title:title controller:vc] ;
  449. }
  450. });
  451. });
  452. }];
  453. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  454. DebugLog(@"No");
  455. }];
  456. [alertControl addAction:actionOne];
  457. [alertControl addAction:alertthree];
  458. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  459. UIViewController *vc= [RAUtils getViewController:self];
  460. [vc presentViewController:alertControl animated:YES completion:nil];
  461. }
  462. else
  463. {
  464. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  465. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count name:self.model_label.text];
  466. dispatch_async(dispatch_get_main_queue(), ^{
  467. if([[return_json valueForKey:@"result"] intValue]==2)
  468. {
  469. // NSString* order_code = [return_json valueForKey:@"order_code"];
  470. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  471. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  472. if(self.shopCartBlock!=nil)
  473. {
  474. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  475. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  476. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  477. iv.image = img;
  478. // [self.contentView addSubview:iv];
  479. self.shopCartBlock(iv);
  480. self.cqty +=count;
  481. if(self.set_cqty)
  482. self.set_cqty(self.cqty);
  483. }
  484. }
  485. else
  486. {
  487. UIViewController *vc= [RAUtils getViewController:self];
  488. NSString *msg = [return_json valueForKey:@"err_msg"];
  489. NSString *title = @"Add To Cart";
  490. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  491. title = @"Add To Cart: Out of Stock";
  492. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  493. self.btnNotifyMe.enabled = YES;
  494. self.btnaddCart.enabled = NO;
  495. }
  496. [RAUtils message_alert:msg title:title controller:vc] ;
  497. }
  498. });
  499. });
  500. }
  501. //
  502. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  503. //
  504. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  505. //
  506. // dispatch_async(dispatch_get_main_queue(), ^{
  507. //
  508. //
  509. //
  510. // if([[return_json valueForKey:@"result"] intValue]==2)
  511. // {
  512. //
  513. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  514. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  515. //// appDelegate.order_code = order_code;
  516. ////
  517. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  518. //// appDelegate.order_code = order_code;
  519. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  520. //
  521. //
  522. // if(self.shopCartBlock!=nil)
  523. // {
  524. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  525. //
  526. //
  527. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  528. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  529. // iv.image = img;
  530. // // [self.contentView addSubview:iv];
  531. // self.shopCartBlock(iv);
  532. //
  533. // self.cqty +=count;
  534. // if(self.set_cqty)
  535. // self.set_cqty(self.cqty);
  536. //
  537. // }
  538. //
  539. //
  540. // }
  541. // else
  542. // {
  543. // UIViewController *vc= [RAUtils getViewController:self];
  544. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  545. // }
  546. //
  547. //
  548. //
  549. //
  550. // });
  551. // });
  552. //
  553. }];
  554. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  555. DebugLog(@"No");
  556. }];
  557. [alertControl addAction:actionOne];
  558. [alertControl addAction:alertthree];
  559. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  560. UIViewController *vc= [RAUtils getViewController:self];
  561. [vc presentViewController:alertControl animated:YES completion:nil];
  562. }
  563. else
  564. {
  565. int c=self.cqty+count;
  566. int m=c%self.step;
  567. if(m!=0&&appDelegate.alert_sold_in_quantities)
  568. {
  569. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  570. //block代码块取代了delegate
  571. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  572. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  573. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count name:self.model_label.text];
  574. dispatch_async(dispatch_get_main_queue(), ^{
  575. if([[return_json valueForKey:@"result"] intValue]==2)
  576. {
  577. // NSString* order_code = [return_json valueForKey:@"order_code"];
  578. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  579. // appDelegate.order_code = order_code;
  580. //
  581. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  582. // appDelegate.order_code = order_code;
  583. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  584. if(self.shopCartBlock!=nil)
  585. {
  586. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  587. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  588. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  589. iv.image = img;
  590. // [self.contentView addSubview:iv];
  591. self.shopCartBlock(iv);
  592. self.cqty +=count;
  593. if(self.set_cqty)
  594. self.set_cqty(self.cqty);
  595. }
  596. }
  597. else
  598. {
  599. UIViewController *vc= [RAUtils getViewController:self];
  600. NSString *msg = [return_json valueForKey:@"err_msg"];
  601. NSString *title = @"Add To Cart";
  602. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  603. title = @"Add To Cart: Out of Stock";
  604. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  605. self.btnNotifyMe.enabled = YES;
  606. self.btnaddCart.enabled = NO;
  607. }
  608. [RAUtils message_alert:msg title:title controller:vc] ;
  609. }
  610. });
  611. });
  612. }];
  613. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  614. DebugLog(@"No");
  615. }];
  616. [alertControl addAction:actionOne];
  617. [alertControl addAction:alertthree];
  618. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  619. UIViewController *vc= [RAUtils getViewController:self];
  620. [vc presentViewController:alertControl animated:YES completion:nil];
  621. }
  622. else
  623. {
  624. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  625. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count name:self.model_label.text];
  626. dispatch_async(dispatch_get_main_queue(), ^{
  627. if([[return_json valueForKey:@"result"] intValue]==2)
  628. {
  629. // NSString* order_code = [return_json valueForKey:@"order_code"];
  630. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  631. // appDelegate.order_code = order_code;
  632. //
  633. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  634. // appDelegate.order_code = order_code;
  635. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  636. if(self.shopCartBlock!=nil)
  637. {
  638. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  639. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  640. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  641. iv.image = img;
  642. // [self.contentView addSubview:iv];
  643. self.shopCartBlock(iv);
  644. self.cqty +=count;
  645. if(self.set_cqty)
  646. self.set_cqty(self.cqty);
  647. }
  648. }
  649. else
  650. {
  651. UIViewController *vc= [RAUtils getViewController:self];
  652. NSString *msg = [return_json valueForKey:@"err_msg"];
  653. NSString *title = @"Add To Cart";
  654. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  655. title = @"Add To Cart: Out of Stock";
  656. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  657. self.btnNotifyMe.enabled = YES;
  658. self.btnaddCart.enabled = NO;
  659. }
  660. [RAUtils message_alert:msg title:title controller:vc] ;
  661. }
  662. });
  663. });
  664. }
  665. //
  666. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  667. //
  668. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  669. //
  670. // dispatch_async(dispatch_get_main_queue(), ^{
  671. //
  672. //
  673. //
  674. // if([[return_json valueForKey:@"result"] intValue]==2)
  675. // {
  676. //
  677. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  678. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  679. //// appDelegate.order_code = order_code;
  680. ////
  681. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  682. //// appDelegate.order_code = order_code;
  683. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  684. //
  685. //
  686. // if(self.shopCartBlock!=nil)
  687. // {
  688. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  689. //
  690. //
  691. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  692. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  693. // iv.image = img;
  694. // // [self.contentView addSubview:iv];
  695. // self.shopCartBlock(iv);
  696. //
  697. // self.cqty +=count;
  698. // if(self.set_cqty)
  699. // self.set_cqty(self.cqty);
  700. //
  701. // }
  702. //
  703. //
  704. // }
  705. // else
  706. // {
  707. // UIViewController *vc= [RAUtils getViewController:self];
  708. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  709. // }
  710. //
  711. //
  712. //
  713. //
  714. // });
  715. // });
  716. //
  717. }
  718. }
  719. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  720. {
  721. [super setSelected:selected animated:animated];
  722. // Configure the view for the selected state
  723. }
  724. - (IBAction)selectorOnClick:(id)sender {
  725. DebugLog(@"select click");
  726. [celldelegate SelectorClicked:(UIButton*) sender];
  727. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  728. }
  729. #pragma mark -
  730. #pragma mark Deck DataSource Protocol Methods
  731. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  732. return [self.photos count];
  733. }
  734. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  735. if(self.photos.count==0)
  736. return nil;
  737. return [self.photos objectAtIndex:index];
  738. }
  739. #pragma mark -
  740. #pragma mark Deck Delegate Protocol Methods
  741. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  742. // User started moving a photo
  743. }
  744. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  745. // User flicked the photo away, revealing the next one in the stack
  746. }
  747. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  748. self.pageControl.currentPage = index;
  749. }
  750. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  751. DebugLog(@"selected %lu", (unsigned long)index);
  752. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  753. // for (int i = 0; i < _data.count; i++) {
  754. // UIImage *imgMod = _data[i];
  755. // [imgList addObject:imgMod];
  756. // }
  757. // 调用展示窗口
  758. ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  759. UIViewController *vc= [RAUtils getViewController:self];
  760. [vc.navigationController pushViewController:imgShow animated:true];
  761. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  762. // [self presentViewController:nav animated:YES completion:nil];
  763. // UIDocumentInteractionController
  764. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  765. // preview.delegate = self;
  766. // [preview presentPreviewAnimated:YES];
  767. }
  768. -(void) neworder
  769. {
  770. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  771. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  772. NSDictionary* return_json = [iSalesNetwork new_Order];
  773. dispatch_async(dispatch_get_main_queue(), ^{
  774. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  775. if([[return_json valueForKey:@"result"] intValue]==2)
  776. {
  777. int result=[[return_json valueForKey:@"result"] intValue];
  778. if(result==2)
  779. {
  780. //successed.
  781. NSString* order_code = [return_json valueForKey:@"orderCode"];
  782. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  783. appDelegate.order_code = order_code;
  784. int count=[self.quantity_text.text intValue];
  785. [self addtocart:count];
  786. // [self ReloadData];
  787. // if(self.shopCartBlock!=nil)
  788. // {
  789. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  790. //
  791. //
  792. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  793. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  794. // iv.image = img;
  795. // // [self.contentView addSubview:iv];
  796. // self.shopCartBlock(iv);
  797. //
  798. // }
  799. }
  800. }
  801. else
  802. {
  803. UIViewController *vc= [RAUtils getViewController:self];
  804. NSString *msg = [return_json valueForKey:@"err_msg"];
  805. NSString *title = @"Add To Cart";
  806. if ([msg hasPrefix:@"Out of Stock.\n"]) {
  807. title = @"Add To Cart: Out of Stock";
  808. msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
  809. self.btnNotifyMe.enabled = YES;
  810. self.btnaddCart.enabled = NO;
  811. }
  812. [RAUtils message_alert:msg title:title controller:vc] ;
  813. }
  814. });
  815. });
  816. }
  817. #pragma mark - UIAlertViewDelegate
  818. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  819. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  820. {
  821. UIApplication * app = [UIApplication sharedApplication];
  822. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  823. if(alertView.tag==1234)//库存小于0
  824. {
  825. // availability warring;
  826. int count=[self.quantity_text.text intValue];
  827. if(buttonIndex!=alertView.cancelButtonIndex)
  828. {
  829. if(appDelegate.order_code==nil)
  830. {
  831. [self neworder];
  832. }
  833. else
  834. {
  835. [self addtocart:count];
  836. }
  837. }
  838. return;
  839. }
  840. // int count=[self.quantity_text.text intValue];
  841. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  842. if(buttonIndex==alertView.cancelButtonIndex)
  843. {
  844. }
  845. else if(buttonIndex==1)
  846. {
  847. //open exist
  848. UIViewController *vc= [RAUtils getViewController:self];
  849. OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  850. ovc.showNavibar = true;
  851. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  852. if(appDelegate.order_code==nil)
  853. {
  854. [self neworder];
  855. }
  856. else
  857. {
  858. if(self.set_update_data)
  859. self.set_update_data(true);
  860. int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  861. for(int i=0;i<model_count;i++)
  862. {
  863. NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  864. NSString* product_id = [item valueForKey:@"product_id"];
  865. if([product_id isEqualToString:self.product_id])
  866. {
  867. self.cqty = [[item valueForKey:@"QTY"]intValue];
  868. if(self.set_cqty)
  869. self.set_cqty(self.cqty);
  870. break;
  871. }
  872. }
  873. int count=[self.quantity_text.text intValue];
  874. [self addtocart:count];
  875. [main_vc checklogin:true];
  876. }
  877. };
  878. ovc.init_style = OL_OPEN;
  879. ovc.onCancel = ^(){
  880. [main_vc checklogin:true];
  881. };
  882. [vc.navigationController pushViewController:ovc animated:true];
  883. }
  884. else
  885. {
  886. //create new;
  887. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  888. {
  889. UIViewController *vc= [RAUtils getViewController:self];
  890. ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  891. cvc.showNavibar = true;
  892. cvc.contact_type = @"Sales_Order_Customer";
  893. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  894. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  895. appDelegate.customerInfo = value;
  896. if(appDelegate.order_code==nil)
  897. [self neworder];
  898. [main_vc checklogin:true];
  899. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  900. //
  901. // if(self.returnValue)
  902. // self.returnValue(value);
  903. };
  904. cvc.onCancel = ^(){
  905. UIViewController *vc= [RAUtils getViewController:self];
  906. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order" controller:vc];
  907. };
  908. cvc.onReset = ^(){
  909. [main_vc checklogin:true];
  910. };
  911. [vc.navigationController pushViewController:cvc animated:true];
  912. }
  913. else
  914. {
  915. [self neworder];
  916. }
  917. }
  918. }
  919. - (void)valueChanged:(UIStepper *)sender {
  920. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  921. [celldelegate stepClicked:(int)sender.value];
  922. // -(void) stepClicked:(int) value;
  923. // 检查缺货
  924. // NSString *cartQtyString = nil;
  925. // if (self.cqyt_label.text) {
  926. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  927. // }
  928. //
  929. // int availability = [self.count_Label.text intValue];
  930. // int buyQTY = [self.quantity_text.text intValue];
  931. // int cartQTY = [cartQtyString intValue];
  932. //
  933. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  934. }
  935. #pragma mark -
  936. #pragma mark Actions
  937. -(void)ClearPhotos
  938. {
  939. NSMutableArray *photosMutable = [self.photos mutableCopy];
  940. [photosMutable removeAllObjects];
  941. self.photos = photosMutable;
  942. [self.photoStack reloadData];
  943. }
  944. - (void)AddPhoto :(UIImage*)photo {
  945. NSMutableArray *photosMutable = [self.photos mutableCopy];
  946. [photosMutable addObject:photo];
  947. self.photos = photosMutable;
  948. [self.photoStack reloadData];
  949. self.pageControl.numberOfPages = [self.photos count];
  950. if(self.photos.count<2-1)//1 for qrcode;
  951. self.photoStack.showBorder=false;
  952. else
  953. self.photoStack.showBorder=true;
  954. }
  955. #pragma mark -
  956. #pragma mark Setup
  957. -(void)setup {
  958. // int availability = [self.count_Label.text intValue];
  959. self.stepper.minimumValue= self.step;
  960. self.stepper.maximumValue = INTMAX_MAX;
  961. self.stepper.stepValue= self.step;
  962. self.stepper.value= self.quantity;
  963. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  964. if(true)//(self.photos==nil)
  965. {
  966. self.photos = [NSArray array];
  967. }
  968. if(true)//(self.photoStack==nil)
  969. {
  970. // if(self.photoStack!=nil)
  971. // [self.photoStack removeFromSuperview];
  972. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  973. // self.photoStack.backgroundColor =[UIColor redColor];
  974. // self.photoStack.center = CGPointMake(self.center.x, 220);
  975. self.photoStack.dataSource = self;
  976. self.photoStack.delegate = self;
  977. // [self addSubview:self.photoStack];
  978. self.pageControl.numberOfPages = [self.photos count];
  979. }
  980. }
  981. - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
  982. if (self.notifyMeBlock) {
  983. self.notifyMeBlock();
  984. }
  985. }
  986. #pragma mark - TextField Delegate
  987. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  988. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  989. // NSString *cartQtyString = nil;
  990. // if (self.cqyt_label.text) {
  991. // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
  992. // }
  993. // int availability = [self.count_Label.text intValue];
  994. int buyQTY = [newString intValue];
  995. // int cartQTY = [cartQtyString intValue];
  996. // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
  997. self.stepper.value = buyQTY;
  998. return YES;
  999. }
  1000. #pragma mark - Private
  1001. /**检查是否缺货*/
  1002. - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
  1003. #ifdef BUILD_NPD
  1004. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1005. if (!appDelegate.bLogin || appDelegate.offline_mode || buyQty < 1) {
  1006. return;
  1007. }
  1008. if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
  1009. if (!appDelegate.order_code) { // 未打开订单状态
  1010. if ((buyQty + cartQty) > availability) {
  1011. self.btnaddCart.enabled = NO;
  1012. self.btnNotifyMe.enabled = YES;
  1013. } else {
  1014. self.btnaddCart.enabled = YES;
  1015. self.btnNotifyMe.enabled = NO;
  1016. }
  1017. } else {
  1018. // 打开订单状态
  1019. if (![Singleton sharedInstance].currentOrderIsMerged) {
  1020. // Shop Order
  1021. self.btnaddCart.enabled = YES;
  1022. // 默认未缺货
  1023. self.btnNotifyMe.enabled = NO;
  1024. if ((buyQty + cartQty) > availability) { // 缺货
  1025. self.btnNotifyMe.enabled = YES;
  1026. }
  1027. } else {
  1028. // Purchase Order
  1029. if ((buyQty + cartQty) > availability) { // 缺货
  1030. self.btnaddCart.enabled = NO;
  1031. self.btnNotifyMe.enabled = YES;
  1032. } else { // 未缺货
  1033. self.btnNotifyMe.enabled = NO;
  1034. self.btnaddCart.enabled = YES;
  1035. }
  1036. }
  1037. }
  1038. } else { // empoyee
  1039. if ((buyQty + cartQty) > availability) { // 缺货
  1040. self.btnaddCart.enabled = NO;
  1041. self.btnNotifyMe.enabled = YES;
  1042. } else { // 未缺货
  1043. self.btnNotifyMe.enabled = NO;
  1044. self.btnaddCart.enabled = YES;
  1045. }
  1046. }
  1047. #endif
  1048. }
  1049. @end