122 lines
4.5 KiB
JavaScript
122 lines
4.5 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const stores_order = require("../../stores/order.js");
|
|
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
|
__name: "statistics",
|
|
setup(__props) {
|
|
const orderStore = stores_order.useOrderStore();
|
|
const currentFilter = common_vendor.ref("today");
|
|
const timeFilters = [
|
|
{ label: "今日", value: "today" },
|
|
{ label: "本周", value: "week" },
|
|
{ label: "本月", value: "month" },
|
|
{ label: "全部", value: "all" }
|
|
];
|
|
const summaryData = common_vendor.computed(() => {
|
|
const orders = orderStore.orders;
|
|
const totalOrders = orders.length;
|
|
const totalAmount = orders.reduce((sum, order) => sum + order.amount, 0);
|
|
const totalWeight = orders.reduce((sum, order) => sum + (order.weight || 0), 0);
|
|
const avgAmount = totalOrders > 0 ? totalAmount / totalOrders : 0;
|
|
return {
|
|
totalOrders,
|
|
totalAmount,
|
|
totalWeight,
|
|
avgAmount
|
|
};
|
|
});
|
|
const categoryStats = common_vendor.computed(() => {
|
|
const categoryMap = {};
|
|
orderStore.orders.forEach((order) => {
|
|
if (!categoryMap[order.category]) {
|
|
categoryMap[order.category] = { name: order.name, amount: 0 };
|
|
}
|
|
categoryMap[order.category].amount += order.amount;
|
|
});
|
|
return Object.values(categoryMap).sort((a, b) => b.amount - a.amount).slice(0, 5);
|
|
});
|
|
const dailyStats = common_vendor.computed(() => {
|
|
const days = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
|
|
return days.map((label, index) => ({
|
|
date: `2026-05-${String(index + 1).padStart(2, "0")}`,
|
|
label,
|
|
amount: Math.floor(Math.random() * 500) + 100
|
|
}));
|
|
});
|
|
const statusStats = common_vendor.computed(() => {
|
|
const stats = { pending: 0, completed: 0, cancelled: 0 };
|
|
orderStore.orders.forEach((order) => {
|
|
if (order.status in stats) {
|
|
stats[order.status]++;
|
|
}
|
|
});
|
|
return stats;
|
|
});
|
|
const getRankClass = (index) => {
|
|
if (index === 0) return "rank-1";
|
|
if (index === 1) return "rank-2";
|
|
if (index === 2) return "rank-3";
|
|
return "";
|
|
};
|
|
const getBarWidth = (amount) => {
|
|
const maxAmount = Math.max(...categoryStats.value.map((item) => item.amount), 1);
|
|
return amount / maxAmount * 100;
|
|
};
|
|
const getBarHeight = (amount) => {
|
|
const maxAmount = Math.max(...dailyStats.value.map((item) => item.amount), 1);
|
|
return amount / maxAmount * 100;
|
|
};
|
|
common_vendor.onMounted(() => {
|
|
const isLogin = common_vendor.index.getStorageSync("admin_login");
|
|
if (!isLogin) {
|
|
common_vendor.index.redirectTo({ url: "/pages/admin/login" });
|
|
return;
|
|
}
|
|
orderStore.loadOrders();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return {
|
|
a: common_vendor.f(timeFilters, (filter, k0, i0) => {
|
|
return {
|
|
a: common_vendor.t(filter.label),
|
|
b: filter.value,
|
|
c: currentFilter.value === filter.value ? 1 : "",
|
|
d: common_vendor.o(($event) => currentFilter.value = filter.value, filter.value)
|
|
};
|
|
}),
|
|
b: common_vendor.t(summaryData.value.totalOrders),
|
|
c: common_vendor.t(summaryData.value.totalAmount.toFixed(2)),
|
|
d: common_vendor.t(summaryData.value.totalWeight.toFixed(2)),
|
|
e: common_vendor.t(summaryData.value.avgAmount.toFixed(2)),
|
|
f: common_vendor.f(categoryStats.value, (item, index, i0) => {
|
|
return {
|
|
a: common_vendor.t(index + 1),
|
|
b: common_vendor.n(getRankClass(index)),
|
|
c: common_vendor.t(item.name),
|
|
d: getBarWidth(item.amount) + "%",
|
|
e: common_vendor.t(item.amount.toFixed(2)),
|
|
f: item.category
|
|
};
|
|
}),
|
|
g: common_vendor.f(5, (i, k0, i0) => {
|
|
return {
|
|
a: i
|
|
};
|
|
}),
|
|
h: common_vendor.f(dailyStats.value, (day, k0, i0) => {
|
|
return {
|
|
a: getBarHeight(day.amount) + "%",
|
|
b: common_vendor.t(day.label),
|
|
c: day.date
|
|
};
|
|
}),
|
|
i: common_vendor.t(statusStats.value.pending),
|
|
j: common_vendor.t(statusStats.value.completed),
|
|
k: common_vendor.t(statusStats.value.cancelled)
|
|
};
|
|
};
|
|
}
|
|
});
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-8cc66245"]]);
|
|
wx.createPage(MiniProgramPage);
|