|
|
@@ -93,6 +93,11 @@
|
|
|
<el-table-column
|
|
|
prop="count"
|
|
|
label="数量">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-input-number
|
|
|
+ v-model="scope.row.count"
|
|
|
+ :min="1"></el-input-number>
|
|
|
+ </template>
|
|
|
</el-table-column>
|
|
|
<el-table-column
|
|
|
prop="price"
|
|
|
@@ -111,10 +116,10 @@
|
|
|
label="小计">
|
|
|
<template slot-scope="scope">
|
|
|
<span v-if="scope.row.discountPrice">
|
|
|
- {{ scope.row.total + scope.row.discountPrice * scope.row.tickets.length }} <s style="color: #f56c6c;">{{ scope.row.total }}</s>
|
|
|
+ {{ numCalc(scope.row.count, scope.row.price, '*') + numCalc(scope.row.count, scope.row.discountPrice, '*') }} <s style="color: #f56c6c;">{{ numCalc(scope.row.count, scope.row.originalPrice, '*') }}</s>
|
|
|
</span>
|
|
|
<span v-else>
|
|
|
- {{ scope.row.total }}
|
|
|
+ {{ numCalc(scope.row.count, scope.row.price, '*') }}
|
|
|
</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
@@ -212,6 +217,52 @@ import PrintSmallTicketCheckbox from '../common/PrintSmallTicketCheckbox'
|
|
|
import UploadImgList from '../common/uploadImgList'
|
|
|
import orderItemMixin from '../common/orderItemMixin'
|
|
|
|
|
|
+/** 封装一个公共方法numCalc() 用于浮点数运算 */
|
|
|
+// num1 num2传入两个值 symbol +-*/符号
|
|
|
+const numCalc = (num1, num2, symbol) => {
|
|
|
+ const str1 = num1.toString()
|
|
|
+ const str2 = num2.toString()
|
|
|
+ let result
|
|
|
+ let str1Length
|
|
|
+ let str2Length
|
|
|
+ try {
|
|
|
+ // 获取小数点后的精度
|
|
|
+ str1Length = str1.split('.')[1].length
|
|
|
+ } catch (error) {
|
|
|
+ // 解决整数没有小数点方法
|
|
|
+ str1Length = 0
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ str2Length = str2.split('.')[1].length
|
|
|
+ } catch (error) {
|
|
|
+ str2Length = 0
|
|
|
+ }
|
|
|
+ // 取两个数的最小精度,即小数点后数字的最大长度
|
|
|
+ const maxLen = Math.max(str1Length, str2Length)
|
|
|
+ // step将两个数都转化为整数至少小数点后移多少位
|
|
|
+ const step = Math.pow(10, maxLen)
|
|
|
+
|
|
|
+ switch (symbol) {
|
|
|
+ case '+':
|
|
|
+ // toFixed()根据最小精度截取运算结果
|
|
|
+ result = ((num1 * step + num2 * step) / step).toFixed(maxLen)
|
|
|
+ break
|
|
|
+ case '-':
|
|
|
+ result = ((num1 * step - num2 * step) / step).toFixed(maxLen)
|
|
|
+ break
|
|
|
+ case '*':
|
|
|
+ result = (((num1 * step) * (num2 * step)) / step / step).toFixed(maxLen)
|
|
|
+ break
|
|
|
+ case '/':
|
|
|
+ result = ((num1 * step) / (num2 * step)).toFixed(maxLen)
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ // 由于toFixed方法返回结果是字符串,还需要转回number输出
|
|
|
+ return Number(result)
|
|
|
+}
|
|
|
+
|
|
|
export default {
|
|
|
mixins: [mixin, orderItemMixin],
|
|
|
props: {
|
|
|
@@ -244,8 +295,8 @@ export default {
|
|
|
},
|
|
|
orderPrice () {
|
|
|
return this.value.reduce((init, item) => {
|
|
|
- let price = this.$NP.times(item.count, item.originalPrice)
|
|
|
- return this.$NP.plus(init, price, item.discountPrice ? item.discountPrice * item.tickets.length : 0)
|
|
|
+ let price = numCalc(item.count, item.originalPrice, '*')
|
|
|
+ return numCalc(init, numCalc(price, item.discountPrice ? numCalc(item.discountPrice, item.count, '*') : 0, '+'), '+')
|
|
|
}, 0)
|
|
|
},
|
|
|
tickets () {
|
|
|
@@ -277,6 +328,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ numCalc,
|
|
|
distinctOrder () {
|
|
|
if (this.tickets.length === 0) {
|
|
|
this.$message.warning('请先添加订单项')
|