// // CategoryViewController.m // RedAnt ERP Mobile // // Created by Ray on 14-5-27. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "CategoryViewController.h" #import "CategorySearchFilterViewController.h" #import "DetailHeaderCell.h" #import "DetailImageCell.h" #import "iSalesNetwork.h" #import "DetailTopicCell.h" #import "RTLabel.h" #import "DetailKVCell.h" #import "LineView.h" #import "PopupNavigationController.h" #import "RAViewController.h" #import "LoginViewController.h" #import "ContactListViewController.h" //#import "RAUtils.h" #import "OrderListViewController.h" //#import "CategoryCellLarge.h" //#import "CategoryCellSmall.h" #import "DetailViewController.h" #import "CategoryCellNPD.h" #import "MainViewController.h" //#import "ScannerViewController.h" #define DEF_CELL_HEIGHT 44 #define DEF_TABLE_HEIGHT 44 #define LINE_WIDTH 0 #define CELL_MARGIN 0 #define LABEL_MARGIN 5 @interface CategoryViewController () @end @implementation CategoryViewController -(void) logout { self.offset = 0; self.category_data=nil; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void)begin_select { self.addCartBtn.enabled=false; self.addWishBtn.enabled=false; self.addPortfolioBtn.enabled=false; self.selectToolbar.hidden=false; // self.collectionview.allowsMultipleSelection = YES; self.isSelectionMode=true; self.select_count=0; } -(void)end_select:(int) type { self.select_count=0; self.selectToolbar.hidden=true; // self.collectionview.allowsMultipleSelection = NO; NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy]; int count = [[items valueForKey:@"count"] intValue]; for(int i=0;i }]; } - (IBAction)onSelectClick:(id)sender { [self begin_select]; } - (IBAction)onCancelSelectClick:(id)sender { [self end_select:0]; } - (IBAction)onSelectAllClick:(id)sender { // int tag =self.selectallBtn.tag; NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy]; int count = [[items valueForKey:@"count"] intValue]; NSString* checked; if (self.selectallBtn.tag == 0) { self.selectallBtn.tag = 1; [self.selectallBtn setTitle:@"Deselect all"]; if(count>0) { self.addWishBtn.enabled = true; self.addCartBtn.enabled = true; self.addPortfolioBtn.enabled=true; } self.select_count=count; checked=@"true"; } else { self.selectallBtn.tag = 0; [self.selectallBtn setTitle:@"Select all"]; self.addWishBtn.enabled = false; self.addCartBtn.enabled = false; self.addPortfolioBtn.enabled=false; checked=@"false"; } for(int i=0;i0) { 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(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil]; // alert. [alert show]; } } else { [main_vc checklogin:false]; [self addtocart]; } } // 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 = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else { if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/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(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil]; // alert. [alert show]; } } else { if(appDelegate.order_code==nil) [ self neworder]; else [self addtocart]; } } } -(void) neworder { UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* return_json = [iSalesNetwork new_Order]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; 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; [self addtocart]; // [self ReloadData]; // 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); // // } } } else { [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ; } }); }); } - (IBAction)onAddPortfolioClick:(id)sender { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(appDelegate.bLogin==false) { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ if(blogin) { [main_vc checklogin:false]; [self addtoportfolio]; } }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else { [self addtoportfolio]; } } - (IBAction)onAddWishlistClick:(id)sender { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(appDelegate.bLogin==false) { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ if(blogin) { [main_vc checklogin:false]; [self addtowish]; } }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else { [self addtowish]; } } -(void) addtocart { NSMutableDictionary* items =[[self.category_data objectForKey:@"items"] mutableCopy]; int count = [[items valueForKey:@"count"] intValue]; NSMutableArray* checked = [[NSMutableArray alloc] init]; for(int i=0;i }]; [categorymenuVC SetMenu:self.categoryMenu]; } // //- (IBAction)onSortClick:(id)sender { // // // NSMutableDictionary* sort_json = [self.category_data objectForKey:@"sort"]; // // NSDictionary* item_json =[section_json objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row ]]; // // NSString* control = [item_json valueForKey:@"control"]; // // if([control isEqualToString:@"enum"])//||[control isEqualToString:@"ui"]) // // { // // // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",indexPath.row]]; // // NSDictionary* cadedate_json = [sort_json objectForKey:@"cadedate"]; // // NSDictionary* value_json = [item_json objectForKey:@"value"]; // // NSString* single_select = [item_json valueForKey:@"single_select"]; // // NSString* required =[item_json valueForKey:@"required"]; // // // // EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"]; // // if([[required lowercaseString] isEqualToString:@"true"]) // // enumvc.canbeEmpty = false; // // else // // enumvc.canbeEmpty =true; // enumvc.cadedate = [sort_json mutableCopy]; // // enumvc.value = [value_json mutableCopy]; // enumvc.single_select =true; // enumvc.auto_close = true; // enumvc.title = @"sort"; // enumvc.is_dialog = true; // // // enumvc.returnValue = ^(NSMutableDictionary* value, int idx){ // [self.category_data setObject:value forKey:@"sort"]; // // NSLog(@"点击了第%d个",pageIndex); // }; // // /// PopupNavigationController * navi=[[PopupNavigationController alloc] initWithRootViewController:enumvc]; // // // self.aBNewPersonNav = [[UINavigationController alloc] initWithRootViewController:enumvc] ; // // enumvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // // // enumvc.delegate = self; // [self presentViewController:enumvc animated:YES completion:^{ // // NSLog(@"login........."); // // <#code#> // }]; // // [self.navigationController pushViewController:enumvc animated:true]; // //} -(void)viewWillLayoutSubviews { // if(self.showDetail==true) // { // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation; // int width=175; // // int height; // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight) // { // width = 370; // // height = 400; // } // else // { // // height = 300; // width = 175; // } // // // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64); // // self.collectionview.frame=frame; // // // // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64); // self.detailView.frame = framedetail; // } self.headerView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.headerView.bounds].CGPath; self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath; } -(void) showCategory { if(self.showDetail==false) return; // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation; // int width=175; // // int height; // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight) // { // width = 370; // // height = 400; // } // else // { // // height = 300; // width = 175; // } // CGRect frame = CGRectMake(0, 48, self.view.bounds.size.width , self.view.bounds.size.height-48); [UIView animateWithDuration:0.5 animations:^{ self.collectionview.frame=frame; }]; self.collectionview.autoresizingMask = self.collectionview.autoresizingMask | UIViewAutoresizingFlexibleWidth; self.showDetail = false; self.cagegoryLabel.hidden = false; } -(void) loadMore { dispatch_async(dispatch_get_main_queue(), ^{ self.isrefreshing=true; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* category_more=[iSalesNetwork Category:self.categoryid customid:0 price_template:0 sort:0 filter:nil keyword:nil offset:self.offset limit:20 alert:self.p_alert qty:self.p_QTY available:self.p_available price:self.p_price] ; dispatch_async(dispatch_get_main_queue(), ^{ NSDictionary* more_items=[category_more objectForKey:@"items"]; if([[category_more valueForKey:@"result"] intValue]==2) { // self.category_data = category_data; NSMutableDictionary* items_json= [[self.category_data objectForKey:@"items"] mutableCopy]; int count =[[more_items valueForKey:@"count"] intValue]; for(int i=0;i