cost.vue 56 KB

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