Procházet zdrojové kódy

feat: 门店档案 - 文档更新为功能说明 + 新增门店改为下拉选择并自动带出地址

skyline před 4 dny
rodič
revize
b98a5b01d1

+ 54 - 10
haha-admin-web/src/views/shop-archive/detail.vue

@@ -11,6 +11,7 @@ import {
   uploadToOss,
   deleteOssFile
 } from "@/api/shopArchive";
+import { getEnabledShops } from "@/api/shop";
 import type {
   ShopArchiveForm,
   FixedAsset,
@@ -31,10 +32,41 @@ const activeTab = ref("basic");
 const loading = ref(false);
 const saving = ref(false);
 
+// 门店下拉选项
+const shopOptions = ref<Array<{ id: string; name: string; address: string }>>([]);
+
+// 加载门店列表(用于下拉选择)
+async function loadShopOptions() {
+  try {
+    const res = await getEnabledShops();
+    if (res && res.data) {
+      shopOptions.value = res.data.map((s: any) => ({
+        id: String(s.id),
+        name: s.name,
+        address: s.address || ""
+      }));
+    }
+  } catch (error) {
+    console.error("加载门店列表失败:", error);
+  }
+}
+
+// 选择门店后自动带出地址
+function handleShopChange(shopId: string) {
+  const shop = shopOptions.value.find(s => s.id === shopId);
+  if (shop) {
+    form.shopName = shop.name;
+    form.shopAddress = shop.address;
+  } else {
+    form.shopName = "";
+    form.shopAddress = "";
+  }
+}
+
 // 页面模式
-const isCreate = computed(() => !route.params.id);
+const isCreate = computed(() => route.query.mode === "create");
 const isView = computed(() => route.query.mode === "view");
-const isEdit = computed(() => !!route.params.id && route.query.mode !== "view");
+const isEdit = computed(() => route.query.mode === "edit");
 const pageTitle = computed(() => {
   if (isCreate.value) return "新增门店档案";
   if (isView.value) return "查看门店档案";
@@ -381,8 +413,8 @@ async function handleSave() {
     return;
   }
 
-  if (!form.shopName) {
-    ElMessage.warning("请输入门店名称");
+  if (!form.shopId) {
+    ElMessage.warning("请选择门店");
     return;
   }
 
@@ -421,7 +453,8 @@ function goBack() {
 
 onMounted(() => {
   loadEnumOptions();
-  if (route.params.id) {
+  loadShopOptions();
+  if (route.params.id && !isCreate.value) {
     loadArchiveDetail();
   }
 });
@@ -448,11 +481,22 @@ onMounted(() => {
         <el-tab-pane label="门店基础信息" name="basic">
           <el-row :gutter="24">
             <el-col :span="8">
-              <el-form-item label="门店名称" required>
-                <el-input
-                  v-model="form.shopName"
-                  placeholder="请输入门店名称"
-                />
+              <el-form-item label="选择门店" required>
+                <el-select
+                  v-model="form.shopId"
+                  placeholder="请选择门店"
+                  clearable
+                  filterable
+                  class="w-full"
+                  @change="handleShopChange"
+                >
+                  <el-option
+                    v-for="shop in shopOptions"
+                    :key="shop.id"
+                    :label="shop.name"
+                    :value="shop.id"
+                  />
+                </el-select>
               </el-form-item>
             </el-col>
             <el-col :span="8">

+ 2 - 2
haha-admin-web/src/views/shop-archive/utils/hook.tsx

@@ -181,12 +181,12 @@ export function useShopArchive(tableRef: Ref) {
 
   // 新增
   function handleAdd() {
-    router.push("/operation/shop-archive/create");
+    router.push({ path: "/operation/shop-archive/detail", query: { mode: "create" } });
   }
 
   // 编辑
   function handleUpdate(row: ShopArchive) {
-    router.push(`/operation/shop-archive/edit/${row.id}`);
+    router.push(`/operation/shop-archive/detail/${row.id}?mode=edit`);
   }
 
   // 查看