Ver Fonte

修复互联网医院和App商城订单金额统计无数据的问题

cgp há 2 semanas atrás
pai
commit
dc600351e1

+ 66 - 60
src/views/his/statistics/appOrderCountStats.vue

@@ -3,22 +3,32 @@
     <div class="app-content">
       <div class="title">App商城订单统计</div>
       <el-form class="search-form" :inline="true">
-        <el-form-item>
-          <treeselect
-            :clearable="false"
-            v-model="companyId"
-            :options="deptOptions"
-            :show-count="true"
-            placeholder="请选择归属部门"
-          />
+        <el-form-item label="公司名称" prop="companyId">
+          <el-select
+            style="width: 220px"
+            filterable
+            v-model="queryParams.companyId"
+            placeholder="请选择公司名"
+            clearable
+            size="small"
+          >
+            <el-option
+              v-for="item in companys"
+              :key="item.companyId"
+              :label="item.companyName"
+              :value="item.companyId"
+            />
+          </el-select>
         </el-form-item>
-        <el-form-item>
+
+        <el-form-item label="员工" prop="companyUserId">
           <el-select
             filterable
-            v-model="companyUserId"
+            v-model="queryParams.companyUserId"
             placeholder="请选择员工"
             clearable
             size="small"
+            :disabled="!queryParams.companyId"
           >
             <el-option
               v-for="item in users"
@@ -28,6 +38,7 @@
             />
           </el-select>
         </el-form-item>
+
         <el-form-item label="下单日期">
           <el-date-picker
             clearable
@@ -40,6 +51,7 @@
             end-placeholder="结束日期"
           />
         </el-form-item>
+
         <el-form-item>
           <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
         </el-form-item>
@@ -70,61 +82,64 @@
 
 <script>
 import { getAppOrderCount } from "@/api/company/statistics";
-import { getUserListByDeptId } from "@/api/company/companyUser";
-import { treeselect } from "@/api/company/companyDept";
-import Treeselect from "@riophae/vue-treeselect";
-import "@riophae/vue-treeselect/dist/vue-treeselect.css";
+import { getUserList } from "@/api/company/companyUser"; // 使用 getUserList(companyId)
+import { getCompanyList } from "@/api/company/company";
 
 export default {
   name: "AppOrderCountStats",
-  components: { Treeselect },
-  watch: {
-    companyId: {
-      handler(newVal) {
-        if (newVal != null) {
-          this.companyUserId = null;
-          this.getUserListByDeptId();
-        } else {
-          this.users = [];
-          this.companyUserId = null;
-        }
-      }
-    }
-  },
   data() {
     return {
-      companyId: null,
-      companyUserId: null,
-      users: [],
-      deptOptions: [],
-      dateRange: [],
-      tableData: []
+      // 仅保留必要查询参数
+      queryParams: {
+        companyId: null,
+        companyUserId: null
+      },
+      companys: [],   // 公司列表
+      users: [],      // 员工列表
+      dateRange: [],  // 日期范围
+      tableData: []   // 表格数据
     };
   },
+  watch: {
+    // 公司变化时,重新加载员工
+    'queryParams.companyId'(newVal) {
+      if (newVal) {
+        this.queryParams.companyUserId = null;
+        this.loadUsers();
+      } else {
+        this.users = [];
+        this.queryParams.companyUserId = null;
+      }
+    }
+  },
   created() {
-    this.loadDeptTree();
+    // 初始化公司下拉列表
+    getCompanyList().then(response => {
+      this.companys = response.data || [];
+    });
   },
   methods: {
-    loadDeptTree() {
-      treeselect().then(response => {
-        this.deptOptions = response.data;
-        if (response.data && response.data.length > 0) {
-          this.companyId = response.data[0].id;
-        }
-      });
-    },
+    // 根据 companyId 加载员工
+    loadUsers() {
+      const companyId = this.queryParams.companyId;
+      if (!companyId) return;
 
-    getUserListByDeptId() {
-      if (!this.companyId) return;
-      getUserListByDeptId({ deptId: this.companyId }).then(response => {
-        this.users = response.data || [];
+      getUserList(companyId).then(res => {
+        if (res.code === 200) {
+          this.users = Array.isArray(res.data) ? res.data : [];
+        } else {
+          this.users = [];
+        }
+      }).catch(() => {
+        this.users = [];
       });
     },
 
+    // 搜索统计
     search() {
       const params = {
-        companyId: this.companyId,
-        companyUserId: this.companyUserId,
+        companyId: this.queryParams.companyId,
+        companyUserId: this.queryParams.companyUserId,
         startTime: this.dateRange?.[0] || undefined,
         endTime: this.dateRange?.[1] ? this.dateRange[1] + " 23:59:59" : undefined
       };
@@ -132,6 +147,8 @@ export default {
       getAppOrderCount(params).then(response => {
         const vo = response.data;
         this.tableData = vo ? [vo] : [];
+      }).catch(() => {
+        this.tableData = [];
       });
     }
   }
@@ -165,15 +182,4 @@ export default {
     }
   }
 }
-
-.vue-treeselect {
-  width: 217px;
-  height: 36px;
-}
-</style>
-
-<style>
-.vue-treeselect__control {
-  display: block;
-}
 </style>

+ 52 - 59
src/views/his/statistics/hisOrderCountStats.vue

@@ -3,22 +3,32 @@
     <div class="app-content">
       <div class="title">互联网医院订单统计</div>
       <el-form class="search-form" :inline="true">
-        <el-form-item>
-          <treeselect
-            :clearable="false"
-            v-model="companyId"
-            :options="deptOptions"
-            :show-count="true"
-            placeholder="请选择归属部门"
-          />
+        <el-form-item label="公司名称" prop="companyId">
+          <el-select
+            style="width: 220px"
+            filterable
+            v-model="queryParams.companyId"
+            placeholder="请选择公司名"
+            clearable
+            size="small"
+          >
+            <el-option
+              v-for="item in companys"
+              :key="item.companyId"
+              :label="item.companyName"
+              :value="item.companyId"
+            />
+          </el-select>
         </el-form-item>
-        <el-form-item>
+
+        <el-form-item label="员工" prop="companyUserId">
           <el-select
             filterable
-            v-model="companyUserId"
+            v-model="queryParams.companyUserId"
             placeholder="请选择员工"
             clearable
             size="small"
+            :disabled="!queryParams.companyId"
           >
             <el-option
               v-for="item in users"
@@ -28,6 +38,7 @@
             />
           </el-select>
         </el-form-item>
+
         <el-form-item label="下单日期">
           <el-date-picker
             clearable
@@ -40,6 +51,7 @@
             end-placeholder="结束日期"
           />
         </el-form-item>
+
         <el-form-item>
           <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
         </el-form-item>
@@ -71,58 +83,50 @@
 <script>
 import { getHisOrderCountStats } from "@/api/company/statistics";
 import { getUserListByDeptId } from "@/api/company/companyUser";
-import { treeselect } from "@/api/company/companyDept";
-import Treeselect from "@riophae/vue-treeselect";
-import "@riophae/vue-treeselect/dist/vue-treeselect.css";
+import { getCompanyList } from "@/api/company/company";
 
 export default {
   name: "HisOrderCountStats",
-  components: { Treeselect },
+  data() {
+    return {
+      // 查询参数统一管理
+      queryParams: {
+        companyId: null,
+        companyUserId: null
+        // 其他参数如 pageNum 等在此场景非必需,可省略
+      },
+      companys: [],        // 公司列表
+      users: [],           // 员工列表
+      dateRange: [],       // 日期范围
+      tableData: []        // 表格数据
+    };
+  },
   watch: {
-    // 监听 companyId 变化,自动重载员工列表
-    companyId: {
+    // 监听公司变化,自动加载员工
+    'queryParams.companyId': {
       handler(newVal) {
         if (newVal != null) {
-          this.companyUserId = null; // 清空已选员工
-          this.getUserListByDeptId();
+          this.queryParams.companyUserId = null; // 清空员工选择
+          this.loadUsers();
         } else {
           this.users = [];
-          this.companyUserId = null;
+          this.queryParams.companyUserId = null;
         }
       },
       immediate: false
     }
   },
-  data() {
-    return {
-      companyId: null,        // 销售公司(部门)ID
-      companyUserId: null,    // 销售人员(员工)ID
-      users: [],              // 员工列表
-      deptOptions: [],        // 部门树形数据
-      dateRange: [],          // 日期范围
-      tableData: []           // 表格数据
-    };
-  },
   created() {
-    this.loadDeptTree();
+    // 初始化公司列表
+    getCompanyList().then(response => {
+      this.companys = response.data || [];
+    });
   },
   methods: {
-    // 加载部门树
-    loadDeptTree() {
-      treeselect().then(response => {
-        this.deptOptions = response.data;
-        if (response.data && response.data.length > 0) {
-          // 默认选中第一个部门
-          this.companyId = response.data[0].id;
-          // 触发 watch 自动加载员工(无需手动调用)
-        }
-      });
-    },
-
-    // 根据 companyId 获取员工列表
-    getUserListByDeptId() {
-      if (!this.companyId) return;
-      getUserListByDeptId({ deptId: this.companyId }).then(response => {
+    // 根据 companyId 加载员工
+    loadUsers() {
+      if (!this.queryParams.companyId) return;
+      getUserListByDeptId({ deptId: this.queryParams.companyId }).then(response => {
         this.users = response.data || [];
       });
     },
@@ -130,8 +134,8 @@ export default {
     // 搜索统计
     search() {
       const params = {
-        companyId: this.companyId,
-        companyUserId: this.companyUserId,
+        companyId: this.queryParams.companyId,
+        companyUserId: this.queryParams.companyUserId,
         startTime: this.dateRange?.[0] || undefined,
         endTime: this.dateRange?.[1] ? this.dateRange[1] + " 23:59:59" : undefined
       };
@@ -172,15 +176,4 @@ export default {
     }
   }
 }
-
-.vue-treeselect {
-  width: 217px;
-  height: 36px;
-}
-</style>
-
-<style>
-.vue-treeselect__control {
-  display: block;
-}
 </style>