123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987 |
- <template>
- <section>
- <el-row style="padding-bottom: 0px;text-align:center;margin-top:20px;z-index: 999;">
- <el-col :span="6" >
- <div ><span style="color:#999;">图表Y轴: </span>
- <el-radio-group v-model="yAxisValue" @change="onYAxisChange">
- <el-radio-button label="0">显示成本</el-radio-button>
- <el-radio-button label="1">显示工时</el-radio-button>
- </el-radio-group></div>
- </el-col>
- <el-col :span="14" style="display: flex;flex-wrap: wrap;">
- <el-date-picker v-show="user.timeType.fixMonthcost==0"
- v-model="dateRange" :editable="false"
- format="yyyy-MM-dd" value-format="yyyy-MM-dd"
- @change="getEchart"
- :clearable="true"
- range-separator="至"
- type="daterange"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- ></el-date-picker>
- <el-date-picker v-show="user.timeType.fixMonthcost==1"
- v-model="dateRange" :editable="false"
- format="yyyy-MM" value-format="yyyy-MM"
- @change="getEchart"
- :clearable="false"
- type="month"
- ></el-date-picker>
- <el-radio-group v-model="radio" @change="getEchart" style="margin-left:10px;">
- <el-radio-button label="项目"></el-radio-button>
- <el-radio-button label="部门"></el-radio-button>
- <el-radio-button label="人员"></el-radio-button>
- <el-radio-button :label="namess" v-if="jichu.customDegreeActive == 1"></el-radio-button>
- </el-radio-group>
- <el-select v-model="personnelValue" filterable clearable placeholder="请选择人员" style="margin-top: 10px;width: 350px" v-if="radio == '人员'" @change="personnel()">
- <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.name"></el-option>
- </el-select>
- </el-col>
- <el-col :span="4">
- <el-button @click="showExportDialog">报表导出</el-button>
- </el-col>
- </el-row>
- <!-- <div id="clearfix" :style="'width:'+widthHtval+'px;position: relative; height:'+containerHeight+'px;'">
- <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
- </div> -->
- <div id="clearfix" :class="radio == '人员' ? 'ryuans' : ''" :style="'overflow-x: auto;width:100%;padding-bottom: 100px; position: relative; height:'+containerHeight+'px;'">
- <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
- </div>
- <!-- <div>
- <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
- </div> -->
- <div style="position:fixed;top:170px;left:600px;" v-show="radio=='部门' && parentDeptId != null">
- <el-button @click="backToParentDept">返回上级</el-button>
- </div>
- <!--导出报表条件选择 -->
- <el-dialog title="工时报表导出" v-if="exportDialog" :visible.sync="exportDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
- <el-form ref="form3" :model="exportParam" >
- <el-form-item prop="projectId" label="选择项目" v-if="radio != '人员'">
- <el-select v-model="exportParam.projectId" placeholder="全部项目" clearable style="width:350px;" filterable="true">
- <el-option v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.id"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item prop="userIds" label="选择人员" v-if="radio == '人员'">
- <el-select v-model="exportParam.userIds" placeholder="全部人员" multiple="true" clearable style="width:350px;" filterable="true">
- <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.id"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item prop="projectId" :label="user.timeType.fixMonthcost==0?'日期范围':'选择月份'">
- <el-date-picker v-show="user.timeType.fixMonthcost==0"
- v-model="exportParam.dateRange" :editable="false"
- format="yyyy-MM-dd" value-format="yyyy-MM-dd"
- :clearable="false"
- range-separator="至"
- type="daterange"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- ></el-date-picker>
-
- <el-date-picker v-show="user.timeType.fixMonthcost==1"
- v-model="dateRange" :editable="false"
- format="yyyy-MM" value-format="yyyy-MM"
- @change="getEchart"
- :clearable="true"
- type="month"
- ></el-date-picker>
- </el-form-item>
-
- <el-form-item label="选择人员" v-if="radio == '项目' || radio == '部门'">
- <el-select v-model="exportParam.userId" placeholder="请选择人员" style="width: 350px" filterable="true" clearable="true">
- <span v-for="(item, index) in users" :key="index">
- <el-option :label="item.name" :value="item.id"></el-option>
- </span>
- </el-select>
- </el-form-item>
- <el-form-item prop="type" label="选择样式" v-if="radio == '项目' || radio == '部门'">
- <el-select v-model="exportParam.type" placeholder="选择样式" style="width:350px;" >
- <el-option label="项目在行上" value="0"></el-option>
- <el-option label="项目在列上" value="1"></el-option>
- </el-select>
- <div class="prompt">
- <el-popover placement="top" width="700" trigger="hover">
- <img v-if="exportParam.type == 0" src="../../assets/image/hangs.png" alt="" width="100%">
- <img v-if="exportParam.type == 1" src="../../assets/image/lies.png" alt="" width="100%">
- <i class="el-icon-question" slot="reference" />
- </el-popover>
- </div>
- </el-form-item>
- <el-form-item v-if="radio == '项目' || radio == '部门'">
- <el-checkbox v-model="exportParam.projectSum" >含单个项目数据汇总</el-checkbox>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button type="primary" @click="exportProjectData" style="width:100%;" >导出</el-button>
- </div>
- </el-dialog>
- </section>
- </template>
- <script>
- import util from "../../common/js/util";
- export default {
- data() {
- return {
- personnelValue: '',
- personnelAll: [],
- yAxisValue: localStorage.yAxisValue?localStorage.yAxisValue:0,
- parentDeptStack:[],
- parentDeptId:null,
- hasReportUserList:[],
- projectList:[],
- exportParam:{projectId:null,dateRange:[],userId: null,type: '0'},
- exportDialog:false,
- dateRange:[],
- user: JSON.parse(sessionStorage.getItem("user")),
- radio: sessionStorage.radio!=null?sessionStorage.radio:'项目',
- containerHeight: 0,
- myChart: null,
- params: null,
- widthHtval: document.body.clientWidth - 230,
- users: [],
- jichu: [],
- namess: '',
- timers: null, // 点击的时间
- zhishin: 0
- };
- },
- methods: {
- //Y轴点击改变显示的数据
- onYAxisChange() {
- localStorage.yAxisValue = this.yAxisValue;
- this.jieliu();
- },
- jutishez() {
- this.http.post('/time-type/getCompanyTimeSetting', {
- companyId: this.user.companyId,
- },
- res => {
- if (res.code == "ok") {
- this.jichu = res.data
- if(res.data.customDegreeActive == 1) {
- this.namess = res.data.customDegreeName
- }
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- getUsers() {
- console.log(this.port.manage.list)
- this.http.post(this.port.manage.list, {
- departmentId: -1,
- pageIndex: 1,
- pageSize: 99999
- },
- res => {
- if (res.code == "ok") {
- this.users = res.data.records;
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
-
- showExportDialog() {
- console.log(12345)
- this.exportDialog = true;
- this.exportParam.dateRange = this.dateRange;
- console.log(this.hasReportUserList)
- if (this.radio == '人员') {
- // this.exportParam.userIds = [];
- }
- },
- //获取我的项目列表
- getMyProjectList() {
- this.http.post('/project/getProjectList', {
- },
- res => {
- if (res.code == "ok") {
- this.projectList = res.data;
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- exportProjectData() {
- var param = {};
- if (this.exportParam.dateRange != null) {
- param = {startDate:this.exportParam.dateRange[0], endDate: this.exportParam.dateRange[1]};
- }
- var url = "/project/exportTimeCost";
- var fileName = '项目工时成本统计.xls';
- if (this.radio == '人员' ) {
- console.log(this.exportParam.userIds);
- fileName = '人员工时成本统计.xls';
- url = '/department/exportUserStatistic';
- if (this.exportParam.userIds != null && this.exportParam.userIds.length > 0) {
- var ids = '';
- this.exportParam.userIds.forEach(u=>{
- ids += u+',';
- })
- param.userIds = ids;
- }
- }
-
- if (this.exportParam.projectId) {
- param.projectId = this.exportParam.projectId;
- }
- if (this.exportParam.userId) {
- if(this.radio == '项目' || this.radio == '部门' || this.radio == '人员'){
- param.userId = this.exportParam.userId;
- }
- }
- if (this.exportParam.projectSum != null) {
- if(this.radio == '项目' || this.radio == '部门'){
- param.projectSum = this.exportParam.projectSum;
- }
- }
- param.type = this.exportParam.type
- this.http.post(url, param,
- res => {
- this.listLoading = false;
- if (res.code == "ok") {
- this.exportDialog = false;
- var aTag = document.createElement('a');
- aTag.download = fileName;
- aTag.href = res.data;
- aTag.click();
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.listLoading = false;
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- // 人员筛选
- personnel() {
- if(this.personnelValue) {
- var arrlist = JSON.parse(JSON.stringify(this.personnelAll))
- var arr = []
- for(var i in arrlist.list) {
- if(arrlist.list[i].name == this.personnelValue) {
- arr.push(arrlist.list[i])
- }
- }
- arrlist.list = arr
- this.gtff(arrlist)
- } else {
- this.gtff(this.personnelAll)
- }
- },
- //获取人员成本统计列表
- getUserCostList() {
- this.listLoading = true;
- console.log(this.port.project.userCost, '获取人员成本统计列表')
- this.http.post(this.port.project.userCost, {
- startDate:this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange,
- endDate: this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange
- },
- res => {
- this.listLoading = false;
- var _this = this;
- this.hasReportUserList = [];
- if (res.code == "ok") {
- //
- // var sss = []
- // var ddd = []
- // for(var i = 0; i < 120; i++) {
- // sss.push(res.data.list[0])
- // ddd.push(res.data.userList[0])
- // }
- // res.data.list = sss
- // res.data.userList = ddd
- for(var i in res.data.list) {
- if(i>20) {
- // this.widthHtval = +this.widthHtval + 2
- this.widthHtval = +this.widthHtval + 40
- } else {
- this.widthHtval = document.body.clientWidth - 230
- }
- }
- //
- this.personnelAll = res.data
- this.gtff(res.data)
- //工时总成本
- // this.hasReportUserList = res.data.userList;
- // var xList = [] yList = [] , list = res.data.list, array = [] , series = [];
- // var totalMoneyCost = res.data.totalCostMoney;
- // var totalHours = 0.0;
- // if (list.length > 0) {
- // var num = list.length==0?0:list[0].project.length;
- // for(var i in list) {
- // xList.push(list[i].name);
- // var pro = list[i].project;
- // for(var j in pro) {
- // if(array.indexOf(pro[j].project) == -1) {
- // array.push(pro[j].project)
- // }
- // }
- // }
- // for(var i in array) {
- // yList.push(array[i]);
- // var dataList = [];
- // for(var j in list) {
- // var project = list[j].project , num = 0;
- // if(project.length != 0) {
- // for(var k in project) {
- // if(project[k].project == array[i]) {
- // dataList.push({
- // "value": this.yAxisValue==0?project[k].money:project[k].time,
- // "cost": project[k].time,
- // "money":project[k].money
- // })
- // totalHours += parseFloat(project[k].time);
- // } else {
- // num++;
- // }
- // if(k == project.length-1 && num != project.length-1) {
- // dataList.push({
- // "value": 0,
- // "cost": 0,
- // "money":0,
- // })
- // }
- // }
- // } else {
- // dataList.push({
- // "value": 0,
- // "cost": 0,
- // "money":0,
- // })
- // }
- // }
- // series.push({
- // name: array[i],
- // type: 'bar',
- // stack:'1',
- // barMaxWidth: 30,
- // data: dataList,
- // })
- // }
- // }
-
-
- // var myChart = echarts.init(document.getElementById("container"));
- // totalHours = totalHours.toFixed(1);
- // // 设置宽度
- // myChart.resize({
- // width: this.widthHtval
- // })
- // // 设置宽度
- // _this.myChart = myChart;
- // var option = {
- // //总成本
- // title: {
- // text: '工时成本总计' + totalMoneyCost.toFixed(2) + '元, 时长'+totalHours+'小时',
- // left:'left',
- // },
- // // 工具箱
- // legend: {
- // x: 80,
- // y: 10,
- // data: yList,
- // show: true,
- // top:"5%",//与上方的距离 可百分比% 可像素px
- // },
- // grid : {
- // top : 80, //距离容器上边界40像素
- // // bottom: 100, //距离容器下边界30像素
- // bottom: 35, //距离容器下边界30像素
- // left: 150,
- // right: 150
- // },
- // toolbox: {
- // show: true,
- // feature:{
- // saveAsImage:{
- // show:true
- // },
- // restore:{
- // show:true
- // },
- // // dataView:{
- // // show:true
- // // },
- // // dataZoom:{
- // // show:true
- // // },
- // magicType:{
- // type:['line','bar']
- // }
- // }
- // },
- // tooltip:{
- // trigger:'axis',
- // formatter: function (params,ticket,callback) {
- // var totalTime = 0;
- // var totalCost = 0;
- // var res = "";
- // for(var i in params) {
- // if (params[i].data.value > 0) {
- // res += "<div style='margin-top:3px;font-size:12px;'><font color='#ddd'>项目名称:" + params[i].seriesName
- // + "</font><br/>工作成本 : " + params[i].data.money
- // + "元 <br/>工作时长"+" : " + params[i].data.cost + "小时</br></div>";
- // totalTime += Number(params[i].data.cost);
- // totalCost += Number(params[i].data.money);
- // }
- // }
- // res = res +'<br/>'+ params[0].name+ '<br/>总计: ' + totalTime.toFixed(1)+'小时 '+totalCost.toFixed(2) + "元<br/>";
- // return res;
- // }
- // },
- // xAxis: {
- // data: xList,
- // axisLabel: {
- // interval:0,rotate:20
- // }
- // },
- // yAxis: [{
- // type : 'value',
- // axisLabel: {
- // formatter:this.yAxisValue==0?'{value} (元)':'{value} (小时)'
- // }
- // }],
- // series: series,
- // };
- // myChart.setOption(option,{notMerge:true});
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.listLoading = false;
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- // 共同方法
- gtff(data) {
- var _this = this;
- this.hasReportUserList = data.userList;
- var xList = [] , yList = [] , list = data.list, array = [] , series = [];
- var totalMoneyCost = data.totalCostMoney;
- var totalHours = 0.0;
- if (list.length > 0) {
- var num = list.length==0?0:list[0].project.length;
- for(var i in list) {
- xList.push(list[i].name);
- var pro = list[i].project;
- for(var j in pro) {
- if(array.indexOf(pro[j].project) == -1) {
- array.push(pro[j].project)
- }
- }
- }
- for(var i in array) {
- yList.push(array[i]);
- var dataList = [];
- for(var j in list) {
- var project = list[j].project , num = 0;
- if(project.length != 0) {
- for(var k in project) {
- if(project[k].project == array[i]) {
- dataList.push({
- "value": this.yAxisValue==0?project[k].money:project[k].time,
- "cost": project[k].time,
- "money":project[k].money
- })
- totalHours += parseFloat(project[k].time);
- } else {
- num++;
- }
- if(k == project.length-1 && num != project.length-1) {
- dataList.push({
- "value": 0,
- "cost": 0,
- "money":0,
- })
- }
- }
- } else {
- dataList.push({
- "value": 0,
- "cost": 0,
- "money":0,
- })
- }
- }
- series.push({
- name: array[i],
- type: 'bar',
- stack:'1',
- barMaxWidth: 30,
- data: dataList,
- })
- }
- }
-
-
- var myChart = echarts.init(document.getElementById("container"));
- totalHours = totalHours.toFixed(1);
- // 设置宽度
- myChart.resize({
- width: this.widthHtval
- })
- // 设置宽度
- _this.myChart = myChart;
- var option = {
- //总成本
- title: {
- text: '工时成本总计' + totalMoneyCost.toFixed(2) + '元, 时长'+totalHours+'小时',
- left:'left',
- },
- // 工具箱
- legend: {
- x: 80,
- y: 10,
- data: yList,
- show: true,
- top:"5%",//与上方的距离 可百分比% 可像素px
- },
- grid : {
- top : 80, //距离容器上边界40像素
- // bottom: 100, //距离容器下边界30像素
- bottom: 35, //距离容器下边界30像素
- left: 150,
- right: 150
- },
- toolbox: {
- show: true,
- feature:{
- saveAsImage:{
- show:true
- },
- restore:{
- show:true
- },
- // dataView:{
- // show:true
- // },
- // dataZoom:{
- // show:true
- // },
- magicType:{
- type:['line','bar']
- }
- }
- },
- tooltip:{
- trigger:'axis',
- formatter: function (params,ticket,callback) {
- var totalTime = 0;
- var totalCost = 0;
- var res = "";
- for(var i in params) {
- if (params[i].data.value > 0) {
- res += "<div style='margin-top:3px;font-size:12px;'><font color='#ddd'>项目名称:" + params[i].seriesName
- + "</font><br/>工作成本 : " + params[i].data.money
- + "元 <br/>工作时长"+" : " + params[i].data.cost + "小时</br></div>";
- totalTime += Number(params[i].data.cost);
- totalCost += Number(params[i].data.money);
- }
- }
- res = res +'<br/>'+ params[0].name+ '<br/>总计: ' + totalTime.toFixed(1)+'小时 '+totalCost.toFixed(2) + "元<br/>";
- return res;
- }
- },
- xAxis: {
- data: xList,
- axisLabel: {
- interval:0,rotate:20
- }
- },
- yAxis: [{
- type : 'value',
- axisLabel: {
- formatter:this.yAxisValue==0?'{value} (元)':'{value} (小时)'
- }
- }],
- series: series,
- };
- myChart.setOption(option,{notMerge:true});
- },
- yanjiu() {
- console.log('触发')
- },
- getEchart(){
- var that = this
- // that.timers = setTimeout(()=>{
- // clearTimeout(that.timers)
- // console.log(that.timers)
- that.jieliu()
- // },100);
- // this.jieliu()
- },
- backToParentDept() {
- if (this.radio == '部门') {
- if (this.parentDeptStack.length > 0) {
- this.parentDeptStack.pop();
- if (this.parentDeptStack.length > 0) {
- this.parentDeptId = this.parentDeptStack[this.parentDeptStack.length -1];
- } else {
- this.parentDeptId = null;
- }
- this.jieliu();
- }
- }
- },
- // 脱离出来的方法
- jieliu() {
- sessionStorage.radio = this.radio;
- var _this = this;
- var param = {};
- if (this.dateRange != null) {
- param = {startDate:this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange,
- endDate: this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange};
- console.log(param);
- }
- var url = '';
- if (this.radio=='项目') {
- url = this.port.project.listCost;
- } else if (this.radio=='部门') {
- url = this.port.project.depCost;
- param.parentDeptId = this.parentDeptId;
- } else if (this.radio=='人员') {
- this.getUserCostList();
- return;
- } else if (this.radio == this.namess) {
- url = '/project/getDegreeCost'
- }
- this.http.post(url, param,
- res => {
- if (res.code == "ok") {
- for(var i in res.data.costList) {
- if(i>20) {
- // this.widthHtval = +this.widthHtval + 2
- this.widthHtval = +this.widthHtval + 40
- } else {
- this.widthHtval = document.body.clientWidth - 230
- }
- }
-
- // 测试写的
- var xList = []
- var yList = []
- var list
- var totalMoneyCost;
- var totalHours = 0.0;
- if(this.radio == '项目' || this.radio=='部门') {
- list = res.data.costList
- totalMoneyCost = ((this.radio=='项目')?res.data.totalMoneyCost:res.data.totalCostMoney);
- for(var i in list) {
- if(this.radio=='项目') {
- xList.push(this.radio=='项目'?list[i].project:list[i].name);
- yList.push({
- "value": this.yAxisValue==0?list[i].costMoney.toFixed(2) || list[i].costMoney:list[i].cost.toFixed(1),
- "id": list[i].id || i,
- "cost": list[i].cost,
- "money":list[i].costMoney.toFixed(2)
- });
- totalHours += parseFloat(list[i].cost);
- } else {
- xList.push(list[i].departmentName);
- yList.push({
- "value": this.yAxisValue==0? list[i].costMoney.toFixed(2) || list[i].costMoney: list[i].costTime.toFixed(1),
- "id": list[i].departmentId,
- "cost": list[i].costTime,
- "hasSubDept": list[i].hasSubDept,
- "money":list[i].costMoney.toFixed(2)
- });
- totalHours += parseFloat(list[i].costTime);
- }
- }
- } else {
- list = res.data
- var totalMoneyCost = 0;
- for(var i in list) {
- console.log(list[i].name, list[i].costMoney, list[i].cost)
- xList.push(list[i].name);
- yList.push({
- "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
- "id": list[i].id || i,
- "cost": list[i].cost,
- "money":list[i].costMoney.toFixed(2)
- });
- totalHours += parseFloat(list[i].cost);
- totalMoneyCost += parseFloat(list[i].costMoney);
- }
- }
- totalHours = totalHours.toFixed(1);
-
- var myChart = echarts.init(document.getElementById("container"));
- myChart.resize({
- width: this.widthHtval
- })
- _this.myChart = myChart;
- // console.log(totalMoneyCost.toFixed(2), '看看', totalMoneyCost)
- // var chengbentongji = totalMoneyCost.toFixed(2) || totalMoneyCost
- if(totalMoneyCost) {
- this.zhishin = totalMoneyCost.toFixed(2)
- }
- if(this.radio == '项目' || this.radio == '人员' || this.radio=='部门') {
- var option = {
- title: {
- text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
- left:'left',
- },
- // 工具箱
- toolbox: {
- show: true,
- feature:{
- saveAsImage:{show:true},restore:{show:true}, magicType:{ type:['line','bar']},
- }
- },
- tooltip:{
- trigger:'axis',
- formatter: function (params,ticket,callback) {
- var res = params[0].name + "<br/>工作成本"+" : " + params[0].data.money
- + "元 <br/>工作时长"+" : " + params[0].data.cost + "小时";
- _this.params = params;
- return res;
- }
- },
- xAxis: {
- data: xList,
- axisLabel: {
- interval:0,rotate:20
- }
- },
- yAxis: [{
- type : 'value',
- axisLabel: {
- formatter:this.yAxisValue==0?'{value} (元)':'{value}小时'
- }
- }],
- series: [{
- name: this.yAxisValue==0?'工作成本(元)':'工作时长(小时)',
- type: 'bar',
- barMaxWidth: 30,
- data: yList,
- }]
- };
- } else {
- var option = {
- title: {
- text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
- left:'left',
- },
- // 工具箱
- toolbox: {
- show: true,
- feature:{
- saveAsImage:{show:true},restore:{show:true}, magicType:{ type:['line','bar']},
- }
- },
- tooltip:{
- trigger:'axis',
- formatter: function (params,ticket,callback) {
- var res = params[0].name + "<br/>工作成本"+" : " + params[0].data.money
- + "元 <br/>工作时长"+" : " + params[0].data.cost + "小时";
- _this.params = params;
- return res;
- }
- },
- xAxis: {
- data: xList,
- axisLabel: {
- interval:0,rotate:20
- }
- },
- yAxis: [{
- type : 'value',
- axisLabel: {
- formatter:this.yAxisValue==0?'{value} (元)':'{value}小时'
- }
- }],
- series: [{
- name: this.yAxisValue==0?'工作成本(元)':'工作时长(小时)',
- type: 'bar',
- barMaxWidth: 30,
- data: yList,
- }]
- };
- }
-
- myChart.setOption(option,{notMerge: true});
- myChart.getZr().on('click', params => {
- const pointInPixel = [params.offsetX, params.offsetY];
- if (myChart.containPixel('grid', pointInPixel)) {
- console.log(_this.params)
- if(_this.radio=='项目') {
- if (_this.dateRange != null) {
- if (this.user.timeType.fixMonthcost == 0) {
- _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
- +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
- } else {
- _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
- +"?startDate="+_this.dateRange+"&endDate="+_this.dateRange);
- }
- } else {
- _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
- }
- } else if (_this.radio=='部门') {
- if (_this.params[0].data.hasSubDept) {
- if (_this.parentDeptId != _this.params[0].data.id) {
- _this.parentDeptId = _this.params[0].data.id;
- _this.parentDeptStack.push(_this.parentDeptId);
- _this.jieliu();
- }
- // _this.jieliu();
- } else {
- if (_this.dateRange != null) {
- _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name
- +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
- } else {
- _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name);
- }
- }
- }
- }
- });
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- // 左右滚动
- scrollFunction () {
- this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
- if (this.domObj.attachEvent) { // IE
- this.domObj.attachEvent('onmousewheel', this.mouseScroll)
- } else if (this.domObj.addEventListener) {
- this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
- }
- this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
- },
- mouseScroll(event) { // google 浏览器下
- let detail = event.wheelDelta || event.detail
- let moveForwardStep = -1
- let moveBackStep = 1
- let step = 0
- step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
- event.preventDefault() // 阻止浏览器默认事件
- this.domObj.scrollLeft = this.domObj.scrollLeft + step
- },
- },
- created() {
- },
- mounted() {
- this.containerHeight = window.innerHeight - 200
- // this.containerHeight = window.innerHeight - 130
- const that = this;
- window.onresize = function temp() {
- this.containerHeight = window.innerHeight - 130
- // this.containerHeight = window.innerHeight - 200
- };
- if (this.user.timeType.fixMonthcost == 0) {
- if (this.$route.query.startDate != null) {
- this.dateRange = [this.$route.query.startDate, this.$route.query.endDate];
- } else {
- //默认查看本月
- var now = new Date();
- var t = util.formatDate.format(now, 'yyyy-MM-dd');
- var startStr = util.formatDate.format(new Date(), 'yyyy-MM') + "-01";
- this.dateRange = [startStr,t];
- }
- this.exportParam.dateRange = this.dateRange;
- } else if (this.user.timeType.fixMonthcost == 1) {
- if (this.$route.query.startDate != null) {
- this.dateRange = this.$route.query.startDate;
- } else {
- //默认查看本月
- var startStr = util.formatDate.format(new Date(), 'yyyy-MM');
- this.dateRange = startStr;
- }
- this.exportParam.dateRange = this.dateRange;
- }
- this.radio = '项目'
- this.getEchart();
- var _this = this;
- window.addEventListener("resize", function() {
- _this.myChart.resize();
- });
- // this.getDepartment();
- this.getMyProjectList();
- this.getUsers()
- this.jutishez()
- this.scrollFunction()
- },
- };
- </script>
- <style lang="scss" scoped>
- #container {
- // display: inline-block;
- display: block;
- position: absolute;
- // width: 100% !important;
- margin-top: 60px;
- }
- .ryuans {
- top: -50px;
- }
- .prompt {
- position: absolute;
- right: 10px;
- top: 0;
- }
- </style>
- <style lang="scss">
- </style>
|