128 lines
3.8 KiB
HTML
128 lines
3.8 KiB
HTML
{layout name="layout" /}
|
||
|
||
<div style="padding: 16px;">
|
||
<div class="layui-row">
|
||
<div class="layui-col-md3" >
|
||
<label class="layui-form-label">开始时间</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="start" class="layui-input" id="start" placeholder="yyyy-MM-dd HH:mm:ss">
|
||
</div>
|
||
</div>
|
||
<div class="layui-col-md3">
|
||
<label class="layui-form-label">结束时间</label>
|
||
<div class="layui-input-block">
|
||
<input type="text" name="end" class="layui-input" id="end" placeholder="yyyy-MM-dd HH:mm:ss">
|
||
</div>
|
||
</div>
|
||
<div class="layui-col-md3">
|
||
<div class="layui-input-block">
|
||
<button type="button" class="layui-btn layui-btn-sm" id="search">搜索</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="sales" style="width: 100%;height:400px;"></div>
|
||
</div>
|
||
<script src="/js/echarts.min.js"></script>
|
||
<script type="text/javascript">
|
||
var laydate = layui.laydate;
|
||
|
||
laydate.render({
|
||
elem: '#start'
|
||
});
|
||
laydate.render({
|
||
elem: '#end'
|
||
});
|
||
|
||
$('#search').click(function() {
|
||
var start = $('#start').val();
|
||
var end = $('#end').val();
|
||
getData(start, end);
|
||
});
|
||
|
||
getData();
|
||
// 基于准备好的dom,初始化echarts实例
|
||
var myChart = echarts.init(document.getElementById('sales'));
|
||
|
||
function getData(start = '', end = ''){
|
||
$.get('/sales/apiGetSales', {start: start, end: end}).done(function(data) {
|
||
// 指定图表的配置项和数据
|
||
var option = {
|
||
title: {
|
||
text: '销售统计'
|
||
},
|
||
tooltip: {},
|
||
legend: {
|
||
data: ['日销额']
|
||
},
|
||
xAxis: {
|
||
data: data.data.sold_at.map(function(item) {
|
||
return item;
|
||
})
|
||
},
|
||
yAxis: {
|
||
//type: 'value'
|
||
},
|
||
series: [
|
||
{
|
||
name: '日销额',
|
||
type: 'line',
|
||
data: data.data.total_sales.map(function(item) {
|
||
return item;
|
||
}),
|
||
label: {
|
||
normal: {
|
||
show: true,
|
||
position: 'top'
|
||
}
|
||
}
|
||
}
|
||
]
|
||
};
|
||
|
||
// 使用刚指定的配置项和数据显示图表。
|
||
myChart.setOption(option);
|
||
});
|
||
}
|
||
|
||
/*
|
||
$.get('/statistics/apiGetSales').done(function(data) {
|
||
// 指定图表的配置项和数据
|
||
var option = {
|
||
title: {
|
||
text: '销售统计'
|
||
},
|
||
tooltip: {},
|
||
legend: {
|
||
data: ['日销额']
|
||
},
|
||
xAxis: {
|
||
data: data.data.sold_at.map(function(item) {
|
||
return item;
|
||
})
|
||
},
|
||
yAxis: {
|
||
//type: 'value'
|
||
},
|
||
series: [
|
||
{
|
||
name: '日销额',
|
||
type: 'line',
|
||
data: data.data.total_sales.map(function(item) {
|
||
return item;
|
||
}),
|
||
label: {
|
||
normal: {
|
||
show: true,
|
||
position: 'top'
|
||
}
|
||
}
|
||
}
|
||
]
|
||
};
|
||
|
||
// 使用刚指定的配置项和数据显示图表。
|
||
myChart.setOption(option);
|
||
});
|
||
*/
|
||
</script> |