|
|
@@ -18,14 +18,11 @@
|
|
|
show-overflow-tooltip>
|
|
|
<template #default="{ row }">
|
|
|
<span v-if="item.prop == 'price'">
|
|
|
- <el-input
|
|
|
+ <amount-input
|
|
|
v-model.trim="row.price"
|
|
|
placeholder="请输入金额"
|
|
|
- @blur="inputMoney($event, row, 'price')"
|
|
|
- @change="handleChange(row)"
|
|
|
- @focus="uninputMoney($event, row, 'price')">
|
|
|
- <!-- <template slot="append">元</template> -->
|
|
|
- </el-input>
|
|
|
+ :value="row.price"
|
|
|
+ @change="handleChange(row)" />
|
|
|
</span>
|
|
|
<span v-else-if="item.prop == 'count'">
|
|
|
<el-input-number v-model="row.count" :min="0" size="mini" @change="handleChange(row)" />
|
|
|
@@ -46,12 +43,12 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- // import AmountInput from '@/components/AmountInput'
|
|
|
+ import AmountInput from '@/components/amountInput'
|
|
|
|
|
|
export default {
|
|
|
name: 'ProductTable',
|
|
|
components: {
|
|
|
- // AmountInput,
|
|
|
+ AmountInput,
|
|
|
},
|
|
|
props: {
|
|
|
productData: {
|
|
|
@@ -107,81 +104,30 @@
|
|
|
productData() {
|
|
|
this.data = []
|
|
|
this.data = this.productData.map((item) => {
|
|
|
- return { ...item, price: this.setPriceFormat(item['price']) }
|
|
|
+ return { ...item, price: item['price'] }
|
|
|
})
|
|
|
},
|
|
|
},
|
|
|
created() {
|
|
|
this.data = []
|
|
|
this.data = this.productData.map((item) => {
|
|
|
- return { ...item, price: this.setPriceFormat(item['price']) }
|
|
|
+ return { ...item, price: item['price'] }
|
|
|
})
|
|
|
},
|
|
|
methods: {
|
|
|
// input修改
|
|
|
- handleChange(item) {
|
|
|
- this.$emit('changeProductData', item)
|
|
|
+ handleChange(row) {
|
|
|
+ console.log('row', row)
|
|
|
+ this.$emit('changeProductData', row)
|
|
|
},
|
|
|
// 删除
|
|
|
- handleDel(item) {
|
|
|
- this.$emit('delProductData', item)
|
|
|
- },
|
|
|
- // 失焦显示数字类型
|
|
|
- inputMoney(el, row, key) {
|
|
|
- let temp = Number(el.target.value) || null
|
|
|
- row[key] = this.priceFormat(temp)
|
|
|
- },
|
|
|
- // 获得焦点金额去掉格式
|
|
|
- uninputMoney(el, row, key) {
|
|
|
- if (el.target.value) {
|
|
|
- row[key] = this.delcommafy(el.target.value)
|
|
|
- } else {
|
|
|
- row[key] = null
|
|
|
- }
|
|
|
- },
|
|
|
- setPriceFormat(num) {
|
|
|
- if (!num) {
|
|
|
- return (num = 0)
|
|
|
- } else if (typeof num == 'number') {
|
|
|
- return this.priceFormat(num)
|
|
|
- } else {
|
|
|
- return num
|
|
|
- }
|
|
|
- },
|
|
|
- // 金额格式化
|
|
|
- priceFormat(num, n) {
|
|
|
- n = n || 2
|
|
|
- let symbol = ','
|
|
|
- if (num === null) return num
|
|
|
- if (typeof num !== 'number') throw new TypeError('num参数应该是一个number类型')
|
|
|
- if (n < 0) throw new Error('参数n不应该小于0')
|
|
|
- let hasDot = parseInt(num) != num //这里检测num是否为小数,true表示小数
|
|
|
- let m = n != undefined && n != null ? n : 1
|
|
|
- num = m == 0 ? num.toFixed(m) + '.' : hasDot ? (n ? num.toFixed(n) : num) : num.toFixed(m)
|
|
|
- symbol = symbol || ','
|
|
|
- num = num.toString().replace(/(\d)(?=(\d{3})+\.)/g, function (match, p1) {
|
|
|
- return p1 + symbol
|
|
|
- })
|
|
|
- if (n == 0 || (!hasDot && !n)) {
|
|
|
- //如果n为0或者传入的num是整数并且没有指定整数的保留位数,则去掉前面操作中的小数位
|
|
|
- num = num.substring(0, num.indexOf('.'))
|
|
|
- }
|
|
|
- return num
|
|
|
- },
|
|
|
- //去除千分位中的‘,’
|
|
|
- delcommafy(num) {
|
|
|
- if (!num) return num
|
|
|
- num = num.toString()
|
|
|
- num = num.replace(/,/gi, '')
|
|
|
- if (num.indexOf('.00') > 0) num = parseInt(num)
|
|
|
- return num
|
|
|
+ handleDel(row) {
|
|
|
+ this.$emit('delProductData', row)
|
|
|
},
|
|
|
// 计算总价
|
|
|
calculatedDiscount(price, count) {
|
|
|
- let intPrice = null
|
|
|
- if (typeof price === 'string') intPrice = this.delcommafy(price) * 100
|
|
|
- else intPrice = price * 100
|
|
|
- return this.priceFormat((intPrice * count) / 100)
|
|
|
+ let intPrice = price * 100
|
|
|
+ return this.formatPrice((intPrice * count) / 100)
|
|
|
},
|
|
|
},
|
|
|
}
|