三七 3 days ago
parent
commit
ba6d31c1d4

+ 9 - 0
src/api/course/courseWatchLog.js

@@ -51,6 +51,15 @@ export function exportCourseWatchLog(query) {
     data: query
   })
 }
+//会员看课统计导出
+export function exportCourseWatchLogStatisticsExport(query) {
+  return request({
+    url: '/course/courseWatchLog/statisticsExport',
+    method: 'POST',
+    data: query
+  })
+}
+
 
 
 export function statisticsList(query) {

+ 9 - 0
src/api/course/qw/courseWatchLog.js

@@ -112,6 +112,15 @@ export function exportCourseWatchLog(query) {
   })
 }
 
+export function exportCourseWatchLogStatisticsExportQw(query) {
+  return request({
+    url: '/qw/course/courseWatchLog/statisticsExport',
+    method: 'POST',
+    data: query
+  })
+}
+
+
 export function watchLogStatisticsExport(query) {
   return request({
     url: '/qw/course/courseWatchLog/watchLogStatisticsExport',

+ 1 - 1
src/views/components/course/userCourseCatalogDetails.vue

@@ -1035,7 +1035,7 @@ export default {
         return syncTemplate(courseId);
       }).then(() => {
         this.getList();
-        this.msgSuccess("同步成功");
+        this.msgSuccess("正在同步模板中!!请稍后!");
       }).catch(() => {
       });
     },

+ 36 - 1
src/views/course/courseTrafficLog/index.vue

@@ -57,7 +57,8 @@
     </el-form>
 
     <!-- 表格 -->
-    <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange">
+    <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange"
+              show-summary :summary-method="getSummaries">
       <el-table-column type="selection" width="55" align="center" />
       <!-- 公司列 -->
       <el-table-column label="公司" align="center" prop="companyName" v-if="activeTab === 'all' || activeTab === 'company'" />
@@ -161,6 +162,40 @@ export default {
     this.getList();
   },
   methods: {
+
+    getSummaries(param) {
+      const { columns, data } = param
+      const sums = []
+
+      columns.forEach((column, index) => {
+        if (index === 0) {
+          // 第一列显示"总计"
+          sums[index] = '总计'
+          return
+        }
+
+        // 如果是流量列
+        if (column.property === 'totalInternetTraffic' ||
+          (column.label === '使用流量' && !column.property)) {
+          const values = data.map(item => Number(item.totalInternetTraffic) || 0)
+          if (!values.every(value => isNaN(value))) {
+            const total = values.reduce((prev, curr) => {
+              const value = Number(curr)
+              return prev + (isNaN(value) ? 0 : value)
+            }, 0)
+            sums[index] = this.formatTrafficData(total)
+          } else {
+            sums[index] = 'N/A'
+          }
+        } else {
+          // 其他列留空
+          sums[index] = ''
+        }
+      })
+
+      return sums
+    },
+
     handleTabClick(tab) {
       this.queryParams.tabType = tab.name;
       this.queryParams.pageNum = 1;

+ 65 - 5
src/views/course/courseTrafficLog/statistics.vue

@@ -27,8 +27,8 @@
           @change="handleDateData"
         ></el-date-picker>
       </el-form-item>
-     
-    
+
+
       <el-form-item>
         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
@@ -48,10 +48,11 @@
       </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
-    
+
 
     <!-- 表格 -->
-    <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange">
+    <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange"
+              show-summary :summary-method="getSummaries">
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="公司" align="center" prop="companyName" />
       <el-table-column v-if="showDept" label="部门" align="center" prop="deptName" />
@@ -61,7 +62,6 @@
       <el-table-column label="金额" align="center" prop="totalAmount">
       </el-table-column>
     </el-table>
-
     <!-- 分页 -->
     <pagination
       v-show="total > 0"
@@ -155,6 +155,66 @@ export default {
     this.getList();
   },
   methods: {
+
+    getSummaries(param) {
+      // 原有的汇总方法
+      const { columns, data } = param;
+      const sums = [];
+
+      columns.forEach((column, index) => {
+        if (index === 0) {
+          sums[index] = '总计';
+          return;
+        }
+
+        if (column.property === 'formattedTotalTraffic') {
+          sums[index] = this.getTotalTraffic();
+        } else if (column.property === 'totalAmount') {
+          sums[index] = '¥' + this.getTotalAmount();
+        } else {
+          sums[index] = '';
+        }
+      });
+
+      return sums;
+    },
+
+
+    // 计算总流量(不四舍五入)
+    getTotalTraffic() {
+      if (!this.courseTrafficLogList || this.courseTrafficLogList.length === 0) {
+        return '0';
+      }
+      let total = 0;
+
+      // 方法B:从格式化字符串中提取数值(如果formattedTotalTraffic类似 "1.23GB")
+      total = this.courseTrafficLogList.reduce((sum, item) => {
+        // 移除非数字字符,只保留数字和小数点
+        if (item.formattedTotalTraffic) {
+          const numStr = item.formattedTotalTraffic.replace(/[^\d.]/g, '');
+          return sum + parseFloat(numStr || 0);
+        }
+        return sum;
+      }, 0);
+
+      // 保留所有小数,不四舍五入
+      return total.toFixed(10).replace(/\.?0+$/, '');
+    },
+
+    // 计算总金额(不四舍五入)
+    getTotalAmount() {
+      if (!this.courseTrafficLogList || this.courseTrafficLogList.length === 0) {
+        return '0';
+      }
+
+      const total = this.courseTrafficLogList.reduce((sum, item) => {
+        return sum + (parseFloat(item.totalAmount) || 0);
+      }, 0);
+
+      // 保留两位小数,不四舍五入
+      return Math.floor(total * 100) / 100;
+    },
+
     handleTabClick(tab) {
       this.queryParams.tabType = tab.name;
       this.queryParams.pageNum = 1;

+ 45 - 4
src/views/course/courseWatchLog/qw/statistics.vue

@@ -50,6 +50,21 @@
       </el-form-item>
     </el-form>
 
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          plain
+          icon="el-icon-download"
+          size="mini"
+          :loading="exportLoading"
+          @click="handleStatisExport"
+          v-hasPermi="['course:courseWatchLog:statisticsExport']"
+        >导出</el-button>
+      </el-col>
+      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
+    </el-row>
+
     <el-table v-if="'济南联志健康' == this.signProjectName" border v-loading="loading" :data="courseWatchLogList" @selection-change="handleSelectionChange"  show-summary :summary-method="getSummaries">
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="企微员工名称" align="center" prop="qwUserName" />
@@ -96,7 +111,18 @@
 </template>
 
 <script>
-import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog,statisticsList,getSignProjectName } from "@/api/course/qw/courseWatchLog";
+import {
+  listCourseWatchLog,
+  getCourseWatchLog,
+  delCourseWatchLog,
+  addCourseWatchLog,
+  updateCourseWatchLog,
+  exportCourseWatchLog,
+  statisticsList,
+  getSignProjectName,
+  exportCourseWatchLogStatisticsExport,
+  exportCourseWatchLogStatisticsExportQw
+} from '@/api/course/qw/courseWatchLog'
 import { courseList,videoList } from '@/api/course/courseRedPacketLog'
 import {getCompanyList} from "@/api/company/company";
 export default {
@@ -179,20 +205,35 @@ export default {
     });
   },
   methods: {
-   getSummaries(param) {
+
+    handleStatisExport(){
+      const queryParams = this.queryParams;
+      this.$confirm('是否确认导出所有会员看课统计数据项?', "警告", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning"
+      }).then(() => {
+        this.exportLoading = true;
+        return exportCourseWatchLogStatisticsExportQw(queryParams);
+      }).then(response => {
+        this.download(response.msg);
+        this.exportLoading = false;
+      }).catch(() => {});
+    },
+    getSummaries(param) {
         const { columns, data } = param;
         const sums = [];
          // 关键改动:创建一个不包含最后一行的新数据数组
         // 如果数据长度大于1,则截取掉最后一行;否则,使用空数组避免错误
         const dataToSum = data.length > 1 ? data.slice(0, -1) : [];
         columns.forEach((column, index) => {
-          
+
           if (index === 0) {
             sums[index] = '页总计';
             return;
           }
           const values = dataToSum.map(item => Number(item[column.property]));
-          
+
           if (!values.every(value => isNaN(value))) {
             sums[index] = values.reduce((prev, curr) => {
               const value = Number(curr);

+ 40 - 1
src/views/course/courseWatchLog/statistics.vue

@@ -75,6 +75,21 @@
       </el-form-item>
     </el-form>
 
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          plain
+          icon="el-icon-download"
+          size="mini"
+          :loading="exportLoading"
+          @click="handleStatisExport"
+          v-hasPermi="['course:courseWatchLog:statisticsExport']"
+        >导出</el-button>
+      </el-col>
+      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
+    </el-row>
+
     <el-table
       border
       v-loading="loading"
@@ -106,7 +121,16 @@
 </template>
 
 <script>
-import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog,statisticsList } from "@/api/course/courseWatchLog";
+import {
+  listCourseWatchLog,
+  getCourseWatchLog,
+  delCourseWatchLog,
+  addCourseWatchLog,
+  updateCourseWatchLog,
+  exportCourseWatchLog,
+  statisticsList,
+  exportCourseWatchLogStatisticsExport
+} from '@/api/course/courseWatchLog'
 import { courseList,videoList } from '@/api/course/courseRedPacketLog'
 import {getUserList} from "@/api/company/companyUser";
 import {getFsUserList} from "@/api/users/user";
@@ -421,6 +445,21 @@ export default {
         this.exportLoading = false;
       }).catch(() => {});
     },
+
+    handleStatisExport(){
+      const queryParams = this.queryParams;
+      this.$confirm('是否确认导出所有会员看课统计数据项?', "警告", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning"
+      }).then(() => {
+        this.exportLoading = true;
+        return exportCourseWatchLogStatisticsExport(queryParams);
+      }).then(response => {
+        this.download(response.msg);
+        this.exportLoading = false;
+      }).catch(() => {});
+    },
     handleScheduleTimeChange(val) {
       if (val) {
         this.queryParams.scheduleStartTime = val[0];