DetailHeaderCell.m 45 KB

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