ContactListViewController.m 29 KB

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