RAOrderEditorViewController.m 52 KB

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