OrderListViewController.m 39 KB

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