cost.vue 48 KB

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