detail.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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.toFixed(2)}}元</span></span>
  15. </el-form-item>
  16. </el-form>
  17. </el-col>
  18. <el-col :span="24" style="margin-top:10px;padding-bottom: 0px;text-align:center;">
  19. <el-radio-group v-model="radio" @change="getList">
  20. <el-radio-button label="人员"></el-radio-button>
  21. <el-radio-button label="子项目"></el-radio-button>
  22. <el-radio-button label="阶段" v-if="user.company.packageProject != 0"></el-radio-button>
  23. </el-radio-group>
  24. </el-col>
  25. <div id="clearfix" :style="'overflow-x: auto;width:100%;padding-bottom: 0px; position: relative; height:'+containerHeight+'px;'">
  26. <div id="container" :style="'height:' + tableHeight + 'px'"></div>
  27. </div>
  28. </section>
  29. </template>
  30. <script>
  31. import util from "../../common/js/util";
  32. export default {
  33. data() {
  34. return {
  35. yAxisValue: localStorage.yAxisValue,
  36. startDate:null,
  37. endDate: null,
  38. detailId: this.$route.params.id,
  39. detailName: this.$route.params.name,
  40. radio:"人员",
  41. user: JSON.parse(sessionStorage.getItem("user")),
  42. cost: 0,
  43. tableHeight: 0,
  44. echart: null,
  45. };
  46. },
  47. methods: {
  48. //返回
  49. backToList() {
  50. if (this.startDate != null) {
  51. this.$router.push("/cost?startDate="+this.startDate+"&endDate="+this.endDate);
  52. } else {
  53. this.$router.push("/cost");
  54. }
  55. },
  56. //获取项目列表
  57. getList() {
  58. this.listLoading = true;
  59. var url = "";
  60. if (this.radio=='人员') {
  61. url = this.port.project.projectCost;
  62. } else if (this.radio=='子项目') {
  63. url = '/sub-project/getTimeCost';
  64. } else {
  65. url = "/project/getCostInStage";
  66. }
  67. this.http.post(url, {
  68. id: this.detailId,
  69. startDate: this.startDate,
  70. endDate: this.endDate,
  71. },
  72. res => {
  73. //
  74. for(var i in res.data.costList) {
  75. if(i>20) {
  76. this.widthHtval = +this.widthHtval + 40
  77. } else {
  78. this.widthHtval = document.body.clientWidth - 230
  79. }
  80. }
  81. //
  82. this.listLoading = false;
  83. var _this = this;
  84. if (res.code == "ok") {
  85. var xList = [],yList = [] , list = res.data.costList;
  86. this.cost = res.data.totalMoneyCost;
  87. for(var i in list) {
  88. xList.push(list[i].name);
  89. yList.push({
  90. "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
  91. "cost": list[i].cost,
  92. "money": list[i].costMoney,
  93. });
  94. }
  95. var myChart = echarts.init(document.getElementById("container"));
  96. // 设置宽度
  97. myChart.resize({
  98. width: this.widthHtval
  99. })
  100. _this.myChart = myChart;
  101. var option = {
  102. // 工具箱
  103. toolbox: {
  104. show: true,
  105. feature:{
  106. saveAsImage:{
  107. show:true
  108. },
  109. restore:{
  110. show:true
  111. },
  112. dataView:{
  113. show:true
  114. },
  115. dataZoom:{
  116. show:true
  117. },
  118. magicType:{
  119. type:['line','bar']
  120. }
  121. }
  122. },
  123. grid : {
  124. top : 80, //距离容器上边界40像素
  125. bottom: 100, //距离容器下边界30像素
  126. left: 150,
  127. right: 150
  128. },
  129. tooltip:{
  130. trigger:'axis',
  131. formatter: function (params,ticket,callback) {
  132. var res = params[0].name + "<br/>工作成本"+" : " + params[0].data.money
  133. + "元 <br/>工作时长"+" : " + params[0].data.cost + "小时";
  134. return res;
  135. }
  136. },
  137. xAxis: {
  138. data: xList,
  139. axisLabel: {
  140. interval:0,rotate:20
  141. }
  142. },
  143. yAxis: [{
  144. type : 'value',
  145. axisLabel: {
  146. formatter:this.yAxisValue==0?'{value} (元)':'{value}(小时)'
  147. }
  148. }],
  149. series: [{
  150. name: this.yAxisValue==0?'工作成本(元)':'工作时长(小时)',
  151. type: 'bar',
  152. barMaxWidth: 30,
  153. data: yList,
  154. }]
  155. };
  156. myChart.setOption(option,{notMerge: true});
  157. } else {
  158. this.$message({
  159. message: res.msg,
  160. type: "error"
  161. });
  162. }
  163. },
  164. error => {
  165. this.listLoading = false;
  166. this.$message({
  167. message: error,
  168. type: "error"
  169. });
  170. });
  171. },
  172. // 左右滚动
  173. scrollFunction () {
  174. this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
  175. if (this.domObj.attachEvent) { // IE
  176. this.domObj.attachEvent('onmousewheel', this.mouseScroll)
  177. } else if (this.domObj.addEventListener) {
  178. this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
  179. }
  180. this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
  181. },
  182. mouseScroll(event) { // google 浏览器下
  183. let detail = event.wheelDelta || event.detail
  184. let moveForwardStep = -1
  185. let moveBackStep = 1
  186. let step = 0
  187. step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
  188. event.preventDefault() // 阻止浏览器默认事件
  189. this.domObj.scrollLeft = this.domObj.scrollLeft + step
  190. },
  191. },
  192. created() {
  193. let height = window.innerHeight;
  194. this.tableHeight = height - 145;
  195. const that = this;
  196. window.onresize = function temp() {
  197. that.tableHeight = window.innerHeight - 145;
  198. };
  199. },
  200. mounted() {
  201. this.startDate = this.$route.query.startDate;
  202. this.endDate = this.$route.query.endDate;
  203. this.getList();
  204. var _this = this;
  205. window.addEventListener("resize", function() {
  206. _this.myChart.resize();
  207. });
  208. this.scrollFunction()
  209. }
  210. };
  211. </script>
  212. <style lang="scss" scoped>
  213. .toolbar {
  214. .el-form-item {
  215. font-size: 14px;
  216. vertical-align: middle;
  217. }
  218. .back {
  219. font-size: 16px;
  220. cursor: pointer;
  221. }
  222. .divLine {
  223. width: 2px;
  224. background: #c3c3c3;
  225. height: 100%;
  226. }
  227. .workName {
  228. color: #333;
  229. font-size: 18px;
  230. }
  231. .workHours {
  232. color: #20a0ff;
  233. font-size: 18px;
  234. }
  235. }
  236. #container {
  237. float: left;
  238. width: 100%;
  239. }
  240. </style>
  241. <style lang="scss">
  242. </style>