智能押金与33优化
This commit is contained in:
@@ -121,6 +121,7 @@ const regionOptions = computed(() => publishOptions.value.region_options);
|
||||
const banRecordOptions = computed(() => publishOptions.value.ban_record_options);
|
||||
const banEvidenceOptions = computed(() => publishOptions.value.ban_evidence_options);
|
||||
const priceConfig = computed(() => publishOptions.value.price_config);
|
||||
const depositRecommendConfig = computed(() => publishOptions.value.deposit_recommend_config);
|
||||
const fireLevelMin = computed(() => publishOptions.value.fire_level_min || 38);
|
||||
const fireLevelPlaceholder = computed(
|
||||
() => `等级低于${fireLevelMin.value}级的号无法发布`
|
||||
@@ -161,6 +162,7 @@ const calculatedSellerPrice = computed(() =>
|
||||
);
|
||||
const calculatedPlatformPricing = computed(() => calculatePlatformPricing());
|
||||
const calculatedFinalPrice = computed(() => calculatedPlatformPricing.value.buyerTotalPrice);
|
||||
const recommendedDepositAmount = computed(() => calculateRecommendedDeposit());
|
||||
const calculatedRatioText = computed(() =>
|
||||
calculatedRatio.value > 0 ? `1:${formatNumber(calculatedRatio.value)}` : ""
|
||||
);
|
||||
@@ -189,6 +191,18 @@ watch(
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
watch(recommendedDepositAmount, () => {
|
||||
syncRecommendedDeposit();
|
||||
}, { immediate: true });
|
||||
|
||||
watch(
|
||||
[() => form.season_insurance, quantityItems],
|
||||
() => {
|
||||
clearForbiddenQuantityItems();
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
async function loadPublishOptions() {
|
||||
try {
|
||||
const [nextPublishOptions, nextSalePriceConfig] = await Promise.all([
|
||||
@@ -397,6 +411,55 @@ function handleAcceleratedSaleRatioInput(value: string | number) {
|
||||
form.accelerated_sale_ratio = Number.isFinite(ratio) ? ratio : "";
|
||||
}
|
||||
|
||||
function syncRecommendedDeposit() {
|
||||
const recommended = recommendedDepositAmount.value;
|
||||
if (recommended <= 0) return;
|
||||
const current = Number(form.deposit_amount);
|
||||
if (form.deposit_amount === "" || !Number.isFinite(current) || current < recommended) {
|
||||
form.deposit_amount = recommended;
|
||||
}
|
||||
}
|
||||
|
||||
function calculateRecommendedDeposit() {
|
||||
const baseAmount = Number(depositRecommendConfig.value.base_amount || 0);
|
||||
const skinAmount = depositRecommendConfig.value.skin_group_rules.reduce((sum, rule) => {
|
||||
const group = skinGroups.value.find((item) => item.key === rule.group_key);
|
||||
if (!group) return sum;
|
||||
const selectedCount = group.options.filter((skin) =>
|
||||
selectedSkins.value.includes(skin)
|
||||
).length;
|
||||
return sum + selectedCount * Number(rule.amount_per_item || 0);
|
||||
}, 0);
|
||||
return roundMoney(baseAmount + skinAmount);
|
||||
}
|
||||
|
||||
function useRecommendedDeposit() {
|
||||
if (recommendedDepositAmount.value > 0) {
|
||||
form.deposit_amount = recommendedDepositAmount.value;
|
||||
}
|
||||
}
|
||||
|
||||
function isGridCardQuantityItem(item: { key: string; label: string }) {
|
||||
return item.key === "gridCard9" || item.label.includes("9格体验卡");
|
||||
}
|
||||
|
||||
function isQuantityItemDisabled(item: { key: string; label: string }) {
|
||||
return form.season_insurance === "3*3" && isGridCardQuantityItem(item);
|
||||
}
|
||||
|
||||
function clearForbiddenQuantityItems() {
|
||||
for (const item of quantityItems.value) {
|
||||
if (!isQuantityItemDisabled(item)) continue;
|
||||
quantityValues[item.key] = 0;
|
||||
quantityModes[item.key] = "赠送";
|
||||
}
|
||||
}
|
||||
|
||||
function setQuantityMode(item: { key: string; label: string }, mode: ChargeMode) {
|
||||
if (isQuantityItemDisabled(item)) return;
|
||||
quantityModes[item.key] = mode;
|
||||
}
|
||||
|
||||
function clampAcceleratedSaleRatioInput() {
|
||||
if (!hasAcceleratedSaleRatioInput() || calculatedDefaultSaleRatio.value <= 0) return;
|
||||
const ratio = Number(form.accelerated_sale_ratio);
|
||||
@@ -489,6 +552,9 @@ function validateForm() {
|
||||
if (!Number.isFinite(Number(form.deposit_amount))) {
|
||||
return "押金格式不正确";
|
||||
}
|
||||
if (recommendedDepositAmount.value > 0 && Number(form.deposit_amount) < recommendedDepositAmount.value) {
|
||||
return `押金不能低于智能推荐 ¥${recommendedDepositAmount.value}`;
|
||||
}
|
||||
if (calculatedConsumablePrice.value > 0 && Number(form.deposit_amount) <= calculatedConsumablePrice.value) {
|
||||
return `押金必须大于额外消耗品总价值 ¥${calculatedConsumablePrice.value}`;
|
||||
}
|
||||
@@ -503,6 +569,11 @@ function validateForm() {
|
||||
return `请上传${item.label}`;
|
||||
}
|
||||
}
|
||||
for (const item of quantityItems.value) {
|
||||
if (isQuantityItemDisabled(item) && Number(quantityValues[item.key] || 0) > 0) {
|
||||
return "赛季保险选择 3*3 时不能填写 9格体验卡";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -542,8 +613,8 @@ function buildAssetSummary() {
|
||||
key: item.key,
|
||||
label: item.label,
|
||||
price: item.price,
|
||||
quantity: Number(quantityValues[item.key] || 0),
|
||||
mode: quantityModes[item.key] || "收费",
|
||||
quantity: isQuantityItemDisabled(item) ? 0 : Number(quantityValues[item.key] || 0),
|
||||
mode: isQuantityItemDisabled(item) ? "赠送" : quantityModes[item.key] || "收费",
|
||||
})),
|
||||
skin_groups: skinGroups.value.reduce<Record<string, string[]>>((groups, group) => {
|
||||
groups[group.key] = group.options.filter((skin) =>
|
||||
@@ -569,6 +640,7 @@ function calculateConsumablePrice() {
|
||||
const total = quantityItems.value.reduce((sum, item) => {
|
||||
const quantity = Number(quantityValues[item.key] || 0);
|
||||
const mode = quantityModes[item.key] || "收费";
|
||||
if (isQuantityItemDisabled(item)) return sum;
|
||||
if (quantity <= 0 || mode !== "收费") return sum;
|
||||
return sum + quantity * readUnitPrice(item.price);
|
||||
}, 0);
|
||||
@@ -897,7 +969,12 @@ function readError(error: unknown, fallback: string) {
|
||||
|
||||
<div class="form-section">
|
||||
<h2 class="section-title">额外消耗品</h2>
|
||||
<div v-for="item in quantityItems" :key="item.key" class="quantity-row">
|
||||
<div
|
||||
v-for="item in quantityItems"
|
||||
:key="item.key"
|
||||
class="quantity-row"
|
||||
:class="{ disabled: isQuantityItemDisabled(item) }"
|
||||
>
|
||||
<div class="quantity-card">
|
||||
<div class="quantity-meta">
|
||||
<strong
|
||||
@@ -908,7 +985,7 @@ function readError(error: unknown, fallback: string) {
|
||||
>
|
||||
<span>*</span>{{ item.label }}
|
||||
</strong>
|
||||
<small>{{ item.price }}</small>
|
||||
<small>{{ isQuantityItemDisabled(item) ? "3*3 已包含,不能填写" : item.price }}</small>
|
||||
</div>
|
||||
<input
|
||||
v-model="quantityValues[item.key]"
|
||||
@@ -917,20 +994,23 @@ function readError(error: unknown, fallback: string) {
|
||||
min="0"
|
||||
placeholder="0"
|
||||
class="quantity-input"
|
||||
:disabled="isQuantityItemDisabled(item)"
|
||||
/>
|
||||
</div>
|
||||
<div class="mode-toggle">
|
||||
<button
|
||||
type="button"
|
||||
:class="{ active: quantityModes[item.key] === '赠送' }"
|
||||
@click="quantityModes[item.key] = '赠送'"
|
||||
:disabled="isQuantityItemDisabled(item)"
|
||||
@click="setQuantityMode(item, '赠送')"
|
||||
>
|
||||
赠送
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:class="{ active: (quantityModes[item.key] || '收费') === '收费' }"
|
||||
@click="quantityModes[item.key] = '收费'"
|
||||
:disabled="isQuantityItemDisabled(item)"
|
||||
@click="setQuantityMode(item, '收费')"
|
||||
>
|
||||
收费
|
||||
</button>
|
||||
@@ -1100,6 +1180,9 @@ function readError(error: unknown, fallback: string) {
|
||||
<span class="hint-label" :data-hint="priceConfig.deposit_placeholder" tabindex="0">押金</span>
|
||||
</template>
|
||||
</van-field>
|
||||
<button class="deposit-recommend-btn" type="button" @click="useRecommendedDeposit">
|
||||
推荐押金 ¥{{ recommendedDepositAmount }}
|
||||
</button>
|
||||
<van-field label="每日损耗" required class="publish-field">
|
||||
<template #input>
|
||||
<div class="radio-group">
|
||||
|
||||
Reference in New Issue
Block a user