| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249 |
- //
- // 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];
- }
- -(void) reload_container_getdata:(bool) update_data
- {
- [super reload_container_getdata:update_data];
- if(update_data)
- {
- self.offset = 0;
- [self.content_data removeAllObjects];
- 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.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];
- //
- // }
-
- NSData* json =nil;
- if(self.init_style==OL_OPEN)
- json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
- else
- json=[NSData dataWithContentsOfFile:dist_path];
- NSError *error=nil;
- self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- // [self.table_order addSubview:ref];
-
- // self.scrollView.contentSize=CGSizeMake(1024, 1024);
-
- // self.btnrefresh = [UIButton buttonWithType:UIButtonTypeCustom];
- // // self.btnrefresh.titleLabel.text =@"Load more";
- // [self.btnrefresh setTitle:NSLocalizedString(@"load_more", nil) forState:UIControlStateNormal];
- // // [self.btnrefresh.titleLabel sizeToFit];
- // self.btnrefresh.titleLabel.adjustsFontSizeToFitWidth = YES;
- // self.btnrefresh.hidden = true;
- // [self.btnrefresh setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- // self.btnrefresh.backgroundColor = [UIColor lightGrayColor];
- // [self.btnrefresh addTarget:self action:@selector(loadmore) forControlEvents:UIControlEventTouchUpInside];
- // self.btnrefresh.frame =CGRectMake(0.0f, 0.0f, self.table_order.bounds.size.width, 44.0f);
- // self.table_order.tableFooterView = self.btnrefresh;//tableFooterView;
- // [self loadpage];
-
- //
- //
- // self.toolbarView.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolbarView.bounds].CGPath;
- // self.toolbarView.layer.masksToBounds = false;
- // //添加四个边阴影
- //
- // self.toolbarView.layer.shadowColor = [UIColor blackColor].CGColor;
- // self.toolbarView.layer.shadowOffset = CGSizeMake(0, 0);
- // self.toolbarView.layer.shadowOpacity = 0.5;
- // self.toolbarView.layer.shadowRadius = 2.0;
- }
- - (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];
-
-
-
- // 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.content_data removeAllObjects];
- // [self.table_order reloadData];
-
- [self loadpage];
-
- // [self loadpage];
- }
- -(void) loadpage
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- if(self.isrefreshing)
- return;
- self.isrefreshing=true;
- if(self.offset==0)
- {
- self.table_order.hidden = true;
-
- self.mum.center = self.view.center;
-
- self.mum.hidden = false;
- [self.mum startAnimating];
- }
- self.label_net_err.hidden=true;
-
- NSMutableArray* arr_status = [[NSMutableArray alloc] init];
-
- NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
- int count = [[self.status_cadedate valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
- int check = [[val_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
- [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
- // break;
- }
- }
- NSString * str_status = [arr_status componentsJoinedByString:@","];
- NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
- if(str_statusname.length==0)
- str_statusname = @"All";
- self.label_filter.text = str_statusname;
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
-
-
-
-
- NSMutableDictionary* content=nil;
- content=[[iSalesNetwork request_OrderList:self.offset limit : self.limit keywords:self.keywords status:str_status customer:self.customer_id] mutableCopy];
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
-
-
- [self.mum stopAnimating];
-
- int result=[[content valueForKey:@"result"] intValue];
-
- if(result==2||result==0)
- {
-
-
- int count = [[content valueForKey:@"count" ] intValue] ;
-
-
- self.time_zone = [content valueForKey:@"time_zone" ];
- self.offset += count;
- for(int i=0;i<count;i++)
- {
-
- NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
-
- }
- if(count<self.limit)
- {
-
- // int i =self.btnrefresh.state;
- self.load_more_hint=@"All loaded";
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
- // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
- }
- else
- {
- self.load_more_hint=@"Load more...";
- // self.btnrefresh.enabled = true;
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
- // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
- }
-
-
- self.table_order.hidden = false;
- [self.table_order reloadData ];
- }
- else if(result==RESULT_NET_ERROR &&self.offset==0)
- {
- self.label_net_err.hidden=false;
- self.table_order.hidden = true;
- }
- else
- {
- [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Order List" controller:self] ;
- }
-
- self.isrefreshing=false;
-
-
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- // bool autologin =[defaults boolForKey:@"autologin"];
- // if(!autologin)
- // {
- // TabBarController * viewController =[self.storyboard instantiateViewControllerWithIdentifier:@"LoginTabBar"];
- // [self presentViewController:viewController animated:YES completion:^{
- //
- // }];
- // }
-
-
- });
- });
-
- });
- }
- - (void)loadmore
- {
- // self.btnrefresh.enabled = NO;
- // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
-
- // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
- [self loadpage];
- }
- //-(void)changeCell
- //{
- //// UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- //// reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
- // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
- //
- //}
- -(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;
-
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- [main_vc reloadCart:true immediately:false];
- [self ReloadData];
-
-
- // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
- // [self loadpage];
-
-
- // 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:@"Create Order" controller:self] ;
- }
-
-
-
-
- });
- });
- }
- #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
- {
- if(buttonIndex!=alertView.cancelButtonIndex)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.order_code.length>0)
- {
- 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 = UIColorFromRGB(0xF2EEEA);
- 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 = UIColorFromRGB(0xF2EEEA);
- 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;
- // 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 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 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:@"SO Saved"]&&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:@"SO Saved"]&&! [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;
-
-
-
- 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 loadpage];
-
- //[self.btnStatusFilter setTitle:setTitle:alert ];
-
-
-
- }
- @end
|