123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, Echarts, undefined) {
- var areaObj = {};
- var Controller = {
- common: function (obj) {
- $(window).resize(function () {
- for (let i in obj) {
- obj[i].chart.resize();
- }
- });
- //点击刷新
- $(document).on("click", "a.btn-refresh", function () {
- let val = $(this).data('chart');
- obj[val].chart.resize();
- obj[val].refresh();
- });
- //每隔60s定时刷新图表
- setInterval(function () {
- $(".btn-refresh").trigger("click");
- }, 60000);
- //点击按钮
- $(document).on("click", ".btn-filter", function () {
- var label = $(this).text();
- var obj = $(this).closest("form").find(".datetimerange").data("daterangepicker");
- var dates = obj.ranges[label];
- obj.startDate = dates[0];
- obj.endDate = dates[1];
- obj.clickApply();
- });
- //选项卡切入事件
- $(document).on("click", "#resetecharts", function () {
- setTimeout(function () {
- $(window).trigger("resize");
- }, 50);
- });
- },
- index: function () {
- let obj = {}
- obj.chart1 = this.api.index.myChart1();
- obj.chart2 = this.api.index.myChart2();
- obj.chart4 = this.api.index.myChart4();
- this.common(obj);
- Form.api.bindevent($("#form1"));
- Form.api.bindevent($("#form2"));
- Form.api.bindevent($("#form4"));
- },
- areas: function () {
- areaObj.chart1 = this.api.areas.myChart1();
- areaObj.chart2 = this.api.areas.myChart2();
- areaObj.chart1.refresh();
- this.common(areaObj);
- //绑定事件
- Form.api.bindevent($("#form1"));
- Form.api.bindevent($("#form2"));
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- },
- index: {
- myChart1: function () {
- // 基于准备好的dom,初始化echarts实例
- let myChart = Echarts.init($('#echarts1')[0], 'walden');
- // 指定图表的配置项和数据
- let option = {
- title: {
- text: '订单金额趋势',
- subtext: ''
- },
- tooltip: {
- trigger: 'axis'
- },
- legend: {
- data: ['订单金额', '退款金额']
- },
- toolbox: {
- show: true,
- feature: {
- dataView: {
- show: true,
- readOnly: false
- },
- magicType: {
- show: true,
- type: ['line', 'bar']
- },
- restore: {
- show: true
- },
- saveAsImage: {
- show: true
- }
- }
- },
- calculable: true,
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: Config.orderSaleCategory
- },
- yAxis: {},
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- series: [{
- name: "订单金额",
- type: 'line',
- smooth: true,
- areaStyle: {
- normal: {}
- },
- lineStyle: {
- normal: {
- width: 1.5
- }
- },
- data: Config.orderSaleAmount
- }, {
- name: '退款金额',
- type: 'line',
- data: Config.afterSaleAmount,
- markPoint: {
- data: [{
- type: 'max',
- name: '最大值'
- },
- {
- type: 'min',
- name: '最小值'
- }
- ]
- },
- markLine: {
- data: [{
- type: 'average',
- name: '平均值'
- }]
- }
- }]
- };
- // 使用刚指定的配置项和数据显示图表。
- myChart.setOption(option);
- var date = '';
- $("#form1 .datetimerange").data("callback", function (start, end) {
- date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
- $(this.element).val(date);
- refresh();
- });
- //点击按钮
- $(document).on("click", ".btn-type", function () {
- refresh();
- });
- var si = null;
- function refresh() {
- si && clearTimeout(si);
- si = setTimeout(function () {
- Fast.api.ajax({
- url: 'shop/report/index',
- data: {
- date: date
- },
- loading: false
- }, function (res) {
- option.xAxis.data = res.orderSaleCategory;
- option.series[0].data = res.orderSaleAmount;
- option.series[1].data = res.afterSaleAmount;
- myChart.clear();
- myChart.setOption(option, true);
- if (res.totalOrderAmount != undefined) {
- $('#totalOrderAmount').html(res.totalOrderAmount)
- }
- if (res.todayOrderAmount != undefined) {
- $('#todayOrderAmount').html(res.todayOrderAmount)
- }
- if (res.totalProfitAmount != undefined) {
- $('#totalProfitAmount').html(res.totalProfitAmount)
- }
- if (res.totalRefundAmount != undefined) {
- $('#totalRefundAmount').html(res.totalRefundAmount)
- }
- if (res.todayRefundAmount != undefined) {
- $('#todayRefundAmount').html(res.todayRefundAmount)
- }
- if (res.yesterdayRefundAmount != undefined) {
- $('#yesterdayRefundAmount').html(res.yesterdayRefundAmount)
- }
- if (res.todayOrderRatio != undefined) {
- let dom = $('#todayOrderRatio');
- dom.html((res.todayOrderRatio > 0 ? '+' : '') + res.todayOrderRatio + '%');
- dom.attr('title', '昨天:' + res.yesterdayOrderAmount);
- if (res.todayOrderRatio >= 0) {
- dom.removeClass('text-danger').addClass('text-success');
- } else {
- dom.removeClass('text-success').addClass('text-danger');
- }
- }
- return false;
- });
- }, 50);
- }
- return {
- chart: myChart,
- refresh: refresh
- };
- },
- myChart2: function () {
- // 基于准备好的dom,初始化echarts实例
- let myChart = Echarts.init($('#echarts2')[0], 'walden');
- // 指定图表的配置项和数据
- let option = {
- title: {
- text: '订单数量趋势',
- subtext: ''
- },
- tooltip: {
- trigger: 'axis'
- },
- legend: {
- data: ['订单数量', '退款数量']
- },
- toolbox: {
- show: true,
- feature: {
- dataView: {
- show: true,
- readOnly: false
- },
- magicType: {
- show: true,
- type: ['line', 'bar']
- },
- restore: {
- show: true
- },
- saveAsImage: {
- show: true
- }
- }
- },
- calculable: true,
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: Config.afterSaleCategory
- },
- yAxis: {},
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- series: [{
- name: "订单数量",
- type: 'line',
- smooth: true,
- areaStyle: {
- normal: {}
- },
- lineStyle: {
- normal: {
- width: 1.5
- }
- },
- data: Config.orderSaleNums
- }, {
- name: '退款数量',
- type: 'line',
- data: Config.afterSaleNums,
- markPoint: {
- data: [{
- type: 'max',
- name: '最大值'
- },
- {
- type: 'min',
- name: '最小值'
- }
- ]
- },
- markLine: {
- data: [{
- type: 'average',
- name: '平均值'
- }]
- }
- }]
- };
- // 使用刚指定的配置项和数据显示图表。
- myChart.setOption(option);
- var date = '';
- $("#form2 .datetimerange").data("callback", function (start, end) {
- date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
- $(this.element).val(date);
- refresh();
- });
- //点击按钮
- $(document).on("click", ".btn-type", function () {
- refresh();
- });
- var si = null;
- function refresh() {
- si && clearTimeout(si);
- si = setTimeout(function () {
- Fast.api.ajax({
- url: 'shop/report/index',
- data: {
- date: date
- },
- loading: false
- }, function (res) {
- option.xAxis.data = res.afterSaleCategory;
- option.series[0].data = res.orderSaleNums;
- option.series[1].data = res.afterSaleNums;
- myChart.clear();
- myChart.setOption(option, true);
- return false;
- });
- }, 50);
- }
- return {
- chart: myChart,
- refresh: refresh
- };
- },
- myChart3: function () {
- return;
- },
- myChart4: function () {
- // 基于准备好的dom,初始化echarts实例
- let myChart = Echarts.init($('#echarts4')[0], 'walden');
- let option = {
- title: {
- text: '销售商品分类占比',
- // subtext: '',
- left: 'left'
- },
- tooltip: {
- trigger: 'item',
- formatter: function (row) {
- let {
- data
- } = row;
- let name = (data && data.name) || '';
- let value = (data && data.value) || 0;
- return `${name}:${value}%`
- }
- },
- legend: {
- type: 'scroll',
- orient: 'vertical',
- right: 10,
- top: 20,
- bottom: 20,
- data: Config.legendData,
- },
- series: [{
- name: '名称',
- type: 'pie',
- radius: '75%',
- center: ['40%', '50%'],
- data: Config.seriesData,
- label: {
- formatter: function (row) {
- let {
- data
- } = row;
- let name = (data && data.name) || '';
- let value = (data && data.value) || 0;
- return `${name} : (${value}%)`
- }
- },
- emphasis: {
- itemStyle: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- }
- }]
- };
- myChart.setOption(option, true);
- var date = '';
- $("#form4 .datetimerange").data("callback", function (start, end) {
- date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
- $(this.element).val(date);
- refresh();
- });
- //点击按钮
- $(document).on("click", ".btn-type", function () {
- refresh();
- });
- var si = null;
- function refresh() {
- si && clearTimeout(si);
- si = setTimeout(function () {
- Fast.api.ajax({
- url: 'shop/report/index',
- data: {
- date: date
- },
- loading: false
- }, function (res) {
- option.series[0].data = res.seriesData;
- option.legend.data = res.legendData;
- myChart.clear();
- myChart.setOption(option, true);
- return false;
- });
- }, 50);
- }
- return {
- chart: myChart,
- refresh: refresh
- };
- }
- },
- areas: {
- myChart1: function () {
- let isFirst = false;
- // 基于准备好的dom,初始化echarts实例
- let myChart = Echarts.init($('#echarts1')[0], 'walden');
- var colors = ['#5470C6', '#91CC75', '#EE6666', '#18bc9c'];
- // 指定图表的配置项和数据
- let option = {
- title: {
- text: '',
- subtext: ''
- },
- color: colors,
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross'
- }
- },
- grid: {
- left: '15',
- right: '4%',
- bottom: '3%',
- top: '11%',
- containLabel: true,
- y2: 120
- },
- toolbox: {
- show: true,
- feature: {
- dataView: {
- show: true,
- readOnly: false
- },
- magicType: {
- show: true,
- type: ['line', 'bar']
- },
- restore: {
- show: true
- },
- saveAsImage: {
- show: true
- }
- }
- },
- legend: {
- data: ['订单数量', '商品数量', '订单金额', '订单占比']
- },
- xAxis: [{
- type: 'category',
- axisTick: {
- alignWithLabel: true
- },
- axisLabel: {
- interval: 0,
- rotate: -30, //倾斜度 -90 至 90 默认为0
- // margin:2,
- // textStyle: {
- // color: '#7c8893',
- // fontSize: 12
- // },
- // formatter: function(value) {
- // return value.split("").join("\n");
- // }
- },
- offset: 10,
- triggerEvent:true,
- data: []
- }],
- yAxis: [{
- type: 'value',
- name: '订单数量',
- min: 0,
- max: 50,
- position: 'right',
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[0]
- }
- },
- axisLabel: {
- formatter: '{value} 个'
- }
- },
- {
- type: 'value',
- name: '商品数量',
- min: 0,
- max: 50,
- position: 'right',
- offset: 80,
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[1]
- }
- },
- axisLabel: {
- formatter: '{value} 件'
- }
- },
- {
- type: 'value',
- name: '订单金额',
- min: 0,
- max: 2500,
- position: 'left',
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[2]
- }
- },
- axisLabel: {
- formatter: '{value} 元'
- }
- },
- {
- type: 'value',
- name: '订单占比',
- min: 0,
- max: 100,
- position: 'left',
- offset: 60,
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[3]
- }
- },
- axisLabel: {
- formatter: '{value} %'
- }
- }
- ],
- series: [{
- name: '订单数量',
- type: 'bar',
- data: [],
- markPoint: {
- data: [{
- type: 'max',
- name: '最大值'
- },
- {
- type: 'min',
- name: '最小值'
- }
- ]
- }
- },
- {
- name: '商品数量',
- type: 'bar',
- yAxisIndex: 1,
- data: [],
- markPoint: {
- data: [{
- type: 'max',
- name: '最大值'
- },
- {
- type: 'min',
- name: '最小值'
- }
- ]
- }
- },
- {
- name: '订单金额',
- type: 'line',
- yAxisIndex: 2,
- data: [],
- markLine: {
- data: [{
- type: 'average',
- name: '平均值'
- }]
- },
- label: {
- show: true
- },
- },
- {
- name: '订单占比',
- type: 'line',
- yAxisIndex: 3,
- data: [],
- markLine: {
- data: [{
- type: 'average',
- name: '平均值'
- }]
- },
- label: {
- show: true
- },
- }
- ]
- };
- // 使用刚指定的配置项和数据显示图表。
- myChart.setOption(option);
- myChart.on('click', 'xAxis', function (res) {
- areaObj.chart2.refresh(res.value);
-
- });
-
- myChart.on('click', 'series', function (res) {
- if(!['最大值','最小值'].includes(res.name)){
- areaObj.chart2.refresh(res.name);
- }
- });
- var date = '';
- $("#form1 .datetimerange").data("callback", function (start, end) {
- date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
- $(this.element).val(date);
- refresh();
- });
- //点击按钮
- $(document).on("click", ".btn-type", function () {
- refresh();
- });
- var si = null;
- function refresh() {
- si && clearTimeout(si);
- si = setTimeout(function () {
- Fast.api.ajax({
- url: 'shop/report/areas',
- data: {
- date: date,
- id: Config.area
- },
- loading: false
- }, function (res) {
- if(res.name){
- option.title.text = res.name;
- }
- option.xAxis[0].data = res.xAxis;
- option.series[0].data = res.orderNums;
- option.series[1].data = res.goodsNums;
- let max_nums = Math.max.apply(null, res.goodsNums);
- option.yAxis[0].max = option.yAxis[1].max = parseInt(max_nums) + 10;
- option.series[2].data = res.orderMoney;
- let max_money = Math.max.apply(null, res.orderMoney);
- option.yAxis[2].max = parseInt(max_money) + 100;
- if (!res.is_oblique) {
- option.xAxis[0].axisLabel.rotate = 0;
- }
- option.series[3].data = res.rate;
- myChart.clear();
- console.log(option)
- myChart.setOption(option, true);
- if(!isFirst){
- //渲染区域
- isFirst = true;
- res.xAxis.length && res.xAxis[0] && areaObj.chart2.refresh(res.xAxis[0])
- }
- return false;
- });
- }, 50);
- }
- return {
- chart: myChart,
- refresh: refresh
- };
- },
- myChart2: function () {
- // 基于准备好的dom,初始化echarts实例
- let myChart = Echarts.init($('#echarts2')[0], 'walden');
- // 指定图表的配置项和数据
- var colors = ['#5470C6', '#91CC75', '#EE6666', '#18bc9c'];
- var date = '',area_name='';
- // 指定图表的配置项和数据
- let option = {
- title: {
- text:'区级统计',
- subtext: ''
- },
- color: colors,
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross'
- }
- },
- grid: {
- left: '15',
- right: '4%',
- bottom: '3%',
- top: '11%',
- containLabel: true,
- y2: 120
- },
- toolbox: {
- show: true,
- feature: {
- dataView: {
- show: true,
- readOnly: false
- },
- magicType: {
- show: true,
- type: ['line', 'bar']
- },
- restore: {
- show: true
- },
- saveAsImage: {
- show: true
- }
- }
- },
- legend: {
- data: ['订单数量', '商品数量', '订单金额', '订单占比']
- },
- xAxis: [{
- type: 'category',
- axisTick: {
- alignWithLabel: true
- },
- axisLabel: {
- interval: 0,
- rotate: -30, //倾斜度 -90 至 90 默认为0
- // margin:2,
- // textStyle: {
- // color: '#7c8893',
- // fontSize: 12
- // },
- // formatter: function(value) {
- // return value.split("").join("\n");
- // }
- },
- offset: 10,
- data: []
- }],
- yAxis: [{
- type: 'value',
- name: '订单数量',
- min: 0,
- max: 50,
- position: 'right',
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[0]
- }
- },
- axisLabel: {
- formatter: '{value} 个'
- }
- },
- {
- type: 'value',
- name: '商品数量',
- min: 0,
- max: 50,
- position: 'right',
- offset: 80,
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[1]
- }
- },
- axisLabel: {
- formatter: '{value} 件'
- }
- },
- {
- type: 'value',
- name: '订单金额',
- min: 0,
- max: 2500,
- position: 'left',
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[2]
- }
- },
- axisLabel: {
- formatter: '{value} 元'
- }
- },
- {
- type: 'value',
- name: '订单占比',
- min: 0,
- max: 100,
- position: 'left',
- offset: 60,
- axisLine: {
- show: true,
- lineStyle: {
- color: colors[3]
- }
- },
- axisLabel: {
- formatter: '{value} %'
- }
- }
- ],
- series: [{
- name: '订单数量',
- type: 'bar',
- data: [],
- markPoint: {
- data: [{
- type: 'max',
- name: '最大值'
- },
- {
- type: 'min',
- name: '最小值'
- }
- ]
- }
- },
- {
- name: '商品数量',
- type: 'bar',
- yAxisIndex: 1,
- data: [],
- markPoint: {
- data: [{
- type: 'max',
- name: '最大值'
- },
- {
- type: 'min',
- name: '最小值'
- }
- ]
- }
- },
- {
- name: '订单金额',
- type: 'line',
- yAxisIndex: 2,
- data: [],
- markLine: {
- data: [{
- type: 'average',
- name: '平均值'
- }]
- },
- label: {
- show: true
- },
- },
- {
- name: '订单占比',
- type: 'line',
- yAxisIndex: 3,
- data: [],
- markLine: {
- data: [{
- type: 'average',
- name: '平均值'
- }]
- },
- label: {
- show: true
- },
- }
- ]
- };
-
- // 使用刚指定的配置项和数据显示图表。
- myChart.setOption(option);
- $("#form2 .datetimerange").data("callback", function (start, end) {
- date = start.format(this.locale.format) + " - " + end.format(this.locale.format);
- $(this.element).val(date);
- refresh();
- });
- //点击按钮
- $(document).on("click", ".btn-type", function () {
- refresh();
- });
- var si = null;
- function refresh(name='') {
- if(name){
- area_name = name;
- }
- si && clearTimeout(si);
- si = setTimeout(function () {
- Fast.api.ajax({
- url: 'shop/report/areas',
- data: {
- date: date,
- name: area_name
- },
- loading: false
- }, function (res) {
- if(res.name){
- option.title.text = res.name;
- }
- option.xAxis[0].data = res.xAxis;
- option.series[0].data = res.orderNums;
- option.series[1].data = res.goodsNums;
- //
- let max_nums = Math.max.apply(null, res.goodsNums);
- option.yAxis[0].max = option.yAxis[1].max = parseInt(max_nums) + 10;
- option.series[2].data = res.orderMoney;
- let max_money = Math.max.apply(null, res.orderMoney);
- option.yAxis[2].max = parseInt(max_money) + 100;
- option.xAxis[0].axisLabel.rotate = res.is_oblique && res.orderMoney.length>6?-30:0;
-
- console.log(option.xAxis[0].axisLabel.rotate)
- option.series[3].data = res.rate;
- myChart.clear();
- console.log(option)
- myChart.setOption(option, true);
- return false;
- });
- }, 50);
- }
- return {
- chart: myChart,
- refresh: refresh
- };
- },
- }
- }
- };
- return Controller;
- });
|