ContactListViewController.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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_REMOTE;
  289. vc.request_url=URL_CUSTOMER_ADV_SEARCH;
  290. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  291. vc.params = params;
  292. vc.data_init = self.adv_search;
  293. // vc.update_order = true;
  294. // vc.contactId=contactid;
  295. // vc.delegate = self;
  296. vc.returnValue = ^(NSMutableDictionary* value){
  297. self.adv_search = value;
  298. self.keywords=nil;
  299. self.offset = 0;
  300. [self.content_data removeAllObjects];
  301. [self loadpage];
  302. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  303. // appDelegate.customerInfo = value;
  304. };
  305. [self.navigationController pushViewController:vc animated:true];
  306. }
  307. - (IBAction)onNewCustomerClick:(id)sender {
  308. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  309. CustomerEditViewController * cuseditVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
  310. cuseditVC.bnewcustomer=true;
  311. cuseditVC.url_type = URL_REMOTE;
  312. cuseditVC.request_url=URL_NEW_CUSTOMER;
  313. cuseditVC.params = params;
  314. cuseditVC.delegate=self;
  315. //
  316. // if(checked.count==count)
  317. // {
  318. // orderinfoVC.have_tail = true
  319. // }
  320. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  321. [self.navigationController pushViewController:cuseditVC animated:false];
  322. }
  323. - (IBAction)resetContactId:(id)sender {
  324. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  325. appDelegate.contact_id=nil;
  326. appDelegate.customerInfo = nil;
  327. // appDelegate.contact_name =nil;
  328. if(self.onReset)
  329. self.onReset();
  330. [self.navigationController popViewControllerAnimated:(false)];
  331. }
  332. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  333. {
  334. NSLog(@"!!!!!!!!!!!!!!!!!!!!!route!!!!!!!!!!!!!!!!!!!!!");
  335. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  336. [self.table reloadData];
  337. // CGSize contentsize = self.scroll.contentSize;
  338. // contentsize.height =330+2 * 230+29+20+20 +1 * 230+29+20+20 ;
  339. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  340. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  341. // {
  342. // contentsize.height+=250;
  343. // }
  344. //
  345. // self.scroll.contentSize = contentsize;
  346. // // CGRect frame = self.view.frame;
  347. // // [self.carouselController.view removeFromSuperview];
  348. // // wait(2000);
  349. // // self.carouselController = [[FPCarouselNonXIBViewController alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 400)];
  350. // // [self.view addSubview:self.carouselController.view];
  351. // // int i = self.view.subviews.count;
  352. // // int b = 0;
  353. // // [self.carouselController updateFrame:CGRectMake(0, 0, self.view.frame.size.width, 400)];
  354. }
  355. //
  356. //-(void)changeCell
  357. //{
  358. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  359. // // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  360. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  361. // DebugLog(@"refresh!!!!!!!!");
  362. //
  363. //}
  364. - (IBAction)onAssignClick:(id)sender {
  365. UIButton* btn = (UIButton*)sender;
  366. UITableViewCell *cell = (UITableViewCell *)btn.superview.superview;;
  367. NSIndexPath *indexPath = [self.table indexPathForCell:cell];
  368. NSLog(@"indexPath is = %i",indexPath.row);
  369. NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
  370. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Getting Contact information"];
  371. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  372. NSDictionary* editor_json = [iSalesNetwork request_CustomerInfo:contactid];
  373. dispatch_async(dispatch_get_main_queue(), ^{
  374. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  375. if([[editor_json valueForKey:@"result"] intValue]==2)
  376. {
  377. __block NSMutableDictionary* data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
  378. //---------------- construct customer_contact----------------------
  379. NSString* customer_first_name = [data_init valueForKey:@"customer_first_name"];
  380. if(customer_first_name==nil)
  381. customer_first_name=@"";
  382. NSString* customer_last_name= [data_init valueForKey:@"customer_last_name"];
  383. if(customer_last_name==nil)
  384. customer_last_name=@"";
  385. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  386. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  387. [data_init setValue:customer_contact forKey:@"customer_contact"];
  388. data_init[@"is_subaction"]=self.is_subaction;
  389. data_init[@"subaction_tag"]= self.subaction_tag;
  390. // [self.navigationController popViewControllerAnimated:false];
  391. if(self.returnValue)
  392. self.returnValue(data_init,self.from);
  393. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  394. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  395. // NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:data_init];
  396. //
  397. // dispatch_async(dispatch_get_main_queue(), ^{
  398. //
  399. //
  400. // if([[editor_json valueForKey:@"result"] intValue]==2)
  401. // {
  402. //
  403. //// [self.navigationController popViewControllerAnimated:false];
  404. //// if(self.returnValue)
  405. //// {
  406. ////
  407. //// self.returnValue(data_init);
  408. //// }
  409. //
  410. //
  411. //
  412. // }
  413. // else
  414. // {
  415. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
  416. // }
  417. //
  418. //
  419. //
  420. // });
  421. // });
  422. }
  423. else
  424. {
  425. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
  426. // self.btn_assign.enabled=false;
  427. }
  428. });
  429. });
  430. }
  431. #pragma mark - Table view data source
  432. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  433. {
  434. if(indexPath.row==self.content_data.count)
  435. return 44;
  436. NSString* value = [self.content_data[indexPath.row] valueForKey:@"name"];
  437. float width = tableView.frame.size.width;
  438. width-=40;
  439. CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  440. // CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
  441. // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
  442. // NSString* key =[self.content_data valueForKey:@"order_info"];
  443. // [cell.keyLabel sizeToFit];
  444. // NSString* val=[item_json valueForKey:@"val"] ;
  445. // if([val isEqual:[NSNull null]])
  446. // val=@"";
  447. // if(val==nil)
  448. // val=@"";
  449. // if([val isEqualToString:@"null"])
  450. // val=@"";
  451. CGRect frame;
  452. frame.size = constraintkey;
  453. frame.origin.x=0;
  454. frame.origin.y=0;
  455. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  456. // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
  457. // rtlabel.lineSpacing = 20.0;
  458. [rtlabel setText: value];
  459. CGSize optimumSize = [rtlabel optimumSize];
  460. // NSLog(@"%@",key);
  461. // [rtlabel sizeThatFits:constraintkey];
  462. // rtlabel frameHeight:<#(CTFrameRef)#>
  463. // rtlabel
  464. // [rtlabel sizeToFit];
  465. //CGSize newsize= rtlabel.frame.size;
  466. // CGSize sizeval=rtlabel.optimumSize;
  467. // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  468. // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
  469. float height = optimumSize.height;
  470. height = MAX(height+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  471. return height;
  472. }
  473. //- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  474. //{
  475. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  476. // if([item_json objectForKey:@"combine"] == nil)
  477. // {
  478. // return 120;
  479. // }
  480. // else
  481. // return 150;
  482. //}
  483. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  484. //{
  485. // return 0;
  486. //}
  487. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  488. //{
  489. // return 0;
  490. //}
  491. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  492. //{
  493. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  494. // return myView;
  495. //
  496. //}
  497. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  498. //{
  499. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  500. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  501. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  502. //// titleLabel.textColor=[UIColor whiteColor];
  503. //// titleLabel.backgroundColor = [UIColor clearColor];
  504. //// if(section==0)
  505. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  506. //// else
  507. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  508. //// [titleLabel sizeToFit];
  509. //// [myView addSubview:titleLabel];
  510. ////
  511. // return myView;
  512. //}
  513. //
  514. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  515. // if(section==0)
  516. // return nil;
  517. // else
  518. // return @"detail section";
  519. //}
  520. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  521. {
  522. return 1;
  523. }
  524. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  525. {
  526. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  527. if( self.content_data.count==0)
  528. return 0;
  529. return self.content_data.count+1;
  530. }
  531. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  532. {
  533. // if(tableView==self.itemListTable)
  534. // {
  535. NSLog(@"row %ld",(long)indexPath.row);
  536. if(indexPath.row==self.content_data.count)
  537. {
  538. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  539. UILabel *moreDataLabel=[[UILabel alloc] init];
  540. moreDataLabel.tag=200;
  541. moreDataLabel.text=self.load_more_hint;
  542. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  543. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  544. moreDataLabel.frame=CGRectMake(0, 10, self.table.bounds.size.width, 20);
  545. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  546. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  547. moreCell.backgroundColor = [UIColor whiteColor];
  548. [moreCell.contentView addSubview:moreDataLabel];
  549. if([self.load_more_hint isEqualToString:@"Load more..."])
  550. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  551. // NSLog(@"更多...");
  552. return moreCell;
  553. }
  554. else
  555. {
  556. // UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ContactListCell"];
  557. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  558. NSString *CellIdentifier = @"ContactListTableViewCell";
  559. ContactListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  560. NSString* value = [self.content_data[indexPath.row] valueForKey:@"name"];
  561. cell.rtlabel.text = value;
  562. cell.btn_assign.hidden = !(self.assig_icon&&(appDelegate.contact_id.length==0));
  563. /* NSString* name= [self.content_data[indexPath.row] valueForKey:@"name"];
  564. NSString* address= [self.content_data[indexPath.row] valueForKey:@"address"];
  565. cell.detailTextLabel.text=address;
  566. cell.textLabel.text=name;
  567. //cell.sep
  568. // [UIColor rg]*/
  569. cell.backgroundColor = [UIColor whiteColor];
  570. // cell.separator.backgroundColor = [UIColor grayColor];
  571. return cell;
  572. }
  573. }
  574. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  575. {
  576. if (indexPath.row>self.content_data.count-1) {
  577. return;
  578. }
  579. NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
  580. bool editable =[[self.content_data[indexPath.row] valueForKey:@"can_update"]boolValue] ;
  581. CustomerInfoViewController * vc =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerInfoViewController"];
  582. vc.url_type = URL_LOCAL;
  583. vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
  584. vc.update_order = self.update_order;
  585. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  586. if(self.ui_type==CONTACT_LIST)
  587. {
  588. vc.edit_icon = self.edit_icon&&editable&&appDelegate.can_update_contact_info;
  589. vc.assig_icon = self.assig_icon&&(appDelegate.contact_id.length==0);
  590. vc.reset_icon = self.reset_icon&&(appDelegate.contact_id.length!=0);
  591. }
  592. else
  593. {
  594. vc.edit_icon = self.edit_icon&&editable&&appDelegate.can_update_contact_info;
  595. vc.assig_icon = self.assig_icon;
  596. vc.reset_icon = self.reset_icon;
  597. }
  598. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  599. // // NSString * string = [checked componentsJoinedByString:@","];
  600. // // [params setValue:string forKey:@"cart2Checkbox"];
  601. //
  602. //
  603. //
  604. //
  605. // addressVC.params = params;
  606. vc.contactId=contactid;
  607. // vc.delegate = self;
  608. vc.from = indexPath;
  609. // orderinfoVC.params = params;
  610. vc.returnValue = ^(NSMutableDictionary* value){
  611. value[@"is_subaction"]=self.is_subaction;
  612. value[@"subaction_tag"]= self.subaction_tag;
  613. [self.navigationController popViewControllerAnimated:false];
  614. if(self.returnValue)
  615. self.returnValue(value,self.from);
  616. };
  617. [self.navigationController pushViewController:vc animated:true];
  618. /*
  619. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  620. appDelegate.contact_id=contactid;
  621. appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
  622. */
  623. // [self.navigationController popViewControllerAnimated:(false)];
  624. // NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  625. // OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  626. //
  627. // dvc.orderid=orderid;
  628. // [self.navigationController pushViewController:dvc animated:true];
  629. //
  630. //
  631. }
  632. /*
  633. #pragma mark - Navigation
  634. // In a storyboard-based application, you will often want to do a little preparation before navigation
  635. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  636. // Get the new view controller using [segue destinationViewController].
  637. // Pass the selected object to the new view controller.
  638. }
  639. */
  640. #pragma mark - searchBar delegate;
  641. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  642. {
  643. self.keywords=searchBar.text;
  644. self.offset = 0;
  645. [self.content_data removeAllObjects];
  646. self.adv_search=nil;
  647. [self loadpage];
  648. NSLog(@"search");
  649. }
  650. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  651. {
  652. if([searchText isEqualToString:@""] && !self.reset)
  653. {
  654. NSLog(@"clear");
  655. self.reset=true;
  656. self.keywords=nil;
  657. self.offset = 0;
  658. [self.content_data removeAllObjects];
  659. self.adv_search=nil;
  660. [self loadpage];
  661. // [self loadpage];
  662. }
  663. else
  664. self.reset = false;
  665. }
  666. @end