| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- //
- // KeHuXingZhiSearchTC.m
- // IBOSSIPAD
- //
- // Created by iHope on 14-8-14.
- // Copyright (c) 2014年 elongtian. All rights reserved.
- //
- #import "KeHuXingZhiSearchTC.h"
- @interface KeHuXingZhiSearchTC()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
- @property(nonatomic,strong) ASIDownManager *mDownManager;
- @property(strong) IBOutlet UISearchBar *searchBar;
- @property(strong) UITableView *tableView;
- @end
- @implementation KeHuXingZhiSearchTC
- - (void)OnLoadFinish:(ASIDownManager *)sender {
-
- NSDictionary *dic = [sender.mWebStr JSONValue];
- NSLog(@"dic=%@",dic);
- [self Cancel];
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- NSString *message=[dic objectForKey:@"Message"];
- if (iStatus == 0) {
- NSArray * approvArr=[dic objectForKey:@"Result"];
- if(approvArr!=nil)
- {
-
- _searchArr=[[NSMutableArray alloc]initWithArray:approvArr];
- _filterArr=[[NSMutableArray alloc] initWithArray:_searchArr];
- if(_searchArr.count==0)
- {
- [self showAlertViewText:@"未找到匹配结果"];
-
- }
- [self.tableView reloadData];
- }
- }
- else if(iStatus==-2||iStatus==-3||iStatus==-4){
- __weak id weakapp=Appdelegate;
- __weak id userShare=[UserInfoManager Share] ;
- [UIAlertView showAlertViewWithTitle:@""
- message:@"加载失败,请您重新登录"
- cancelButtonTitle:nil
- otherButtonTitles:[NSArray arrayWithObject:@"OK"]
- onDismiss:^(int buttonIndex) {
- [userShare ClearUserData];
- [weakapp changeViewDidLogout];
-
- }
- onCancel:^ {}];
-
-
-
-
- }
- else {
- [self.tableView reloadData];
- [self showAlertViewText:message];
-
-
- }
-
- }
- }
- - (void)OnLoadFail:(ASIDownManager *)sender {
- [self Cancel];
- [self.tableView reloadData];
- [self showAlertViewText:@"加载失败"];
- }
- - (void)Cancel {
- [self StopLoading];
-
- }
- -(void)reloadData
- {
- [self StartLoading];
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
-
- [dict setObject:@"GetDataSource" forKey:@"Action"];
-
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:@"CustomerType" forKey:@"DataSourceCode"];
-
- [_mDownManager PostHttpRequest:urlStr :dict :nil :nil];
- }
- -(void)GotoBack
- {
- if(!_Subview){
- [self dismissViewControllerAnimated:YES completion:^(void){
- }];}
- else{
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- -(void)viewWillAppear:(BOOL)animated
- {
-
- _searchArr=[NSMutableArray new];
- _filterArr=[NSMutableArray new];
- self.mDownManager = [[ASIDownManager alloc] init];
- self.mDownManager = [[ASIDownManager alloc] init];
- _mDownManager.delegate = self;
- _mDownManager.OnImageDown = @selector(OnLoadFinish:);
- _mDownManager.OnImageFail = @selector(OnLoadFail:);
- [self reloadData];
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.navigationItem.title=@"客户性质";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"fanhui_icon.png"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(GotoBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 44, 20);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
-
- _tableView=[UITableView new];
- _tableView.delegate=self;
- _tableView.dataSource=self;
- _tableView.frame=CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height) ;
- [self.view addSubview:_tableView];
- //搜索框
- _searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 44)];
- _searchBar.delegate=self;
- self.tableView.tableHeaderView=_searchBar;
-
-
- }
- -(void)dealloc
- {
- [self Cancel];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Table view data source
- /*- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 135.0f;
- }*/
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- // Return the number of sections.
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // Return the number of rows in the section.
- return _filterArr.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
- if(cell==nil)
- {
- cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
-
- }
- NSDictionary *dic=_filterArr[indexPath.row];
-
- NSString *name=[dic objectForKey:@"CustomerTypeName"];
- cell.textLabel.text=name;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if(!_Subview){
- [self dismissViewControllerAnimated:YES completion:^(void){
- NSDictionary *dic=_filterArr[indexPath.row];
- NSString * str=[dic objectForKey:@"CustomerTypeName"];
- NSString *WareID=[dic objectForKey:@"CustomerType"];
- [_parentVC.btnKeHuXingZhi setTitle:str forState:UIControlStateNormal];
- _parentVC.KeHuXingZhiHiddenStr=WareID;
-
- }];
- }
- else {
- NSDictionary *dic=_filterArr[indexPath.row];
- NSString * str=[dic objectForKey:@"CustomerTypeName"];
- NSString *WareID=[dic objectForKey:@"CustomerType"];
- [_parentVC2.btnKeHuXingZhi setTitle:str forState:UIControlStateNormal];
- _parentVC2.KeHuXingZhiHiddenStr=WareID;
- [self.navigationController popViewControllerAnimated:YES];
-
- }
-
- // [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)AddCancelButton
- {
- //添加取消按钮
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
- [button2 addTarget:self action:@selector(CancelSearch)
- forControlEvents:UIControlEventTouchUpInside];
- button2.frame = CGRectMake(0, 0, 40, 24);
- [button2 setTitle:@"取消" forState:UIControlStateNormal];
- [button2 setTitleColor:NavBarItemColor forState:UIControlStateNormal];
- UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:button2];
- self.navigationItem.rightBarButtonItem = menuButton2;
- }
- -(void)CancelSearch
- {
- [_searchBar resignFirstResponder];
- [self RemoveCancel];
- }
- -(void) RemoveCancel
- {
- self.navigationItem.rightBarButtonItem = nil;
- }
- #pragma mark search bar delegate
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- {
- [self AddCancelButton];
- return YES;
- }
- - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- return YES;
- }
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
-
- if ([searchText isEqualToString:@""]) {
- self.filterArr = _searchArr;
- [_tableView reloadData];
- return;
- }
-
- NSString *keyName = @"";
- // if (_searchState == DataSearchStateBank) {
- keyName = @"CustomerTypeName";
- //}
- //< 模糊查找
- // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@ Or %K contains[cd] %@", keyName, searchText,@"OrganizationCode",searchText];
- NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@ Or %K contains[cd] %@", keyName, searchText,@"CustomerTypeName",searchText];
-
- //< 精确查找
- // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K == %@", keyName, searchText];
-
- NSLog(@"predicate %@",predicateString);
- NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_searchArr filteredArrayUsingPredicate:predicateString]];
-
- self.filterArr = filteredArray;
- [_tableView reloadData];
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
- [searchBar resignFirstResponder];
- [self CancelSearch];
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [_searchBar resignFirstResponder];
- [self CancelSearch];
- }
- @end
|