add customer point card

This commit is contained in:
Timi
2026-08-20 01:30:07 +08:00
parent f4fb604f53
commit 805e8ecb84
3 changed files with 90 additions and 16 deletions
+15 -1
View File
@@ -26,6 +26,16 @@
<pass-time-label :timestamp="customer.createdAt" underline /> <pass-time-label :timestamp="customer.createdAt" underline />
</template> </template>
</t-cell> </t-cell>
<t-cell>
<template #title>
<photo-scroller
:model-value="photoList"
:show-add="false"
:show-remove="false"
title="照片列表"
/>
</template>
</t-cell>
</t-cell-group> </t-cell-group>
<customer-tag-card <customer-tag-card
v-if="customer && canReadTag" v-if="customer && canReadTag"
@@ -171,7 +181,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { DialogPlugin, Toast } from "tdesign-mobile-vue"; import { DialogPlugin, Toast } from "tdesign-mobile-vue";
import { PassTimeLabel, Text, useUserStore } from "timi-web"; import { AttachmentAPI, PassTimeLabel, Text, useUserStore } from "timi-web";
import CustomerAPI from "@/api/CustomerAPI"; import CustomerAPI from "@/api/CustomerAPI";
import PointAPI from "@/api/PointAPI"; import PointAPI from "@/api/PointAPI";
import TagAPI from "@/api/TagAPI"; import TagAPI from "@/api/TagAPI";
@@ -179,6 +189,7 @@ import BodyAreaSelector from "@/components/BodyAreaSelector.vue";
import CodeScanner from "@/components/CodeScanner.vue"; import CodeScanner from "@/components/CodeScanner.vue";
import CustomerProfileCard from "@/components/CustomerProfileCard.vue"; import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import CustomerSelector from "@/components/CustomerSelector.vue"; import CustomerSelector from "@/components/CustomerSelector.vue";
import PhotoScroller from "@/components/PhotoScroller.vue";
import TagSelector from "@/components/TagSelector.vue"; import TagSelector from "@/components/TagSelector.vue";
import CustomerTagCard from "@/pages/customer/component/CustomerTagCard.vue"; import CustomerTagCard from "@/pages/customer/component/CustomerTagCard.vue";
import { useSettingStore } from "@/store/settingStore"; import { useSettingStore } from "@/store/settingStore";
@@ -213,6 +224,9 @@ const isLunarBirthdate = computed(() => customer.value?.birthdateCalendar === "L
const solarBirthdateText = computed(() => formatSolarBirthdate(customer.value)); const solarBirthdateText = computed(() => formatSolarBirthdate(customer.value));
const birthdateText = computed(() => showSolarBirthdate.value && isLunarBirthdate.value ? solarBirthdateText.value : formatBirthdate(customer.value)); const birthdateText = computed(() => showSolarBirthdate.value && isLunarBirthdate.value ? solarBirthdateText.value : formatBirthdate(customer.value));
const ageText = computed(() => customer.value?.age === undefined || customer.value?.age === null ? "" : `${customer.value.age} 岁`); const ageText = computed(() => customer.value?.age === undefined || customer.value?.age === null ? "" : `${customer.value.age} 岁`);
const photoList = computed(() => (customer.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => AttachmentAPI.getReadURL(item.id || "")));
const selectedAreas = computed<BodyAreaValue>({ const selectedAreas = computed<BodyAreaValue>({
get() { get() {
return normalizeBodyAreaValue(customer.value?.conditioningPart); return normalizeBodyAreaValue(customer.value?.conditioningPart);
+61 -9
View File
@@ -58,10 +58,21 @@
alt-text="客户照片" alt-text="客户照片"
:loading="isPhotoUploading" :loading="isPhotoUploading"
:preview="false" :preview="false"
@add="openPhotoPicker" @add="openPhotoPicker('photo')"
@clear="handlePhotoClear" @clear="handlePhotoClear"
/> />
</t-form-item> </t-form-item>
<t-form-item label="积分卡">
<photo-field
v-model="pointCardURL"
add-text="拍积分卡"
alt-text="积分卡"
:loading="isPointCardUploading"
:preview="false"
@add="openPhotoPicker('pointCard')"
@clear="handlePointCardClear"
/>
</t-form-item>
<t-form-item label="性别"> <t-form-item label="性别">
<t-radio-group class="sex" v-model="formData.gender" variant="default-filled"> <t-radio-group class="sex" v-model="formData.gender" variant="default-filled">
<t-radio :block="false" borderless value="MALE">男</t-radio> <t-radio :block="false" borderless value="MALE">男</t-radio>
@@ -178,7 +189,7 @@ import PhotoField from "@/components/PhotoField.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore"; import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { useSettingStore } from "@/store/settingStore"; import { useSettingStore } from "@/store/settingStore";
import type { BodyAreaValue, Customer } from "@/types/Customer"; import type { BodyAreaValue, Customer } from "@/types/Customer";
import { createBodyAreaValue, getCustomerPhotoURL, normalizeBodyAreaValue } from "@/utils/customer"; import { createBodyAreaValue, getCustomerPhotoURL, getCustomerPointCardURL, normalizeBodyAreaValue } from "@/utils/customer";
import { gaoRoleCodes, permissionCodes } from "@/utils/permission"; import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
import { compressUploadImage } from "@/utils/imageCompression"; import { compressUploadImage } from "@/utils/imageCompression";
@@ -276,16 +287,23 @@ async function handleIntroducerChange(id: string): Promise<void> {
// ---------- 表单 ---------- // ---------- 表单 ----------
const photoInputRef = ref<HTMLInputElement>(); const photoInputRef = ref<HTMLInputElement>();
type PhotoPickerTarget = "photo" | "pointCard";
const photoPickerTarget = ref<PhotoPickerTarget>("photo");
const photoTempFileId = ref(""); const photoTempFileId = ref("");
const isPhotoUploading = ref(false); const isPhotoUploading = ref(false);
const photoURL = ref(); const photoURL = ref();
const pointCardTempFileId = ref("");
const isPointCardUploading = ref(false);
const pointCardURL = ref("");
const originalAttachmentList = ref<Attachment[]>([]); const originalAttachmentList = ref<Attachment[]>([]);
const photoChanged = ref(false); const photoChanged = ref(false);
const pointCardChanged = ref(false);
const selectedAreas = ref<BodyAreaValue>(createBodyAreaValue()); const selectedAreas = ref<BodyAreaValue>(createBodyAreaValue());
const formData = reactive<Customer>({ const formData = reactive<Customer>({
}); });
function openPhotoPicker(): void { function openPhotoPicker(target: PhotoPickerTarget): void {
photoPickerTarget.value = target;
photoInputRef.value?.click(); photoInputRef.value?.click();
} }
@@ -352,9 +370,12 @@ async function loadDetail() {
Object.assign(formData, customer); Object.assign(formData, customer);
formData.storeId = customer.storeId || formData.storeId; formData.storeId = customer.storeId || formData.storeId;
photoURL.value = getCustomerPhotoURL(customer); photoURL.value = getCustomerPhotoURL(customer);
pointCardURL.value = getCustomerPointCardURL(customer);
originalAttachmentList.value = [...(customer.attachmentList || [])]; originalAttachmentList.value = [...(customer.attachmentList || [])];
photoTempFileId.value = ""; photoTempFileId.value = "";
pointCardTempFileId.value = "";
photoChanged.value = false; photoChanged.value = false;
pointCardChanged.value = false;
selectedAreas.value = normalizeBodyAreaValue(customer.conditioningPart); selectedAreas.value = normalizeBodyAreaValue(customer.conditioningPart);
introducerCustomerId.value = customer.introducerCustomerId || customer.introducerCustomer?.id || ""; introducerCustomerId.value = customer.introducerCustomerId || customer.introducerCustomer?.id || "";
} catch (err) { } catch (err) {
@@ -394,15 +415,30 @@ async function handlePhotoSelected(event: Event): Promise<void> {
if (!file) { if (!file) {
return; return;
} }
const isPointCard = photoPickerTarget.value === "pointCard";
if (isPointCard) {
isPointCardUploading.value = true;
} else {
isPhotoUploading.value = true; isPhotoUploading.value = true;
}
try { try {
const compressedFile = await compressUploadImage(file); const compressedFile = await compressUploadImage(file);
const [tempFile] = await AttachmentAPI.upload(compressedFile); const [tempFile] = await AttachmentAPI.upload(compressedFile);
if (isPointCard) {
pointCardTempFileId.value = tempFile.id;
pointCardURL.value = AttachmentAPI.getTempReadURL(tempFile.id);
pointCardChanged.value = true;
} else {
photoTempFileId.value = tempFile.id; photoTempFileId.value = tempFile.id;
photoURL.value = AttachmentAPI.getTempReadURL(tempFile.id); photoURL.value = AttachmentAPI.getTempReadURL(tempFile.id);
photoChanged.value = true; photoChanged.value = true;
}
} finally { } finally {
if (isPointCard) {
isPointCardUploading.value = false;
} else {
isPhotoUploading.value = false; isPhotoUploading.value = false;
}
input.value = ""; input.value = "";
} }
} }
@@ -412,6 +448,11 @@ function handlePhotoClear(): void {
photoChanged.value = true; photoChanged.value = true;
} }
function handlePointCardClear(): void {
pointCardTempFileId.value = "";
pointCardChanged.value = true;
}
// ---------- 保存 ---------- // ---------- 保存 ----------
const isSubmitting = ref(false); const isSubmitting = ref(false);
@@ -427,12 +468,7 @@ async function doSubmit(): Promise<void> {
const payload: Customer = { ...formData }; const payload: Customer = { ...formData };
payload.conditioningPart = selectedAreas.value; payload.conditioningPart = selectedAreas.value;
payload.introducerCustomerId = introducerCustomerId.value || ""; payload.introducerCustomerId = introducerCustomerId.value || "";
payload.attachmentList = photoChanged.value payload.attachmentList = buildAttachmentList();
? (photoTempFileId.value ? [{
attachType: "PHOTO",
tempFileId: photoTempFileId.value
}] : [])
: [...originalAttachmentList.value];
delete payload.introducerCustomer; delete payload.introducerCustomer;
if (isCreateMode.value) { if (isCreateMode.value) {
@@ -455,6 +491,22 @@ async function doSubmit(): Promise<void> {
isSubmitting.value = false; isSubmitting.value = false;
} }
} }
function buildAttachmentList(): Attachment[] {
let attachmentList = [...originalAttachmentList.value];
if (photoChanged.value) {
attachmentList = replaceAttachment(attachmentList, "PHOTO", photoTempFileId.value);
}
if (pointCardChanged.value) {
attachmentList = replaceAttachment(attachmentList, "POINT_CARD", pointCardTempFileId.value);
}
return attachmentList;
}
function replaceAttachment(attachmentList: Attachment[], attachType: "PHOTO" | "POINT_CARD", tempFileId: string): Attachment[] {
const preservedList = attachmentList.filter(item => item.attachType !== attachType);
return tempFileId ? [...preservedList, { attachType, tempFileId }] : preservedList;
}
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
+9 -1
View File
@@ -2,7 +2,15 @@ import { AttachmentAPI } from "timi-web";
import type { BodyAreaValue, Customer } from "@/types/Customer"; import type { BodyAreaValue, Customer } from "@/types/Customer";
export function getCustomerPhotoURL(customer?: Customer): string { export function getCustomerPhotoURL(customer?: Customer): string {
const attachment = customer?.attachmentList?.find(item => item.attachType === "PHOTO"); return getCustomerAttachmentURL(customer, "PHOTO");
}
export function getCustomerPointCardURL(customer?: Customer): string {
return getCustomerAttachmentURL(customer, "POINT_CARD");
}
function getCustomerAttachmentURL(customer: Customer | undefined, attachType: string): string {
const attachment = customer?.attachmentList?.find(item => item.attachType === attachType);
if (!attachment?.id) { if (!attachment?.id) {
return ""; return "";
} }