| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- //
- // SettlementTypeVC.m
- // IBOSS
- //
- // Created by apple on 16/1/14.
- // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
- //
- // 功能描述:收款方式视图控制器
- #import "SettlementTypeVC.h"
- #import "SettlementTypeModel.h"
- @interface SettlementTypeVC()
- /**
- 下载管理器
- */
- @property (nonatomic,strong) ASIDownManager *mDownManager;
- /**
- 搜索栏
- */
- @property (strong) IBOutlet UISearchBar *searchBar;
- /**
- table view
- */
- @property (strong) UITableView *tableView;
- /**
- 收款方式模型
- */
- @property (nonatomic,strong) SettlementTypeModel *model;
- /**
- 确定按钮
- */
- @property (nonatomic,strong) UIBarButtonItem *menuButtonOk;
- /**
- 确定按钮
- */
- @property (nonatomic,strong) UIButton *btnOk;
- @end
- @implementation SettlementTypeVC
- #pragma mark - 公共函数
- /**
- 初始化函数
- @return <#return value description#>
- */
- - (id)init{
- self = [super init];
- if(self){
- self.arrFilterData = [[NSMutableArray alloc]init];
- self.arrSearchData = [[NSMutableArray alloc]init];
- self.model = [SettlementTypeModel new];
- }
-
- return self;
- }
- /**
- 视图加载函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"请选择";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back"] 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;
-
- //保存
- _btnOk = [UIButton buttonWithType:UIButtonTypeCustom];
- [_btnOk addTarget:self action:@selector(saveData)
- forControlEvents:UIControlEventTouchUpInside];
- _btnOk.frame = CGRectMake(0, 0, 44, 20);
- [_btnOk setTitle:@"确定" forState:UIControlStateNormal];
- [_btnOk setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
- _btnOk.enabled=NO;
- _menuButtonOk = [[UIBarButtonItem alloc] initWithCustomView:_btnOk];
- self.tableView = [UITableView new];
- self.tableView.dataSource = self;
- self.tableView.delegate = self;
- self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 44 - 20 - 4) ;
- [self.view addSubview:self.tableView];
-
- //搜索框
- self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
- self.searchBar.delegate = self;
- self.tableView.tableHeaderView = self.searchBar;
-
-
- }
- /**
- 视图将出现函数
- @param animated <#animated description#>
- */
- - (void)viewWillAppear:(BOOL)animated{
-
- if(!_arrFilterData){
- _arrFilterData = [[NSMutableArray alloc]init];
- _arrSearchData = [[NSMutableArray alloc]init];
- }
-
- [_arrSearchData addObjectsFromArray:_arrFilterData];
- self.mDownManager = [[ASIDownManager alloc] init];
- self.mDownManager.delegate = self;
- self.mDownManager.onRequestSuccess = @selector(onRequestSuccess:);
- self.mDownManager.onRequestFail = @selector(onRequestFail:);
- [self reloadData];
-
- }
- /**
- 内存释放
- */
- - (void)dealloc{
- [self cancel];
- }
- #pragma mark - 委托函数
- /**
- 数据加载成功回调函数
- @param sender <#sender description#>
- */
- - (void)onRequestSuccess:(ASIDownManager *)sender {
- // 取消进度条
- [self cancel];
- // 服务器返回数据转换model
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- // 服务器返回数据结果
- NSArray *approvArr = (NSArray *)resultModel.result;
- if(approvArr != nil)
- {
- [_arrSearchData removeAllObjects];
- [_arrSearchData addObjectsFromArray:approvArr];
- [_arrFilterData removeAllObjects];
- [_arrFilterData addObjectsFromArray:_arrSearchData];
- if(_arrSearchData.count == 0)
- {
- [self showAlertViewText:@"未找到匹配结果"];
- }
- [_model parseSettlementArr:_arrFilterData ];
- [self.tableView reloadData];
- }
- }
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- return;
- }
-
-
- else {
- [self.tableView reloadData];
- [self showAlertViewText:message];
- }
- }
- /**
- 数据请求失败回调函数
- @param sender <#sender description#>
- */
- - (void)onRequestFail:(ASIDownManager *)sender {
- [self cancel];
- [self.tableView reloadData];
- [self showAlertViewText:@"网络异常"];
- }
- /**
- 获取table view的cell
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifier = @"SettlementTypeCell";
- SettlementTypeCell * cell = (SettlementTypeCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if(cell == nil){
- NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SettlementTypeCell" owner:self options:nil];
- cell = [nib objectAtIndex:0];
- }
- SettlementTypeModel* infoModel = self.model.arrSettlement[indexPath.row];
-
- [cell parseInfoModel:infoModel];
- return cell;
- }
- /**
- 获取table view的行数
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return _arrFilterData.count;
- }
- /**
- 获取table view的高度
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 148.0f;
- }
- /**
- table view的点击事件
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- SettlementTypeModel* infoModel=self.model.arrSettlement[indexPath.row];
-
- if ([self.sDelegate respondsToSelector:@selector(showProtocolValue:)]) {
- [self.sDelegate showProtocolValue:infoModel];
- }
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- search bar开始编辑回调函数
- @param searchBar <#searchBar description#>
- @return <#return value description#>
- */
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- {
- [self addCancelButton];
- return YES;
- }
- /**
- search bar替换指定的文本
- @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;
- }
- /**
- search bar改变搜索文本
- @param searchBar <#searchBar description#>
- @param searchText <#searchText description#>
- */
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
-
- if ([searchText isEqualToString:@""]) {
- self.arrFilterData = _arrSearchData;
- [_model parseSettlementArr:_arrFilterData ];
- [_tableView reloadData];
- return;
- }
-
- NSString *keyName = @"SettlementTypeName";
-
- //< 模糊查找
- NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
- //< 精确查找
- // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K == %@", keyName, searchText];
-
- NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearchData filteredArrayUsingPredicate:predicateString]];
-
- self.arrFilterData = filteredArray;
- [_model parseSettlementArr:_arrFilterData ];
- [_tableView reloadData];
- }
- /**
- search bar搜索按钮点击
- @param searchBar <#searchBar description#>
- */
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
- [searchBar resignFirstResponder];
- [self cancelSearch];
- }
- /**
- scroll view回调函数
- @param scrollView <#scrollView description#>
- */
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [_searchBar resignFirstResponder];
- [self cancelSearch];
- }
- #pragma mark -私有函数
- /**
- 加载数据函数
- */
- - (void)reloadData
- {
- [self startLoading];
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary new];
- [dict setObject:@"GetReceivableWay" forKey:@"Action"];
- [dict setObject:kkAccountCode forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [self.mDownManager postHttpRequest:urlStr dic:dict files:nil];
- }
- /**
- 取消进度条加载函数
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 返回函数
- */
- - (void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 保存数据函数
- */
- - (void)saveData{
- [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;
- }
- @end
|