cost.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div id="container"></div>
  3. </template>
  4. <script>
  5. import util from "../../common/js/util";
  6. export default {
  7. data() {
  8. return {
  9. user: JSON.parse(sessionStorage.getItem("user")),
  10. myChart: null
  11. };
  12. },
  13. methods: {
  14. getEchart(){
  15. var _this = this;
  16. this.http.post(this.port.project.listCost, {},
  17. res => {
  18. if (res.code == "ok") {
  19. var xList = [], yList = [], list = res.data.costList, totalMoneyCost = res.data.totalMoneyCost;
  20. for(var i in list) {
  21. xList.push(list[i].project);
  22. yList.push({
  23. value: list[i].cost,
  24. "id": list[i].id,
  25. });
  26. }
  27. var myChart = echarts.init(document.getElementById("container"));
  28. _this.myChart = myChart;
  29. var option = {
  30. title: {
  31. text: '项目成本统计 总计' + totalMoneyCost + '元',
  32. left:'left',
  33. },
  34. // 工具箱
  35. toolbox: {
  36. show: true,
  37. feature:{
  38. saveAsImage:{
  39. show:true
  40. },
  41. restore:{
  42. show:true
  43. },
  44. dataView:{
  45. show:true
  46. },
  47. dataZoom:{
  48. show:true
  49. },
  50. magicType:{
  51. type:['line','bar']
  52. }
  53. }
  54. },
  55. tooltip:{
  56. trigger:'axis'
  57. },
  58. xAxis: {
  59. data: xList,
  60. axisLabel: {
  61. interval:0,rotate:40
  62. }
  63. },
  64. yAxis: [{
  65. type : 'value',
  66. axisLabel: {
  67. formatter:'{value} (h)'
  68. }
  69. }],
  70. series: [{
  71. name: '工作时长(h)',
  72. type: 'bar',
  73. barMaxWidth: 30,
  74. data: yList,
  75. }]
  76. };
  77. myChart.setOption(option);
  78. myChart.on('click', function(params) {
  79. _this.$router.push("/cost/" + params.data.id + "/" + params.name);
  80. });
  81. } else {
  82. this.$message({
  83. message: res.msg,
  84. type: "error"
  85. });
  86. }
  87. },
  88. error => {
  89. this.$message({
  90. message: error,
  91. type: "error"
  92. });
  93. });
  94. }
  95. },
  96. created() {
  97. },
  98. mounted() {
  99. this.$el.style.height = (window.innerHeight - 100) + "px";
  100. const that = this;
  101. window.onresize = function temp() {
  102. that.$el.style.height = (window.innerHeight - 100) + "px";
  103. };
  104. this.getEchart();
  105. var _this = this;
  106. window.addEventListener("resize", function() {
  107. _this.myChart.resize();
  108. });
  109. }
  110. };
  111. </script>
  112. <style lang="scss" scoped>
  113. #container {
  114. width: 100%;
  115. margin-top: 10px;
  116. }
  117. </style>
  118. <style lang="scss">
  119. </style>