OrderListViewController.m 43 KB

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