app.controller('businessStatsCtrl', ['$scope', '$http', '$timeout', '$state', '$interval', 'uiGridConstants', 'i18nService', 'toaster', function ($scope, $http, $timeout, $state, $interval, uiGridConstants, i18nService, toaster) { i18nService.setCurrentLang("zh-cn"); moment.locale('zh-cn'); $scope.startTimeOpen = false; $scope.endTimeOpen = false; $scope.timeChange = function (newDate, oldDate) { $scope.startTimeOpen = false; $scope.endTimeOpen = false; }; var defaultValue = { agent: {id: "", nickname: "-选择代理商-"}, dealer: {value: "", label: "-选择经销商-"}, }; //下拉框数据 $scope.condition = { agent: [defaultValue.agent], dealer: [defaultValue.dealer], }; //查询条件 $scope.query = { agent: defaultValue.agent, dealer: defaultValue.dealer, startTime: moment().format("YYYY-MM-DD"), endTime: moment().format("YYYY-MM-DD"), }; //不传分页参数则获取全部代理商 $http.get('/agent/getAgentsDetailList', {}).then(function (data) { $scope.condition.agent = data.data.payload.dataList; $scope.condition.agent.unshift(defaultValue.agent);//可以选空 }); function getCurrentTab() { var currentType = "" if ($state.current.url === "/charge") { currentType = "charge" } if ($state.current.url === "/chargeCard") { currentType = "chargeCard" } if ($state.current.url === "/consumption") { currentType = "consumption" } return currentType } // 路由状态监听有问题,暂时用定时器 var timer1 = null $scope.getCurrentTabTimer = function () { if (timer1) { return } timer1 = $interval(function () { $scope.currentType = getCurrentTab() }, 1000) }; $scope.$on("$destroy", function () { $interval.cancel(timer1) timer1 = null }); $scope.getCurrentTabTimer() // angular 事件绑定 $scope.ngEvent = { //初始化代理商 changeAgent: function () { var id = $scope.query.agent.id; //无论是否选择了数据,都清空子级下拉框选中的项 $scope.query.dealer = defaultValue.dealer; //无论怎么选择,都清空子下拉框的所有选项 $scope.condition.dealer = [defaultValue.dealer]; //如果选择了代理商,则加载经销商 if (id) { $http.get('/ad/getDealerList', {params: {agentId: id}}).then(function (data) { $scope.condition.dealer = data.data.payload; $scope.condition.dealer.unshift(defaultValue.dealer);//可以选空 }); } }, changeDealer: function () { }, quickTime: function (event, passDay) { $scope.query.startTime = moment().add(-(passDay - 1), "day").format("YYYY-MM-DD"); $scope.query.endTime = moment().format("YYYY-MM-DD"); }, //查询 query: function () { if ($scope.query.startTime > $scope.query.endTime) { toaster.pop("info", "提示", "开始时间必须小于结束时间!"); return; } $scope.refreshTableData(); }, exportExcelOpen: false, //导出 exportExcel: function () { var params = { type: getCurrentTab() }; var query = $scope.query; params.agentId = query.agent.id params.dealerId = query.dealer.value params.startTime = query.startTime params.endTime = query.endTime if ($scope.ngEvent.exportExcelOpen) { toaster.pop("info", "提示", "有一份报表正在生成,请稍候!"); return; } else { $scope.ngEvent.exportExcelOpen = true; } $http.get('/manager/exportExcel', {params: params}).then(function (data) { data = data.data $scope.ngEvent.exportExcelOpen = false; if (data.result == 1) { var payload = data.payload; toaster.pop("success", data.description); $state.go('app.tool.offlineTask', { searchKey: payload }); } }).catch(function (data) { $scope.ngEvent.exportExcelOpen = false; if (data.status == 504) { toaster.pop("error", "计算超时,请前往任务->执行离线生成报表"); } else { toaster.pop("error", "系统错误,请重试"); } }); } }; // 通知刷新子页面数据 $scope.refreshTableData = function () { $scope.$broadcast("refreshTableData"); }; // 订单统计 var businessChartPanel; $scope.showChart = function (apiType) { $("#chartInfoPanel").modal(); apiType === 'order' ? $scope.dialogName = '用户订单统计' : $scope.dialogName = '用户活跃度统计' //展示趋势图 businessChartPanel = echarts.init(document.getElementById('businessChartPanel')); //resize事件绑定 $(window).off("resize.businessChartPanel").on("resize.businessChartPanel", function () { businessChartPanel.resize(); }); loadChartData(apiType); $(window).trigger('resize') }; $scope.closeChart = function () { $("#chartInfoPanel").modal('hide'); }; //按条件加载统计图 var loadChartData = $scope.loadChartData = function (apiType) { var params = {type: getCurrentTab()}; var query = $scope.query; params.agentId = query.agent.id params.dealerId = query.dealer.value params.startTime = query.startTime params.endTime = query.endTime var mask = new Mask("正在统计,请稍候..."); mask.show(true).dom.css({'z-index': 1060}); var url = '/manager/getBusinessTrend'; if (apiType === 'userActivity') { url = '/manager/getUserActivityTrend'; } //获取数据 $http.get(url, { params: params }).then(function (data) { mask.remove(); var payload = data.data.payload var option = setChartOption(payload.dataList, apiType); businessChartPanel.setOption(option); }); }; //趋势自定义样式 function setChartOption(dataList, apiType) { var xData = []; var seriesData = []; for (var index in dataList) { var item = dataList[index] xData.push(moment(item.date).format("MM-DD")); seriesData.push(parseFloat(item.value)); } var option = { legend: { show: false }, tooltip: { trigger: 'axis', axisPointer: { lineStyle: { color: '#108EE9', width: .3, } } }, grid: { x: 40, x2: 15, y: 45, y2: 40, }, xAxis: [ { type: 'category', axisLabel: { textStyle: { color: "#aaa", fontSize: "12px" } }, axisTick: { show: false, }, axisLine: { show: false, }, data: xData } ], yAxis: [ { type: 'value', axisLabel: { textStyle: { color: "#aaa", fontSize: "12px" } }, axisTick: { show: false, }, axisLine: { show: false, }, splitLine: { lineStyle: { color: '#ccc', width: 0.3, type: 'dotted' } }, }, ], series: [] }; var name = apiType === 'order' ? '总额' : '总数' var color = apiType === 'order' ? '#ED6066' : '#07C160' option.series.push({ name: name, type: 'bar', symbolSize: 0, itemStyle: { normal: { color: color, } }, data: seriesData, }); return option } }]);