add point
This commit is contained in:
@@ -17,6 +17,16 @@
|
||||
v-if="matchedCustomer"
|
||||
:customer="matchedCustomer"
|
||||
/>
|
||||
<div v-if="showSourceValueInput" class="source-value-panel">
|
||||
<div class="source-value-title">自定义积分</div>
|
||||
<t-input
|
||||
v-model.trim="pointValueText"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
:placeholder="sourceValuePlaceholder"
|
||||
/>
|
||||
</div>
|
||||
<t-cell-group
|
||||
v-if="recentRecordList.length"
|
||||
title="最近登记记录"
|
||||
@@ -81,13 +91,15 @@ import type { EventItem } from "@/types/EventItem";
|
||||
import type { EventRecord } from "@/types/EventRecord";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getEventRecordPhotoURL } from "@/utils/eventRecord";
|
||||
import { Storage, Time } from "timi-web";
|
||||
import { Storage, Time, useUserStore } from "timi-web";
|
||||
import { loadSourceValueRange } from "@/utils/point";
|
||||
|
||||
defineOptions({
|
||||
name: "QuickSignInPage"
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const settingStore = useSettingStore();
|
||||
|
||||
// ---------- 登记事件 ----------
|
||||
@@ -106,15 +118,17 @@ async function loadActions(): Promise<void> {
|
||||
if (selectedEventId.value) {
|
||||
Storage.setString(EventItemStorageKey, selectedEventId);
|
||||
}
|
||||
await loadSourceValueRule();
|
||||
}
|
||||
|
||||
function selectEvent(eventId?: string): void {
|
||||
async function selectEvent(eventId?: string): Promise<void> {
|
||||
if (!eventId) {
|
||||
return;
|
||||
}
|
||||
selectedEventId.value = eventId;
|
||||
Storage.setString(EventItemStorageKey, selectedEventId);
|
||||
eventSelectorVisible.value = false;
|
||||
await loadSourceValueRule();
|
||||
Toast.success("登记事件已切换");
|
||||
}
|
||||
|
||||
@@ -177,23 +191,58 @@ async function toRecordDetail(id: string): Promise<void> {
|
||||
// ---------- 表单 ----------
|
||||
|
||||
const submitting = ref(false);
|
||||
const pointValueText = ref("");
|
||||
const sourceValueRange = ref<[number, number]>();
|
||||
const canSubmitRegister = computed(() => !!matchedCustomer.value && !!selectedEventId.value);
|
||||
const showSourceValueInput = computed(() => (
|
||||
userStore.hasPermissions(permissionCodes.point.sourceValue)
|
||||
&& !!sourceValueRange.value
|
||||
));
|
||||
const sourceValuePlaceholder = computed(() => {
|
||||
const range = sourceValueRange.value;
|
||||
return range ? `请输入 ${range[0]}-${range[1]} 的正整数` : "请输入积分";
|
||||
});
|
||||
|
||||
async function loadSourceValueRule(): Promise<void> {
|
||||
if (!selectedEventId.value || !userStore.hasPermissions(permissionCodes.point.sourceValue)) {
|
||||
sourceValueRange.value = undefined;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
sourceValueRange.value = await loadSourceValueRange([selectedEventId.value]);
|
||||
} catch {
|
||||
sourceValueRange.value = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSourceValue(): number | undefined {
|
||||
const value = Number(pointValueText.value);
|
||||
return Number.isSafeInteger(value) && 0 < value ? value : undefined;
|
||||
}
|
||||
|
||||
async function doSubmit(): Promise<void> {
|
||||
const customer = matchedCustomer.value;
|
||||
if (!customer) {
|
||||
return;
|
||||
}
|
||||
const pointValue = resolveSourceValue();
|
||||
const range = sourceValueRange.value;
|
||||
if (showSourceValueInput.value && (!pointValue || !range || pointValue < range[0] || range[1] < pointValue)) {
|
||||
Toast.warning(`自定义积分必须是 ${range?.[0] || 1}-${range?.[1] || 0} 的正整数`);
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
try {
|
||||
await EventRecordAPI.create({
|
||||
customerId: customer.id,
|
||||
eventId: selectedEventId.value,
|
||||
pointValue: showSourceValueInput.value ? pointValue : undefined,
|
||||
remark: "客户快速扫码登记"
|
||||
});
|
||||
scanStatus.value = `登记成功:${customer.name || customer.code || scanCode.value}。`;
|
||||
scanCode.value = "";
|
||||
matchedCustomer.value = undefined;
|
||||
pointValueText.value = "";
|
||||
recentRecordList.value = [];
|
||||
latestDecodedText = "";
|
||||
scannerSessionKey.value += 1;
|
||||
@@ -251,6 +300,23 @@ async function doSubmit(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
.source-value-panel {
|
||||
padding: .75rem 1rem;
|
||||
background: rgba(255, 255, 255, .94);
|
||||
box-shadow: 0 .75rem 2rem rgba(15, 23, 42, .08);
|
||||
border-radius: .875rem;
|
||||
|
||||
.source-value-title {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.t-input {
|
||||
margin-top: .5rem;
|
||||
border: 1px solid var(--td-component-border);
|
||||
border-radius: .75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.code-box {
|
||||
padding: .875rem;
|
||||
background: #f7faff;
|
||||
@@ -339,6 +405,11 @@ async function doSubmit(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
.source-value-panel {
|
||||
background: rgba(15, 23, 42, .88);
|
||||
box-shadow: 0 .75rem 2rem rgba(2, 6, 23, .32);
|
||||
}
|
||||
|
||||
.code-box {
|
||||
background: rgba(30, 41, 59, .9);
|
||||
border-color: rgba(148, 163, 184, .16);
|
||||
|
||||
Reference in New Issue
Block a user