ContactListViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. //
  2. // ContactListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/29/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ContactListViewController.h"
  9. #import "iSalesNetwork.h"
  10. #import "ContactListTableViewCell.h"
  11. #import "CustomerEditViewController.h"
  12. #import "ContactAdvanceSearchViewController.h"
  13. #define DEF_CELL_HEIGHT 44
  14. //#define DEF_TABLE_HEIGHT 44
  15. //#define LINE_WIDTH 0
  16. //#define CELL_MARGIN 0
  17. #define LABEL_MARGIN 15
  18. @interface ContactListViewController ()
  19. @end
  20. @implementation ContactListViewController
  21. - (void)awakeFromNib {
  22. self.edit_icon = true;
  23. self.assig_icon = true;
  24. self.reset_icon=false;
  25. }
  26. -(void) logout
  27. {
  28. self.offset = 0;
  29. [self.content_data removeAllObjects];
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  34. self.label_net_err.layer.borderWidth = 2.0;
  35. self.label_net_err.layer.cornerRadius=15;
  36. self.label_net_err.layer.masksToBounds=true;
  37. self.edgesForExtendedLayout = UIRectEdgeNone;
  38. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  39. // tap.minimumPressDuration = 0.8; //定义按的时间
  40. [self.label_net_err addGestureRecognizer:tap];
  41. // Do any additional setup after loading the view.
  42. self.offset = 0;
  43. self.limit = 25;
  44. self.content_data = [[NSMutableArray alloc]init];
  45. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  46. ref.tag = 201 ;
  47. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  48. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  49. // ref.hidden = true;
  50. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  51. [self.table addSubview:ref];
  52. self.reset = false;
  53. //// UILabel* titleLabel= [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 100
  54. //
  55. // , 44)];
  56. // titleLabel.text=@"Contacts";
  57. // // titleLabel.backgroundColor =[UIColor yellowColor];
  58. // titleLabel.textAlignment=NSTextAlignmentCenter;
  59. // // [titleLabel sizeToFit];
  60. //
  61. // //将搜索条放在一个UIView上
  62. // // UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1768, 44)];
  63. //
  64. //
  65. //
  66. //
  67. // searchView.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth;
  68. //
  69. // titleLabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
  70. // titleLabel.center=searchView.center;
  71. //
  72. //
  73. //
  74. // self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(searchView.frame.size.width-200.0f-8.0f,0.0f,200.0f,44.0f)];
  75. // self.searchBar.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
  76. // self.searchBar.delegate = self;
  77. // [self.searchBar setPlaceholder:@"name/address"];
  78. // //searchBar.barTintColor=[UIColor clearColor];
  79. // self.searchBar.searchBarStyle=UISearchBarStyleMinimal;
  80. // [searchView addSubview:titleLabel];
  81. // [searchView addSubview:self.searchBar];
  82. //
  83. // self.navigationItem.titleView = searchView;
  84. // NSMutableArray * items = [[NSMutableArray alloc]init];
  85. //
  86. //
  87. // UIBarButtonItem *Btnback = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
  88. //
  89. // Btnback = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
  90. // style:UIBarButtonItemStylePlain
  91. // target:self
  92. // action:@selector(onBack:)];
  93. //
  94. //
  95. // UIBarButtonItem *btnAS = nil;
  96. // btnAS =[[UIBarButtonItem alloc] initWithTitle:@"Advanced search"
  97. // style:UIBarButtonItemStylePlain
  98. // target:self
  99. // action:@selector(onASearch:)];
  100. //
  101. //
  102. //
  103. //
  104. // //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#>
  105. // //[savebtn setImage:[UIImage imageNamed:@"save"] ];
  106. //
  107. //
  108. // /*
  109. // UIBarMetricsDefault,
  110. // UIBarMetricsCompact,
  111. // UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
  112. // UIBarMetricsCompactPrompt
  113. //
  114. // */
  115. // // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  116. // // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
  117. // // item1.title = @"item1";
  118. // //// item1.image = [UIImage imageNamed:@"rect_setting"];
  119. // // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
  120. // //// item2.image = [UIImage imageNamed:@"rect_about"];
  121. // // item2.title = @"item2";
  122. //
  123. //
  124. // UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  125. // fixedItem.width = 20.0f;
  126. //
  127. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  128. ////
  129. //// if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  130. //
  131. // [items addObject:Btnback];
  132. //
  133. // [items addObject:fixedItem];
  134. //
  135. // [items addObject:btnAS];
  136. // // [items addObject:item2];
  137. // self.navigationItem.leftBarButtonItems=items;
  138. self.offset = 0;
  139. [self.content_data removeAllObjects];
  140. // [self loadpage];
  141. }
  142. -(void)manually_refresh
  143. {
  144. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  145. if(self.isrefreshing)
  146. {
  147. [reF endRefreshing];
  148. return;
  149. }
  150. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  151. if ([self respondsToSelector:@selector(ReloadData)])
  152. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  153. }
  154. -(void)ReloadData
  155. {
  156. self.keywords=self.searchBar.text;
  157. self.offset = 0;
  158. [self.content_data removeAllObjects];
  159. [self.table reloadData];
  160. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  161. [reF endRefreshing];
  162. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  163. [self loadpage];
  164. // [self loadpage];
  165. }
  166. - (void)didReceiveMemoryWarning {
  167. [super didReceiveMemoryWarning];
  168. // Dispose of any resources that can be recreated.
  169. }
  170. -(void) viewWillAppear:(BOOL)animated
  171. {
  172. [super viewWillAppear:animated];
  173. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  174. // self.offset = 0;
  175. // [self.content_data removeAllObjects];
  176. // [self loadpage];
  177. [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  178. }
  179. -(void) reload_container_getdata:(bool) update_data
  180. {
  181. [super reload_container_getdata:update_data];
  182. if(update_data)
  183. {
  184. self.offset = 0;
  185. [self.content_data removeAllObjects];
  186. [self loadpage];
  187. }
  188. else
  189. {
  190. [self.table reloadData];
  191. }
  192. }
  193. -(void) loadpage
  194. {
  195. dispatch_async(dispatch_get_main_queue(), ^{
  196. if(self.isrefreshing)
  197. return;
  198. self.label_net_err.hidden=true;
  199. self.isrefreshing=true;
  200. if(self.offset==0)
  201. {
  202. self.table.hidden = true;
  203. // [self.params setValue:[NSString stringWithFormat:@"%ld",self.offset] forKey:@"offset"];
  204. self.mum.center = self.view.center;
  205. self.mum.hidden = false;
  206. [self.mum startAnimating];
  207. }
  208. // self.btnrefresh.enabled = false;
  209. //
  210. // NSTimeInterval animationDuration = 0.30f;
  211. // [UIView beginAnimations:@"ResizeView" context:nil];
  212. // [UIView setAnimationDuration:animationDuration];
  213. // self.prepageButton.enabled=false;
  214. // self.nextpageButton.enabled=false;
  215. // self.mum.hidden = false;
  216. // self.grid.hidden = true;
  217. // self.mum.hidden = false;
  218. // self.tableview.hidden = true;
  219. // [UIView commitAnimations];
  220. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  221. NSMutableDictionary* content=nil;
  222. content=[[iSalesNetwork request_ContactList:self.offset limit : self.limit keywords:self.keywords type:self.contact_type adv_search:self.adv_search] mutableCopy];
  223. dispatch_async(dispatch_get_main_queue(), ^{
  224. [self.mum stopAnimating];
  225. if([[content valueForKey:@"result"] intValue]==2)
  226. {
  227. self.table.hidden =false;
  228. int count = [[content valueForKey:@"count" ] intValue] ;
  229. self.offset += count;
  230. for(int i=0;i<count;i++)
  231. {
  232. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  233. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  234. }
  235. if(count<self.limit)
  236. {
  237. // int i =self.btnrefresh.state;
  238. self.load_more_hint=@"All loaded";
  239. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  240. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  241. }
  242. else
  243. {
  244. self.load_more_hint=@"Load more...";
  245. // self.btnrefresh.enabled = true;
  246. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  247. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  248. }
  249. [self.table reloadData ];
  250. }
  251. else if([[content valueForKey:@"result"] intValue]==RESULT_NET_ERROR &&self.offset==0)
  252. {
  253. self.label_net_err.hidden=false;
  254. self.table.hidden = true;
  255. }
  256. else
  257. {
  258. [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Contact List" controller:self] ;
  259. }
  260. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  261. // bool autologin =[defaults boolForKey:@"autologin"];
  262. // if(!autologin)
  263. // {
  264. // TabBarController * viewController =[self.storyboard instantiateViewControllerWithIdentifier:@"LoginTabBar"];
  265. // [self presentViewController:viewController animated:YES completion:^{
  266. //
  267. // }];
  268. // }
  269. self.isrefreshing=false;
  270. });
  271. });
  272. });
  273. }
  274. - (void)loadmore
  275. {
  276. // self.btnrefresh.enabled = NO;
  277. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  278. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  279. [self loadpage];
  280. }
  281. - (IBAction)onBack:(UIBarButtonItem *)sender {
  282. if(self.onCancel)
  283. self.onCancel();
  284. [self.navigationController popViewControllerAnimated:(false)];
  285. }
  286. - (IBAction)onASearch:(UIBarButtonItem *)sender {
  287. ContactAdvanceSearchViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"ContactAdvanceSearchViewController"];
  288. vc.url_type = URL_LOCAL;
  289. vc.request_url=LOCAL_URL_CUSTOMER_ADV_SEARCH;
  290. vc.data_init = self.adv_search;
  291. // vc.update_order = true;
  292. // vc.contactId=contactid;
  293. // vc.delegate = self;
  294. vc.returnValue = ^(NSMutableDictionary* value){
  295. self.adv_search = value;
  296. self.keywords=nil;
  297. self.offset = 0;
  298. [self.content_data removeAllObjects];
  299. [self loadpage];
  300. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  301. // appDelegate.customerInfo = value;
  302. };
  303. [self.navigationController pushViewController:vc animated:true];
  304. }
  305. - (IBAction)onNewCustomerClick:(id)sender {
  306. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  307. CustomerEditViewController * cuseditVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
  308. cuseditVC.bnewcustomer=true;
  309. cuseditVC.url_type = URL_REMOTE;
  310. cuseditVC.request_url=URL_NEW_CUSTOMER;
  311. cuseditVC.params = params;
  312. cuseditVC.delegate=self;
  313. //
  314. // if(checked.count==count)
  315. // {
  316. // orderinfoVC.have_tail = true
  317. // }
  318. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  319. [self.navigationController pushViewController:cuseditVC animated:false];
  320. }
  321. - (IBAction)resetContactId:(id)sender {
  322. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  323. appDelegate.contact_id=nil;
  324. appDelegate.customerInfo = nil;
  325. // appDelegate.contact_name =nil;
  326. if(self.onReset)
  327. self.onReset();
  328. [self.navigationController popViewControllerAnimated:(false)];
  329. }
  330. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  331. {
  332. NSLog(@"!!!!!!!!!!!!!!!!!!!!!route!!!!!!!!!!!!!!!!!!!!!");
  333. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  334. [self.table reloadData];
  335. // CGSize contentsize = self.scroll.contentSize;
  336. // contentsize.height =330+2 * 230+29+20+20 +1 * 230+29+20+20 ;
  337. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  338. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  339. // {
  340. // contentsize.height+=250;
  341. // }
  342. //
  343. // self.scroll.contentSize = contentsize;
  344. // // CGRect frame = self.view.frame;
  345. // // [self.carouselController.view removeFromSuperview];
  346. // // wait(2000);
  347. // // self.carouselController = [[FPCarouselNonXIBViewController alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 400)];
  348. // // [self.view addSubview:self.carouselController.view];
  349. // // int i = self.view.subviews.count;
  350. // // int b = 0;
  351. // // [self.carouselController updateFrame:CGRectMake(0, 0, self.view.frame.size.width, 400)];
  352. }
  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. #pragma mark - Table view data source
  363. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  364. {
  365. if(indexPath.row==self.content_data.count)
  366. return 44;
  367. NSString* value = [self.content_data[indexPath.row] valueForKey:@"name"];
  368. float width = tableView.frame.size.width;
  369. width-=40;
  370. CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  371. // CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  372. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  373. // NSString* key =[self.content_data valueForKey:@"order_info"];
  374. // [cell.keyLabel sizeToFit];
  375. // NSString* val=[item_json valueForKey:@"val"] ;
  376. // if([val isEqual:[NSNull null]])
  377. // val=@"";
  378. // if(val==nil)
  379. // val=@"";
  380. // if([val isEqualToString:@"null"])
  381. // val=@"";
  382. CGRect frame;
  383. frame.size = constraintkey;
  384. frame.origin.x=0;
  385. frame.origin.y=0;
  386. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  387. // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  388. // rtlabel.lineSpacing = 20.0;
  389. [rtlabel setText: value];
  390. CGSize optimumSize = [rtlabel optimumSize];
  391. // NSLog(@"%@",key);
  392. // [rtlabel sizeThatFits:constraintkey];
  393. // rtlabel frameHeight:<#(CTFrameRef)#>
  394. // rtlabel
  395. // [rtlabel sizeToFit];
  396. //CGSize newsize= rtlabel.frame.size;
  397. // CGSize sizeval=rtlabel.optimumSize;
  398. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  399. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  400. float height = optimumSize.height;
  401. height = MAX(height+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  402. return height;
  403. }
  404. //- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  405. //{
  406. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  407. // if([item_json objectForKey:@"combine"] == nil)
  408. // {
  409. // return 120;
  410. // }
  411. // else
  412. // return 150;
  413. //}
  414. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  415. //{
  416. // return 0;
  417. //}
  418. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  419. //{
  420. // return 0;
  421. //}
  422. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  423. //{
  424. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  425. // return myView;
  426. //
  427. //}
  428. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  429. //{
  430. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  431. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  432. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  433. //// titleLabel.textColor=[UIColor whiteColor];
  434. //// titleLabel.backgroundColor = [UIColor clearColor];
  435. //// if(section==0)
  436. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  437. //// else
  438. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  439. //// [titleLabel sizeToFit];
  440. //// [myView addSubview:titleLabel];
  441. ////
  442. // return myView;
  443. //}
  444. //
  445. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  446. // if(section==0)
  447. // return nil;
  448. // else
  449. // return @"detail section";
  450. //}
  451. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  452. {
  453. return 1;
  454. }
  455. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  456. {
  457. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  458. if( self.content_data.count==0)
  459. return 0;
  460. return self.content_data.count+1;
  461. }
  462. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  463. {
  464. // if(tableView==self.itemListTable)
  465. // {
  466. NSLog(@"row %ld",(long)indexPath.row);
  467. if(indexPath.row==self.content_data.count)
  468. {
  469. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  470. UILabel *moreDataLabel=[[UILabel alloc] init];
  471. moreDataLabel.tag=200;
  472. moreDataLabel.text=self.load_more_hint;
  473. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  474. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  475. moreDataLabel.frame=CGRectMake(0, 10, self.table.bounds.size.width, 20);
  476. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  477. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  478. moreCell.backgroundColor = [UIColor whiteColor];
  479. [moreCell.contentView addSubview:moreDataLabel];
  480. if([self.load_more_hint isEqualToString:@"Load more..."])
  481. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  482. // NSLog(@"更多...");
  483. return moreCell;
  484. }
  485. else
  486. {
  487. // UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ContactListCell"];
  488. NSString *CellIdentifier = @"ContactListTableViewCell";
  489. ContactListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  490. NSString* value = [self.content_data[indexPath.row] valueForKey:@"name"];
  491. cell.rtlabel.text = value;
  492. /* NSString* name= [self.content_data[indexPath.row] valueForKey:@"name"];
  493. NSString* address= [self.content_data[indexPath.row] valueForKey:@"address"];
  494. cell.detailTextLabel.text=address;
  495. cell.textLabel.text=name;
  496. //cell.sep
  497. // [UIColor rg]*/
  498. cell.backgroundColor = [UIColor whiteColor];
  499. // cell.separator.backgroundColor = [UIColor grayColor];
  500. return cell;
  501. }
  502. }
  503. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  504. {
  505. if (indexPath.row>self.content_data.count-1) {
  506. return;
  507. }
  508. NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
  509. bool editable =[[self.content_data[indexPath.row] valueForKey:@"can_update"]boolValue] ;
  510. CustomerInfoViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerInfoViewController"];
  511. vc.url_type = URL_LOCAL;
  512. vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
  513. vc.update_order = self.update_order;
  514. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  515. if(self.ui_type==CONTACT_LIST)
  516. {
  517. vc.edit_icon = self.edit_icon&&editable&&appDelegate.can_update_contact_info;
  518. vc.assig_icon = self.assig_icon&&(appDelegate.contact_id.length==0);
  519. vc.reset_icon = self.reset_icon&&(appDelegate.contact_id.length!=0);
  520. }
  521. else
  522. {
  523. vc.edit_icon = self.edit_icon&&editable&&appDelegate.can_update_contact_info;
  524. vc.assig_icon = self.assig_icon;
  525. vc.reset_icon = self.reset_icon;
  526. }
  527. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  528. // // NSString * string = [checked componentsJoinedByString:@","];
  529. // // [params setValue:string forKey:@"cart2Checkbox"];
  530. //
  531. //
  532. //
  533. //
  534. // addressVC.params = params;
  535. vc.contactId=contactid;
  536. // vc.delegate = self;
  537. vc.from = indexPath;
  538. // orderinfoVC.params = params;
  539. vc.returnValue = ^(NSMutableDictionary* value){
  540. value[@"is_subaction"]=self.is_subaction;
  541. value[@"subaction_tag"]= self.subaction_tag;
  542. [self.navigationController popViewControllerAnimated:false];
  543. if(self.returnValue)
  544. self.returnValue(value,self.from);
  545. };
  546. [self.navigationController pushViewController:vc animated:true];
  547. /*
  548. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  549. appDelegate.contact_id=contactid;
  550. appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
  551. */
  552. // [self.navigationController popViewControllerAnimated:(false)];
  553. // NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  554. // OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  555. //
  556. // dvc.orderid=orderid;
  557. // [self.navigationController pushViewController:dvc animated:true];
  558. //
  559. //
  560. }
  561. /*
  562. #pragma mark - Navigation
  563. // In a storyboard-based application, you will often want to do a little preparation before navigation
  564. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  565. // Get the new view controller using [segue destinationViewController].
  566. // Pass the selected object to the new view controller.
  567. }
  568. */
  569. #pragma mark - searchBar delegate;
  570. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  571. {
  572. self.keywords=searchBar.text;
  573. self.offset = 0;
  574. [self.content_data removeAllObjects];
  575. self.adv_search=nil;
  576. [self loadpage];
  577. NSLog(@"search");
  578. }
  579. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  580. {
  581. if([searchText isEqualToString:@""] && !self.reset)
  582. {
  583. NSLog(@"clear");
  584. self.reset=true;
  585. self.keywords=nil;
  586. self.offset = 0;
  587. [self.content_data removeAllObjects];
  588. self.adv_search=nil;
  589. [self loadpage];
  590. // [self loadpage];
  591. }
  592. else
  593. self.reset = false;
  594. }
  595. @end