OrderListViewController.m 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  1. //
  2. // OrderListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/18/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OrderListViewController.h"
  9. #import "OrderListTableViewCell.h"
  10. #import "iSalesNetwork.h"
  11. #import "OrderDetailViewController.h"
  12. #import "MainViewController.h"
  13. #import "ContactListViewController.h"
  14. #import "DefaultAppearance.h"
  15. #import "DefaultTableHeaderView.h"
  16. #import "SelectUploadOrderViewController.h"
  17. @interface OrderListViewController ()
  18. @property (nonatomic,strong) NSMutableArray *mergeList;
  19. @property (strong, nonatomic) IBOutlet UIButton *mergeListButton;
  20. @end
  21. @implementation OrderListViewController
  22. - (NSMutableArray *)mergeList {
  23. if (!_mergeList) {
  24. _mergeList = [NSMutableArray array];
  25. }
  26. return _mergeList;
  27. }
  28. -(void) logout
  29. {
  30. self.offset = 0;
  31. [self.content_data removeAllObjects];
  32. [self.table_order reloadData];
  33. self.status_cadedate = nil;
  34. }
  35. -(void) reload_container_getdata:(bool) update_data
  36. {
  37. [super reload_container_getdata:update_data];
  38. if(update_data)
  39. {
  40. // self.offset = 0;
  41. // [self.content_data removeAllObjects];
  42. self.reset_result=true;
  43. self.norefresh=true;
  44. [self loadpage];
  45. }
  46. else
  47. {
  48. [self.table_order reloadData];
  49. }
  50. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  51. if(appDelegate.can_create_order)
  52. {
  53. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  54. self.btn_newOrder.enabled = true;
  55. }
  56. else
  57. {
  58. [self.btn_newOrder setImage:nil];
  59. self.btn_newOrder.enabled = false;
  60. }
  61. }
  62. -(void) showHidePrice
  63. {
  64. [self reload_container_getdata:false];
  65. }
  66. - (void)viewDidLoad {
  67. [super viewDidLoad];
  68. self.edgesForExtendedLayout = UIRectEdgeNone;
  69. self.loading_queue = dispatch_queue_create("orderlist_loading", NULL);
  70. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  71. self.label_net_err.layer.borderWidth = 2.0;
  72. self.label_net_err.layer.cornerRadius=15;
  73. self.label_net_err.layer.masksToBounds=true;
  74. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  75. // tap.minimumPressDuration = 0.8; //定义按的时间
  76. [self.label_net_err addGestureRecognizer:tap];
  77. // Do any additional setup after loading the view.
  78. self.offset = 0;
  79. self.limit = 25;
  80. self.content_data = [[NSMutableArray alloc]init];
  81. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  82. ref.tag = 201 ;
  83. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  84. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  85. // ref.hidden = true;
  86. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  87. [self.table_order addSubview:ref];
  88. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  89. // NSString *documents = [paths objectAtIndex:0];
  90. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  91. // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  92. //
  93. // NSLog(@"文件已经存在了");
  94. //
  95. // }
  96. // else
  97. // {
  98. //
  99. //
  100. //
  101. // // NSLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  102. //
  103. // NSData *mainBundleFile = [NSData dataWithContentsOfFile:order_filter_source_path];
  104. //
  105. // // NSLog(@"mainBundleFile==%@",mainBundleFile);
  106. //
  107. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  108. //
  109. // contents:mainBundleFile
  110. //
  111. // attributes:nil];
  112. //
  113. // }
  114. [self loadfilter];
  115. }
  116. -(void) loadfilter
  117. {
  118. if(self.status_cadedate!=nil)
  119. return;
  120. UIApplication * app = [UIApplication sharedApplication];
  121. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  122. NSData* json =nil;
  123. if(self.init_style==OL_OPEN)
  124. {
  125. json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  126. NSError *error=nil;
  127. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  128. }
  129. else
  130. {
  131. // json=//[NSData dataWithContentsOfFile:dist_path];
  132. // NSError *error=nil;
  133. self.status_cadedate = appDelegate.OrderFilter;//[[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  134. }
  135. }
  136. - (IBAction)onCancel:(id)sender {
  137. if(self.onCancel)
  138. self.onCancel();
  139. [self.navigationController popViewControllerAnimated:false];
  140. }
  141. - (IBAction)onStatusFilterClick:(id)sender {
  142. EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  143. enumvc.delegate = self;
  144. enumvc.max_select = 0;
  145. //enumvc.updatePosition = indexPath;
  146. // if([[required lowercaseString] isEqualToString:@"true"])
  147. // enumvc.canbeEmpty = false;
  148. // else
  149. // enumvc.canbeEmpty =true;
  150. enumvc.cadedate = self.status_cadedate ;
  151. enumvc.title = @"Order Status Selection";
  152. // enumvc.value = [value_json mutableCopy];
  153. enumvc.single_select =false;
  154. [self.navigationController pushViewController:enumvc animated:true];
  155. }
  156. - (void)viewWillAppear:(BOOL)animated
  157. {
  158. [super viewWillAppear:animated];
  159. [self loadfilter];
  160. // [self ReloadData]; // 保存新订单后返回没刷新
  161. // UIApplication * app = [UIApplication sharedApplication];
  162. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  163. // if(appDelegate.bLogin==false)
  164. // {
  165. // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  166. //// loginvc.delegate = self;
  167. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  168. //
  169. // loginvc.returnValue = ^(bool blogin){
  170. //
  171. //
  172. // UIApplication * app = [UIApplication sharedApplication];
  173. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  174. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  175. //
  176. // [main_vc checklogin:true];
  177. //
  178. //// self.offset = 0;
  179. //// [self.content_data removeAllObjects];
  180. //// [self loadpage];
  181. //
  182. // [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  183. //
  184. // };
  185. //
  186. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  187. //
  188. //
  189. //
  190. //
  191. //
  192. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  193. //
  194. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  195. // [self presentViewController:navi animated:YES completion:^{
  196. //
  197. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  198. //
  199. // NSLog(@"LoginViewController present.........");
  200. //
  201. // // self.btop = false;
  202. // // <#code#>
  203. // }];
  204. // }
  205. // else
  206. // {
  207. //
  208. // if(!self.norefresh)//避免 多次刷新
  209. // {
  210. // self.norefresh = true;
  211. // self.offset = 0;
  212. // [self.content_data removeAllObjects];
  213. // [self loadpage];
  214. //
  215. // }
  216. //
  217. // }
  218. [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  219. }
  220. - (IBAction)onNewOrderClicked:(id)sender {
  221. NSString* msg=@"Do you want to create a new order?";
  222. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  223. if(appDelegate.order_code.length==0)
  224. {
  225. if(appDelegate.contact_id.length>0)
  226. {
  227. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  228. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  229. }
  230. }
  231. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Attention", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  232. [alert show];
  233. }
  234. - (void)didReceiveMemoryWarning {
  235. [super didReceiveMemoryWarning];
  236. // Dispose of any resources that can be recreated.
  237. }
  238. -(void)manually_refresh
  239. {
  240. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  241. if(self.isrefreshing)
  242. {
  243. [reF endRefreshing];
  244. return;
  245. }
  246. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  247. if ([self respondsToSelector:@selector(ReloadData)])
  248. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  249. }
  250. -(void)ReloadData
  251. {
  252. // [self.content_data removeAllObjects];
  253. // [self.table_order reloadData];
  254. // self.table_order.hidden = true;
  255. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  256. [reF endRefreshing];
  257. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  258. self.keywords=self.searchbar.text;
  259. // self.offset = 0;
  260. self.reset_result=true;
  261. // [self.content_data removeAllObjects];
  262. // [self.table_order reloadData];
  263. [self loadpage];
  264. // [self loadpage];
  265. }
  266. -(void) loadpage
  267. {
  268. dispatch_async(self.loading_queue, ^{
  269. dispatch_sync(dispatch_get_main_queue(), ^{
  270. if(self.reset_result)
  271. {
  272. self.offset = 0;
  273. [self.content_data removeAllObjects];
  274. [self.table_order reloadData];
  275. }
  276. // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  277. NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  278. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  279. for(int i=0;i<count;i++)
  280. {
  281. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  282. int check = [[val_json valueForKey:@"check"] intValue];
  283. if(check==1)
  284. {
  285. // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  286. [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  287. // break;
  288. }
  289. }
  290. // NSString * str_status = [arr_status componentsJoinedByString:@","];
  291. NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
  292. if(str_statusname.length==0)
  293. str_statusname = @"All";
  294. self.label_filter.text = str_statusname;
  295. if(self.offset==0)
  296. {
  297. self.table_order.hidden = true;
  298. self.mum.center = self.view.center;
  299. self.mum.hidden = false;
  300. [self.mum startAnimating];
  301. }
  302. self.label_net_err.hidden=true;
  303. });
  304. });
  305. dispatch_async(self.loading_queue, ^{
  306. if(self.isrefreshing)
  307. return;
  308. self.isrefreshing=true;
  309. NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  310. // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  311. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  312. for(int i=0;i<count;i++)
  313. {
  314. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  315. int check = [[val_json valueForKey:@"check"] intValue];
  316. if(check==1)
  317. {
  318. [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  319. // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  320. // break;
  321. }
  322. }
  323. NSString * str_status = [arr_status componentsJoinedByString:@","];
  324. NSMutableDictionary* content=nil;
  325. content=[[iSalesNetwork request_OrderList:self.offset limit : self.limit keywords:self.keywords status:str_status customer:self.customer_id] mutableCopy];
  326. dispatch_sync(dispatch_get_main_queue(), ^{
  327. [self.mum stopAnimating];
  328. int result=[[content valueForKey:@"result"] intValue];
  329. if(result==2||result==0)
  330. {
  331. int count = [[content valueForKey:@"count" ] intValue] ;
  332. self.time_zone = [content valueForKey:@"time_zone" ];
  333. self.offset += count;
  334. for(int i=0;i<count;i++)
  335. {
  336. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  337. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  338. }
  339. if(count<self.limit)
  340. {
  341. // int i =self.btnrefresh.state;
  342. self.load_more_hint=@"All loaded";
  343. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  344. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  345. }
  346. else
  347. {
  348. self.load_more_hint=@"Load more...";
  349. // self.btnrefresh.enabled = true;
  350. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  351. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  352. }
  353. self.table_order.hidden = false;
  354. self.reset_result=false;
  355. [self.table_order reloadData ];
  356. }
  357. else if(result==RESULT_NET_ERROR &&self.offset==0)
  358. {
  359. self.label_net_err.hidden=false;
  360. self.table_order.hidden = true;
  361. }
  362. else
  363. {
  364. [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Order List" controller:self] ;
  365. }
  366. self.isrefreshing=false;
  367. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  368. // bool autologin =[defaults boolForKey:@"autologin"];
  369. // if(!autologin)
  370. // {
  371. // TabBarController * viewController =[self.storyboard instantiateViewControllerWithIdentifier:@"LoginTabBar"];
  372. // [self presentViewController:viewController animated:YES completion:^{
  373. //
  374. // }];
  375. // }
  376. });
  377. });
  378. }
  379. - (void)loadmore
  380. {
  381. // self.btnrefresh.enabled = NO;
  382. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  383. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  384. [self loadpage];
  385. }
  386. //-(void)changeCell
  387. //{
  388. //// UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  389. //// reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  390. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  391. // DebugLog(@"refresh!!!!!!!!");
  392. //
  393. //}
  394. -(void) neworder
  395. {
  396. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  397. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  398. NSDictionary* return_json = [iSalesNetwork new_Order];
  399. dispatch_async(dispatch_get_main_queue(), ^{
  400. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  401. if([[return_json valueForKey:@"result"] intValue]==2)
  402. {
  403. int result=[[return_json valueForKey:@"result"] intValue];
  404. if(result==2)
  405. {
  406. //successed.
  407. NSString* order_code = [return_json valueForKey:@"orderCode"];
  408. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  409. appDelegate.order_code = order_code;
  410. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  411. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  412. [main_vc reloadCart:true immediately:false];
  413. [self ReloadData];
  414. // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  415. // [self loadpage];
  416. // if(self.shopCartBlock!=nil)
  417. // {
  418. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  419. //
  420. //
  421. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  422. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  423. // iv.image = img;
  424. // // [self.contentView addSubview:iv];
  425. // self.shopCartBlock(iv);
  426. //
  427. // }
  428. }
  429. }
  430. else
  431. {
  432. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  433. }
  434. });
  435. });
  436. }
  437. #pragma mark - UIAlertViewDelegate
  438. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  439. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  440. {
  441. if(buttonIndex!=alertView.cancelButtonIndex)
  442. {
  443. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  444. if(appDelegate.order_code && appDelegate.order_code.length>0)
  445. {
  446. appDelegate.order_code= nil;
  447. [appDelegate SetSo:nil];
  448. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) {
  449. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  450. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  451. cvc.showNavibar = true;
  452. cvc.contact_type = @"Sales_Order_Customer";
  453. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  454. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  455. appDelegate.customerInfo = value;
  456. self.norefresh = true;
  457. [self neworder];
  458. // [main_vc checklogin:true];
  459. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  460. //
  461. // if(self.returnValue)
  462. // self.returnValue(value);
  463. };
  464. cvc.onCancel = ^(){
  465. self.norefresh = true;
  466. if(appDelegate.customerInfo==nil)
  467. {
  468. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  469. }
  470. else
  471. {
  472. [self neworder];
  473. }
  474. // [main_vc checklogin:true];
  475. };
  476. cvc.onReset = ^(){
  477. // [main_vc checklogin:true];
  478. };
  479. [self.navigationController pushViewController:cvc animated:true];
  480. }
  481. else if (appDelegate.user_type == USER_ROLE_CUSTOMER){
  482. [self neworder];
  483. }
  484. }
  485. else
  486. {
  487. //create new;
  488. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  489. {
  490. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  491. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  492. cvc.showNavibar = true;
  493. cvc.contact_type = @"Sales_Order_Customer";
  494. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  495. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  496. appDelegate.customerInfo = value;
  497. if(appDelegate.order_code==nil)
  498. [self neworder];
  499. // [main_vc checklogin:true];
  500. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  501. //
  502. // if(self.returnValue)
  503. // self.returnValue(value);
  504. };
  505. cvc.onCancel = ^(){
  506. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  507. };
  508. cvc.onReset = ^(){
  509. [main_vc checklogin:true];
  510. };
  511. [self.navigationController pushViewController:cvc animated:true];
  512. }
  513. else
  514. {
  515. [self neworder];
  516. }
  517. }
  518. }
  519. }
  520. #pragma mark - Table view data source
  521. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  522. {
  523. return 66;
  524. }
  525. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  526. //{
  527. // return 0;
  528. //}
  529. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  530. //{
  531. // return 0;
  532. //}
  533. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  534. //{
  535. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  536. // return myView;
  537. //
  538. //}
  539. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  540. {
  541. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  542. if(value==nil)
  543. value=@"";
  544. unsigned long color = strtoul([value UTF8String],0,16);
  545. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  546. // myView.backgroundColor = UIColorFromRGB(0x996633);
  547. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  548. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  549. myView.layer.shadowOffset = CGSizeMake(0, 0);
  550. myView.layer.shadowOpacity = 0.5;
  551. myView.layer.shadowRadius = 2.0;
  552. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 2, 130, 22)];
  553. statuslabel.textColor=UIColorFromRGB(color);
  554. statuslabel.backgroundColor = [UIColor clearColor];
  555. statuslabel.text=NSLocalizedString(@"Status", nil);
  556. [statuslabel sizeToFit];
  557. [myView addSubview:statuslabel];
  558. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  559. solabel.textColor=UIColorFromRGB(color);
  560. solabel.backgroundColor = [UIColor clearColor];
  561. solabel.text=NSLocalizedString(@"SO#", nil);
  562. [solabel sizeToFit];
  563. [myView addSubview:solabel];
  564. UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 2, 135, 22)];
  565. userlabel.textColor=UIColorFromRGB(color);
  566. userlabel.backgroundColor = [UIColor clearColor];
  567. userlabel.text=NSLocalizedString(@"Sales rep", nil);
  568. [userlabel sizeToFit];
  569. [myView addSubview:userlabel];
  570. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 21, 135, 22)];
  571. creatorlabel.textColor=UIColorFromRGB(color);
  572. creatorlabel.backgroundColor = [UIColor clearColor];
  573. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  574. [creatorlabel sizeToFit];
  575. [myView addSubview:creatorlabel];
  576. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 11, 150, 22)];
  577. contactlabel.textColor=UIColorFromRGB(color);
  578. contactlabel.backgroundColor = [UIColor clearColor];
  579. contactlabel.text=NSLocalizedString(@"Contact", nil);
  580. [contactlabel sizeToFit];
  581. [myView addSubview:contactlabel];
  582. //
  583. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  584. // modellabel.textColor=[UIColor whiteColor];
  585. // modellabel.backgroundColor = [UIColor clearColor];
  586. // modellabel.text=NSLocalizedString(@"Model", nil);
  587. // [modellabel sizeToFit];
  588. // [myView addSubview:modellabel];
  589. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  590. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  591. // modellabel.textColor=[UIColor whiteColor];
  592. // modellabel.backgroundColor = [UIColor clearColor];
  593. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  594. // [modellabel sizeToFit];
  595. // [myView addSubview:modellabel];
  596. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  597. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  598. pricelabel.textColor=UIColorFromRGB(color);
  599. pricelabel.backgroundColor = [UIColor clearColor];
  600. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  601. [pricelabel sizeToFit];
  602. [myView addSubview:pricelabel];
  603. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  604. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  605. timelabel.textColor=UIColorFromRGB(color);
  606. timelabel.backgroundColor = [UIColor clearColor];
  607. if(self.time_zone==nil)
  608. timelabel.text=@"Create time";
  609. else
  610. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  611. [timelabel sizeToFit];
  612. [myView addSubview:timelabel];
  613. myView.autoresizesSubviews=true;
  614. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  615. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  616. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  617. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  618. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  619. //
  620. return myView;
  621. }
  622. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  623. {
  624. return 44;
  625. }
  626. //
  627. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  628. // if(section==0)
  629. // return nil;
  630. // else
  631. // return @"detail section";
  632. //}
  633. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  634. {
  635. return 1;
  636. }
  637. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  638. {
  639. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  640. if( self.content_data.count==0)
  641. return 0;
  642. return self.content_data.count+1;
  643. }
  644. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  645. {
  646. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  647. // if(tableView==self.itemListTable)
  648. // {
  649. // if(indexPath.row>self.content_data.count)
  650. // {
  651. // int debug=true;
  652. // }
  653. // NSLog(@"row %ld",(long)indexPath.row);
  654. if(indexPath.row==self.content_data.count)
  655. {
  656. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  657. UILabel *moreDataLabel=[[UILabel alloc] init];
  658. moreDataLabel.tag=200;
  659. moreDataLabel.text=self.load_more_hint;
  660. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  661. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  662. moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20);
  663. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  664. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  665. [moreCell.contentView addSubview:moreDataLabel];
  666. if([self.load_more_hint isEqualToString:@"Load more..."])
  667. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  668. // NSLog(@"更多...");
  669. moreCell.backgroundColor = [UIColor whiteColor];
  670. return moreCell;
  671. }
  672. else
  673. {
  674. NSString *CellIdentifier = @"OrderListTableViewCell";
  675. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  676. NSString* po= [self.content_data[indexPath.row] valueForKey:@"so#"];
  677. NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"];
  678. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  679. {
  680. }
  681. else
  682. {
  683. price=nil;
  684. }
  685. NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  686. NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ;
  687. NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"];
  688. NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"];
  689. NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"];
  690. NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  691. cell.label_so.text=po;
  692. cell.labelprice.text=price;
  693. cell.label_date.text=purchase_time;
  694. cell.label_contact.text=customer_name;
  695. cell.label_model.text = model_count;
  696. cell.label_sales.text = sales;
  697. cell.label_creator.text = creator;
  698. cell.label_status.text=status;
  699. cell.backgroundColor = [UIColor whiteColor];
  700. return cell;
  701. }
  702. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  703. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  704. // cell.bundle_item=combine_json;
  705. // NSString* img_url = [item_json valueForKey:@"img_url"];
  706. // NSString* description = [item_json valueForKey:@"description"];
  707. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  708. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  709. // NSString* currency = [item_json valueForKey:@"currency"];
  710. // int count =[[item_json valueForKey:@"count"] intValue];
  711. // double price =[[item_json valueForKey:@"price"] doubleValue];
  712. // // cell.labelAttribute.text = attribute;
  713. // cell.labelCurrency.text = currency;
  714. // cell.labelDescription.text = description;
  715. // // cell.labelIdentifier.text = identifier;
  716. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
  717. //
  718. //
  719. //
  720. // [cell set_Count:count];
  721. // NSString* file_name=[img_url lastPathComponent];
  722. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  723. // if(img_data!=nil)
  724. // {
  725. //
  726. // UIImage * img =[UIImage imageWithData:img_data];
  727. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  728. // }
  729. // else
  730. // {
  731. //
  732. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  733. //
  734. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  735. //
  736. // dispatch_async(dispatch_get_main_queue(), ^{
  737. //
  738. //
  739. //
  740. // if(downloadimg_data!=nil)
  741. // {
  742. // [iSalesDB cache_img:downloadimg_data :file_name ];
  743. //
  744. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  745. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  746. // }
  747. //
  748. // });
  749. // });
  750. //
  751. //
  752. // }
  753. // }
  754. // else
  755. // {
  756. // NSString *CellIdentifier = @"OrderInfoListItem";
  757. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  758. // return cell;
  759. // }
  760. }
  761. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  762. {
  763. //
  764. if(indexPath.row==self.content_data.count)
  765. return;
  766. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  767. OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  768. // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
  769. dvc.selectOrder=^(NSMutableDictionary* order_detail){
  770. [self.navigationController popViewControllerAnimated:false];
  771. if(self.selectOrder)
  772. self.selectOrder(order_detail);
  773. };
  774. NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
  775. dvc.order_code = order_code;
  776. dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
  777. // bool temp_order = false ;
  778. // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
  779. // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
  780. // temp_order=true;
  781. //
  782. // dvc.isTempOrder = temp_order;
  783. // dvc
  784. dvc.orderid=orderid;
  785. // dvc.category_id=nil;
  786. // dvc.ispush=true;
  787. // [dvc reload];
  788. [self.navigationController pushViewController:dvc animated:true];
  789. }
  790. #pragma mark - searchBar delegate;
  791. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  792. {
  793. self.keywords=searchBar.text;
  794. // self.offset = 0;
  795. // [self.content_data removeAllObjects];
  796. self.reset_result=true;
  797. [self loadpage];
  798. }
  799. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  800. {
  801. if([searchText isEqualToString:@""] && !self.reset)
  802. {
  803. NSLog(@"clear");
  804. self.reset=true;
  805. self.keywords=nil;
  806. // self.offset = 0;
  807. // [self.content_data removeAllObjects];
  808. self.reset_result=true;
  809. [self loadpage];
  810. }
  811. else
  812. self.reset = false;
  813. }
  814. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  815. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  816. {
  817. // 添加一个删除按钮
  818. // self.indexPath=indexPath;
  819. if(indexPath.row==self.content_data.count)
  820. return @[];
  821. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  822. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  823. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  824. NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  825. if(appDelegate.user_type==USER_ROLE_EMPLOYEE) {
  826. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  827. NSLog(@"delete click");
  828. NSString * title =[NSString stringWithFormat:@"Are you sure to delete order SO#: %@",so];
  829. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  830. //block代码块取代了delegate
  831. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  832. // textField.text = self.save_name;
  833. //
  834. //
  835. // }];
  836. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  837. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Delete Order"];
  838. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  839. NSDictionary* return_json = [iSalesNetwork delete_Order:orderid];
  840. dispatch_async(dispatch_get_main_queue(), ^{
  841. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  842. if([[return_json valueForKey:@"result"] intValue]==2)
  843. {
  844. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  845. {
  846. appDelegate.order_code= nil;
  847. [appDelegate SetSo:nil];
  848. }
  849. [RAUtils message_alert:nil title:@"Order Delete" controller:self] ;
  850. [self ReloadData];
  851. }
  852. else
  853. {
  854. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order" controller:self] ;
  855. }
  856. });
  857. });
  858. }];
  859. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  860. NSLog(@"Cancel");
  861. }];
  862. [alertControl addAction:actionOne];
  863. [alertControl addAction:alertthree];
  864. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  865. [self presentViewController:alertControl animated:YES completion:nil];
  866. }];
  867. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  868. // 添加一个编辑按钮
  869. UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  870. NSLog(@"edit click");
  871. NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
  872. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  873. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  874. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Cancel Order"];
  875. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  876. NSDictionary* return_json = [iSalesNetwork cancel_Order:orderid order_code:nil];
  877. dispatch_async(dispatch_get_main_queue(), ^{
  878. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  879. if([[return_json valueForKey:@"result"] intValue]==2)
  880. {
  881. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  882. {
  883. appDelegate.order_code= nil;
  884. appDelegate.user_type = 0;
  885. appDelegate.customerInfo = nil;
  886. appDelegate.contact_id = nil;
  887. appDelegate.order_customer_id = nil;
  888. [appDelegate SetSo:nil];
  889. appDelegate.cart_count=0;
  890. [appDelegate update_count_mark];
  891. }
  892. [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  893. [self ReloadData];
  894. }
  895. else
  896. {
  897. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  898. }
  899. });
  900. });
  901. }];
  902. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  903. NSLog(@"Cancel");
  904. }];
  905. [alertControl addAction:actionOne];
  906. [alertControl addAction:alertthree];
  907. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  908. [self presentViewController:alertControl animated:YES completion:nil];
  909. //
  910. }];
  911. cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
  912. if([order_status isEqualToString:@"Saved Order"]&&appDelegate.can_cancel_order)
  913. return @[cancelAction];
  914. else
  915. {
  916. if([order_status isEqualToString:@"Quote Saved"])
  917. {
  918. NSMutableArray* arr=[@[] mutableCopy];
  919. if(appDelegate.can_delete_order)
  920. [arr addObject:deleteRowAction];
  921. if(appDelegate.can_cancel_order)
  922. [arr addObject:cancelAction];
  923. return arr;
  924. }
  925. }
  926. } else if (appDelegate.user_type==USER_ROLE_CUSTOMER) {
  927. UITableViewRowAction *add2MergeListAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Add To MergeList" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  928. NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  929. NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"];
  930. __block BOOL contain = NO;
  931. [self.mergeList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  932. NSString *so_id = [(NSDictionary *)obj objectForKey:@"so_id"];
  933. if ([so_id isEqualToString:so]) {
  934. contain = YES;
  935. *stop = YES;
  936. }
  937. }]; // 避免重复添加
  938. if (!contain) {
  939. // 锁订单
  940. NSDictionary *lock_dic = [iSalesNetwork open_Order:orderCode];
  941. if ([[lock_dic objectForKey:@"result"] integerValue] == RESULT_TRUE) {
  942. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  943. [dic setValue:orderid forKey:@"order_id"];
  944. [dic setValue:so forKey:@"so_id"];
  945. [dic setValue:customer_name forKey:@"company_name"];
  946. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  947. [self.mergeList addObject:dic];
  948. } else {
  949. [RAUtils message_alert:[lock_dic objectForKey:@"err_msg"] title:nil controller:self];
  950. }
  951. }
  952. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationFade];
  953. DebugLog(@"%@",self.mergeList);
  954. }];
  955. add2MergeListAction.backgroundColor = UIColorFromRGB(0x336699);
  956. return @[add2MergeListAction];
  957. }
  958. return @[];
  959. }
  960. - (void)tableView:(UITableView *)tableView
  961. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  962. }
  963. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  964. if(indexPath.row==self.content_data.count)
  965. return UITableViewCellEditingStyleNone;
  966. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  967. bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue];
  968. NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  969. if(![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"])
  970. return UITableViewCellEditingStyleNone;
  971. else
  972. {
  973. if(appDelegate.offline_mode==false||offline_edit)
  974. return UITableViewCellEditingStyleDelete;
  975. else
  976. return UITableViewCellEditingStyleNone;
  977. }
  978. }
  979. /*
  980. #pragma mark - Navigation
  981. // In a storyboard-based application, you will often want to do a little preparation before navigation
  982. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  983. // Get the new view controller using [segue destinationViewController].
  984. // Pass the selected object to the new view controller.
  985. }
  986. */
  987. #pragma mark EnumSelectViewControllerDelegate
  988. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  989. {
  990. self.status_cadedate = value;
  991. UIApplication * app = [UIApplication sharedApplication];
  992. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  993. appDelegate.OrderFilter = value;
  994. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  995. // NSString *documents = [paths objectAtIndex:0];
  996. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  997. //
  998. //
  999. // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  1000. // //
  1001. // // NSLog(@"文件已经存在了");
  1002. // //
  1003. // // }
  1004. // // else
  1005. // // {
  1006. // //
  1007. // //
  1008. // //
  1009. // // NSLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  1010. //
  1011. //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil];
  1012. //
  1013. // // NSLog(@"mainBundleFile==%@",mainBundleFile);
  1014. //
  1015. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  1016. //
  1017. // contents:data
  1018. //
  1019. // attributes:nil];
  1020. //
  1021. // }
  1022. // self.keywords=searchBar.text;
  1023. // self.offset = 0;
  1024. // [self.content_data removeAllObjects];
  1025. self.reset_result=true;
  1026. [self loadpage];
  1027. //[self.btnStatusFilter setTitle:setTitle:alert ];
  1028. }
  1029. #pragma mark - button action
  1030. - (IBAction)mergeListButtonClick:(UIButton *)sender {
  1031. if (!self.mergeList.count) {
  1032. [RAUtils message_alert:@"Merge List is Empty" title:nil controller:self];
  1033. return;
  1034. }
  1035. SelectUploadOrderViewController *mergeVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SelectUploadOrderViewController"];
  1036. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mergeVC];
  1037. mergeVC.mergeList = self.mergeList;
  1038. mergeVC.title = @"Merge List";
  1039. __weak typeof(self) weakself = self;
  1040. mergeVC.mergeBlock = ^(NSDictionary *ret) {
  1041. DebugLog(@"merge order return: %@",ret);
  1042. if (weakself) {
  1043. __strong typeof(weakself) strongself = weakself;
  1044. if([[ret objectForKey:@"result"]integerValue] == RESULT_TRUE) {
  1045. [weakself.mergeList removeAllObjects];
  1046. [strongself loadpage];
  1047. } else {
  1048. NSString *msg = [ret objectForKey:@"err_msg"];
  1049. [RAUtils message_alert:msg title:nil controller:strongself];
  1050. }
  1051. }
  1052. };
  1053. nav.modalPresentationStyle = UIModalPresentationFormSheet;
  1054. [self presentViewController:nav animated:YES completion:nil];
  1055. }
  1056. @end