f
This commit is contained in:
@@ -11,8 +11,7 @@
|
||||
|
||||
<div class="border-b border-gray-200">
|
||||
<wd-input v-model="price" type="number" label="¥" label-width="28px" size="large"
|
||||
:placeholder="priceRangePlaceholder" @blur="onBlurPrice"
|
||||
custom-class="wd-input" />
|
||||
:placeholder="priceRangePlaceholder" @blur="onBlurPrice" custom-class="wd-input" />
|
||||
</div>
|
||||
<div class="flex items-center justify-between mt-2">
|
||||
<div>推广收益为<span class="text-orange-500"> {{ promotionRevenue }} </span>元</div>
|
||||
@@ -40,6 +39,7 @@
|
||||
<script setup>
|
||||
import { ref, computed, watch, toRefs } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { calculatePromotionPricing, safeTruncate } from '@/utils/promotionPricing.js'
|
||||
const props = defineProps({
|
||||
defaultPrice: {
|
||||
type: Number,
|
||||
@@ -67,31 +67,12 @@ const priceRangePlaceholder = computed(() => {
|
||||
return `${min} - ${max}`
|
||||
})
|
||||
|
||||
const costPrice = computed(() => {
|
||||
if (!productConfig.value) return 0.00
|
||||
// 平台定价成本
|
||||
let platformPricing = 0
|
||||
platformPricing += productConfig.value.cost_price
|
||||
if (price.value > productConfig.value.p_pricing_standard) {
|
||||
platformPricing += (price.value - productConfig.value.p_pricing_standard) * productConfig.value.p_overpricing_ratio
|
||||
}
|
||||
|
||||
if (productConfig.value.a_pricing_standard > platformPricing && productConfig.value.a_pricing_end > platformPricing && productConfig.value.a_overpricing_ratio > 0) {
|
||||
if (price.value > productConfig.value.a_pricing_standard) {
|
||||
if (price.value > productConfig.value.a_pricing_end) {
|
||||
platformPricing += (productConfig.value.a_pricing_end - productConfig.value.a_pricing_standard) * productConfig.value.a_overpricing_ratio
|
||||
} else {
|
||||
platformPricing += (price.value - productConfig.value.a_pricing_standard) * productConfig.value.a_overpricing_ratio
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return safeTruncate(platformPricing)
|
||||
const pricingResult = computed(() => {
|
||||
return calculatePromotionPricing(price.value, productConfig.value)
|
||||
})
|
||||
|
||||
const promotionRevenue = computed(() => {
|
||||
return safeTruncate(price.value - costPrice.value)
|
||||
});
|
||||
const costPrice = computed(() => pricingResult.value.costPrice)
|
||||
const promotionRevenue = computed(() => pricingResult.value.promotionRevenue)
|
||||
|
||||
// 价格校验与修正逻辑
|
||||
const validatePrice = (currentPrice) => {
|
||||
@@ -130,15 +111,6 @@ const validatePrice = (currentPrice) => {
|
||||
}
|
||||
return { newPrice, message };
|
||||
}
|
||||
function safeTruncate(num, decimals = 2) {
|
||||
if (isNaN(num) || !isFinite(num)) return "0.00";
|
||||
|
||||
const factor = 10 ** decimals;
|
||||
const scaled = Math.trunc(num * factor);
|
||||
const truncated = scaled / factor;
|
||||
|
||||
return truncated.toFixed(decimals);
|
||||
}
|
||||
const isManualConfirm = ref(false)
|
||||
const onConfirm = () => {
|
||||
if (isManualConfirm.value) return
|
||||
|
||||
Reference in New Issue
Block a user