RAOrderEditorViewController.m 54 KB

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