RAOrderEditorViewController.m 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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 && appDelegate.customer_type == CustomerTypeStore) {
  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. [urgencyDic setObject:weakSelf.params forKey:@"params"];
  1016. }
  1017. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  1018. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  1019. }];
  1020. }
  1021. - (void)cancel_urgency_timer {
  1022. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  1023. }
  1024. - (void)recoveryFromUrgencyDic:(NSDictionary *)urgencyDic {
  1025. self.disable_dropdown_refresh=true;
  1026. self.url_type = URL_RESTORE;
  1027. self.params = [NSMutableDictionary dictionary];
  1028. self.content_data_download = [urgencyDic objectForKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1029. self.resumeOrder = YES;
  1030. self.pageIndex = [[urgencyDic objectForKey:@"page_index"] integerValue];
  1031. self.pageContentDownloadArray = [urgencyDic objectForKey:@"download_content_array"];
  1032. self.pageContentControlArray = [urgencyDic objectForKey:@"control_content_array"];
  1033. self.pageChangeDataArray = [urgencyDic objectForKey:@"changed_data_array"];
  1034. self.pageUpParams = [urgencyDic objectForKey:@"up_param_array"];
  1035. self.request_url = [urgencyDic objectForKey:@"request_url"];
  1036. self.params = [urgencyDic objectForKey:@"params"];
  1037. }
  1038. @end