support consume point

This commit is contained in:
Timi
2026-08-18 16:46:13 +08:00
parent eaee1ae49b
commit eb6b8beb6b
14 changed files with 281 additions and 99 deletions
+16 -13
View File
@@ -83,7 +83,7 @@
</t-form-item>
</div>
<div v-if="showSourceValueInput" class="source-value-panel">
<div class="source-value-title">自定义积分</div>
<div class="source-value-title" v-text="sourceValueAction === 'CONSUME' ? '消耗积分' : '发放积分'" />
<t-input
v-model.trim="pointValueText"
type="number"
@@ -146,10 +146,11 @@ import PhotoScroller from "@/components/PhotoScroller.vue";
import { useSettingStore } from "@/store/settingStore";
import type { Customer } from "@/types/Customer";
import type { EventItem } from "@/types/EventItem";
import type { PointAction } from "@/types/Point";
import { getCustomerPhotoURL } from "@/utils/customer";
import { getEventNumberValuePlaceholder, resolveEventNumberValue } from "@/utils/eventValue";
import { permissionCodes } from "@/utils/permission";
import { loadSourceValueRange } from "@/utils/point";
import { loadSourceValueConfig, type SourceValueConfig } from "@/utils/point";
import { compressUploadImage, compressUploadImageList } from "@/utils/imageCompression";
import EventSelector from "@/components/EventSelector.vue";
import EventRecordAPI from "@/api/EventRecordAPI.ts";
@@ -171,31 +172,33 @@ const selectedNumberEventList = computed(() => selectedEventIdList.value
.map(eventId => eventList.value.find(item => item.id === eventId))
.filter((item): item is EventItem => item?.valueType === "NUMBER"));
const pointValueText = ref("");
const sourceValueRange = ref<[number, number]>();
const sourceValueConfig = ref<SourceValueConfig>();
const sourceValueAction = ref<PointAction>("EARN");
const showSourceValueInput = computed(() => (
userStore.hasPermissions(permissionCodes.point.sourceValue)
&& !!sourceValueRange.value
&& !!sourceValueConfig.value
));
const sourceValuePlaceholder = computed(() => {
const range = sourceValueRange.value;
return range ? `请输入 ${range[0]}-${range[1]} 的正整数` : "请输入积分";
const range = sourceValueConfig.value?.range;
return range ? `请输入 ${range[0]}-${range[1]} 的数量` : "请输入数量";
});
async function loadSourceValueRule(): Promise<void> {
if (!selectedEventIdList.value.length || !userStore.hasPermissions(permissionCodes.point.sourceValue)) {
sourceValueRange.value = undefined;
sourceValueConfig.value = undefined;
return;
}
try {
sourceValueRange.value = await loadSourceValueRange(selectedEventIdList.value);
sourceValueConfig.value = await loadSourceValueConfig(selectedEventIdList.value);
sourceValueAction.value = sourceValueConfig.value?.action || "EARN";
} catch {
sourceValueRange.value = undefined;
sourceValueConfig.value = undefined;
}
}
function resolveSourceValue(): number | undefined {
const value = Number(pointValueText.value);
return Number.isSafeInteger(value) && 0 < value ? value : undefined;
return Number.isSafeInteger(value) && 0 < value ? sourceValueAction.value === "CONSUME" ? -value : value : undefined;
}
function getNumberValuePlaceholder(event: EventItem): string {
@@ -640,9 +643,9 @@ function validateForm(): string {
}
if (showSourceValueInput.value) {
const pointValue = resolveSourceValue();
const range = sourceValueRange.value;
if (!pointValue || !range || pointValue < range[0] || range[1] < pointValue) {
showToast(`自定义积分必须是 ${range?.[0] || 1}-${range?.[1] || 0} 的正整数`, "warning");
const range = sourceValueConfig.value?.range;
if (!pointValue || !range || Math.abs(pointValue) < range[0] || range[1] < Math.abs(pointValue)) {
showToast(`积分数量必须是 ${range?.[0] || 1}-${range?.[1] || 0} 的正整数`, "warning");
return "";
}
}