support consume point
This commit is contained in:
@@ -25,13 +25,16 @@
|
||||
<t-form-item label="积分值模式" :arrow="formModel.triggerType !== 'CUSTOMER_EVENT_VALUE_TIER'" @click="openModePicker">
|
||||
<span class="picker-text" v-text="getModeText(formModel.pointMode)" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="formModel.pointMode === 'FIXED'" label="固定积分" required-mark>
|
||||
<t-form-item v-if="formModel.pointMode === 'FIXED'" label="积分动作" arrow @click="openPointActionPicker">
|
||||
<span class="picker-text" v-text="getPointActionText(formModel.pointAction)" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="formModel.pointMode === 'FIXED'" label="积分数量" required-mark>
|
||||
<t-input
|
||||
v-model.trim="formModel.pointValueText"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
placeholder="请输入正整数"
|
||||
placeholder="请输入数量"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="formModel.triggerType === 'AFTER_COUNT_EVERY_TIME'" label="触发阈值" required-mark>
|
||||
@@ -45,14 +48,17 @@
|
||||
</t-form-item>
|
||||
<div v-if="formModel.pointMode === 'SOURCE_VALUE'" class="source-condition">
|
||||
<div class="source-title">自定义积分范围</div>
|
||||
<t-form-item label="积分动作" arrow @click="openPointActionPicker">
|
||||
<span class="picker-text" v-text="getPointActionText(formModel.pointAction)" />
|
||||
</t-form-item>
|
||||
<div class="source-inputs">
|
||||
<t-input v-model.trim="formModel.minText" type="number" align="right" borderless placeholder="最小值" />
|
||||
<span>至</span>
|
||||
<t-input v-model.trim="formModel.maxText" type="number" align="right" borderless placeholder="最大值" />
|
||||
</div>
|
||||
<span class="tips">登记时只有输入在此范围内的正整数,系统才会按本规则发放积分</span>
|
||||
<span class="tips">登记时输入数量,系统会按选定动作执行积分变化</span>
|
||||
</div>
|
||||
<template v-if="formModel.triggerType === 'CUSTOMER_EVENT_VALUE_TIER'" class="tier-condition">
|
||||
<template v-if="formModel.triggerType === 'CUSTOMER_EVENT_VALUE_TIER'">
|
||||
<t-form-item label="来源事件" required-mark arrow @click="openSourceEventPicker">
|
||||
<span class="picker-text" v-text="selectedSourceEventName" />
|
||||
</t-form-item>
|
||||
@@ -76,7 +82,7 @@
|
||||
</div>
|
||||
</t-form-item>
|
||||
</card-container>
|
||||
<card-container tips="命中规则并发放积分后不再匹配其他规则">
|
||||
<card-container tips="命中规则并执行积分动作后不再匹配后续规则">
|
||||
<t-form-item label="优先级" required-mark>
|
||||
<t-input v-model.trim="formModel.priorityText" type="number" align="right" borderless placeholder="数值越小越优先" />
|
||||
</t-form-item>
|
||||
@@ -162,6 +168,15 @@
|
||||
@confirm="confirmModePicker"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="pointActionPickerVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-model="pointActionPickerDraft"
|
||||
:columns="pointActionPickerColumns"
|
||||
title="积分动作"
|
||||
@cancel="pointActionPickerVisible = false"
|
||||
@confirm="confirmPointActionPicker"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="beginAtPickerVisible" placement="bottom">
|
||||
<t-date-time-picker
|
||||
v-model="beginAtDraftText"
|
||||
@@ -194,7 +209,7 @@ import PointAPI from "@/api/PointAPI";
|
||||
import PointRuleTierEditor from "@/pages/point/component/PointRuleTierEditor.vue";
|
||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
import type { PointRule, PointRuleMode, PointRuleStatus, PointRuleTier, PointRuleTierForm, PointRuleTriggerType } from "@/types/Point";
|
||||
import type { PointAction, PointRule, PointRuleMode, PointRuleStatus, PointRuleTier, PointRuleTierForm, PointRuleTriggerType } from "@/types/Point";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
import { getTierMinValue, isLastTier, resolveNonNegativeInteger } from "@/utils/pointRule";
|
||||
@@ -230,6 +245,7 @@ const formModel = reactive({
|
||||
status: "DRAFT" as PointRuleStatus,
|
||||
triggerType: "EVERY_TIME" as PointRuleTriggerType,
|
||||
pointMode: "FIXED" as PointRuleMode,
|
||||
pointAction: "EARN" as PointAction,
|
||||
pointValueText: "",
|
||||
thresholdText: "",
|
||||
minText: "",
|
||||
@@ -276,10 +292,12 @@ const selectedSourceEventName = computed(() => sourceEventList.value.find(item =
|
||||
let tierKey = 0;
|
||||
|
||||
function createTierForm(tier?: PointRuleTier, isLast = false): PointRuleTierForm {
|
||||
const pointValue = tier?.pointValue;
|
||||
return {
|
||||
key: tierKey++,
|
||||
maxText: !isLast && tier?.max !== undefined && tier.max !== null ? String(tier.max) : "",
|
||||
pointValueText: tier ? String(tier.pointValue) : "0"
|
||||
pointAction: pointValue !== undefined && pointValue < 0 ? "CONSUME" : "EARN",
|
||||
pointValueText: pointValue === undefined ? "0" : String(Math.abs(pointValue))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -401,6 +419,13 @@ const triggerPickerColumns = [triggerOptions];
|
||||
const modePickerVisible = ref(false);
|
||||
const modePickerDraft = ref<PickerValue[]>([]);
|
||||
const modePickerColumns = computed(() => [modeOptions.value]);
|
||||
const pointActionOptions: Array<{ label: string; value: PointAction }> = [
|
||||
{ label: "发放积分", value: "EARN" },
|
||||
{ label: "消耗积分", value: "CONSUME" }
|
||||
];
|
||||
const pointActionPickerVisible = ref(false);
|
||||
const pointActionPickerDraft = ref<PickerValue[]>([]);
|
||||
const pointActionPickerColumns = [pointActionOptions];
|
||||
|
||||
function openStatusPicker(): void {
|
||||
statusPickerDraft.value = [formModel.status];
|
||||
@@ -453,6 +478,22 @@ function confirmModePicker(value: Array<string | number>): void {
|
||||
modePickerVisible.value = false;
|
||||
}
|
||||
|
||||
function openPointActionPicker(): void {
|
||||
if (formModel.pointMode === "TIER") {
|
||||
return;
|
||||
}
|
||||
pointActionPickerDraft.value = [formModel.pointAction];
|
||||
pointActionPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmPointActionPicker(value: Array<string | number>): void {
|
||||
const action = value[0];
|
||||
if (action === "EARN" || action === "CONSUME") {
|
||||
formModel.pointAction = action;
|
||||
}
|
||||
pointActionPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function getStatusText(status: PointRuleStatus): string {
|
||||
return statusOptions.find(item => item.value === status)?.label || "草稿";
|
||||
}
|
||||
@@ -465,6 +506,10 @@ function getModeText(pointMode: PointRuleMode): string {
|
||||
return modeOptions.value.find(item => item.value === pointMode)?.label || "固定积分";
|
||||
}
|
||||
|
||||
function getPointActionText(action: PointAction): string {
|
||||
return action === "CONSUME" ? "消耗积分" : "发放积分";
|
||||
}
|
||||
|
||||
// ---------- 生效时间 ----------
|
||||
|
||||
const minimumDateTimeText = "1970-01-01 00:00";
|
||||
@@ -511,6 +556,11 @@ function resolvePositiveInteger(value: string): number | undefined {
|
||||
return Number.isSafeInteger(numberValue) && 0 < numberValue ? numberValue : undefined;
|
||||
}
|
||||
|
||||
function resolveSignedPointValue(value: string, action: PointAction): number | undefined {
|
||||
const pointValue = resolvePositiveInteger(value);
|
||||
return pointValue === undefined ? undefined : action === "CONSUME" ? -pointValue : pointValue;
|
||||
}
|
||||
|
||||
function resolveTimestamp(value: string): number | undefined {
|
||||
if (!value.trim()) {
|
||||
return undefined;
|
||||
@@ -532,7 +582,7 @@ function buildCondition(): PointRule["conditionJson"] {
|
||||
tiers: formModel.tiers.map((tier, index) => {
|
||||
const result: PointRuleTier = {
|
||||
min: getTierMinValue(formModel.tiers, index) || 0,
|
||||
pointValue: resolveNonNegativeInteger(tier.pointValueText) || 0
|
||||
pointValue: (tier.pointAction === "CONSUME" ? -1 : 1) * (resolveNonNegativeInteger(tier.pointValueText) || 0)
|
||||
};
|
||||
if (!isLastTier(formModel.tiers, index)) {
|
||||
result.max = resolveNonNegativeInteger(tier.maxText);
|
||||
@@ -543,8 +593,8 @@ function buildCondition(): PointRule["conditionJson"] {
|
||||
}
|
||||
if (formModel.pointMode === "SOURCE_VALUE") {
|
||||
return {
|
||||
min: resolvePositiveInteger(formModel.minText),
|
||||
max: resolvePositiveInteger(formModel.maxText)
|
||||
min: resolveSignedPointValue(formModel.minText, formModel.pointAction),
|
||||
max: resolveSignedPointValue(formModel.maxText, formModel.pointAction)
|
||||
};
|
||||
}
|
||||
if (formModel.triggerType === "FIRST_TIME") {
|
||||
@@ -599,7 +649,7 @@ function validateForm(): boolean {
|
||||
return false;
|
||||
}
|
||||
if (pointValue === undefined) {
|
||||
Toast.warning(`第 ${i + 1} 档积分必须是大于等于 0 的整数`);
|
||||
Toast.warning(`第 ${i + 1} 档积分数量必须是大于等于 0 的整数`);
|
||||
return false;
|
||||
}
|
||||
if (!isLastTier(formModel.tiers, i)) {
|
||||
@@ -611,7 +661,7 @@ function validateForm(): boolean {
|
||||
}
|
||||
}
|
||||
} else if (formModel.pointMode === "FIXED" && !resolvePositiveInteger(formModel.pointValueText)) {
|
||||
Toast.warning("固定积分必须是正整数");
|
||||
Toast.warning("积分数量必须是正整数");
|
||||
return false;
|
||||
}
|
||||
if (formModel.triggerType === "AFTER_COUNT_EVERY_TIME" && !resolvePositiveInteger(formModel.thresholdText)) {
|
||||
@@ -622,7 +672,7 @@ function validateForm(): boolean {
|
||||
const min = resolvePositiveInteger(formModel.minText);
|
||||
const max = resolvePositiveInteger(formModel.maxText);
|
||||
if (!min || !max || max < min) {
|
||||
Toast.warning("自定义积分范围必须是正整数,且最大值不能小于最小值");
|
||||
Toast.warning("积分数量范围必须是正整数,且最大值不能小于最小值");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -654,7 +704,7 @@ async function saveRule(): Promise<void> {
|
||||
status: formModel.status,
|
||||
triggerType: formModel.triggerType,
|
||||
pointMode: formModel.pointMode,
|
||||
pointValue: formModel.pointMode === "FIXED" ? resolvePositiveInteger(formModel.pointValueText) : null,
|
||||
pointValue: formModel.pointMode === "FIXED" ? resolveSignedPointValue(formModel.pointValueText, formModel.pointAction) : null,
|
||||
conditionJson: buildCondition(),
|
||||
beginAt: resolveTimestamp(formModel.beginAtText),
|
||||
endAt: resolveTimestamp(formModel.endAtText),
|
||||
@@ -727,10 +777,13 @@ async function fillForm(): Promise<void> {
|
||||
status: current.status === "ACTIVE" ? "ACTIVE" : current.status === "INACTIVE" ? "INACTIVE" : "DRAFT",
|
||||
triggerType: current.triggerType || "EVERY_TIME",
|
||||
pointMode: current.pointMode || "FIXED",
|
||||
pointValueText: current.pointValue === undefined || current.pointValue === null ? "" : String(current.pointValue),
|
||||
pointAction: current.pointValue !== undefined && current.pointValue !== null
|
||||
? current.pointValue < 0 ? "CONSUME" : "EARN"
|
||||
: current.conditionJson?.min !== undefined && current.conditionJson.min < 0 ? "CONSUME" : "EARN",
|
||||
pointValueText: current.pointValue === undefined || current.pointValue === null ? "" : String(Math.abs(current.pointValue)),
|
||||
thresholdText: current.conditionJson?.threshold === undefined ? "" : String(current.conditionJson.threshold),
|
||||
minText: current.conditionJson?.min === undefined ? "" : String(current.conditionJson.min),
|
||||
maxText: current.conditionJson?.max === undefined ? "" : String(current.conditionJson.max),
|
||||
minText: current.conditionJson?.min === undefined ? "" : String(Math.abs(current.conditionJson.min)),
|
||||
maxText: current.conditionJson?.max === undefined ? "" : String(Math.abs(current.conditionJson.max)),
|
||||
sourceEventId: current.conditionJson?.sourceEventId || "",
|
||||
windowAmountText: current.conditionJson?.window?.amount === undefined ? "1" : String(current.conditionJson.window.amount),
|
||||
tiers: current.conditionJson?.tiers?.length
|
||||
|
||||
Reference in New Issue
Block a user