update permission and product
This commit is contained in:
@@ -5,9 +5,13 @@
|
||||
<t-form-item v-if="isGlobalManager" label="门店" required-mark :arrow="isCreateMode" @click="openStorePicker">
|
||||
<span class="picker-text" v-text="selectedStoreName" />
|
||||
</t-form-item>
|
||||
<t-form-item label="登记事件" required-mark arrow @click="openEventPicker">
|
||||
<t-form-item label="触发来源" required-mark arrow @click="openTriggerSourcePicker">
|
||||
<span class="picker-text" v-text="getTriggerSourceText(formModel.triggerSourceType)" />
|
||||
</t-form-item>
|
||||
<t-form-item v-if="formModel.triggerSourceType === 'EVENT_RECORD'" label="触发事件" required-mark arrow @click="openEventPicker">
|
||||
<span class="picker-text" v-text="selectedEventName" />
|
||||
</t-form-item>
|
||||
<t-form-item v-else label-width="0" class="form-tips">订单首次全额实收时触发,同一订单每条规则只生效一次</t-form-item>
|
||||
<t-form-item label="规则名称" required-mark>
|
||||
<t-input v-model.trim="formModel.name" align="right" borderless placeholder="例如:每次登记加 10 分" />
|
||||
</t-form-item>
|
||||
@@ -19,16 +23,10 @@
|
||||
</t-form-item>
|
||||
</card-container>
|
||||
<card-container v-entrance-transition="70">
|
||||
<t-form-item label="触发类型" arrow @click="openTriggerPicker">
|
||||
<span class="picker-text" v-text="getTriggerText(formModel.triggerType)" />
|
||||
</t-form-item>
|
||||
<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="积分动作" arrow @click="openPointActionPicker">
|
||||
<t-form-item 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-form-item label="积分数量" required-mark>
|
||||
<t-input
|
||||
v-model.trim="formModel.pointValueText"
|
||||
type="number"
|
||||
@@ -37,36 +35,6 @@
|
||||
placeholder="请输入数量"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item v-if="formModel.triggerType === 'AFTER_COUNT_EVERY_TIME'" label="触发阈值" required-mark>
|
||||
<t-input
|
||||
v-model.trim="formModel.thresholdText"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
placeholder="累计登记达到几次"
|
||||
/>
|
||||
</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>
|
||||
</div>
|
||||
<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>
|
||||
<t-form-item label="累计窗口(年)" label-width="8rem">
|
||||
<t-input v-model.trim="formModel.windowAmountText" type="number" align="right" borderless />
|
||||
</t-form-item>
|
||||
<point-rule-tier-editor v-model="formModel.tiers" :value-unit="selectedSourceValueUnit" />
|
||||
</template>
|
||||
</card-container>
|
||||
<card-container v-entrance-transition="140">
|
||||
<t-form-item label="生效开始" arrow @click="openBeginAtPicker">
|
||||
@@ -102,18 +70,18 @@
|
||||
<t-picker
|
||||
v-model="eventPickerDraft"
|
||||
:columns="eventPickerColumns"
|
||||
title="选择登记事件"
|
||||
title="选择触发事件"
|
||||
@cancel="eventPickerVisible = false"
|
||||
@confirm="confirmEventPicker"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="sourceEventPickerVisible" placement="bottom">
|
||||
<t-popup v-model="triggerSourcePickerVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-model="sourceEventPickerDraft"
|
||||
:columns="sourceEventPickerColumns"
|
||||
title="选择来源事件"
|
||||
@cancel="sourceEventPickerVisible = false"
|
||||
@confirm="confirmSourceEventPicker"
|
||||
v-model="triggerSourcePickerDraft"
|
||||
:columns="triggerSourcePickerColumns"
|
||||
title="触发来源"
|
||||
@cancel="triggerSourcePickerVisible = false"
|
||||
@confirm="confirmTriggerSourcePicker"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="statusPickerVisible" placement="bottom">
|
||||
@@ -125,24 +93,6 @@
|
||||
@confirm="confirmStatusPicker"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="triggerPickerVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-model="triggerPickerDraft"
|
||||
:columns="triggerPickerColumns"
|
||||
title="触发类型"
|
||||
@cancel="triggerPickerVisible = false"
|
||||
@confirm="confirmTriggerPicker"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="modePickerVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-model="modePickerDraft"
|
||||
:columns="modePickerColumns"
|
||||
title="积分值模式"
|
||||
@cancel="modePickerVisible = false"
|
||||
@confirm="confirmModePicker"
|
||||
/>
|
||||
</t-popup>
|
||||
<t-popup v-model="pointActionPickerVisible" placement="bottom">
|
||||
<t-picker
|
||||
v-model="pointActionPickerDraft"
|
||||
@@ -181,29 +131,17 @@ import { Time } from "timi-web";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import EventAPI from "@/api/EventAPI";
|
||||
import PointAPI from "@/api/PointAPI";
|
||||
import PointRuleTierEditor from "@/pages/point/component/PointRuleTierEditor.vue";
|
||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
import type {
|
||||
PointAction,
|
||||
PointRule,
|
||||
PointRuleMode,
|
||||
PointRuleStatus,
|
||||
PointRuleTier,
|
||||
PointRuleTierForm,
|
||||
PointRuleTriggerType
|
||||
PointRuleTriggerSourceType
|
||||
} from "@/types/Point";
|
||||
import { getEventValueUnitText } from "@/utils/eventValue";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
|
||||
import {
|
||||
formatTierBoundaryValue,
|
||||
getTierMinValue,
|
||||
isLastTier,
|
||||
resolveNonNegativeInteger,
|
||||
resolveTierBoundaryValue
|
||||
} from "@/utils/pointRule";
|
||||
import { Message } from "@/utils/message";
|
||||
|
||||
type PickerValue = string | number;
|
||||
@@ -232,19 +170,12 @@ const isSaving = ref(false);
|
||||
const formModel = reactive({
|
||||
id: "",
|
||||
storeId: "",
|
||||
eventId: "",
|
||||
triggerSourceType: "EVENT_RECORD" as PointRuleTriggerSourceType,
|
||||
triggerRefId: "",
|
||||
name: "",
|
||||
status: "DRAFT" as PointRuleStatus,
|
||||
triggerType: "EVERY_TIME" as PointRuleTriggerType,
|
||||
pointMode: "FIXED" as PointRuleMode,
|
||||
pointAction: "EARN" as PointAction,
|
||||
pointValueText: "",
|
||||
thresholdText: "",
|
||||
minText: "",
|
||||
maxText: "",
|
||||
sourceEventId: "",
|
||||
windowAmountText: "1",
|
||||
tiers: [] as PointRuleTierForm[],
|
||||
beginAtText: "",
|
||||
endAtText: "",
|
||||
exclusive: false,
|
||||
@@ -255,7 +186,7 @@ const formModel = reactive({
|
||||
|
||||
const eventList = ref<EventItem[]>([]);
|
||||
const selectedStoreName = computed(() => currentStoreStore.storeList.find(item => item.id === formModel.storeId)?.name || "请选择门店");
|
||||
const selectedEventName = computed(() => eventList.value.find(item => item.id === formModel.eventId)?.name || "请选择登记事件");
|
||||
const selectedEventName = computed(() => eventList.value.find(item => item.id === formModel.triggerRefId)?.name || "请选择触发事件");
|
||||
const storePickerVisible = ref(false);
|
||||
const storePickerDraft = ref<PickerValue[]>([]);
|
||||
const storePickerColumns = computed(() => [
|
||||
@@ -270,36 +201,6 @@ const eventPickerColumns = computed(() => [
|
||||
.map(item => ({ label: item.name || "未命名事件", value: item.id || "" }))
|
||||
.filter(item => item.value)
|
||||
]);
|
||||
const sourceEventPickerVisible = ref(false);
|
||||
const sourceEventPickerDraft = ref<PickerValue[]>([]);
|
||||
const sourceEventList = computed(() => eventList.value.filter(item => item.valueType === "NUMBER" && item.id));
|
||||
const selectedSourceEvent = computed(() => sourceEventList.value.find(item => item.id === formModel.sourceEventId));
|
||||
const selectedSourceValueUnit = computed(() => selectedSourceEvent.value?.valueUnit || null);
|
||||
const sourceEventPickerColumns = computed(() => [
|
||||
sourceEventList.value
|
||||
.map(item => ({ label: `${item.name || "未命名事件"}(${getEventValueUnitText(item.valueUnit)})`, value: item.id || "" }))
|
||||
.filter(item => item.value)
|
||||
]);
|
||||
const selectedSourceEventName = computed(() => selectedSourceEvent.value
|
||||
? `${selectedSourceEvent.value.name || "未命名事件"}(${getEventValueUnitText(selectedSourceEvent.value.valueUnit)})`
|
||||
: "请选择来源事件");
|
||||
|
||||
let tierKey = 0;
|
||||
|
||||
function createTierForm(tier?: PointRuleTier, isLast = false, valueUnit?: EventItem["valueUnit"]): PointRuleTierForm {
|
||||
const pointValue = tier?.pointValue;
|
||||
return {
|
||||
key: tierKey++,
|
||||
minText: tier?.min === undefined || tier.min === null ? "0" : formatTierBoundaryValue(tier.min, valueUnit),
|
||||
maxText: !isLast && tier?.max !== undefined && tier.max !== null ? formatTierBoundaryValue(tier.max, valueUnit) : "",
|
||||
pointAction: pointValue !== undefined && pointValue < 0 ? "CONSUME" : "EARN",
|
||||
pointValueText: pointValue === undefined ? "0" : String(Math.abs(pointValue))
|
||||
};
|
||||
}
|
||||
|
||||
if (!formModel.tiers.length) {
|
||||
formModel.tiers.push(createTierForm(undefined, true));
|
||||
}
|
||||
|
||||
function openStorePicker(): void {
|
||||
if (!isCreateMode.value || !storePickerColumns.value[0]?.length) {
|
||||
@@ -311,14 +212,14 @@ function openStorePicker(): void {
|
||||
|
||||
async function confirmStorePicker(value: Array<string | number>): Promise<void> {
|
||||
const storeId = String(value[0] || "");
|
||||
if (storeId) {
|
||||
if (storeId && storeId !== formModel.storeId) {
|
||||
formModel.storeId = storeId;
|
||||
formModel.eventId = "";
|
||||
formModel.triggerRefId = "";
|
||||
try {
|
||||
await loadEventList();
|
||||
} catch {
|
||||
eventList.value = [];
|
||||
Message.error("登记事件加载失败");
|
||||
Message.error("触发事件加载失败");
|
||||
}
|
||||
}
|
||||
storePickerVisible.value = false;
|
||||
@@ -326,47 +227,21 @@ async function confirmStorePicker(value: Array<string | number>): Promise<void>
|
||||
|
||||
function openEventPicker(): void {
|
||||
if (!eventPickerColumns.value[0]?.length) {
|
||||
Message.warning("暂无可选登记事件");
|
||||
Message.warning("暂无可选触发事件");
|
||||
return;
|
||||
}
|
||||
eventPickerDraft.value = [formModel.eventId];
|
||||
eventPickerDraft.value = [formModel.triggerRefId];
|
||||
eventPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmEventPicker(value: Array<string | number>): void {
|
||||
const eventId = String(value[0] || "");
|
||||
if (eventId) {
|
||||
formModel.eventId = eventId;
|
||||
formModel.triggerRefId = eventId;
|
||||
}
|
||||
eventPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function openSourceEventPicker(): void {
|
||||
if (formModel.triggerType !== "CUSTOMER_EVENT_VALUE_TIER") {
|
||||
return;
|
||||
}
|
||||
if (!sourceEventPickerColumns.value[0]?.length) {
|
||||
Message.warning("暂无可用的 NUMBER 来源事件");
|
||||
return;
|
||||
}
|
||||
sourceEventPickerDraft.value = [formModel.sourceEventId];
|
||||
sourceEventPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmSourceEventPicker(value: Array<string | number>): void {
|
||||
const sourceEventId = String(value[0] || "");
|
||||
if (sourceEventId) {
|
||||
const previousSourceEvent = sourceEventList.value.find(item => item.id === formModel.sourceEventId);
|
||||
const nextSourceEvent = sourceEventList.value.find(item => item.id === sourceEventId);
|
||||
if (formModel.sourceEventId && previousSourceEvent?.valueUnit !== nextSourceEvent?.valueUnit) {
|
||||
formModel.tiers = [createTierForm(undefined, true, nextSourceEvent?.valueUnit)];
|
||||
Message.warning("来源事件单位已变化,原分档已清空,请重新配置");
|
||||
}
|
||||
formModel.sourceEventId = sourceEventId;
|
||||
}
|
||||
sourceEventPickerVisible.value = false;
|
||||
}
|
||||
|
||||
async function prepareStoreScope(): Promise<void> {
|
||||
if (isGlobalManager.value) {
|
||||
await currentStoreStore.loadStoreList();
|
||||
@@ -383,12 +258,10 @@ async function prepareStoreScope(): Promise<void> {
|
||||
async function loadEventList(): Promise<void> {
|
||||
const options = isGlobalManager.value ? { storeId: formModel.storeId } : undefined;
|
||||
const result = await EventAPI.list({ index: 0, size: 1000 }, options);
|
||||
eventList.value = result.list || [];
|
||||
const requiredEventIdList = [formModel.eventId, formModel.sourceEventId].filter((id, index, list) => id && list.indexOf(id) === index);
|
||||
for (const eventId of requiredEventIdList) {
|
||||
if (!eventList.value.some(item => item.id === eventId)) {
|
||||
eventList.value.push(await EventAPI.detail(eventId));
|
||||
}
|
||||
// 退役消费事件不能作为触发对象
|
||||
eventList.value = (result.list || []).filter(item => item.bizType !== "LEGACY_CONSUMPTION");
|
||||
if (formModel.triggerRefId && !eventList.value.some(item => item.id === formModel.triggerRefId)) {
|
||||
eventList.value.push(await EventAPI.detail(formModel.triggerRefId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,31 +272,16 @@ const statusOptions: Array<{ label: string; value: PointRuleStatus }> = [
|
||||
{ label: "启用", value: "ACTIVE" },
|
||||
{ label: "停用", value: "INACTIVE" }
|
||||
];
|
||||
const triggerOptions: Array<{ label: string; value: PointRuleTriggerType }> = [
|
||||
{ label: "每次登记", value: "EVERY_TIME" },
|
||||
{ label: "首次登记", value: "FIRST_TIME" },
|
||||
{ label: "达到阈值后每次登记", value: "AFTER_COUNT_EVERY_TIME" },
|
||||
{ label: "登记时自定义积分", value: "SOURCE_VALUE" },
|
||||
{ label: "按来源事件累计分档", value: "CUSTOMER_EVENT_VALUE_TIER" }
|
||||
const triggerSourceOptions: Array<{ label: string; value: PointRuleTriggerSourceType }> = [
|
||||
{ label: "事件登记", value: "EVENT_RECORD" },
|
||||
{ label: "订单全额实收", value: "SALES_ORDER_PAID" }
|
||||
];
|
||||
const modeOptions = computed<Array<{ label: string; value: PointRuleMode }>>(() => {
|
||||
if (formModel.triggerType === "CUSTOMER_EVENT_VALUE_TIER") {
|
||||
return [{ label: "分档积分", value: "TIER" }];
|
||||
}
|
||||
if (formModel.triggerType === "SOURCE_VALUE") {
|
||||
return [{ label: "使用登记时填写的积分", value: "SOURCE_VALUE" }];
|
||||
}
|
||||
return [{ label: "固定积分", value: "FIXED" }];
|
||||
});
|
||||
const statusPickerVisible = ref(false);
|
||||
const statusPickerDraft = ref<PickerValue[]>([]);
|
||||
const statusPickerColumns = [statusOptions];
|
||||
const triggerPickerVisible = ref(false);
|
||||
const triggerPickerDraft = ref<PickerValue[]>([]);
|
||||
const triggerPickerColumns = [triggerOptions];
|
||||
const modePickerVisible = ref(false);
|
||||
const modePickerDraft = ref<PickerValue[]>([]);
|
||||
const modePickerColumns = computed(() => [modeOptions.value]);
|
||||
const triggerSourcePickerVisible = ref(false);
|
||||
const triggerSourcePickerDraft = ref<PickerValue[]>([]);
|
||||
const triggerSourcePickerColumns = [triggerSourceOptions];
|
||||
const pointActionOptions: Array<{ label: string; value: PointAction }> = [
|
||||
{ label: "发放积分", value: "EARN" },
|
||||
{ label: "消耗积分", value: "CONSUME" }
|
||||
@@ -445,48 +303,23 @@ function confirmStatusPicker(value: Array<string | number>): void {
|
||||
statusPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function openTriggerPicker(): void {
|
||||
triggerPickerDraft.value = [formModel.triggerType];
|
||||
triggerPickerVisible.value = true;
|
||||
function openTriggerSourcePicker(): void {
|
||||
triggerSourcePickerDraft.value = [formModel.triggerSourceType];
|
||||
triggerSourcePickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmTriggerPicker(value: Array<string | number>): void {
|
||||
const triggerType = value[0];
|
||||
if (typeof triggerType === "string" && triggerOptions.some(item => item.value === triggerType)) {
|
||||
formModel.triggerType = triggerType as PointRuleTriggerType;
|
||||
formModel.pointMode = triggerType === "SOURCE_VALUE" ? "SOURCE_VALUE" : triggerType === "CUSTOMER_EVENT_VALUE_TIER" ? "TIER" : "FIXED";
|
||||
}
|
||||
triggerPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function openModePicker(): void {
|
||||
if (formModel.triggerType === "CUSTOMER_EVENT_VALUE_TIER") {
|
||||
return;
|
||||
}
|
||||
modePickerDraft.value = [formModel.pointMode];
|
||||
modePickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmModePicker(value: Array<string | number>): void {
|
||||
const pointMode = value[0];
|
||||
if (pointMode === "FIXED" || pointMode === "SOURCE_VALUE" || pointMode === "TIER") {
|
||||
if (!modeOptions.value.some(item => item.value === pointMode)) {
|
||||
return;
|
||||
function confirmTriggerSourcePicker(value: Array<string | number>): void {
|
||||
const triggerSourceType = value[0];
|
||||
if (typeof triggerSourceType === "string" && triggerSourceOptions.some(item => item.value === triggerSourceType)) {
|
||||
formModel.triggerSourceType = triggerSourceType as PointRuleTriggerSourceType;
|
||||
if (formModel.triggerSourceType === "SALES_ORDER_PAID") {
|
||||
formModel.triggerRefId = "";
|
||||
}
|
||||
formModel.pointMode = pointMode;
|
||||
formModel.triggerType = pointMode === "SOURCE_VALUE"
|
||||
? "SOURCE_VALUE"
|
||||
: pointMode === "TIER"
|
||||
? "CUSTOMER_EVENT_VALUE_TIER"
|
||||
: formModel.triggerType === "SOURCE_VALUE" || formModel.triggerType === "CUSTOMER_EVENT_VALUE_TIER" ? "EVERY_TIME" : formModel.triggerType;
|
||||
}
|
||||
modePickerVisible.value = false;
|
||||
triggerSourcePickerVisible.value = false;
|
||||
}
|
||||
|
||||
function openPointActionPicker(): void {
|
||||
if (formModel.pointMode === "TIER") {
|
||||
return;
|
||||
}
|
||||
pointActionPickerDraft.value = [formModel.pointAction];
|
||||
pointActionPickerVisible.value = true;
|
||||
}
|
||||
@@ -503,12 +336,8 @@ function getStatusText(status: PointRuleStatus): string {
|
||||
return statusOptions.find(item => item.value === status)?.label || "草稿";
|
||||
}
|
||||
|
||||
function getTriggerText(triggerType: PointRuleTriggerType): string {
|
||||
return triggerOptions.find(item => item.value === triggerType)?.label || "每次登记";
|
||||
}
|
||||
|
||||
function getModeText(pointMode: PointRuleMode): string {
|
||||
return modeOptions.value.find(item => item.value === pointMode)?.label || "固定积分";
|
||||
function getTriggerSourceText(triggerSourceType: PointRuleTriggerSourceType): string {
|
||||
return triggerSourceOptions.find(item => item.value === triggerSourceType)?.label || "事件登记";
|
||||
}
|
||||
|
||||
function getPointActionText(action: PointAction): string {
|
||||
@@ -561,9 +390,9 @@ 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 resolvePointValue(): number | undefined {
|
||||
const pointValue = resolvePositiveInteger(formModel.pointValueText);
|
||||
return pointValue === undefined ? undefined : formModel.pointAction === "CONSUME" ? -pointValue : pointValue;
|
||||
}
|
||||
|
||||
function resolveTimestamp(value: string): number | undefined {
|
||||
@@ -574,121 +403,23 @@ function resolveTimestamp(value: string): number | undefined {
|
||||
return Number.isFinite(timestamp) ? timestamp : undefined;
|
||||
}
|
||||
|
||||
function buildCondition(): PointRule["conditionJson"] {
|
||||
if (formModel.triggerType === "CUSTOMER_EVENT_VALUE_TIER") {
|
||||
const valueUnit = selectedSourceValueUnit.value;
|
||||
return {
|
||||
sourceEventId: formModel.sourceEventId,
|
||||
sourceValueField: "numberValue",
|
||||
window: {
|
||||
type: "ROLLING",
|
||||
amount: resolvePositiveInteger(formModel.windowAmountText) || 1,
|
||||
unit: "YEAR"
|
||||
},
|
||||
tiers: formModel.tiers.map((tier, index) => {
|
||||
const min = getTierMinValue(formModel.tiers, index, valueUnit);
|
||||
const result: PointRuleTier = {
|
||||
min: min ?? 0,
|
||||
pointValue: (tier.pointAction === "CONSUME" ? -1 : 1) * (resolveNonNegativeInteger(tier.pointValueText) || 0)
|
||||
};
|
||||
if (!isLastTier(formModel.tiers, index)) {
|
||||
result.max = resolveTierBoundaryValue(tier.maxText, valueUnit);
|
||||
}
|
||||
return result;
|
||||
})
|
||||
};
|
||||
}
|
||||
if (formModel.pointMode === "SOURCE_VALUE") {
|
||||
return {
|
||||
min: resolveSignedPointValue(formModel.minText, formModel.pointAction),
|
||||
max: resolveSignedPointValue(formModel.maxText, formModel.pointAction)
|
||||
};
|
||||
}
|
||||
if (formModel.triggerType === "FIRST_TIME") {
|
||||
return { scope: "CUSTOMER_EVENT" };
|
||||
}
|
||||
if (formModel.triggerType === "AFTER_COUNT_EVERY_TIME") {
|
||||
return {
|
||||
threshold: resolvePositiveInteger(formModel.thresholdText),
|
||||
includeCurrent: true,
|
||||
scope: "CUSTOMER_EVENT"
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
function validateForm(): boolean {
|
||||
if (!formModel.storeId) {
|
||||
Message.warning("请选择门店");
|
||||
return false;
|
||||
}
|
||||
if (!formModel.eventId) {
|
||||
Message.warning("请选择登记事件");
|
||||
return false;
|
||||
}
|
||||
if (!formModel.name.trim()) {
|
||||
Message.warning("请输入规则名称");
|
||||
return false;
|
||||
}
|
||||
if (formModel.triggerType === "CUSTOMER_EVENT_VALUE_TIER") {
|
||||
if (formModel.pointMode !== "TIER") {
|
||||
Message.warning("分档规则必须使用分档积分模式");
|
||||
return false;
|
||||
}
|
||||
if (!selectedSourceEvent.value) {
|
||||
Message.warning("请选择 NUMBER 类型的来源事件");
|
||||
return false;
|
||||
}
|
||||
if (selectedSourceValueUnit.value !== "CENT" && selectedSourceValueUnit.value !== "COUNT") {
|
||||
Message.warning("来源事件必须配置数值单位");
|
||||
return false;
|
||||
}
|
||||
if (!resolvePositiveInteger(formModel.windowAmountText)) {
|
||||
Message.warning("累计窗口必须是正整数");
|
||||
return false;
|
||||
}
|
||||
if (!formModel.tiers.length || !(formModel.tiers.length < 100)) {
|
||||
Message.warning("分档数量必须是 1-100 档");
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < formModel.tiers.length; i++) {
|
||||
const tier = formModel.tiers[i];
|
||||
const min = getTierMinValue(formModel.tiers, i, selectedSourceValueUnit.value);
|
||||
const pointValue = resolveNonNegativeInteger(tier.pointValueText);
|
||||
if (min === undefined) {
|
||||
Message.warning(`第 ${i + 1} 档的上一档最大值无效`);
|
||||
return false;
|
||||
}
|
||||
if (pointValue === undefined) {
|
||||
Message.warning(`第 ${i + 1} 档积分数量必须是大于等于 0 的整数`);
|
||||
return false;
|
||||
}
|
||||
if (!isLastTier(formModel.tiers, i)) {
|
||||
const max = resolveTierBoundaryValue(tier.maxText, selectedSourceValueUnit.value);
|
||||
if (max === undefined || max < min) {
|
||||
Message.warning(selectedSourceValueUnit.value === "CENT"
|
||||
? `第 ${i + 1} 档最大值必须是不小于最小值且最多两位小数`
|
||||
: `第 ${i + 1} 档最大值必须是不小于最小值的整数`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (formModel.pointMode === "FIXED" && !resolvePositiveInteger(formModel.pointValueText)) {
|
||||
if (formModel.triggerSourceType === "EVENT_RECORD" && !formModel.triggerRefId) {
|
||||
Message.warning("请选择触发事件");
|
||||
return false;
|
||||
}
|
||||
if (!resolvePositiveInteger(formModel.pointValueText)) {
|
||||
Message.warning("积分数量必须是正整数");
|
||||
return false;
|
||||
}
|
||||
if (formModel.triggerType === "AFTER_COUNT_EVERY_TIME" && !resolvePositiveInteger(formModel.thresholdText)) {
|
||||
Message.warning("请输入有效的触发阈值");
|
||||
return false;
|
||||
}
|
||||
if (formModel.pointMode === "SOURCE_VALUE") {
|
||||
const min = resolvePositiveInteger(formModel.minText);
|
||||
const max = resolvePositiveInteger(formModel.maxText);
|
||||
if (!min || !max || max < min) {
|
||||
Message.warning("积分数量范围必须是正整数,且最大值不能小于最小值");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const beginAt = resolveTimestamp(formModel.beginAtText);
|
||||
const endAt = resolveTimestamp(formModel.endAtText);
|
||||
if (beginAt !== undefined && endAt !== undefined && endAt < beginAt) {
|
||||
@@ -707,13 +438,14 @@ async function saveRule(): Promise<void> {
|
||||
const payload: PointRule = {
|
||||
id: formModel.id || undefined,
|
||||
storeId: formModel.storeId,
|
||||
eventId: formModel.eventId,
|
||||
ruleMode: "SIMPLE",
|
||||
triggerSourceType: formModel.triggerSourceType,
|
||||
triggerRefType: formModel.triggerSourceType === "EVENT_RECORD" ? "EVENT" : undefined,
|
||||
triggerRefId: formModel.triggerSourceType === "EVENT_RECORD" ? formModel.triggerRefId : undefined,
|
||||
name: formModel.name.trim(),
|
||||
status: formModel.status,
|
||||
triggerType: formModel.triggerType,
|
||||
pointMode: formModel.pointMode,
|
||||
pointValue: formModel.pointMode === "FIXED" ? resolveSignedPointValue(formModel.pointValueText, formModel.pointAction) : null,
|
||||
conditionJson: buildCondition(),
|
||||
pointValue: resolvePointValue() ?? null,
|
||||
groovyScriptId: undefined,
|
||||
beginAt: resolveTimestamp(formModel.beginAtText),
|
||||
endAt: resolveTimestamp(formModel.endAtText),
|
||||
exclusive: formModel.exclusive,
|
||||
@@ -742,37 +474,19 @@ async function fillForm(): Promise<void> {
|
||||
Object.assign(formModel, {
|
||||
id: current.id || "",
|
||||
storeId: current.storeId || formModel.storeId,
|
||||
eventId: current.eventId || "",
|
||||
triggerSourceType: current.triggerSourceType || "EVENT_RECORD",
|
||||
triggerRefId: current.triggerRefId || "",
|
||||
name: current.name || "",
|
||||
status: current.status === "ACTIVE" ? "ACTIVE" : current.status === "INACTIVE" ? "INACTIVE" : "DRAFT",
|
||||
triggerType: current.triggerType || "EVERY_TIME",
|
||||
pointMode: current.pointMode || "FIXED",
|
||||
pointAction: current.pointValue !== undefined && current.pointValue !== null
|
||||
? current.pointValue < 0 ? "CONSUME" : "EARN"
|
||||
: current.conditionJson?.min !== undefined && current.conditionJson.min < 0 ? "CONSUME" : "EARN",
|
||||
pointAction: current.pointValue !== undefined && current.pointValue !== null && current.pointValue < 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(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: [],
|
||||
beginAtText: current.beginAt ? Time.toDateTime(current.beginAt) : "",
|
||||
endAtText: current.endAt ? Time.toDateTime(current.endAt) : "",
|
||||
exclusive: current.exclusive ?? false,
|
||||
remark: current.remark || ""
|
||||
});
|
||||
await loadEventList();
|
||||
const valueUnit = selectedSourceValueUnit.value;
|
||||
formModel.tiers = current.conditionJson?.tiers?.length
|
||||
? current.conditionJson.tiers.map((tier, index, list) => createTierForm(tier, index === list.length - 1, valueUnit))
|
||||
: [createTierForm(undefined, true, valueUnit)];
|
||||
return;
|
||||
}
|
||||
await loadEventList();
|
||||
if (!formModel.tiers.length) {
|
||||
formModel.tiers.push(createTierForm(undefined, true, selectedSourceValueUnit.value));
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -821,54 +535,10 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.source-condition {
|
||||
padding: .75rem 1rem 1rem;
|
||||
|
||||
.source-title {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.source-inputs {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: .5rem;
|
||||
|
||||
.t-input {
|
||||
flex: 1;
|
||||
border: 1px solid var(--td-component-border);
|
||||
padding: .25rem .5rem;
|
||||
border-radius: .5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tier-condition {
|
||||
padding: .75rem 1rem 1rem;
|
||||
|
||||
.window-row {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: .5rem 0;
|
||||
|
||||
.t-input {
|
||||
flex: 1;
|
||||
border: 1px solid var(--td-component-border);
|
||||
padding: .25rem .5rem;
|
||||
border-radius: .5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.window-label {
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
|
||||
.tips {
|
||||
.form-tips {
|
||||
padding: 0 1rem;
|
||||
font-size: .8125rem;
|
||||
color: #52607a;
|
||||
font-size: .75rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -880,15 +550,9 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
|
||||
|
||||
.picker-text,
|
||||
.source-condition p {
|
||||
.form-tips {
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.source-inputs .t-input {
|
||||
background: rgba(15, 23, 42, .72);
|
||||
border-color: rgba(148, 163, 184, .16);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user