Commit c4338a5e by cen

feat:新增向上取整

1 parent 71506557
...@@ -23,7 +23,27 @@ export default { ...@@ -23,7 +23,27 @@ export default {
methods: { methods: {
async getList () { async getList () {
const params = this.params const params = this.params
const data = [{ name: '正常订单', value: '1' }, { name: '打折策略', value: '2' }, { name: '买赠策略', value: '3' }, { name: '冲量活动', value: '4' }, { name: '组合付款', value: '5' }] // 默认支持所有订单类型
let data = [
{ name: '正常订单', value: '1' },
{ name: '打折策略', value: '2' },
{ name: '买赠策略', value: '3' },
{ name: '冲量活动', value: '4' },
{ name: '组合付款', value: '5' }
]
// 基于门店配置控制是否只允许“正常订单”
try {
const flag = uni?.$storage?.get && uni.$storage.get('createAllGoodsFlag')
// createAllGoodsFlag = 0:只能选择正常订单
if (flag === 0 || flag === '0') {
data = [{ name: '正常订单', value: '1' }]
}
} catch (e) {
// 读取失败时不影响默认行为
console.warn('read createAllGoodsFlag failed', e)
}
this.updateParams(params, data || []) this.updateParams(params, data || [])
}, },
initData (list) { initData (list) {
......
const target = ['ip', 'dev', 'uat', 'prod', 'beta'] const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 3 const index = 2
/** /**
* *
0本地 0本地
......
...@@ -292,26 +292,18 @@ export default { ...@@ -292,26 +292,18 @@ export default {
// - 打折策略(2)、买赠策略(3)、组合付款(5):使用 finalPrice(优惠后价格) // - 打折策略(2)、买赠策略(3)、组合付款(5):使用 finalPrice(优惠后价格)
const orderType = e.djOrderType || data.djOrderType const orderType = e.djOrderType || data.djOrderType
if (orderType === 1 || orderType === 4) { if (orderType === 1 || orderType === 4) {
// 正常订单或冲量活动,使用原价 // 正常订单或冲量活动,使用原价(向上取整保留2位小数)
if (e.totalPrice !== undefined && e.totalPrice !== null) { if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = Number( e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1)).toFixed(2)
utils.decimal(Number(e.totalPrice) / Number(e.number || 1), 2)
).toFixed(2)
} else if (e.finalPrice !== undefined && e.finalPrice !== null) { } else if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.price = Number( e.price = utils.ceilDecimal(Number(e.finalPrice) / Number(e.number || 1)).toFixed(2)
utils.decimal(Number(e.finalPrice) / Number(e.number || 1), 2)
).toFixed(2)
} }
} else { } else {
// 优惠类型订单,使用优惠后价格 // 优惠类型订单,使用优惠后价格(向上取整保留2位小数)
if (e.finalPrice !== undefined && e.finalPrice !== null) { if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.price = Number( e.price = utils.ceilDecimal(Number(e.finalPrice) / Number(e.number || 1)).toFixed(2)
utils.decimal(Number(e.finalPrice) / Number(e.number || 1), 2)
).toFixed(2)
} else if (e.totalPrice !== undefined && e.totalPrice !== null) { } else if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = Number( e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1)).toFixed(2)
utils.decimal(Number(e.totalPrice) / Number(e.number || 1), 2)
).toFixed(2)
} }
} }
e.positionStr = this.positionTypeList.filter(v => v.positionValue == e.upgradeGoodsPosition)[0]?.positionName || '' e.positionStr = this.positionTypeList.filter(v => v.positionValue == e.upgradeGoodsPosition)[0]?.positionName || ''
...@@ -326,24 +318,24 @@ export default { ...@@ -326,24 +318,24 @@ export default {
// 获取订单类型(优先使用套餐内商品的订单类型,否则使用订单级别的) // 获取订单类型(优先使用套餐内商品的订单类型,否则使用订单级别的)
const orderType = item.packageGoodsOrderList?.[0]?.djOrderType || data.djOrderType const orderType = item.packageGoodsOrderList?.[0]?.djOrderType || data.djOrderType
item.packageGoodsOrderList.forEach(g => { item.packageGoodsOrderList.forEach(g => {
// 根据订单类型决定使用哪个价格 // 根据订单类型决定使用哪个价格,并对商品单价向上取整保留两位小数
if (orderType === 1 || orderType === 4) { if (orderType === 1 || orderType === 4) {
// 正常订单或冲量活动,使用原价 // 正常订单或冲量活动,使用原价
if (g.totalPrice !== undefined && g.totalPrice !== null) { if (g.totalPrice !== undefined && g.totalPrice !== null) {
g.price = Number(g.totalPrice) / Number(g.number || 1) g.price = utils.ceilDecimal(Number(g.totalPrice) / Number(g.number || 1)).toFixed(2)
} else if (g.finalPrice !== undefined && g.finalPrice !== null) { } else if (g.finalPrice !== undefined && g.finalPrice !== null) {
g.price = Number(g.finalPrice) / Number(g.number || 1) g.price = utils.ceilDecimal(Number(g.finalPrice) / Number(g.number || 1)).toFixed(2)
} else { } else {
g.price = g.upgradePrice || 0 g.price = utils.ceilDecimal(g.upgradePrice || 0).toFixed(2)
} }
} else { } else {
// 优惠类型订单,使用优惠后价格 // 优惠类型订单,使用优惠后价格
if (g.finalPrice !== undefined && g.finalPrice !== null) { if (g.finalPrice !== undefined && g.finalPrice !== null) {
g.price = Number(g.finalPrice) / Number(g.number || 1) g.price = utils.ceilDecimal(Number(g.finalPrice) / Number(g.number || 1)).toFixed(2)
} else if (g.totalPrice !== undefined && g.totalPrice !== null) { } else if (g.totalPrice !== undefined && g.totalPrice !== null) {
g.price = Number(g.totalPrice) / Number(g.number || 1) g.price = utils.ceilDecimal(Number(g.totalPrice) / Number(g.number || 1)).toFixed(2)
} else { } else {
g.price = g.upgradePrice || 0 g.price = utils.ceilDecimal(g.upgradePrice || 0).toFixed(2)
} }
} }
}) })
...@@ -351,22 +343,12 @@ export default { ...@@ -351,22 +343,12 @@ export default {
// 套餐价格根据订单类型计算 // 套餐价格根据订单类型计算
item.price = item.goodsList.reduce((prev, cur) => { item.price = item.goodsList.reduce((prev, cur) => {
// 根据订单类型决定使用哪个价格 // 根据订单类型决定使用哪个价格
const unitPrice = (orderType === 1 || orderType === 4) const unitPrice = orderType === 1 || orderType === 4 ? (cur.totalPrice !== undefined && cur.totalPrice !== null ? Number(cur.totalPrice) / Number(cur.number || 1) : cur.finalPrice !== undefined && cur.finalPrice !== null ? Number(cur.finalPrice) / Number(cur.number || 1) : cur.price || 0) : cur.finalPrice !== undefined && cur.finalPrice !== null ? Number(cur.finalPrice) / Number(cur.number || 1) : cur.totalPrice !== undefined && cur.totalPrice !== null ? Number(cur.totalPrice) / Number(cur.number || 1) : cur.price || 0
? (cur.totalPrice !== undefined && cur.totalPrice !== null
? Number(cur.totalPrice) / Number(cur.number || 1)
: (cur.finalPrice !== undefined && cur.finalPrice !== null
? Number(cur.finalPrice) / Number(cur.number || 1)
: cur.price || 0))
: (cur.finalPrice !== undefined && cur.finalPrice !== null
? Number(cur.finalPrice) / Number(cur.number || 1)
: (cur.totalPrice !== undefined && cur.totalPrice !== null
? Number(cur.totalPrice) / Number(cur.number || 1)
: cur.price || 0))
return prev + unitPrice return prev + unitPrice
}, 0) }, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1 item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count let total = item.price * item.count
item.finalPrice = utils.decimal(total, 2) item.finalPrice = total
item.packageGoodsOrderList.forEach(g => { item.packageGoodsOrderList.forEach(g => {
g.positionStr = this.positionTypeList.filter(v => v.positionValue == g.upgradeGoodsPosition)[0]?.positionName || '' g.positionStr = this.positionTypeList.filter(v => v.positionValue == g.upgradeGoodsPosition)[0]?.positionName || ''
}) })
...@@ -584,7 +566,7 @@ export default { ...@@ -584,7 +566,7 @@ export default {
if (data) { if (data) {
console.log(`类型为:${selectPayType}`) console.log(`类型为:${selectPayType}`)
console.log(this.orderInfo) console.log(this.orderInfo)
console.log(data,'data') console.log(data, 'data')
if (selectPayType == 3 || selectPayType == 1) { if (selectPayType == 3 || selectPayType == 1) {
// 确保 orderInfo 和 payOrder 对象存在,避免空指针错误 // 确保 orderInfo 和 payOrder 对象存在,避免空指针错误
if (!this.orderInfo) { if (!this.orderInfo) {
......
...@@ -877,7 +877,7 @@ export default { ...@@ -877,7 +877,7 @@ export default {
if (e.specificationData.indexOf(';~;') == -1) { if (e.specificationData.indexOf(';~;') == -1) {
// 修复取值字段名字错误问题 // 修复取值字段名字错误问题
if (!e.price) { if (!e.price) {
e.price = utils.decimal(Number(e.totalPrice / e.number), 2) e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1))
//最低价 //最低价
} }
e.sellPrice = e.price e.sellPrice = e.price
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
</template> </template>
<script> <script>
import utils from '@/utils/utils'
export default { export default {
name: 'OrderStrategy', name: 'OrderStrategy',
props: { props: {
...@@ -127,17 +128,17 @@ export default { ...@@ -127,17 +128,17 @@ export default {
// 折扣比例:0.1-10,表示 0.1 折到 10 折(即 0.01 到 1.0) // 折扣比例:0.1-10,表示 0.1 折到 10 折(即 0.01 到 1.0)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10) const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} else if (this.localState.mode === 'amount' && this.localState.discountAmount) { } else if (this.localState.mode === 'amount' && this.localState.discountAmount) {
const discountAmount = parseFloat(this.localState.discountAmount) const discountAmount = parseFloat(this.localState.discountAmount)
// 折扣金额:0.01 到不能大于基础价格 // 折扣金额:0.01 到不能大于基础价格
if (discountAmount >= 0.01 && discountAmount <= basePrice) { if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// 买赠策略 // 买赠策略
...@@ -145,7 +146,7 @@ export default { ...@@ -145,7 +146,7 @@ export default {
if (this.localState.isGift === '1') { if (this.localState.isGift === '1') {
return '¥0.00' return '¥0.00'
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// 组合付款 // 组合付款
...@@ -155,13 +156,13 @@ export default { ...@@ -155,13 +156,13 @@ export default {
// 抵扣金额:0.01 到不能大于基础价格 // 抵扣金额:0.01 到不能大于基础价格
if (deductAmount >= 0.01 && deductAmount <= basePrice) { if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
}, },
watch: { watch: {
...@@ -254,15 +255,15 @@ export default { ...@@ -254,15 +255,15 @@ export default {
if (this.localState.mode === 'ratio' && this.localState.discountRatio) { if (this.localState.mode === 'ratio' && this.localState.discountRatio) {
const ratio = parseFloat(this.localState.discountRatio) const ratio = parseFloat(this.localState.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
return Math.round(bp * (ratio / 10) * 100) / 100 return utils.ceilDecimal(bp * (ratio / 10))
} }
} else if (this.localState.mode === 'amount' && this.localState.discountAmount) { } else if (this.localState.mode === 'amount' && this.localState.discountAmount) {
const discountAmount = parseFloat(this.localState.discountAmount) const discountAmount = parseFloat(this.localState.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= bp) { if (discountAmount >= 0.01 && discountAmount <= bp) {
return Math.round((bp - discountAmount) * 100) / 100 return utils.ceilDecimal(bp - discountAmount)
} }
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
} }
// 买赠策略 // 买赠策略
...@@ -270,7 +271,7 @@ export default { ...@@ -270,7 +271,7 @@ export default {
if (this.localState.isGift === '1') { if (this.localState.isGift === '1') {
return 0 return 0
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
} }
// 组合付款 // 组合付款
...@@ -278,13 +279,13 @@ export default { ...@@ -278,13 +279,13 @@ export default {
if (this.localState.mode === 'deduct' && this.localState.deductAmount) { if (this.localState.mode === 'deduct' && this.localState.deductAmount) {
const deductAmount = parseFloat(this.localState.deductAmount) const deductAmount = parseFloat(this.localState.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= bp) { if (deductAmount >= 0.01 && deductAmount <= bp) {
return Math.round((bp - deductAmount) * 100) / 100 return utils.ceilDecimal(bp - deductAmount)
} }
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
}, },
// 失去焦点时格式化(跟价格输入框一样的逻辑) // 失去焦点时格式化(跟价格输入框一样的逻辑)
onBlur(key) { onBlur(key) {
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
</view> </view>
</template> </template>
<script> <script>
import utils from '@/utils/utils'
import OrderStrategy from './OrderStrategy.vue' import OrderStrategy from './OrderStrategy.vue'
export default { export default {
...@@ -256,12 +257,12 @@ export default { ...@@ -256,12 +257,12 @@ export default {
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) { if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
const ratio = parseFloat(strategyConfig.discountRatio) const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
finalPricePerUnit = Math.round(sellPrice * (ratio / 10) * 100) / 100 finalPricePerUnit = utils.ceilDecimal(sellPrice * (ratio / 10))
} }
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) { } else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount) const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= sellPrice) { if (discountAmount >= 0.01 && discountAmount <= sellPrice) {
finalPricePerUnit = Math.round((sellPrice - discountAmount) * 100) / 100 finalPricePerUnit = utils.ceilDecimal(sellPrice - discountAmount)
} }
} }
} }
...@@ -278,7 +279,7 @@ export default { ...@@ -278,7 +279,7 @@ export default {
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) { if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
const deductAmount = parseFloat(strategyConfig.deductAmount) const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= sellPrice) { if (deductAmount >= 0.01 && deductAmount <= sellPrice) {
finalPricePerUnit = Math.round((sellPrice - deductAmount) * 100) / 100 finalPricePerUnit = utils.ceilDecimal(sellPrice - deductAmount)
} }
} }
} }
...@@ -316,7 +317,7 @@ export default { ...@@ -316,7 +317,7 @@ export default {
if (!goods) return 0 if (!goods) return 0
const sellPrice = parseFloat(goods.sellPrice || 0) const sellPrice = parseFloat(goods.sellPrice || 0)
// 四舍五入保留两位小数 // 四舍五入保留两位小数
return Math.round(sellPrice * 100) / 100 return utils.ceilDecimal(sellPrice)
}, },
// 计算最终显示价格 // 计算最终显示价格
getDisplayPrice(goods, item) { getDisplayPrice(goods, item) {
...@@ -332,13 +333,13 @@ export default { ...@@ -332,13 +333,13 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio) const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10) const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) { } else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount) const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= basePrice) { if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + basePrice.toFixed(2)
...@@ -358,7 +359,7 @@ export default { ...@@ -358,7 +359,7 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount) const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= basePrice) { if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + basePrice.toFixed(2)
...@@ -372,7 +373,7 @@ export default { ...@@ -372,7 +373,7 @@ export default {
const packageItem = this.list.find(pkg => pkg.packageGoods.goodsList.includes(goods)) const packageItem = this.list.find(pkg => pkg.packageGoods.goodsList.includes(goods))
if (packageItem) { if (packageItem) {
const number = parseInt(packageItem.packageGoods.number || 1) const number = parseInt(packageItem.packageGoods.number || 1)
const totalFinalPrice = Math.round(finalPricePerUnit * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(finalPricePerUnit * number)
// 存储总价和单价优惠后的价格 // 存储总价和单价优惠后的价格
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
this.$set(goods, 'finalPricePerUnit', finalPricePerUnit) this.$set(goods, 'finalPricePerUnit', finalPricePerUnit)
...@@ -403,7 +404,7 @@ export default { ...@@ -403,7 +404,7 @@ export default {
// 按当前单价和套餐数量,重新计算无优惠时的 finalPrice // 按当前单价和套餐数量,重新计算无优惠时的 finalPrice
const unitPrice = parseFloat(goods.sellPrice || 0) const unitPrice = parseFloat(goods.sellPrice || 0)
const number = parseInt(item?.packageGoods?.number || 1) const number = parseInt(item?.packageGoods?.number || 1)
const totalFinalPrice = Math.round(unitPrice * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(unitPrice * number)
this.$set(goods, 'finalPricePerUnit', unitPrice) this.$set(goods, 'finalPricePerUnit', unitPrice)
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
}, },
...@@ -413,7 +414,7 @@ export default { ...@@ -413,7 +414,7 @@ export default {
if (item.packageGoods && item.packageGoods.goodsList) { if (item.packageGoods && item.packageGoods.goodsList) {
item.packageGoods.goodsList.forEach(goods => { item.packageGoods.goodsList.forEach(goods => {
if (goods.strategyConfig && goods.finalPricePerUnit !== undefined) { if (goods.strategyConfig && goods.finalPricePerUnit !== undefined) {
const totalFinalPrice = Math.round(goods.finalPricePerUnit * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(goods.finalPricePerUnit * number)
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
} }
}) })
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
</template> </template>
<script> <script>
import utils from '@/utils/utils'
import OrderStrategy from './OrderStrategy.vue' import OrderStrategy from './OrderStrategy.vue'
export default { export default {
...@@ -109,7 +110,7 @@ export default { ...@@ -109,7 +110,7 @@ export default {
if (!item || !item.goods) return 0 if (!item || !item.goods) return 0
const sellPrice = parseFloat(item.goods.sellPrice || 0) const sellPrice = parseFloat(item.goods.sellPrice || 0)
// 四舍五入保留两位小数 // 四舍五入保留两位小数
return Math.round(sellPrice * 100) / 100 return utils.ceilDecimal(sellPrice)
}, },
// 计算最终显示价格 // 计算最终显示价格
getDisplayPrice(item) { getDisplayPrice(item) {
...@@ -126,14 +127,14 @@ export default { ...@@ -126,14 +127,14 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio) const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10) const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) { } else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
// 折扣金额:0.01 到不能大于基础价格 // 折扣金额:0.01 到不能大于基础价格
const discountAmount = parseFloat(strategyConfig.discountAmount) const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= basePrice) { if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + basePrice.toFixed(2)
...@@ -154,7 +155,7 @@ export default { ...@@ -154,7 +155,7 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount) const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= basePrice) { if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + basePrice.toFixed(2)
...@@ -166,7 +167,7 @@ export default { ...@@ -166,7 +167,7 @@ export default {
onPriceChange(item, finalPricePerUnit) { onPriceChange(item, finalPricePerUnit) {
// 计算总价:单件优惠价 * 数量 // 计算总价:单件优惠价 * 数量
const number = parseInt(item.goods.number || 1) const number = parseInt(item.goods.number || 1)
const totalFinalPrice = Math.round(finalPricePerUnit * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(finalPricePerUnit * number)
// 存储总价 // 存储总价
this.$set(item.goods, 'finalPrice', totalFinalPrice) this.$set(item.goods, 'finalPrice', totalFinalPrice)
// 同时存储单价优惠后的价格,用于数量改变时重新计算 // 同时存储单价优惠后的价格,用于数量改变时重新计算
...@@ -178,7 +179,7 @@ export default { ...@@ -178,7 +179,7 @@ export default {
// 如果有优惠策略配置 // 如果有优惠策略配置
if (item.goods.strategyConfig && item.goods.finalPricePerUnit !== undefined) { if (item.goods.strategyConfig && item.goods.finalPricePerUnit !== undefined) {
const number = parseInt(item.goods.number || 1) const number = parseInt(item.goods.number || 1)
const totalFinalPrice = Math.round(item.goods.finalPricePerUnit * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(item.goods.finalPricePerUnit * number)
this.$set(item.goods, 'finalPrice', totalFinalPrice) this.$set(item.goods, 'finalPrice', totalFinalPrice)
} }
}, },
...@@ -353,7 +354,7 @@ export default { ...@@ -353,7 +354,7 @@ export default {
// 按当前单价和数量,重新计算无优惠时的 finalPrice // 按当前单价和数量,重新计算无优惠时的 finalPrice
const unitPrice = parseFloat(goods.sellPrice || 0) const unitPrice = parseFloat(goods.sellPrice || 0)
const number = parseInt(goods.number || 1) const number = parseInt(goods.number || 1)
const totalFinalPrice = Math.round(unitPrice * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(unitPrice * number)
this.$set(goods, 'finalPricePerUnit', unitPrice) this.$set(goods, 'finalPricePerUnit', unitPrice)
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
}, },
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
</template> </template>
<script> <script>
import utils from '@/utils/utils'
import OrderStrategy from './OrderStrategy.vue' import OrderStrategy from './OrderStrategy.vue'
export default { export default {
...@@ -359,7 +360,7 @@ export default { ...@@ -359,7 +360,7 @@ export default {
} else if (item.goods && item.goods.number) { } else if (item.goods && item.goods.number) {
number = parseInt(item.goods.number || 1) number = parseInt(item.goods.number || 1)
} }
const totalFinalPrice = Math.round(unitPrice * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(unitPrice * number)
this.$set(goods, 'finalPricePerUnit', unitPrice) this.$set(goods, 'finalPricePerUnit', unitPrice)
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
}, },
...@@ -409,8 +410,8 @@ export default { ...@@ -409,8 +410,8 @@ export default {
sellPrice = parseFloat(item.goods.sellPrice || 0) sellPrice = parseFloat(item.goods.sellPrice || 0)
} }
// 四舍五入保留两位小数 // 向上取整保留两位小数
return Math.round(sellPrice * 100) / 100 return utils.ceilDecimal(sellPrice)
}, },
// 计算最终显示价格 // 计算最终显示价格
getDisplayPrice(item) { getDisplayPrice(item) {
...@@ -426,16 +427,16 @@ export default { ...@@ -426,16 +427,16 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio) const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10) const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) { } else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount) const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= basePrice) { if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// '3' 买赠策略 // '3' 买赠策略
...@@ -443,7 +444,7 @@ export default { ...@@ -443,7 +444,7 @@ export default {
if (strategyConfig.isGift === '1') { if (strategyConfig.isGift === '1') {
return '¥0.00' return '¥0.00'
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// '5' 组合付款 // '5' 组合付款
...@@ -452,13 +453,13 @@ export default { ...@@ -452,13 +453,13 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount) const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= basePrice) { if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
}, },
// 价格变化回调(finalPrice 是单件商品优惠后的价格,需要乘以数量得到总价) // 价格变化回调(finalPrice 是单件商品优惠后的价格,需要乘以数量得到总价)
onPriceChange(item, finalPricePerUnit) { onPriceChange(item, finalPricePerUnit) {
...@@ -466,12 +467,12 @@ export default { ...@@ -466,12 +467,12 @@ export default {
if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) { if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
number = parseInt(item.multipleSpecificationsGoods.number || 1) number = parseInt(item.multipleSpecificationsGoods.number || 1)
const totalFinalPrice = Math.round(finalPricePerUnit * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(finalPricePerUnit * number)
this.$set(item.multipleSpecificationsGoods.goods, 'finalPrice', totalFinalPrice) this.$set(item.multipleSpecificationsGoods.goods, 'finalPrice', totalFinalPrice)
this.$set(item.multipleSpecificationsGoods.goods, 'finalPricePerUnit', finalPricePerUnit) this.$set(item.multipleSpecificationsGoods.goods, 'finalPricePerUnit', finalPricePerUnit)
} else if (item.goods) { } else if (item.goods) {
number = parseInt(item.goods.number || 1) number = parseInt(item.goods.number || 1)
const totalFinalPrice = Math.round(finalPricePerUnit * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(finalPricePerUnit * number)
this.$set(item.goods, 'finalPrice', totalFinalPrice) this.$set(item.goods, 'finalPrice', totalFinalPrice)
this.$set(item.goods, 'finalPricePerUnit', finalPricePerUnit) this.$set(item.goods, 'finalPricePerUnit', finalPricePerUnit)
} }
...@@ -490,7 +491,7 @@ export default { ...@@ -490,7 +491,7 @@ export default {
} }
if (goods && goods.strategyConfig && goods.finalPricePerUnit !== undefined) { if (goods && goods.strategyConfig && goods.finalPricePerUnit !== undefined) {
const totalFinalPrice = Math.round(goods.finalPricePerUnit * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(goods.finalPricePerUnit * number)
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
} }
}, },
......
...@@ -459,16 +459,21 @@ export default { ...@@ -459,16 +459,21 @@ export default {
} }
}, },
async getShopMerchantPointConfig() { async getShopMerchantPointConfig() {
const { shopMerchantId: merchantId } = this.userInfo, const { shopMerchantId: merchantId } = this.userInfo
{ pointsMultiRole } = await uni.$api.equityApi.getShopMerchantPointConfig({ const { pointsMultiRole, createAllGoodsFlag } = await uni.$api.equityApi.getShopMerchantPointConfig({
merchantId merchantId
}) })
this.pointsMultiRole = pointsMultiRole this.pointsMultiRole = pointsMultiRole
if (pointsMultiRole != 'Y') if (pointsMultiRole != 'Y') {
this.formList[0].map(e => { this.formList[0].map(e => {
if (e.value == 'deliveryName') e.hidden = true if (e.value == 'deliveryName') e.hidden = true
if (e.value == 'referrer') e.label = '推荐人' if (e.value == 'referrer') e.label = '推荐人'
}) })
}
// 订单类型配置:createAllGoodsFlag = 1 显示全部类型;0 仅正常订单
if (createAllGoodsFlag !== undefined && createAllGoodsFlag !== null) {
uni.$storage.set('createAllGoodsFlag', createAllGoodsFlag)
}
}, },
// 选择行事件 // 选择行事件
handleCell(val) { handleCell(val) {
...@@ -856,13 +861,13 @@ export default { ...@@ -856,13 +861,13 @@ export default {
}) })
}) })
}, },
// 计算最终价格(优惠后的总价,单位:元) // 计算最终价格(优惠后的总价,单位:元),向上取整保留2位小数
calculateFinalPrice(goods, sellPrice, number, orderTypeCode) { calculateFinalPrice(goods, sellPrice, number, orderTypeCode) {
const price = parseFloat(sellPrice || 0) const price = parseFloat(sellPrice || 0)
const qty = parseInt(number || 1) const qty = parseInt(number || 1)
if (!price || !orderTypeCode) { if (!price || !orderTypeCode) {
return Math.round(price * qty * 100) / 100 return utils.ceilDecimal(price * qty)
} }
const orderType = String(orderTypeCode || '') const orderType = String(orderTypeCode || '')
...@@ -874,16 +879,16 @@ export default { ...@@ -874,16 +879,16 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio) const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
// 单价 * 折扣比例 * 数量 // 单价 * 折扣比例 * 数量
return Math.round(price * (ratio / 10) * qty * 100) / 100 return utils.ceilDecimal(price * (ratio / 10) * qty)
} }
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) { } else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount) const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= price) { if (discountAmount >= 0.01 && discountAmount <= price) {
// (单价 - 折扣金额) * 数量 // (单价 - 折扣金额) * 数量
return Math.round((price - discountAmount) * qty * 100) / 100 return utils.ceilDecimal((price - discountAmount) * qty)
} }
} }
return Math.round(price * qty * 100) / 100 return utils.ceilDecimal(price * qty)
} }
// '3' 买赠策略 // '3' 买赠策略
...@@ -891,7 +896,7 @@ export default { ...@@ -891,7 +896,7 @@ export default {
if (strategyConfig.isGift === '1') { if (strategyConfig.isGift === '1') {
return 0 return 0
} }
return Math.round(price * qty * 100) / 100 return utils.ceilDecimal(price * qty)
} }
// '5' 组合付款 // '5' 组合付款
...@@ -900,14 +905,14 @@ export default { ...@@ -900,14 +905,14 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount) const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= price) { if (deductAmount >= 0.01 && deductAmount <= price) {
// (单价 - 抵扣金额) * 数量 // (单价 - 抵扣金额) * 数量
return Math.round((price - deductAmount) * qty * 100) / 100 return utils.ceilDecimal((price - deductAmount) * qty)
} }
} }
return Math.round(price * qty * 100) / 100 return utils.ceilDecimal(price * qty)
} }
// '1' 正常订单、'4' 冲量活动:原价 // '1' 正常订单、'4' 冲量活动:原价
return Math.round(price * qty * 100) / 100 return utils.ceilDecimal(price * qty)
}, },
// 计算优惠相关字段(discountType, discountValue) // 计算优惠相关字段(discountType, discountValue)
calculateDiscountFields(goods, sellPrice, number, orderTypeCode) { calculateDiscountFields(goods, sellPrice, number, orderTypeCode) {
...@@ -995,6 +1000,7 @@ export default { ...@@ -995,6 +1000,7 @@ export default {
const hasValidFinalPrice = item.finalPrice !== undefined && item.finalPrice !== null && !isNaN(parseFloat(item.finalPrice)) const hasValidFinalPrice = item.finalPrice !== undefined && item.finalPrice !== null && !isNaN(parseFloat(item.finalPrice))
const finalPrice = hasValidFinalPrice ? parseFloat(item.finalPrice) : this.calculateFinalPrice(item, sellPrice, number, orderInfo.orderTypeCode) const finalPrice = hasValidFinalPrice ? parseFloat(item.finalPrice) : this.calculateFinalPrice(item, sellPrice, number, orderInfo.orderTypeCode)
const discountFields = this.calculateDiscountFields(item, sellPrice, number, orderInfo.orderTypeCode) const discountFields = this.calculateDiscountFields(item, sellPrice, number, orderInfo.orderTypeCode)
const unitFinalPrice = finalPrice / number
const obj = { const obj = {
goodsId: item.merchantGoodsId, goodsId: item.merchantGoodsId,
goodsName: item.goodsName, goodsName: item.goodsName,
...@@ -1004,6 +1010,8 @@ export default { ...@@ -1004,6 +1010,8 @@ export default {
goodsPrice: this.multipliedByHundred(item.sellPrice), goodsPrice: this.multipliedByHundred(item.sellPrice),
// 后端使用“分”单位,这里将元转为分 // 后端使用“分”单位,这里将元转为分
finalPrice: this.multipliedByHundred(finalPrice), finalPrice: this.multipliedByHundred(finalPrice),
// 商品实付单价(向上取整保留两位,单位:分)
singleProductFinalPrice: this.multipliedByHundred(utils.ceilDecimal(unitFinalPrice)),
discountType: discountFields.discountType, discountType: discountFields.discountType,
discountValue: discountFields.discountValue discountValue: discountFields.discountValue
} }
...@@ -1018,6 +1026,7 @@ export default { ...@@ -1018,6 +1026,7 @@ export default {
const hasValidFinalPrice = ele.finalPrice !== undefined && ele.finalPrice !== null && !isNaN(parseFloat(ele.finalPrice)) const hasValidFinalPrice = ele.finalPrice !== undefined && ele.finalPrice !== null && !isNaN(parseFloat(ele.finalPrice))
const finalPrice = hasValidFinalPrice ? parseFloat(ele.finalPrice) : this.calculateFinalPrice(ele, sellPrice, number, orderInfo.orderTypeCode) const finalPrice = hasValidFinalPrice ? parseFloat(ele.finalPrice) : this.calculateFinalPrice(ele, sellPrice, number, orderInfo.orderTypeCode)
const discountFields = this.calculateDiscountFields(ele, sellPrice, number, orderInfo.orderTypeCode) const discountFields = this.calculateDiscountFields(ele, sellPrice, number, orderInfo.orderTypeCode)
const unitFinalPrice = finalPrice / number
let obj = { let obj = {
packageId: item.packageCode, packageId: item.packageCode,
packageName: item.packageName, packageName: item.packageName,
...@@ -1029,6 +1038,7 @@ export default { ...@@ -1029,6 +1038,7 @@ export default {
specificationsValue: ele.specificationData ? ele.specificationData.replace(/;~;/g, '/') : '', specificationsValue: ele.specificationData ? ele.specificationData.replace(/;~;/g, '/') : '',
goodsPrice: this.multipliedByHundred(ele.sellPrice), goodsPrice: this.multipliedByHundred(ele.sellPrice),
finalPrice: this.multipliedByHundred(finalPrice), finalPrice: this.multipliedByHundred(finalPrice),
singleProductFinalPrice: this.multipliedByHundred(utils.ceilDecimal(unitFinalPrice)),
discountType: discountFields.discountType, discountType: discountFields.discountType,
discountValue: discountFields.discountValue discountValue: discountFields.discountValue
} }
...@@ -1044,6 +1054,7 @@ export default { ...@@ -1044,6 +1054,7 @@ export default {
const hasValidFinalPrice = goods.finalPrice !== undefined && goods.finalPrice !== null && !isNaN(parseFloat(goods.finalPrice)) const hasValidFinalPrice = goods.finalPrice !== undefined && goods.finalPrice !== null && !isNaN(parseFloat(goods.finalPrice))
const finalPrice = hasValidFinalPrice ? parseFloat(goods.finalPrice) : this.calculateFinalPrice(goods, sellPrice, number, orderInfo.orderTypeCode) const finalPrice = hasValidFinalPrice ? parseFloat(goods.finalPrice) : this.calculateFinalPrice(goods, sellPrice, number, orderInfo.orderTypeCode)
const discountFields = this.calculateDiscountFields(goods, sellPrice, number, orderInfo.orderTypeCode) const discountFields = this.calculateDiscountFields(goods, sellPrice, number, orderInfo.orderTypeCode)
const unitFinalPrice = finalPrice / number
const obj = { const obj = {
goodsId: goods.merchantGoodsId, goodsId: goods.merchantGoodsId,
goodsName: goods.upgradeGoodsName || goods.goodsName, goodsName: goods.upgradeGoodsName || goods.goodsName,
...@@ -1052,6 +1063,7 @@ export default { ...@@ -1052,6 +1063,7 @@ export default {
specificationsValue: goods.specificationData ? goods.specificationData.replace(/;~;/g, '/') : '', specificationsValue: goods.specificationData ? goods.specificationData.replace(/;~;/g, '/') : '',
goodsPrice: this.multipliedByHundred(goods.sellPrice), goodsPrice: this.multipliedByHundred(goods.sellPrice),
finalPrice: this.multipliedByHundred(finalPrice), finalPrice: this.multipliedByHundred(finalPrice),
singleProductFinalPrice: this.multipliedByHundred(utils.ceilDecimal(unitFinalPrice)),
discountType: discountFields.discountType, discountType: discountFields.discountType,
discountValue: discountFields.discountValue discountValue: discountFields.discountValue
} }
...@@ -1149,8 +1161,8 @@ export default { ...@@ -1149,8 +1161,8 @@ export default {
} }
}) })
console.log(total, 'total') console.log(total, 'total')
// 更新总价(单位:元,保留两位小数) // 更新总价(单位:元,向上取整保留两位小数)
this.orderObj.total = (Math.round(total * 100) / 100).toFixed(2) this.orderObj.total = utils.ceilDecimal(total).toFixed(2)
}, },
// 获取园区店支付方式 // 获取园区店支付方式
......
...@@ -282,7 +282,7 @@ export default { ...@@ -282,7 +282,7 @@ export default {
// 待上传协议状态也支持撤销 // 待上传协议状态也支持撤销
if (order.payType == 1) { if (order.payType == 1) {
// 线上支付显示"错误工单" // 线上支付显示"错误工单"
config.secondaryButtons.push({ text: '错误工单', type: 'secondary', dataType: 'error' }) // config.secondaryButtons.push({ text: '错误工单', type: 'secondary', dataType: 'error' })
} else { } else {
// 非线上支付显示"撤销工单" // 非线上支付显示"撤销工单"
config.secondaryButtons.push({ text: '撤销工单', type: 'secondary', dataType: 'revoke' }) config.secondaryButtons.push({ text: '撤销工单', type: 'secondary', dataType: 'revoke' })
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
</template> </template>
<script> <script>
import utils from '@/utils/utils'
export default { export default {
name: 'OrderStrategy', name: 'OrderStrategy',
props: { props: {
...@@ -127,17 +128,17 @@ export default { ...@@ -127,17 +128,17 @@ export default {
// 折扣比例:0.1-10,表示 0.1 折到 10 折(即 0.01 到 1.0) // 折扣比例:0.1-10,表示 0.1 折到 10 折(即 0.01 到 1.0)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10) const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} else if (this.localState.mode === 'amount' && this.localState.discountAmount) { } else if (this.localState.mode === 'amount' && this.localState.discountAmount) {
const discountAmount = parseFloat(this.localState.discountAmount) const discountAmount = parseFloat(this.localState.discountAmount)
// 折扣金额:0.01 到不能大于基础价格 // 折扣金额:0.01 到不能大于基础价格
if (discountAmount >= 0.01 && discountAmount <= basePrice) { if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// 买赠策略 // 买赠策略
...@@ -145,7 +146,7 @@ export default { ...@@ -145,7 +146,7 @@ export default {
if (this.localState.isGift === '1') { if (this.localState.isGift === '1') {
return '¥0.00' return '¥0.00'
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// 组合付款 // 组合付款
...@@ -155,13 +156,13 @@ export default { ...@@ -155,13 +156,13 @@ export default {
// 抵扣金额:0.01 到不能大于基础价格 // 抵扣金额:0.01 到不能大于基础价格
if (deductAmount >= 0.01 && deductAmount <= basePrice) { if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
}, },
watch: { watch: {
...@@ -254,15 +255,15 @@ export default { ...@@ -254,15 +255,15 @@ export default {
if (this.localState.mode === 'ratio' && this.localState.discountRatio) { if (this.localState.mode === 'ratio' && this.localState.discountRatio) {
const ratio = parseFloat(this.localState.discountRatio) const ratio = parseFloat(this.localState.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
return Math.round(bp * (ratio / 10) * 100) / 100 return utils.ceilDecimal(bp * (ratio / 10))
} }
} else if (this.localState.mode === 'amount' && this.localState.discountAmount) { } else if (this.localState.mode === 'amount' && this.localState.discountAmount) {
const discountAmount = parseFloat(this.localState.discountAmount) const discountAmount = parseFloat(this.localState.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= bp) { if (discountAmount >= 0.01 && discountAmount <= bp) {
return Math.round((bp - discountAmount) * 100) / 100 return utils.ceilDecimal(bp - discountAmount)
} }
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
} }
// 买赠策略 // 买赠策略
...@@ -270,7 +271,7 @@ export default { ...@@ -270,7 +271,7 @@ export default {
if (this.localState.isGift === '1') { if (this.localState.isGift === '1') {
return 0 return 0
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
} }
// 组合付款 // 组合付款
...@@ -278,13 +279,13 @@ export default { ...@@ -278,13 +279,13 @@ export default {
if (this.localState.mode === 'deduct' && this.localState.deductAmount) { if (this.localState.mode === 'deduct' && this.localState.deductAmount) {
const deductAmount = parseFloat(this.localState.deductAmount) const deductAmount = parseFloat(this.localState.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= bp) { if (deductAmount >= 0.01 && deductAmount <= bp) {
return Math.round((bp - deductAmount) * 100) / 100 return utils.ceilDecimal(bp - deductAmount)
} }
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
} }
return Math.round(bp * 100) / 100 return utils.ceilDecimal(bp)
}, },
// 失去焦点时格式化(跟价格输入框一样的逻辑) // 失去焦点时格式化(跟价格输入框一样的逻辑)
onBlur(key) { onBlur(key) {
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
</view> </view>
</template> </template>
<script> <script>
import utils from '@/utils/utils'
export default { export default {
name: 'Package', name: 'Package',
props: { props: {
...@@ -199,7 +200,7 @@ export default { ...@@ -199,7 +200,7 @@ export default {
// 按当前单价和套餐数量,重新计算无优惠时的 finalPrice // 按当前单价和套餐数量,重新计算无优惠时的 finalPrice
const unitPrice = parseFloat(goods.sellPrice || 0) const unitPrice = parseFloat(goods.sellPrice || 0)
const number = parseInt(item?.packageGoods?.number || 1) const number = parseInt(item?.packageGoods?.number || 1)
const totalFinalPrice = Math.round(unitPrice * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(unitPrice * number)
this.$set(goods, 'finalPricePerUnit', unitPrice) this.$set(goods, 'finalPricePerUnit', unitPrice)
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
} }
......
...@@ -82,6 +82,7 @@ ...@@ -82,6 +82,7 @@
</template> </template>
<script> <script>
import utils from '@/utils/utils'
import NP from 'number-precision' import NP from 'number-precision'
import OrderStrategy from './OrderStrategy.vue' import OrderStrategy from './OrderStrategy.vue'
...@@ -414,7 +415,7 @@ export default { ...@@ -414,7 +415,7 @@ export default {
number = parseInt(item.goods.number || 1) number = parseInt(item.goods.number || 1)
} }
const totalFinalPrice = Math.round(unitPrice * number * 100) / 100 const totalFinalPrice = utils.ceilDecimal(unitPrice * number)
this.$set(goods, 'finalPricePerUnit', unitPrice) this.$set(goods, 'finalPricePerUnit', unitPrice)
this.$set(goods, 'finalPrice', totalFinalPrice) this.$set(goods, 'finalPrice', totalFinalPrice)
}, },
...@@ -447,12 +448,12 @@ export default { ...@@ -447,12 +448,12 @@ export default {
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) { if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
const ratio = parseFloat(strategyConfig.discountRatio) const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
finalPricePerUnit = Math.round(sellPrice * (ratio / 10) * 100) / 100 finalPricePerUnit = utils.ceilDecimal(sellPrice * (ratio / 10))
} }
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) { } else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount) const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= sellPrice) { if (discountAmount >= 0.01 && discountAmount <= sellPrice) {
finalPricePerUnit = Math.round((sellPrice - discountAmount) * 100) / 100 finalPricePerUnit = utils.ceilDecimal(sellPrice - discountAmount)
} }
} }
} }
...@@ -469,7 +470,7 @@ export default { ...@@ -469,7 +470,7 @@ export default {
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) { if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
const deductAmount = parseFloat(strategyConfig.deductAmount) const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= sellPrice) { if (deductAmount >= 0.01 && deductAmount <= sellPrice) {
finalPricePerUnit = Math.round((sellPrice - deductAmount) * 100) / 100 finalPricePerUnit = utils.ceilDecimal(sellPrice - deductAmount)
} }
} }
} }
...@@ -479,7 +480,7 @@ export default { ...@@ -479,7 +480,7 @@ export default {
} }
}) })
item.packageGoods.totalPrice = total item.packageGoods.totalPrice = total
return total.toFixed(2) return utils.ceilDecimal(total).toFixed(2)
}, },
// 根据订单类型获取策略类型 // 根据订单类型获取策略类型
getStrategyType(item) { getStrategyType(item) {
...@@ -556,7 +557,7 @@ export default { ...@@ -556,7 +557,7 @@ export default {
} }
// 四舍五入保留两位小数 // 四舍五入保留两位小数
return Math.round(sellPrice * 100) / 100 return utils.ceilDecimal(sellPrice)
}, },
// 计算最终显示价格 // 计算最终显示价格
getDisplayPrice(item) { getDisplayPrice(item) {
...@@ -572,16 +573,16 @@ export default { ...@@ -572,16 +573,16 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio) const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && ratio <= 10) { if (ratio >= 0.1 && ratio <= 10) {
const finalPrice = basePrice * (ratio / 10) const finalPrice = basePrice * (ratio / 10)
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) { } else if (strategyConfig.mode === 'amount' && strategyConfig.discountAmount) {
const discountAmount = parseFloat(strategyConfig.discountAmount) const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= basePrice) { if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// '3' 买赠策略 // '3' 买赠策略
...@@ -589,7 +590,7 @@ export default { ...@@ -589,7 +590,7 @@ export default {
if (strategyConfig.isGift === '1') { if (strategyConfig.isGift === '1') {
return '¥0.00' return '¥0.00'
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
// '5' 组合付款 // '5' 组合付款
...@@ -598,13 +599,13 @@ export default { ...@@ -598,13 +599,13 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount) const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= basePrice) { if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2) return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
} }
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
} }
return '¥' + basePrice.toFixed(2) return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
}, },
// 价格变化回调(finalPricePerUnit 为单件优惠价,需要乘以数量得到总价,单位:元) // 价格变化回调(finalPricePerUnit 为单件优惠价,需要乘以数量得到总价,单位:元)
onPriceChange(item, finalPricePerUnit, packageItem) { onPriceChange(item, finalPricePerUnit, packageItem) {
...@@ -621,7 +622,7 @@ export default { ...@@ -621,7 +622,7 @@ export default {
number = parseInt(item.goods.number || 1) number = parseInt(item.goods.number || 1)
} }
const totalFinalPrice = Math.round(finalPricePerUnit * number * 100) / 100 // 元 const totalFinalPrice = utils.ceilDecimal(finalPricePerUnit * number) // 元
// 如果是套餐内的商品(直接是商品对象,有 sellPrice 等属性) // 如果是套餐内的商品(直接是商品对象,有 sellPrice 等属性)
if (item && item.sellPrice !== undefined && !item.goodsFlag) { if (item && item.sellPrice !== undefined && !item.goodsFlag) {
...@@ -629,7 +630,7 @@ export default { ...@@ -629,7 +630,7 @@ export default {
// 赠品 // 赠品
this.$set(item, 'finalPrice', 0) this.$set(item, 'finalPrice', 0)
} else { } else {
const originalTotal = Math.round(parseFloat(item.sellPrice || 0) * number * 100) / 100 const originalTotal = utils.ceilDecimal(parseFloat(item.sellPrice || 0) * number)
// 有优惠且不等于原价,保存优惠后的总价;否则置为 null // 有优惠且不等于原价,保存优惠后的总价;否则置为 null
if (totalFinalPrice < originalTotal) { if (totalFinalPrice < originalTotal) {
this.$set(item, 'finalPrice', totalFinalPrice) this.$set(item, 'finalPrice', totalFinalPrice)
...@@ -644,7 +645,7 @@ export default { ...@@ -644,7 +645,7 @@ export default {
if (totalFinalPrice === 0) { if (totalFinalPrice === 0) {
this.$set(item.multipleSpecificationsGoods.goods, 'finalPrice', 0) this.$set(item.multipleSpecificationsGoods.goods, 'finalPrice', 0)
} else { } else {
const originalTotal = Math.round(parseFloat(item.multipleSpecificationsGoods.goods.sellPrice || 0) * number * 100) / 100 const originalTotal = utils.ceilDecimal(parseFloat(item.multipleSpecificationsGoods.goods.sellPrice || 0) * number)
if (totalFinalPrice < originalTotal) { if (totalFinalPrice < originalTotal) {
this.$set(item.multipleSpecificationsGoods.goods, 'finalPrice', totalFinalPrice) this.$set(item.multipleSpecificationsGoods.goods, 'finalPrice', totalFinalPrice)
} else { } else {
...@@ -658,7 +659,7 @@ export default { ...@@ -658,7 +659,7 @@ export default {
if (totalFinalPrice === 0) { if (totalFinalPrice === 0) {
this.$set(item.goods, 'finalPrice', 0) this.$set(item.goods, 'finalPrice', 0)
} else { } else {
const originalTotal = Math.round(parseFloat(item.goods.sellPrice || 0) * number * 100) / 100 const originalTotal = utils.ceilDecimal(parseFloat(item.goods.sellPrice || 0) * number)
if (totalFinalPrice < originalTotal) { if (totalFinalPrice < originalTotal) {
this.$set(item.goods, 'finalPrice', totalFinalPrice) this.$set(item.goods, 'finalPrice', totalFinalPrice)
} else { } else {
......
...@@ -229,6 +229,15 @@ const decimal = (num, fixed) => { ...@@ -229,6 +229,15 @@ const decimal = (num, fixed) => {
return Math.round(num * pow) / pow return Math.round(num * pow) / pow
} }
/** 向上取整,保留 fixed 位小数(默认2位),用于商品价格、总价等 */
const ceilDecimal = (num, fixed = 2) => {
const n = Number(num)
if (isNaN(n)) return 0
const pow = Math.pow(10, fixed)
// 避免浮点误差导致的边界问题(如 1.005、256.693 等)
return Math.ceil((n + Number.EPSILON) * pow) / pow
}
const setPrice = price => { const setPrice = price => {
let [num, decimal] = price.toString().split('.') let [num, decimal] = price.toString().split('.')
if (!decimal) decimal = '00' if (!decimal) decimal = '00'
...@@ -273,21 +282,41 @@ const filterValue = (val, unit = '') => { ...@@ -273,21 +282,41 @@ const filterValue = (val, unit = '') => {
* 检测VIN码 * 检测VIN码
*/ */
function validateVIN(vin) { function validateVIN(vin) {
if (vin.length !== 17) return false; if (vin.length !== 17) return false
const weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]; const weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2]
const charMap = { const charMap = {
'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, A: 1,
'J': 1, 'K': 2, 'L': 3, 'M': 4, 'N': 5, 'P': 7, 'R': 9, 'S': 2, B: 2,
'T': 3, 'U': 4, 'V': 5, 'W': 6, 'X': 7, 'Y': 8, 'Z': 9 C: 3,
}; D: 4,
let sum = 0; E: 5,
F: 6,
G: 7,
H: 8,
J: 1,
K: 2,
L: 3,
M: 4,
N: 5,
P: 7,
R: 9,
S: 2,
T: 3,
U: 4,
V: 5,
W: 6,
X: 7,
Y: 8,
Z: 9
}
let sum = 0
for (let i = 0; i < 17; i++) { for (let i = 0; i < 17; i++) {
const char = vin[i].toUpperCase(); const char = vin[i].toUpperCase()
const value = charMap[char] || parseInt(char, 10); const value = charMap[char] || parseInt(char, 10)
sum += value * weights[i]; sum += value * weights[i]
} }
const checkDigit = (sum % 11) === 10 ? 'X' : (sum % 11).toString(); const checkDigit = sum % 11 === 10 ? 'X' : (sum % 11).toString()
return checkDigit === vin[8]; return checkDigit === vin[8]
} }
const nullValues = [undefined,'undefined',null,'null'] const nullValues = [undefined,'undefined',null,'null']
...@@ -309,6 +338,7 @@ export default { ...@@ -309,6 +338,7 @@ export default {
getViewInfo, getViewInfo,
setPrice, setPrice,
decimal, decimal,
ceilDecimal,
showNoAccess, showNoAccess,
setCopyData, setCopyData,
refreshPageData, refreshPageData,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!