support consume point
This commit is contained in:
@@ -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 "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
/>
|
||||
</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"
|
||||
@@ -99,11 +99,12 @@ import { useSettingStore } from "@/store/settingStore";
|
||||
import type { Customer } from "@/types/Customer";
|
||||
import type { EventItem } from "@/types/EventItem";
|
||||
import type { EventRecord } from "@/types/EventRecord";
|
||||
import type { PointAction } from "@/types/Point";
|
||||
import { getEventNumberValuePlaceholder, resolveEventNumberValue } from "@/utils/eventValue";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getEventRecordPhotoURL } from "@/utils/eventRecord";
|
||||
import { Storage, Time, useUserStore } from "timi-web";
|
||||
import { loadSourceValueRange } from "@/utils/point";
|
||||
import { loadSourceValueConfig, type SourceValueConfig } from "@/utils/point";
|
||||
|
||||
defineOptions({
|
||||
name: "QuickSignInPage"
|
||||
@@ -206,34 +207,36 @@ async function toRecordDetail(id: string): Promise<void> {
|
||||
const submitting = ref(false);
|
||||
const pointValueText = ref("");
|
||||
const numberValueText = ref("");
|
||||
const sourceValueRange = ref<[number, number]>();
|
||||
const sourceValueConfig = ref<SourceValueConfig>();
|
||||
const sourceValueAction = ref<PointAction>("EARN");
|
||||
const canSubmitRegister = computed(() => !!matchedCustomer.value && !!selectedEventId.value);
|
||||
const showNumberValueInput = computed(() => selectedEvent.value?.valueType === "NUMBER");
|
||||
const numberValuePlaceholder = computed(() => selectedEvent.value ? getEventNumberValuePlaceholder(selectedEvent.value) : "请输入事件数值");
|
||||
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 (!selectedEventId.value || !userStore.hasPermissions(permissionCodes.point.sourceValue)) {
|
||||
sourceValueRange.value = undefined;
|
||||
sourceValueConfig.value = undefined;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
sourceValueRange.value = await loadSourceValueRange([selectedEventId.value]);
|
||||
sourceValueConfig.value = await loadSourceValueConfig([selectedEventId.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 resolveNumberValue(): number | undefined {
|
||||
@@ -255,9 +258,9 @@ async function doSubmit(): Promise<void> {
|
||||
Toast.warning("请填写事件数值");
|
||||
return;
|
||||
}
|
||||
const range = sourceValueRange.value;
|
||||
if (showSourceValueInput.value && (!pointValue || !range || pointValue < range[0] || range[1] < pointValue)) {
|
||||
Toast.warning(`自定义积分必须是 ${range?.[0] || 1}-${range?.[1] || 0} 的正整数`);
|
||||
const range = sourceValueConfig.value?.range;
|
||||
if (showSourceValueInput.value && (!pointValue || !range || Math.abs(pointValue) < range[0] || range[1] < Math.abs(pointValue))) {
|
||||
Toast.warning(`积分数量必须是 ${range?.[0] || 1}-${range?.[1] || 0} 的正整数`);
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
|
||||
Reference in New Issue
Block a user