可充值金额和不同费率,升级金额算法的需求,来回改,参照了微信,然后参考支付宝,由于都是临时想法和时间的关系,连人和代码呗折腾成这样了:
离开键盘的事件
- (void)textFieldDidEndEditing:(UITextField *)textField{
if(textField.text.length>0 ){
[self checkAmtValidV];
}
}
//确定的事件
- (IBAction)confirmAction:(id)sender {
[self checkAmtValidV];
}
//乱的不想看的事件
-(void)checkAmtValidV{
NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:1];
YFRegisterNormalCell *cell = (YFRegisterNormalCell *)[_mTableView cellForRowAtIndexPath:index];
strAmt=cell.mTextField.text;
if (strAmt.length <= 0) {
[self alert:@"请输入金额"];
return;
}
if([strAmt doubleValue]==0){
[self alert:@"请输入大于0的金额"];
return;
}
if (![YFValidateUtils validateAmount:strAmt]) {
[self alert:@"您输入的金额有误"];
return;
}
// double d=money+serviceCharge;
// YFElectronicCardListModel *model=_dataArray[indexMerge];
//交易限额
NSDictionary *para = @{@"application":@"QueryFukaLimitQuota.Req",
@"userId":[USER_DEFAULT objectForKey:kUserId],
@"transType":@"1",
@"cardType":@"14",
};
[self.request requestWithDictionary:para completion:^(BOOL success, id responseData) {
if (success) {
double money=[strAmt doubleValue];
int i=[responseData[@"need"] intValue];
if(i ==1){
if(availableBlanceStr.length>0){
feeRate=responseData[@"feeRate"];
rateLeft.text = [NSString stringWithFormat:@"服务费(%@%@)",feeRate,@"%"];
//计算服务费
double serviceCharge=money*([feeRate doubleValue]/100);
NSString *fourPointStr=[self formatStringAfterPoint:[NSString stringWithFormat:@"%.4f",serviceCharge]];
serviceCharge=[fourPointStr doubleValue];
if(serviceCharge<=0.1){
serviceCharge=0.1;
if (([availableBlanceStr doubleValue]/100-serviceCharge)<=0) {
[self showHud:@"福卡可用余额不足"];
return;
}
}
if (money>[responseData[@"singleTransQuota"] doubleValue]/100) {
[self showHud:@"输入单笔金额超限"];
return ;
}
if (isAllMoeny) {
//总金额有变化
YFElectronicCardListModel *modelAllMoeny=_dataArray[indexMerge];
money=[modelAllMoeny.balance doubleValue]/100;
serviceCharge=money*([feeRate doubleValue]/100);
NSString *fourPointStr=[self formatStringAfterPoint:[NSString stringWithFormat:@"%.4f",serviceCharge]];
serviceCharge=[fourPointStr doubleValue];
//总金额
twoDownLab.text=[NSString stringWithFormat:@"¥%.2f",money];
rechargeAmountRight.text = twoDownLab.text;
// cell.mTextField.text= [NSString stringWithFormat:@"%.2f",(money-serviceCharge)];
//显示出来
oneUpLab.text=[NSString stringWithFormat:@"服务费(%@%@)",feeRate,@"%"];
oneDownLab.text=@"总金额";
if(serviceCharge<=0.1){
//服务费
serviceCharge=0.1;
twoUpLab.text=@"¥0.1";
//升级金额
upgradeRight.text = [NSString stringWithFormat:@"¥%.2f",(money-serviceCharge)];
}
else{
//服务费
twoUpLab.text=[NSString stringWithFormat:@"¥%@",fourPointStr];
//升级金额
upgradeRight.text = [NSString stringWithFormat:@"¥%.2f",(money-serviceCharge)];
}
//服务费显示
rateRight.text = twoUpLab.text;
_viewAlpha.hidden=NO;
_whiteView.hidden=NO;
[_mTableView reloadData];
}
else{
if(money<=([availableBlanceStr doubleValue]/100-serviceCharge)){
[cell.mTextField resignFirstResponder];
if (_VipArray.count>0) {
YFElectronicCardListModel *modelVip=_VipArray[indexVip];
if((money+[modelVip.balance doubleValue]/100)>5000){
[self alert:@"升级后福卡VIP金额超限,不可大于5000元"];
return;
}
}
//显示出来
oneUpLab.text=[NSString stringWithFormat:@"服务费(%@%@)",feeRate,@"%"];
oneDownLab.text=@"总金额";
if(serviceCharge<=0.1){
//服务费
serviceCharge=0.1;
twoUpLab.text=@"¥0.1";
//升级金额
// upgradeRight.text = [NSString stringWithFormat:@"¥%.2f",money-serviceCharge];
upgradeRight.text = [NSString stringWithFormat:@"¥%.2f",money];
//总金额
twoDownLab.text=[NSString stringWithFormat:@"¥%.2f",(money+serviceCharge)];
}
else{
//服务费
twoUpLab.text=[NSString stringWithFormat:@"¥%@",fourPointStr];
//升级金额
upgradeRight.text = [NSString stringWithFormat:@"¥%.2f",money];
//总金额
twoDownLab.text=[NSString stringWithFormat:@"¥%.2f",(money+serviceCharge)];
}
rechargeAmountRight.text = twoDownLab.text;
//服务费显示
rateRight.text = twoUpLab.text;
_viewAlpha.hidden=NO;
_whiteView.hidden=NO;
[_mTableView reloadData];
}
else if(([availableBlanceStr doubleValue]/100-serviceCharge)<money&&money<=([availableBlanceStr doubleValue]/100)){
//中间的金额按照全部流程去算
serviceCharge=money*([feeRate doubleValue]/100);
NSString *fourPointStr=[self formatStringAfterPoint:[NSString stringWithFormat:@"%.4f",serviceCharge]];
serviceCharge=[fourPointStr doubleValue];
//总金额有变化
YFElectronicCardListModel *modelAllMoeny=_dataArray[indexMerge];
money=[modelAllMoeny.balance doubleValue]/100;
//总金额
twoDownLab.text=[NSString stringWithFormat:@"¥%.2f",money];
rechargeAmountRight.text = twoDownLab.text;
// cell.mTextField.text= [NSString stringWithFormat:@"%.2f",(money-serviceCharge)];
//显示出来
oneUpLab.text=[NSString stringWithFormat:@"服务费(%@%@)",feeRate,@"%"];
oneDownLab.text=@"总金额";
if(serviceCharge<=0.1){
//服务费
serviceCharge=0.1;
twoUpLab.text=@"¥0.1";
//升级金额
upgradeRight.text = [NSString stringWithFormat:@"¥%.2f",(money-serviceCharge)];
}
else{
//服务费
twoUpLab.text=[NSString stringWithFormat:@"¥%@",fourPointStr];
//升级金额
upgradeRight.text = [NSString stringWithFormat:@"¥%.2f",(money-serviceCharge)];
}
//服务费显示
rateRight.text = twoUpLab.text;
_viewAlpha.hidden=NO;
_whiteView.hidden=NO;
[_mTableView reloadData];
}
else if(money>[availableBlanceStr doubleValue]/100){
[self showHud:@"输入金额超过福卡可用余额"];
return;
}
}
}
}
}
}];
}