DetailHeaderCell.m 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  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. @implementation DetailHeaderCell
  17. @synthesize celldelegate;
  18. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  19. {
  20. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  21. if (self) {
  22. // Initialization code
  23. }
  24. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  25. // self.selector_imageView.layer.borderWidth = 1;
  26. return self;
  27. }
  28. - (void)awakeFromNib
  29. {
  30. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  31. // self.selector_imageView.layer.borderWidth = 1;
  32. self.selector_Button.layer.borderWidth = 0.5;
  33. self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  34. self.selector_Button.layer.cornerRadius = 0;
  35. [self.descriptionRTLabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  36. [self.descriptionRTLabel setTextAlignment:RTTextAlignmentCenter];
  37. [self.descriptionRTLabel setFont:[UIFont systemFontOfSize:22]];
  38. // self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  39. // self.label_net_err.layer.borderWidth = 2.0;
  40. // self.label_net_err.layer.cornerRadius=15;
  41. // self.label_net_err.layer.masksToBounds=true;
  42. // Initialization code
  43. }
  44. - (IBAction)add_toWatchList:(id)sender {
  45. // int count=[self.quantity_text.text intValue];
  46. UIApplication * app = [UIApplication sharedApplication];
  47. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  48. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  49. if(appDelegate.bLogin==false)
  50. {
  51. UIViewController *vc= [RAUtils getViewController:self];
  52. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  53. // loginvc.delegate = self;
  54. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  55. loginvc.returnValue = ^(bool blogin){
  56. // UIApplication * app = [UIApplication sharedApplication];
  57. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  58. if(blogin)
  59. {
  60. if(self.set_update_data)
  61. self.set_update_data(true);
  62. [main_vc checklogin:true];
  63. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  64. NSDictionary* return_json = [iSalesNetwork add_toWatchList:self.product_id ];
  65. dispatch_async(dispatch_get_main_queue(), ^{
  66. if([[return_json valueForKey:@"result"] intValue]==2)
  67. {
  68. // NSLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  69. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  70. if(self.WatchlistBlock!=nil)
  71. {
  72. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  73. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  74. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  75. iv.image = img;
  76. // [self.contentView addSubview:iv];
  77. self.WatchlistBlock(iv);
  78. }
  79. }
  80. else
  81. {
  82. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wishlist" controller:vc] ;
  83. }
  84. });
  85. });
  86. }
  87. // self.offset = 0;
  88. // [self.content_data removeAllObjects];
  89. // [self loadpage];
  90. //
  91. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  92. };
  93. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  94. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  95. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  96. [vc presentViewController:navi animated:YES completion:^{
  97. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  98. NSLog(@"LoginViewController present.........");
  99. // self.btop = false;
  100. // <#code#>
  101. }];
  102. }
  103. else
  104. {
  105. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  106. NSDictionary* return_json = [iSalesNetwork add_toWatchList:self.product_id ];
  107. dispatch_async(dispatch_get_main_queue(), ^{
  108. if([[return_json valueForKey:@"result"] intValue]==2)
  109. {
  110. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  111. if(self.WatchlistBlock!=nil)
  112. {
  113. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  114. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  115. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  116. iv.image = img;
  117. // [self.contentView addSubview:iv];
  118. self.WatchlistBlock(iv);
  119. }
  120. }
  121. else
  122. {
  123. UIViewController *vc= [RAUtils getViewController:self];
  124. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wishlist" controller:vc] ;
  125. }
  126. });
  127. });
  128. }
  129. }
  130. - (IBAction)add_toCart:(id)sender {
  131. int count=[self.quantity_text.text intValue];
  132. UIApplication * app = [UIApplication sharedApplication];
  133. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  134. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  135. if(appDelegate.bLogin==false)
  136. {
  137. UIViewController *vc= [RAUtils getViewController:self];
  138. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  139. // loginvc.delegate = self;
  140. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  141. loginvc.returnValue = ^(bool blogin){
  142. // UIApplication * app = [UIApplication sharedApplication];
  143. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  144. if(blogin)
  145. {
  146. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  147. {
  148. if(self.set_update_data)
  149. self.set_update_data(true);
  150. [main_vc checklogin:false];
  151. 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];
  152. // alert.
  153. [alert show];
  154. }
  155. else
  156. {
  157. [main_vc checklogin:true];
  158. int c=[self.count_Label.text intValue];
  159. NSLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  160. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  161. if(c<count)
  162. {
  163. 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];
  164. // alert.
  165. alert.tag = 1234;
  166. [alert show];
  167. }
  168. else
  169. {
  170. if(appDelegate.order_code==nil)
  171. [ self neworder];
  172. else
  173. [self addtocart:count];
  174. }
  175. }
  176. }
  177. // self.offset = 0;
  178. // [self.content_data removeAllObjects];
  179. // [self loadpage];
  180. //
  181. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  182. };
  183. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  184. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  185. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  186. [vc presentViewController:navi animated:YES completion:^{
  187. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  188. NSLog(@"LoginViewController present.........");
  189. // self.btop = false;
  190. // <#code#>
  191. }];
  192. }
  193. else
  194. {
  195. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  196. {
  197. [main_vc checklogin:false];
  198. if(appDelegate.can_create_order)
  199. {
  200. NSString* msg =@"";
  201. if(appDelegate.contact_id.length>0)
  202. {
  203. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  204. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  205. }
  206. 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];
  207. // alert.
  208. [alert show];
  209. }
  210. else
  211. {
  212. 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];
  213. // alert.
  214. [alert show];
  215. }
  216. }
  217. else
  218. {
  219. // if ([self.priceLabel.text isEqualToString:@"No Price."])
  220. // {
  221. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Model No Price" message:@"Cannot add model without price." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  222. ////
  223. ////
  224. ////
  225. //// [alert show];
  226. //
  227. //
  228. //
  229. // [RAUtils alert_view:@"Cannot add model without price." title:@"Model No Price."];
  230. // }
  231. // else
  232. {
  233. int c=[self.count_Label.text intValue];
  234. NSLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  235. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  236. if(c<count)
  237. {
  238. 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];
  239. // alert.
  240. alert.tag = 1234;
  241. [alert show];
  242. }
  243. else
  244. {
  245. if(appDelegate.order_code==nil)
  246. [ self neworder];
  247. else
  248. [self addtocart:count];
  249. }
  250. }
  251. }
  252. }
  253. }
  254. -(void) addtocart:(int) count
  255. {
  256. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  257. if(self.cqty>0)
  258. {
  259. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  260. //block代码块取代了delegate
  261. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  262. int c=self.cqty+count;
  263. int m=c%self.step;
  264. if(m!=0&&appDelegate.alert_sold_in_quantities)
  265. {
  266. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
  267. //block代码块取代了delegate
  268. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  269. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  270. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  271. dispatch_async(dispatch_get_main_queue(), ^{
  272. if([[return_json valueForKey:@"result"] intValue]==2)
  273. {
  274. // NSString* order_code = [return_json valueForKey:@"order_code"];
  275. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  276. // appDelegate.order_code = order_code;
  277. //
  278. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  279. // appDelegate.order_code = order_code;
  280. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  281. if(self.shopCartBlock!=nil)
  282. {
  283. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  284. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  285. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  286. iv.image = img;
  287. // [self.contentView addSubview:iv];
  288. self.shopCartBlock(iv);
  289. self.cqty +=count;
  290. if(self.set_cqty)
  291. self.set_cqty(self.cqty);
  292. }
  293. }
  294. else
  295. {
  296. UIViewController *vc= [RAUtils getViewController:self];
  297. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  298. }
  299. });
  300. });
  301. }];
  302. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  303. NSLog(@"No");
  304. }];
  305. [alertControl addAction:actionOne];
  306. [alertControl addAction:alertthree];
  307. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  308. UIViewController *vc= [RAUtils getViewController:self];
  309. [vc presentViewController:alertControl animated:YES completion:nil];
  310. }
  311. else
  312. {
  313. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  314. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  315. dispatch_async(dispatch_get_main_queue(), ^{
  316. if([[return_json valueForKey:@"result"] intValue]==2)
  317. {
  318. // NSString* order_code = [return_json valueForKey:@"order_code"];
  319. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  320. // appDelegate.order_code = order_code;
  321. //
  322. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  323. // appDelegate.order_code = order_code;
  324. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  325. if(self.shopCartBlock!=nil)
  326. {
  327. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  328. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  329. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  330. iv.image = img;
  331. // [self.contentView addSubview:iv];
  332. self.shopCartBlock(iv);
  333. self.cqty +=count;
  334. if(self.set_cqty)
  335. self.set_cqty(self.cqty);
  336. }
  337. }
  338. else
  339. {
  340. UIViewController *vc= [RAUtils getViewController:self];
  341. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  342. }
  343. });
  344. });
  345. }
  346. //
  347. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  348. //
  349. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  350. //
  351. // dispatch_async(dispatch_get_main_queue(), ^{
  352. //
  353. //
  354. //
  355. // if([[return_json valueForKey:@"result"] intValue]==2)
  356. // {
  357. //
  358. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  359. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  360. //// appDelegate.order_code = order_code;
  361. ////
  362. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  363. //// appDelegate.order_code = order_code;
  364. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  365. //
  366. //
  367. // if(self.shopCartBlock!=nil)
  368. // {
  369. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  370. //
  371. //
  372. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  373. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  374. // iv.image = img;
  375. // // [self.contentView addSubview:iv];
  376. // self.shopCartBlock(iv);
  377. //
  378. // self.cqty +=count;
  379. // if(self.set_cqty)
  380. // self.set_cqty(self.cqty);
  381. //
  382. // }
  383. //
  384. //
  385. // }
  386. // else
  387. // {
  388. // UIViewController *vc= [RAUtils getViewController:self];
  389. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  390. // }
  391. //
  392. //
  393. //
  394. //
  395. // });
  396. // });
  397. //
  398. }];
  399. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  400. NSLog(@"No");
  401. }];
  402. [alertControl addAction:actionOne];
  403. [alertControl addAction:alertthree];
  404. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  405. UIViewController *vc= [RAUtils getViewController:self];
  406. [vc presentViewController:alertControl animated:YES completion:nil];
  407. }
  408. else
  409. {
  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];
  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. // appDelegate.order_code = order_code;
  425. //
  426. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  427. // appDelegate.order_code = order_code;
  428. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  429. if(self.shopCartBlock!=nil)
  430. {
  431. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  432. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  433. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  434. iv.image = img;
  435. // [self.contentView addSubview:iv];
  436. self.shopCartBlock(iv);
  437. self.cqty +=count;
  438. if(self.set_cqty)
  439. self.set_cqty(self.cqty);
  440. }
  441. }
  442. else
  443. {
  444. UIViewController *vc= [RAUtils getViewController:self];
  445. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  446. }
  447. });
  448. });
  449. }];
  450. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  451. NSLog(@"No");
  452. }];
  453. [alertControl addAction:actionOne];
  454. [alertControl addAction:alertthree];
  455. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  456. UIViewController *vc= [RAUtils getViewController:self];
  457. [vc presentViewController:alertControl animated:YES completion:nil];
  458. }
  459. else
  460. {
  461. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  462. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  463. dispatch_async(dispatch_get_main_queue(), ^{
  464. if([[return_json valueForKey:@"result"] intValue]==2)
  465. {
  466. // NSString* order_code = [return_json valueForKey:@"order_code"];
  467. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  468. // appDelegate.order_code = order_code;
  469. //
  470. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  471. // appDelegate.order_code = order_code;
  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. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  490. }
  491. });
  492. });
  493. }
  494. //
  495. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  496. //
  497. // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  498. //
  499. // dispatch_async(dispatch_get_main_queue(), ^{
  500. //
  501. //
  502. //
  503. // if([[return_json valueForKey:@"result"] intValue]==2)
  504. // {
  505. //
  506. // // NSString* order_code = [return_json valueForKey:@"order_code"];
  507. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  508. //// appDelegate.order_code = order_code;
  509. ////
  510. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  511. //// appDelegate.order_code = order_code;
  512. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  513. //
  514. //
  515. // if(self.shopCartBlock!=nil)
  516. // {
  517. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  518. //
  519. //
  520. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  521. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  522. // iv.image = img;
  523. // // [self.contentView addSubview:iv];
  524. // self.shopCartBlock(iv);
  525. //
  526. // self.cqty +=count;
  527. // if(self.set_cqty)
  528. // self.set_cqty(self.cqty);
  529. //
  530. // }
  531. //
  532. //
  533. // }
  534. // else
  535. // {
  536. // UIViewController *vc= [RAUtils getViewController:self];
  537. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  538. // }
  539. //
  540. //
  541. //
  542. //
  543. // });
  544. // });
  545. //
  546. }
  547. }
  548. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  549. {
  550. [super setSelected:selected animated:animated];
  551. // Configure the view for the selected state
  552. }
  553. - (IBAction)selectorOnClick:(id)sender {
  554. NSLog(@"select click");
  555. [celldelegate SelectorClicked:(UIButton*) sender];
  556. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  557. }
  558. #pragma mark -
  559. #pragma mark Deck DataSource Protocol Methods
  560. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  561. return [self.photos count];
  562. }
  563. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  564. if(self.photos.count==0)
  565. return nil;
  566. return [self.photos objectAtIndex:index];
  567. }
  568. #pragma mark -
  569. #pragma mark Deck Delegate Protocol Methods
  570. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  571. // User started moving a photo
  572. }
  573. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  574. // User flicked the photo away, revealing the next one in the stack
  575. }
  576. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  577. self.pageControl.currentPage = index;
  578. }
  579. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  580. NSLog(@"selected %lu", (unsigned long)index);
  581. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  582. // for (int i = 0; i < _data.count; i++) {
  583. // UIImage *imgMod = _data[i];
  584. // [imgList addObject:imgMod];
  585. // }
  586. // 调用展示窗口
  587. ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  588. UIViewController *vc= [RAUtils getViewController:self];
  589. [vc.navigationController pushViewController:imgShow animated:true];
  590. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  591. // [self presentViewController:nav animated:YES completion:nil];
  592. // UIDocumentInteractionController
  593. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  594. // preview.delegate = self;
  595. // [preview presentPreviewAnimated:YES];
  596. }
  597. -(void) neworder
  598. {
  599. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  600. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  601. NSDictionary* return_json = [iSalesNetwork new_Order];
  602. dispatch_async(dispatch_get_main_queue(), ^{
  603. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  604. if([[return_json valueForKey:@"result"] intValue]==2)
  605. {
  606. int result=[[return_json valueForKey:@"result"] intValue];
  607. if(result==2)
  608. {
  609. //successed.
  610. NSString* order_code = [return_json valueForKey:@"orderCode"];
  611. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  612. appDelegate.order_code = order_code;
  613. int count=[self.quantity_text.text intValue];
  614. [self addtocart:count];
  615. // [self ReloadData];
  616. // if(self.shopCartBlock!=nil)
  617. // {
  618. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  619. //
  620. //
  621. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  622. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  623. // iv.image = img;
  624. // // [self.contentView addSubview:iv];
  625. // self.shopCartBlock(iv);
  626. //
  627. // }
  628. }
  629. }
  630. else
  631. {
  632. UIViewController *vc= [RAUtils getViewController:self];
  633. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  634. }
  635. });
  636. });
  637. }
  638. #pragma mark - UIAlertViewDelegate
  639. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  640. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  641. {
  642. UIApplication * app = [UIApplication sharedApplication];
  643. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  644. if(alertView.tag==1234)//库存小于0
  645. {
  646. // availability warring;
  647. int count=[self.quantity_text.text intValue];
  648. if(buttonIndex!=alertView.cancelButtonIndex)
  649. {
  650. if(appDelegate.order_code==nil)
  651. {
  652. [self neworder];
  653. }
  654. else
  655. {
  656. [self addtocart:count];
  657. }
  658. }
  659. return;
  660. }
  661. // int count=[self.quantity_text.text intValue];
  662. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  663. if(buttonIndex==alertView.cancelButtonIndex)
  664. {
  665. }
  666. else if(buttonIndex==1)
  667. {
  668. //open exist
  669. UIViewController *vc= [RAUtils getViewController:self];
  670. OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  671. ovc.showNavibar = true;
  672. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  673. if(appDelegate.order_code==nil)
  674. {
  675. [self neworder];
  676. }
  677. else
  678. {
  679. if(self.set_update_data)
  680. self.set_update_data(true);
  681. int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  682. for(int i=0;i<model_count;i++)
  683. {
  684. NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  685. NSString* product_id = [item valueForKey:@"product_id"];
  686. if([product_id isEqualToString:self.product_id])
  687. {
  688. self.cqty = [[item valueForKey:@"QTY"]intValue];
  689. if(self.set_cqty)
  690. self.set_cqty(self.cqty);
  691. break;
  692. }
  693. }
  694. int count=[self.quantity_text.text intValue];
  695. [self addtocart:count];
  696. [main_vc checklogin:true];
  697. }
  698. };
  699. ovc.init_style = OL_OPEN;
  700. ovc.onCancel = ^(){
  701. [main_vc checklogin:true];
  702. };
  703. [vc.navigationController pushViewController:ovc animated:true];
  704. }
  705. else
  706. {
  707. //create new;
  708. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  709. {
  710. UIViewController *vc= [RAUtils getViewController:self];
  711. ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  712. cvc.showNavibar = true;
  713. cvc.contact_type = @"Sales_Order_Customer";
  714. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  715. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  716. appDelegate.customerInfo = value;
  717. if(appDelegate.order_code==nil)
  718. [self neworder];
  719. [main_vc checklogin:true];
  720. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  721. //
  722. // if(self.returnValue)
  723. // self.returnValue(value);
  724. };
  725. cvc.onCancel = ^(){
  726. UIViewController *vc= [RAUtils getViewController:self];
  727. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error." controller:vc];
  728. };
  729. cvc.onReset = ^(){
  730. [main_vc checklogin:true];
  731. };
  732. [vc.navigationController pushViewController:cvc animated:true];
  733. }
  734. else
  735. {
  736. [self neworder];
  737. }
  738. }
  739. }
  740. - (void)valueChanged:(UIStepper *)sender {
  741. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  742. [celldelegate stepClicked:(int)sender.value];
  743. // -(void) stepClicked:(int) value;
  744. }
  745. #pragma mark -
  746. #pragma mark Actions
  747. - (void)AddPhoto :(UIImage*)photo {
  748. NSMutableArray *photosMutable = [self.photos mutableCopy];
  749. [photosMutable addObject:photo];
  750. self.photos = photosMutable;
  751. [self.photoStack reloadData];
  752. self.pageControl.numberOfPages = [self.photos count];
  753. if(self.photos.count<2-1)//1 for qrcode;
  754. self.photoStack.showBorder=false;
  755. else
  756. self.photoStack.showBorder=true;
  757. }
  758. #pragma mark -
  759. #pragma mark Setup
  760. -(void)setup {
  761. self.stepper.minimumValue= self.step;
  762. self.stepper.stepValue= self.step;
  763. self.stepper.value= self.quantity;
  764. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  765. if(true)//(self.photos==nil)
  766. {
  767. self.photos = [NSArray arrayWithObjects:
  768. nil];
  769. }
  770. if(true)//(self.photoStack==nil)
  771. {
  772. // if(self.photoStack!=nil)
  773. // [self.photoStack removeFromSuperview];
  774. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  775. // self.photoStack.backgroundColor =[UIColor redColor];
  776. // self.photoStack.center = CGPointMake(self.center.x, 220);
  777. self.photoStack.dataSource = self;
  778. self.photoStack.delegate = self;
  779. // [self addSubview:self.photoStack];
  780. self.pageControl.numberOfPages = [self.photos count];
  781. }
  782. }
  783. @end