RAOrderEditorViewController.m 54 KB

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