define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Datatable, Table, Echarts) { var Controller = { index: function () { // 1. 初始化近 7 天订单与交易金额趋势图 (双轴图表) var trendDom = document.getElementById('chart-order-trend'); if (trendDom) { var trendChart = Echarts.init(trendDom, 'walden'); var trendOption = { tooltip: { trigger: 'axis', axisPointer: { type: 'cross', crossStyle: { color: '#999' } } }, legend: { data: ['订单量 (单)', '交易额 (元)'], top: 0, right: 10, textStyle: { color: '#64748b' } }, grid: { left: '3%', right: '4%', bottom: '3%', top: '15%', containLabel: true }, xAxis: [{ type: 'category', data: Config.dateColumns || [], axisPointer: { type: 'shadow' }, axisLine: { lineStyle: { color: '#cbd5e1' } }, axisLabel: { color: '#64748b' } }], yAxis: [ { type: 'value', name: '订单量 (单)', minInterval: 1, splitLine: { lineStyle: { type: 'dashed', color: '#f1f5f9' } }, axisLabel: { color: '#64748b' } }, { type: 'value', name: '交易额 (元)', splitLine: { show: false }, axisLabel: { color: '#64748b', formatter: '¥{value}' } } ], series: [ { name: '订单量 (单)', type: 'bar', barMaxWidth: 26, itemStyle: { barBorderRadius: [4, 4, 0, 0], color: new Echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#38bdf8' }, { offset: 1, color: '#0284c7' } ]) }, data: Config.orderCounts || [] }, { name: '交易额 (元)', type: 'line', yAxisIndex: 1, smooth: true, showSymbol: true, symbolSize: 6, itemStyle: { color: '#10b981' }, lineStyle: { width: 3, color: '#10b981' }, areaStyle: { color: new Echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(16, 185, 129, 0.28)' }, { offset: 1, color: 'rgba(16, 185, 129, 0.02)' } ]) }, data: Config.orderAmounts || [] } ] }; trendChart.setOption(trendOption); } // 2. 初始化订单履约状态环形分布图 var statusDom = document.getElementById('chart-order-status'); if (statusDom) { var statusChart = Echarts.init(statusDom, 'walden'); // 语义色板 var colorMap = { '已完成': '#10b981', '待接单': '#f59e0b', '已接单': '#3b82f6', '服务中': '#06b6d4', '待支付': '#94a3b8', '报价中': '#8b5cf6', '已取消': '#cbd5e1', '售后中': '#ef4444' }; var rawData = Config.statusData || []; var formattedData = rawData.map(function (item) { return { name: item.name, value: item.value, itemStyle: { color: colorMap[item.name] || undefined } }; }); var statusOption = { tooltip: { trigger: 'item', formatter: '{b}: {c} 单 ({d}%)' }, legend: { orient: 'horizontal', bottom: '0', left: 'center', textStyle: { color: '#64748b', fontSize: 12 }, itemWidth: 10, itemHeight: 10 }, series: [ { name: '订单状态', type: 'pie', radius: ['45%', '72%'], center: ['50%', '45%'], avoidLabelOverlap: false, itemStyle: { borderRadius: 6, borderColor: '#fff', borderWidth: 2 }, label: { show: false, position: 'center' }, emphasis: { label: { show: true, fontSize: 16, fontWeight: 'bold', formatter: '{b}\n{c} 单' } }, labelLine: { show: false }, data: formattedData } ] }; statusChart.setOption(statusOption); } // 3. 统一监听视口变化 $(window).resize(function () { if (trendChart) trendChart.resize(); if (statusChart) statusChart.resize(); }); // 点击刷新支持 $(document).on("click", ".btn-refresh", function () { setTimeout(function () { if (trendChart) trendChart.resize(); if (statusChart) statusChart.resize(); }, 100); }); } }; return Controller; });