| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- //
- // FreezeReasonViewController.m
- // IBOSS
- //
- // Created by 关宏厚 on 2020/4/30.
- // Copyright © 2020 elongtian. All rights reserved.
- //
- #import "FreezeReasonViewController.h"
- @interface FreezeReasonViewController ()
- @end
- @implementation FreezeReasonViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title = @"请选择";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back.png"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0,45,22);
- 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;
- }
- /**
- viewWillAppear函数
- */
- - (void)viewWillAppear:(BOOL)animated {
- _arrSearch = [[NSMutableArray alloc]init];
- _arrFilter = [[NSMutableArray alloc]init];
-
- [self reloadData];
- }
- -(void)reloadData
- {
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"GetFreezeReason" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
-
- _mDownManager = [[ASIDownManager alloc] init];
- [self startLoading];
- _mDownManager.delegate = self;
- _mDownManager.onRequestSuccess = @selector(onFreezeReasonLoadFinish:);
- _mDownManager.onRequestFail = @selector(onFreezeReasonLoadFail:);
- [_mDownManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
- }
- -(void)onFreezeReasonLoadFinish:(ASIDownManager*)sender {
-
- [self cancel];
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- int iStatus = resultModel.status;
- NSString *message=resultModel.message;
- if(iStatus==0)
- {
-
- NSDictionary *resultDic= (NSDictionary*)resultModel.result;
- NSArray *resultArray= [resultDic objectForKey:@"Table"];
- if(resultArray!=nil&&resultArray.count>0)
- {
-
- _arrSearch = [[NSMutableArray alloc]initWithArray:resultArray];
- _arrFilter = [[NSMutableArray alloc] initWithArray:_arrSearch];
- if(_arrSearch.count == 0){
- [self showAlertViewText:@"未找到匹配结果"];
- }
- [self.tableView reloadData];
- }
-
- }
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- return;
- }else {
- [self.tableView reloadData];
- [self showAlertViewText:message];
- }
- }
- -(void)onFreezeReasonLoadFail:(ASIDownManager *)sender
- {
- [self cancel];
- [self showAlertViewText:@"网络异常"];
- }
- /**
- 取消进度条
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 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 _arrFilter.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";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ];
- if(cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
-
- }
- NSDictionary *dic=_arrFilter[indexPath.row];
- NSString *name = [dic objectForKey:@"DictionaryValue"];
- cell.textLabel.textAlignment = NSTextAlignmentCenter;
- cell.textLabel.font=textFont;
- cell.textLabel.text=name;
- return cell;
- }
- /**
- 增加取消按钮
- */
- - (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;
- }
- /**
- 点击tableview的每一行
-
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- NSDictionary *dic=_arrFilter[indexPath.row];
- NSString *reasonName = [dic objectForKey:@"DictionaryValue"];
- NSString *reasonId = [dic objectForKey:@"DictionaryID"];
- if([self.inventoryDelegate respondsToSelector:@selector(getFreezeReason:name:)]){
- [self.inventoryDelegate getFreezeReason:reasonId name:reasonName];
- }
- if(_isPresentVc)
- {
- [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;
- }
- /**
- searchbar委托函数
-
- @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;
- }
- /**
- searchBar文本变化完成
-
- @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 = @"";
- keyName = @"DictionaryValue";
- NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@ Or %K contains[cd] %@", keyName, searchText,@"DictionaryValue",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];
- }
- /**
- scrollview回调事件
-
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- [_searchBar resignFirstResponder];
- [self cancelSearch];
- }
- @end
|