update permission and product
This commit is contained in:
@@ -75,25 +75,6 @@
|
||||
@add="capturePhoto"
|
||||
/>
|
||||
</div>
|
||||
<t-form
|
||||
v-if="showSourceValueInput"
|
||||
class="input-form"
|
||||
label-align="left"
|
||||
label-width="6rem"
|
||||
>
|
||||
<t-form-item label="积分动作" content-align="right">
|
||||
<span class="form-text" v-text="sourceValueAction === 'CONSUME' ? '消耗积分' : '发放积分'" />
|
||||
</t-form-item>
|
||||
<t-form-item label="积分数量" required-mark>
|
||||
<t-input
|
||||
v-model.trim="pointValueText"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
:placeholder="sourceValuePlaceholder"
|
||||
/>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-cell-group
|
||||
v-if="recentRecordList.length"
|
||||
title="最近登记记录"
|
||||
@@ -145,16 +126,14 @@ import type { Customer } from "@/types/Customer";
|
||||
import type { EventItem, EventOptionSelectionMap } from "@/types/EventItem";
|
||||
import type { EventRecord } from "@/types/EventRecord";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import type { PointAction } from "@/types/Point";
|
||||
import { getEventNumberValuePlaceholder, resolveEventNumberValue } from "@/utils/eventValue";
|
||||
import { isPackagePurchaseEvent } from "@/utils/event";
|
||||
import { isRetiredEvent } from "@/utils/event";
|
||||
import { resolveSelectedOptionGroupList, validateEventOptionSelection } from "@/utils/eventOption";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getEventRecordPhotoURL, hasPhotoAttachment } from "@/utils/eventRecord";
|
||||
import { compressUploadImageList } from "@/utils/imageCompression";
|
||||
import { Storage, Time } from "timi-web";
|
||||
import { AttachmentAPI, useUserStore, type Attachment } from "timi-web-api";
|
||||
import { loadSourceValueConfig, type SourceValueConfig } from "@/utils/point";
|
||||
import { AttachmentAPI, type Attachment } from "timi-web-api";
|
||||
import EventSelector from "@/components/EventSelector.vue";
|
||||
import { Space } from "timi-tdesign-mobile";
|
||||
|
||||
@@ -163,7 +142,6 @@ defineOptions({
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const settingStore = useSettingStore();
|
||||
|
||||
// ---------- 登记事件 ----------
|
||||
@@ -179,7 +157,6 @@ const selectedEventList = computed(() => selectedEventIdList.value
|
||||
.filter((item): item is EventItem => !!item));
|
||||
const selectedNumberEventList = computed(() => selectedEventList.value.filter(item => item.valueType === "NUMBER"));
|
||||
const selectedRequiredPhotoEventList = computed(() => selectedEventList.value.filter(item => item.requirePhoto === true));
|
||||
let sourceValueRequestNo = 0;
|
||||
|
||||
function normalizeEventId(item?: EventItem): string {
|
||||
if (!item || item.id === undefined || item.id === null) {
|
||||
@@ -195,7 +172,7 @@ async function loadActions(): Promise<void> {
|
||||
isEventLoading.value = true;
|
||||
eventLoadFailed.value = false;
|
||||
try {
|
||||
eventList.value = (await EventAPI.listValid()).filter(item => !isPackagePurchaseEvent(item));
|
||||
eventList.value = (await EventAPI.listValid()).filter(item => !isRetiredEvent(item));
|
||||
selectedEventIdList.value = buildInitialSelectedEventIdList();
|
||||
syncStoredEventId();
|
||||
} catch (error) {
|
||||
@@ -203,12 +180,10 @@ async function loadActions(): Promise<void> {
|
||||
eventLoadFailed.value = true;
|
||||
eventList.value = [];
|
||||
selectedEventIdList.value = [];
|
||||
sourceValueConfig.value = undefined;
|
||||
Message.error("登记事件加载失败");
|
||||
} finally {
|
||||
isEventLoading.value = false;
|
||||
}
|
||||
await loadSourceValueRule();
|
||||
}
|
||||
|
||||
function buildInitialSelectedEventIdList(): string[] {
|
||||
@@ -231,7 +206,6 @@ function normalizeSelectedEventIdList(eventIdList: string[]): string[] {
|
||||
async function handleEventSelectionChange(eventIdList: string[]): Promise<void> {
|
||||
selectedEventIdList.value = normalizeSelectedEventIdList(eventIdList);
|
||||
syncStoredEventId();
|
||||
await loadSourceValueRule();
|
||||
}
|
||||
|
||||
function resolveRecordOptionGroupList(eventId: string) {
|
||||
@@ -320,45 +294,8 @@ async function toRecordDetail(id: string): Promise<void> {
|
||||
// ---------- 表单 ----------
|
||||
|
||||
const submitting = ref(false);
|
||||
const pointValueText = ref("");
|
||||
const numberValueTextMap = reactive<Record<string, string>>({});
|
||||
const sourceValueConfig = ref<SourceValueConfig>();
|
||||
const sourceValueAction = ref<PointAction>("EARN");
|
||||
const canSubmitRegister = computed(() => !!matchedCustomer.value && !!selectedEventIdList.value.length);
|
||||
const showSourceValueInput = computed(() => (
|
||||
userStore.hasPermissions(permissionCodes.point.sourceValue)
|
||||
&& !!sourceValueConfig.value
|
||||
));
|
||||
const sourceValuePlaceholder = computed(() => {
|
||||
const range = sourceValueConfig.value?.range;
|
||||
return range ? `请输入 ${range[0]}-${range[1]} 的数量` : "请输入数量";
|
||||
});
|
||||
|
||||
async function loadSourceValueRule(): Promise<void> {
|
||||
const requestNo = ++sourceValueRequestNo;
|
||||
if (!selectedEventIdList.value.length || !userStore.hasPermissions(permissionCodes.point.sourceValue)) {
|
||||
sourceValueConfig.value = undefined;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const config = await loadSourceValueConfig(selectedEventIdList.value);
|
||||
if (requestNo !== sourceValueRequestNo) {
|
||||
return;
|
||||
}
|
||||
sourceValueConfig.value = config;
|
||||
sourceValueAction.value = sourceValueConfig.value?.action || "EARN";
|
||||
} catch {
|
||||
if (requestNo !== sourceValueRequestNo) {
|
||||
return;
|
||||
}
|
||||
sourceValueConfig.value = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSourceValue(): number | undefined {
|
||||
const value = Number(pointValueText.value);
|
||||
return Number.isSafeInteger(value) && 0 < value ? sourceValueAction.value === "CONSUME" ? -value : value : undefined;
|
||||
}
|
||||
|
||||
function getNumberValuePlaceholder(event: EventItem): string {
|
||||
return getEventNumberValuePlaceholder(event);
|
||||
@@ -484,19 +421,12 @@ async function doSubmit(): Promise<void> {
|
||||
if (!validateNumberValueList()) {
|
||||
return;
|
||||
}
|
||||
const pointValue = resolveSourceValue();
|
||||
const range = sourceValueConfig.value?.range;
|
||||
if (showSourceValueInput.value && (!pointValue || !range || Math.abs(pointValue) < range[0] || range[1] < Math.abs(pointValue))) {
|
||||
Message.warning(`积分数量必须是 ${range?.[0] || 1}-${range?.[1] || 0} 的正整数`);
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
try {
|
||||
await EventRecordAPI.createBatch(selectedEventIdList.value.map(eventId => ({
|
||||
eventId,
|
||||
customerId: customer.id,
|
||||
selectedOptionGroupList: resolveRecordOptionGroupList(eventId),
|
||||
pointValue: showSourceValueInput.value ? pointValue : undefined,
|
||||
numberValue: resolveNumberValue(eventId),
|
||||
remark: "客户快速扫码登记",
|
||||
attachmentList: buildPhotoAttachmentList()
|
||||
@@ -504,7 +434,6 @@ async function doSubmit(): Promise<void> {
|
||||
scanStatus.value = `登记成功:${customer.name || customer.code || scanCode.value}。`;
|
||||
scanCode.value = "";
|
||||
matchedCustomer.value = undefined;
|
||||
pointValueText.value = "";
|
||||
recordPhotoItemList.value = [];
|
||||
for (const eventId of Object.keys(numberValueTextMap)) {
|
||||
delete numberValueTextMap[eventId];
|
||||
|
||||
Reference in New Issue
Block a user