RAOrderEditorViewController.m 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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. if(appDelegate.order_status==0)
  119. {
  120. 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];
  121. }
  122. else
  123. {
  124. 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];
  125. }
  126. alert.tag = CLOSE_ACTION;
  127. [alert show];
  128. }
  129. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  130. if(alertView.tag == CLOSE_ACTION)
  131. {
  132. if(buttonIndex==1)
  133. {
  134. [self.navigationController popViewControllerAnimated:true];
  135. }
  136. if(buttonIndex==2)
  137. {
  138. [self.navigationController popViewControllerAnimated:false];
  139. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  140. //#ifdef RA_NOTIFICATION
  141. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  142. //#else
  143. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  144. //#endif
  145. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  146. }
  147. else if(buttonIndex==3)
  148. {
  149. // close order;
  150. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  151. UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  152. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  153. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  154. dispatch_async(dispatch_get_main_queue(), ^{
  155. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  156. [waitalert dismissViewControllerAnimated:YES completion:nil];
  157. if([[order_json valueForKey:@"result"] intValue]==2)
  158. {
  159. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  160. [appDelegate closeOrder];
  161. //#ifdef RA_NOTIFICATION
  162. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  163. //#else
  164. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  165. //#endif
  166. [((MainViewController*)appDelegate.main_vc) switchToHome];
  167. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  168. {
  169. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  170. }
  171. [self prepareReturn:nil];
  172. [self.navigationController popViewControllerAnimated:true];
  173. }
  174. else
  175. {
  176. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  177. }
  178. });
  179. });
  180. }
  181. }
  182. }
  183. - (void)setupPageControlBar {
  184. // 1. 控制ToolBar Item显隐
  185. NSMutableArray *items = [self.pageControlToolBar.items mutableCopy];
  186. if (self.pageIndex == 0) {
  187. // 首页不需要前一页
  188. if ([items containsObject:self.frontBarItem]) {
  189. [items removeObject:self.frontBarItem];
  190. }
  191. } else if (self.pageIndex == totalPage - 1) {
  192. // // 尾页不需要后一页
  193. // if ([items containsObject:self.nextBarItem]) {
  194. // [items removeObject:self.nextBarItem];
  195. // }
  196. // 尾页点击Next进入Preview
  197. if (![items containsObject:self.nextBarItem]) {
  198. [items addObject:self.nextBarItem];
  199. }
  200. } else {
  201. // 中间显示前一页、后一页按钮
  202. if (![items containsObject:self.frontBarItem]) {
  203. [items insertObject:self.frontBarItem atIndex:0];
  204. }
  205. if (![items containsObject:self.nextBarItem]) {
  206. [items addObject:self.nextBarItem];
  207. }
  208. }
  209. self.pageControlToolBar.items = items;
  210. }
  211. - (NSString *)getValue:(NSString *)key from:(NSArray *)control {
  212. NSString *ret = nil;
  213. for(int i = 0; i < control.count; i++)
  214. {
  215. NSMutableArray* items=(NSMutableArray*)control[i];
  216. for(int j=0;j<items.count;j++)
  217. {
  218. NSDictionary* item=items[j];
  219. NSString* item_name=[item valueForKey:@"name"];
  220. if([item_name isEqualToString:key])
  221. {
  222. NSString* control = [item valueForKey:@"control"];
  223. if([control isEqualToString:@"enum"])
  224. {
  225. NSDictionary* cadedate = [item objectForKey:@"cadedate"];
  226. int cc = [[cadedate valueForKey:@"count"] intValue];
  227. for(int l=0;l<cc;l++)
  228. {
  229. NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
  230. if([[val_json valueForKey:@"check"]intValue]==1)
  231. return [val_json valueForKey:@"value_id"];
  232. }
  233. }
  234. else
  235. return [item valueForKey:@"value"];
  236. }
  237. }
  238. }
  239. return ret;
  240. }
  241. #pragma mark - BarItem Action
  242. - (IBAction)frontBarItemClick:(UIBarButtonItem *)sender {
  243. if (self.pageIndex == 0) {
  244. return;
  245. }
  246. // 结束编辑防止TextFiled在编辑中时返回,Table会Reload,此时TextFiled会结束编辑,但是Data已经改变。
  247. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  248. self.pageIndex--;
  249. // 1.恢复当前页面数据
  250. NSMutableDictionary* upparams = [self.pageUpParams lastObject]; // 前页上行参数
  251. __weak typeof(self) weakSelf = self;
  252. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  253. [weakSelf.params removeObjectForKey:key];
  254. }];
  255. [self.pageUpParams removeLastObject];
  256. [self.params setObject:@(self.pageIndex) forKey:@"step"];
  257. self.content_data_control = [self.pageContentControlArray lastObject];
  258. [self.pageContentControlArray removeLastObject];
  259. self.content_data_download = [self.pageContentDownloadArray lastObject];
  260. [self.pageContentDownloadArray removeLastObject];
  261. self.changed_data = [self.pageChangeDataArray lastObject];
  262. [self.pageChangeDataArray removeLastObject];
  263. // 2.刷新页面
  264. [self.editorTable reloadData];
  265. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  266. [self setupPageControlBar];
  267. }
  268. - (IBAction)nextBarItemClick:(UIBarButtonItem *)sender {
  269. if (self.pageIndex == totalPage) {
  270. return;
  271. }
  272. // 结束编辑防止TextFiled在编辑中时下一页,Table会Reload,此时TextFiled会结束编辑,但是Data已经改变。
  273. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  274. NSMutableDictionary* upparams = [self check_cancommit:true]; // 当前页上行参数
  275. if(self.cancommit==false)
  276. return;
  277. __weak typeof(self) weakSelf = self;
  278. if (self.pageIndex == totalPage - 1) {
  279. // 在此设置Step 避免返回后index不正确。
  280. [upparams setObject:@(self.pageIndex + 1) forKey:@"step"];
  281. // 尾页 进入Preview
  282. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  283. [weakSelf.params setObject:obj forKey:key];
  284. }];
  285. RAOrderPreviewController * orderinfoVC = [[RAOrderPreviewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  286. orderinfoVC.disable_dropdown_refresh=true;
  287. orderinfoVC.url_type = URL_REMOTE;
  288. orderinfoVC.request_url=URL_BACK_ORDER_PREVIEW;
  289. orderinfoVC.params = self.params;
  290. orderinfoVC.delegate=self.delegate;
  291. [self.navigationController pushViewController:orderinfoVC animated:true];
  292. return;
  293. }
  294. self.pageIndex++;
  295. // 请求页码
  296. [upparams setObject:@(self.pageIndex) forKey:@"step"];
  297. // 1.保存当前页面数据
  298. if (upparams == nil) {
  299. upparams = [NSMutableDictionary dictionary];
  300. }
  301. [self.pageUpParams addObject:upparams];
  302. if (self.content_data_control == nil) {
  303. self.content_data_control = [NSMutableArray array];
  304. }
  305. [self.pageContentControlArray addObject:self.content_data_control];
  306. if (self.content_data_download == nil) {
  307. self.content_data_download = [NSMutableDictionary dictionary];
  308. }
  309. [self.pageContentDownloadArray addObject:self.content_data_download];
  310. if (self.changed_data == nil) {
  311. self.changed_data = [NSMutableDictionary dictionary];
  312. }
  313. [self.pageChangeDataArray addObject:self.changed_data];
  314. // 2.请求下一页数据
  315. // 当前页及之前所有页参数均上传
  316. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  317. [weakSelf.params setObject:obj forKey:key];
  318. }];
  319. [self setupPageControlBar];
  320. self.content_data_download = [NSMutableDictionary dictionary];
  321. [self refresh:nil];
  322. }
  323. #pragma mark - Override
  324. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  325. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  326. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  327. NSString* control = [item_json valueForKey:@"control"];
  328. if([control isEqualToString:@"model"]) {
  329. ((CommonEditorCellModel *)cell).avalibilityLabel.hidden = YES;
  330. }
  331. return cell;
  332. }
  333. - (void)download_success {
  334. NSString *title = [self.content_data_download objectForKey:@"title"];
  335. self.title = title;
  336. [self setupPageControlBar];
  337. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  338. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  339. NSString* order_customerid=[self getValue:@"customer_cid"];
  340. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  341. appDelegate.order_customer_id = order_customerid;
  342. }
  343. - (void)download_failed {
  344. // 恢复为前一页
  345. [self frontBarItemClick:nil];
  346. }
  347. -(NSString*) getValue:(NSString*)name
  348. {
  349. if (self.pageContentControlArray.count) {
  350. NSString* ret=nil;
  351. for (NSInteger i = self.pageContentControlArray.count - 1; i >= 0 ; i--) {
  352. NSArray *control = [self.pageContentControlArray objectAtIndex:i];
  353. ret = [self getValue:name from:control];
  354. if (ret != nil) {
  355. return ret;
  356. }
  357. }
  358. return ret;
  359. } else {
  360. return [self getValue:name from:self.content_data_control];
  361. }
  362. }
  363. #pragma mark - Place Order
  364. - (void)alertMessage:(NSString *)msg {
  365. if (notifyMe_switch) {
  366. if ([self.class_name isEqualToString:@"RAOrderEditorViewController"]) {
  367. NSString *err_msg = msg;
  368. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
  369. __weak typeof(self) weakself = self;
  370. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  371. [weakself.navigationController popViewControllerAnimated:YES];
  372. }];
  373. [alertVC addAction:action];
  374. [self presentViewController:alertVC animated:YES completion:nil];
  375. } else {
  376. [RAUtils message_alert:msg title:nil controller:self] ;
  377. }
  378. } else {
  379. [RAUtils message_alert:msg title:nil controller:self] ;
  380. }
  381. }
  382. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  383. {
  384. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  385. if([value isEqualToString:@"new_addr"])
  386. {
  387. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  388. addressVC.url_type = URL_REMOTE;
  389. addressVC.request_url=URL_ADDRESS_EDOTOR;
  390. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  391. addressVC.params = params;
  392. addressVC.delegate = self;
  393. addressVC.from = indexPath;
  394. // orderinfoVC.params = params;
  395. [self.navigationController pushViewController:addressVC animated:true];
  396. }else if([value isEqualToString:@"credit_card"])
  397. {
  398. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  399. NSDictionary *data = [item_json objectForKey:@"data"];
  400. if(data!=nil)
  401. {
  402. cardVC.content_data_download = [data mutableCopy];
  403. cardVC.url_type = URL_NONE;
  404. cardVC.request_url=nil;
  405. }
  406. else
  407. {
  408. cardVC.url_type = URL_REMOTE;
  409. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  410. }
  411. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  412. params[@"orderCode"]=appDelegate.order_code;
  413. cardVC.params = params;
  414. cardVC.delegate = self;
  415. cardVC.from = indexPath;
  416. [self.navigationController pushViewController:cardVC animated:true];
  417. }
  418. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  419. {
  420. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  421. cvc.showNavibar = true;
  422. cvc.contact_type = value;
  423. __weak typeof(self) weakself = self;
  424. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  425. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  426. };
  427. [self.navigationController pushViewController:cvc animated:true];
  428. }
  429. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  430. {
  431. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  432. cvc.showNavibar = true;
  433. cvc.contact_type = value;
  434. __weak typeof(self) weakself = self;
  435. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  436. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  437. };
  438. [self.navigationController pushViewController:cvc animated:true];
  439. }
  440. else if([value isEqualToString:@"Sales_Order_Customer"])
  441. {
  442. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  443. cvc.contact_type = value;
  444. cvc.showNavibar = true;
  445. __weak typeof(self) weakself = self;
  446. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  447. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  448. };
  449. [self.navigationController pushViewController:cvc animated:true];
  450. }
  451. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  452. {
  453. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  454. cvc.showNavibar = true;
  455. cvc.contact_type = value;
  456. __weak typeof(self) weakself = self;
  457. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  458. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  459. };
  460. [self.navigationController pushViewController:cvc animated:true];
  461. }
  462. else if([value isEqualToString:@"Contact_Return_To"])
  463. {
  464. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  465. cvc.showNavibar = true;
  466. cvc.contact_type = value;
  467. __weak typeof(self) weakself = self;
  468. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  469. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  470. };
  471. [self.navigationController pushViewController:cvc animated:true];
  472. }
  473. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  474. {
  475. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  476. cvc.showNavibar = true;
  477. cvc.contact_type = value;
  478. __weak typeof(self) weakself = self;
  479. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  480. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  481. };
  482. [self.navigationController pushViewController:cvc animated:true];
  483. }
  484. }
  485. - (UIView *)createDemoView:(NSString*) msg
  486. {
  487. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  488. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  489. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  490. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  491. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  492. titleLabel.text=@"Order Submission";
  493. titleLabel.numberOfLines = 0;
  494. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  495. // titleLabel.textAlignment = NSTextAlignmentRight;
  496. titleLabel.textAlignment = NSTextAlignmentCenter;
  497. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  498. CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  499. //[titleLabel sizeToFit];
  500. // titleLabel.center.x = demoView.center.x;
  501. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  502. [demoView addSubview:titleLabel];
  503. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  504. lineLabel.font = [UIFont systemFontOfSize:17];
  505. lineLabel.text=msg;
  506. lineLabel.numberOfLines = 0;
  507. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  508. CGSize sizemsg = [msg sizeWithFont:[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. //
  581. //- (IBAction)onSaveClick:(id)sender {
  582. //
  583. // id a = nil;
  584. // NSMutableArray *arr = [NSMutableArray array];
  585. // [arr addObject:a];
  586. //
  587. // [self.lastedit endEditing:true];
  588. // [self.lasttextview endEditing:true];
  589. //
  590. // NSMutableDictionary* upparams = [self check_cancommit:false];
  591. //
  592. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  593. // upparams[@"shipping"] = nil;
  594. //
  595. //
  596. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order"];
  597. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  598. //
  599. // NSDictionary* editor_json = [RANetwork save_Order:upparams];
  600. //
  601. // dispatch_async(dispatch_get_main_queue(), ^{
  602. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  603. //
  604. //
  605. // if([[editor_json valueForKey:@"result"] intValue]==2)
  606. // {
  607. //
  608. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  609. //
  610. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  611. //
  612. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  613. // {
  614. // appDelegate.customerInfo = customerInfo;
  615. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  616. // }
  617. // NSString *msg = nil;
  618. // if ([editor_json objectForKey:@"so#"]) {
  619. // msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  620. // }
  621. // [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  622. //
  623. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  624. // {
  625. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  626. // [self prepareReturn:nil];
  627. // [self.navigationController popViewControllerAnimated:true];
  628. // }
  629. //
  630. // if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  631. //
  632. // if (![Singleton sharedInstance].currentOrderIsMerged) {
  633. // [self releaseOrderAfterSave];
  634. // }
  635. //
  636. //
  637. // }
  638. //
  639. // }
  640. // else
  641. // {
  642. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  643. // }
  644. //
  645. // });
  646. // });
  647. //
  648. //}
  649. - (void)releaseOrderAfterSave {
  650. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  651. [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  652. [appDelegate closeOrder];
  653. [appDelegate SetSo:nil];
  654. appDelegate.cart_count=0;
  655. [appDelegate update_count_mark];
  656. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  657. [self prepareReturn:nil];
  658. [self.navigationController popToRootViewControllerAnimated:false];
  659. }
  660. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  661. {
  662. NSString* ret=nil;
  663. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  664. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  665. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  666. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  667. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  668. if(customer_address1.length>0)
  669. [arraddr addObject:customer_address1];
  670. if(customer_address2.length>0)
  671. [arraddr addObject:customer_address2];
  672. if(customer_address3.length>0)
  673. [arraddr addObject:customer_address3];
  674. if(customer_address4.length>0)
  675. [arraddr addObject:customer_address4];
  676. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  677. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  678. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  679. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  680. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  681. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  682. if(customer_city.length>0)
  683. [arrcty addObject:customer_city];
  684. if(customer_state.length>0)
  685. [arrcty addObject:customer_state];
  686. if(customer_zipcode.length>0)
  687. [arrcty addObject:customer_zipcode];
  688. if(customer_country.length>0)
  689. [arrcty addObject:customer_country];
  690. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  691. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  692. if(addr_string.length>0)
  693. [arrext addObject:addr_string];
  694. if(cty_string.length>0)
  695. [arrext addObject:cty_string];
  696. ret = [arrext componentsJoinedByString:@"\r\n"];
  697. return ret;
  698. }
  699. -(NSMutableDictionary*)create_cusromer_info_from_table
  700. {
  701. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  702. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  703. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  704. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  705. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  706. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  707. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  708. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  709. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  710. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  711. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  712. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  713. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  714. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  715. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  716. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  717. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  718. NSString * firstname =nil;
  719. NSString* lastname = nil;
  720. NSString* contact_name = [self getValue:@"customer_contact"];
  721. if(contact_name!=nil)
  722. {
  723. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  724. if(_arr.count>=1)
  725. {
  726. firstname =_arr[0];
  727. if(_arr.count>1)
  728. {
  729. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  730. }
  731. }
  732. }
  733. [ret setValue:firstname forKey:@"customer_first_name"];
  734. [ret setValue:lastname forKey:@"customer_last_name"];
  735. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  736. return ret;
  737. }
  738. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  739. {
  740. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  741. NSArray *keys= [key_map allKeys];
  742. //遍历keys
  743. for(int i=0;i<[keys count];i++)
  744. {
  745. //得到当前key
  746. NSString *key=[keys objectAtIndex:i];
  747. //如果key不是pic,说明value是字符类型,比如name:Boris
  748. NSString* valuefrom = [key_map valueForKey:key];
  749. if(valuefrom.length==0)
  750. continue;
  751. NSString* value=[self getValue:valuefrom];
  752. [ret setValue:value forKey:valuefrom];
  753. }
  754. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  755. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  756. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  757. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  758. return ret;
  759. }
  760. #pragma mark - multi_action sub action clicked
  761. - (void)MActionClicked:(UIButton *)sender {
  762. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  763. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  764. int refresh =0;
  765. NSMutableDictionary* section_json=nil;
  766. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  767. NSString* subid=[item_json valueForKey:@"subid"];
  768. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  769. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  770. NSString* type = [sub_action valueForKey:@"type"];
  771. if([type isEqualToString:@"pull"])
  772. {
  773. [self.lastedit endEditing:true];
  774. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  775. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  776. NSMutableDictionary* value=[self create_value_map:keymap];
  777. if(subid==nil)
  778. {
  779. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  780. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  781. int icount=[[section_json valueForKey:@"count"] intValue];
  782. for (int ic=0;ic<icount;ic++)
  783. {
  784. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  785. NSString* mapto = [modify_item valueForKey:@"name"];
  786. if(mapto.length==0)
  787. continue;
  788. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  789. if(valuefrom==nil)
  790. continue;
  791. NSString* valuestr=[value valueForKey:valuefrom];
  792. // valuestr = [self getValue:valuefrom];
  793. if(true)
  794. {
  795. if(valuestr.length>0)
  796. [modify_item setValue:valuestr forKey:@"value"];
  797. else
  798. [modify_item setValue:@"" forKey:@"value"];
  799. [modify_item setValue:@"true" forKey:@"dirty"];
  800. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  801. }
  802. }
  803. }
  804. else
  805. {
  806. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  807. int section = [(NSString*)idarr[0] intValue];
  808. int item=[(NSString*)idarr[1] intValue];
  809. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  810. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  811. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  812. NSString* control_type = [olditem valueForKey:@"control"];
  813. if([control_type isEqualToString:@"switch"])
  814. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  815. else if([control_type isEqualToString:@"enum"])
  816. {
  817. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  818. }
  819. else
  820. {
  821. [RAUtils alert_view:@"" title:@"not impl"];
  822. }
  823. [olditem setValue:@"true" forKey:@"dirty"];
  824. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  825. }
  826. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  827. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  828. if(refresh==1)
  829. {
  830. // if(restore_json!=nil)
  831. // {
  832. // int rc=[[restore_json valueForKey:@"count"] intValue];
  833. // for(int ir=0;ir<rc;ir++)
  834. // {
  835. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  836. //
  837. //
  838. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  839. // for(int i=0;i<section_count;i++)
  840. // {
  841. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  842. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  843. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  844. // for(int j=0;j<item_count;j++)
  845. // {
  846. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  847. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  848. //
  849. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  850. // {
  851. // [itemjson removeObjectForKey:@"dirty"];
  852. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  853. // }
  854. //
  855. // }
  856. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  857. // }
  858. //
  859. //
  860. // }
  861. //
  862. // }
  863. [self refresh:refresh_trigger] ;
  864. return ;
  865. }
  866. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  867. [self.editorTable reloadData ];
  868. }
  869. else
  870. {
  871. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  872. NSDictionary * item_json = sub_action;
  873. NSString* value = [item_json valueForKey:@"value"];
  874. if([value isEqualToString:@"new_addr"])
  875. {
  876. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  877. addressVC.url_type = URL_REMOTE;
  878. addressVC.request_url=URL_ADDRESS_EDOTOR;
  879. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  880. // NSString * string = [checked componentsJoinedByString:@","];
  881. // [params setValue:string forKey:@"cart2Checkbox"];
  882. params[@"is_subaction"]=@"true";
  883. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  884. addressVC.params = params;
  885. addressVC.delegate = self;
  886. addressVC.from = indexPath;
  887. // orderinfoVC.params = params;
  888. [self.navigationController pushViewController:addressVC animated:true];
  889. }else if([value isEqualToString:@"credit_card"])
  890. {
  891. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  892. NSDictionary *data = [item_json objectForKey:@"data"];
  893. if(data!=nil)
  894. {
  895. cardVC.content_data_download = [data mutableCopy];
  896. cardVC.url_type = URL_NONE;
  897. cardVC.request_url=nil;
  898. }
  899. else
  900. {
  901. cardVC.url_type = URL_REMOTE;
  902. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  903. }
  904. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  905. params[@"orderCode"]=appDelegate.order_code;
  906. params[@"is_subaction"]=@"true";
  907. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  908. cardVC.params = params;
  909. cardVC.delegate = self;
  910. cardVC.from = indexPath;
  911. // orderinfoVC.params = params;
  912. [self.navigationController pushViewController:cardVC animated:true];
  913. }
  914. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  915. {
  916. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  917. cvc.showNavibar = true;
  918. cvc.contact_type = value;
  919. cvc.is_subaction = @"true";
  920. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  921. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  922. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  923. //
  924. // if(self.returnValue)
  925. // self.returnValue(value);
  926. };
  927. [self.navigationController pushViewController:cvc animated:true];
  928. }
  929. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  930. {
  931. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  932. cvc.showNavibar = true;
  933. cvc.contact_type = value;
  934. cvc.is_subaction = @"true";
  935. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  936. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  937. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  938. //
  939. // if(self.returnValue)
  940. // self.returnValue(value);
  941. };
  942. [self.navigationController pushViewController:cvc animated:true];
  943. }
  944. else if([value isEqualToString:@"Sales_Order_Customer"])
  945. {
  946. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  947. cvc.is_subaction = @"true";
  948. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  949. cvc.showNavibar = true;
  950. cvc.contact_type = value;
  951. __weak typeof(self) weakself = self;
  952. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  953. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  954. //
  955. // if(self.returnValue)
  956. // self.returnValue(value);
  957. };
  958. [self.navigationController pushViewController:cvc animated:true];
  959. }
  960. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  961. {
  962. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  963. cvc.showNavibar = true;
  964. cvc.contact_type = value;
  965. cvc.is_subaction = @"true";
  966. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  967. __weak typeof(self) weakself = self;
  968. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  969. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  970. //
  971. // if(self.returnValue)
  972. // self.returnValue(value);
  973. };
  974. [self.navigationController pushViewController:cvc animated:true];
  975. }
  976. else if([value isEqualToString:@"Contact_Return_To"])
  977. {
  978. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  979. cvc.is_subaction = @"true";
  980. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  981. cvc.showNavibar = true;
  982. cvc.contact_type = value;
  983. __weak typeof(self) weakself = self;
  984. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  985. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  986. //
  987. // if(self.returnValue)
  988. // self.returnValue(value);
  989. };
  990. [self.navigationController pushViewController:cvc animated:true];
  991. }
  992. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  993. {
  994. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  995. cvc.is_subaction = @"true";
  996. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  997. cvc.showNavibar = true;
  998. cvc.contact_type = value;
  999. __weak typeof(self) weakself = self;
  1000. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1001. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1002. //
  1003. // if(self.returnValue)
  1004. // self.returnValue(value);
  1005. };
  1006. [self.navigationController pushViewController:cvc animated:true];
  1007. }
  1008. }
  1009. }
  1010. #pragma mark - Urgency
  1011. -(void) viewWillDisappear:(BOOL)animated
  1012. {
  1013. [super viewWillDisappear:animated];
  1014. [self cancel_urgency_timer];
  1015. }
  1016. - (void)start_urgency_timer {
  1017. if (!self.editable) {
  1018. return;
  1019. }
  1020. __weak typeof(self) weakSelf = self;
  1021. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1022. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  1023. __block NSString* labelsotext= mainVC.labelSo.text;
  1024. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  1025. #ifdef OFFLINE_MODE
  1026. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  1027. #endif
  1028. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  1029. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  1030. // DebugLog(@"timer start....");
  1031. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1032. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  1033. if ([weakSelf.class_name isEqualToString:@"RAOrderEditorViewController"]) {
  1034. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  1035. NSString *so = [labelsotext substringFromIndex:5];
  1036. [urgencyDic setValue:so forKey:@"order_so"];
  1037. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  1038. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  1039. // page
  1040. [urgencyDic setObject:@(weakSelf.pageIndex) forKey:@"page_index"];
  1041. [urgencyDic setObject:weakSelf.pageContentDownloadArray forKey:@"download_content_array"];
  1042. [urgencyDic setObject:weakSelf.pageContentControlArray forKey:@"control_content_array"];
  1043. [urgencyDic setObject:weakSelf.pageChangeDataArray forKey:@"changed_data_array"];
  1044. [urgencyDic setObject:weakSelf.pageUpParams forKey:@"up_param_array"];
  1045. [urgencyDic setObject:weakSelf.request_url forKey:@"request_url"];
  1046. [urgencyDic setObject:weakSelf.params forKey:@"params"];
  1047. }
  1048. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  1049. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  1050. }];
  1051. }
  1052. - (void)cancel_urgency_timer {
  1053. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  1054. }
  1055. - (void)recoveryFromUrgencyDic:(NSDictionary *)urgencyDic {
  1056. self.disable_dropdown_refresh=true;
  1057. self.url_type = URL_RESTORE;
  1058. self.params = [NSMutableDictionary dictionary];
  1059. self.content_data_download = [urgencyDic objectForKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1060. self.resumeOrder = YES;
  1061. self.pageIndex = [[urgencyDic objectForKey:@"page_index"] integerValue];
  1062. self.pageContentDownloadArray = [urgencyDic objectForKey:@"download_content_array"];
  1063. self.pageContentControlArray = [urgencyDic objectForKey:@"control_content_array"];
  1064. self.pageChangeDataArray = [urgencyDic objectForKey:@"changed_data_array"];
  1065. self.pageUpParams = [urgencyDic objectForKey:@"up_param_array"];
  1066. self.request_url = [urgencyDic objectForKey:@"request_url"];
  1067. self.params = [urgencyDic objectForKey:@"params"];
  1068. }
  1069. @end