| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- //
- // CustomerInfoViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 9/10/15.
- // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "CustomerInfoViewController.h"
- #import "RANetwork.h"
- #import "CustomerEditViewController.h"
- #import "MainViewController.h"
- #import "JKTimerManager.h"
- @interface CustomerInfoViewController ()
- @end
- @implementation CustomerInfoViewController
- - (void)onEditClick:(id)sender {
-
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
-
- [params setValue:self.contactId forKey:@"contact_id"];
- CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc]initWithNibName:@"CommonEditor.iPad" bundle:nil];
-
- cuseditVC.bnewcustomer=false;
- cuseditVC.url_type = URL_REMOTE;
- cuseditVC.request_url=URL_EDIT_CUSTOMER;
-
- cuseditVC.params = params;
-
- cuseditVC.delegate=self;
-
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
- [self.navigationController pushViewController:cuseditVC animated:false];
-
- }
- - (void)onAssignClick:(id)sender {
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
-
-
-
-
-
- // [self.navigationController popViewControllerAnimated:(false)];
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
-
- for(int i=0;i<section_count;i++)
- {
- NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
- int count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<count;j++)
- {
- NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
-
- //NSObject* obj=[itemjson valueForKey:@"name"];
-
- NSString* name = itemjson[@"name"];//[[ valueForKey:@"name"] stringValue];
- // DebugLog(@"%@",name.class);
- // DebugLog(@"%@",self.data_init.class);
- // DebugLog(@"%@",NSDictionary.class);
- NSString* value = itemjson[@"value"];//[[itemjson valueForKey:@""] stringValue];
-
- //[self.data_init setValue:value forKey:name];
- self.data_init[name]=value;
-
-
-
- }
-
- }
- //---------------- construct customer_contact----------------------
- NSString* customer_first_name = [self.data_init valueForKey:@"customer_first_name"];
- if(customer_first_name==nil)
- customer_first_name=@"";
-
- NSString* customer_last_name= [self.data_init valueForKey:@"customer_last_name"];
- if(customer_last_name==nil)
- customer_last_name=@"";
- NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
- customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- [self.data_init setValue:customer_contact forKey:@"customer_contact"];
- //---------------- finish construct customer_contact----------------------
-
- #ifdef SCANNER_ORDER
- [self.navigationController popViewControllerAnimated:false];
- if(self.returnValue)
- {
- self.returnValue(self.data_init);
-
- }
- return;
- #endif
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(self.update_order && appDelegate.order_code!=nil)
- {
-
- [RANetwork request_update_ordercustomer:appDelegate.order_code customerinfo:self.data_init completionHandler:^(NSMutableDictionary *result) {
-
- NSDictionary* editor_json = result;
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- [self.navigationController popViewControllerAnimated:false];
- if(self.returnValue)
- {
-
- self.returnValue(self.data_init);
- }
-
-
-
- }
- else
- {
-
- [RAUtils message_box:@"Update Order Customer Infomation" message:[editor_json valueForKey:@"err_msg"] completion:nil];
- }
-
-
-
- }];
-
- }
- else
- {
-
- [self.navigationController popViewControllerAnimated:false];
- if(self.returnValue)
- {
- self.returnValue(self.data_init);
-
- }
-
- }
-
-
- }
- - (void)onResetClick:(id)sender {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(appDelegate.order_code.length>0)
- {
- //当前已打开订单则关闭订单。
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order and reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- #ifdef SCANNER_ORDER
- [self.navigationController popViewControllerAnimated:false];
- if(self.returnValue)
- {
- self.returnValue(nil);
-
- }
- return;
- #endif
-
-
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Release Order" completion:nil];
- [RANetwork request_release_order:appDelegate.order_code withScreen:ScreenCodeCustomerInfo completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* order_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = nil;
- [appDelegate closeOrder];
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadContact:false immediately:false];
- #endif
-
- [self.navigationController popToRootViewControllerAnimated:false];
-
-
-
- }
- else
- {
-
- [RAUtils message_box:@"Release Order" message:[order_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
- }];
- // }];
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"Cancel");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
- }
- else
- {
- //询问并清空当前的全局contact_id、customer
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- #ifdef SCANNER_ORDER
- [self.navigationController popViewControllerAnimated:false];
- if(self.returnValue)
- {
- self.returnValue(nil);
-
- }
- return;
- #endif
-
-
- if(appDelegate.user_type!=USER_ROLE_CUSTOMER)
- {
- appDelegate.contact_id=nil;
- appDelegate.customerInfo = nil;
- }
-
- [self.navigationController popViewControllerAnimated:(false)];
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"Cancel");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
- }
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
-
- if(self.rightbtn_title!=nil)
- [ self.right_btn setTitle:self.rightbtn_title];
- // UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
- // // closeButton.title = @"Close";
-
-
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
-
- self.navigationItem.leftBarButtonItem = backButton;
-
-
- NSMutableArray * items = [[NSMutableArray alloc]init];
- self.btn_edit = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onEditClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
-
-
- // self.btn_edit.tintColor = UIColorFromRGB(0x996633);
-
-
-
- self.btn_assign = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"assign"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onAssignClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
-
-
- // self.btn_assign.tintColor = UIColorFromRGB(0x996633);
-
-
- self.btn_reset = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"reset"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onResetClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
-
-
- // self.btn_reset.tintColor = UIColorFromRGB(0x996633);
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(self.edit_icon)
- [items addObject:self.btn_edit];
- if ((appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) && appDelegate.order_code.length > 0 && ![RASingleton sharedInstance].currentOrderIsMerged) {
- // shop order 隐藏assign
- } else {
- if(self.assig_icon)
- [items addObject:self.btn_assign];
- }
- if(self.reset_icon)
- [items addObject:self.btn_reset];
-
- self.navigationItem.rightBarButtonItems=items;
-
-
-
- if (self.data_init==nil) {
-
- [self request_fill];
- }
- else
- {
- [self fillData];
- }
-
-
-
-
- // Do any additional setup after loading the view.
- }
- - (void)onBackClick:(UIButton *)sender {
-
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
-
-
-
- NSMutableDictionary* back_data = [self.data_init mutableCopy];
-
- // [self.navigationController popViewControllerAnimated:(false)];
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
-
- for(int i=0;i<section_count;i++)
- {
- NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
- int count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<count;j++)
- {
- NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
-
- NSString* name = [itemjson valueForKey:@"name"];
-
- NSString* value = [itemjson valueForKey:@"value"];
-
- [back_data setValue:value forKey:name];
-
-
-
- }
-
- }
- //---------------- construct customer_contact----------------------
- NSString* customer_first_name = [back_data valueForKey:@"customer_first_name"];
- if(customer_first_name==nil)
- customer_first_name=@"";
-
- NSString* customer_last_name= [back_data valueForKey:@"customer_last_name"];
- if(customer_last_name==nil)
- customer_last_name=@"";
- NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
- customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- [back_data setValue:customer_contact forKey:@"customer_contact"];
-
-
-
-
- if(self.onClose)
- {
-
- self.onClose(back_data);
- }
-
-
- [self.navigationController popViewControllerAnimated:(false)];
- // [self.navigationController dismissViewControllerAnimated:true completion:^{
- // ;
- // }];
- }
- -(void) request_fill
- {
- // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Loading Contact information" completion:^{
-
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Loading Contact information" completion:nil];
- [RANetwork request_contactinfo:self.contactId completionHandler:^(NSMutableDictionary *result) {
- NSMutableDictionary* editor_json = result;
-
- [pop hide];
- // [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
- self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
-
- [self fillData];
- self.btn_assign.enabled=true;
-
- }
- else
- {
- [RAUtils message_box:@"Loading Contact Information" message:[editor_json valueForKey:@"err_msg"] completion:nil] ;
- self.btn_assign.enabled=false;
- }
- // }];
-
- }];
- return;
- // }];
-
- }
- - (void) fillData
- {
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
-
-
- // NSDictionary* data = [self.data_init objectForKey:@"customerInfo"];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
- int count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
-
- NSString* control=[itemjson valueForKey:@"control"];
-
- NSString* name = [itemjson valueForKey:@"name"];
-
- NSString* value = [self.data_init valueForKey:name];
-
- [itemjson setValue:value forKey:@"value"];
-
- if([control isEqualToString:@"img"])
- {
- {
- NSString* img_url = [itemjson valueForKey:@"img_url_0"];
-
- NSString* url_value = [self.data_init valueForKey:img_url];
- [itemjson setValue:url_value forKey:@"img_url_0"];
- }
- {
- NSString* img_url = [itemjson valueForKey:@"img_url_1"];
-
- NSString* url_value = [self.data_init valueForKey:img_url];
- [itemjson setValue:url_value forKey:@"img_url_1"];
- }
- {
- NSString* img_url = [itemjson valueForKey:@"img_url_2"];
-
- NSString* url_value = [self.data_init valueForKey:img_url];
- [itemjson setValue:url_value forKey:@"img_url_2"];
- }
- }
-
- [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j]];
-
-
- }
- [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i]];
- }
- self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
-
- // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
- [self.editorTable reloadData];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #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 - Urgency
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self start_urgency_timer];
- }
- -(void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self cancel_urgency_timer];
- }
- - (void)dealloc {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
-
- }
- - (void)start_urgency_timer {
-
- if (!self.editable) {
- return;
- }
-
- __weak typeof(self) weakSelf = self;
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
- #ifdef OFFLINE_MODE
- [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
- #endif
- [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
-
- NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
-
- // DebugLog(@"timer start....");
-
- [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
-
- [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
-
-
- [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
- [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
-
- }];
- }
- - (void)cancel_urgency_timer {
- [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
- }
- @end
|