var myChart; var tabIndex = 0; $(document).ready(function() { layui.use('laydate', function() { var laydate = layui.laydate; //日期 laydate.render({ elem: '#sc_times', range: "~", theme: '#249fea', }); }); //tab切换 $('.hu-tab li').click(function() { $(this).addClass('active') .siblings().removeClass('active'); tabIndex = $(this).index(); $('.hu-content >div').eq(tabIndex).show() .siblings().hide(); }); //柱形图 //基于准备好的dom,初始化echarts实例 myChart = echarts.init(document.getElementById('huData')); var option = { tooltip: { trigger: 'axis', }, legend: { data: [], bottom: 40, padding: 5, }, grid: { bottom: 180 }, dataZoom: [{ // 这个dataZoom组件,默认控制x轴。 type: 'slider', // 这个 dataZoom 组件是 slider 型 dataZoom 组件 xAxisIndex: 0, start: 0, // 左边在 0% 的位置。 end: 100, // 右边在 100% 的位置。 bottom: 100, }, ], xAxis: [{ type: 'category', data: [], axisPointer: { type: '' }, axisLabel: { interval: 0, rotate: 40 } }], yAxis: [{ type: 'value', name: '通话次数(次)', nameLocation: 'end', axisLabel: { formatter: '{value} ' } }, { type: 'value', name: '通话时长(s)', nameLocation: 'end', axisLabel: { formatter: '{value} ' } } ], series: [{ type: 'bar', name: '呼入次数', data: [] }, { type: 'line', name: '呼入时长', yAxisIndex: 1, data: [] }, { type: 'bar', name: '呼出次数', data: [] }, { type: 'line', name: '呼出时长', yAxisIndex: 1, data: [] }, { type: 'bar', name: '呼出未接通次数', data: [] }, { type: 'line', name: '振铃时长', yAxisIndex: 1, data: [] }, { type: 'line', name: '通话总时长', yAxisIndex: 1, data: [] }, { type: 'line', name: '平均通话时长', yAxisIndex: 1, data: [] } ], //color: ['#1ab394', '#fbbe5b', '#88ebc4', '#fa957f', '#cddc39', '#ff5722', '#e91e63', '#673ab7', '#61a0a8', '#bda29a'] color: ['#74dbc6', '#d9c228', '#a1ef9f', '#66d1e8', '#8565e3', '#f8a6ad', '#e45764', '#bbb1f3', '#32a1e8', '#32da62'] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); //搜索事件 $("#sc_btns").click(function() { getDataList(); }); getDataList(); }) function getDataList() { var colsArr = []; var dataArr = []; var keys = []; var loadindex; $.ajax({ type: 'get', url: huayi.config.callcenter_url + "callcenterapi/api/talktime/getcolumnlist", async: true, dataType: 'json', success:function(data){ if(data.state.toLowerCase() == "success") { var cons = data.data; var legends=[]; if(cons && cons.length > 0) { var newArr = []; for (var j=0;j=1){ legends.push(cons[j]) } } myChart.setOption({ legend: { data: legends, }, }); newArr.push({ field: keys[0], title: keys[0], align: 'center', fixed: true, //sort: true, width: 150, }); for(var i = 0, colNL = keys.length; i < colNL; i++) { newArr.push({ field: keys[i], title: keys[i], align: 'center', //fixed: true, //sort: true, //width: 150, }); } colsArr.push(newArr); } } } }); $.ajax({ type: 'get', url: huayi.config.callcenter_url + "callcenterapi/api/talktime/getdatalist", async: true, dataType: 'json', beforeSend: function() { loadindex = layer.load() }, data: { stime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[0], endtime: $('#sc_times').val() && $('#sc_times').val().split(' ~ ')[1], }, success: function(data) { if(data.state.toLowerCase() == "success") { var result = data.data; if(result && result.length > 0) { dataArr = result; layui.use('table', function() { var table = layui.table; //方法级渲染 table.render({ elem: '#t_callTotal', skin: 'row', //line (行边框风格) row (列边框风格) nob (无边框风格) even: true, //开启隔行背景 size: 'lg', //sm,lg尺寸的表格 cellMinWidth: 100, page: true, cols: colsArr, data: dataArr, height: 'full-150' }); }); myChart.setOption({ xAxis: { data: (function() { var res = []; for(var i = 0; i < result.length; i++) { res.push(result[i].坐席名称); } return res; })(), }, series: (function() { var formatterArr = function(tarr, prames) { var newArrs = []; $.each(tarr, function(i, v) { $.each(v, function(j, k) { if(j == prames) { newArrs.push(k); } }); }); return { name: prames, data: newArrs }; } console.log( [formatterArr(result, "呼入次数"), formatterArr(result, "呼入时长"), formatterArr(result, "呼出次数"), formatterArr(result, "呼出时长"), formatterArr(result, "呼出未接通次数"), formatterArr(result, "振铃时长"), formatterArr(result, "通话总时长"), formatterArr(result, "平均通话时长") ]) return [formatterArr(result, "呼入次数"), formatterArr(result, "呼入时长"), formatterArr(result, "呼出次数"), formatterArr(result, "呼出时长"), formatterArr(result, "呼出未接通次数"), formatterArr(result, "振铃时长"), formatterArr(result, "通话总时长"), formatterArr(result, "平均通话时长") ] })(), }); } } }, }).then(function() { layer.close(loadindex); }); } function getNowYear() { //获取当前年份 var myDate = new Date(); return myDate.getFullYear(); //获取完整的年份(4位,1970-????) } //导出 function dcexcel(obj) { var beginyear=$('#sc_times').val() && $('#sc_times').val().split(' ~ ')[0]; var endyear=$('#sc_times').val() && $('#sc_times').val().split(' ~ ')[1]; var url=huayi.config.callcenter_url +"callcenterapi/api/talktime/exportexcel?stime="+ beginyear +"&endtime="+endyear ; obj.href = url; }