'use strict'; app.controller('realTimeCtrl', ["$scope", "$rootScope", "$state", "$timeout", "$interval", "$http", "$cookieStore", "SweetAlert", "Restangular", "api_report", "api_statistic", "moment", "api_event_form", "api_user_data", "api_bpm", "api_category", "$modal", "i18nService","api_newreport", function ($scope, $rootScope, $state, $timeout, $interval, $http, $cookieStore, SweetAlert, Restangular, api_report, api_statistic, moment, api_event_form, api_user_data, api_bpm, api_category, $modal, i18nService,api_newreport) { //默认无选中,选择日期 $scope.searchstate = 'none'; // 默认故障分布 $scope.categoryActive = '一级故障分类'; // 默认超时单 $scope.timeoutType = '接单超时'; // 默认超时单-小时数 $scope.timeoutNum = 2; //日期显示格式 $scope.datepickerPopuptime = 'yyyy-MM-dd'; //按日 $scope.dateItemClick = function () { $scope.dateItem = 'day'; $scope.datepickerPopuptime = 'yyyy-MM-dd';//日期格式化 $scope.day(0);//今日 }; // 切换院区 $scope.own = {}; $scope.changeBranch = function(){ console.log($scope.own.branch); $scope.dutys = []; $scope.own.duty = null; $scope.own.branch && $scope.getOwnDuty($scope.own.branch.id); } // 获取院区 $scope.branchs = []; $scope.getOwnBranch = function(){ api_category .getOwnBranch({}) .then(function (response) { if (response) { if ((response.status = 200)) { $scope.branchs = response.data; if($rootScope.user.duty){ $scope.own.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName}; $scope.getOwnDuty($rootScope.user.duty.branch, true); }else if($rootScope.user.branch){ $scope.own.branch = $rootScope.user.branch; $scope.getOwnDuty($rootScope.user.branch.id, true); $scope.init(); } } } }); } $scope.getOwnBranch(); // 获取责任科室 $scope.dutys = []; $scope.getOwnDuty = function(branchId, isFirst = false, isReload = false){ api_category .getOwnDuty({branchId: branchId}) .then(function (response) { if (response) { if ((response.status = 200)) { $scope.dutys = response.data; if(isFirst && $rootScope.user.duty){ $scope.own.duty = $rootScope.user.duty; $scope.init(); } if(isReload){ if($rootScope.user.duty){ $scope.own.duty = $rootScope.user.duty; } $scope.mdxquery(); } } } }); } //切换开始/结束日期 $scope.timesChange = function (str) { //切换结束日期的时候为年底或月底,方便传参 switch (str) { case 'month': $scope.endtimesModel = moment($scope.endtimesModel).endOf('month').toDate(); break; case 'year': $scope.endtimesModel = moment($scope.endtimesModel).endOf('year').toDate(); break; } $scope.datepickerUpdate(str); }; //配置项更新 $scope.datepickerUpdate = function (str) { //开始的datepickerOptions $scope.datepickerOptionsStart = { maxDate: moment($scope.endtimesModel).format('YYYY/MM/DD'), minMode: str, datepickerMode: str }; //结束的datepickerOptions $scope.datepickerOptionsEnd = { minDate: moment($scope.starttimesModel).format('YYYY/MM/DD'), maxDate: moment().format('YYYY/MM/DD'), minMode: str, datepickerMode: str }; }; //日期选择 //本周,上周 $scope.week = function (num) { if(num === 0){ // 本周 $scope.searchstate = "week" + num; $scope.starttimesModel = moment().startOf('week').add(1, 'days').toDate(); $scope.endtimesModel = moment().endOf('week').add(1, 'days').toDate(); }else{ num = num > 1 ? num : 1; $scope.searchstate = "week" + num; $scope.starttimesModel = moment().week( moment().week() - num).startOf('week').add(1, 'days').toDate(); $scope.endtimesModel = moment().week( moment().week() - num).endOf('week').add(1, 'days').toDate(); } $scope.datepickerUpdate('day'); } //本月,上月 $scope.month = function (num) { if(num === 0){ // 本月 $scope.searchstate = "month" + num; $scope.starttimesModel = moment().startOf('month').toDate(); $scope.endtimesModel = moment().endOf('month').toDate(); }else{ num = num > 1 ? num : 1; $scope.searchstate = "month" + num; $scope.starttimesModel = moment().month( moment().month() - num).startOf('month').toDate(); $scope.endtimesModel = moment().month( moment().month() - num).endOf('month').toDate(); } $scope.datepickerUpdate('month'); } //本日,上一日 $scope.day = function (num) { if(num === 0){ // 本日 $scope.searchstate = "day" + num; $scope.starttimesModel = moment().startOf('day').toDate(); $scope.endtimesModel = moment().endOf('day').toDate(); }else{ num = num > 1 ? num : 1; $scope.searchstate = "day" + num; $scope.starttimesModel = moment().day( moment().day() - num).startOf('day').toDate(); $scope.endtimesModel = moment().day( moment().day() - num).endOf('day').toDate(); } $scope.datepickerUpdate('day'); } //选择上一周,上个月,去年等等快捷方式 $scope.chooseDate = function (date) { switch (date) { case 'day0'://本日 $scope.day(0); break; case 'day1'://上一日 $scope.day(1); break; case 'week0'://本周 $scope.week(0); break; case 'week1'://上周 $scope.week(1); break; case 'month0'://本月 $scope.month(0); break; case 'month1'://上月 $scope.month(1); break; } }; /** *日历 */ //打开开始日期选择框 $scope.startOpen = function ($event) { console.log(1) $event.preventDefault(); $event.stopPropagation(); $scope.endOpened = false; $scope.startOpened = !$scope.startOpened; }; //打开结束日期选择框 $scope.endOpen = function ($event) { $event.preventDefault(); $event.stopPropagation(); $scope.startOpened = false; $scope.endOpened = !$scope.endOpened; }; //重置 $scope.reload = function () { $scope.dateItemClick('day'); if($rootScope.user.duty){ $scope.own.branch = {id: $rootScope.user.duty.branch, hosName: $rootScope.user.duty.branchName}; $scope.getOwnDuty($rootScope.user.duty.branch, false, true); }else if($rootScope.user.branch){ $scope.own.branch = $rootScope.user.branch; $scope.getOwnDuty($rootScope.user.branch.id, false, true); } }; //loading $scope.isArrays = function (arr) { return Array.isArray(arr); }; //图表 逾期统计环形图 function barechart6(datas) { datas = { "pieChart": [ { "name": "逾期接单数", "value": datas.resolvedOnTime || 0 }, { "name": "逾期处理数", "value": datas.resolvedOverTime || 0 }, ], } var dom = document.getElementById("XYSJ"); var option = null; var myChart = echarts.init(dom); var data = datas.pieChart; option = { color: ["#1978F2", "#33CC85"], title: { textAlign: "center", textStyle: { color: "#333", fontSize: 16, // align: 'center', }, subtextStyle: { fontSize: 14, color: ["#005395"], fontWeight: "bolder", }, x: "34.5%", y: "50%", }, tooltip: { trigger: "item", formatter: function (a) { return a["data"]["name"] + ":" + a["data"]["value"]; }, position: ["50%", "30%"], }, grid: { bottom: 150, left: 100, right: "10%", }, legend: { orient: "vertical", top: "middle", right: "5%", textStyle: { color: "#333", fontSize: 12, }, itemWidth: 8, itemHeight: 8, icon: "roundRect", data: data, }, series: [ // 主要展示层的 { radius: ["50%", "65%"], center: ["35%", "60%"], type: "pie", label: { normal: { show: true, formatter: "{c}", textStyle: { fontSize: 14, }, position: "outside", }, emphasis: { show: true, }, }, labelLine: { normal: { show: true, length: 5, length2: 25, }, emphasis: { show: true, }, }, name: "", data: data, }, ], }; if (option && typeof option === "object") { myChart.setOption(option, true); myChart.hideLoading(); } } //图表 故障现象趋势图 function barechart11(datas) { datas = { "data": [ datas.map(v => v.count), ], "dates": datas.map(v => v.hour + '时'), "title": [ "建单数", ], } console.log(datas); if (datas) { var dom = document.getElementById("deck_24build"); var myChart = echarts.init(dom); var option = null; var serie = []; for (var i = 0; i < datas.data.length; i++) { var Series = { name: datas.title[i], type: "line", itemStyle: { normal: { // color: '#49A9EE' }, }, lineStyle: { normal: { // color: '#49A9EE' }, }, data: datas.data[i], }; serie.push(Series); } console.log(serie); myChart.showLoading({ text: "数据加载中...", color: "#c23531", textColor: "#fff", maskColor: "rgba(255,255,255,0)", zlevel: 0, }); myChart.hideLoading(); option = { tooltip: { trigger: "axis", axisPointer: { // 坐标轴指示器,坐标轴触发有效 // type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' lineStyle: { color: "#49A9EE", type: "dotted", }, }, }, // legend: { // data: datas.title, // align: "left", // // itemWidth:10, // // itemHeight:10, // bottom: 0, // }, grid: { left: "2%", right: "2%", bottom: "5%", top: "20%", containLabel: true, }, xAxis: [ { type: "category", // axisTick: { // alignWithLabel: true // }, axisLabel: { textStyle: { color: "#7B7B7B", // fontSize: '14', }, }, axisLine: { show: true, lineStyle: { color: "#7B7B7B", // type: 'dotted' }, }, // data: ['10-12', '10-12', '10-12', '10-12', '10-12', '10-12', '10-12', '10-12', '10-12'] data: datas.dates, }, ], yAxis: [ { type: "value", scale: true, name: "建单数", min: 0, minInterval: 1, boundaryGap: [0.2, 0.2], // axisLabel: { // formatter: '{value}' // } axisLabel: { textStyle: { color: "#7B7B7B", // fontSize: '14', }, }, axisLine: { show: true, lineStyle: { color: "#7B7B7B", // type: 'dotted' }, }, }, ], series: serie, // [{ // name: '分类1', // type: 'line', // itemStyle: { // normal: { // color: '#49A9EE' // } // }, // lineStyle: { // normal: { // color: '#49A9EE' // } // }, // data: [10, 20, 5, 43, 12, 34, 12, 56, 67] // }, { // name: '分类2', // type: 'line', // itemStyle: { // normal: { // color: '#87C966' // } // }, // lineStyle: { // normal: { // color: '#87C966' // } // }, // data: [12, 10, 15, 23, 19, 24, 18, 26, 57] // }] }; if (option && typeof option === "object") { myChart.setOption(option, true); myChart.hideLoading(); } } // console.log(echarts) } // 查询人员统计 $scope.incidentCount = null; $scope.userCount = null; $scope.overtimeCount = null; $scope.getPersonnelStatistics = function(type){ if(type === 'overtimeCount'){ $scope[type] = null; }else{ $scope.incidentCount = null; $scope.userCount = null; $scope.overtimeCount = null; } api_newreport.fetchDataListIndex('indexCount2', { "dutyId": $scope.own.duty ? $scope.own.duty.id : undefined, "branchId": $scope.own.duty ? undefined: ($scope.own.branch ? $scope.own.branch.id : undefined), "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD HH:mm:ss'), "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD HH:mm:ss'), "receveOver": $scope.timeoutType == '接单超时' ? 1 : undefined, "receveOverHour": $scope.timeoutNum, }).then(function (res) { if (res.status == 200) { $scope.incidentCount = res.incidentCount ? res.incidentCount[0] : {}; $scope.userCount = res.userCount || []; $scope.overtimeCount = res.overtimeCount ? res.overtimeCount.map(v => ({...v,logTime: v.logTime ? moment(v.logTime).format('MM月DD日前完成') : ''})) : []; barechart6(res.overdueCount[0]); barechart11(res.incidentHourCount); } }) } // 查询故障分布 $scope.typedataList = null; $scope.getTypedataList = function(){ $scope.typedataList = null; $scope.typedataList = null; let hierarchy; if($scope.categoryActive === '一级故障分类'){ hierarchy = 1; }else if($scope.categoryActive === '二级故障分类'){ hierarchy = 2; }else if($scope.categoryActive === '三级故障分类'){ hierarchy = 3; } api_event_form.fetchSjlxList({ "dutyId": $scope.own.duty ? $scope.own.duty.id : undefined, "branchId": $scope.own.duty ? undefined: ($scope.own.branch ? $scope.own.branch.id : undefined), "startTime": moment($scope.starttimesModel).format('YYYY-MM-DD'), "endTime": moment($scope.endtimesModel).format('YYYY-MM-DD'), "hierarchy": hierarchy, "sortData": "sum", "sortType": "desc", "resolve":'resolve', }).then(function (res) { if (res.stats == 200) { $scope.typedataList = res.typedataList || []; } }) } // 超时单 $scope.timeoutTypeHandler = function(type){ typeof type === 'string' && ($scope.timeoutType = type); typeof type === 'number' && ($scope.timeoutNum = type); $scope.getPersonnelStatistics('overtimeCount'); } // 超时单 $scope.categoryActiveHandler = function(type){ $scope.categoryActive = type; $scope.getTypedataList(); } // 搜索 $scope.mdxquery = function(type){ $scope.getPersonnelStatistics(type); $scope.getTypedataList(); } //初始化 $scope.init = function(){ $scope.dateItemClick('day'); $scope.mdxquery(); } }])