DetailHeaderCell.m 50 KB

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