RAOrderEditorViewController.m 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  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. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
  142. NSDictionary* order_json = result;
  143. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  144. [waitalert dismissViewControllerAnimated:YES completion:^{
  145. if([[order_json valueForKey:@"result"] intValue]==2)
  146. {
  147. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  148. [appDelegate closeOrder];
  149. //#ifdef RA_NOTIFICATION
  150. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  151. //#else
  152. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  153. //#endif
  154. [((MainViewController*)appDelegate.main_vc) switchToHome];
  155. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  156. {
  157. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  158. }
  159. [self prepareReturn:nil];
  160. [self.navigationController popViewControllerAnimated:true];
  161. }
  162. else
  163. {
  164. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  165. }
  166. }];
  167. }];
  168. }];
  169. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  170. //
  171. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  172. //
  173. // dispatch_async(dispatch_get_main_queue(), ^{
  174. // // [waitalert dismissViewControllerAnimated:YES completion:nil];
  175. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  176. //
  177. // if([[order_json valueForKey:@"result"] intValue]==2)
  178. // {
  179. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  180. //
  181. // [appDelegate closeOrder];
  182. //
  183. //
  184. // //#ifdef RA_NOTIFICATION
  185. // // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  186. // //#else
  187. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  188. // //#endif
  189. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  190. //
  191. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  192. // {
  193. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  194. // }
  195. //
  196. // [self prepareReturn:nil];
  197. //
  198. //
  199. // [self.navigationController popViewControllerAnimated:true];
  200. //
  201. //
  202. // }
  203. // else
  204. // {
  205. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  206. // }
  207. //
  208. //
  209. //
  210. // });
  211. // });
  212. }];
  213. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  214. }];
  215. [alertController addAction:action_0];
  216. [alertController addAction:action_1];
  217. [alertController addAction:action_2];
  218. [alertController addAction:action_3];
  219. [self presentViewController:alertController animated:YES completion:nil];
  220. //
  221. // 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];
  222. // else
  223. // {
  224. // 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];
  225. // }
  226. // alert.tag = CLOSE_ACTION;
  227. //
  228. // [alert show];
  229. }
  230. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  231. //
  232. // if(alertView.tag == CLOSE_ACTION)
  233. // {
  234. // if(buttonIndex==1)
  235. // {
  236. //
  237. // [self.navigationController popViewControllerAnimated:true];
  238. //
  239. // }
  240. // if(buttonIndex==2)
  241. // {
  242. //
  243. // [self.navigationController popViewControllerAnimated:false];
  244. //
  245. //
  246. //
  247. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  248. ////#ifdef RA_NOTIFICATION
  249. //// [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  250. ////#else
  251. //// [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  252. ////#endif
  253. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  254. //
  255. // }
  256. // else if(buttonIndex==3)
  257. // {
  258. // // close order;
  259. //
  260. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  261. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  262. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  263. //
  264. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  265. //
  266. // dispatch_async(dispatch_get_main_queue(), ^{
  267. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  268. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  269. //
  270. // if([[order_json valueForKey:@"result"] intValue]==2)
  271. // {
  272. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  273. //
  274. // [appDelegate closeOrder];
  275. //
  276. //
  277. ////#ifdef RA_NOTIFICATION
  278. //// [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  279. ////#else
  280. //// [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  281. ////#endif
  282. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  283. //
  284. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  285. // {
  286. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  287. // }
  288. //
  289. // [self prepareReturn:nil];
  290. //
  291. //
  292. // [self.navigationController popViewControllerAnimated:true];
  293. //
  294. //
  295. // }
  296. // else
  297. // {
  298. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  299. // }
  300. //
  301. //
  302. //
  303. // });
  304. // });
  305. //
  306. //
  307. // }
  308. // }
  309. //
  310. //}
  311. - (void)setupPageControlBar {
  312. // 1. 控制ToolBar Item显隐
  313. NSMutableArray *items = [self.pageControlToolBar.items mutableCopy];
  314. if (self.pageIndex == 0) {
  315. // 首页不需要前一页
  316. if ([items containsObject:self.frontBarItem]) {
  317. [items removeObject:self.frontBarItem];
  318. }
  319. } else if (self.pageIndex == totalPage - 1) {
  320. // // 尾页不需要后一页
  321. // if ([items containsObject:self.nextBarItem]) {
  322. // [items removeObject:self.nextBarItem];
  323. // }
  324. // 尾页点击Next进入Preview
  325. if (![items containsObject:self.nextBarItem]) {
  326. [items addObject:self.nextBarItem];
  327. }
  328. } else {
  329. // 中间显示前一页、后一页按钮
  330. if (![items containsObject:self.frontBarItem]) {
  331. [items insertObject:self.frontBarItem atIndex:0];
  332. }
  333. if (![items containsObject:self.nextBarItem]) {
  334. [items addObject:self.nextBarItem];
  335. }
  336. }
  337. self.pageControlToolBar.items = items;
  338. }
  339. - (NSString *)getValue:(NSString *)key from:(NSArray *)control {
  340. NSString *ret = nil;
  341. for(int i = 0; i < control.count; i++)
  342. {
  343. NSMutableArray* items=(NSMutableArray*)control[i];
  344. for(int j=0;j<items.count;j++)
  345. {
  346. NSDictionary* item=items[j];
  347. NSString* item_name=[item valueForKey:@"name"];
  348. if([item_name isEqualToString:key])
  349. {
  350. NSString* control = [item valueForKey:@"control"];
  351. if([control isEqualToString:@"enum"])
  352. {
  353. NSDictionary* cadedate = [item objectForKey:@"cadedate"];
  354. int cc = [[cadedate valueForKey:@"count"] intValue];
  355. for(int l=0;l<cc;l++)
  356. {
  357. NSDictionary* val_json=[cadedate objectForKey:[NSString stringWithFormat:@"val_%d",l]];
  358. if([[val_json valueForKey:@"check"]intValue]==1)
  359. return [val_json valueForKey:@"value_id"];
  360. }
  361. }
  362. else
  363. return [item valueForKey:@"value"];
  364. }
  365. }
  366. }
  367. return ret;
  368. }
  369. #pragma mark - BarItem Action
  370. - (IBAction)frontBarItemClick:(UIBarButtonItem *)sender {
  371. if (self.pageIndex == 0) {
  372. return;
  373. }
  374. // 结束编辑防止TextFiled在编辑中时返回,Table会Reload,此时TextFiled会结束编辑,但是Data已经改变。
  375. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  376. self.pageIndex--;
  377. // 1.恢复当前页面数据
  378. NSMutableDictionary* upparams = [self.pageUpParams lastObject]; // 前页上行参数
  379. __weak typeof(self) weakSelf = self;
  380. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  381. [weakSelf.params removeObjectForKey:key];
  382. }];
  383. [self.pageUpParams removeLastObject];
  384. [self.params setObject:@(self.pageIndex) forKey:@"step"];
  385. self.content_data_control = [self.pageContentControlArray lastObject];
  386. [self.pageContentControlArray removeLastObject];
  387. self.content_data_download = [self.pageContentDownloadArray lastObject];
  388. [self.pageContentDownloadArray removeLastObject];
  389. self.changed_data = [self.pageChangeDataArray lastObject];
  390. [self.pageChangeDataArray removeLastObject];
  391. // 2.刷新页面
  392. [self.editorTable reloadData];
  393. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  394. [self setupPageControlBar];
  395. }
  396. - (IBAction)nextBarItemClick:(UIBarButtonItem *)sender {
  397. if (self.pageIndex == totalPage) {
  398. return;
  399. }
  400. // 结束编辑防止TextFiled在编辑中时下一页,Table会Reload,此时TextFiled会结束编辑,但是Data已经改变。
  401. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  402. NSMutableDictionary* upparams = [self check_cancommit:true]; // 当前页上行参数
  403. if(self.cancommit==false)
  404. return;
  405. __weak typeof(self) weakSelf = self;
  406. if (self.pageIndex == totalPage - 1) {
  407. // 在此设置Step 避免返回后index不正确。
  408. [upparams setObject:@(self.pageIndex + 1) forKey:@"step"];
  409. // 尾页 进入Preview
  410. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  411. [weakSelf.params setObject:obj forKey:key];
  412. }];
  413. RAOrderPreviewController * orderinfoVC = [[RAOrderPreviewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  414. orderinfoVC.disable_dropdown_refresh=true;
  415. orderinfoVC.url_type = URL_REMOTE;
  416. orderinfoVC.request_url=URL_BACK_ORDER_PREVIEW;
  417. orderinfoVC.params = self.params;
  418. orderinfoVC.delegate=self.delegate;
  419. [self.navigationController pushViewController:orderinfoVC animated:true];
  420. return;
  421. }
  422. self.pageIndex++;
  423. // 请求页码
  424. [upparams setObject:@(self.pageIndex) forKey:@"step"];
  425. // 1.保存当前页面数据
  426. if (upparams == nil) {
  427. upparams = [NSMutableDictionary dictionary];
  428. }
  429. [self.pageUpParams addObject:upparams];
  430. if (self.content_data_control == nil) {
  431. self.content_data_control = [NSMutableArray array];
  432. }
  433. [self.pageContentControlArray addObject:self.content_data_control];
  434. if (self.content_data_download == nil) {
  435. self.content_data_download = [NSMutableDictionary dictionary];
  436. }
  437. [self.pageContentDownloadArray addObject:self.content_data_download];
  438. if (self.changed_data == nil) {
  439. self.changed_data = [NSMutableDictionary dictionary];
  440. }
  441. [self.pageChangeDataArray addObject:self.changed_data];
  442. // 2.请求下一页数据
  443. // 当前页及之前所有页参数均上传
  444. [upparams enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
  445. [weakSelf.params setObject:obj forKey:key];
  446. }];
  447. [self setupPageControlBar];
  448. self.content_data_download = [NSMutableDictionary dictionary];
  449. [self refresh:nil discardDirty:false];
  450. }
  451. #pragma mark - Override
  452. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  453. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  454. NSDictionary* item_json =((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row];
  455. NSString* control = [item_json valueForKey:@"control"];
  456. if([control isEqualToString:@"model"]) {
  457. ((CommonEditorCellModel *)cell).avalibilityLabel.hidden = YES;
  458. }
  459. return cell;
  460. }
  461. - (void)download_success {
  462. NSString *title = [self.content_data_download objectForKey:@"title"];
  463. self.title = title;
  464. [self setupPageControlBar];
  465. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  466. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  467. NSString* order_customerid=[self getValue:@"customer_cid"];
  468. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  469. appDelegate.order_customer_id = order_customerid;
  470. }
  471. - (void)download_failed {
  472. // 恢复为前一页
  473. [self frontBarItemClick:nil];
  474. }
  475. -(NSString*) getValue:(NSString*)name
  476. {
  477. if (self.pageContentControlArray.count) {
  478. NSString* ret=nil;
  479. for (NSInteger i = self.pageContentControlArray.count - 1; i >= 0 ; i--) {
  480. NSArray *control = [self.pageContentControlArray objectAtIndex:i];
  481. ret = [self getValue:name from:control];
  482. if (ret != nil) {
  483. return ret;
  484. }
  485. }
  486. return ret;
  487. } else {
  488. return [self getValue:name from:self.content_data_control];
  489. }
  490. }
  491. #pragma mark - Place Order
  492. - (void)alertMessage:(NSString *)msg {
  493. if (notifyMe_switch) {
  494. if ([self.class_name isEqualToString:@"RAOrderEditorViewController"]) {
  495. NSString *err_msg = msg;
  496. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
  497. __weak typeof(self) weakself = self;
  498. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  499. [weakself.navigationController popViewControllerAnimated:YES];
  500. }];
  501. [alertVC addAction:action];
  502. [self presentViewController:alertVC animated:YES completion:nil];
  503. } else {
  504. [RAUtils message_alert:msg title:nil controller:self] ;
  505. }
  506. } else {
  507. [RAUtils message_alert:msg title:nil controller:self] ;
  508. }
  509. }
  510. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  511. {
  512. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  513. if([value isEqualToString:@"new_addr"])
  514. {
  515. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  516. addressVC.url_type = URL_REMOTE;
  517. addressVC.request_url=URL_ADDRESS_EDOTOR;
  518. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  519. addressVC.params = params;
  520. addressVC.delegate = self;
  521. addressVC.from = indexPath;
  522. // orderinfoVC.params = params;
  523. [self.navigationController pushViewController:addressVC animated:true];
  524. }else if([value isEqualToString:@"credit_card"])
  525. {
  526. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  527. NSDictionary *data = [item_json objectForKey:@"data"];
  528. if(data!=nil)
  529. {
  530. cardVC.content_data_download = [data mutableCopy];
  531. cardVC.url_type = URL_NONE;
  532. cardVC.request_url=nil;
  533. }
  534. else
  535. {
  536. cardVC.url_type = URL_REMOTE;
  537. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  538. }
  539. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  540. params[@"orderCode"]=appDelegate.order_code;
  541. cardVC.params = params;
  542. cardVC.delegate = self;
  543. cardVC.from = indexPath;
  544. [self.navigationController pushViewController:cardVC animated:true];
  545. }
  546. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  547. {
  548. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  549. cvc.showNavibar = true;
  550. cvc.contact_type = value;
  551. __weak typeof(self) weakself = self;
  552. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  553. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  554. };
  555. [self.navigationController pushViewController:cvc animated:true];
  556. }
  557. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  558. {
  559. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  560. cvc.showNavibar = true;
  561. cvc.contact_type = value;
  562. __weak typeof(self) weakself = self;
  563. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  564. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  565. };
  566. [self.navigationController pushViewController:cvc animated:true];
  567. }
  568. else if([value isEqualToString:@"Sales_Order_Customer"])
  569. {
  570. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  571. cvc.contact_type = value;
  572. cvc.showNavibar = true;
  573. __weak typeof(self) weakself = self;
  574. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  575. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  576. };
  577. [self.navigationController pushViewController:cvc animated:true];
  578. }
  579. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  580. {
  581. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  582. cvc.showNavibar = true;
  583. cvc.contact_type = value;
  584. __weak typeof(self) weakself = self;
  585. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  586. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  587. };
  588. [self.navigationController pushViewController:cvc animated:true];
  589. }
  590. else if([value isEqualToString:@"Contact_Return_To"])
  591. {
  592. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  593. cvc.showNavibar = true;
  594. cvc.contact_type = value;
  595. __weak typeof(self) weakself = self;
  596. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  597. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  598. };
  599. [self.navigationController pushViewController:cvc animated:true];
  600. }
  601. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  602. {
  603. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  604. cvc.showNavibar = true;
  605. cvc.contact_type = value;
  606. __weak typeof(self) weakself = self;
  607. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  608. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  609. };
  610. [self.navigationController pushViewController:cvc animated:true];
  611. }
  612. }
  613. - (UIView *)createDemoView:(NSString*) msg
  614. {
  615. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  616. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  617. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  618. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  619. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  620. titleLabel.text=@"Order Submission";
  621. titleLabel.numberOfLines = 0;
  622. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  623. // titleLabel.textAlignment = NSTextAlignmentRight;
  624. titleLabel.textAlignment = NSTextAlignmentCenter;
  625. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  626. // CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  627. CGSize sizetitle = [RAUtils sizeWithFont:titleLabel.text=@"Order Submission" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  628. //[titleLabel sizeToFit];
  629. // titleLabel.center.x = demoView.center.x;
  630. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  631. [demoView addSubview:titleLabel];
  632. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  633. lineLabel.font = [UIFont systemFontOfSize:17];
  634. lineLabel.text=msg;
  635. lineLabel.numberOfLines = 0;
  636. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  637. // CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  638. CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  639. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  640. //[lineLabel sizeToFit];
  641. [demoView addSubview:lineLabel];
  642. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  643. return demoView;
  644. }
  645. -(float) getprice:(NSString*) name section :(long) index
  646. {
  647. NSMutableDictionary* section_json=nil;
  648. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  649. int count=0;
  650. count=[[section_json valueForKey:@"count"] intValue];
  651. for(int i=0;i<count;i++)
  652. {
  653. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  654. if([[olditem valueForKey:@"name"] isEqualToString:name])
  655. {
  656. return [[olditem valueForKey:@"value"] floatValue];
  657. }
  658. }
  659. return 0;
  660. }
  661. - (void)textFieldDidEndEditing:(UITextField *)textField
  662. {
  663. // [super textFieldDidEndEditing:textField];
  664. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  665. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  666. // table滑动后,cell可能会滚出table visible范围,此时indexPath为nil
  667. if (indexPath == nil) {
  668. indexPath = self.lastedit_from;
  669. }
  670. // 避免提前将lastedit_from置空
  671. [super textFieldDidEndEditing:textField];
  672. NSMutableDictionary* section_json=nil;
  673. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  674. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  675. NSString* name = [item_json valueForKey:@"name"];
  676. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  677. {
  678. float shipping = [self getprice:@"shipping" section:indexPath.section];
  679. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  680. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  681. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  682. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  683. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  684. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  685. int count=0;
  686. count=[[section_json valueForKey:@"count"] intValue];
  687. int total_row_idx=-1;
  688. for(int i=0;i<count;i++)
  689. {
  690. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  691. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ] || [[olditem valueForKey:@"name"] isEqualToString:@"totalPrice_a" ])
  692. {
  693. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  694. [olditem setValue:@"true" forKey:@"dirty"];
  695. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  696. total_row_idx=i;
  697. }
  698. }
  699. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  700. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  701. if(total_row_idx>=0)
  702. {
  703. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  704. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  705. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  706. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  707. }
  708. }
  709. }
  710. //
  711. //- (IBAction)onSaveClick:(id)sender {
  712. //
  713. // id a = nil;
  714. // NSMutableArray *arr = [NSMutableArray array];
  715. // [arr addObject:a];
  716. //
  717. // [self.lastedit endEditing:true];
  718. // [self.lasttextview endEditing:true];
  719. //
  720. // NSMutableDictionary* upparams = [self check_cancommit:false];
  721. //
  722. // if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  723. // upparams[@"shipping"] = nil;
  724. //
  725. //
  726. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order"];
  727. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  728. //
  729. // NSDictionary* editor_json = [RANetwork save_Order:upparams];
  730. //
  731. // dispatch_async(dispatch_get_main_queue(), ^{
  732. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  733. //
  734. //
  735. // if([[editor_json valueForKey:@"result"] intValue]==2)
  736. // {
  737. //
  738. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  739. //
  740. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  741. //
  742. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  743. // {
  744. // appDelegate.customerInfo = customerInfo;
  745. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  746. // }
  747. // NSString *msg = nil;
  748. // if ([editor_json objectForKey:@"so#"]) {
  749. // msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  750. // }
  751. // [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  752. //
  753. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  754. // {
  755. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  756. // [self prepareReturn:nil];
  757. // [self.navigationController popViewControllerAnimated:true];
  758. // }
  759. //
  760. // if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  761. //
  762. // if (![Singleton sharedInstance].currentOrderIsMerged) {
  763. // [self releaseOrderAfterSave];
  764. // }
  765. //
  766. //
  767. // }
  768. //
  769. // }
  770. // else
  771. // {
  772. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  773. // }
  774. //
  775. // });
  776. // });
  777. //
  778. //}
  779. - (void)releaseOrderAfterSave {
  780. dispatch_async(dispatch_get_main_queue(), ^{
  781. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  782. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
  783. [appDelegate closeOrder];
  784. [appDelegate SetSo:nil];
  785. appDelegate.cart_count=0;
  786. [appDelegate update_count_mark];
  787. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  788. [self prepareReturn:nil];
  789. [self.navigationController popToRootViewControllerAnimated:false];
  790. });
  791. //
  792. // [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  793. //
  794. // [appDelegate closeOrder];
  795. // [appDelegate SetSo:nil];
  796. // appDelegate.cart_count=0;
  797. // [appDelegate update_count_mark];
  798. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  799. //
  800. // [self prepareReturn:nil];
  801. // [self.navigationController popToRootViewControllerAnimated:false];
  802. }
  803. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  804. {
  805. NSString* ret=nil;
  806. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  807. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  808. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  809. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  810. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  811. if(customer_address1.length>0)
  812. [arraddr addObject:customer_address1];
  813. if(customer_address2.length>0)
  814. [arraddr addObject:customer_address2];
  815. if(customer_address3.length>0)
  816. [arraddr addObject:customer_address3];
  817. if(customer_address4.length>0)
  818. [arraddr addObject:customer_address4];
  819. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  820. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  821. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  822. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  823. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  824. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  825. if(customer_city.length>0)
  826. [arrcty addObject:customer_city];
  827. if(customer_state.length>0)
  828. [arrcty addObject:customer_state];
  829. if(customer_zipcode.length>0)
  830. [arrcty addObject:customer_zipcode];
  831. if(customer_country.length>0)
  832. [arrcty addObject:customer_country];
  833. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  834. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  835. if(addr_string.length>0)
  836. [arrext addObject:addr_string];
  837. if(cty_string.length>0)
  838. [arrext addObject:cty_string];
  839. ret = [arrext componentsJoinedByString:@"\r\n"];
  840. return ret;
  841. }
  842. -(NSMutableDictionary*)create_cusromer_info_from_table
  843. {
  844. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  845. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  846. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  847. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  848. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  849. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  850. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  851. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  852. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  853. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  854. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  855. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  856. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  857. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  858. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  859. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  860. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  861. NSString * firstname =nil;
  862. NSString* lastname = nil;
  863. NSString* contact_name = [self getValue:@"customer_contact"];
  864. if(contact_name!=nil)
  865. {
  866. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  867. if(_arr.count>=1)
  868. {
  869. firstname =_arr[0];
  870. if(_arr.count>1)
  871. {
  872. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  873. }
  874. }
  875. }
  876. [ret setValue:firstname forKey:@"customer_first_name"];
  877. [ret setValue:lastname forKey:@"customer_last_name"];
  878. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  879. return ret;
  880. }
  881. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  882. {
  883. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  884. NSArray *keys= [key_map allKeys];
  885. //遍历keys
  886. for(int i=0;i<[keys count];i++)
  887. {
  888. //得到当前key
  889. NSString *key=[keys objectAtIndex:i];
  890. //如果key不是pic,说明value是字符类型,比如name:Boris
  891. NSString* valuefrom = [key_map valueForKey:key];
  892. if(valuefrom.length==0)
  893. continue;
  894. NSString* value=[self getValue:valuefrom];
  895. [ret setValue:value forKey:valuefrom];
  896. }
  897. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  898. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  899. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  900. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  901. return ret;
  902. }
  903. #pragma mark - multi_action sub action clicked
  904. - (void)MActionClicked:(UIButton *)sender {
  905. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  906. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  907. int refresh =0;
  908. NSMutableDictionary* section_json=nil;
  909. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  910. NSString* subid=[item_json valueForKey:@"subid"];
  911. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  912. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  913. NSString* type = [sub_action valueForKey:@"type"];
  914. bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
  915. if([type isEqualToString:@"pull"])
  916. {
  917. [self.lastedit endEditing:true];
  918. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  919. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  920. NSMutableDictionary* value=[self create_value_map:keymap];
  921. if(subid==nil)
  922. {
  923. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  924. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  925. int icount=[[section_json valueForKey:@"count"] intValue];
  926. for (int ic=0;ic<icount;ic++)
  927. {
  928. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  929. NSString* mapto = [modify_item valueForKey:@"name"];
  930. if(mapto.length==0)
  931. continue;
  932. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  933. if(valuefrom==nil)
  934. continue;
  935. NSString* valuestr=[value valueForKey:valuefrom];
  936. // valuestr = [self getValue:valuefrom];
  937. if(true)
  938. {
  939. if(valuestr.length>0)
  940. [modify_item setValue:valuestr forKey:@"value"];
  941. else
  942. [modify_item setValue:@"" forKey:@"value"];
  943. [modify_item setValue:@"true" forKey:@"dirty"];
  944. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  945. }
  946. }
  947. }
  948. else
  949. {
  950. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  951. int section = [(NSString*)idarr[0] intValue];
  952. int item=[(NSString*)idarr[1] intValue];
  953. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  954. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  955. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  956. NSString* control_type = [olditem valueForKey:@"control"];
  957. if([control_type isEqualToString:@"switch"])
  958. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  959. else if([control_type isEqualToString:@"enum"])
  960. {
  961. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  962. }
  963. else
  964. {
  965. [RAUtils message_alert:@"not impl" title:@"Sorry" controller:self];
  966. // [RAUtils alert_view:@"" title:@"not impl"];
  967. }
  968. [olditem setValue:@"true" forKey:@"dirty"];
  969. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  970. }
  971. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  972. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  973. if(refresh==1)
  974. {
  975. // if(restore_json!=nil)
  976. // {
  977. // int rc=[[restore_json valueForKey:@"count"] intValue];
  978. // for(int ir=0;ir<rc;ir++)
  979. // {
  980. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  981. //
  982. //
  983. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  984. // for(int i=0;i<section_count;i++)
  985. // {
  986. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  987. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  988. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  989. // for(int j=0;j<item_count;j++)
  990. // {
  991. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  992. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  993. //
  994. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  995. // {
  996. // [itemjson removeObjectForKey:@"dirty"];
  997. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  998. // }
  999. //
  1000. // }
  1001. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1002. // }
  1003. //
  1004. //
  1005. // }
  1006. //
  1007. // }
  1008. [self refresh:refresh_trigger discardDirty:discardDirty];
  1009. return ;
  1010. }
  1011. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1012. [self.editorTable reloadData ];
  1013. }
  1014. else
  1015. {
  1016. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1017. NSDictionary * item_json = sub_action;
  1018. NSString* value = [item_json valueForKey:@"value"];
  1019. if([value isEqualToString:@"new_addr"])
  1020. {
  1021. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1022. addressVC.url_type = URL_REMOTE;
  1023. addressVC.request_url=URL_ADDRESS_EDOTOR;
  1024. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1025. // NSString * string = [checked componentsJoinedByString:@","];
  1026. // [params setValue:string forKey:@"cart2Checkbox"];
  1027. params[@"is_subaction"]=@"true";
  1028. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1029. addressVC.params = params;
  1030. addressVC.delegate = self;
  1031. addressVC.from = indexPath;
  1032. // orderinfoVC.params = params;
  1033. [self.navigationController pushViewController:addressVC animated:true];
  1034. }else if([value isEqualToString:@"credit_card"])
  1035. {
  1036. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1037. NSDictionary *data = [item_json objectForKey:@"data"];
  1038. if(data!=nil)
  1039. {
  1040. cardVC.content_data_download = [data mutableCopy];
  1041. cardVC.url_type = URL_NONE;
  1042. cardVC.request_url=nil;
  1043. }
  1044. else
  1045. {
  1046. cardVC.url_type = URL_REMOTE;
  1047. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  1048. }
  1049. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1050. params[@"orderCode"]=appDelegate.order_code;
  1051. params[@"is_subaction"]=@"true";
  1052. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1053. cardVC.params = params;
  1054. cardVC.delegate = self;
  1055. cardVC.from = indexPath;
  1056. // orderinfoVC.params = params;
  1057. [self.navigationController pushViewController:cardVC animated:true];
  1058. }
  1059. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  1060. {
  1061. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1062. cvc.showNavibar = true;
  1063. cvc.contact_type = value;
  1064. cvc.is_subaction = @"true";
  1065. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1066. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1067. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1068. //
  1069. // if(self.returnValue)
  1070. // self.returnValue(value);
  1071. };
  1072. [self.navigationController pushViewController:cvc animated:true];
  1073. }
  1074. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  1075. {
  1076. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1077. cvc.showNavibar = true;
  1078. cvc.contact_type = value;
  1079. cvc.is_subaction = @"true";
  1080. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1081. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1082. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1083. //
  1084. // if(self.returnValue)
  1085. // self.returnValue(value);
  1086. };
  1087. [self.navigationController pushViewController:cvc animated:true];
  1088. }
  1089. else if([value isEqualToString:@"Sales_Order_Customer"])
  1090. {
  1091. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1092. cvc.is_subaction = @"true";
  1093. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1094. cvc.showNavibar = true;
  1095. cvc.contact_type = value;
  1096. __weak typeof(self) weakself = self;
  1097. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1098. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1099. //
  1100. // if(self.returnValue)
  1101. // self.returnValue(value);
  1102. };
  1103. [self.navigationController pushViewController:cvc animated:true];
  1104. }
  1105. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  1106. {
  1107. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1108. cvc.showNavibar = true;
  1109. cvc.contact_type = value;
  1110. cvc.is_subaction = @"true";
  1111. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1112. __weak typeof(self) weakself = self;
  1113. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1114. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1115. //
  1116. // if(self.returnValue)
  1117. // self.returnValue(value);
  1118. };
  1119. [self.navigationController pushViewController:cvc animated:true];
  1120. }
  1121. else if([value isEqualToString:@"Contact_Return_To"])
  1122. {
  1123. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1124. cvc.is_subaction = @"true";
  1125. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1126. cvc.showNavibar = true;
  1127. cvc.contact_type = value;
  1128. __weak typeof(self) weakself = self;
  1129. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1130. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1131. //
  1132. // if(self.returnValue)
  1133. // self.returnValue(value);
  1134. };
  1135. [self.navigationController pushViewController:cvc animated:true];
  1136. }
  1137. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  1138. {
  1139. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1140. cvc.is_subaction = @"true";
  1141. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1142. cvc.showNavibar = true;
  1143. cvc.contact_type = value;
  1144. __weak typeof(self) weakself = self;
  1145. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1146. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1147. //
  1148. // if(self.returnValue)
  1149. // self.returnValue(value);
  1150. };
  1151. [self.navigationController pushViewController:cvc animated:true];
  1152. }
  1153. }
  1154. }
  1155. #pragma mark - Urgency
  1156. -(void) viewWillDisappear:(BOOL)animated
  1157. {
  1158. [super viewWillDisappear:animated];
  1159. [self cancel_urgency_timer];
  1160. }
  1161. - (void)start_urgency_timer {
  1162. if (!self.editable) {
  1163. return;
  1164. }
  1165. __weak typeof(self) weakSelf = self;
  1166. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1167. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  1168. __block NSString* labelsotext= mainVC.labelSo.text;
  1169. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  1170. #ifdef OFFLINE_MODE
  1171. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  1172. #endif
  1173. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  1174. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  1175. // DebugLog(@"timer start....");
  1176. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1177. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  1178. if ([weakSelf.class_name isEqualToString:@"RAOrderEditorViewController"]) {
  1179. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  1180. NSString *so = [labelsotext substringFromIndex:5];
  1181. [urgencyDic setValue:so forKey:@"order_so"];
  1182. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  1183. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  1184. // page
  1185. [urgencyDic setObject:@(weakSelf.pageIndex) forKey:@"page_index"];
  1186. [urgencyDic setObject:weakSelf.pageContentDownloadArray forKey:@"download_content_array"];
  1187. [urgencyDic setObject:weakSelf.pageContentControlArray forKey:@"control_content_array"];
  1188. [urgencyDic setObject:weakSelf.pageChangeDataArray forKey:@"changed_data_array"];
  1189. [urgencyDic setObject:weakSelf.pageUpParams forKey:@"up_param_array"];
  1190. [urgencyDic setObject:weakSelf.request_url forKey:@"request_url"];
  1191. [urgencyDic setObject:weakSelf.params forKey:@"params"];
  1192. }
  1193. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  1194. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  1195. }];
  1196. }
  1197. - (void)cancel_urgency_timer {
  1198. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  1199. }
  1200. - (void)recoveryFromUrgencyDic:(NSDictionary *)urgencyDic {
  1201. self.disable_dropdown_refresh=true;
  1202. self.url_type = URL_RESTORE;
  1203. self.params = [NSMutableDictionary dictionary];
  1204. self.content_data_download = [urgencyDic objectForKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1205. self.resumeOrder = YES;
  1206. self.pageIndex = [[urgencyDic objectForKey:@"page_index"] integerValue];
  1207. self.pageContentDownloadArray = [urgencyDic objectForKey:@"download_content_array"];
  1208. self.pageContentControlArray = [urgencyDic objectForKey:@"control_content_array"];
  1209. self.pageChangeDataArray = [urgencyDic objectForKey:@"changed_data_array"];
  1210. self.pageUpParams = [urgencyDic objectForKey:@"up_param_array"];
  1211. self.request_url = [urgencyDic objectForKey:@"request_url"];
  1212. self.params = [urgencyDic objectForKey:@"params"];
  1213. }
  1214. @end