ContactListViewController.m 29 KB

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