RAOrderEditorViewController.m 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. //
  2. // RAOrderEditorViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Jack on 2017/11/7.
  6. // Copyright © 2017年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RAOrderEditorViewController.h"
  9. #import "AppDelegate.h"
  10. #import "MainViewController.h"
  11. #import "AddressEditorViewController.h"
  12. #import "CreditCardEditorViewController.h"
  13. #import "JKTimerManager.h"
  14. #import "RAOrderPreviewController.h"
  15. #define CLOSE_ACTION 567
  16. static const int totalPage = 3;
  17. @interface RAOrderEditorViewController ()
  18. @property (nonatomic,assign) BOOL isResume;///<恢复
  19. @property (nonatomic,assign) NSInteger userType;///<恢复使用
  20. @property (nonatomic,assign) NSInteger pageIndex;///<当前页码
  21. /**
  22. * 保存不同页码上行参数,最新的在最后。
  23. * 点击下一页时将当前页面上行参数写入数组尾
  24. * 退回到前一页后删除最后一个元素
  25. */
  26. @property (nonatomic,strong) NSMutableArray *pageUpParams;
  27. @property (nonatomic,strong) NSMutableArray *pageContentDownloadArray;///<保存不同页码content_data_download
  28. @property (nonatomic,strong) NSMutableArray *pageContentControlArray;///<保存不同页码content_data_control
  29. @property (nonatomic,strong) NSMutableArray *pageChangeDataArray;///<保存不同页码change_data
  30. @property (strong, nonatomic) IBOutlet UIToolbar *pageControlToolBar;
  31. @property (strong, nonatomic) IBOutlet UIBarButtonItem *frontBarItem;
  32. @property (strong, nonatomic) IBOutlet UIBarButtonItem *nextBarItem;
  33. @end
  34. @implementation RAOrderEditorViewController
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. // Do any additional setup after loading the view.
  38. self.editable = YES;
  39. self.navigationController.navigationBarHidden = NO;
  40. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  41. style:UIBarButtonItemStylePlain
  42. target:self
  43. action:@selector(onCloseClick:)];
  44. self.navigationItem.leftBarButtonItem = closeButton;
  45. // UIBarButtonItem *savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  46. // style:UIBarButtonItemStylePlain
  47. // target:self
  48. // action:@selector(onSaveClick:)];
  49. //
  50. // self.navigationItem.rightBarButtonItem = savebtn;
  51. [self setupPageControlBar];
  52. }
  53. -(void) viewWillAppear:(BOOL)animated
  54. {
  55. [super viewWillAppear:animated];
  56. [self start_urgency_timer];
  57. self.isResume = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_resume"] boolValue];
  58. self.userType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_userType"] integerValue];
  59. if (!self.isResume) {
  60. // 正常情况
  61. } else {
  62. // 恢复
  63. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
  64. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
  65. }
  66. self.navigationController.navigationBarHidden=false;
  67. }
  68. - (void)didReceiveMemoryWarning {
  69. [super didReceiveMemoryWarning];
  70. // Dispose of any resources that can be recreated.
  71. }
  72. - (void)dealloc {
  73. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  74. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  75. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  76. if (self.isResume && self.userType == USER_ROLE_CUSTOMER) {
  77. [self releaseOrderAfterSave];
  78. }
  79. }
  80. - (void)awakeFromNib {
  81. [super awakeFromNib];
  82. self.navigationItem.rightBarButtonItem = nil;
  83. }
  84. #pragma mark - Lazy Load
  85. - (NSMutableArray *)pageUpParams {
  86. if (!_pageUpParams) {
  87. _pageUpParams = [NSMutableArray array];
  88. }
  89. return _pageUpParams;
  90. }
  91. - (NSMutableArray *)pageContentDownloadArray {
  92. if (!_pageContentDownloadArray) {
  93. _pageContentDownloadArray = [NSMutableArray array];
  94. }
  95. return _pageContentDownloadArray;
  96. }
  97. - (NSMutableArray *)pageContentControlArray {
  98. if (!_pageContentControlArray) {
  99. _pageContentControlArray = [NSMutableArray array];
  100. }
  101. return _pageContentControlArray;
  102. }
  103. - (NSMutableArray *)pageChangeDataArray {
  104. if (!_pageChangeDataArray) {
  105. _pageChangeDataArray = [NSMutableArray array];
  106. }
  107. return _pageChangeDataArray;
  108. }
  109. #pragma mark - Private
  110. - (void)onCloseClick:(UIButton *)sender {
  111. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  112. if (self.resumeOrder) {
  113. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  114. return;
  115. }
  116. UIAlertView * alert = nil;
  117. if(appDelegate.order_status==0)
  118. {
  119. alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and cancel order", nil), nil];
  120. }
  121. else
  122. {
  123. alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
  124. }
  125. alert.tag = CLOSE_ACTION;
  126. [alert show];
  127. }
  128. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  129. if(alertView.tag == CLOSE_ACTION)
  130. {
  131. if(buttonIndex==1)
  132. {
  133. [self.navigationController popViewControllerAnimated:true];
  134. }
  135. if(buttonIndex==2)
  136. {
  137. [self.navigationController popViewControllerAnimated:false];
  138. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  139. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  140. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  141. }
  142. else if(buttonIndex==3)
  143. {
  144. // close order;
  145. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  146. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  147. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  148. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  149. dispatch_async(dispatch_get_main_queue(), ^{
  150. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  151. if([[order_json valueForKey:@"result"] intValue]==2)
  152. {
  153. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  154. [appDelegate closeOrder];
  155. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  156. [((MainViewController*)appDelegate.main_vc) switchToHome];
  157. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  158. {
  159. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  160. }
  161. [self prepareReturn:nil];
  162. [self.navigationController popViewControllerAnimated:true];
  163. }
  164. else
  165. {
  166. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  167. }
  168. });
  169. });
  170. }
  171. }
  172. }
  173. - (void)setupPageControlBar {
  174. // 1. 控制ToolBar Item显隐
  175. NSMutableArray *items = [self.pageControlToolBar.items mutableCopy];
  176. if (self.pageIndex == 0) {
  177. // 首页不需要前一页
  178. if ([items containsObject:self.frontBarItem]) {
  179. [items removeObject:self.frontBarItem];
  180. }
  181. } else if (self.pageIndex == totalPage - 1) {
  182. // // 尾页不需要后一页
  183. // if ([items containsObject:self.nextBarItem]) {
  184. // [items removeObject:self.nextBarItem];
  185. // }
  186. // 尾页点击Next进入Preview
  187. if (![items containsObject:self.nextBarItem]) {
  188. [items addObject:self.nextBarItem];
  189. }
  190. } else {
  191. // 中间显示前一页、后一页按钮
  192. if (![items containsObject:self.frontBarItem]) {
  193. [items insertObject:self.frontBarItem atIndex:0];
  194. }
  195. if (![items containsObject:self.nextBarItem]) {
  196. [items addObject:self.nextBarItem];
  197. }
  198. }
  199. self.pageControlToolBar.items = items;
  200. }
  201. #pragma mark - BarItem Action
  202. - (IBAction)frontBarItemClick:(UIBarButtonItem *)sender {
  203. self.pageIndex--;
  204. // 1.恢复当前页面数据
  205. NSMutableDictionary* upparams = [self.pageUpParams lastObject]; // 前页上行参数
  206. __weak typeof(self) weakSelf = self;
  207. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  208. [weakSelf.params removeObjectForKey:key];
  209. }];
  210. [self.pageUpParams removeLastObject];
  211. [self.params setObject:@(self.pageIndex) forKey:@"step"];
  212. self.content_data_control = [self.pageContentControlArray lastObject];
  213. [self.pageContentControlArray removeLastObject];
  214. self.content_data_download = [self.pageContentDownloadArray lastObject];
  215. [self.pageContentDownloadArray removeLastObject];
  216. self.changed_data = [self.pageChangeDataArray lastObject];
  217. [self.pageChangeDataArray removeLastObject];
  218. // 2.刷新页面
  219. [self.editorTable reloadData];
  220. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  221. [self setupPageControlBar];
  222. }
  223. - (IBAction)nextBarItemClick:(UIBarButtonItem *)sender {
  224. NSMutableDictionary* upparams = [self check_cancommit:false]; // 当前页上行参数
  225. if(self.cancommit==false)
  226. return;
  227. __weak typeof(self) weakSelf = self;
  228. if (self.pageIndex == totalPage - 1) {
  229. // 在此设置Step 避免返回后index不正确。
  230. [upparams setObject:@(self.pageIndex + 1) forKey:@"step"];
  231. // 尾页 进入Preview
  232. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  233. [weakSelf.params setObject:obj forKey:key];
  234. }];
  235. RAOrderPreviewController * orderinfoVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"RAOrderPreviewController"];
  236. orderinfoVC.disable_dropdown_refresh=true;
  237. orderinfoVC.url_type = URL_REMOTE;
  238. orderinfoVC.request_url=URL_BACK_ORDER_PREVIEW;
  239. orderinfoVC.params = self.params;
  240. orderinfoVC.delegate=self.delegate;
  241. [self.navigationController pushViewController:orderinfoVC animated:true];
  242. return;
  243. }
  244. self.pageIndex++;
  245. // 请求页码
  246. [upparams setObject:@(self.pageIndex) forKey:@"step"];
  247. // 1.保存当前页面数据
  248. if (upparams == nil) {
  249. upparams = [NSMutableDictionary dictionary];
  250. }
  251. [self.pageUpParams addObject:upparams];
  252. if (self.content_data_control == nil) {
  253. self.content_data_control = [NSMutableArray array];
  254. }
  255. [self.pageContentControlArray addObject:self.content_data_control];
  256. if (self.content_data_download == nil) {
  257. self.content_data_download = [NSMutableDictionary dictionary];
  258. }
  259. [self.pageContentDownloadArray addObject:self.content_data_download];
  260. if (self.changed_data == nil) {
  261. self.changed_data = [NSMutableDictionary dictionary];
  262. }
  263. [self.pageChangeDataArray addObject:self.changed_data];
  264. // 2.请求下一页数据
  265. // 当前页及之前所有页参数均上传
  266. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  267. [weakSelf.params setObject:obj forKey:key];
  268. }];
  269. [self setupPageControlBar];
  270. self.content_data_download = [NSMutableDictionary dictionary];
  271. [self refresh:nil];
  272. }
  273. #pragma mark - Override
  274. - (void)download_success {
  275. NSString *title = [self.content_data_download objectForKey:@"title"];
  276. self.title = title;
  277. [self setupPageControlBar];
  278. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  279. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  280. NSString* order_customerid=[self getValue:@"customer_cid"];
  281. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  282. appDelegate.order_customer_id = order_customerid;
  283. }
  284. #pragma mark - Place Order
  285. - (void)alertMessage:(NSString *)msg {
  286. if (notifyMe_switch) {
  287. if ([self.class_name isEqualToString:@"RAOrderEditorViewController"]) {
  288. NSString *err_msg = msg;
  289. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
  290. __weak typeof(self) weakself = self;
  291. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  292. [weakself.navigationController popViewControllerAnimated:YES];
  293. }];
  294. [alertVC addAction:action];
  295. [self presentViewController:alertVC animated:YES completion:nil];
  296. } else {
  297. [RAUtils message_alert:msg title:nil controller:self] ;
  298. }
  299. } else {
  300. [RAUtils message_alert:msg title:nil controller:self] ;
  301. }
  302. }
  303. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  304. {
  305. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  306. if([value isEqualToString:@"new_addr"])
  307. {
  308. AddressEditorViewController * addressVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
  309. addressVC.url_type = URL_REMOTE;
  310. addressVC.request_url=URL_ADDRESS_EDOTOR;
  311. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  312. addressVC.params = params;
  313. addressVC.delegate = self;
  314. addressVC.from = indexPath;
  315. // orderinfoVC.params = params;
  316. [self.navigationController pushViewController:addressVC animated:true];
  317. }else if([value isEqualToString:@"credit_card"])
  318. {
  319. CreditCardEditorViewController * cardVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
  320. NSDictionary *data = [item_json objectForKey:@"data"];
  321. if(data!=nil)
  322. {
  323. cardVC.content_data_download = [data mutableCopy];
  324. cardVC.url_type = URL_NONE;
  325. cardVC.request_url=nil;
  326. }
  327. else
  328. {
  329. cardVC.url_type = URL_REMOTE;
  330. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  331. }
  332. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  333. params[@"orderCode"]=appDelegate.order_code;
  334. cardVC.params = params;
  335. cardVC.delegate = self;
  336. cardVC.from = indexPath;
  337. [self.navigationController pushViewController:cardVC animated:true];
  338. }
  339. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  340. {
  341. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  342. cvc.showNavibar = true;
  343. cvc.contact_type = value;
  344. __weak typeof(self) weakself = self;
  345. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  346. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  347. };
  348. [self.navigationController pushViewController:cvc animated:true];
  349. }
  350. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  351. {
  352. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  353. cvc.showNavibar = true;
  354. cvc.contact_type = value;
  355. __weak typeof(self) weakself = self;
  356. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  357. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  358. };
  359. [self.navigationController pushViewController:cvc animated:true];
  360. }
  361. else if([value isEqualToString:@"Sales_Order_Customer"])
  362. {
  363. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  364. cvc.contact_type = value;
  365. cvc.showNavibar = true;
  366. __weak typeof(self) weakself = self;
  367. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  368. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  369. };
  370. [self.navigationController pushViewController:cvc animated:true];
  371. }
  372. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  373. {
  374. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  375. cvc.showNavibar = true;
  376. cvc.contact_type = value;
  377. __weak typeof(self) weakself = self;
  378. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  379. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  380. };
  381. [self.navigationController pushViewController:cvc animated:true];
  382. }
  383. else if([value isEqualToString:@"Contact_Return_To"])
  384. {
  385. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  386. cvc.showNavibar = true;
  387. cvc.contact_type = value;
  388. __weak typeof(self) weakself = self;
  389. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  390. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  391. };
  392. [self.navigationController pushViewController:cvc animated:true];
  393. }
  394. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  395. {
  396. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  397. cvc.showNavibar = true;
  398. cvc.contact_type = value;
  399. __weak typeof(self) weakself = self;
  400. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  401. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  402. };
  403. [self.navigationController pushViewController:cvc animated:true];
  404. }
  405. }
  406. - (UIView *)createDemoView:(NSString*) msg
  407. {
  408. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  409. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  410. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  411. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  412. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  413. titleLabel.text=@"Order Submission";
  414. titleLabel.numberOfLines = 0;
  415. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  416. // titleLabel.textAlignment = NSTextAlignmentRight;
  417. titleLabel.textAlignment = NSTextAlignmentCenter;
  418. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  419. CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  420. //[titleLabel sizeToFit];
  421. // titleLabel.center.x = demoView.center.x;
  422. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  423. [demoView addSubview:titleLabel];
  424. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  425. lineLabel.font = [UIFont systemFontOfSize:17];
  426. lineLabel.text=msg;
  427. lineLabel.numberOfLines = 0;
  428. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  429. CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  430. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  431. //[lineLabel sizeToFit];
  432. [demoView addSubview:lineLabel];
  433. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  434. return demoView;
  435. }
  436. -(float) getprice:(NSString*) name section :(long) index
  437. {
  438. NSMutableDictionary* section_json=nil;
  439. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  440. int count=0;
  441. count=[[section_json valueForKey:@"count"] intValue];
  442. for(int i=0;i<count;i++)
  443. {
  444. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  445. if([[olditem valueForKey:@"name"] isEqualToString:name])
  446. {
  447. return [[olditem valueForKey:@"value"] floatValue];
  448. }
  449. }
  450. return 0;
  451. }
  452. - (void)textFieldDidEndEditing:(UITextField *)textField
  453. {
  454. [super textFieldDidEndEditing:textField];
  455. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  456. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  457. NSMutableDictionary* section_json=nil;
  458. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  459. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  460. NSString* name = [item_json valueForKey:@"name"];
  461. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  462. {
  463. float shipping = [self getprice:@"shipping" section:indexPath.section];
  464. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  465. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  466. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  467. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  468. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  469. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  470. int count=0;
  471. count=[[section_json valueForKey:@"count"] intValue];
  472. int total_row_idx=-1;
  473. for(int i=0;i<count;i++)
  474. {
  475. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  476. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  477. {
  478. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  479. [olditem setValue:@"true" forKey:@"dirty"];
  480. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  481. total_row_idx=i;
  482. }
  483. }
  484. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  485. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  486. if(total_row_idx>=0)
  487. {
  488. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  489. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  490. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  491. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  492. }
  493. }
  494. }
  495. - (IBAction)onSaveClick:(id)sender {
  496. id a = nil;
  497. NSMutableArray *arr = [NSMutableArray array];
  498. [arr addObject:a];
  499. [self.lastedit endEditing:true];
  500. [self.lasttextview endEditing:true];
  501. NSMutableDictionary* upparams = [self check_cancommit:false];
  502. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  503. upparams[@"shipping"] = nil;
  504. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving Order"];
  505. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  506. NSDictionary* editor_json = [RANetwork save_Order:upparams];
  507. dispatch_async(dispatch_get_main_queue(), ^{
  508. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  509. if([[editor_json valueForKey:@"result"] intValue]==2)
  510. {
  511. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  512. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  513. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  514. {
  515. appDelegate.customerInfo = customerInfo;
  516. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  517. }
  518. NSString *msg = nil;
  519. if ([editor_json objectForKey:@"so#"]) {
  520. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  521. }
  522. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  523. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  524. {
  525. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  526. [self prepareReturn:nil];
  527. [self.navigationController popViewControllerAnimated:true];
  528. }
  529. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  530. if (![Singleton sharedInstance].currentOrderIsMerged) {
  531. [self releaseOrderAfterSave];
  532. }
  533. }
  534. }
  535. else
  536. {
  537. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  538. }
  539. });
  540. });
  541. }
  542. - (void)releaseOrderAfterSave {
  543. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  544. [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  545. [appDelegate closeOrder];
  546. [appDelegate SetSo:nil];
  547. appDelegate.cart_count=0;
  548. [appDelegate update_count_mark];
  549. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  550. [self prepareReturn:nil];
  551. [self.navigationController popToRootViewControllerAnimated:false];
  552. }
  553. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  554. {
  555. NSString* ret=nil;
  556. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  557. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  558. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  559. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  560. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  561. if(customer_address1.length>0)
  562. [arraddr addObject:customer_address1];
  563. if(customer_address2.length>0)
  564. [arraddr addObject:customer_address2];
  565. if(customer_address3.length>0)
  566. [arraddr addObject:customer_address3];
  567. if(customer_address4.length>0)
  568. [arraddr addObject:customer_address4];
  569. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  570. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  571. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  572. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  573. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  574. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  575. if(customer_city.length>0)
  576. [arrcty addObject:customer_city];
  577. if(customer_state.length>0)
  578. [arrcty addObject:customer_state];
  579. if(customer_zipcode.length>0)
  580. [arrcty addObject:customer_zipcode];
  581. if(customer_country.length>0)
  582. [arrcty addObject:customer_country];
  583. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  584. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  585. if(addr_string.length>0)
  586. [arrext addObject:addr_string];
  587. if(cty_string.length>0)
  588. [arrext addObject:cty_string];
  589. ret = [arrext componentsJoinedByString:@"\r\n"];
  590. return ret;
  591. }
  592. -(NSMutableDictionary*)create_cusromer_info_from_table
  593. {
  594. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  595. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  596. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  597. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  598. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  599. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  600. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  601. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  602. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  603. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  604. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  605. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  606. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  607. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  608. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  609. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  610. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  611. NSString * firstname =nil;
  612. NSString* lastname = nil;
  613. NSString* contact_name = [self getValue:@"customer_contact"];
  614. if(contact_name!=nil)
  615. {
  616. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  617. if(_arr.count>=1)
  618. {
  619. firstname =_arr[0];
  620. if(_arr.count>1)
  621. {
  622. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  623. }
  624. }
  625. }
  626. [ret setValue:firstname forKey:@"customer_first_name"];
  627. [ret setValue:lastname forKey:@"customer_last_name"];
  628. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  629. return ret;
  630. }
  631. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  632. {
  633. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  634. NSArray *keys= [key_map allKeys];
  635. //遍历keys
  636. for(int i=0;i<[keys count];i++)
  637. {
  638. //得到当前key
  639. NSString *key=[keys objectAtIndex:i];
  640. //如果key不是pic,说明value是字符类型,比如name:Boris
  641. NSString* valuefrom = [key_map valueForKey:key];
  642. if(valuefrom.length==0)
  643. continue;
  644. NSString* value=[self getValue:valuefrom];
  645. [ret setValue:value forKey:valuefrom];
  646. }
  647. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  648. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  649. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  650. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  651. return ret;
  652. }
  653. #pragma mark - multi_action sub action clicked
  654. - (void)MActionClicked:(UIButton *)sender {
  655. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  656. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  657. int refresh =0;
  658. NSMutableDictionary* section_json=nil;
  659. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  660. NSString* subid=[item_json valueForKey:@"subid"];
  661. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  662. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  663. NSString* type = [sub_action valueForKey:@"type"];
  664. if([type isEqualToString:@"pull"])
  665. {
  666. [self.lastedit endEditing:true];
  667. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  668. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  669. NSMutableDictionary* value=[self create_value_map:keymap];
  670. if(subid==nil)
  671. {
  672. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  673. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  674. int icount=[[section_json valueForKey:@"count"] intValue];
  675. for (int ic=0;ic<icount;ic++)
  676. {
  677. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  678. NSString* mapto = [modify_item valueForKey:@"name"];
  679. if(mapto.length==0)
  680. continue;
  681. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  682. if(valuefrom==nil)
  683. continue;
  684. NSString* valuestr=[value valueForKey:valuefrom];
  685. // valuestr = [self getValue:valuefrom];
  686. if(true)
  687. {
  688. if(valuestr.length>0)
  689. [modify_item setValue:valuestr forKey:@"value"];
  690. else
  691. [modify_item setValue:@"" forKey:@"value"];
  692. [modify_item setValue:@"true" forKey:@"dirty"];
  693. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  694. }
  695. }
  696. }
  697. else
  698. {
  699. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  700. int section = [(NSString*)idarr[0] intValue];
  701. int item=[(NSString*)idarr[1] intValue];
  702. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  703. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  704. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  705. NSString* control_type = [olditem valueForKey:@"control"];
  706. if([control_type isEqualToString:@"switch"])
  707. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  708. else if([control_type isEqualToString:@"enum"])
  709. {
  710. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  711. }
  712. else
  713. {
  714. [RAUtils alert_view:@"" title:@"not impl"];
  715. }
  716. [olditem setValue:@"true" forKey:@"dirty"];
  717. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  718. }
  719. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  720. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  721. if(refresh==1)
  722. {
  723. // if(restore_json!=nil)
  724. // {
  725. // int rc=[[restore_json valueForKey:@"count"] intValue];
  726. // for(int ir=0;ir<rc;ir++)
  727. // {
  728. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  729. //
  730. //
  731. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  732. // for(int i=0;i<section_count;i++)
  733. // {
  734. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  735. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  736. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  737. // for(int j=0;j<item_count;j++)
  738. // {
  739. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  740. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  741. //
  742. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  743. // {
  744. // [itemjson removeObjectForKey:@"dirty"];
  745. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  746. // }
  747. //
  748. // }
  749. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  750. // }
  751. //
  752. //
  753. // }
  754. //
  755. // }
  756. [self refresh:refresh_trigger] ;
  757. return ;
  758. }
  759. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  760. [self.editorTable reloadData ];
  761. }
  762. else
  763. {
  764. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  765. NSDictionary * item_json = sub_action;
  766. NSString* value = [item_json valueForKey:@"value"];
  767. if([value isEqualToString:@"new_addr"])
  768. {
  769. AddressEditorViewController * addressVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
  770. addressVC.url_type = URL_REMOTE;
  771. addressVC.request_url=URL_ADDRESS_EDOTOR;
  772. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  773. // NSString * string = [checked componentsJoinedByString:@","];
  774. // [params setValue:string forKey:@"cart2Checkbox"];
  775. params[@"is_subaction"]=@"true";
  776. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  777. addressVC.params = params;
  778. addressVC.delegate = self;
  779. addressVC.from = indexPath;
  780. // orderinfoVC.params = params;
  781. [self.navigationController pushViewController:addressVC animated:true];
  782. }else if([value isEqualToString:@"credit_card"])
  783. {
  784. CreditCardEditorViewController * cardVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CreditCardEditorViewController"];
  785. NSDictionary *data = [item_json objectForKey:@"data"];
  786. if(data!=nil)
  787. {
  788. cardVC.content_data_download = [data mutableCopy];
  789. cardVC.url_type = URL_NONE;
  790. cardVC.request_url=nil;
  791. }
  792. else
  793. {
  794. cardVC.url_type = URL_REMOTE;
  795. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  796. }
  797. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  798. params[@"orderCode"]=appDelegate.order_code;
  799. params[@"is_subaction"]=@"true";
  800. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  801. cardVC.params = params;
  802. cardVC.delegate = self;
  803. cardVC.from = indexPath;
  804. // orderinfoVC.params = params;
  805. [self.navigationController pushViewController:cardVC animated:true];
  806. }
  807. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  808. {
  809. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  810. cvc.showNavibar = true;
  811. cvc.contact_type = value;
  812. cvc.is_subaction = @"true";
  813. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  814. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  815. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  816. //
  817. // if(self.returnValue)
  818. // self.returnValue(value);
  819. };
  820. [self.navigationController pushViewController:cvc animated:true];
  821. }
  822. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  823. {
  824. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  825. cvc.showNavibar = true;
  826. cvc.contact_type = value;
  827. cvc.is_subaction = @"true";
  828. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  829. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  830. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  831. //
  832. // if(self.returnValue)
  833. // self.returnValue(value);
  834. };
  835. [self.navigationController pushViewController:cvc animated:true];
  836. }
  837. else if([value isEqualToString:@"Sales_Order_Customer"])
  838. {
  839. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  840. cvc.is_subaction = @"true";
  841. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  842. cvc.showNavibar = true;
  843. cvc.contact_type = value;
  844. __weak typeof(self) weakself = self;
  845. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  846. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  847. //
  848. // if(self.returnValue)
  849. // self.returnValue(value);
  850. };
  851. [self.navigationController pushViewController:cvc animated:true];
  852. }
  853. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  854. {
  855. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  856. cvc.showNavibar = true;
  857. cvc.contact_type = value;
  858. cvc.is_subaction = @"true";
  859. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  860. __weak typeof(self) weakself = self;
  861. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  862. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  863. //
  864. // if(self.returnValue)
  865. // self.returnValue(value);
  866. };
  867. [self.navigationController pushViewController:cvc animated:true];
  868. }
  869. else if([value isEqualToString:@"Contact_Return_To"])
  870. {
  871. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  872. cvc.is_subaction = @"true";
  873. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  874. cvc.showNavibar = true;
  875. cvc.contact_type = value;
  876. __weak typeof(self) weakself = self;
  877. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  878. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  879. //
  880. // if(self.returnValue)
  881. // self.returnValue(value);
  882. };
  883. [self.navigationController pushViewController:cvc animated:true];
  884. }
  885. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  886. {
  887. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  888. cvc.is_subaction = @"true";
  889. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  890. cvc.showNavibar = true;
  891. cvc.contact_type = value;
  892. __weak typeof(self) weakself = self;
  893. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  894. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  895. //
  896. // if(self.returnValue)
  897. // self.returnValue(value);
  898. };
  899. [self.navigationController pushViewController:cvc animated:true];
  900. }
  901. }
  902. }
  903. #pragma mark - Urgency
  904. -(void) viewWillDisappear:(BOOL)animated
  905. {
  906. [super viewWillDisappear:animated];
  907. [self cancel_urgency_timer];
  908. }
  909. - (void)start_urgency_timer {
  910. if (!self.editable) {
  911. return;
  912. }
  913. __weak typeof(self) weakSelf = self;
  914. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  915. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  916. #ifdef OFFLINE_MODE
  917. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  918. #endif
  919. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  920. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  921. // DebugLog(@"timer start....");
  922. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  923. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  924. if ([weakSelf.class_name isEqualToString:@"RAOrderEditorViewController"]) {
  925. // CreateOrderViewController
  926. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  927. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  928. NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  929. [urgencyDic setValue:so forKey:@"order_so"];
  930. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  931. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  932. // page
  933. [urgencyDic setObject:@(weakSelf.pageIndex) forKey:@"page_index"];
  934. [urgencyDic setObject:weakSelf.pageContentDownloadArray forKey:@"download_content_array"];
  935. [urgencyDic setObject:weakSelf.pageContentControlArray forKey:@"control_content_array"];
  936. [urgencyDic setObject:weakSelf.pageChangeDataArray forKey:@"changed_data_array"];
  937. [urgencyDic setObject:weakSelf.pageUpParams forKey:@"up_param_array"];
  938. [urgencyDic setObject:weakSelf.request_url forKey:@"request_url"];
  939. }
  940. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  941. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  942. }];
  943. }
  944. - (void)cancel_urgency_timer {
  945. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  946. }
  947. - (void)recoveryFromUrgencyDic:(NSDictionary *)urgencyDic {
  948. self.disable_dropdown_refresh=true;
  949. self.url_type = URL_RESTORE;
  950. self.params = [NSMutableDictionary dictionary];
  951. self.content_data_download = [urgencyDic objectForKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  952. self.resumeOrder = YES;
  953. self.pageIndex = [[urgencyDic objectForKey:@"page_index"] integerValue];
  954. self.pageContentDownloadArray = [urgencyDic objectForKey:@"download_content_array"];
  955. self.pageContentControlArray = [urgencyDic objectForKey:@"control_content_array"];
  956. self.pageChangeDataArray = [urgencyDic objectForKey:@"changed_data_array"];
  957. self.pageUpParams = [urgencyDic objectForKey:@"up_param_array"];
  958. self.request_url = [urgencyDic objectForKey:@"request_url"];
  959. }
  960. @end