RAOrderEditorViewController.m 56 KB

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