瀏覽代碼

Merge branch 'xinyan' into test

xinyan 7 月之前
父節點
當前提交
6944f37bee

+ 28 - 0
src/views/reportManage/dataCenter/api.ts

@@ -235,3 +235,31 @@ export function exportData(query) {
     responseType: 'blob'
   });
 }
+
+// 日周月数据导出
+export function exportDayData(query) {
+  return request({
+    url: '/api/report_manage/data-day/download/',
+    method: 'GET',
+    params: query,
+    responseType: 'blob'
+  });
+}
+
+export function exportWeekData(query) {
+  return request({
+    url: '/api/report_manage/data-week/download/',
+    method: 'GET',
+    params: query,
+    responseType: 'blob'
+  });
+}
+
+export function exportMonthData(query) {
+  return request({
+    url: '/api/report_manage/data-month/download/',
+    method: 'GET',
+    params: query,
+    responseType: 'blob'
+  });
+}

+ 69 - 1
src/views/reportManage/dataCenter/normalDisplay/components/TableDataDisplay.vue

@@ -2,6 +2,7 @@
 import { computed, defineProps, inject, onMounted, reactive, ref, Ref, watch } from 'vue';
 import { useRouter } from 'vue-router';
 import {
+  exportDayData, exportMonthData, exportWeekData,
   getDayData,
   getDayTotalData,
   getMonthData,
@@ -11,6 +12,9 @@ import {
 } from '/src/views/reportManage/dataCenter/api';
 import { dayDataColumns, monthDataColumns, weekDataColumns } from '../../utils/columns';
 import dayjs from 'dayjs';
+import { exportTaskData } from '/@/views/reportManage/TaskManage/api';
+import { ElMessage } from 'element-plus';
+
 
 const router = useRouter();
 const dateType = inject<Ref>('dateDimension');
@@ -85,7 +89,8 @@ const gridOptions = reactive({
     },
     slots: {
       buttons: 'toolbar_buttons',
-    },
+      tools: 'toolbar_tools'
+    }
   },
   day: {
     columns: dayDataColumns,
@@ -334,6 +339,61 @@ const handleImport = () => {
   window.open(url, '_blank');
 };
 
+async function handleExport(taskIds, apiFunc, startDate, endDate,dateTypeKey) {
+  try {
+    gridOptions.loading = true;
+    const response = await apiFunc({
+      [`${ dateTypeKey }_start_date`]: startDate.value,
+      [`${ dateTypeKey }_end_date`]: endDate.value,
+      task_ids: taskIds,
+      sort: sortOrder.value,
+      order_date: order_date.value,
+      order_total_sales_current_monthly: totalSales.value,
+    });
+    const url = window.URL.createObjectURL(new Blob([response.data]));
+    const link = document.createElement('a');
+    // 根据 dateTypeKey 设置文件名
+    let fileName = '';
+    if (dateTypeKey === 'day') {
+      fileName = `${startDate.value}~${endDate.value}日数据.xlsx`;  // 当为天时
+    } else if (dateTypeKey === 'week') {
+      fileName = `${startDate.value}~${endDate.value}周数据.xlsx`;  // 当为周时
+    } else if (dateTypeKey === 'month') {
+      fileName = `${startDate.value}~${endDate.value}月数据.xlsx`; // 当为月时
+    }
+    link.href = url;
+    link.setAttribute('download', fileName);
+    document.body.appendChild(link);
+    link.click();
+    gridOptions.loading = false;
+    ElMessage.success('导出数据成功');
+  } catch (error) {
+    console.error('导出数据失败:', error);
+  }
+}
+
+async function handleExportDay() {
+  await handleExport(taskIds.value, exportDayData, dayStartDate, dayEndDate,'day');
+}
+
+async function handleExportWeek() {
+  await handleExport(taskIds.value, exportWeekData, weekStartDate, weekEndDate,'week');
+}
+
+async function handleExportMonth() {
+  await handleExport(taskIds.value, exportMonthData, monthStartDate, monthEndDate,'month');
+}
+
+async function handelExportCurrent() {
+  if (dateType.value === 'day') {
+    await handleExportDay();
+  } else if (dateType.value === 'week') {
+    await handleExportWeek();
+  } else if (dateType.value === 'month') {
+    await handleExportMonth();
+  }
+}
+
 function formatEmptyCell({ cellValue }) {
   if (cellValue === null || cellValue === undefined || cellValue === '') {
     return '--';
@@ -401,6 +461,7 @@ watch([() => props.taskIds, currentDate], async ([newTaskIds, newCurrentDate]) =
   clearSort();
   if (newTaskIds) {
     taskIdsAvailable.value = true;
+    taskIds.value = newTaskIds;
   }
   if (taskIdsAvailable.value && newTaskIds) {
     await fetchCurrentData(newTaskIds, true); // 使用 await 确保顺序
@@ -421,6 +482,13 @@ onMounted(() => {
       <template #toolbar_buttons>
         <el-button icon="plus" target="_blank" type="primary" @click="handleImport">数据录入</el-button>
       </template>
+      <template #toolbar_tools>
+        <div class="pr-2.5">
+          <el-tooltip content="下载表格" placement="top">
+            <vxe-button circle icon="vxe-icon-download" @click="handelExportCurrent"></vxe-button>
+          </el-tooltip>
+        </div>
+      </template>
       <template #platformNumber_default="{ row }">
         <div class="font-semibold" style="padding: 0">{{ row.platformNumber }}</div>
       </template>