Bootstrap

input输入限制算法

 /** 设置按照指定格式输入
         * event:$event
         * e: 当前值
         * row:本条数据
         * code:字段
         * */
        checkNum(event,e, row, code,type='countDecimal'){
            let isDecimal
            if(type=='countDecimal'){
                isDecimal = this.countDecimal_Order
            }else if(type=='unitDecimal'){
                isDecimal = this.unitDecimal_Order
            }
            if(this.actType_order=='editor'){
                event.target.style.background = "#e1f3d8"
                this.changeOrderIds_order.push({
                    id:row.id,
                    code:code
                })
            }
            if (isDecimal === 0) {
                row[code] = e.replace(/[^\d]/g, '')
            } else {
                if (e.indexOf('.') === 0){
                    e = e.substring(1)
                }
                let reg = /\D+/ig
                if (reg.test(e) && e.indexOf('.') == -1) {
                    e = e.replace(/\D/ig,'')
                }
                let len1 = e.substring(0,1)
                let len2 = e.substring(1,2)
                if (e.length > 1 && len1 == 0 && len2 != '.') {
                    e = e.substring(1)
                }
                //限制小数点个数
                if (e.indexOf('.') != -1) {
                    let str2 = e.substring(e.indexOf('.')+1)
                    if (str2.indexOf('.') != -1) {
                        e = e.substring(0, e.indexOf('.') + 1 + str2.indexOf('.'))
                    }
                }
                let max = isDecimal
                let reg2 = new RegExp("\^(-)*(\\d+)\\.(\\d{0," + max + "}).*$")
                e = e.replace(reg2, '$1$2.$3')
                row[code] = e
            }
        },

;