cost.vue 51 KB

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