ContactListViewController.m 32 KB

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