fix edit customer lost photo
This commit is contained in:
@@ -59,7 +59,7 @@
|
|||||||
:loading="isPhotoUploading"
|
:loading="isPhotoUploading"
|
||||||
:preview="false"
|
:preview="false"
|
||||||
@add="openPhotoPicker"
|
@add="openPhotoPicker"
|
||||||
@clear="photoTempFileId = ''"
|
@clear="handlePhotoClear"
|
||||||
/>
|
/>
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
<t-form-item label="性别">
|
<t-form-item label="性别">
|
||||||
@@ -168,7 +168,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { AttachmentAPI, useUserStore } from "timi-web";
|
import { AttachmentAPI, useUserStore, type Attachment } from "timi-web";
|
||||||
import { Toast } from "tdesign-mobile-vue";
|
import { Toast } from "tdesign-mobile-vue";
|
||||||
import CustomerAPI from "@/api/CustomerAPI";
|
import CustomerAPI from "@/api/CustomerAPI";
|
||||||
import BodyAreaSelector from "@/components/BodyAreaSelector.vue";
|
import BodyAreaSelector from "@/components/BodyAreaSelector.vue";
|
||||||
@@ -178,7 +178,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, normalizeBodyAreaValue } from "@/utils/customer";
|
import { createBodyAreaValue, getCustomerPhotoURL, 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";
|
||||||
|
|
||||||
@@ -279,6 +279,8 @@ const photoInputRef = ref<HTMLInputElement>();
|
|||||||
const photoTempFileId = ref("");
|
const photoTempFileId = ref("");
|
||||||
const isPhotoUploading = ref(false);
|
const isPhotoUploading = ref(false);
|
||||||
const photoURL = ref();
|
const photoURL = ref();
|
||||||
|
const originalAttachmentList = ref<Attachment[]>([]);
|
||||||
|
const photoChanged = ref(false);
|
||||||
const selectedAreas = ref<BodyAreaValue>(createBodyAreaValue());
|
const selectedAreas = ref<BodyAreaValue>(createBodyAreaValue());
|
||||||
const formData = reactive<Customer>({
|
const formData = reactive<Customer>({
|
||||||
});
|
});
|
||||||
@@ -349,6 +351,10 @@ async function loadDetail() {
|
|||||||
const customer = await CustomerAPI.detail(id);
|
const customer = await CustomerAPI.detail(id);
|
||||||
Object.assign(formData, customer);
|
Object.assign(formData, customer);
|
||||||
formData.storeId = customer.storeId || formData.storeId;
|
formData.storeId = customer.storeId || formData.storeId;
|
||||||
|
photoURL.value = getCustomerPhotoURL(customer);
|
||||||
|
originalAttachmentList.value = [...(customer.attachmentList || [])];
|
||||||
|
photoTempFileId.value = "";
|
||||||
|
photoChanged.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,12 +400,18 @@ async function handlePhotoSelected(event: Event): Promise<void> {
|
|||||||
const [tempFile] = await AttachmentAPI.upload(compressedFile);
|
const [tempFile] = await AttachmentAPI.upload(compressedFile);
|
||||||
photoTempFileId.value = tempFile.id;
|
photoTempFileId.value = tempFile.id;
|
||||||
photoURL.value = AttachmentAPI.getTempReadURL(tempFile.id);
|
photoURL.value = AttachmentAPI.getTempReadURL(tempFile.id);
|
||||||
|
photoChanged.value = true;
|
||||||
} finally {
|
} finally {
|
||||||
isPhotoUploading.value = false;
|
isPhotoUploading.value = false;
|
||||||
input.value = "";
|
input.value = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handlePhotoClear(): void {
|
||||||
|
photoTempFileId.value = "";
|
||||||
|
photoChanged.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- 保存 ----------
|
// ---------- 保存 ----------
|
||||||
|
|
||||||
const isSubmitting = ref(false);
|
const isSubmitting = ref(false);
|
||||||
@@ -415,10 +427,12 @@ 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 = photoTempFileId.value ? [{
|
payload.attachmentList = photoChanged.value
|
||||||
|
? (photoTempFileId.value ? [{
|
||||||
attachType: "PHOTO",
|
attachType: "PHOTO",
|
||||||
tempFileId: photoTempFileId.value
|
tempFileId: photoTempFileId.value
|
||||||
}] : undefined;
|
}] : [])
|
||||||
|
: [...originalAttachmentList.value];
|
||||||
delete payload.introducerCustomer;
|
delete payload.introducerCustomer;
|
||||||
|
|
||||||
if (isCreateMode.value) {
|
if (isCreateMode.value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user