detail.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item>
  7. <el-button type="text" @click="backToList" icon="el-icon-back" class="back">返回</el-button>
  8. </el-form-item>
  9. <el-form-item class="divLine"></el-form-item>
  10. <el-form-item>
  11. <span class="workName">{{detailName}}</span>
  12. </el-form-item>
  13. <el-form-item style="float:right;">
  14. <span style="font-size:18px;">项目成本:<span style="color:#20a0ff;">{{cost}}元</span></span>
  15. </el-form-item>
  16. </el-form>
  17. </el-col>
  18. <div id="container" :style="'height:' + tableHeight + 'px'"></div>
  19. </section>
  20. </template>
  21. <script>
  22. import util from "../../common/js/util";
  23. export default {
  24. data() {
  25. return {
  26. detailId: this.$route.params.id,
  27. detailName: this.$route.params.name,
  28. user: JSON.parse(sessionStorage.getItem("user")),
  29. cost: 0,
  30. tableHeight: 0,
  31. echart: null,
  32. };
  33. },
  34. methods: {
  35. //返回
  36. backToList() {
  37. this.$router.go(-1);
  38. },
  39. //获取项目列表
  40. getList() {
  41. this.listLoading = true;
  42. this.http.post(this.port.project.projectCost, {
  43. id: this.detailId,
  44. },
  45. res => {
  46. this.listLoading = false;
  47. var _this = this;
  48. if (res.code == "ok") {
  49. var xList = [],yList = [] , list = res.data.costList;
  50. this.cost = res.data.totalMoneyCost;
  51. for(var i in list) {
  52. xList.push(list[i].name);
  53. yList.push({
  54. "value": list[i].cost,
  55. "cost": list[i].costMoney
  56. });
  57. }
  58. var myChart = echarts.init(document.getElementById("container"));
  59. _this.myChart = myChart;
  60. var option = {
  61. // 工具箱
  62. toolbox: {
  63. show: true,
  64. feature:{
  65. saveAsImage:{
  66. show:true
  67. },
  68. restore:{
  69. show:true
  70. },
  71. dataView:{
  72. show:true
  73. },
  74. dataZoom:{
  75. show:true
  76. },
  77. magicType:{
  78. type:['line','bar']
  79. }
  80. }
  81. },
  82. tooltip:{
  83. trigger:'axis',
  84. formatter: function (params,ticket,callback) {
  85. var res = params[0].name + "<br/>工作时长(h)"+" : " + params[0].data.value
  86. + "h <br/>工作成本(元)"+" : " + params[0].data.cost + "元";
  87. return res;
  88. }
  89. },
  90. xAxis: {
  91. data: xList,
  92. axisLabel: {
  93. interval:0,rotate:20
  94. }
  95. },
  96. yAxis: [{
  97. type : 'value',
  98. axisLabel: {
  99. formatter:'{value} (h)'
  100. }
  101. }],
  102. series: [{
  103. name: '工作时长(h)',
  104. type: 'bar',
  105. barMaxWidth: 30,
  106. data: yList,
  107. }]
  108. };
  109. myChart.setOption(option);
  110. } else {
  111. this.$message({
  112. message: res.msg,
  113. type: "error"
  114. });
  115. }
  116. },
  117. error => {
  118. this.listLoading = false;
  119. this.$message({
  120. message: error,
  121. type: "error"
  122. });
  123. });
  124. },
  125. },
  126. created() {
  127. let height = window.innerHeight;
  128. this.tableHeight = height - 145;
  129. const that = this;
  130. window.onresize = function temp() {
  131. that.tableHeight = window.innerHeight - 145;
  132. };
  133. },
  134. mounted() {
  135. this.getList();
  136. var _this = this;
  137. window.addEventListener("resize", function() {
  138. _this.myChart.resize();
  139. });
  140. }
  141. };
  142. </script>
  143. <style lang="scss" scoped>
  144. .toolbar {
  145. .el-form-item {
  146. font-size: 14px;
  147. vertical-align: middle;
  148. }
  149. .back {
  150. font-size: 16px;
  151. cursor: pointer;
  152. }
  153. .divLine {
  154. width: 2px;
  155. background: #c3c3c3;
  156. height: 100%;
  157. }
  158. .workName {
  159. color: #333;
  160. font-size: 18px;
  161. }
  162. .workHours {
  163. color: #20a0ff;
  164. font-size: 18px;
  165. }
  166. }
  167. #container {
  168. float: left;
  169. width: 100%;
  170. }
  171. </style>
  172. <style lang="scss">
  173. </style>