computed:{
debitMoneyAllForm: function() {
// num = this.debitMoneyAll
num = 3444333
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}
},
支持货币格式及自定义保留小数:
formatMoney = (s, n) => {
if (s == undefined || s == '') {
return
}
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse(),
r = s.split(".")[1];
var t = "";
for (var i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").reverse().join("") + "." + r
}
倒计时禁用功能:
不可点击时:
可以点击时:
//html结构
<i-button type="primary" shape="circle" @click="againSignNew" :disabled="!timeFlag" style="width: 200px">{{btnText}}</i-button>
data初始值:
new Vue({
el: '#app',
data: function() {
return{
btnText:'我同意并签署该合同(10s)',
timeFlag:false,
downTime:'2',
timer:null,
}
},
mounted:function() {
var _this = this;
_this.againSignNew()
},
methods:{
countDown:function(){
var _this = this;
var sys_second = _this.downTime
_this.timer = setInterval(function () {
if (sys_second > 1) {
sys_second -= 1;
var second = Math.floor(sys_second % 60);
if (second > 0) {
if (second < 10) {
second = second;
}
_this.btnText = "我同意并签署该合同(" + second + "s)";
}
} else {
clearInterval(_this.timer);
_this.timeFlag = true;
_this.btnText = "我同意并签署该合同";
}
},
1000);
},
againSignNew:function(){
var _this = this;
_this.againSignModel = true
_this.timeFlag = false
clearInterval(_this.timer);
_this.btnText="我同意并签署该合同(" + _this.downTime + "s)";
_this.countDown()
},
}
})