| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- //
- // IBOSSIPAD
- //
- // Created by iHope on 14-8-14.
- // Copyright (c) 2014年 elongtian. All rights reserved.
- //
- #import "SalesManSearchVC.h"
- #import "SalesManSearchCell.h"
- @interface SalesManSearchVC()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
- {
- UITextField *txtCode;
- UITextField *txtName;
- }
- @property(nonatomic,strong) ASIDownManager *mDownManager;
- @property(nonatomic,strong) UITableView *tableView;
- @end
- @implementation SalesManSearchVC
- #pragma mark - 公共函数
- /**
- viewDidLoad函数
- */
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- _searchArr=[NSMutableArray new];
- _filterArr=[NSMutableArray new];
- self.navigationItem.title=@"业务员查询";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- self.navigationController.navigationBar.barTintColor = NavigationBarTintColor;
- self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
-
- _tableView=[UITableView new];
- _tableView.delegate=self;
- _tableView.dataSource=self;
- _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
- _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;
- [self reloadData];
-
- }
- #pragma mark-委托函数
- /**
- tableviewcell的高度
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 89.0f;
- }
- /**
- tableview的分区数
- @param tableView <#tableView description#>
- @return <#return value description#>
- */
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- /**
- 获取tableview的行数
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _filterArr.count;
- }
- /**
- 获取tableviewcell
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- SalesManSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
- if(cell==nil)
- {
- NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"SalesManSearchCell" owner:self options:nil];
- cell = [nib objectAtIndex:0];
- }
- NSDictionary *dic=_filterArr[indexPath.row];
-
- NSString *name=[dic objectForKey:@"StaffName"];
- NSString *code=[dic objectForKey:@"StaffCode"];
- NSString *fullname=[dic objectForKey:@"OrganizationName"];
- cell.lblStaffName.text=name;
- cell.lblStaffCode.text=code;
- cell.lblDepartment.text=fullname;
- cell.lblStaffId=[dic objectForKey:@"StaffID"];
- return cell;
-
- }
- /**
- tableviewcell的点击事件
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- [self dismissViewControllerAnimated:YES completion:^(void){
- NSDictionary *dic=_filterArr[indexPath.row];
- NSString *staffName=[dic objectForKey:@"StaffName"];
- NSString *staffId=[dic objectForKey:@"StaffID"];
- if([self.salesmanDelegate respondsToSelector:@selector(salesman:salesmanName:)]){
- [self.salesmanDelegate salesman:staffId salesmanName:staffName];
- }
-
- }];
-
- }
- /**
- 数据加载成功函数
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
- NSDictionary *dic = [sender.mWebStr JSONValue];
- [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==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
- [self showReLoginDialog:message];
- return;
- }
-
- else {
- [self.tableView reloadData];
- [self showAlertViewText:message];
-
-
- }
-
- }
- }
- /**
- 数据加载失败函数
- @param sender <#sender description#>
- */
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self cancel];
- [self.tableView reloadData];
- [self showAlertViewText:@"加载失败"];
- }
- /**
- 搜索栏开始编辑函数
- @param searchBar <#searchBar description#>
- @return <#return value description#>
- */
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- {
- [self addCancelButton];
- return YES;
- }
- /**
- 是否允许替换文本
- @param searchBar <#searchBar description#>
- @param range <#range description#>
- @param text <#text description#>
- @return <#return value description#>
- */
- - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- return YES;
- }
- /**
- 搜索栏文本输入结束回调函数
- @param searchBar <#searchBar description#>
- @param searchText <#searchText description#>
- */
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
-
- if ([searchText isEqualToString:@""]) {
- self.filterArr = _searchArr;
- [_tableView reloadData];
- return;
- }
-
- NSString *keyName = @"";
- // if (_searchState == DataSearchStateBank) {
- keyName = @"StaffName";
- //}
- //< 模糊查找
- // 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,@"StaffName",searchText];
-
- //< 精确查找
- // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K == %@", keyName, searchText];
-
- NSLog(@"predicate %@",predicateString);
- NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_searchArr filteredArrayUsingPredicate:predicateString]];
-
- self.filterArr = filteredArray;
- [_tableView reloadData];
- }
- /**
- 取消搜索函数
- @param searchBar <#searchBar description#>
- */
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
- [searchBar resignFirstResponder];
- [self cancelSearch];
- }
- /**
- scrollView回调函数
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [_searchBar resignFirstResponder];
- [self cancelSearch];
- }
- #pragma mark - 私有函数
- /**
- 返回函数
- */
- -(void)goBack
- {
- if(!_subview){
- [self dismissViewControllerAnimated:YES completion:^(void){
- }];}
- else{
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- /**
- 取消进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 加载数据接口
- */
- -(void)reloadData
- {
- [self startLoading];
- self.mDownManager = [[ASIDownManager alloc] init];
- _mDownManager.delegate = self;
- _mDownManager.OnImageDown = @selector(onLoadFinish:);
- _mDownManager.OnImageFail = @selector(onLoadFail:);
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetStaffDataSource" 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:@"" forKey:@"StaffCode"];
- [dict setObject:@"" forKey:@"StaffName"];
- [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];}
- /**
- 添加取消按钮
- */
- -(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;
- }
- @end
|