Commit c4338a5e by cen

feat:新增向上取整

1 parent 71506557
......@@ -23,7 +23,27 @@ export default {
methods: {
async getList () {
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 || [])
},
initData (list) {
......
const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 3
const index = 2
/**
*
0本地
......
......@@ -292,26 +292,18 @@ export default {
// - 打折策略(2)、买赠策略(3)、组合付款(5):使用 finalPrice(优惠后价格)
const orderType = e.djOrderType || data.djOrderType
if (orderType === 1 || orderType === 4) {
// 正常订单或冲量活动,使用原价
// 正常订单或冲量活动,使用原价(向上取整保留2位小数)
if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.totalPrice) / Number(e.number || 1), 2)
).toFixed(2)
e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1)).toFixed(2)
} else if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.finalPrice) / Number(e.number || 1), 2)
).toFixed(2)
e.price = utils.ceilDecimal(Number(e.finalPrice) / Number(e.number || 1)).toFixed(2)
}
} else {
// 优惠类型订单,使用优惠后价格
// 优惠类型订单,使用优惠后价格(向上取整保留2位小数)
if (e.finalPrice !== undefined && e.finalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.finalPrice) / Number(e.number || 1), 2)
).toFixed(2)
e.price = utils.ceilDecimal(Number(e.finalPrice) / Number(e.number || 1)).toFixed(2)
} else if (e.totalPrice !== undefined && e.totalPrice !== null) {
e.price = Number(
utils.decimal(Number(e.totalPrice) / Number(e.number || 1), 2)
).toFixed(2)
e.price = utils.ceilDecimal(Number(e.totalPrice) / Number(e.number || 1)).toFixed(2)
}
}
e.positionStr = this.positionTypeList.filter(v => v.positionValue == e.upgradeGoodsPosition)[0]?.positionName || ''
......@@ -326,24 +318,24 @@ export default {
// 获取订单类型(优先使用套餐内商品的订单类型,否则使用订单级别的)
const orderType = item.packageGoodsOrderList?.[0]?.djOrderType || data.djOrderType
item.packageGoodsOrderList.forEach(g => {
// 根据订单类型决定使用哪个价格
// 根据订单类型决定使用哪个价格,并对商品单价向上取整保留两位小数
if (orderType === 1 || orderType === 4) {
// 正常订单或冲量活动,使用原价
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) {
g.price = Number(g.finalPrice) / Number(g.number || 1)
g.price = utils.ceilDecimal(Number(g.finalPrice) / Number(g.number || 1)).toFixed(2)
} else {
g.price = g.upgradePrice || 0
g.price = utils.ceilDecimal(g.upgradePrice || 0).toFixed(2)
}
} 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 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 {
g.price = g.upgradePrice || 0
g.price = utils.ceilDecimal(g.upgradePrice || 0).toFixed(2)
}
}
})
......@@ -351,22 +343,12 @@ export default {
// 套餐价格根据订单类型计算
item.price = item.goodsList.reduce((prev, cur) => {
// 根据订单类型决定使用哪个价格
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))
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
return prev + unitPrice
}, 0)
item.count = item.goodsList.length ? item.goodsList[0].number : 1
let total = item.price * item.count
item.finalPrice = utils.decimal(total, 2)
item.finalPrice = total
item.packageGoodsOrderList.forEach(g => {
g.positionStr = this.positionTypeList.filter(v => v.positionValue == g.upgradeGoodsPosition)[0]?.positionName || ''
})
......@@ -584,7 +566,7 @@ export default {
if (data) {
console.log(`类型为:${selectPayType}`)
console.log(this.orderInfo)
console.log(data,'data')
console.log(data, 'data')
if (selectPayType == 3 || selectPayType == 1) {
// 确保 orderInfo 和 payOrder 对象存在,避免空指针错误
if (!this.orderInfo) {
......
......@@ -58,6 +58,7 @@
</template>
<script>
import utils from '@/utils/utils'
export default {
name: 'OrderStrategy',
props: {
......@@ -127,17 +128,17 @@ export default {
// 折扣比例:0.1-10,表示 0.1 折到 10 折(即 0.01 到 1.0)
if (ratio >= 0.1 && 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) {
const discountAmount = parseFloat(this.localState.discountAmount)
// 折扣金额:0.01 到不能大于基础价格
if (discountAmount >= 0.01 && discountAmount <= basePrice) {
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 {
if (this.localState.isGift === '1') {
return '¥0.00'
}
return '¥' + basePrice.toFixed(2)
return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
}
// 组合付款
......@@ -155,13 +156,13 @@ export default {
// 抵扣金额:0.01 到不能大于基础价格
if (deductAmount >= 0.01 && deductAmount <= basePrice) {
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: {
......@@ -254,15 +255,15 @@ export default {
if (this.localState.mode === 'ratio' && this.localState.discountRatio) {
const ratio = parseFloat(this.localState.discountRatio)
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) {
const discountAmount = parseFloat(this.localState.discountAmount)
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 {
if (this.localState.isGift === '1') {
return 0
}
return Math.round(bp * 100) / 100
return utils.ceilDecimal(bp)
}
// 组合付款
......@@ -278,13 +279,13 @@ export default {
if (this.localState.mode === 'deduct' && this.localState.deductAmount) {
const deductAmount = parseFloat(this.localState.deductAmount)
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) {
......
......@@ -34,6 +34,7 @@
</view>
</template>
<script>
import utils from '@/utils/utils'
import OrderStrategy from './OrderStrategy.vue'
export default {
......@@ -256,12 +257,12 @@ export default {
if (strategyConfig.mode === 'ratio' && strategyConfig.discountRatio) {
const ratio = parseFloat(strategyConfig.discountRatio)
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) {
const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= sellPrice) {
finalPricePerUnit = Math.round((sellPrice - discountAmount) * 100) / 100
finalPricePerUnit = utils.ceilDecimal(sellPrice - discountAmount)
}
}
}
......@@ -278,7 +279,7 @@ export default {
if (strategyConfig.mode === 'deduct' && strategyConfig.deductAmount) {
const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= sellPrice) {
finalPricePerUnit = Math.round((sellPrice - deductAmount) * 100) / 100
finalPricePerUnit = utils.ceilDecimal(sellPrice - deductAmount)
}
}
}
......@@ -316,7 +317,7 @@ export default {
if (!goods) return 0
const sellPrice = parseFloat(goods.sellPrice || 0)
// 四舍五入保留两位小数
return Math.round(sellPrice * 100) / 100
return utils.ceilDecimal(sellPrice)
},
// 计算最终显示价格
getDisplayPrice(goods, item) {
......@@ -332,13 +333,13 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && 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) {
const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
......@@ -358,7 +359,7 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
......@@ -372,7 +373,7 @@ export default {
const packageItem = this.list.find(pkg => pkg.packageGoods.goodsList.includes(goods))
if (packageItem) {
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, 'finalPricePerUnit', finalPricePerUnit)
......@@ -403,7 +404,7 @@ export default {
// 按当前单价和套餐数量,重新计算无优惠时的 finalPrice
const unitPrice = parseFloat(goods.sellPrice || 0)
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, 'finalPrice', totalFinalPrice)
},
......@@ -413,7 +414,7 @@ export default {
if (item.packageGoods && item.packageGoods.goodsList) {
item.packageGoods.goodsList.forEach(goods => {
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)
}
})
......
......@@ -33,6 +33,7 @@
</template>
<script>
import utils from '@/utils/utils'
import OrderStrategy from './OrderStrategy.vue'
export default {
......@@ -109,7 +110,7 @@ export default {
if (!item || !item.goods) return 0
const sellPrice = parseFloat(item.goods.sellPrice || 0)
// 四舍五入保留两位小数
return Math.round(sellPrice * 100) / 100
return utils.ceilDecimal(sellPrice)
},
// 计算最终显示价格
getDisplayPrice(item) {
......@@ -126,14 +127,14 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && 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) {
// 折扣金额:0.01 到不能大于基础价格
const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= basePrice) {
const finalPrice = basePrice - discountAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
......@@ -154,7 +155,7 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= basePrice) {
const finalPrice = basePrice - deductAmount
return '¥' + (Math.round(finalPrice * 100) / 100).toFixed(2)
return '¥' + utils.ceilDecimal(finalPrice).toFixed(2)
}
}
return '¥' + basePrice.toFixed(2)
......@@ -166,7 +167,7 @@ export default {
onPriceChange(item, finalPricePerUnit) {
// 计算总价:单件优惠价 * 数量
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)
// 同时存储单价优惠后的价格,用于数量改变时重新计算
......@@ -178,7 +179,7 @@ export default {
// 如果有优惠策略配置
if (item.goods.strategyConfig && item.goods.finalPricePerUnit !== undefined) {
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)
}
},
......@@ -353,7 +354,7 @@ export default {
// 按当前单价和数量,重新计算无优惠时的 finalPrice
const unitPrice = parseFloat(goods.sellPrice || 0)
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, 'finalPrice', totalFinalPrice)
},
......
......@@ -60,6 +60,7 @@
</template>
<script>
import utils from '@/utils/utils'
import OrderStrategy from './OrderStrategy.vue'
export default {
......@@ -359,7 +360,7 @@ export default {
} else if (item.goods && item.goods.number) {
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, 'finalPrice', totalFinalPrice)
},
......@@ -409,8 +410,8 @@ export default {
sellPrice = parseFloat(item.goods.sellPrice || 0)
}
// 四舍五入保留两位小数
return Math.round(sellPrice * 100) / 100
// 向上取整保留两位小数
return utils.ceilDecimal(sellPrice)
},
// 计算最终显示价格
getDisplayPrice(item) {
......@@ -426,16 +427,16 @@ export default {
const ratio = parseFloat(strategyConfig.discountRatio)
if (ratio >= 0.1 && 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) {
const discountAmount = parseFloat(strategyConfig.discountAmount)
if (discountAmount >= 0.01 && discountAmount <= basePrice) {
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' 买赠策略
......@@ -443,7 +444,7 @@ export default {
if (strategyConfig.isGift === '1') {
return '¥0.00'
}
return '¥' + basePrice.toFixed(2)
return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
}
// '5' 组合付款
......@@ -452,13 +453,13 @@ export default {
const deductAmount = parseFloat(strategyConfig.deductAmount)
if (deductAmount >= 0.01 && deductAmount <= basePrice) {
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 是单件商品优惠后的价格,需要乘以数量得到总价)
onPriceChange(item, finalPricePerUnit) {
......@@ -466,12 +467,12 @@ export default {
if (item.multipleSpecificationsGoods && item.multipleSpecificationsGoods.goods) {
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, 'finalPricePerUnit', finalPricePerUnit)
} else if (item.goods) {
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, 'finalPricePerUnit', finalPricePerUnit)
}
......@@ -490,7 +491,7 @@ export default {
}
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 diff could not be displayed because it is too large.
......@@ -282,7 +282,7 @@ export default {
// 待上传协议状态也支持撤销
if (order.payType == 1) {
// 线上支付显示"错误工单"
config.secondaryButtons.push({ text: '错误工单', type: 'secondary', dataType: 'error' })
// config.secondaryButtons.push({ text: '错误工单', type: 'secondary', dataType: 'error' })
} else {
// 非线上支付显示"撤销工单"
config.secondaryButtons.push({ text: '撤销工单', type: 'secondary', dataType: 'revoke' })
......
......@@ -58,6 +58,7 @@
</template>
<script>
import utils from '@/utils/utils'
export default {
name: 'OrderStrategy',
props: {
......@@ -127,17 +128,17 @@ export default {
// 折扣比例:0.1-10,表示 0.1 折到 10 折(即 0.01 到 1.0)
if (ratio >= 0.1 && 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) {
const discountAmount = parseFloat(this.localState.discountAmount)
// 折扣金额:0.01 到不能大于基础价格
if (discountAmount >= 0.01 && discountAmount <= basePrice) {
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 {
if (this.localState.isGift === '1') {
return '¥0.00'
}
return '¥' + basePrice.toFixed(2)
return '¥' + utils.ceilDecimal(basePrice).toFixed(2)
}
// 组合付款
......@@ -155,13 +156,13 @@ export default {
// 抵扣金额:0.01 到不能大于基础价格
if (deductAmount >= 0.01 && deductAmount <= basePrice) {
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: {
......@@ -254,15 +255,15 @@ export default {
if (this.localState.mode === 'ratio' && this.localState.discountRatio) {
const ratio = parseFloat(this.localState.discountRatio)
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) {
const discountAmount = parseFloat(this.localState.discountAmount)
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 {
if (this.localState.isGift === '1') {
return 0
}
return Math.round(bp * 100) / 100
return utils.ceilDecimal(bp)
}
// 组合付款
......@@ -278,13 +279,13 @@ export default {
if (this.localState.mode === 'deduct' && this.localState.deductAmount) {
const deductAmount = parseFloat(this.localState.deductAmount)
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) {
......
......@@ -32,6 +32,7 @@
</view>
</template>
<script>
import utils from '@/utils/utils'
export default {
name: 'Package',
props: {
......@@ -199,7 +200,7 @@ export default {
// 按当前单价和套餐数量,重新计算无优惠时的 finalPrice
const unitPrice = parseFloat(goods.sellPrice || 0)
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, 'finalPrice', totalFinalPrice)
}
......
......@@ -229,6 +229,15 @@ const decimal = (num, fixed) => {
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 => {
let [num, decimal] = price.toString().split('.')
if (!decimal) decimal = '00'
......@@ -269,25 +278,45 @@ const filterValue = (val, unit = '') => {
}
/**
*
*
* 检测VIN码
*/
function validateVIN(vin) {
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];
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 charMap = {
'A': 1, 'B': 2, 'C': 3, 'D': 4, '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;
A: 1,
B: 2,
C: 3,
D: 4,
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++) {
const char = vin[i].toUpperCase();
const value = charMap[char] || parseInt(char, 10);
sum += value * weights[i];
const char = vin[i].toUpperCase()
const value = charMap[char] || parseInt(char, 10)
sum += value * weights[i]
}
const checkDigit = (sum % 11) === 10 ? 'X' : (sum % 11).toString();
return checkDigit === vin[8];
const checkDigit = sum % 11 === 10 ? 'X' : (sum % 11).toString()
return checkDigit === vin[8]
}
const nullValues = [undefined,'undefined',null,'null']
......@@ -309,6 +338,7 @@ export default {
getViewInfo,
setPrice,
decimal,
ceilDecimal,
showNoAccess,
setCopyData,
refreshPageData,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!