DetailHeaderCell.m 45 KB

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