添加统计逻辑

This commit is contained in:
2025-12-29 17:28:14 +08:00
parent 1e542a55bf
commit b8a9f9b62e
10 changed files with 205 additions and 11 deletions

View File

@@ -429,6 +429,21 @@ layui.config({
var $ = layui.$
,laydate = layui.laydate;
// 统计数据(从后端传递)
var statisticsData = {
monthlySales: parseFloat('{$monthlySales|default=0}') || 0,
monthlyOrders: parseInt('{$monthlyOrders|default=0}') || 0,
monthlyCustomers: parseInt('{$monthlyCustomers|default=0}') || 0,
salesCompare: parseFloat('{$salesCompare|default=0}') || 0,
ordersCompare: parseFloat('{$ordersCompare|default=0}') || 0,
customersCompare: parseFloat('{$customersCompare|default=0}') || 0,
oldCustomers: parseInt('{$oldCustomers|default=0}') || 0,
newCustomers: parseInt('{$newCustomers|default=0}') || 0
};
// 渲染统计数据
renderStatistics();
// 日期选择器
laydate.render({
elem: '#date-filter',
@@ -438,6 +453,38 @@ layui.config({
// 初始化所有图表(仅样式,不填充数据)
initCharts();
// 渲染统计数据
function renderStatistics() {
// 格式化金额(保留两位小数,添加千分位)
function formatMoney(amount) {
if (!amount) return '0.00';
return parseFloat(amount).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
// 格式化同比显示
function formatCompare(compare) {
if (compare > 0) {
return '<span style="color: #52c41a;">↑ ' + Math.abs(compare).toFixed(2) + '%</span>';
} else if (compare < 0) {
return '<span style="color: #ff4d4f;">↓ ' + Math.abs(compare).toFixed(2) + '%</span>';
} else {
return '<span style="color: #999;">持平</span>';
}
}
// 渲染月销售总额
$('#monthly-sales').text('¥' + formatMoney(statisticsData.monthlySales));
$('#sales-compare').html(formatCompare(statisticsData.salesCompare));
// 渲染月订单量
$('#monthly-orders').text(statisticsData.monthlyOrders);
$('#orders-compare').html(formatCompare(statisticsData.ordersCompare));
// 渲染月客户数
$('#monthly-customers').text(statisticsData.monthlyCustomers);
$('#customers-compare').html(formatCompare(statisticsData.customersCompare));
}
function initCharts() {
// 月客户分析 - 饼图
@@ -466,8 +513,8 @@ layui.config({
formatter: '{b}: {d}%'
},
data: [
{value: 28, name: '老客', itemStyle: {color: '#FFB6C1'}},
{value: 72, name: '新客', itemStyle: {color: '#FF69B4'}}
{value: statisticsData.oldCustomers, name: '老客', itemStyle: {color: '#FFB6C1'}},
{value: statisticsData.newCustomers, name: '新客', itemStyle: {color: '#FF69B4'}}
]
}]
});