| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- //
- // PayTypeVC.m
- // IBOSS
- //
- // Created by Dongke on 16/1/20.
- // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
- //
- // 功能描述:收款方式控制器
- #import "PayTypeVC.h"
- #import "PayTypeModel.h"
- #import "TypeViewCell.h"
- @implementation PayTypeVC
- NSInteger row;
- #pragma mark - 公共函数
- /**
- 视图加载完成函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.arrFilterData = [[NSMutableArray alloc]init];
- self.arrSearchData = [[NSMutableArray alloc]init];
- row = 0;
- 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;
-
- 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];
- }
-
- if(!_arrSearchData){
- _arrSearchData = [[NSMutableArray alloc]init];
- }
-
- self.arrTextModels = [[NSMutableArray alloc]init];
- self.mDownManager = [[ASIDownManager alloc] init];
- self.mDownManager.delegate = self;
- self.mDownManager.onRequestSuccess = @selector(onRequestSuccess:);
- self.mDownManager.onRequestFail = @selector(onRequestFail:);
- [self reloadData];
- }
- #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:@"未找到匹配结果"];
- }
- [self changeArrToModel:_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.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 = @"TypeViewCell";
- TypeViewCell *cell =(TypeViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if(cell == nil){
- NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TypeViewCell" owner:self options:nil];
- cell = [nib objectAtIndex:0];
- }
- PayTypeModel* infoModel = self.arrTextModels[indexPath.row];
- [cell parseInfoModel:infoModel];
- return cell;
- }
- /**
- table view的点击事件
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- row = indexPath.row;
- [self.payDelegate setPayTypeModel:self.arrTextModels[indexPath.row]];
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 获取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;
- }
- /**
- 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;
- [self changeArrToModel:_arrFilterData];
- [_tableView reloadData];
- return;
- }
-
- NSString *keyName = @"SettlementTypeName";
-
- //< 模糊查找
- NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
- NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearchData filteredArrayUsingPredicate:predicateString]];
-
- self.arrFilterData = filteredArray;
- [self changeArrToModel:_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)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 加载数据函数
- */
- - (void)reloadData
- {
- [self startLoading];
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary new];
- [dict setObject:@"GetReceivableWayIphone" forKey:@"Action"];
- [dict setObject:kkAccountCode forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
-
- }
- /**
- 保存数组数据
- @param arr <#arr description#>
- */
- - (void)changeArrToModel:(NSArray* )arr{
-
- if(arr != nil){
- [_arrTextModels removeAllObjects];
- for(int i = 0;i < arr.count;i++)
- {
- PayTypeModel * info = [PayTypeModel new];
- NSDictionary * dic = arr[i];
- info.settlementType = [NSString stringWithFormat:@"%@",[dic objectForKey:@"SettlementType"]];
- info.settlementTypeName = [dic objectForKey:@"SettlementTypeName"];
- info.receivableSum = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ReceivableSum"]];
- info.existsHandlingFee = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ExistsHandlingFee"]];
- info.earnestFee = [NSString stringWithFormat:@"%@",[dic objectForKey:@"EarnestFee"]];
- info.remarks = [NSString stringWithFormat:@"%@",[dic objectForKey:@"Remarks"]];
- info.salesID = [NSString stringWithFormat:@"%@",[dic objectForKey:@"SalesID"]];
- info.valueFlag = [NSString stringWithFormat:@"%@",[dic objectForKey:@"ValueFlag"]];
- [_arrTextModels addObject:info];
- }
- }
-
- }
- /**
- 添加取消按钮
- */
- - (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;
- }
- /**
- 取消进度条加载
- */
- - (void)cancel {
- [self stopLoading];
- }
- @end
|