// // OrderListViewController.m // RedAnt ERP Mobile // // Created by Ray on 8/18/15. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved. // #import "OrderListViewController.h" #import "OrderListTableViewCell.h" #import "iSalesNetwork.h" #import "OrderDetailViewController.h" #import "MainViewController.h" #import "ContactListViewController.h" @interface OrderListViewController () @end @implementation OrderListViewController -(void) logout { self.offset = 0; [self.content_data removeAllObjects]; [self.table_order reloadData]; self.status_cadedate = nil; } -(void) reload_container_getdata:(bool) update_data { [super reload_container_getdata:update_data]; if(update_data) { // self.offset = 0; // [self.content_data removeAllObjects]; self.reset_result=true; self.norefresh=true; [self loadpage]; } else { [self.table_order reloadData]; } AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.can_create_order) { [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]]; self.btn_newOrder.enabled = true; } else { [self.btn_newOrder setImage:nil]; self.btn_newOrder.enabled = false; } } -(void) showHidePrice { [self reload_container_getdata:false]; } - (void)viewDidLoad { [super viewDidLoad]; self.edgesForExtendedLayout = UIRectEdgeNone; self.loading_queue = dispatch_queue_create("orderlist_loading", NULL); 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; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)]; // tap.minimumPressDuration = 0.8; //定义按的时间 [self.label_net_err addGestureRecognizer:tap]; // Do any additional setup after loading the view. self.offset = 0; self.limit = 25; self.content_data = [[NSMutableArray alloc]init]; UIRefreshControl *ref = [[UIRefreshControl alloc]init]; ref.tag = 201 ; 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.table_order addSubview:ref]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *documents = [paths objectAtIndex:0]; NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"]; // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) { // // NSLog(@"文件已经存在了"); // // } // else // { // // // // // NSLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath); // // NSData *mainBundleFile = [NSData dataWithContentsOfFile:order_filter_source_path]; // // // NSLog(@"mainBundleFile==%@",mainBundleFile); // // [[NSFileManager defaultManager] createFileAtPath:dist_path // // contents:mainBundleFile // // attributes:nil]; // // } [self loadfilter]; } -(void) loadfilter { if(self.status_cadedate!=nil) return; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; NSData* json =nil; if(self.init_style==OL_OPEN) { json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]]; NSError *error=nil; self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy]; } else { // json=//[NSData dataWithContentsOfFile:dist_path]; // NSError *error=nil; self.status_cadedate = appDelegate.OrderFilter;//[[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy]; } } - (IBAction)onCancel:(id)sender { if(self.onCancel) self.onCancel(); [self.navigationController popViewControllerAnimated:false]; } - (IBAction)onStatusFilterClick:(id)sender { EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"]; enumvc.delegate = self; enumvc.max_select = 0; //enumvc.updatePosition = indexPath; // if([[required lowercaseString] isEqualToString:@"true"]) // enumvc.canbeEmpty = false; // else // enumvc.canbeEmpty =true; enumvc.cadedate = self.status_cadedate ; enumvc.title = @"Order Status Selection"; // enumvc.value = [value_json mutableCopy]; enumvc.single_select =false; [self.navigationController pushViewController:enumvc animated:true]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self loadfilter]; // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // if(appDelegate.bLogin==false) // { // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; //// loginvc.delegate = self; // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 // // loginvc.returnValue = ^(bool blogin){ // // // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; // // [main_vc checklogin:true]; // //// self.offset = 0; //// [self.content_data removeAllObjects]; //// [self loadpage]; // // [[self navigationController] setNavigationBarHidden:!self.showNavibar 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(!self.norefresh)//避免 多次刷新 // { // self.norefresh = true; // self.offset = 0; // [self.content_data removeAllObjects]; // [self loadpage]; // // } // // } [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO]; } - (IBAction)onNewOrderClicked:(id)sender { NSString* msg=@"Do you want to create a new order?"; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.order_code.length==0) { if(appDelegate.contact_id.length>0) { msg = [msg stringByAppendingString:@"\n\nCustomer:"]; msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]]; } } UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Attention", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil]; [alert show]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)manually_refresh { UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201]; if(self.isrefreshing) { [reF endRefreshing]; return; } reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"]; if ([self respondsToSelector:@selector(ReloadData)]) [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1]; } -(void)ReloadData { // [self.content_data removeAllObjects]; // [self.table_order reloadData]; // self.table_order.hidden = true; UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201]; [reF endRefreshing]; reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; self.keywords=self.searchbar.text; // self.offset = 0; self.reset_result=true; // [self.content_data removeAllObjects]; // [self.table_order reloadData]; [self loadpage]; // [self loadpage]; } -(void) loadpage { dispatch_async(self.loading_queue, ^{ dispatch_sync(dispatch_get_main_queue(), ^{ if(self.reset_result) { self.offset = 0; [self.content_data removeAllObjects]; [self.table_order reloadData]; } // NSMutableArray* arr_status = [[NSMutableArray alloc] init]; NSMutableArray* arr_statusname = [[NSMutableArray alloc] init]; int count = [[self.status_cadedate valueForKey:@"count"] intValue]; for(int i=0;i0) { appDelegate.order_code= nil; [appDelegate SetSo:nil]; // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ]; cvc.showNavibar = true; cvc.contact_type = @"Sales_Order_Customer"; cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){ appDelegate.contact_id=[value valueForKey:@"customer_cid"]; appDelegate.customerInfo = value; self.norefresh = true; [self neworder]; // [main_vc checklogin:true]; // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION]; // // if(self.returnValue) // self.returnValue(value); }; cvc.onCancel = ^(){ self.norefresh = true; if(appDelegate.customerInfo==nil) { [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self]; } else { [self neworder]; } // [main_vc checklogin:true]; }; cvc.onReset = ^(){ // [main_vc checklogin:true]; }; [self.navigationController pushViewController:cvc animated:true]; } else { //create new; if(appDelegate.customerInfo==nil)// select contact if current contact not exist { MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ]; cvc.showNavibar = true; cvc.contact_type = @"Sales_Order_Customer"; cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){ appDelegate.contact_id=[value valueForKey:@"customer_cid"]; appDelegate.customerInfo = value; if(appDelegate.order_code==nil) [self neworder]; // [main_vc checklogin:true]; // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION]; // // if(self.returnValue) // self.returnValue(value); }; cvc.onCancel = ^(){ [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self]; }; cvc.onReset = ^(){ [main_vc checklogin:true]; }; [self.navigationController pushViewController:cvc animated:true]; } else { [self neworder]; } } } } #pragma mark - Table view data source - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { return 66; } //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section //{ // return 0; //} //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section //{ // return 0; //} //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section //{ // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; // return myView; // //} - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)]; myView.backgroundColor = UIColorFromRGB(0x996633); myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath; myView.layer.shadowColor = [UIColor blackColor].CGColor; myView.layer.shadowOffset = CGSizeMake(0, 0); myView.layer.shadowOpacity = 0.5; myView.layer.shadowRadius = 2.0; UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 2, 130, 22)]; statuslabel.textColor=[UIColor whiteColor]; statuslabel.backgroundColor = [UIColor clearColor]; statuslabel.text=NSLocalizedString(@"Status", nil); [statuslabel sizeToFit]; [myView addSubview:statuslabel]; UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)]; solabel.textColor=[UIColor whiteColor]; solabel.backgroundColor = [UIColor clearColor]; solabel.text=NSLocalizedString(@"SO#", nil); [solabel sizeToFit]; [myView addSubview:solabel]; UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 2, 135, 22)]; userlabel.textColor=[UIColor whiteColor]; userlabel.backgroundColor = [UIColor clearColor]; userlabel.text=NSLocalizedString(@"Sales rep", nil); [userlabel sizeToFit]; [myView addSubview:userlabel]; UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 21, 135, 22)]; creatorlabel.textColor=[UIColor whiteColor]; creatorlabel.backgroundColor = [UIColor clearColor]; creatorlabel.text=NSLocalizedString(@"Create by", nil); [creatorlabel sizeToFit]; [myView addSubview:creatorlabel]; UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 11, 150, 22)]; contactlabel.textColor=[UIColor whiteColor]; contactlabel.backgroundColor = [UIColor clearColor]; contactlabel.text=NSLocalizedString(@"Contact", nil); [contactlabel sizeToFit]; [myView addSubview:contactlabel]; // // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)]; // modellabel.textColor=[UIColor whiteColor]; // modellabel.backgroundColor = [UIColor clearColor]; // modellabel.text=NSLocalizedString(@"Model", nil); // [modellabel sizeToFit]; // [myView addSubview:modellabel]; // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)]; // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; // modellabel.textColor=[UIColor whiteColor]; // modellabel.backgroundColor = [UIColor clearColor]; // modellabel.text=NSLocalizedString(@"Items/QTY", nil); // [modellabel sizeToFit]; // [myView addSubview:modellabel]; UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)]; pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; pricelabel.textColor=[UIColor whiteColor]; pricelabel.backgroundColor = [UIColor clearColor]; pricelabel.text=NSLocalizedString(@"Order Total", nil); [pricelabel sizeToFit]; [myView addSubview:pricelabel]; UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)]; timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; timelabel.textColor=[UIColor whiteColor]; timelabel.backgroundColor = [UIColor clearColor]; if(self.time_zone==nil) timelabel.text=@"Create time"; else timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone]; [timelabel sizeToFit]; [myView addSubview:timelabel]; myView.autoresizesSubviews=true; // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin]; // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; myView.autoresizingMask = UIViewAutoresizingFlexibleWidth; // return myView; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 44; } // //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // if(section==0) // return nil; // else // return @"detail section"; //} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // NSDictionary * item_json = [self.content_data objectForKey:@"items"]; if( self.content_data.count==0) return 0; return self.content_data.count+1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; // if(tableView==self.itemListTable) // { // if(indexPath.row>self.content_data.count) // { // int debug=true; // } // NSLog(@"row %ld",(long)indexPath.row); if(indexPath.row==self.content_data.count) { UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"]; UILabel *moreDataLabel=[[UILabel alloc] init]; moreDataLabel.tag=200; moreDataLabel.text=self.load_more_hint; [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]]; [moreDataLabel setTextAlignment:NSTextAlignmentCenter]; moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20); [moreDataLabel setBackgroundColor:[UIColor clearColor]]; // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged]; [moreCell.contentView addSubview:moreDataLabel]; if([self.load_more_hint isEqualToString:@"Load more..."]) [self performSelector:@selector(loadmore) withObject:nil afterDelay:1]; // NSLog(@"更多..."); moreCell.backgroundColor = [UIColor whiteColor]; return moreCell; } else { NSString *CellIdentifier = @"OrderListTableViewCell"; OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; NSString* po= [self.content_data[indexPath.row] valueForKey:@"so#"]; NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"]; if(appDelegate.can_see_price&&appDelegate.price_hidden==false) { } else { price=nil; } NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"]; NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ; NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"]; NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"]; NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"]; NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"]; cell.label_so.text=po; cell.labelprice.text=price; cell.label_date.text=purchase_time; cell.label_contact.text=customer_name; cell.label_model.text = model_count; cell.label_sales.text = sales; cell.label_creator.text = creator; cell.label_status.text=status; cell.backgroundColor = [UIColor whiteColor]; return cell; } // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]; // NSDictionary * combine_json =[item_json objectForKey:@"combine"]; // cell.bundle_item=combine_json; // NSString* img_url = [item_json valueForKey:@"img_url"]; // 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]; // double price =[[item_json valueForKey:@"price"] doubleValue]; // // cell.labelAttribute.text = attribute; // cell.labelCurrency.text = currency; // cell.labelDescription.text = description; // // cell.labelIdentifier.text = identifier; // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price]; // // // // [cell set_Count:count]; // NSString* file_name=[img_url lastPathComponent]; // NSData* img_data=[iSalesDB load_cached_img:file_name]; // if(img_data!=nil) // { // // UIImage * img =[UIImage imageWithData:img_data]; // [cell.btnImage setBackgroundImage: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) // { // [iSalesDB cache_img:downloadimg_data :file_name ]; // // UIImage * img =[UIImage imageWithData:downloadimg_data]; // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal]; // } // // }); // }); // // // } // } // else // { // NSString *CellIdentifier = @"OrderInfoListItem"; // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // return cell; // } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // if(indexPath.row==self.content_data.count) return; NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"]; OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ]; // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"]; dvc.selectOrder=^(NSMutableDictionary* order_detail){ [self.navigationController popViewControllerAnimated:false]; if(self.selectOrder) self.selectOrder(order_detail); }; NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"]; dvc.order_code = order_code; dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue]; // bool temp_order = false ; // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"]; // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"]) // temp_order=true; // // dvc.isTempOrder = temp_order; // dvc dvc.orderid=orderid; // dvc.category_id=nil; // dvc.ispush=true; // [dvc reload]; [self.navigationController pushViewController:dvc animated:true]; } #pragma mark - searchBar delegate; - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { self.keywords=searchBar.text; // self.offset = 0; // [self.content_data removeAllObjects]; self.reset_result=true; [self loadpage]; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if([searchText isEqualToString:@""] && !self.reset) { NSLog(@"clear"); self.reset=true; self.keywords=nil; // self.offset = 0; // [self.content_data removeAllObjects]; self.reset_result=true; [self loadpage]; } else self.reset = false; } #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮 - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { // 添加一个删除按钮 // self.indexPath=indexPath; if(indexPath.row==self.content_data.count) return @[]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.user_type!=USER_ROLE_EMPLOYEE) return @[]; NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"]; NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"]; NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"]; UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"delete click"); NSString * title =[NSString stringWithFormat:@"Are you sure to delete order SO#: %@",so]; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; //block代码块取代了delegate // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) { // textField.text = self.save_name; // // // }]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Delete Order"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* return_json = [iSalesNetwork delete_Order:orderid]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[return_json valueForKey:@"result"] intValue]==2) { if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]]) { appDelegate.order_code= nil; [appDelegate SetSo:nil]; } [RAUtils message_alert:nil title:@"Order Delete" controller:self] ; [self ReloadData]; } else { [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order" controller:self] ; } }); }); }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"Cancel"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; }]; deleteRowAction.backgroundColor = UIColorFromRGB(0x336699); // 添加一个编辑按钮 UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"edit click"); NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so]; UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Cancel Order"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* return_json = [iSalesNetwork cancel_Order:orderid]; dispatch_async(dispatch_get_main_queue(), ^{ [waitalert dismissWithClickedButtonIndex:0 animated:FALSE]; if([[return_json valueForKey:@"result"] intValue]==2) { if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]]) { appDelegate.order_code= nil; [appDelegate SetSo:nil]; } [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ; [self ReloadData]; } else { [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ; } }); }); }]; UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"Cancel"); }]; [alertControl addAction:actionOne]; [alertControl addAction:alertthree]; //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField) [self presentViewController:alertControl animated:YES completion:nil]; // }]; cancelAction.backgroundColor = UIColorFromRGB(0xff9933); if([order_status isEqualToString:@"Saved Order"]&&appDelegate.can_cancel_order) return @[cancelAction]; else { if([order_status isEqualToString:@"Quote Saved"]) { NSMutableArray* arr=[@[] mutableCopy]; if(appDelegate.can_delete_order) [arr addObject:deleteRowAction]; if(appDelegate.can_cancel_order) [arr addObject:cancelAction]; return arr; } } return @[]; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row==self.content_data.count) return UITableViewCellEditingStyleNone; NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"]; if(![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"]) return UITableViewCellEditingStyleNone; else return UITableViewCellEditingStyleDelete; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ #pragma mark EnumSelectViewControllerDelegate -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath { self.status_cadedate = value; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; appDelegate.OrderFilter = value; // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); // NSString *documents = [paths objectAtIndex:0]; // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"]; // // // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) { // // // // NSLog(@"文件已经存在了"); // // // // } // // else // // { // // // // // // // // NSLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath); // //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil]; // // // NSLog(@"mainBundleFile==%@",mainBundleFile); // // [[NSFileManager defaultManager] createFileAtPath:dist_path // // contents:data // // attributes:nil]; // // } // self.keywords=searchBar.text; // self.offset = 0; // [self.content_data removeAllObjects]; self.reset_result=true; [self loadpage]; //[self.btnStatusFilter setTitle:setTitle:alert ]; } @end