DetailHeaderCell.m 51 KB

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