RAOrderEditorViewController.m 56 KB

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