RAOrderEditorViewController.m 57 KB

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