|
@@ -28,24 +28,16 @@ const monthData = [];
|
|
|
const order_date = ref('');
|
|
|
const sortOrder = ref('');
|
|
|
|
|
|
-// 保存排序状态到 localStorage
|
|
|
-const saveSortState = () => {
|
|
|
- localStorage.setItem('sortField', order_date.value);
|
|
|
- localStorage.setItem('sortOrder', sortOrder.value);
|
|
|
-};
|
|
|
-
|
|
|
-// 读取排序状态并应用
|
|
|
-const loadSortState = () => {
|
|
|
- order_date.value = localStorage.getItem('sortField') || '';
|
|
|
- sortOrder.value = localStorage.getItem('sortOrder') || '';
|
|
|
-};
|
|
|
-
|
|
|
const gridOptions = reactive({
|
|
|
border: 'inner',
|
|
|
height: 900,
|
|
|
align: null,
|
|
|
round: true,
|
|
|
loading: false,
|
|
|
+ id: 'normalCustomStorage',
|
|
|
+ customConfig: {
|
|
|
+ storage: true
|
|
|
+ },
|
|
|
columnConfig: {
|
|
|
resizable: true,
|
|
|
},
|
|
@@ -105,6 +97,19 @@ const gridEvents = {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+// 保存排序状态到 localStorage
|
|
|
+const saveSortState = () => {
|
|
|
+ localStorage.setItem('sortField', order_date.value);
|
|
|
+ localStorage.setItem('sortOrder', sortOrder.value);
|
|
|
+};
|
|
|
+
|
|
|
+// 读取排序状态并应用
|
|
|
+const loadSortState = () => {
|
|
|
+ order_date.value = localStorage.getItem('sortField') || '';
|
|
|
+ sortOrder.value = localStorage.getItem('sortOrder') || '';
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
watch(currentDate, (newValue) => {
|
|
|
if (dateType.value === 'day') {
|
|
|
dayStartDate.value = dayjs(newValue.dailyStartDate).format('YYYY-MM-DD');
|
|
@@ -124,12 +129,12 @@ watch(currentDate, (newValue) => {
|
|
|
async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, dateTypeKey) {
|
|
|
try {
|
|
|
gridOptions.loading = true;
|
|
|
- loadSortState()
|
|
|
+ loadSortState();
|
|
|
const resp = await apiFunc({
|
|
|
page: gridOptions.pagerConfig.currentPage,
|
|
|
limit: gridOptions.pagerConfig.pageSize,
|
|
|
- [`${dateTypeKey}_start_date`]: startDate.value,
|
|
|
- [`${dateTypeKey}_end_date`]: endDate.value,
|
|
|
+ [`${ dateTypeKey }_start_date`]: startDate.value,
|
|
|
+ [`${ dateTypeKey }_end_date`]: endDate.value,
|
|
|
task_ids: taskIds,
|
|
|
sort: sortOrder.value,
|
|
|
order_date: order_date.value,
|
|
@@ -142,11 +147,11 @@ async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, date
|
|
|
const salesColumns = [];
|
|
|
const otherColumns = [];
|
|
|
|
|
|
- dataColumns.value = dataColumns.value.filter(column => !/\d{2}-\d{2}的/.test(column.field) && !column.field.includes('余额币种') && !column.field.includes('退货率'));
|
|
|
+ dataColumns.value = dataColumns.value.filter(column => !/\d{2}-\d{2}/.test(column.field) && !column.field.includes('余额币种') && !column.field.includes('退货率'));
|
|
|
|
|
|
resp.data.forEach(row => {
|
|
|
for (const key in row) {
|
|
|
- if (/\d{2}-\d{2}的/.test(key) || key.includes('余额币种') || key.includes('退货率')) {
|
|
|
+ if (/\d{2}-\d{2}/.test(key) || key.includes('余额币种') || key.includes('退货率')) {
|
|
|
allColumns.add(key);
|
|
|
}
|
|
|
}
|
|
@@ -155,18 +160,18 @@ async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, date
|
|
|
//"的销售额"字段可以排序
|
|
|
allColumns.forEach(key => {
|
|
|
let isSortable = false;
|
|
|
- if (key.includes('的销售额')) {
|
|
|
+ if (key.includes('的销售额')&& !key.includes('增长率')) {
|
|
|
isSortable = true;
|
|
|
}
|
|
|
const column = {
|
|
|
field: key,
|
|
|
title: key,
|
|
|
- minWidth: key.includes('~') ? 95 : /\d{4}-\d{2}-\d{2}的/.test(key) ? 88 : 82,
|
|
|
+ minWidth: key.includes('~') ? 95 : /\d{4}-\d{2}-\d{2}的/.test(key) ? 88 : key.includes('截止')? 90 :79,
|
|
|
align: 'center',
|
|
|
formatter: formatEmptyCell,
|
|
|
sortable: isSortable,
|
|
|
};
|
|
|
- if (key.includes('的销售额')) {
|
|
|
+ if (key.includes('的销售额')&& !key.includes('增长率')) {
|
|
|
salesColumns.push(column);
|
|
|
} else {
|
|
|
otherColumns.push(column);
|
|
@@ -174,13 +179,27 @@ async function fetchData(taskIds, apiFunc, startDate, endDate, dataColumns, date
|
|
|
});
|
|
|
|
|
|
// 对 salesColumns 按日期排序
|
|
|
- if (dateType.value=='day'){
|
|
|
+ if (dateType.value == 'day') {
|
|
|
salesColumns.sort((a, b) => {
|
|
|
const dateA = a.field.match(/\d{4}-\d{2}-\d{2}/)[0];
|
|
|
const dateB = b.field.match(/\d{4}-\d{2}-\d{2}/)[0];
|
|
|
return new Date(dateA) - new Date(dateB);
|
|
|
});
|
|
|
}
|
|
|
+ else if (dateType.value=='week'){
|
|
|
+ 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'){
|
|
|
+ salesColumns.sort((a, b) => {
|
|
|
+ const dateA = a.field.match(/\d{4}-\d{2}/)[0];
|
|
|
+ const dateB = b.field.match(/\d{4}-\d{2}/)[0];
|
|
|
+ return new Date(dateA) - new Date(dateB);
|
|
|
+ });
|
|
|
+ }
|
|
|
const dynamicColumns = [...salesColumns, ...otherColumns];
|
|
|
|
|
|
if (dateType.value === dateTypeKey) {
|
|
@@ -223,7 +242,14 @@ function fetchCurrentData(taskIds, resetPage = false) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const salesOrder = ref(null);
|
|
|
+const salesField = ref(null);
|
|
|
+
|
|
|
function handleSortChange({ column, order }) {
|
|
|
+ salesOrder.value = order;
|
|
|
+ salesField.value = column.field;
|
|
|
+ //console.log('salesOrder', salesOrder.value);
|
|
|
+ //console.log('salesField', salesField.value);
|
|
|
sortOrder.value = order === 'asc' ? 'smallfirst' : 'bigfirst';
|
|
|
const sortField = column.field;
|
|
|
if (sortField) {
|
|
@@ -235,7 +261,7 @@ function handleSortChange({ column, order }) {
|
|
|
} else if (match) {
|
|
|
order_date.value = match[1];
|
|
|
} else if (matchMonth) {
|
|
|
- order_date.value = `${matchMonth[1]}-01`;
|
|
|
+ order_date.value = `${ matchMonth[1] }-01`;
|
|
|
}
|
|
|
}
|
|
|
saveSortState(); // 保存排序状态
|
|
@@ -248,7 +274,7 @@ watch(() => props.taskIds, (newTaskIds) => {
|
|
|
|
|
|
// 组件挂载时读取排序状态
|
|
|
onMounted(() => {
|
|
|
- loadSortState();
|
|
|
+ //loadSortState();
|
|
|
//fetchCurrentData(props.taskIds);
|
|
|
});
|
|
|
|
|
@@ -268,8 +294,7 @@ function formatEmptyCell({ cellValue }) {
|
|
|
}
|
|
|
if (typeof cellValue === 'number') {
|
|
|
const formatter = new Intl.NumberFormat('en-US', {
|
|
|
- minimumFractionDigits: 2,
|
|
|
- maximumFractionDigits: 2,
|
|
|
+ minimumFractionDigits: 0,
|
|
|
});
|
|
|
return formatter.format(cellValue);
|
|
|
}
|
|
@@ -288,7 +313,10 @@ const headerCellStyle = () => {
|
|
|
fontSize: '12px',
|
|
|
};
|
|
|
};
|
|
|
-
|
|
|
+onMounted(() => {
|
|
|
+ loadSortState();
|
|
|
+ //fetchCurrentData(props.taskIds);
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<template>
|