tongji.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. (function () {
  2. var page = {
  3. init: function ($page) {
  4. var gpsNumber = renlian.storage.get('userinfo').baseinfo.gpsNumber;
  5. renlian.httpget(config.webapi+"?s=api/get_driving_data", {gpsNumber:gpsNumber}, function (res) {
  6. var sData = [];
  7. var drivingdata = null;
  8. if(res.success){
  9. var respData = res.data;
  10. var days5Dist = 0;
  11. var day5Time = 0;
  12. console.log(respData);
  13. respData.forEach(v => {
  14. sData.push(v.totalDist.toFixed(2));
  15. days5Dist += v.totalDist;
  16. day5Time += v.totalTime;
  17. });
  18. var averageSpeed = (days5Dist / day5Time).toFixed(2);
  19. if(day5Time == 0){
  20. averageSpeed = 0.00;
  21. }
  22. drivingdata = [{name:'里程总计', value: days5Dist.toFixed(2) + 'km'}, {name:'累计时长', value: day5Time.toFixed(2) + '小时'}, {name:'平均速度', value: averageSpeed + 'km/h'}]
  23. //直方
  24. chartMap = {};
  25. chartMap['drive-data-bar'] = echarts.init(document.getElementById('drive-data-bar'));
  26. var xData = [];
  27. for(let i = 0;i < 5; ++i){
  28. var time = new Date(new Date() - 24*60*60*1000*i);
  29. var date = time.Format("MM-dd");
  30. xData.unshift(date);
  31. }
  32. var option1 = {
  33. title:{
  34. text: '近期行驶里程',
  35. x:'center',
  36. },
  37. color: ['#3398DB'],
  38. tooltip : {
  39. trigger: 'axis',
  40. axisPointer : { // 坐标轴指示器,坐标轴触发有效
  41. type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  42. }
  43. },
  44. grid: {
  45. left: '3%',
  46. right: '4%',
  47. bottom: '3%',
  48. containLabel: true
  49. },
  50. xAxis : [
  51. {
  52. type : 'category',
  53. data : xData,
  54. axisTick: {
  55. alignWithLabel: true
  56. },
  57. }
  58. ],
  59. yAxis : [
  60. {
  61. name: '里程/公里',
  62. type : 'value'
  63. }
  64. ],
  65. series : [
  66. {
  67. name:'行驶里程',
  68. type:'bar',
  69. barWidth: '50%',
  70. data:sData
  71. }
  72. ]
  73. };
  74. chartMap['drive-data-bar'].setOption(option1);
  75. //列表数据
  76. //renlian.httpget(config.webapi + "renlian/adms/desktop/data", { type: 'Target', id: _item.F_Id }, function(data){});
  77. // var drivingdata = '[{"name":"里程总计","value":"236.00km"},{"name":"累计时长","value":"1天00时00分"},{"name":"平均速度", "value":"9.83km/h"}]';
  78. // data = JSON.parse(drivingdata);
  79. var _itemHtml = ''
  80. $.each(drivingdata, function (_index, _item) {
  81. if(_index == 2){
  82. _itemHtml += '\
  83. <div style="flex: 0 0 100%;height:120px;padding-top: 40px;" class="targetItem">\
  84. <div class="number">'+ _item.value + '</div>\
  85. <div class="name">'+ _item.name +'</div>\
  86. </div>';
  87. }else{
  88. _itemHtml += '\
  89. <div style="flex: 0 0 50%;height:120px;padding-top: 40px;" class="targetItem">\
  90. <div class="number">'+ _item.value + '</div>\
  91. <div class="name">'+ _item.name +'</div>\
  92. </div>';
  93. }
  94. $page.find('#driving-data').html(_itemHtml);
  95. });
  96. }else{
  97. }
  98. });
  99. }
  100. };
  101. return page;
  102. })();