fix user profile update

This commit is contained in:
Timi
2026-08-07 18:20:29 +08:00
parent 82e717e3c6
commit 16fa5fdd36
10 changed files with 386 additions and 73 deletions
+78 -3
View File
@@ -18,6 +18,9 @@
</template>
</t-input>
</t-form-item>
<t-form-item v-if="isGlobalManager" label="门店" required-mark arrow @click="openStorePicker">
<div class="picker-text" v-text="selectedStoreName" />
</t-form-item>
<div v-if="scannerVisible && scannerTarget === 'code'" class="code-scanner-wrapper">
<code-scanner
visible
@@ -153,31 +156,46 @@
@change="handleIntroducerChange"
/>
</div>
<t-popup v-model="storePickerVisible" placement="bottom">
<t-picker
v-model="storePickerDraft"
:columns="storePickerColumns"
title="选择门店"
@cancel="storePickerVisible = false"
@confirm="confirmStorePicker"
/>
</t-popup>
</template>
<script setup lang="ts">
import { AttachmentAPI } from "timi-web";
import { AttachmentAPI, useUserStore } from "timi-web";
import { Toast } from "tdesign-mobile-vue";
import CustomerAPI from "@/api/CustomerAPI";
import BodyAreaSelector from "@/components/BodyAreaSelector.vue";
import CodeScanner from "@/components/CodeScanner.vue";
import CustomerSelector from "@/components/CustomerSelector.vue";
import PhotoField from "@/components/PhotoField.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { useSettingStore } from "@/store/settingStore";
import type { BodyAreaValue, Customer } from "@/types/Customer";
import { createBodyAreaValue, normalizeBodyAreaValue } from "@/utils/customer";
import { permissionCodes } from "@/utils/permission";
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
import { compressUploadImage } from "@/utils/imageCompression";
type PickerValue = string | number;
defineOptions({
name: "CustomerEdit"
});
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const settingStore = useSettingStore();
const currentStoreStore = useCurrentStoreStore();
const isCreateMode = computed(() => route.name === "CustomerCreate");
const savePermissionCode = computed(() => isCreateMode.value ? permissionCodes.customer.create : permissionCodes.customer.update);
const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
let latestDecodedText = "";
@@ -268,9 +286,60 @@ function openPhotoPicker(): void {
photoInputRef.value?.click();
}
const canSubmit = computed(() => formData.name?.trim());
const canSubmit = computed(() => formData.name?.trim() && formData.storeId);
// ---------- 门店选择 ----------
const storePickerVisible = ref(false);
const storePickerDraft = ref<PickerValue[]>([]);
const storePickerColumns = computed(() => [
currentStoreStore.storeList.map(item => ({
label: item.name || item.code || "未命名门店",
value: item.id || ""
})).filter(item => item.value)
]);
const selectedStoreName = computed(() => {
const store = currentStoreStore.storeList.find(item => item.id === formData.storeId);
return store?.name || store?.code || "请选择门店";
});
function openStorePicker(): void {
if (!currentStoreStore.storeList.length) {
Toast.warning("暂无可选门店");
return;
}
storePickerDraft.value = [formData.storeId || ""];
storePickerVisible.value = true;
}
function confirmStorePicker(): void {
const storeId = String(storePickerDraft.value[0] || "");
if (!storeId) {
return;
}
formData.storeId = storeId;
currentStoreStore.selectStore(storeId);
storePickerVisible.value = false;
}
async function prepareStoreScope(): Promise<void> {
if (isGlobalManager.value) {
await currentStoreStore.loadStoreList();
const queryStoreId = String(route.query.storeId || "");
formData.storeId = currentStoreStore.storeList.some(item => item.id === queryStoreId)
? queryStoreId
: currentStoreStore.currentStoreId;
return;
}
const store = await currentStoreStore.loadLoginStore();
formData.storeId = store?.id || "";
}
async function loadDetail() {
await prepareStoreScope();
const id = String(route.params.id || "");
if (!id) {
return;
@@ -278,6 +347,7 @@ async function loadDetail() {
try {
const customer = await CustomerAPI.detail(id);
Object.assign(formData, customer);
formData.storeId = customer.storeId || formData.storeId;
selectedAreas.value = normalizeBodyAreaValue(customer.conditioningPart);
introducerCustomerId.value = customer.introducerCustomer?.id || "";
} catch (err) {
@@ -334,6 +404,11 @@ async function handlePhotoSelected(event: Event): Promise<void> {
const isSubmitting = ref(false);
async function doSubmit(): Promise<void> {
if (!formData.storeId) {
Toast.warning("请选择门店");
return;
}
isSubmitting.value = true;
try {
formData.conditioningPart = selectedAreas.value;