fastadmin在给供应商充值的时候,需要点击add.html进行新增,这里可以实现JS自动获取供应商余额,根绝变更类型,自动计算相应金额并填写,edit.html同理,不过用的很少,就暂时不做了。
文件地址
public\assets\js\backend\your.js
add: function () {
Controller.api.bindevent();
console.log('点击了添加按钮');
// (function(){
//("#c-money").bind('input porpertychange',function(){
// console.log("输入了金额");
// let vipmanreseller = document.getElementById("c-vipmanreseller_id").value;
// let money = document.getElementById("c-money").value;
// let change = document.getElementById("c-change").value;
// console.log("分销商:"+vipmanreseller);
// console.log('变动金额:' + money);
// console.log(change);
// });
// });
("#c-money").change(function(){
vipmanreseller = document.getElementById("c-vipmanreseller_id").value;
if (vipmanreseller<1) {
toastr.error("请选择分销商");
return false;
};
change = document.getElementById("c-change").value;
console.log(change);
money = document.getElementById("c-money").value;
//查余额.ajax({
url:'/api/vip/tools/yourapiname?userid=' + vipmanreseller,
type:'GET',
success:(res)=>{
console.log(res);
if (1 > res) {
toastr.success("查询余额失败或需要核实");
return false;
}
console.log('修改金额');
if (change == '增加' || change == '充值') {
//这里需要转化一下字符串为浮点数,不然就是字符串相加了
aftermoney = parseFloat(money) + parseFloat(res);
}else if(change == '减少'){
aftermoney = res - money;
}
document.getElementById("c-beforemoney").value = res;
document.getElementById("c-aftermoney").value = aftermoney;
toastr.success("计算成功,请核实!");
},
error:(res)=>{
console.log('false');
toastr.error("获取余额失败,请核实!");
}
});
// console.log(vipmanreseller);
});
},