Browse Source

feat: 首页新增企业下拉框+修复租户选择bug

alphah 1 week ago
parent
commit
5bcfee44c0
2 changed files with 52 additions and 14 deletions
  1. BIN
      frontend/dist.zip
  2. 52 14
      frontend/src/views/dashboard/tenant.vue

BIN
frontend/dist.zip


+ 52 - 14
frontend/src/views/dashboard/tenant.vue

@@ -27,11 +27,27 @@
     <div class="core-data-section">
       <div class="section-header">
         <h2>转账数据统计</h2>
-        <!-- <a href="#" class="more-link">更多数据</a> -->
+        <div class="section-header-right">
+          <el-select
+            v-if="!is_platform_user"
+            v-model="selectedEnterpriseId"
+            placeholder="选择企业"
+            filterable
+            class="enterprise-select"
+            @change="handleEnterpriseChange"
+          >
+            <el-option
+              v-for="item in enterpriseStore.getEnterpriseList"
+              :key="item.enterprise_id"
+              :label="item.name"
+              :value="item.enterprise_id"
+            />
+          </el-select>
+        </div>
       </div>
 
       <div v-if="is_platform_user" style="margin-bottom: 16px; width: 300px;">
-        <el-select v-model="currentTenantId" placeholder="选择商户" @change="handleTenantChange">
+        <el-select v-model="currentTenantId" placeholder="选择商户">
           <el-option
             v-for="tenant in allTenantData"
             :key="tenant.id"
@@ -111,6 +127,10 @@ const is_platform_user = computed(() => {
 
 const currentTenantId = ref<number | undefined>(undefined);
 
+const selectedEnterpriseId = ref<string | undefined>(
+  enterpriseStore.getCurrentEnterprise?.enterprise_id
+);
+
 const currentEnterpriseId = computed(() => enterpriseStore.getCurrentEnterprise?.enterprise_id);
 
 const currentEnterprise = computed(() => enterpriseStore.getCurrentEnterprise);
@@ -134,18 +154,15 @@ const summaryAmount = ref<{
   amount_of_all?: string;
 }>({});
 
-function handleTenantChange(value: number | undefined) {
-  currentTenantId.value = value;
-}
-
 const allTenantData = ref<TenantTable[]>([]);
 
+function handleEnterpriseChange() {
+  enterpriseStore.setCurrentEnterprise(selectedEnterpriseId.value!);
+}
+
 async function fetchStatAmount() {
-  if (!is_platform_user.value) {
-    currentTenantId.value = undefined;
-  }
   try {
-    const res = await AccountAPI.statAmount(currentTenantId.value, currentEnterpriseId.value);
+    const res = await AccountAPI.statAmount(currentTenantId.value, selectedEnterpriseId.value);
     statAmount.value = res.data.data || {};
   } catch (error) {
     console.error("获取统计金额失败:", error);
@@ -154,7 +171,7 @@ async function fetchStatAmount() {
 
 async function fetchConsumeAmount() {
   try {
-    const res = await AccountAPI.statConsumeAmount(currentTenantId.value, currentEnterpriseId.value);
+    const res = await AccountAPI.statConsumeAmount(currentTenantId.value, selectedEnterpriseId.value);
     consumeAmount.value = res.data.data || {};
   } catch (error) {
     console.error("获取消费统计金额失败:", error);
@@ -163,7 +180,7 @@ async function fetchConsumeAmount() {
 
 async function fetchSummaryAmount() {
   try {
-    const res = await AccountAPI.statSummaryAmount(currentTenantId.value, currentEnterpriseId.value);
+    const res = await AccountAPI.statSummaryAmount(currentTenantId.value, selectedEnterpriseId.value);
     summaryAmount.value = res.data.data || {};
   } catch (error) {
     console.error("获取汇总统计金额失败:", error);
@@ -184,9 +201,14 @@ async function fetchAllTenantData() {
   }
 }
 
-onMounted(() => {
+onMounted(async () => {
   if (is_platform_user.value) {
-    fetchAllTenantData();
+    await fetchAllTenantData();
+  } else {
+    await enterpriseStore.loadEnterpriseList();
+    if (!selectedEnterpriseId.value) {
+      selectedEnterpriseId.value = enterpriseStore.getCurrentEnterprise?.enterprise_id;
+    }
   }
   fetchStatAmount();
   fetchConsumeAmount();
@@ -199,6 +221,12 @@ watch(currentTenantId, () => {
   fetchSummaryAmount();
 });
 
+watch(selectedEnterpriseId, () => {
+  fetchStatAmount();
+  fetchConsumeAmount();
+  fetchSummaryAmount();
+});
+
 // 租户仪表盘组件
 </script>
 
@@ -278,6 +306,16 @@ watch(currentTenantId, () => {
   color: #303133;
 }
 
+.section-header-right {
+  display: flex;
+  align-items: center;
+  gap: 12px;
+}
+
+.enterprise-select {
+  width: 260px;
+}
+
 .more-link {
   font-size: 12px;
   color: #409eff;