前端实现货币标准格式 例如:3,444,333.00,及按钮倒计时功能

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()
            },
        }
})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值