detailDep.vue 13 KB

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