dashboard.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. define(['jquery', 'bootstrap', 'backend', 'addtabs', 'echarts', 'echarts-theme'], function ($, undefined, Backend, undefined, Echarts) {
  2. var Controller = {
  3. index: function () {
  4. var procChart = null;
  5. var chartData = Config.procuremenChart || {};
  6. var chartEl = document.getElementById('procuremen-echart');
  7. if (chartEl) {
  8. procChart = Echarts.init(chartEl, 'walden');
  9. var labels = chartData.labels || [];
  10. var seriesMeta = [
  11. {name: '待确认', key: 'confirm', color: '#f0ad4e'},
  12. {name: '待审批', key: 'approval', color: '#7266ba'},
  13. {name: '已完结', key: 'completed', color: '#27C24C'}
  14. ];
  15. var maxVal = 0;
  16. seriesMeta.forEach(function (meta) {
  17. (chartData[meta.key] || []).forEach(function (v) {
  18. var n = parseInt(v, 10) || 0;
  19. if (n > maxVal) {
  20. maxVal = n;
  21. }
  22. });
  23. });
  24. procChart.setOption({
  25. color: seriesMeta.map(function (m) {
  26. return m.color;
  27. }),
  28. title: {
  29. text: '近7天单数',
  30. left: 0,
  31. top: 0,
  32. textStyle: {
  33. fontSize: 13,
  34. fontWeight: 600,
  35. color: '#555'
  36. }
  37. },
  38. tooltip: {
  39. trigger: 'axis',
  40. axisPointer: {type: 'line', lineStyle: {color: '#ddd'}},
  41. backgroundColor: 'rgba(50,50,50,0.92)',
  42. borderWidth: 0,
  43. textStyle: {fontSize: 12}
  44. },
  45. legend: {
  46. data: seriesMeta.map(function (m) {
  47. return m.name;
  48. }),
  49. top: 0,
  50. right: 0,
  51. itemWidth: 10,
  52. itemHeight: 10,
  53. textStyle: {fontSize: 11}
  54. },
  55. grid: {
  56. left: 2,
  57. right: 14,
  58. top: 36,
  59. bottom: 10,
  60. containLabel: true
  61. },
  62. xAxis: {
  63. type: 'category',
  64. boundaryGap: false,
  65. data: labels,
  66. axisTick: {show: false},
  67. axisLabel: {
  68. fontSize: 11,
  69. color: '#888',
  70. margin: 4,
  71. interval: 0,
  72. showMinLabel: true,
  73. showMaxLabel: true,
  74. alignMinLabel: 'left',
  75. alignMaxLabel: 'right'
  76. },
  77. axisLine: {lineStyle: {color: '#e8e8e8'}}
  78. },
  79. yAxis: {
  80. type: 'value',
  81. minInterval: 1,
  82. min: 0,
  83. max: maxVal <= 1 ? 2 : null,
  84. splitNumber: maxVal <= 2 ? 2 : 4,
  85. axisLabel: {fontSize: 11, color: '#888'},
  86. splitLine: {lineStyle: {color: '#f0f0f0', type: 'dashed'}}
  87. },
  88. series: seriesMeta.map(function (meta) {
  89. return {
  90. name: meta.name,
  91. type: 'line',
  92. smooth: true,
  93. showSymbol: true,
  94. symbol: 'circle',
  95. symbolSize: function (val) {
  96. return (parseInt(val, 10) || 0) > 0 ? 6 : 0;
  97. },
  98. lineStyle: {width: 2, color: meta.color},
  99. itemStyle: {color: meta.color, borderWidth: 2, borderColor: '#fff'},
  100. emphasis: {focus: 'series', lineStyle: {width: 3}},
  101. data: chartData[meta.key] || []
  102. };
  103. })
  104. });
  105. }
  106. $(window).resize(function () {
  107. if (procChart) {
  108. procChart.resize();
  109. }
  110. });
  111. setTimeout(function () {
  112. if (procChart) {
  113. procChart.resize();
  114. }
  115. }, 120);
  116. setTimeout(function () {
  117. if (procChart) {
  118. procChart.resize();
  119. }
  120. }, 400);
  121. $(document).on('click', '.btn-refresh', function () {
  122. setTimeout(function () {
  123. if (procChart) {
  124. procChart.resize();
  125. }
  126. }, 0);
  127. });
  128. }
  129. };
  130. return Controller;
  131. });