cost.vue 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. <template>
  2. <section>
  3. <el-row style="padding-bottom: 0px;text-align:center;margin-top:20px;z-index: 999;">
  4. <el-col :span="6" >
  5. <div ><span style="color:#999;">图表Y轴: </span>
  6. <el-radio-group v-model="yAxisValue" @change="onYAxisChange">
  7. <el-radio-button label="0">显示成本</el-radio-button>
  8. <el-radio-button label="1">显示工时</el-radio-button>
  9. </el-radio-group></div>
  10. </el-col>
  11. <el-col :span="14" style="display: flex;flex-wrap: wrap;">
  12. <el-date-picker v-show="user.timeType.fixMonthcost==0"
  13. v-model="dateRange" :editable="false"
  14. format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  15. @change="getEchart"
  16. :clearable="true"
  17. range-separator="至"
  18. type="daterange"
  19. start-placeholder="开始日期"
  20. end-placeholder="结束日期"
  21. ></el-date-picker>
  22. <el-date-picker v-show="user.timeType.fixMonthcost==1"
  23. v-model="dateRange" :editable="false"
  24. format="yyyy-MM" value-format="yyyy-MM"
  25. @change="getEchart"
  26. :clearable="false"
  27. type="month"
  28. ></el-date-picker>
  29. <el-radio-group v-model="radio" @change="getEchart" style="margin-left:10px;">
  30. <el-radio-button label="项目"></el-radio-button>
  31. <el-radio-button label="部门"></el-radio-button>
  32. <el-radio-button label="人员"></el-radio-button>
  33. <el-radio-button :label="namess" v-if="jichu.customDegreeActive == 1"></el-radio-button>
  34. </el-radio-group>
  35. <el-select v-model="personnelValue" filterable clearable placeholder="请选择人员" style="margin-top: 10px;width: 350px" v-if="radio == '人员'" @change="personnel()">
  36. <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.name"></el-option>
  37. </el-select>
  38. </el-col>
  39. <el-col :span="4">
  40. <el-button @click="showExportDialog">报表导出</el-button>
  41. </el-col>
  42. </el-row>
  43. <!-- <div id="clearfix" :style="'width:'+widthHtval+'px;position: relative; height:'+containerHeight+'px;'">
  44. <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
  45. </div> -->
  46. <div id="clearfix" :class="radio == '人员' ? 'ryuans' : ''" :style="'overflow-x: auto;width:100%;padding-bottom: 100px; position: relative; height:'+containerHeight+'px;'">
  47. <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
  48. </div>
  49. <!-- <div>
  50. <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
  51. </div> -->
  52. <div style="position:fixed;top:170px;left:600px;" v-show="radio=='部门' && parentDeptId != null">
  53. <el-button @click="backToParentDept">返回上级</el-button>
  54. </div>
  55. <!--导出报表条件选择 -->
  56. <el-dialog title="工时报表导出" v-if="exportDialog" :visible.sync="exportDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
  57. <el-form ref="form3" :model="exportParam" >
  58. <el-form-item prop="projectId" label="选择项目" v-if="radio != '人员'">
  59. <el-select v-model="exportParam.projectId" placeholder="全部项目" clearable style="width:350px;" filterable="true">
  60. <el-option v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.id"></el-option>
  61. </el-select>
  62. </el-form-item>
  63. <el-form-item prop="userIds" label="选择人员" v-if="radio == '人员'">
  64. <el-select v-model="exportParam.userIds" placeholder="全部人员" multiple="true" clearable style="width:350px;" filterable="true">
  65. <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  66. </el-select>
  67. </el-form-item>
  68. <el-form-item prop="projectId" :label="user.timeType.fixMonthcost==0?'日期范围':'选择月份'">
  69. <el-date-picker v-show="user.timeType.fixMonthcost==0"
  70. v-model="exportParam.dateRange" :editable="false"
  71. format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  72. :clearable="false"
  73. range-separator="至"
  74. type="daterange"
  75. start-placeholder="开始日期"
  76. end-placeholder="结束日期"
  77. ></el-date-picker>
  78. <el-date-picker v-show="user.timeType.fixMonthcost==1"
  79. v-model="dateRange" :editable="false"
  80. format="yyyy-MM" value-format="yyyy-MM"
  81. @change="getEchart"
  82. :clearable="true"
  83. type="month"
  84. ></el-date-picker>
  85. </el-form-item>
  86. <el-form-item label="选择人员" v-if="radio == '项目' || radio == '部门'">
  87. <el-select v-model="exportParam.userId" placeholder="请选择人员" style="width: 350px" filterable="true" clearable="true">
  88. <span v-for="(item, index) in users" :key="index">
  89. <el-option :label="item.name" :value="item.id"></el-option>
  90. </span>
  91. </el-select>
  92. </el-form-item>
  93. <el-form-item prop="type" label="选择样式" v-if="radio == '项目' || radio == '部门'">
  94. <el-select v-model="exportParam.type" placeholder="选择样式" style="width:350px;" >
  95. <el-option label="项目在行上" value="0"></el-option>
  96. <el-option label="项目在列上" value="1"></el-option>
  97. </el-select>
  98. <div class="prompt">
  99. <el-popover placement="top" width="1200" trigger="hover">
  100. <img src="../../assets/image/hanglie.png" alt="" width="100%">
  101. <i class="el-icon-question" slot="reference" />
  102. </el-popover>
  103. </div>
  104. </el-form-item>
  105. <el-form-item v-if="radio == '项目' || radio == '部门'">
  106. <el-checkbox v-model="exportParam.projectSum" >含单个项目数据汇总</el-checkbox>
  107. </el-form-item>
  108. </el-form>
  109. <div slot="footer" class="dialog-footer">
  110. <el-button type="primary" @click="exportProjectData" style="width:100%;" >导出</el-button>
  111. </div>
  112. </el-dialog>
  113. </section>
  114. </template>
  115. <script>
  116. import util from "../../common/js/util";
  117. export default {
  118. data() {
  119. return {
  120. personnelValue: '',
  121. personnelAll: [],
  122. yAxisValue: localStorage.yAxisValue?localStorage.yAxisValue:0,
  123. parentDeptStack:[],
  124. parentDeptId:null,
  125. hasReportUserList:[],
  126. projectList:[],
  127. exportParam:{projectId:null,dateRange:[],userId: null,type: '0'},
  128. exportDialog:false,
  129. dateRange:[],
  130. user: JSON.parse(sessionStorage.getItem("user")),
  131. radio: sessionStorage.radio!=null?sessionStorage.radio:'项目',
  132. containerHeight: 0,
  133. myChart: null,
  134. params: null,
  135. widthHtval: document.body.clientWidth - 230,
  136. users: [],
  137. jichu: [],
  138. namess: '',
  139. timers: null, // 点击的时间
  140. zhishin: 0
  141. };
  142. },
  143. methods: {
  144. //Y轴点击改变显示的数据
  145. onYAxisChange() {
  146. localStorage.yAxisValue = this.yAxisValue;
  147. this.jieliu();
  148. },
  149. jutishez() {
  150. this.http.post('/time-type/getCompanyTimeSetting', {
  151. companyId: this.user.companyId,
  152. },
  153. res => {
  154. if (res.code == "ok") {
  155. this.jichu = res.data
  156. if(res.data.customDegreeActive == 1) {
  157. this.namess = res.data.customDegreeName
  158. }
  159. } else {
  160. this.$message({
  161. message: res.msg,
  162. type: "error"
  163. });
  164. }
  165. },
  166. error => {
  167. this.$message({
  168. message: error,
  169. type: "error"
  170. });
  171. });
  172. },
  173. getUsers() {
  174. console.log(this.port.manage.list)
  175. this.http.post(this.port.manage.list, {
  176. departmentId: -1,
  177. pageIndex: 1,
  178. pageSize: 99999
  179. },
  180. res => {
  181. if (res.code == "ok") {
  182. this.users = res.data.records;
  183. } else {
  184. this.$message({
  185. message: res.msg,
  186. type: "error"
  187. });
  188. }
  189. },
  190. error => {
  191. this.$message({
  192. message: error,
  193. type: "error"
  194. });
  195. });
  196. },
  197. showExportDialog() {
  198. console.log(12345)
  199. this.exportDialog = true;
  200. this.exportParam.dateRange = this.dateRange;
  201. console.log(this.hasReportUserList)
  202. if (this.radio == '人员') {
  203. // this.exportParam.userIds = [];
  204. }
  205. },
  206. //获取我的项目列表
  207. getMyProjectList() {
  208. this.http.post('/project/getProjectList', {
  209. },
  210. res => {
  211. if (res.code == "ok") {
  212. this.projectList = res.data;
  213. } else {
  214. this.$message({
  215. message: res.msg,
  216. type: "error"
  217. });
  218. }
  219. },
  220. error => {
  221. this.$message({
  222. message: error,
  223. type: "error"
  224. });
  225. });
  226. },
  227. exportProjectData() {
  228. var param = {};
  229. if (this.exportParam.dateRange != null) {
  230. param = {startDate:this.exportParam.dateRange[0], endDate: this.exportParam.dateRange[1]};
  231. }
  232. var url = "/project/exportTimeCost";
  233. var fileName = '项目工时成本统计.xls';
  234. if (this.radio == '人员' ) {
  235. console.log(this.exportParam.userIds);
  236. fileName = '人员工时成本统计.xls';
  237. url = '/department/exportUserStatistic';
  238. if (this.exportParam.userIds != null && this.exportParam.userIds.length > 0) {
  239. var ids = '';
  240. this.exportParam.userIds.forEach(u=>{
  241. ids += u+',';
  242. })
  243. param.userIds = ids;
  244. }
  245. }
  246. if (this.exportParam.projectId) {
  247. param.projectId = this.exportParam.projectId;
  248. }
  249. if (this.exportParam.userId) {
  250. if(this.radio == '项目' || this.radio == '部门' || this.radio == '人员'){
  251. param.userId = this.exportParam.userId;
  252. }
  253. }
  254. if (this.exportParam.projectSum != null) {
  255. if(this.radio == '项目' || this.radio == '部门'){
  256. param.projectSum = this.exportParam.projectSum;
  257. }
  258. }
  259. param.type = this.exportParam.type
  260. this.http.post(url, param,
  261. res => {
  262. this.listLoading = false;
  263. if (res.code == "ok") {
  264. this.exportDialog = false;
  265. var aTag = document.createElement('a');
  266. aTag.download = fileName;
  267. aTag.href = res.data;
  268. aTag.click();
  269. } else {
  270. this.$message({
  271. message: res.msg,
  272. type: "error"
  273. });
  274. }
  275. },
  276. error => {
  277. this.listLoading = false;
  278. this.$message({
  279. message: error,
  280. type: "error"
  281. });
  282. });
  283. },
  284. // 人员筛选
  285. personnel() {
  286. if(this.personnelValue) {
  287. var arrlist = JSON.parse(JSON.stringify(this.personnelAll))
  288. var arr = []
  289. for(var i in arrlist.list) {
  290. if(arrlist.list[i].name == this.personnelValue) {
  291. arr.push(arrlist.list[i])
  292. }
  293. }
  294. arrlist.list = arr
  295. this.gtff(arrlist)
  296. } else {
  297. this.gtff(this.personnelAll)
  298. }
  299. },
  300. //获取人员成本统计列表
  301. getUserCostList() {
  302. this.listLoading = true;
  303. console.log(this.port.project.userCost, '获取人员成本统计列表')
  304. this.http.post(this.port.project.userCost, {
  305. startDate:this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange,
  306. endDate: this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange
  307. },
  308. res => {
  309. this.listLoading = false;
  310. var _this = this;
  311. this.hasReportUserList = [];
  312. if (res.code == "ok") {
  313. //
  314. // var sss = []
  315. // var ddd = []
  316. // for(var i = 0; i < 120; i++) {
  317. // sss.push(res.data.list[0])
  318. // ddd.push(res.data.userList[0])
  319. // }
  320. // res.data.list = sss
  321. // res.data.userList = ddd
  322. for(var i in res.data.list) {
  323. if(i>20) {
  324. // this.widthHtval = +this.widthHtval + 2
  325. this.widthHtval = +this.widthHtval + 40
  326. } else {
  327. this.widthHtval = document.body.clientWidth - 230
  328. }
  329. }
  330. //
  331. this.personnelAll = res.data
  332. this.gtff(res.data)
  333. //工时总成本
  334. // this.hasReportUserList = res.data.userList;
  335. // var xList = [] yList = [] , list = res.data.list, array = [] , series = [];
  336. // var totalMoneyCost = res.data.totalCostMoney;
  337. // var totalHours = 0.0;
  338. // if (list.length > 0) {
  339. // var num = list.length==0?0:list[0].project.length;
  340. // for(var i in list) {
  341. // xList.push(list[i].name);
  342. // var pro = list[i].project;
  343. // for(var j in pro) {
  344. // if(array.indexOf(pro[j].project) == -1) {
  345. // array.push(pro[j].project)
  346. // }
  347. // }
  348. // }
  349. // for(var i in array) {
  350. // yList.push(array[i]);
  351. // var dataList = [];
  352. // for(var j in list) {
  353. // var project = list[j].project , num = 0;
  354. // if(project.length != 0) {
  355. // for(var k in project) {
  356. // if(project[k].project == array[i]) {
  357. // dataList.push({
  358. // "value": this.yAxisValue==0?project[k].money:project[k].time,
  359. // "cost": project[k].time,
  360. // "money":project[k].money
  361. // })
  362. // totalHours += parseFloat(project[k].time);
  363. // } else {
  364. // num++;
  365. // }
  366. // if(k == project.length-1 && num != project.length-1) {
  367. // dataList.push({
  368. // "value": 0,
  369. // "cost": 0,
  370. // "money":0,
  371. // })
  372. // }
  373. // }
  374. // } else {
  375. // dataList.push({
  376. // "value": 0,
  377. // "cost": 0,
  378. // "money":0,
  379. // })
  380. // }
  381. // }
  382. // series.push({
  383. // name: array[i],
  384. // type: 'bar',
  385. // stack:'1',
  386. // barMaxWidth: 30,
  387. // data: dataList,
  388. // })
  389. // }
  390. // }
  391. // var myChart = echarts.init(document.getElementById("container"));
  392. // totalHours = totalHours.toFixed(1);
  393. // // 设置宽度
  394. // myChart.resize({
  395. // width: this.widthHtval
  396. // })
  397. // // 设置宽度
  398. // _this.myChart = myChart;
  399. // var option = {
  400. // //总成本
  401. // title: {
  402. // text: '工时成本总计' + totalMoneyCost.toFixed(2) + '元, 时长'+totalHours+'小时',
  403. // left:'left',
  404. // },
  405. // // 工具箱
  406. // legend: {
  407. // x: 80,
  408. // y: 10,
  409. // data: yList,
  410. // show: true,
  411. //        top:"5%",//与上方的距离 可百分比% 可像素px
  412. // },
  413. // grid : {
  414. // top : 80, //距离容器上边界40像素
  415. // // bottom: 100, //距离容器下边界30像素
  416. // bottom: 35, //距离容器下边界30像素
  417. // left: 150,
  418. // right: 150
  419. // },
  420. // toolbox: {
  421. // show: true,
  422. // feature:{
  423. // saveAsImage:{
  424. // show:true
  425. // },
  426. // restore:{
  427. // show:true
  428. // },
  429. // // dataView:{
  430. // // show:true
  431. // // },
  432. // // dataZoom:{
  433. // // show:true
  434. // // },
  435. // magicType:{
  436. // type:['line','bar']
  437. // }
  438. // }
  439. // },
  440. // tooltip:{
  441. // trigger:'axis',
  442. // formatter: function (params,ticket,callback) {
  443. // var totalTime = 0;
  444. // var totalCost = 0;
  445. // var res = "";
  446. // for(var i in params) {
  447. // if (params[i].data.value > 0) {
  448. // res += "<div style='margin-top:3px;font-size:12px;'><font color='#ddd'>项目名称:" + params[i].seriesName
  449. // + "</font><br/>工作成本 : " + params[i].data.money
  450. // + "元 <br/>工作时长"+" : " + params[i].data.cost + "小时</br></div>";
  451. // totalTime += Number(params[i].data.cost);
  452. // totalCost += Number(params[i].data.money);
  453. // }
  454. // }
  455. // res = res +'<br/>'+ params[0].name+ '<br/>总计: ' + totalTime.toFixed(1)+'小时 '+totalCost.toFixed(2) + "元<br/>";
  456. // return res;
  457. // }
  458. // },
  459. // xAxis: {
  460. // data: xList,
  461. // axisLabel: {
  462. // interval:0,rotate:20
  463. // }
  464. // },
  465. // yAxis: [{
  466. // type : 'value',
  467. // axisLabel: {
  468. // formatter:this.yAxisValue==0?'{value} (元)':'{value} (小时)'
  469. // }
  470. // }],
  471. // series: series,
  472. // };
  473. // myChart.setOption(option,{notMerge:true});
  474. } else {
  475. this.$message({
  476. message: res.msg,
  477. type: "error"
  478. });
  479. }
  480. },
  481. error => {
  482. this.listLoading = false;
  483. this.$message({
  484. message: error,
  485. type: "error"
  486. });
  487. });
  488. },
  489. // 共同方法
  490. gtff(data) {
  491. var _this = this;
  492. this.hasReportUserList = data.userList;
  493. var xList = [] , yList = [] , list = data.list, array = [] , series = [];
  494. var totalMoneyCost = data.totalCostMoney;
  495. var totalHours = 0.0;
  496. if (list.length > 0) {
  497. var num = list.length==0?0:list[0].project.length;
  498. for(var i in list) {
  499. xList.push(list[i].name);
  500. var pro = list[i].project;
  501. for(var j in pro) {
  502. if(array.indexOf(pro[j].project) == -1) {
  503. array.push(pro[j].project)
  504. }
  505. }
  506. }
  507. for(var i in array) {
  508. yList.push(array[i]);
  509. var dataList = [];
  510. for(var j in list) {
  511. var project = list[j].project , num = 0;
  512. if(project.length != 0) {
  513. for(var k in project) {
  514. if(project[k].project == array[i]) {
  515. dataList.push({
  516. "value": this.yAxisValue==0?project[k].money:project[k].time,
  517. "cost": project[k].time,
  518. "money":project[k].money
  519. })
  520. totalHours += parseFloat(project[k].time);
  521. } else {
  522. num++;
  523. }
  524. if(k == project.length-1 && num != project.length-1) {
  525. dataList.push({
  526. "value": 0,
  527. "cost": 0,
  528. "money":0,
  529. })
  530. }
  531. }
  532. } else {
  533. dataList.push({
  534. "value": 0,
  535. "cost": 0,
  536. "money":0,
  537. })
  538. }
  539. }
  540. series.push({
  541. name: array[i],
  542. type: 'bar',
  543. stack:'1',
  544. barMaxWidth: 30,
  545. data: dataList,
  546. })
  547. }
  548. }
  549. var myChart = echarts.init(document.getElementById("container"));
  550. totalHours = totalHours.toFixed(1);
  551. // 设置宽度
  552. myChart.resize({
  553. width: this.widthHtval
  554. })
  555. // 设置宽度
  556. _this.myChart = myChart;
  557. var option = {
  558. //总成本
  559. title: {
  560. text: '工时成本总计' + totalMoneyCost.toFixed(2) + '元, 时长'+totalHours+'小时',
  561. left:'left',
  562. },
  563. // 工具箱
  564. legend: {
  565. x: 80,
  566. y: 10,
  567. data: yList,
  568. show: true,
  569.       top:"5%",//与上方的距离 可百分比% 可像素px
  570. },
  571. grid : {
  572. top : 80, //距离容器上边界40像素
  573. // bottom: 100, //距离容器下边界30像素
  574. bottom: 35, //距离容器下边界30像素
  575. left: 150,
  576. right: 150
  577. },
  578. toolbox: {
  579. show: true,
  580. feature:{
  581. saveAsImage:{
  582. show:true
  583. },
  584. restore:{
  585. show:true
  586. },
  587. // dataView:{
  588. // show:true
  589. // },
  590. // dataZoom:{
  591. // show:true
  592. // },
  593. magicType:{
  594. type:['line','bar']
  595. }
  596. }
  597. },
  598. tooltip:{
  599. trigger:'axis',
  600. formatter: function (params,ticket,callback) {
  601. var totalTime = 0;
  602. var totalCost = 0;
  603. var res = "";
  604. for(var i in params) {
  605. if (params[i].data.value > 0) {
  606. res += "<div style='margin-top:3px;font-size:12px;'><font color='#ddd'>项目名称:" + params[i].seriesName
  607. + "</font><br/>工作成本 : " + params[i].data.money
  608. + "元 <br/>工作时长"+" : " + params[i].data.cost + "小时</br></div>";
  609. totalTime += Number(params[i].data.cost);
  610. totalCost += Number(params[i].data.money);
  611. }
  612. }
  613. res = res +'<br/>'+ params[0].name+ '<br/>总计: ' + totalTime.toFixed(1)+'小时 '+totalCost.toFixed(2) + "元<br/>";
  614. return res;
  615. }
  616. },
  617. xAxis: {
  618. data: xList,
  619. axisLabel: {
  620. interval:0,rotate:20
  621. }
  622. },
  623. yAxis: [{
  624. type : 'value',
  625. axisLabel: {
  626. formatter:this.yAxisValue==0?'{value} (元)':'{value} (小时)'
  627. }
  628. }],
  629. series: series,
  630. };
  631. myChart.setOption(option,{notMerge:true});
  632. },
  633. yanjiu() {
  634. console.log('触发')
  635. },
  636. getEchart(){
  637. var that = this
  638. // that.timers = setTimeout(()=>{
  639. // clearTimeout(that.timers)
  640. // console.log(that.timers)
  641. that.jieliu()
  642. // },100);
  643. // this.jieliu()
  644. },
  645. backToParentDept() {
  646. if (this.radio == '部门') {
  647. if (this.parentDeptStack.length > 0) {
  648. this.parentDeptStack.pop();
  649. if (this.parentDeptStack.length > 0) {
  650. this.parentDeptId = this.parentDeptStack[this.parentDeptStack.length -1];
  651. } else {
  652. this.parentDeptId = null;
  653. }
  654. this.jieliu();
  655. }
  656. }
  657. },
  658. // 脱离出来的方法
  659. jieliu() {
  660. sessionStorage.radio = this.radio;
  661. var _this = this;
  662. var param = {};
  663. if (this.dateRange != null) {
  664. param = {startDate:this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange,
  665. endDate: this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange};
  666. console.log(param);
  667. }
  668. var url = '';
  669. if (this.radio=='项目') {
  670. url = this.port.project.listCost;
  671. } else if (this.radio=='部门') {
  672. url = this.port.project.depCost;
  673. param.parentDeptId = this.parentDeptId;
  674. } else if (this.radio=='人员') {
  675. this.getUserCostList();
  676. return;
  677. } else if (this.radio == this.namess) {
  678. url = '/project/getDegreeCost'
  679. }
  680. this.http.post(url, param,
  681. res => {
  682. if (res.code == "ok") {
  683. for(var i in res.data.costList) {
  684. if(i>20) {
  685. // this.widthHtval = +this.widthHtval + 2
  686. this.widthHtval = +this.widthHtval + 40
  687. } else {
  688. this.widthHtval = document.body.clientWidth - 230
  689. }
  690. }
  691. // 测试写的
  692. var xList = []
  693. var yList = []
  694. var list
  695. var totalMoneyCost;
  696. var totalHours = 0.0;
  697. if(this.radio == '项目' || this.radio=='部门') {
  698. list = res.data.costList
  699. totalMoneyCost = ((this.radio=='项目')?res.data.totalMoneyCost:res.data.totalCostMoney);
  700. for(var i in list) {
  701. if(this.radio=='项目') {
  702. xList.push(this.radio=='项目'?list[i].project:list[i].name);
  703. yList.push({
  704. "value": this.yAxisValue==0?list[i].costMoney.toFixed(2) || list[i].costMoney:list[i].cost.toFixed(1),
  705. "id": list[i].id || i,
  706. "cost": list[i].cost,
  707. "money":list[i].costMoney.toFixed(2)
  708. });
  709. totalHours += parseFloat(list[i].cost);
  710. } else {
  711. xList.push(list[i].departmentName);
  712. yList.push({
  713. "value": this.yAxisValue==0? list[i].costMoney.toFixed(2) || list[i].costMoney: list[i].costTime.toFixed(1),
  714. "id": list[i].departmentId,
  715. "cost": list[i].costTime,
  716. "hasSubDept": list[i].hasSubDept,
  717. "money":list[i].costMoney.toFixed(2)
  718. });
  719. totalHours += parseFloat(list[i].costTime);
  720. }
  721. }
  722. } else {
  723. list = res.data
  724. var totalMoneyCost = 0;
  725. for(var i in list) {
  726. console.log(list[i].name, list[i].costMoney, list[i].cost)
  727. xList.push(list[i].name);
  728. yList.push({
  729. "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
  730. "id": list[i].id || i,
  731. "cost": list[i].cost,
  732. "money":list[i].costMoney.toFixed(2)
  733. });
  734. totalHours += parseFloat(list[i].cost);
  735. totalMoneyCost += parseFloat(list[i].costMoney);
  736. }
  737. }
  738. totalHours = totalHours.toFixed(1);
  739. var myChart = echarts.init(document.getElementById("container"));
  740. myChart.resize({
  741. width: this.widthHtval
  742. })
  743. _this.myChart = myChart;
  744. // console.log(totalMoneyCost.toFixed(2), '看看', totalMoneyCost)
  745. // var chengbentongji = totalMoneyCost.toFixed(2) || totalMoneyCost
  746. if(totalMoneyCost) {
  747. this.zhishin = totalMoneyCost.toFixed(2)
  748. }
  749. if(this.radio == '项目' || this.radio == '人员' || this.radio=='部门') {
  750. var option = {
  751. title: {
  752. text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
  753. left:'left',
  754. },
  755. // 工具箱
  756. toolbox: {
  757. show: true,
  758. feature:{
  759. saveAsImage:{show:true},restore:{show:true}, magicType:{ type:['line','bar']},
  760. }
  761. },
  762. tooltip:{
  763. trigger:'axis',
  764. formatter: function (params,ticket,callback) {
  765. var res = params[0].name + "<br/>工作成本"+" : " + params[0].data.money
  766. + "元 <br/>工作时长"+" : " + params[0].data.cost + "小时";
  767. _this.params = params;
  768. return res;
  769. }
  770. },
  771. xAxis: {
  772. data: xList,
  773. axisLabel: {
  774. interval:0,rotate:20
  775. }
  776. },
  777. yAxis: [{
  778. type : 'value',
  779. axisLabel: {
  780. formatter:this.yAxisValue==0?'{value} (元)':'{value}小时'
  781. }
  782. }],
  783. series: [{
  784. name: this.yAxisValue==0?'工作成本(元)':'工作时长(小时)',
  785. type: 'bar',
  786. barMaxWidth: 30,
  787. data: yList,
  788. }]
  789. };
  790. } else {
  791. var option = {
  792. title: {
  793. text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
  794. left:'left',
  795. },
  796. // 工具箱
  797. toolbox: {
  798. show: true,
  799. feature:{
  800. saveAsImage:{show:true},restore:{show:true}, magicType:{ type:['line','bar']},
  801. }
  802. },
  803. tooltip:{
  804. trigger:'axis',
  805. formatter: function (params,ticket,callback) {
  806. var res = params[0].name + "<br/>工作成本"+" : " + params[0].data.money
  807. + "元 <br/>工作时长"+" : " + params[0].data.cost + "小时";
  808. _this.params = params;
  809. return res;
  810. }
  811. },
  812. xAxis: {
  813. data: xList,
  814. axisLabel: {
  815. interval:0,rotate:20
  816. }
  817. },
  818. yAxis: [{
  819. type : 'value',
  820. axisLabel: {
  821. formatter:this.yAxisValue==0?'{value} (元)':'{value}小时'
  822. }
  823. }],
  824. series: [{
  825. name: this.yAxisValue==0?'工作成本(元)':'工作时长(小时)',
  826. type: 'bar',
  827. barMaxWidth: 30,
  828. data: yList,
  829. }]
  830. };
  831. }
  832. myChart.setOption(option,{notMerge: true});
  833. myChart.getZr().on('click', params => {
  834. const pointInPixel = [params.offsetX, params.offsetY];
  835. if (myChart.containPixel('grid', pointInPixel)) {
  836. console.log(_this.params)
  837. if(_this.radio=='项目') {
  838. if (_this.dateRange != null) {
  839. if (this.user.timeType.fixMonthcost == 0) {
  840. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  841. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  842. } else {
  843. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  844. +"?startDate="+_this.dateRange+"&endDate="+_this.dateRange);
  845. }
  846. } else {
  847. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
  848. }
  849. } else if (_this.radio=='部门') {
  850. if (_this.params[0].data.hasSubDept) {
  851. if (_this.parentDeptId != _this.params[0].data.id) {
  852. _this.parentDeptId = _this.params[0].data.id;
  853. _this.parentDeptStack.push(_this.parentDeptId);
  854. _this.jieliu();
  855. }
  856. // _this.jieliu();
  857. } else {
  858. if (_this.dateRange != null) {
  859. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name
  860. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  861. } else {
  862. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name);
  863. }
  864. }
  865. }
  866. }
  867. });
  868. } else {
  869. this.$message({
  870. message: res.msg,
  871. type: "error"
  872. });
  873. }
  874. },
  875. error => {
  876. this.$message({
  877. message: error,
  878. type: "error"
  879. });
  880. });
  881. },
  882. // 左右滚动
  883. scrollFunction () {
  884. this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
  885. if (this.domObj.attachEvent) { // IE
  886. this.domObj.attachEvent('onmousewheel', this.mouseScroll)
  887. } else if (this.domObj.addEventListener) {
  888. this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
  889. }
  890. this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
  891. },
  892. mouseScroll(event) { // google 浏览器下
  893. let detail = event.wheelDelta || event.detail
  894. let moveForwardStep = -1
  895. let moveBackStep = 1
  896. let step = 0
  897. step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
  898. event.preventDefault() // 阻止浏览器默认事件
  899. this.domObj.scrollLeft = this.domObj.scrollLeft + step
  900. },
  901. },
  902. created() {
  903. },
  904. mounted() {
  905. this.containerHeight = window.innerHeight - 200
  906. // this.containerHeight = window.innerHeight - 130
  907. const that = this;
  908. window.onresize = function temp() {
  909. this.containerHeight = window.innerHeight - 130
  910. // this.containerHeight = window.innerHeight - 200
  911. };
  912. if (this.user.timeType.fixMonthcost == 0) {
  913. if (this.$route.query.startDate != null) {
  914. this.dateRange = [this.$route.query.startDate, this.$route.query.endDate];
  915. } else {
  916. //默认查看本月
  917. var now = new Date();
  918. var t = util.formatDate.format(now, 'yyyy-MM-dd');
  919. var startStr = util.formatDate.format(new Date(), 'yyyy-MM') + "-01";
  920. this.dateRange = [startStr,t];
  921. }
  922. this.exportParam.dateRange = this.dateRange;
  923. } else if (this.user.timeType.fixMonthcost == 1) {
  924. if (this.$route.query.startDate != null) {
  925. this.dateRange = this.$route.query.startDate;
  926. } else {
  927. //默认查看本月
  928. var startStr = util.formatDate.format(new Date(), 'yyyy-MM');
  929. this.dateRange = startStr;
  930. }
  931. this.exportParam.dateRange = this.dateRange;
  932. }
  933. this.radio = '项目'
  934. this.getEchart();
  935. var _this = this;
  936. window.addEventListener("resize", function() {
  937. _this.myChart.resize();
  938. });
  939. // this.getDepartment();
  940. this.getMyProjectList();
  941. this.getUsers()
  942. this.jutishez()
  943. this.scrollFunction()
  944. },
  945. };
  946. </script>
  947. <style lang="scss" scoped>
  948. #container {
  949. // display: inline-block;
  950. display: block;
  951. position: absolute;
  952. // width: 100% !important;
  953. margin-top: 60px;
  954. }
  955. .ryuans {
  956. top: -50px;
  957. }
  958. .prompt {
  959. position: absolute;
  960. right: 10px;
  961. top: 0;
  962. }
  963. </style>
  964. <style lang="scss">
  965. </style>