detailDep.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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-cascader v-model="departmentId" placeholder="请选择部门" style="width: 70%;margin-left:10px;" @change="getList"
  13. :options="option" :props="{ checkStrictly: true }" :show-all-levels="false"></el-cascader>
  14. </el-form-item>
  15. <el-form-item style="float:right;">
  16. <span style="font-size:18px;">部门成本:<span style="color:#20a0ff;">{{cost}}元</span></span>
  17. </el-form-item>
  18. </el-form>
  19. </el-col>
  20. <div id="container" :style="'height:' + tableHeight + 'px'"></div>
  21. </section>
  22. </template>
  23. <script>
  24. import util from "../../common/js/util";
  25. export default {
  26. data() {
  27. return {
  28. detailId: this.$route.params.id,
  29. detailName: this.$route.params.name,
  30. user: JSON.parse(sessionStorage.getItem("user")),
  31. cost: 0,
  32. tableHeight: 0,
  33. echart: null,
  34. option: [],
  35. departmentId: [].concat(parseInt(this.$route.params.id)),
  36. };
  37. },
  38. methods: {
  39. //返回
  40. backToList() {
  41. this.$router.go(-1);
  42. },
  43. // 获取部门列表
  44. getDepartment() {
  45. this.http.post( this.port.manage.depList, {},
  46. res => {
  47. if (res.code == "ok") {
  48. var list = res.data , array = [];
  49. for(var i in list) {
  50. if(list[i].id == this.detailId) {
  51. array.push(list[i])
  52. }
  53. }
  54. this.option = this.changeArr(array);
  55. } else {
  56. this.$message({
  57. message: res.msg,
  58. type: "error"
  59. });
  60. }
  61. },
  62. error => {
  63. this.$message({
  64. message: error,
  65. type: "error"
  66. });
  67. });
  68. },
  69. // 修改数组
  70. changeArr(arr) {
  71. for (var i = 0; i < arr.length; i++) {
  72. if(arr[i].id != -1 && arr[i].id != 0) {
  73. if (arr[i].children != null && arr[i].children.length>0) {
  74. arr[i].children = this.changeArr(arr[i].children);
  75. }
  76. arr[i].id && (arr[i].value = arr[i].id);
  77. delete arr[i].id;
  78. }
  79. }
  80. for(var i in arr) {
  81. if(arr[i].id == -1 || arr[i].id == 0) {
  82. arr.splice(i,1)
  83. }
  84. }
  85. return arr;
  86. },
  87. //获取项目列表
  88. getList() {
  89. this.listLoading = true;
  90. this.http.post(this.port.project.userCost, {
  91. departmentId: this.departmentId[this.departmentId.length-1],
  92. },
  93. res => {
  94. this.listLoading = false;
  95. var _this = this;
  96. if (res.code == "ok") {
  97. var xList = [] , yList = [] , list = res.data , array = [] , series = [];
  98. this.cost = res.data.totalMoneyCost;
  99. var num = list[0].project.length;
  100. for(var i in list) {
  101. xList.push(list[i].name);
  102. var pro = list[i].project;
  103. for(var j in pro) {
  104. if(array.indexOf(pro[j].project) == -1) {
  105. array.push(pro[j].project)
  106. }
  107. }
  108. }
  109. for(var i in array) {
  110. yList.push(array[i]);
  111. var dataList = [];
  112. for(var j in list) {
  113. var project = list[j].project , num = 0;
  114. if(project.length != 0) {
  115. for(var k in project) {
  116. if(project[k].project == array[i]) {
  117. dataList.push({
  118. "value": project[k].time,
  119. "cost": project[k].money,
  120. })
  121. } else {
  122. num++;
  123. }
  124. if(k == project.length-1 && num != project.length-1) {
  125. dataList.push({
  126. "value": 0,
  127. "cost": 0,
  128. })
  129. }
  130. }
  131. } else {
  132. dataList.push({
  133. "value": 0,
  134. "cost": 0,
  135. })
  136. }
  137. }
  138. series.push({
  139. name: array[i],
  140. type: 'bar',
  141. stack:'1',
  142. barMaxWidth: 30,
  143. data: dataList,
  144. })
  145. }
  146. var myChart = echarts.init(document.getElementById("container"));
  147. _this.myChart = myChart;
  148. var option = {
  149. // 工具箱
  150. legend: {
  151. x: 80,
  152. y: 10,
  153. data: yList
  154. },
  155. grid : {
  156. top : 80, //距离容器上边界40像素
  157. bottom: 35 //距离容器下边界30像素
  158. },
  159. toolbox: {
  160. show: true,
  161. feature:{
  162. saveAsImage:{
  163. show:true
  164. },
  165. restore:{
  166. show:true
  167. },
  168. dataView:{
  169. show:true
  170. },
  171. dataZoom:{
  172. show:true
  173. },
  174. magicType:{
  175. type:['line','bar']
  176. }
  177. }
  178. },
  179. tooltip:{
  180. trigger:'axis',
  181. formatter: function (params,ticket,callback) {
  182. var res = params[0].name + "<br/>";
  183. for(var i in params) {
  184. res += "项目名称:" + params[i].seriesName
  185. + "<br/>工作时长(h)" + params[i].data.value
  186. + "h <br/>工作成本(元)"+" : " + params[i].data.cost + "元</br></br>";
  187. }
  188. return res;
  189. }
  190. },
  191. xAxis: {
  192. data: xList,
  193. axisLabel: {
  194. interval:0,rotate:20
  195. }
  196. },
  197. yAxis: [{
  198. type : 'value',
  199. axisLabel: {
  200. formatter:'{value} (h)'
  201. }
  202. }],
  203. series: series,
  204. };
  205. myChart.setOption(option);
  206. } else {
  207. this.$message({
  208. message: res.msg,
  209. type: "error"
  210. });
  211. }
  212. },
  213. error => {
  214. this.listLoading = false;
  215. this.$message({
  216. message: error,
  217. type: "error"
  218. });
  219. });
  220. },
  221. },
  222. created() {
  223. let height = window.innerHeight;
  224. this.tableHeight = height - 145;
  225. const that = this;
  226. window.onresize = function temp() {
  227. that.tableHeight = window.innerHeight - 145;
  228. };
  229. },
  230. mounted() {
  231. this.getDepartment();
  232. this.getList();
  233. var _this = this;
  234. window.addEventListener("resize", function() {
  235. _this.myChart.resize();
  236. });
  237. }
  238. };
  239. </script>
  240. <style lang="scss" scoped>
  241. .toolbar {
  242. .el-form-item {
  243. font-size: 14px;
  244. vertical-align: middle;
  245. }
  246. .back {
  247. font-size: 16px;
  248. cursor: pointer;
  249. }
  250. .divLine {
  251. width: 2px;
  252. background: #c3c3c3;
  253. height: 100%;
  254. }
  255. .workName {
  256. color: #333;
  257. font-size: 18px;
  258. }
  259. .workHours {
  260. color: #20a0ff;
  261. font-size: 18px;
  262. }
  263. }
  264. #container {
  265. float: left;
  266. width: 100%;
  267. }
  268. </style>
  269. <style lang="scss">
  270. </style>