DetailHeaderCell.m 50 KB

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