// // DepositAmountVC.m // IBOSS // // Created by 关宏厚 on 2020/7/24. // Copyright © 2020 elongtian. All rights reserved. // #import "PaymentMethodVC.h" #import "PayTypeModel.h" @interface PaymentMethodVC () @end @implementation PaymentMethodVC - (void)viewDidLoad { [super viewDidLoad]; [self loadNavStyle]; [self initUI]; if(_receivableList!=nil&&_receivableList.count>0) { [_vTableView reloadData]; } else { [self reloadData]; } [self registerKeybordNotification]; } -(void)loadNavStyle { //右边 UIButton *btnAdd = [UIButton buttonWithType:UIButtonTypeCustom]; [btnAdd addTarget:self action:@selector(submitData) forControlEvents:UIControlEventTouchUpInside]; btnAdd.frame = CGRectMake(0, 0,60,14); [btnAdd setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; btnAdd.titleLabel.font=[UIFont systemFontOfSize:16]; [btnAdd setTitle:@"确定" forState:UIControlStateNormal]; UIBarButtonItem *menubtnAdd = [[UIBarButtonItem alloc] initWithCustomView:btnAdd]; self.navigationItem.title=@"请选择"; self.navigationItem.rightBarButtonItem = menubtnAdd; //返回 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; } /** 安全区视图发生变化 */ -(void)viewSafeAreaInsetsDidChange{ _vTableView.frame = CGRectMake(0,0,self.view.frame.size.width, self.view.safeAreaLayoutGuide.layoutFrame.size.height); [super viewSafeAreaInsetsDidChange]; } /** 加载数据函数 */ - (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"]; self.downManager = [[ASIDownManager alloc] init]; self.downManager.delegate = self; self.downManager.onRequestSuccess = @selector(onRequestSuccess:); self.downManager.onRequestFail = @selector(onRequestFail:); [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil]; } /** 数据加载成功函数 @param sender <#sender description#> */ - (void)onRequestSuccess:(ASIDownManager *)sender { // 取消进度条 [self stopLoading]; // 服务器返回数据转换model RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr]; // 服务器返回数据状态值 int iStatus = resultModel.status; // 服务器返回数据消息 NSString *message = resultModel.message; // 服务器返回数据状态值正确 if (iStatus == 0) { // 服务器返回数据结果 NSArray *paymentMethodArr = (NSArray *)resultModel.result; if(paymentMethodArr != nil&&paymentMethodArr.count>0) { _receivableList=[[NSMutableArray alloc]init]; for(int i=0;i */ - (void)onRequestFail:(ASIDownManager *)sender { [self showAlertViewText:@"网络异常"]; } -(void)initUI{ _vTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; _vTableView.separatorStyle = UITableViewCellSeparatorStyleNone; _vTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _vTableView.backgroundColor = [UIColor whiteColor]; _vTableView.delegate = self; _vTableView.dataSource=self; [self.view addSubview:_vTableView]; } -(void)submitData{ [self.view endEditing:YES]; if([self.paymentMethodDelegate respondsToSelector:@selector(callbackPaymentMethod:)]) { [self.paymentMethodDelegate callbackPaymentMethod:_receivableList]; } [self.navigationController popViewControllerAnimated:YES]; } #pragma mark - tableView回调 /** 单元格cell个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [_receivableList count]; } /** <#Description#> @param tableView <#tableView description#> @return <#return value description#> */ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } /** 高度 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 97; } /** 每个单元格cell @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"PaymentMethodCell"; PaymentMethodCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier ]; cell=[[PaymentMethodCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.selectionStyle=UITableViewCellSelectionStyleNone; cell.position= indexPath.row; cell.cellDelegate=self; PayTypeModel *paytypeModel = [_receivableList objectAtIndex:indexPath.row]; [cell parsePaymentMethod:paytypeModel]; return cell; } -(void)update:(int) position flag:(int) flag text:(NSString *) str { PayTypeModel *model = [_receivableList objectAtIndex:position]; if(flag == 1){ model.receivableSum = str; }else{ model.remarks = str; } } // 键盘弹出改变tableview高度 - (void)registerKeybordNotification { NSNotificationCenter *notification = [NSNotificationCenter defaultCenter]; [notification removeObserver:self]; [notification addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil]; [notification addObserver:self selector:@selector(hideKeyboard:) name:UIKeyboardWillHideNotification object:nil]; #ifdef __IPHONE_5_0 // 5.0以上系统中文键盘高度与4.0系统不一样 float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 5.0) { [notification addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillChangeFrameNotification object:nil]; } #endif } - (void)showKeyboard:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGFloat keyboardHeight = CGRectGetHeight([aValue CGRectValue]); CGFloat height = CGRectGetHeight(self.view.frame) - keyboardHeight; /* 使用动画效果,过度更加平滑 */ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.1]; { CGRect rect = _vTableView.frame; rect.size.height = height; _vTableView.frame = rect; } [UIView commitAnimations]; } - (void)hideKeyboard:(NSNotification *)notification { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.1]; { CGRect rect = _vTableView.frame; rect.size.height = CGRectGetHeight(self.view.frame) ; _vTableView.frame = rect; } [UIView commitAnimations]; } -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ if(scrollView.isDragging){ [self.view endEditing:YES]; } } - (void)goBack { [self.navigationController popViewControllerAnimated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end