DetailHeaderCell.m 45 KB

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