// // WatchListViewController.m // RedAnt ERP Mobile // // Created by Ray on 14-8-1. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "WatchListViewController.h" #import "RANetwork.h" #import "ModelItemCell.h" #import "DetailViewController.h" #import "LoginViewController.h" #import "MainViewController.h" #import "TearSheetParamViewController.h" #import "EditModelPriceViewController.h" #import "ContactListViewController.h" #import "DefaultTableHeaderView.h" #import "DefaultAppearance.h" #import "SortItemViewController.h" #import "SortButton.h" #import "UIColor+JK_HEX.h" #import "CartUtils.h" #import "RAPDFViewController.h" #import "JKMessageBoxController.h" #import "FileCache.h" //#define ALERT_DEL 1025 //#import "PDFViewController.h" @interface WatchListViewController () @property (strong, nonatomic) IBOutlet UIBarButtonItem *emailBtn; @property (strong, nonatomic) IBOutlet UIBarButtonItem *printBtn; @property (nonatomic,strong) SortItemViewController *sortItemController; @property (nonatomic,assign) int sortIndex; @property (nonatomic,strong) SortButton *sortButton; @property (nonatomic,strong) UILabel *qtyLabel; @property (nonatomic,strong) NSOperationQueue *dataOperationQueue; @property (nonatomic,copy) NSString *print_url; //仅用于加购物车的临时变量,避免wishlist刷新后check 丢失。 @property (nonatomic,strong) NSMutableArray* checked_cart; @property (nonatomic,strong) NSMutableArray* checked_iid_cart; @end @implementation WatchListViewController - (NSOperationQueue *)dataOperationQueue { if (!_dataOperationQueue) { _dataOperationQueue = [[NSOperationQueue alloc] init]; _dataOperationQueue.maxConcurrentOperationCount = 1; } return _dataOperationQueue; } -(void) logout { self.content_data = nil; [self refresh_ui]; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } #ifndef RA_NOTIFICATION -(void) reload_container_getdata:(bool) update_data { [super reload_container_getdata:update_data]; if(update_data) [self reload_data]; else [self.itemListTable reloadData]; } #endif - (IBAction)onAddtoCart:(id)sender { self.checked_cart = [[NSMutableArray alloc] init]; self.checked_iid_cart= [[NSMutableArray alloc] init]; int count = [[self.content_data valueForKey:@"count"] intValue]; 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:true]; //// } // } // // // 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;//有三种状态,自己看看是哪种 // [self presentViewController:navi animated:YES completion:^{ // // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); // // DebugLog(@"LoginViewController present........."); // // // self.btop = false; // // <#code#> // }]; // } // 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(@"", 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) addtocart { [self addtocart:self.checked_cart checked_iid:self.checked_iid_cart]; self.checked_cart=nil; self.checked_iid_cart=nil; } -(void) addtocart:(NSMutableArray*) checked checked_iid:(NSMutableArray*)checked_iid { if(checked.count==0) { [RAUtils message_box:@"Cannot Add to cart." message:@"You must select at least one model." completion:nil]; return; } NSString * ids = [checked_iid componentsJoinedByString:@","]; self.btnAddtoCart.enabled = false; [RANetwork request_move_wish2cart:ids completionHandler:^(NSMutableDictionary *result) { NSDictionary* return_json = result; self.btnAddtoCart.enabled = true; if([[return_json valueForKey:@"result"] intValue]==2) { #ifdef RA_NOTIFICATION [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA]; #else AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false]; [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true]; [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false]; #endif [RAUtils message_box:@" Multiple items moved to Cart" message:@"" completion:nil]; } else { [self reload_data]; [RAUtils message_box:@"Move To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil]; } }]; } - (void)viewDidLoad { [super viewDidLoad]; DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame)); UIRefreshControl *ref = [[UIRefreshControl alloc]init]; ref.tag = 200 ; ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; // ref.hidden = true; [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged]; [self.itemListTable addSubview:ref]; DebugLog(@"%@",NSStringFromCGRect(self.itemListTable.frame)); // [[UIToolbar appearance] setBackgroundColor: [UIColor whiteColor]]; 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; CGPoint center = self.mum.center; self.mum.frame = CGRectMake(0, 0, 100, 100); self.mum.center = center; // self.mum.backgroundColor = [UIColor colorWithHEX:0xA5A5A5 alpha:0.5]; self.mum.layer.cornerRadius = 5.0f; self.mum.layer.masksToBounds = YES; self.sortIndex = 0; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)]; // tap.minimumPressDuration = 0.8; //定义按的时间 [self.label_net_err addGestureRecognizer:tap]; // [self reload_data]; } -(void)manually_refresh { UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; if(self.isrefreshing) { [reF endRefreshing]; return; } reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"]; [self performSelector:@selector(reload_data) withObject:nil afterDelay:1]; // DebugLog(@"refresh!!!!!!!!"); } - (IBAction)onSelectClick:(id)sender { // self.total=0; if([self.btnselect.title isEqualToString:@"Select all"]) { int count =[[self.content_data valueForKey:@"count"] intValue]; for(int i=0;i 1) { return; } dispatch_async(dispatch_get_main_queue(), ^{ if(self.isrefreshing) return; // [self.content_data removeAllObjects]; // [self.itemListTable reloadData]; self.isrefreshing=true; self.label_net_err.hidden=true; self.itemListTable.hidden=true; self.mum.center = self.view.center; self.mum.hidden = false; [self.mum startAnimating]; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; [reF endRefreshing]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; [RANetwork request_wishlist:self.sortIndex completionHandler:^(NSMutableDictionary *result) { NSMutableDictionary* cart_json =result; [self.mum stopAnimating]; self.isrefreshing=false; if (self.dataOperationQueue.operationCount > 1) { return ; } int result_code=[[cart_json valueForKey:@"result"] intValue]; self.content_data = [cart_json mutableCopy]; [self.itemListTable reloadData]; self.print_url = [cart_json objectForKey:@"wishlist_print_url"]; if(result_code==2||result_code==1||result_code==0) { self.itemListTable.hidden=false; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; appDelegate.wish_count =[[self.content_data valueForKey:@"count"] intValue]; } else if(result_code==RESULT_NET_ERROR) { self.label_net_err.hidden=false; self.itemListTable.hidden=true; } else { [RAUtils message_box:@"Loading Wish list" message:[cart_json valueForKey:@"err_msg"] completion:nil]; } self.isrefreshing=false; }]; return; }); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 33; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"]; if(value==nil) value=@""; unsigned long color = strtoul([value UTF8String],0,16); NSString *sectionTitle = @"Wish List"; DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 33)]; // UIButton *sortButton = [UIButton buttonWithType:UIButtonTypeCustom]; // sortButton.frame = CGRectMake(20, 5.5, (33 - 5.5 * 2), (33 - 5.5 * 2)); // [sortButton setImage:[UIImage imageNamed:@"check_1_24"] forState:UIControlStateNormal]; // [sortButton addTarget:self action:@selector(wishlistSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; // [myView addSubview:sortButton]; [myView addSubview:self.sortButton]; UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5.5, tableView.bounds.size.width, 22)]; titlelabel.textColor=UIColorFromRGB(color); titlelabel.textAlignment=NSTextAlignmentCenter; titlelabel.autoresizingMask=UIViewAutoresizingFlexibleWidth; titlelabel.text=sectionTitle; titlelabel.center = myView.center; myView.autoresizesSubviews=true; [myView addSubview:titlelabel]; [myView addSubview:self.qtyLabel]; return myView; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // NSDictionary * item_json = [self.content_data objectForKey:@"items"]; int count =[[self.content_data valueForKey:@"count"] intValue]; return count; } - (IBAction)imgbtnClicked:(UIButton *)sender { UITableViewCell* cell =(UITableViewCell*) sender.superview.superview; NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell]; // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row); NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; NSString* product_id = [item_json valueForKey:@"product_id"]; NSString *name = [item_json objectForKey:@"description"]; NSRange subRange = [name rangeOfString:@"\n"]; name = [name substringToIndex:subRange.location]; DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ]; // dvc dvc.product_id=product_id; dvc.category_id=nil; dvc.ispush=true; dvc.model_name = name; [dvc reload]; [self.navigationController pushViewController:dvc animated:true]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // if(tableView==self.itemListTable) // { NSString *CellIdentifier = @"WatchListItemCell"; ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; // Button 设置了大小约束,Size就不会随内容变化 [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit]; #if __IPHONE_OS_VERSION_MIN_REQUIRED <150000 [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; #endif [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill]; [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill]; cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit; NSString* img_url = [item_json valueForKey:@"img"]; NSString* description = [item_json valueForKey:@"description"]; // NSString* identifier = [item_json valueForKey:@"identifier"]; // NSString* attribute = [item_json valueForKey:@"attribute"]; // NSString* currency = [item_json valueForKey:@"currency"]; // int count =[[item_json valueForKey:@"count"] intValue]; NSString* price =[item_json valueForKey:@"tear_sheet_price"]; // cell.labelAttribute.text = attribute; // cell.labelCurrency.text = currency; cell.labelDescription.text = description; // cell.labelIdentifier.text = identifier; cell.labelPrice.text = price; // cell.editCount.text =[NSString stringWithFormat:@"%d",count]; // NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]]; int check = [[item_json valueForKey:@"check"] intValue]; if(check==1) cell.img_checkmark.hidden=false; else cell.img_checkmark.hidden=true; // UIImageView* iv =cell.btnImage.imageView; // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal]; [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal]; NSString* file_name=[img_url lastPathComponent]; NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url]; if(img_data!=nil) { UIImage * img =[UIImage imageWithData:img_data]; // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal]; [cell.btnImage setImage:img forState:UIControlStateNormal]; } else { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]]; dispatch_async(dispatch_get_main_queue(), ^{ if(downloadimg_data!=nil) { [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url]; UIImage * img =[UIImage imageWithData:downloadimg_data]; // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal]; [cell.btnImage setImage:img forState:UIControlStateNormal]; } else // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal]; [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal]; }); }); } cell.backgroundColor = [UIColor whiteColor];// [UIColor whiteColor];; int qty = [item_json[@"cart_count"] intValue]; cell.qty_Label.text = [NSString stringWithFormat:@"QTY: %d",qty]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath]; cell.selected = false; // self.dirty = true; NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy]; int check = [[item_json valueForKey:@"check"] intValue]; if(check==1) { [item_json setValue:@"0" forKey:@"check"]; cell.img_checkmark.hidden=true; [self.btnselect setTitle: @"Select all"]; } else { [item_json setValue:@"1" forKey:@"check"]; cell.img_checkmark.hidden=false; } [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } //#pragma mark - UIAlertViewDelegate //// Called when a button is clicked. The view will be automatically dismissed after this call returns //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex //{ // // // //} - (BOOL)isPureFloat:(NSString*)string{ NSScanner* scan = [NSScanner scannerWithString:string]; float val; return[scan scanFloat:&val] && [scan isAtEnd]; } #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮 //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { // 添加一个删除按钮 self.indexPath=indexPath; // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { DebugLog(@"delete click"); UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Delete confirm" message:@"Are you sure remove model from wishlist?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy]; NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]]; // __block UIAlertController* wait_alert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{ PopWaitAlert* pop=[RAUtils waiting_pop:@"Remove Model" completion:nil]; [RANetwork request_remove_wishlist:ids completionHandler:^(NSMutableDictionary *result) { NSMutableDictionary* cart_json = result; // [wait_alert dismissViewControllerAnimated:YES completion:^{ [pop hide]; if([[cart_json valueForKey:@"result"] intValue]==2) { [self reload_data]; } else { [RAUtils message_box:@"Delete Model" message:cart_json[@"err_msg"] completion:nil]; } // }]; }]; // }]; }]; UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertController addAction:action_2]; [alertController addAction:action_3]; [self presentViewController:alertController animated:YES completion:nil]; }]; deleteRowAction.backgroundColor = UIColorFromRGB(0x336699); return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]]; // // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // if(appDelegate.user_type==USER_ROLE_EMPLOYEE) // // return @[deleteRowAction]; // // else // return @[deleteRowAction]; // } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } #pragma mark - sort button - (void)wishlistSortButtonClicked:(UIButton *)sender { DebugLog(@"wish list sort button clicked"); [self.view addSubview:self.sortItemController.view]; } - (SortItemViewController *)sortItemController { if (!_sortItemController) { _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(40, 40)]; _sortItemController.sortIndex = self.sortIndex; _sortItemController.sortData = @[ @{@"title":@"Last",@"icon":@"TX_18"}, @{@"title":@"First",@"icon":@"TS_18"}, @{@"title":@"Item number a-z",@"icon":@"IX_18"}, @{@"title":@"Item number z-a",@"icon":@"IS_18"}, @{@"title":@"Description",@"icon":@"DX_18"}, ]; __weak typeof(self) weakSelf = self; _sortItemController.sortBlock = ^(int sort){ weakSelf.sortIndex = sort; [weakSelf reload_data]; }; } // _sortItemController.sortIndex = self.sortIndex; return _sortItemController; } - (SortButton *)sortButton { if (!_sortButton) { _sortButton = [SortButton sortButtonWithHeight:33]; [_sortButton addTarget:self action:@selector(wishlistSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; } return _sortButton; } - (void)setSortIndex:(int)sortIndex { _sortIndex = sortIndex; NSString *selectedImageName = @""; switch (sortIndex) { case 0:{ selectedImageName = @"TX_22"; } break; case 1:{ selectedImageName = @"TS_22"; } break; case 2:{ selectedImageName = @"IX_22"; } break; case 3:{ selectedImageName = @"IS_22"; } break; case 4:{ selectedImageName = @"DX_22"; } break; default: break; } self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName]; } - (UILabel *)qtyLabel { if (!_qtyLabel) { _qtyLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.itemListTable.bounds.size.width - 200, 5.5, 40, 22)]; _qtyLabel.text = @"QTY"; _qtyLabel.textAlignment = NSTextAlignmentCenter; _qtyLabel.autoresizingMask= UIViewAutoresizingFlexibleLeftMargin; } return _qtyLabel; } #pragma mark - rotation //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { // // self.sortItemController.view.frame = self.view.bounds; //} - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [coordinator animateAlongsideTransition:^(id _Nonnull context) { // what ever you want to prepare } completion:^(id _Nonnull context) { self.sortItemController.view.frame = self.view.bounds; // self.sortItemController.view.frame = self.view.bounds; self.qtyLabel.frame = CGRectMake(self.itemListTable.bounds.size.width - 200, 5.5, 40, 22); }]; } //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // return YES; //} - (BOOL)shouldAutorotate { return YES; } //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { // // self.sortItemController.view.frame = self.view.bounds; // self.qtyLabel.frame = CGRectMake(self.itemListTable.bounds.size.width - 200, 5.5, 40, 22); // //} #pragma mark - Action - (IBAction)printWishlistClick:(UIBarButtonItem *)sender { if ([[self.content_data valueForKey:@"count"] intValue] < 1) { [RAUtils message_box:@"Warning" message:@"Please add wishlist first" completion:nil]; return; } if (self.print_url.length == 0) { [RAUtils message_box:@"Warning" message:@"There is no resource to print" completion:nil]; } RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"]; ViewController.url = self.print_url; ViewController.canSave = false; ViewController.isLocalfile=NO; NSString* subject; subject =@"Wishlist Print"; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"]; NSMutableArray* send_to = [[NSMutableArray alloc]init]; if(customer_email.length>0) { send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy]; } ViewController.mail_to = send_to; // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Wish_List %@.pdf",cur_time]; /* #ifdef BUILD_HOMER ViewController.filename = [NSString stringWithFormat:@"HOMER_Wish_List.pdf"]; #endif #if defined(BUILD_NPD) || defined(BUILD_USAI) ViewController.filename = [NSString stringWithFormat:@"NPD_Wish_List.pdf"]; #endif */ ViewController.filename = [NSString stringWithFormat:@"%@_Wish_List.pdf",COMPANY_SHORT_NAME]; ViewController.mail_subject = subject; ViewController.hidenavi = false; [self.navigationController pushViewController:ViewController animated:YES]; } - (IBAction)emailWishlistClick:(UIBarButtonItem *)sender { if ([[self.content_data valueForKey:@"count"] intValue] < 1) { [RAUtils message_box:@"Warning" message:@"Please add wishlist first" completion:nil]; return; } JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"]; emailAddrVC.textFiled.secureTextEntry = NO; emailAddrVC.yesButtonTitle = @"send"; __weak typeof(emailAddrVC) weakVC = emailAddrVC; __weak typeof(self) weakself = self; emailAddrVC.textHandler = ^(NSString *text){ // 验证邮箱格式是否正确 // NSString *match = EMAIL_MATCHES; // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match]; // BOOL isEmailAddr = [predicate evaluateWithObject:text]; BOOL isEmailAddr = YES; if (isEmailAddr) { // 验证是邮件地址,发送邮件 [weakVC dismissViewControllerAnimated:YES completion:^{ // __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{ PopWaitAlert* pop=[RAUtils waiting_pop:@"Sending Email" completion:nil]; [RANetwork request_emailwishlist:text completionHandler:^(NSMutableDictionary *result) { DebugLog(@"email wishlist result: %@",result); // [waitting_alert dismissViewControllerAnimated:YES completion:^{ [pop hide]; // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES]; if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) { UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [errorAlertVC addAction:action]; [weakself presentViewController:errorAlertVC animated:YES completion:nil]; }else { [RAUtils message_box:@"Email was sent successfully" message:@"" completion:nil]; } // }]; }]; // }]; }]; } else { // 非邮件地址,警告 [weakVC warning:@"Please enter right email address"]; } }; [self presentViewController:emailAddrVC animated:YES completion:nil]; } - (void)reRefreshView { [self.itemListTable reloadData]; } #pragma mark - RA_NOTIFICAITON -(void) refresh_ui { [self.itemListTable reloadData]; } -(void) reload_data { __weak typeof(self) weakself = self; NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ if (weakself) { __strong typeof(weakself) strongself = weakself; [strongself operation_reload_data]; } }]; [self.dataOperationQueue addOperation:operation]; } @end