<input type="text" class="defaultInput smInput" v-model="row.row.unitPrice" @input="onlyPrice(row.$index)" @change="alterRecord(row.row)">
// 返回单价(不为负)
onlyPrice(index){
var value = this.detailList[index].unitPrice
//先把非数字的都替换掉,除了数字和.和-号
value = value.replace(/[^\d\.]/g,'');
//前两位不能是0加数字
value = value.replace(/^0\d[0-9]*/g,'');
//必须保证第一个为数字而不是.
value = value.replace(/^\./g,'');
//保证只有出现一个.而没有多个.
value = value.replace(/\.{2,}/g,'.');
//保证.只出现一次,而不能出现两次以上
value = value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
//如果第一位是负号,则允许添加
value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');
if(Number(value) > 100000000) {
this.message(_this,'warning','最大不能超过1亿!')
value = value.slice(0,value.length-1)
}
this.$set(this.detailList[index],'unitPrice',value)
},