RAOrderEditorViewController.m 55 KB

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