| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212 |
- //
- // PortfolioViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 12/7/15.
- // Copyright © 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "PortfolioViewController.h"
- #import "iSalesNetwork.h"
- #import "ModelItemCell.h"
- #import "DetailViewController.h"
- #import "LoginViewController.h"
- #import "MainViewController.h"
- #import "TearSheetParamViewController.h"
- #import "EditModelPriceViewController.h"
- #import "ContactListViewController.h"
- #define ALERT_DEL 1025
- @interface PortfolioViewController ()
- @end
- @implementation PortfolioViewController
- -(void) logout
- {
- self.content_data = nil;
- }
- -(void) reload_container_getdata:(bool) update_data
- {
- [super reload_container_getdata:update_data];
- if(update_data)
- [self reload_data];
- else
- [self.itemListTable reloadData];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.can_create_portfolio)
- {
-
-
- [self.btnCreatePort setTitle:@"Create Portfolio"];
- self.btnCreatePort.enabled = true;
- }
- else
- {
- [self.btnCreatePort setTitle:@""];
- self.btnCreatePort.enabled = false;
- }
- }
- -(void) showHidePrice
- {
- [self reload_container_getdata:false];
- // [self refresh_total];
-
- }
- - (IBAction)onAddtoCart:(id)sender {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.bLogin==false)
- {
-
- LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
- loginvc.returnValue = ^(bool blogin){
-
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
- if(blogin)
- {
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- {
-
- [main_vc checklogin:false];
-
- if(appDelegate.can_create_order)
- {
- NSString* msg =@"Do you want to switch to a pending order or a new order?";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
-
-
-
- // alert.
- [alert show];
- }
- else
- {
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
-
- // alert.
- [alert show];
- }
- }
- else
- {
- [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 = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- NSLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
- {
- [main_vc checklogin:false];
- if(appDelegate.can_create_order)
- {
- NSString* msg =@"Do you want to switch to a pending order or a new order?";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
-
- // alert.
- [alert show];
- }
- else
- {
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
-
- // alert.
- [alert show];
- }
- }
- else
- {
-
- if(appDelegate.order_code==nil)
- [ self neworder];
- else
- [self addtocart];
-
-
-
- }
- }
-
- }
- -(void) addtocart
- {
-
-
- NSMutableArray* checked = [[NSMutableArray alloc] init];
-
- NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
-
- int count = [[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- bool check = [[item_json valueForKey:@"check"] boolValue];
- if(check)
- {
- [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
- [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
- }
- }
-
- if(checked.count==0)
- {
- [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to cart." controller:self] ;
- return;
- }
-
- NSString * ids = [checked componentsJoinedByString:@","];
- self.btnCreatePort.enabled = false;
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [iSalesNetwork add_toCart:ids count:-1];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- self.btnCreatePort.enabled = true;
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- // int result=[[return_json valueForKey:@"result"] intValue];
- // if(result==2)
- // {
- // //successed.
-
- // NSString* order_code = [return_json valueForKey:@"order_code"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = order_code;
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = order_code;
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false ];
- [RAUtils message_alert:nil title:@" Multiple items added to Cart" controller:self] ;
-
- // [self end_select];
-
-
-
- // }
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- }
-
-
-
-
- });
- });
- }
- -(void) neworder
- {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [iSalesNetwork new_Order];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- int result=[[return_json valueForKey:@"result"] intValue];
- if(result==2)
- {
- //successed.
-
- NSString* order_code = [return_json valueForKey:@"orderCode"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = order_code;
-
-
- [self addtocart];
-
-
- // [self ReloadData];
-
-
- // if(self.shopCartBlock!=nil)
- // {
- // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
- //
- //
- // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- // iv.image = img;
- // // [self.contentView addSubview:iv];
- // self.shopCartBlock(iv);
- //
- // }
-
- }
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- }
-
-
-
-
- });
- });
- }
- - (IBAction)onCreateTearSheet:(id)sender {
-
-
- self.pdf_url= nil;
- NSMutableArray* checked = [[NSMutableArray alloc] init];
-
- NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
-
- int count = [[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- bool check = [[item_json valueForKey:@"check"] boolValue];
- if(check)
- {
- [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
- [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
- }
- }
- // disable for debug
- if(checked.count==0)
- {
- [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Create Portfolio." controller:self] ;
- return;
- }
-
-
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- NSString * string = [checked componentsJoinedByString:@","];
-
- NSString * string_iid = [checked_iid componentsJoinedByString:@","];
- [params setValue:string forKey:@"product_ids"];
- [params setValue:string_iid forKey:@"item_ids"];
- TearSheetParamViewController * VC =[ self.storyboard instantiateViewControllerWithIdentifier:@"TearSheetParamViewController"];
-
-
- VC.url_type = URL_REMOTE;
- VC.request_url=URL_DM_PARAMS;
-
- VC.params = params;
-
- // VC.delegate=self;
-
- VC.return_url=^(NSString* url,NSString* path, bool remove_item)
- {
- self.pdf_url = url;
- self.path = path;
- self.remove_item = remove_item;
- };
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- VC.onDismiss=^(NSString* catelog_name)
- {
- // PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
- // ViewController.url = self.pdf_url;
- // ViewController.mail_content = [self.content_data valueForKey:@"email_content"];
- //
- // ViewController.save_name =catelog_name;
- //
- //
- // NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
- //
- // if(company==nil)
- // company=@"";
- // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
- //
- //
- // NSMutableArray* send_to = [[NSMutableArray alloc]init];
- // if(customer_email.length>0)
- // [send_to addObject:customer_email];
- // ViewController.mail_to = send_to;
- //
- // NSString* subject;
- // if (company.length==0) {
- // subject = @"Tear sheet";
- //
- //
- //
- // }
- // else
- // {
- // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
- // }
- // ViewController.mail_subject = subject;
- //
- // ViewController.onLoadSuccess =^(NSString* url)
- // {
- // if(self.remove_item)
- // {
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* cart_json = [iSalesNetwork watchlist_remove:string_iid];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- //
- // if([[cart_json valueForKey:@"result"] intValue]==2)
- // {
- // [self reload_data];
- // }
- // else
- // {
- // [RAUtils error_alert:[cart_json valueForKey:@"err_msg"] title:@"Failed to remove model from wishlist."] ;
- // }
- //
- // });
- // });
- // }
- // };
- //
- //
- // ViewController.onSavePDF=^(NSString* name,NSString* file)
- // {
- //
- // NSString* cid= [appDelegate.customerInfo valueForKey:@"customer_cid"];
- // if(cid==nil)
- // cid=@"";
- //
- // NSString *path = NSTemporaryDirectory();
- // NSString *temp_path = [path stringByAppendingPathComponent:file];
- //
- // [iSalesDB save_pdf:temp_path filename:file];
- // NSString* str_sendto=[send_to componentsJoinedByString:@";"];
- // NSString *sql = [NSString stringWithFormat:
- // @"INSERT INTO pdf_cache (name,file_name,c_id,c_name,o_id,pdf_type,send_to) VALUES ('%@', '%@', '%@', '%@', '%@', '%@', '%@')",
- // name, file,cid, company, @"", @"Tear Sheet",str_sendto];
- //
- // [iSalesDB execSql:sql];
- //
- // };
- //
- // // ViewController. = self.function_name;
- // // ViewController.behavior =BEHAVIOR_SEARCH;
- //
- // [self.navigationController pushViewController:ViewController animated:YES];
- // [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
- };
-
- //
- // if(checked.count==count)
- // {
- // orderinfoVC.have_tail = true
- // }
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:VC] ;
-
-
-
-
-
- navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- NSLog(@"TearSheetParamViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- [self.btnselect setTitle:@"Select all"];
-
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- 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];
-
- [[UIToolbar appearance] setBackgroundColor:UIColorFromRGB(0xF2EEEA)];
-
- 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];
-
-
-
- // self.toolbar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolbar.bounds].CGPath;
- // self.toolbar.layer.masksToBounds = false;
- //// //添加四个边阴影
- //
- // self.toolbar.layer.shadowColor = [UIColor blackColor].CGColor;
- // self.toolbar.layer.shadowOffset = CGSizeMake(0, 0);
- // self.toolbar.layer.shadowOpacity = 0.5;
- // self.toolbar.layer.shadowRadius = 2.0;
-
- //
- // self.toolbar.layer.borderWidth = 1;
- // self.toolbar.layer.borderColor = [[UIColor blackColor] CGColor];
- //
- // self.toolbar.clipsToBounds = YES;
- // [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"];
- if ([self respondsToSelector:@selector(reload_data)])
- [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<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- [item_json setValue:@"1" forKey:@"check"];
-
- ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
- cell.img_checkmark.hidden=false;
- // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
-
- [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
-
-
- }
-
- [self.btnselect setTitle:@"Deselect all"];
-
-
- }
- else
- {
- int count =[[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
- [item_json setValue:@"0" forKey:@"check"];
-
- ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
- cell.img_checkmark.hidden=true;
- [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
-
- }
-
- [self.btnselect setTitle:@"Select all"];
- // self.btnselect.titleLabel.text=@"Select all";
- }
-
- }
- - (IBAction)onDeleteClick:(id)sender {
- NSMutableArray* checked = [[NSMutableArray alloc] init];
-
-
-
- int count = [[self.content_data valueForKey:@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- int check = [[item_json valueForKey:@"check"] intValue];
- if(check==1)
- {
- [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
-
- }
- }
- // disable for debug
- if(checked.count==0)
- return;
-
- // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
- NSString * string = [checked componentsJoinedByString:@","];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = [iSalesNetwork portfolio_remove:string];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- [self reload_data];
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Portfolio" controller:self] ;
- }
-
- });
- });
-
-
- }
- -(void) viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
-
-
- [[self navigationController] setNavigationBarHidden:YES animated:NO];
- }
- -(void) reload_data
- {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- if(self.isrefreshing)
- return;
- self.isrefreshing=true;
- self.label_net_err.hidden=true;
- self.itemListTable.hidden=true;
- [self.content_data removeAllObjects];
- [self.itemListTable reloadData];
- 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"];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = [iSalesNetwork request_Portfolio];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.mum stopAnimating];
-
- int result=[[cart_json valueForKey:@"result"] intValue];
-
- if(result==2||result==1||result==0)
- {
- self.itemListTable.hidden=false;
- self.content_data = [cart_json mutableCopy];
- [self.itemListTable reloadData];
-
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- appDelegate.port_count =[[self.content_data valueForKey:@"count"] intValue];
- }
- else
- if(result==RESULT_NET_ERROR)
- {
- self.label_net_err.hidden=false;
- self.itemListTable.hidden=true;
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Watchlist" controller:self] ;
- }
-
- self.isrefreshing=false;
-
- });
- });
- });
- }
- - (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 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 = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
- //// titleLabel.textColor=[UIColor whiteColor];
- //// titleLabel.backgroundColor = [UIColor clearColor];
- //// if(section==0)
- //// titleLabel.text=NSLocalizedString(@"display_items", nil);
- //// else
- //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
- //// [titleLabel sizeToFit];
- //// [myView addSubview:titleLabel];
- ////
- // return myView;
- //}
- //
- //- (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"];
- 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];
- // NSLog(@"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"];
-
- DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
- // dvc
-
- dvc.product_id=product_id;
- dvc.category_id=nil;
- dvc.ispush=true;
- [dvc reload];
- [self.navigationController pushViewController:dvc animated:true];
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // 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]];
-
- 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];
- float discount = [[item_json valueForKey:@"tear_sheet_discount"] floatValue];
- float price =[[item_json valueForKey:@"tear_sheet_price"] floatValue];
- // cell.labelAttribute.text = attribute;
- // cell.labelCurrency.text = currency;
- cell.labelDescription.text = description;
- // cell.labelIdentifier.text = identifier;
-
- NSString* str_price =[NSString stringWithFormat:@"%.2f",price * (1.0-discount/100)];
- if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
- {
-
- }
- else
- {
- str_price=nil;
- }
- cell.labelPrice.text = str_price;
- // 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];
- 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];
- // cell.btnImage.imageView.image = img;
- }
- 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
- [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
-
-
- });
- });
-
-
- }
- cell.backgroundColor = UIColorFromRGB(0xF2EEEA);
- 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;
- }
- //- (void)tableView:(UITableView *)tableView
- //commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- //
- //
- // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
- //
- // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
- //
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* cart_json = [iSalesNetwork watchlist_remove:ids];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // if([[cart_json valueForKey:@"result"] intValue]==2)
- // {
- // [self reload_data];
- // }
- // else
- // {
- // [RAUtils error_alert:[cart_json valueForKey:@"err_msg"] title:@"Failed to remove model from wishlist."] ;
- // }
- //
- //
- //
- // });
- // });
- //}
- //#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
- {
-
- // 添加一个删除按钮
-
- self.indexPath=indexPath;
-
- UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
-
- NSLog(@"delete click");
-
-
-
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from portfolio?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
- alert.tag = ALERT_DEL;
- // alert.
- [alert show];
-
-
-
-
-
-
- }];
- deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
-
- // 添加一个编辑按钮
-
- UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" Edit "handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
-
- NSLog(@"edit click");
-
-
-
- UIViewController* parentvc=self;
-
-
-
-
- EditModelPriceViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
-
-
- NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
-
-
-
- vc.set_watch_list=true;
- vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
- vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
- vc.cart_id = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
- // vc.delegate = parentvc.self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
- vc.onSetValue = ^(double price,double discount){
- [self reload_data];//[main_vc checklogin:true];
- };
-
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [parentvc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- NSLog(@"EditModelPriceViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
- [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
-
-
- }];
- editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
-
-
-
-
-
-
-
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- {
- NSMutableArray* arr=[@[] mutableCopy];
-
- [arr addObject:deleteRowAction];
- if(appDelegate.can_set_tearsheet_price)
- {
- [arr addObject:editRowAction];
-
- }
- return arr;
- // return @[deleteRowAction, editRowAction];
- }
- else
- return @[deleteRowAction];
-
-
- }
- - (void)tableView:(UITableView *)tableView
- commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-
-
-
- }
- #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
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // if(alertView.tag==1234)
- // {
- //
- // // availability warring;
- //
- //
- // if(buttonIndex!=alertView.cancelButtonIndex)
- // {
- // if(appDelegate.order_code==nil)
- // {
- // [self neworder];
- // }
- // else
- // {
- // [self addtocart];
- // }
- // }
- // return;
- // }
- // int count=[self.quantity_text.text intValue];
-
-
-
- if(alertView.tag==ALERT_DEL)
- {
- if(buttonIndex!=alertView.cancelButtonIndex)
- {
- [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]];
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* cart_json = [iSalesNetwork portfolio_remove:ids];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[cart_json valueForKey:@"result"] intValue]==2)
- {
- [self reload_data];
- }
- else
- {
- [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
- }
-
- });
- });
-
- }
- return;
- }
-
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(buttonIndex==alertView.cancelButtonIndex)
- {
-
-
-
- }
- else if(buttonIndex==1)
- {
- //open exist
-
- OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- ovc.showNavibar = true;
- ovc.selectOrder = ^(NSMutableDictionary* order_detail){
- if(appDelegate.order_code==nil)
- {
- [self neworder];
- }
- else
- {
- [self addtocart];
- [main_vc checklogin:true];
-
- }
-
- };
- ovc.init_style = OL_OPEN;
- ovc.onCancel = ^(){
-
- [main_vc checklogin:true];
-
- };
-
- [self.navigationController pushViewController:ovc animated:true];
- }
- else
- {
- //create new;
-
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- 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 - 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.
- }
- */
- @end
|