// // PositionNumberViewController.m // IBOSS // // Created by 关宏厚 on 2019/9/4. // Copyright © 2019 elongtian. All rights reserved. // #import "PositionNumberViewController.h" @interface PositionNumberViewController () @end @implementation PositionNumberViewController - (void)viewDidLoad { [super viewDidLoad]; //是否是dismissViewController if (_isPresentViewFlg) { UIView *vTitle = [[UIView alloc]init]; vTitle.frame = CGRectMake(0, 0, Screen_Width, 44 + rectStatusHeight); vTitle.backgroundColor = NavigationBarTintColor; [self.view addSubview:vTitle]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(gotoBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(20, rectStatusHeight + 13, 9, 15); [vTitle addSubview:button]; UILabel *lblTitle = [[UILabel alloc]init]; lblTitle.frame = CGRectMake(9, rectStatusHeight + 13, Screen_Width-2*9 - 20, 15); lblTitle.textColor = [UIColor whiteColor]; lblTitle.text = @"请选择"; lblTitle.textAlignment = NSTextAlignmentCenter; [vTitle addSubview:lblTitle]; }else{ self.navigationItem.title = @"请选择"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(gotoBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0,45,22); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; [self.navigationController setNavigationBarHidden:NO]; } _tableView = [UITableView new]; _tableView.delegate=self; _tableView.dataSource=self; //是否是dismissViewController if (_isPresentViewFlg) { self.tableView.frame = CGRectMake(0, 44 + rectStatusHeight, self.view.bounds.size.width, self.view.bounds.size.height - 44 - rectStatusHeight - 1) ; } else{ self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-rectNavHeight - rectStatusHeight - 1) ; } [self.view addSubview:_tableView]; //搜索框 _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)]; _searchBar.delegate=self; self.tableView.tableHeaderView=_searchBar; } /** viewWillAppear @param animated <#animated description#> */ - (void)viewWillAppear:(BOOL)animated { self.arrSearch = [[NSMutableArray alloc] init] ; self.arrFilter = [[NSMutableArray alloc] init] ; _downManager = [[ASIDownManager alloc] init]; _downManager.delegate = self; _downManager.onRequestSuccess = @selector(onLoadFinish:); _downManager.onRequestFail = @selector(onLoadFail:); [self reloadData]; } /** 加载库存列表数据 */ - (void)reloadData { [self startLoading]; NSString *urlStr = ServerURL; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:@"GetPositionNumber" forKey:@"Action"]; [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"]; [dict setObject:kkUserCode forKey:@"UserCode"]; [dict setObject:kkUserPwd forKey:@"UserPassword"]; [dict setObject:kkSessionKey forKey:@"SessionKey"]; [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } #pragma mark - searchbar回调 /** 数据加载成功回调 @param sender <#sender description#> */ - (void)onLoadFinish:(ASIDownManager *)sender{ /// 取消进度条 [self cancel]; // 服务器返回数据 RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; // 服务器返回数据状态值 int iStatus = resultModel.status; // 服务器返回数据消息 NSString *message = resultModel.message; // 服务器返回数据状态值正确 if (iStatus == 0) { NSDictionary * approveDic = (NSDictionary *)resultModel.result; NSArray *approvArr= [approveDic objectForKey:@"Table"]; if(approvArr != nil) { _arrSearch = [[NSMutableArray alloc]initWithArray:approvArr]; self.arrFilter = [[NSMutableArray alloc] initWithArray:_arrSearch]; if(!_arrSearch || _arrSearch.count == 0){ [self showAlertViewText:@"未找到匹配结果"]; } [self.tableView reloadData]; } } // 服务器返回数据状态值异常 else if(iStatus == ActionResultStatusAuthError ||iStatus == ActionResultStatusNoLogin ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){ [self showReLoginDialog:message]; } else { [self.tableView reloadData]; [self showAlertViewText:message]; } } /** 加载失败 @param sender <#sender description#> */ - (void)onLoadFail:(ASIDownManager *)sender { [self cancel]; [self.tableView reloadData]; [self showAlertViewText:@"网络异常"]; } #pragma mark - tableView回调 /** Section @param tableView <#tableView description#> @return <#return value description#> */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } /** 单元格个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.arrFilter.count; } /** 每个单元格 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (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 = self.arrFilter[indexPath.row]; cell.textLabel.text = [dic objectForKey:@"DictionaryValue"]; cell.textLabel.textAlignment = NSTextAlignmentCenter; cell.textLabel.font = [UIFont systemFontOfSize:TextFontOfSize]; return cell; } /** 单元格点击事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic=self.arrFilter[indexPath.row]; BaseIDAndNameModel *model = [BaseIDAndNameModel new]; model.id = [dic objectForKey:@"DictionaryID"]; model.name = [dic objectForKey:@"DictionaryValue"]; if ([self.bDelegate respondsToSelector:@selector(baseIDAndNameDoneDatas : BaseIDAndName:)]){ [self.bDelegate baseIDAndNameDoneDatas:model BaseIDAndName:self.showDialogViewTag]; } //是否是dismissViewController if (_isPresentViewFlg) { [self dismissViewControllerAnimated:YES completion:nil]; }else{ [self.navigationController popViewControllerAnimated:YES]; } } /** 开始编辑 @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.arrFilter = _arrSearch; [_tableView reloadData]; return; } NSString *keyName = @"DictionaryValue"; //< 模糊查找 NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", keyName, searchText]; NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]]; self.arrFilter = filteredArray; [_tableView reloadData]; } /** 查询点击事件 @param searchBar <#searchBar description#> */ - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [searchBar resignFirstResponder]; [self cancelSearch]; } /** 开始拖动 @param scrollView <#scrollView description#> */ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [_searchBar resignFirstResponder]; [self cancelSearch]; } #pragma mark - 私有函数 /** 进度条隐藏 */ - (void)cancel { [self stopLoading]; } /** 添加取消按钮 */ - (void)addCancelButton { //添加取消按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(cancelSearch) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0, 40, 24); [button setTitle:@"取消" forState:UIControlStateNormal]; [button setTitleColor:NavBarItemColor forState:UIControlStateNormal]; UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.rightBarButtonItem = menuButton; } /** 取消查询 */ - (void)cancelSearch { [_searchBar resignFirstResponder]; [self removeCancel]; } /** 取消按钮隐藏 */ - (void) removeCancel { self.navigationItem.rightBarButtonItem = nil; } /** 返回父界面 */ - (void)gotoBack { //是否是dismissViewController if (_isPresentViewFlg) { [self dismissViewControllerAnimated:YES completion:nil]; }else{ [self.navigationController popViewControllerAnimated:YES]; } } @end