|
|
@@ -2,16 +2,15 @@
|
|
|
* @Author: liuzhenlin 461480418@qq.ocm
|
|
|
* @Date: 2023-01-10 16:18:28
|
|
|
* @LastEditors: liuzhenlin
|
|
|
- * @LastEditTime: 2023-01-10 17:49:42
|
|
|
+ * @LastEditTime: 2023-01-17 17:44:24
|
|
|
* @Description: file content
|
|
|
- * @FilePath: \订单全流程管理系统\src\components\amountInput\index.vue
|
|
|
+ * @FilePath: \订单全流程管理系统\src\components\currency\index.vue
|
|
|
-->
|
|
|
<template>
|
|
|
<div>
|
|
|
<el-input
|
|
|
v-bind="$attrs"
|
|
|
v-model.trim="num"
|
|
|
- oninput="value=value.replace(/[^0-9.]/g,'')"
|
|
|
@blur="inputMoney($event)"
|
|
|
@change="handleChange"
|
|
|
@focus="uninputMoney($event)"
|
|
|
@@ -33,23 +32,19 @@
|
|
|
num: '',
|
|
|
}
|
|
|
},
|
|
|
- watch: {
|
|
|
- value(val) {
|
|
|
- this.num = this.formatPrice(val)
|
|
|
- },
|
|
|
- },
|
|
|
-
|
|
|
mounted() {
|
|
|
this.num = this.formatPrice(this.value)
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
returnNum() {
|
|
|
- this.$emit('input', this.delcommafy(this.num))
|
|
|
+ if (this.num) {
|
|
|
+ this.$emit('input', this.CurrencyFomatNumber(this.num))
|
|
|
+ }
|
|
|
},
|
|
|
handleChange(val) {
|
|
|
this.$nextTick(() => {
|
|
|
- this.$emit('change', this.delcommafy(val))
|
|
|
+ this.$emit('change', this.CurrencyFomatNumber(val))
|
|
|
})
|
|
|
},
|
|
|
// 失焦显示数字类型
|
|
|
@@ -60,17 +55,38 @@
|
|
|
// 获得焦点金额去掉格式
|
|
|
uninputMoney(el) {
|
|
|
if (el.target.value) {
|
|
|
- this.num = this.delcommafy(el.target.value)
|
|
|
+ this.num = this.CurrencyFomatNumber(el.target.value)
|
|
|
} else {
|
|
|
this.num = null
|
|
|
}
|
|
|
},
|
|
|
//去除千分位中的‘,’
|
|
|
- delcommafy(num) {
|
|
|
- if (!num) return num
|
|
|
- num = num.toString().replace('¥', '').replace(/,/gi, '')
|
|
|
- if (num.indexOf('.00') > 0) num = parseInt(num)
|
|
|
- return num
|
|
|
+ CurrencyFomatNumber(num, n = 2) {
|
|
|
+ let number = num.replace('¥', '')
|
|
|
+ if (number != null && number != '' && number != undefined) {
|
|
|
+ number = number.replace(/,/g, '') //去除千分位的','
|
|
|
+ if (isNaN(number)) {
|
|
|
+ //判断是否是数字
|
|
|
+ number = '0'
|
|
|
+ } else {
|
|
|
+ number = Math.round(number * Math.pow(10, n)) / Math.pow(10, n) //n幂
|
|
|
+ number = number.toString()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ number = '0'
|
|
|
+ }
|
|
|
+ //a.indexOf(x,y);返回x值在a字符串值中从y位置开始检索首次出现的位置
|
|
|
+ var numLength = number.indexOf('.')
|
|
|
+ //判断传递的值是整数增加小数点再补"0"
|
|
|
+ if (numLength < 0) {
|
|
|
+ numLength = number.length
|
|
|
+ number += '.'
|
|
|
+ }
|
|
|
+ //不足n位小数的,循环补"0"
|
|
|
+ while (number.length <= numLength + n) {
|
|
|
+ number += '0'
|
|
|
+ }
|
|
|
+ return parseFloat(number)
|
|
|
},
|
|
|
},
|
|
|
}
|