|
@@ -1,7 +1,13 @@
|
|
|
<script lang="ts" setup>
|
|
|
import { computed, defineProps, inject, onMounted, reactive, ref, Ref, watch } from 'vue';
|
|
|
import { useRouter } from 'vue-router';
|
|
|
-import { getDayData, getMonthData, getWeekData } from '/src/views/reportManage/dataCenter/api';
|
|
|
+import {
|
|
|
+ getDayData,
|
|
|
+ getDayTotalData,
|
|
|
+ getMonthData, getMonthTotalData,
|
|
|
+ getWeekData,
|
|
|
+ getWeekTotalData
|
|
|
+} from '/src/views/reportManage/dataCenter/api';
|
|
|
import { dayDataColumns, monthDataColumns, weekDataColumns } from '../../utils/columns';
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
@@ -122,6 +128,44 @@ const loadSortState = () => {
|
|
|
gridOptions.sortConfig.defaultSort.order = localStorage.getItem('salesOrder') || '';
|
|
|
gridOptions.sortConfig.defaultSort.field = localStorage.getItem('salesField') || '';
|
|
|
};
|
|
|
+const totalRow = ref({});
|
|
|
+
|
|
|
+async function fetchTotalData(taskIds, apiFunc, startDate, endDate, dateTypeKey) {
|
|
|
+ try {
|
|
|
+ const resp = await apiFunc({
|
|
|
+ data_start_date: startDate.value,
|
|
|
+ data_end_date: endDate.value,
|
|
|
+ task_ids: taskIds,
|
|
|
+ });
|
|
|
+ totalRow.value = resp.data[0] || {};
|
|
|
+ totalRow.value.platformNumber = '汇总';
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error fetching total data:', error);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function fetchDayTotal(taskIds) {
|
|
|
+ fetchTotalData(taskIds, getDayTotalData, dayStartDate, dayEndDate,'day');
|
|
|
+}
|
|
|
+
|
|
|
+function fetchWeekTotal(taskIds) {
|
|
|
+ fetchTotalData(taskIds, getWeekTotalData, weekStartDate, weekEndDate,'week');
|
|
|
+}
|
|
|
+
|
|
|
+function fetchMonthTotal(taskIds) {
|
|
|
+ fetchTotalData(taskIds, getMonthTotalData, monthStartDate, monthEndDate,'month');
|
|
|
+}
|
|
|
+
|
|
|
+function fetchCurrentTotalData(taskIds) {
|
|
|
+ if (dateType.value === 'day') {
|
|
|
+ fetchDayTotal(taskIds);
|
|
|
+ } else if (dateType.value === 'week') {
|
|
|
+ fetchWeekTotal(taskIds);
|
|
|
+ }else if (dateType.value === 'month') {
|
|
|
+ fetchMonthTotal(taskIds);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, dateTypeKey) {
|
|
|
try {
|
|
@@ -136,7 +180,7 @@ async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, date
|
|
|
sort: sortOrder.value,
|
|
|
order_date: order_date.value,
|
|
|
});
|
|
|
- gridOptions[dateType.value].data = resp.data;
|
|
|
+ gridOptions[dateType.value].data = [totalRow.value, ...resp.data];
|
|
|
gridOptions.pagerConfig.total = resp.total;
|
|
|
if (sortStatus.value) {
|
|
|
if (resp.data.length > 0) {
|
|
@@ -163,7 +207,7 @@ async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, date
|
|
|
const column = {
|
|
|
field: key,
|
|
|
title: key,
|
|
|
- minWidth: key.includes('~') ? 95 : /\d{4}-\d{2}-\d{2}的/.test(key) ? 93 : key.includes('截止') ? 90 : 79,
|
|
|
+ minWidth: key.includes('~') ? 95 : /\d{4}-\d{2}-\d{2}的/.test(key) ? 93 : key.includes('截止') ? 90 : /\d{4}-\d{2}的销售额/.test(key) ? 127 : 79,
|
|
|
align: 'center',
|
|
|
formatter: formatEmptyCell,
|
|
|
sortable: isSortable,
|
|
@@ -186,7 +230,6 @@ async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, date
|
|
|
salesColumns.sort((a, b) => {
|
|
|
const dateA = a.field.match(/\d{4}-\d{2}-\d{2}~\d{4}-\d{2}-\d{2}/)[0].split('~')[0];
|
|
|
const dateB = b.field.match(/\d{4}-\d{2}-\d{2}~\d{4}-\d{2}-\d{2}/)[0].split('~')[0];
|
|
|
- console.log(dateA, dateB);
|
|
|
return new Date(dateA) - new Date(dateB);
|
|
|
});
|
|
|
} else if (dateType.value == 'month') {
|
|
@@ -299,6 +342,8 @@ const headerCellStyle = () => {
|
|
|
};
|
|
|
|
|
|
watch([() => props.taskIds, currentDate], ([newTaskIds, newCurrentDate]) => {
|
|
|
+ sortStatus.value = true;
|
|
|
+
|
|
|
if (dateType.value === 'day') {
|
|
|
dayStartDate.value = dayjs(newCurrentDate.dailyStartDate).format('YYYY-MM-DD');
|
|
|
dayEndDate.value = dayjs(newCurrentDate.dailyTime).format('YYYY-MM-DD');
|
|
@@ -315,6 +360,7 @@ watch([() => props.taskIds, currentDate], ([newTaskIds, newCurrentDate]) => {
|
|
|
taskIdsAvailable.value = true;
|
|
|
}
|
|
|
if (taskIdsAvailable.value && newTaskIds) {
|
|
|
+ fetchCurrentTotalData(newTaskIds);
|
|
|
fetchCurrentData(newTaskIds, true);
|
|
|
taskIdsAvailable.value = false; // 调用后重置标记
|
|
|
}
|