| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430 |
- //
- // RAOrderEditorViewController.m
- // iSales-NPD
- //
- // Created by Jack on 2017/11/7.
- // Copyright © 2017年 United Software Applications, Inc. All rights reserved.
- //
- #import "RAOrderEditorViewController.h"
- #import "AppDelegate.h"
- #import "MainViewController.h"
- #import "AddressEditorViewController.h"
- #import "CreditCardEditorViewController.h"
- #import "JKTimerManager.h"
- #import "RAOrderPreviewController.h"
- #import "CommonEditorCellModel.h"
- //#define CLOSE_ACTION 567
- static const int totalPage = 3;
- @interface RAOrderEditorViewController ()
- @property (nonatomic,assign) BOOL isResume;///<恢复
- @property (nonatomic,assign) NSInteger userType;///<恢复使用
- @property (nonatomic,assign) NSInteger pageIndex;///<当前页码
- /**
- * 保存不同页码上行参数,最新的在最后。
- * 点击下一页时将当前页面上行参数写入数组尾
- * 退回到前一页后删除最后一个元素
- */
- @property (nonatomic,strong) NSMutableArray *pageUpParams;
- @property (nonatomic,strong) NSMutableArray *pageContentDownloadArray;///<保存不同页码content_data_download
- @property (nonatomic,strong) NSMutableArray *pageContentControlArray;///<保存不同页码content_data_control
- @property (nonatomic,strong) NSMutableArray *pageChangeDataArray;///<保存不同页码change_data
- @property (strong, nonatomic) IBOutlet UIToolbar *pageControlToolBar;
- @property (strong, nonatomic) IBOutlet UIBarButtonItem *frontBarItem;
- @property (strong, nonatomic) IBOutlet UIBarButtonItem *nextBarItem;
- @end
- @implementation RAOrderEditorViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.editable = YES;
-
- self.navigationController.navigationBarHidden = NO;
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onCloseClick:)];
-
- self.navigationItem.leftBarButtonItem = closeButton;
-
-
- // UIBarButtonItem *savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- // style:UIBarButtonItemStylePlain
- // target:self
- // action:@selector(onSaveClick:)];
- //
- // self.navigationItem.rightBarButtonItem = savebtn;
-
-
- [self setupPageControlBar];
- }
- -(void) viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- [self start_urgency_timer];
-
- self.isResume = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_resume"] boolValue];
- self.userType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_userType"] integerValue];
-
- if (!self.isResume) {
- // 正常情况
-
- } else {
- // 恢复
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
- }
- self.navigationController.navigationBarHidden=false;
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (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"];
-
- if (self.isResume && self.userType == USER_ROLE_CUSTOMER) {
- [self releaseOrderAfterSave];
- }
-
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.navigationItem.rightBarButtonItem = nil;
- }
- #pragma mark - Lazy Load
- - (NSMutableArray *)pageUpParams {
- if (!_pageUpParams) {
- _pageUpParams = [NSMutableArray array];
- }
- return _pageUpParams;
- }
- - (NSMutableArray *)pageContentDownloadArray {
- if (!_pageContentDownloadArray) {
- _pageContentDownloadArray = [NSMutableArray array];
- }
- return _pageContentDownloadArray;
- }
- - (NSMutableArray *)pageContentControlArray {
- if (!_pageContentControlArray) {
- _pageContentControlArray = [NSMutableArray array];
- }
- return _pageContentControlArray;
- }
- - (NSMutableArray *)pageChangeDataArray {
- if (!_pageChangeDataArray) {
- _pageChangeDataArray = [NSMutableArray array];
- }
- return _pageChangeDataArray;
- }
- #pragma mark - Private
- - (void)onCloseClick:(UIButton *)sender {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if (self.resumeOrder) {
- [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
- return;
- }
-
-
- // UIAlertView * alert = nil;
- NSString* a2title = nil;
- if(appDelegate.order_status==0)
- a2title= @"Close and cancel order";
- else
- a2title=@"Close and release order";
-
-
-
-
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Choose your action" message:@"" preferredStyle:UIAlertControllerStyleAlert];
-
-
- UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-
- [self.navigationController popViewControllerAnimated:true];
-
- }];
-
- UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-
- [self.navigationController popViewControllerAnimated:false];
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //#ifdef RA_NOTIFICATION
- // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- //#endif
- [((MainViewController*)appDelegate.main_vc) switchToOrder];
- }];
- UIAlertAction *action_2 = [UIAlertAction actionWithTitle:a2title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // close order;
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // __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:nil completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* order_json = result;
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- // [waitalert dismissViewControllerAnimated:YES completion:^{
-
- [pop hide];
- if([[order_json valueForKey:@"result"] intValue]==2)
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- [appDelegate closeOrder];
-
-
- //#ifdef RA_NOTIFICATION
- // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- //#endif
- [((MainViewController*)appDelegate.main_vc) switchToHome];
-
- if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
- {
- [((MainViewController*)appDelegate.main_vc) Loginout:false];
- }
-
- [self prepareReturn:nil];
-
-
- [self.navigationController popViewControllerAnimated:true];
-
-
- }
- else
- {
-
- [RAUtils message_box:@"Open Order" message:[order_json valueForKey:@"err_msg"] completion:nil];
- }
- // }];
-
-
-
-
- }];
-
- }];
- UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
-
-
- }];
- [alertController addAction:action_0];
- [alertController addAction:action_1];
- [alertController addAction:action_2];
- [alertController addAction:action_3];
-
-
- [self presentViewController:alertController animated:YES completion:nil];
-
- }
- - (void)setupPageControlBar {
-
- // 1. 控制ToolBar Item显隐
- NSMutableArray *items = [self.pageControlToolBar.items mutableCopy];
- if (self.pageIndex == 0) {
- // 首页不需要前一页
- if ([items containsObject:self.frontBarItem]) {
- [items removeObject:self.frontBarItem];
- }
-
- } else if (self.pageIndex == totalPage - 1) {
- // // 尾页不需要后一页
- // if ([items containsObject:self.nextBarItem]) {
- // [items removeObject:self.nextBarItem];
- // }
-
- // 尾页点击Next进入Preview
- if (![items containsObject:self.nextBarItem]) {
- [items addObject:self.nextBarItem];
- }
-
- } else {
- // 中间显示前一页、后一页按钮
- if (![items containsObject:self.frontBarItem]) {
- [items insertObject:self.frontBarItem atIndex:0];
- }
- if (![items containsObject:self.nextBarItem]) {
- [items addObject:self.nextBarItem];
- }
-
-
- }
- self.pageControlToolBar.items = items;
- }
- - (NSString *)getValue:(NSString *)key from:(NSArray *)control {
- NSString *ret = nil;
- for(int i = 0; i < control.count; i++)
- {
- NSMutableArray* items=(NSMutableArray*)control[i];
- for(int j=0;j<items.count;j++)
- {
- NSDictionary* item=items[j];
- NSString* item_name=[item valueForKey:@"name"];
- if([item_name isEqualToString:key])
- {
- NSString* control = [item valueForKey:@"control"];
-
- if([control isEqualToString:@"enum"])
- {
- NSDictionary* cadedate = [item objectForKey:@"cadedate"];
- int cc = [[cadedate valueForKey:@"count"] intValue];
- for(int l=0;l<cc;l++)
- {
- NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
- if([[val_json valueForKey:@"check"]intValue]==1)
- return [val_json valueForKey:@"value_id"];
- }
-
- }
- else
-
- return [item valueForKey:@"value"];
- }
- }
- }
- return ret;
- }
- #pragma mark - BarItem Action
- - (IBAction)frontBarItemClick:(UIBarButtonItem *)sender {
- if (self.pageIndex == 0) {
- return;
- }
- // 结束编辑防止TextFiled在编辑中时返回,Table会Reload,此时TextFiled会结束编辑,但是Data已经改变。
- [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
-
- self.pageIndex--;
-
- // 1.恢复当前页面数据
- NSMutableDictionary* upparams = [self.pageUpParams lastObject]; // 前页上行参数
- __weak typeof(self) weakSelf = self;
- [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- [weakSelf.params removeObjectForKey:key];
-
- }];
- [self.pageUpParams removeLastObject];
- [self.params setObject:@(self.pageIndex) forKey:@"step"];
-
- self.content_data_control = [self.pageContentControlArray lastObject];
- [self.pageContentControlArray removeLastObject];
-
- self.content_data_download = [self.pageContentDownloadArray lastObject];
- [self.pageContentDownloadArray removeLastObject];
-
- self.changed_data = [self.pageChangeDataArray lastObject];
- [self.pageChangeDataArray removeLastObject];
-
- // 2.刷新页面
- [self.editorTable reloadData];
- self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
-
- [self setupPageControlBar];
- }
- - (IBAction)nextBarItemClick:(UIBarButtonItem *)sender {
- if (self.pageIndex == totalPage) {
- return;
- }
- // 结束编辑防止TextFiled在编辑中时下一页,Table会Reload,此时TextFiled会结束编辑,但是Data已经改变。
- [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
-
- NSMutableDictionary* upparams = [self check_cancommit:true]; // 当前页上行参数
- if(self.cancommit==false)
- return;
- __weak typeof(self) weakSelf = self;
- if (self.pageIndex == totalPage - 1) {
-
- // 在此设置Step 避免返回后index不正确。
- [upparams setObject:@(self.pageIndex + 1) forKey:@"step"];
- // 尾页 进入Preview
- [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- [weakSelf.params setObject:obj forKey:key];
-
- }];
-
- RAOrderPreviewController * orderinfoVC = [[RAOrderPreviewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
-
- orderinfoVC.disable_dropdown_refresh=true;
- orderinfoVC.url_type = URL_REMOTE;
- orderinfoVC.request_url=URL_BACK_ORDER_PREVIEW;
-
- orderinfoVC.params = self.params;
-
- orderinfoVC.delegate=self.delegate;
- [self.navigationController pushViewController:orderinfoVC animated:true];
-
- return;
- }
- self.pageIndex++;
- // 请求页码
- [upparams setObject:@(self.pageIndex) forKey:@"step"];
-
- // 1.保存当前页面数据
- if (upparams == nil) {
- upparams = [NSMutableDictionary dictionary];
- }
- [self.pageUpParams addObject:upparams];
- if (self.content_data_control == nil) {
- self.content_data_control = [NSMutableArray array];
- }
- [self.pageContentControlArray addObject:self.content_data_control];
- if (self.content_data_download == nil) {
- self.content_data_download = [NSMutableDictionary dictionary];
- }
- [self.pageContentDownloadArray addObject:self.content_data_download];
-
- if (self.changed_data == nil) {
- self.changed_data = [NSMutableDictionary dictionary];
- }
- [self.pageChangeDataArray addObject:self.changed_data];
-
- // 2.请求下一页数据
- // 当前页及之前所有页参数均上传
- [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
-
- [weakSelf.params setObject:obj forKey:key];
-
- }];
-
- [self setupPageControlBar];
- self.content_data_download = [NSMutableDictionary dictionary];
-
- [self refresh:nil discardDirty:false];
- }
- #pragma mark - Override
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
-
- NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
- NSString* control = [item_json valueForKey:@"control"];
-
- if([control isEqualToString:@"model"]) {
- ((CommonEditorCellModel *)cell).avalibilityLabel.hidden = YES;
- }
-
- return cell;
-
- }
- - (void)download_success {
-
- NSString *title = [self.content_data_download objectForKey:@"title"];
- self.title = title;
-
- [self setupPageControlBar];
-
- // 用于处理不同child,在成功去的数据后,需要附加的操作。
-
- self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
-
- NSString* order_customerid=[self getValue:@"customer_cid"];
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_customer_id = order_customerid;
-
- }
- - (void)download_failed {
-
- // 恢复为前一页
- [self frontBarItemClick:nil];
-
- }
- -(NSString*) getValue:(NSString*)name
- {
-
- if (self.pageContentControlArray.count) {
- NSString* ret=nil;
- for (NSInteger i = self.pageContentControlArray.count - 1; i >= 0 ; i--) {
- NSArray *control = [self.pageContentControlArray objectAtIndex:i];
- ret = [self getValue:name from:control];
- if (ret != nil) {
- return ret;
- }
- }
- return ret;
- } else {
- return [self getValue:name from:self.content_data_control];
- }
-
-
- }
- #pragma mark - Place Order
- - (void)alertMessage:(NSString *)msg {
- if (notifyMe_switch) {
-
- if ([self.class_name isEqualToString:@"RAOrderEditorViewController"]) {
-
- NSString *err_msg = msg;
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
- __weak typeof(self) weakself = self;
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- [weakself.navigationController popViewControllerAnimated:YES];
-
- }];
- [alertVC addAction:action];
-
- [self presentViewController:alertVC animated:YES completion:nil];
-
- } else {
-
- // [RAUtils message_box:nil message:msg completion:nil] ;
-
- [RAUtils message_box:nil message:msg completion:nil];
- }
-
- } else {
-
- // [RAUtils message_box:nil message:msg completion:nil] ;
- [RAUtils message_box:nil message:msg completion:nil];
- }
- }
- -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if([value isEqualToString:@"new_addr"])
- {
- AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
-
- addressVC.url_type = URL_REMOTE;
-
- addressVC.request_url=URL_ADDRESS_EDOTOR;
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- addressVC.params = params;
-
-
- addressVC.delegate = self;
-
- addressVC.from = indexPath;
- // orderinfoVC.params = params;
-
- [self.navigationController pushViewController:addressVC animated:true];
-
- }else if([value isEqualToString:@"credit_card"])
- {
- CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
-
-
- NSDictionary *data = [item_json objectForKey:@"data"];
-
- if(data!=nil)
- {
-
- cardVC.content_data_download = [data mutableCopy];
- cardVC.url_type = URL_NONE;
-
- cardVC.request_url=nil;
- }
- else
- {
- cardVC.url_type = URL_REMOTE;
-
- cardVC.request_url=URL_CREDITCARD_EDOTOR;
- }
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- params[@"orderCode"]=appDelegate.order_code;
- cardVC.params = params;
-
- cardVC.delegate = self;
-
- cardVC.from = indexPath;
-
-
- [self.navigationController pushViewController:cardVC animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_From"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Customer"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
-
- cvc.contact_type = value;
- cvc.showNavibar = true;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Contact_Return_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
-
- }
- - (UIView *)createDemoView:(NSString*) msg
- {
- UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
-
- // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
- // [imageView setImage:[UIImage imageNamed:@"demo"]];
-
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
- titleLabel.font = [UIFont boldSystemFontOfSize:20];
- titleLabel.text=@"Order Submission";
- titleLabel.numberOfLines = 0;
- titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
- // titleLabel.textAlignment = NSTextAlignmentRight;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
- // CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
- CGSize sizetitle = [RAUtils sizeWithFont:titleLabel.text=@"Order Submission" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- //[titleLabel sizeToFit];
- // titleLabel.center.x = demoView.center.x;
- titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
- [demoView addSubview:titleLabel];
-
- UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
- lineLabel.font = [UIFont systemFontOfSize:17];
- lineLabel.text=msg;
- lineLabel.numberOfLines = 0;
- lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
-
- // CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
-
- lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
- //[lineLabel sizeToFit];
-
- [demoView addSubview:lineLabel];
- demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
- return demoView;
- }
- -(float) getprice:(NSString*) name section :(long) index
- {
- NSMutableDictionary* section_json=nil;
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
- if([[olditem valueForKey:@"name"] isEqualToString:name])
- {
- return [[olditem valueForKey:@"value"] floatValue];
-
- }
-
- }
-
- return 0;
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
- // [super textFieldDidEndEditing:textField];
-
- UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
-
- // table滑动后,cell可能会滚出table visible范围,此时indexPath为nil
- if (indexPath == nil) {
- indexPath = self.lastedit_from;
- }
-
- // 避免提前将lastedit_from置空
- [super textFieldDidEndEditing:textField];
-
- NSMutableDictionary* section_json=nil;
-
-
- // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
-
-
- NSString* name = [item_json valueForKey:@"name"];
-
- if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
- {
- float shipping = [self getprice:@"shipping" section:indexPath.section];
- float order_discount =[self getprice:@"order_discount" section:indexPath.section];
- float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
- float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
- float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
- float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
- float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax-order_discount;
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int count=0;
-
- count=[[section_json valueForKey:@"count"] intValue];
-
- int total_row_idx=-1;
-
- for(int i=0;i<count;i++)
- {
- NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
- if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ] || [[olditem valueForKey:@"name"] isEqualToString:@"totalPrice_a" ])
- {
- [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
- [olditem setValue:@"true" forKey:@"dirty"];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
-
- total_row_idx=i;
-
- }
-
- }
-
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
-
-
- self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
-
-
- if(total_row_idx>=0)
- {
-
-
-
- NSUInteger newIndex[] = {indexPath.section, total_row_idx};
- NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
- // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
- [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
- }
-
- }
- }
- - (void)releaseOrderAfterSave {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
- [appDelegate closeOrder];
- [appDelegate SetSo:nil];
- appDelegate.cart_count=0;
- [appDelegate update_count_mark];
- [((MainViewController*)appDelegate.main_vc) switchToOrder];
-
- [self prepareReturn:nil];
- [self.navigationController popToRootViewControllerAnimated:false];
- });
- }
- -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
- {
- NSString* ret=nil;
- NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
- NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
- NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
- NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
-
- NSMutableArray* arraddr = [[NSMutableArray alloc] init];
- if(customer_address1.length>0)
- [arraddr addObject:customer_address1];
- if(customer_address2.length>0)
- [arraddr addObject:customer_address2];
- if(customer_address3.length>0)
- [arraddr addObject:customer_address3];
- if(customer_address4.length>0)
- [arraddr addObject:customer_address4];
- NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
-
-
- NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
- NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
- NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
- NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
-
- NSMutableArray* arrcty = [[NSMutableArray alloc] init];
- if(customer_city.length>0)
- [arrcty addObject:customer_city];
- if(customer_state.length>0)
- [arrcty addObject:customer_state];
- if(customer_zipcode.length>0)
- [arrcty addObject:customer_zipcode];
- if(customer_country.length>0)
- [arrcty addObject:customer_country];
- NSString *cty_string = [arrcty componentsJoinedByString:@", "];
-
-
- NSMutableArray* arrext = [[NSMutableArray alloc] init];
- if(addr_string.length>0)
- [arrext addObject:addr_string];
- if(cty_string.length>0)
- [arrext addObject:cty_string];
-
- ret = [arrext componentsJoinedByString:@"\r\n"];
-
-
- return ret;
- }
- -(NSMutableDictionary*)create_cusromer_info_from_table
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
-
- [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
- [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
- [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
- [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
- [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
- [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
- [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
- [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
- [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
- [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
- [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
- [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
- [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
- [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
- [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
-
- NSString * firstname =nil;
-
- NSString* lastname = nil;
- NSString* contact_name = [self getValue:@"customer_contact"];
- if(contact_name!=nil)
- {
- NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
-
-
-
- if(_arr.count>=1)
- {
- firstname =_arr[0];
- if(_arr.count>1)
- {
-
- lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
- }
- }
- }
- [ret setValue:firstname forKey:@"customer_first_name"];
- [ret setValue:lastname forKey:@"customer_last_name"];
-
- // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
-
- return ret;
- }
- -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
- {
- NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
- NSArray *keys= [key_map allKeys];
- //遍历keys
- for(int i=0;i<[keys count];i++)
- {
- //得到当前key
- NSString *key=[keys objectAtIndex:i];
- //如果key不是pic,说明value是字符类型,比如name:Boris
- NSString* valuefrom = [key_map valueForKey:key];
-
- if(valuefrom.length==0)
- continue;
- NSString* value=[self getValue:valuefrom];
-
- [ret setValue:value forKey:valuefrom];
- }
- NSDictionary * customerinfo =[self create_cusromer_info_from_table];
- [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
- [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
- [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
- return ret;
- }
- #pragma mark - multi_action sub action clicked
- - (void)MActionClicked:(UIButton *)sender {
-
- UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
- NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
- int refresh =0;
- NSMutableDictionary* section_json=nil;
-
- NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
- NSString* subid=[item_json valueForKey:@"subid"];
- NSString* refresh_trigger = [item_json valueForKey:@"name"];
- NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
- NSString* type = [sub_action valueForKey:@"type"];
- bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
- if([type isEqualToString:@"pull"])
- {
-
- [self.lastedit endEditing:true];
-
- refresh = [[sub_action valueForKey:@"refresh"] intValue];
- NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
-
- NSMutableDictionary* value=[self create_value_map:keymap];
-
- if(subid==nil)
- {
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
- int icount=[[section_json valueForKey:@"count"] intValue];
- for (int ic=0;ic<icount;ic++)
- {
- NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
-
-
- NSString* mapto = [modify_item valueForKey:@"name"];
- if(mapto.length==0)
- continue;
- NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
- if(valuefrom==nil)
- continue;
- NSString* valuestr=[value valueForKey:valuefrom];
-
-
-
-
-
- // valuestr = [self getValue:valuefrom];
- if(true)
- {
- if(valuestr.length>0)
- [modify_item setValue:valuestr forKey:@"value"];
- else
- [modify_item setValue:@"" forKey:@"value"];
- [modify_item setValue:@"true" forKey:@"dirty"];
- [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
- }
- }
- }
- else
- {
-
- NSArray* idarr=[subid componentsSeparatedByString:@"_"];
- int section = [(NSString*)idarr[0] intValue];
- int item=[(NSString*)idarr[1] intValue];
- NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
-
- section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
- NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
-
- NSString* control_type = [olditem valueForKey:@"control"];
- if([control_type isEqualToString:@"switch"])
- olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
- else if([control_type isEqualToString:@"enum"])
- {
- olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
-
- }
- else
- {
- [RAUtils message_box:@"Sorry" message:@"not impl" completion:nil];
- // [RAUtils alert_view:@"" title:@"not impl"];
- }
-
- [olditem setValue:@"true" forKey:@"dirty"];
- [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
-
- }
- [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
-
-
- if(refresh==1)
- {
-
- [self refresh:refresh_trigger discardDirty:discardDirty];
- return ;
- }
-
- // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- [self.editorTable reloadData ];
-
-
- }
- else
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSDictionary * item_json = sub_action;
- NSString* value = [item_json valueForKey:@"value"];
- if([value isEqualToString:@"new_addr"])
- {
- AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
-
- addressVC.url_type = URL_REMOTE;
-
- addressVC.request_url=URL_ADDRESS_EDOTOR;
-
-
-
-
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
- // NSString * string = [checked componentsJoinedByString:@","];
- // [params setValue:string forKey:@"cart2Checkbox"];
-
-
- params[@"is_subaction"]=@"true";
- params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
- addressVC.params = params;
-
-
- addressVC.delegate = self;
-
- addressVC.from = indexPath;
- // orderinfoVC.params = params;
-
- [self.navigationController pushViewController:addressVC animated:true];
-
- }else if([value isEqualToString:@"credit_card"])
- {
- CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
-
-
- NSDictionary *data = [item_json objectForKey:@"data"];
-
- if(data!=nil)
- {
-
- cardVC.content_data_download = [data mutableCopy];
- cardVC.url_type = URL_NONE;
-
- cardVC.request_url=nil;
- }
- else
- {
- cardVC.url_type = URL_REMOTE;
-
- cardVC.request_url=URL_CREDITCARD_EDOTOR;
- }
- NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-
- params[@"orderCode"]=appDelegate.order_code;
-
- params[@"is_subaction"]=@"true";
- params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
- cardVC.params = params;
-
- cardVC.delegate = self;
-
- cardVC.from = indexPath;
-
-
- // orderinfoVC.params = params;
-
- [self.navigationController pushViewController:cardVC animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
-
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_From"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
-
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Customer"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Contact_Return_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
- else if([value isEqualToString:@"Sales_Order_Ship_To"])
- {
-
-
- ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.is_subaction = @"true";
- cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
- cvc.showNavibar = true;
- cvc.contact_type = value;
- __weak typeof(self) weakself = self;
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
-
-
- [self.navigationController pushViewController:cvc animated:true];
-
- }
-
-
- }
- }
- #pragma mark - Urgency
- -(void) viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self cancel_urgency_timer];
- }
- - (void)start_urgency_timer {
-
- if (!self.editable) {
- return;
- }
-
- __weak typeof(self) weakSelf = self;
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
- __block NSString* labelsotext= mainVC.labelSo.text;
- [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"];
-
-
-
- if ([weakSelf.class_name isEqualToString:@"RAOrderEditorViewController"]) {
-
-
- [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
- NSString *so = [labelsotext substringFromIndex:5];
- [urgencyDic setValue:so forKey:@"order_so"];
- [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
-
- [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
-
- // page
- [urgencyDic setObject:@(weakSelf.pageIndex) forKey:@"page_index"];
- [urgencyDic setObject:weakSelf.pageContentDownloadArray forKey:@"download_content_array"];
- [urgencyDic setObject:weakSelf.pageContentControlArray forKey:@"control_content_array"];
- [urgencyDic setObject:weakSelf.pageChangeDataArray forKey:@"changed_data_array"];
- [urgencyDic setObject:weakSelf.pageUpParams forKey:@"up_param_array"];
- [urgencyDic setObject:weakSelf.request_url forKey:@"request_url"];
- [urgencyDic setObject:weakSelf.params forKey:@"params"];
- }
-
- [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];
- }
- - (void)recoveryFromUrgencyDic:(NSDictionary *)urgencyDic {
-
-
- self.disable_dropdown_refresh=true;
- self.url_type = URL_RESTORE;
- self.params = [NSMutableDictionary dictionary];
- self.content_data_download = [urgencyDic objectForKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
- self.resumeOrder = YES;
-
- self.pageIndex = [[urgencyDic objectForKey:@"page_index"] integerValue];
- self.pageContentDownloadArray = [urgencyDic objectForKey:@"download_content_array"];
- self.pageContentControlArray = [urgencyDic objectForKey:@"control_content_array"];
- self.pageChangeDataArray = [urgencyDic objectForKey:@"changed_data_array"];
- self.pageUpParams = [urgencyDic objectForKey:@"up_param_array"];
- self.request_url = [urgencyDic objectForKey:@"request_url"];
- self.params = [urgencyDic objectForKey:@"params"];
- }
- @end
|