// // DetailHeaderCell.m // RedAnt ERP Mobile // // Created by Ray on 14-6-5. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "DetailHeaderCell.h" #import "RANetwork.h" #import "MainViewController.h" #import "LoginViewController.h" #import "ContactListViewController.h" #import "RAUtils.h" #import "OrderListViewController.h" #import "ImageScrollerViewController.h" #import "CartUtils.h" //#import "CustomIOSAlertView.h" #import "TextUtils.h" #import "ContentPreviewController.h" #import "DetailViewController.h" #import "RAPDFViewController.h" @implementation DetailHeaderCell @synthesize celldelegate; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor]; // self.selector_imageView.layer.borderWidth = 1; return self; } - (void)awakeFromNib { [super awakeFromNib]; #ifdef BUILD_UWAVER // self.addPortfolioBtn.title = @"Add to Hang Tag"; self.btn_hangtag.hidden=false; #else self.btn_hangtag.hidden=true; #endif // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor]; // self.selector_imageView.layer.borderWidth = 1; self.quantity_text.delegate = self; self.selector_Button.layer.borderWidth = 0.5; self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor]; self.selector_Button.layer.cornerRadius = 0; [self.descriptionRTLabel setLineBreakMode: RTTextLineBreakModeWordWrapping]; [self.descriptionRTLabel setTextAlignment:RTTextAlignmentCenter]; [self.descriptionRTLabel setFont:[UIFont systemFontOfSize:22]]; // self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor; // self.label_net_err.layer.borderWidth = 2.0; // self.label_net_err.layer.cornerRadius=15; // self.label_net_err.layer.masksToBounds=true; // Initialization code [self addObserver:self forKeyPath:@"stack_contents" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:@"content changed"]; } -(void) dealloc { [self removeObserver:self forKeyPath:@"stack_contents"]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if([keyPath isEqualToString:@"stack_contents"]) { [self.ytplayerView stopVideo]; self.ytplayerView.hidden=true; } } - (IBAction)create_HangTag:(id)sender { } - (IBAction)add_toPortfolio:(id)sender { // int count=[self.quantity_text.text intValue]; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if (RASingleton.sharedInstance.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) { [[NSNotificationCenter defaultCenter] postNotificationName:No_Rights_Notification object:nil]; return; } MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(appDelegate.bLogin==false) { UIViewController *vc= [RAUtils getViewController:self]; LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(blogin) { if(self.set_update_data) self.set_update_data(true); [main_vc checklogin:true]; [RANetwork request_addto_portfolio:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json =result; if([[return_json valueForKey:@"result"] intValue]==2) { // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false]; #endif if(self.WatchlistBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.PortfolioBlock(iv); } } else { [RAUtils message_box:@"Add to portfolio" message:[return_json valueForKey:@"err_msg"] completion:nil] ; } }]; } // self.offset = 0; // [self.content_data removeAllObjects]; // [self loadpage]; // // [[self navigationController] setNavigationBarHidden:YES animated:NO]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 [vc presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); DebugLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else { [RANetwork request_addto_portfolio:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json =result; if([[return_json valueForKey:@"result"] intValue]==2) { #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false]; #endif if(self.WatchlistBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.PortfolioBlock(iv); } } else { // UIViewController *vc= [RAUtils getViewController:self]; [RAUtils message_box:@"Add to portfolio" message:[return_json valueForKey:@"err_msg"] completion:nil] ; } }]; } } - (IBAction)add_toWatchList:(id)sender { // int count=[self.quantity_text.text intValue]; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(appDelegate.bLogin==false) { UIViewController *vc= [RAUtils getViewController:self]; LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(blogin) { if(self.set_update_data) self.set_update_data(true); [main_vc checklogin:true]; [RANetwork request_addto_wishlist:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json =result; if([[return_json valueForKey:@"result"] intValue]==2) { // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false]; #endif if(self.WatchlistBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.WatchlistBlock(iv); } } else { [RAUtils message_box:@"Add Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ; } }]; } // self.offset = 0; // [self.content_data removeAllObjects]; // [self loadpage]; // // [[self navigationController] setNavigationBarHidden:YES animated:NO]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 [vc presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); DebugLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else { [RANetwork request_addto_wishlist:self.product_id withScreen:ScreenCodeModelInfo completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json =result; if([[return_json valueForKey:@"result"] intValue]==2) { #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false]; #endif if(self.WatchlistBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.WatchlistBlock(iv); } } else { // UIViewController *vc= [RAUtils getViewController:self]; [RAUtils message_box:@"Add Wish List" message:[return_json valueForKey:@"err_msg"] completion:nil] ; } }]; } } - (IBAction)add_toCart:(id)sender { [CartUtils add_to_cart:[RAUtils getViewController:self] selectorholder:self selector:@selector(addtocart)]; return; // // // int count=[self.quantity_text.text intValue]; // // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; // if(appDelegate.bLogin==false) // { // UIViewController *vc= [RAUtils getViewController:self]; // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"]; // // loginvc.delegate = self; // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // // loginvc.returnValue = ^(bool blogin){ // // // // UIApplication * app = [UIApplication sharedApplication]; // // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // // // // // if(blogin) // { // if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true) // { // if(self.set_update_data) // self.set_update_data(true); // [main_vc checklogin:false]; // // // 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]; // // // // // alert. // [alert show]; // } // else // { // [main_vc checklogin:true]; // // int c=[self.count_Label.text intValue]; // DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c); // // NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""]; // // // // if(!appDelegate.can_create_backorder && c // }]; // } // else // { // //// if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&appDelegate.order_code==nil) // if(appDelegate.order_code==nil) // { // [main_vc checklogin:false]; // // if(appDelegate.can_create_order) // { // NSString* msg =@""; // if(appDelegate.contact_id.length>0) // { // msg = [msg stringByAppendingString:@"\n\nCustomer:"]; // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]]; // // } // 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]; // // // alert. // [alert show]; // } // else // { // 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]; // // // alert. // [alert show]; // } // } // else // { // //// if ([self.priceLabel.text isEqualToString:@"No Price."]) //// { ////// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Model No Price" message:@"Cannot add model without price." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; ////// ////// ////// ////// [alert show]; //// //// //// //// [RAUtils alert_view:@"Cannot add model without price." title:@"Model No Price."]; //// } //// else // { // // int c=[self.count_Label.text intValue]; // DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c); // // NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""]; // // // // if(c0) { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { int c=self.cqty+count; int m=c%self.step; if(m!=0&&appDelegate.alert_sold_in_quantities) { UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json = result; if([[return_json valueForKey:@"result"] intValue]==2) { // NSString* order_code = [return_json valueForKey:@"order_code"]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif if(self.shopCartBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.shopCartBlock(iv); self.cqty +=count; if(self.set_cqty) self.set_cqty(self.cqty); } } else { UIViewController *vc= [RAUtils getViewController:self]; NSString *msg = [return_json valueForKey:@"err_msg"]; NSString *title = @"Add To Cart"; if ([msg hasPrefix:@"Out of Stock.\n"]) { title = @"Add To Cart: Out of Stock"; msg = [msg substringFromIndex:[@"Out of Stock.\n" length]]; self.btnNotifyMe.enabled = YES; self.btnaddCart.enabled = NO; } [RAUtils message_box:title message:msg completion:nil] ; } }]; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { DebugLog(@"No"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) UIViewController *vc= [RAUtils getViewController:self]; [vc presentViewController:alertControl animated:YES completion:nil]; } else { [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json = result; if([[return_json valueForKey:@"result"] intValue]==2) { // NSString* order_code = [return_json valueForKey:@"order_code"]; #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif if(self.shopCartBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.shopCartBlock(iv); self.cqty +=count; if(self.set_cqty) self.set_cqty(self.cqty); } } else { UIViewController *vc= [RAUtils getViewController:self]; NSString *msg = [return_json valueForKey:@"err_msg"]; NSString *title = @"Add To Cart"; if ([msg hasPrefix:@"Out of Stock.\n"]) { title = @"Add To Cart: Out of Stock"; msg = [msg substringFromIndex:[@"Out of Stock.\n" length]]; self.btnNotifyMe.enabled = YES; self.btnaddCart.enabled = NO; } [RAUtils message_box:title message:msg completion:nil] ; } }]; } }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { DebugLog(@"No"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) UIViewController *vc= [RAUtils getViewController:self]; [vc presentViewController:alertControl animated:YES completion:nil]; } else #endif { #ifdef MPACK AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; int c=self.cqty+count; int m=c%self.step; if(m!=0&&appDelegate.alert_sold_in_quantities) { UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { [RANetwork request_addto_cart:self.product_id count:count name:self.model_label.text completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json =result; if([[return_json valueForKey:@"result"] intValue]==2) { #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else // NSString* order_code = [return_json valueForKey:@"order_code"]; AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; // appDelegate.order_code = order_code; // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // appDelegate.order_code = order_code; [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif if(self.shopCartBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.shopCartBlock(iv); self.cqty +=count; if(self.set_cqty) self.set_cqty(self.cqty); } } else { UIViewController *vc= [RAUtils getViewController:self]; NSString *msg = [return_json valueForKey:@"err_msg"]; NSString *title = @"Add To Cart"; if ([msg hasPrefix:@"Out of Stock.\n"]) { title = @"Add To Cart: Out of Stock"; msg = [msg substringFromIndex:[@"Out of Stock.\n" length]]; self.btnNotifyMe.enabled = YES; self.btnaddCart.enabled = NO; } [RAUtils message_box:title message:msg completion:nil] ; } }]; }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { DebugLog(@"No"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) UIViewController *vc= [RAUtils getViewController:self]; [vc presentViewController:alertControl animated:YES completion:nil]; } else #endif { NSString* model_name=self.model_label.text; [RANetwork request_addto_cart:self.product_id count:count name:model_name completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json = result; if([[return_json valueForKey:@"result"] intValue]==2) { #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif if(self.shopCartBlock!=nil) { UIImage* img=[self photoStackView:self.photoStack photoForIndex:0]; CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100); UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect]; iv.image = img; // [self.contentView addSubview:iv]; self.shopCartBlock(iv); self.cqty +=count; if(self.set_cqty) self.set_cqty(self.cqty); } } else { // UIViewController *vc= [RAUtils getViewController:self]; NSString *msg = [return_json valueForKey:@"err_msg"]; NSString *title = @"Add To Cart"; if ([msg hasPrefix:@"Out of Stock.\n"]) { title = @"Add To Cart: Out of Stock"; msg = [msg substringFromIndex:[@"Out of Stock.\n" length]]; self.btnNotifyMe.enabled = YES; self.btnaddCart.enabled = NO; } [RAUtils message_box:title message:msg completion:nil] ; } }]; } } } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (IBAction)selectorOnClick:(id)sender { DebugLog(@"select click"); [celldelegate SelectorClicked:(UIButton*) sender]; // [self performSegueWithIdentifier:@"selector_popover" sender:self]; } #pragma mark - #pragma mark Deck DataSource Protocol Methods -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack { return [self.photos count]; } -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index { if(self.photos.count==0) return nil; return [self.photos objectAtIndex:index]; } #pragma mark - #pragma mark Deck Delegate Protocol Methods -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index { // User started moving a photo } -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex { // User flicked the photo away, revealing the next one in the stack } -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index { self.pageControl.currentPage = index; } - (UIView *)createVideoView:(NSString*) videoID { UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)]; // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)]; // [imageView setImage:[UIImage imageNamed:@"demo"]]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)]; titleLabel.font = [UIFont boldSystemFontOfSize:20]; titleLabel.text=@"a separated player will show here:"; titleLabel.numberOfLines = 0; titleLabel.lineBreakMode =NSLineBreakByWordWrapping; // titleLabel.textAlignment = NSTextAlignmentRight; titleLabel.textAlignment = NSTextAlignmentCenter; CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width; // CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; CGSize sizetitle = [RAUtils sizeWithFont:@"a separated player will show here:" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; //[titleLabel sizeToFit]; // titleLabel.center.x = demoView.center.x; titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height); [demoView addSubview:titleLabel]; UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)]; lineLabel.font = [UIFont boldSystemFontOfSize:17]; lineLabel.text=videoID; lineLabel.numberOfLines = 0; lineLabel.lineBreakMode =NSLineBreakByWordWrapping; // CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; CGSize sizemsg = [RAUtils sizeWithFont:videoID font:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping]; lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height); //[lineLabel sizeToFit]; [demoView addSubview:lineLabel]; demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25); return demoView; } -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index { DebugLog(@"selected %lu", (unsigned long)index); NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]]; if([item[@"type"] isEqualToString:@"video"]) { NSString* video_code=item[@"code"]; // [TextUtils expression_varable:video regex:<#(NSString *)#>] // video_code=@"hqNcj6_lYg0"; // NSString* video_id=[self.playerView Embed2VID:video_code]; // // NSDictionary *playerVars = @{ // @"playsinline" : @1, // @"autoplay" : @(1), // @"rel":@0, // @"showinfo": @0, // @"modestbranding":@0, // @"enablejsapi":@1 // }; // // [self.playerView loadWithVideoId:video_id playerVars:playerVars]; [self.ytplayerView LoadWithVid:video_code]; for(UIView *v in self.ytplayerView.subviews) { if([v isKindOfClass:[UIButton class] ]) [self.ytplayerView bringSubviewToFront:v]; } self.ytplayerView.hidden=false; return; } else { if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) { return; } ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"]; preVC.content = self.stack_contents; // preVC.currentIndex = index; [preVC setOffset:index]; UIViewController *superVC= [RAUtils getViewController:self]; [superVC.navigationController pushViewController:preVC animated:true]; return; } // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count]; // for (int i = 0; i < _data.count; i++) { // UIImage *imgMod = _data[i]; // [imgList addObject:imgMod]; // } // 调用展示窗口 // ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index]; // // UIViewController *vc= [RAUtils getViewController:self]; // [vc.navigationController pushViewController:imgShow animated:true]; // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow]; // [self presentViewController:nav animated:YES completion:nil]; // UIDocumentInteractionController // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url]; // preview.delegate = self; // [preview presentPreviewAnimated:YES]; } -(void) neworder { // __block UIAlertController * waitalert = [RAUtils waiting_alert:[RAUtils getViewController:self] title:@"Create Order" completion:^{ PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil]; [RANetwork request_create_order:^(NSMutableDictionary *result) { NSMutableDictionary* return_json = result; // [waitalert dismissViewControllerAnimated:YES completion:^{ [pop hide]; if([[return_json valueForKey:@"result"] intValue]==2) { int result=[[return_json valueForKey:@"result"] intValue]; if(result==2) { //successed. NSString* order_code = [return_json valueForKey:@"orderCode"]; AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.order_code = order_code; int count=[self.quantity_text.text intValue]; [self addtocart:count]; } } else { // UIViewController *vc= [RAUtils getViewController:self]; NSString *msg = [return_json valueForKey:@"err_msg"]; NSString *title = @"Add To Cart"; if ([msg hasPrefix:@"Out of Stock.\n"]) { title = @"Add To Cart: Out of Stock"; msg = [msg substringFromIndex:[@"Out of Stock.\n" length]]; self.btnNotifyMe.enabled = YES; self.btnaddCart.enabled = NO; } [RAUtils message_box:title message:msg completion:nil] ; } // }]; }]; // }]; } - (void)valueChanged:(UIStepper *)sender { self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ]; [celldelegate stepClicked:(int)sender.value]; // -(void) stepClicked:(int) value; // 检查缺货 // NSString *cartQtyString = nil; // if (self.cqyt_label.text) { // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]]; // } // // int availability = [self.count_Label.text intValue]; // int buyQTY = [self.quantity_text.text intValue]; // int cartQTY = [cartQtyString intValue]; // // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY]; } #pragma mark - #pragma mark Actions -(void)ClearPhotos { NSMutableArray *photosMutable = [self.photos mutableCopy]; [photosMutable removeAllObjects]; self.photos = photosMutable; [self.photoStack reloadData]; } - (void)AddPhoto :(UIImage*)photo { NSMutableArray *photosMutable = [self.photos mutableCopy]; [photosMutable addObject:photo]; self.photos = photosMutable; [self.photoStack reloadData]; self.pageControl.numberOfPages = [self.photos count]; if(self.photos.count<2-1)//1 for qrcode; self.photoStack.showBorder=false; else self.photoStack.showBorder=true; } #pragma mark - #pragma mark Setup -(void)setup { // int availability = [self.count_Label.text intValue]; self.stepper.minimumValue= self.step; self.stepper.maximumValue = INTMAX_MAX; self.stepper.stepValue= self.step; self.stepper.value= self.quantity; [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; if(true)//(self.photos==nil) { self.photos = [NSArray array]; } if(true)//(self.photoStack==nil) { // if(self.photoStack!=nil) // [self.photoStack removeFromSuperview]; // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)]; // self.photoStack.backgroundColor =[UIColor redColor]; // self.photoStack.center = CGPointMake(self.center.x, 220); self.photoStack.dataSource = self; self.photoStack.delegate = self; // [self addSubview:self.photoStack]; self.pageControl.numberOfPages = [self.photos count]; } } - (IBAction)notifyMeButtonClicked:(UIButton *)sender { if (self.notifyMeBlock) { self.notifyMeBlock(); } } #pragma mark - TextField Delegate - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; // NSString *cartQtyString = nil; // if (self.cqyt_label.text) { // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]]; // } // int availability = [self.count_Label.text intValue]; int buyQTY = [newString intValue]; // int cartQTY = [cartQtyString intValue]; // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY]; self.stepper.value = buyQTY; return YES; } #pragma mark - Private /**检查是否缺货*/ - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得 //#if defined(BUILD_NPD) || defined(BUILD_USAI) AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; if (!appDelegate.bLogin || buyQty < 1) { return; } #ifdef OFFLINE_MODE if (appDelegate.offline_mode) { return; } #endif if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer if (!appDelegate.order_code) { // 未打开订单状态 if ((buyQty + cartQty) > availability) { self.btnaddCart.enabled = NO; self.btnNotifyMe.enabled = YES; } else { self.btnaddCart.enabled = YES; self.btnNotifyMe.enabled = NO; } } else { // 打开订单状态 if (![RASingleton sharedInstance].currentOrderIsMerged) { // Shop Order self.btnaddCart.enabled = YES; // 默认未缺货 self.btnNotifyMe.enabled = NO; if ((buyQty + cartQty) > availability) { // 缺货 self.btnNotifyMe.enabled = YES; } } else { // Purchase Order if ((buyQty + cartQty) > availability) { // 缺货 self.btnaddCart.enabled = NO; self.btnNotifyMe.enabled = YES; } else { // 未缺货 self.btnNotifyMe.enabled = NO; self.btnaddCart.enabled = YES; } } } } else { // empoyee if ((buyQty + cartQty) > availability) { // 缺货 self.btnaddCart.enabled = NO; self.btnNotifyMe.enabled = YES; } else { // 未缺货 self.btnNotifyMe.enabled = NO; self.btnaddCart.enabled = YES; } } //#endif } - (IBAction)introduceBtnClick:(UIButton *)sender { if (self.introduceBlock) { self.introduceBlock(sender); } } - (IBAction)descriptionBtnClick:(UIButton *)sender { if (self.descriptionBlock) { self.descriptionBlock(sender); } } - (IBAction)OnClosePlayer:(id)sender { [self.ytplayerView stopVideo]; self.ytplayerView.hidden=true; } - (IBAction)noLoginBtnClick:(UIButton *)sender { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(appDelegate.bLogin==false) { DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self]; LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"]; loginvc.returnValue = ^(bool blogin){ if(blogin) { [vc reload]; [main_vc checklogin:true]; } }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 [vc presentViewController:navi animated:YES completion:^{ }]; } } @end