ContactListViewController.m 31 KB

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