detailDep.vue 12 KB

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