12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307 |
- <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" size="small">
- <el-radio-button label="0" v-if="permissions.countCost">显示成本</el-radio-button>
- <el-radio-button label="1" v-if="permissions.countHours">显示工时</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" size="small"
- 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" size="small"
- 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;" size="small">
- <el-radio-button label="项目"></el-radio-button>
- <el-radio-button label="主项目" v-if="user.timeType.mainProjectState"></el-radio-button>
- <el-radio-button label="项目分类"></el-radio-button>
- <el-radio-button label="部门"></el-radio-button>
- <el-radio-button label="人员" v-if="permissions.countPersonnel"></el-radio-button>
- <el-radio-button :label="namess" v-if="jichu.customDegreeActive == 1"></el-radio-button>
- <el-radio-button v-for="item in theCustomList" :key="item.id" :label="item.name"></el-radio-button>
- </el-radio-group>
- <!--
- <el-select v-model="customName" filterable placeholder="请选择" style="margin-top: 10px;width: 350px" v-if="theCustomListFlg" @change="jieliu()">
- <el-option v-for="item in customList" :key="item.id" :label="item.name" :value="item.name"></el-option>
- </el-select> -->
- <el-select v-model="personnelValue" filterable clearable placeholder="请选择人员" size="small" 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="exportProjectData" v-if="theCustomListFlg" size="small">报表导出</el-button>
- <el-button @click="showExportDialog" v-else size="small">报表导出</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 != '人员' && radio != '项目分类'">
- <el-select v-model="exportParam.projectId" placeholder="全部项目" clearable style="width:350px;" filterable="true" popper-class="projectSelectPopperClass">
- <el-option v-for="item in projectList" :key="item.id" :label="item.projectName + item.projectCode" :value="item.id">
- <span style="float: left;color: #8492a6;">{{ item.projectCode }}</span>
- <span style="float: right;font-size: 13px;">{{ item.projectName }}</span>
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="部门选择" v-if="radio == '项目'">
- <el-cascader v-model="exportParam.deptId" :options="departmentList" placeholder="请选择部门"
- :props="{ checkStrictly: true, expandTrigger: 'hover' }" clearable filterable style="width:350px;"
- ></el-cascader>
- </el-form-item>
- <el-form-item prop="projectCategoryId" label="项目分类" v-if="radio == '项目分类'">
- <el-select v-model="exportParam.projectCategoryId" placeholder="全部项目分类" clearable style="width:350px;" filterable="true">
- <el-option v-for="item in categoryList" :key="item.id" :label="item.name" :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 == '部门' || 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 == '部门' || radio == '项目分类'">
- <el-select v-model="exportParam.type" placeholder="选择样式" style="width:350px;" >
- <el-option :label="radio == '项目分类' ? '项目分类在行上' : '项目在行上'" value="0"></el-option>
- <el-option :label="radio == '项目分类' ? '项目分类在列上' : '项目在列上'" value="1"></el-option>
- </el-select>
- <div class="prompt">
- <el-popover placement="top" width="1200" trigger="hover">
- <img src="../../assets/image/hanglie.png" alt="" width="100%" v-if="this.radio != '项目分类'">
- <img src="../../assets/image/hanglie_corp.png" alt="" width="100%" v-else>
- <i class="el-icon-question" slot="reference" />
- </el-popover>
- </div>
- </el-form-item>
- <el-form-item v-if="(radio == '项目' || radio == '部门' || radio == '项目分类') && exportParam.type == '0'">
- <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:[],
- categoryList: [],
- exportParam:{projectId:null,dateRange:[],userId: null,type: '0'},
- exportDialog:false,
- dateRange:[],
- user: JSON.parse(sessionStorage.getItem("user")),
- permissions: JSON.parse(sessionStorage.getItem("permissions")),
- radio: sessionStorage.radio!=null?sessionStorage.radio:'项目',
- containerHeight: 0,
- // myChart: null,
- params: null,
- widthHtval: document.body.clientWidth - 230,
- users: [],
- jichu: [],
- namess: '',
- timers: null, // 点击的时间
- zhishin: 0,
- theCustomList: [], // 自定义数据来源
- theCustomListFlg: false, // 判断是否点击的是自定义配置的数据来源
- theCustomListId: '',
- theCustomListPlantLIst: [],
- theCustomListPlant: '',
- customId: '',
- customName: '',
- customList: [],
- departmentList: []
- };
- },
- 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
- // pageSize: -1
- // },
- this.http.post('/user/getSimpleActiveUserList', {},
- res => {
- if (res.code == "ok") {
- this.users = res.data;
- } 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 = [];
- }
- if (this.radio == '项目') {
- this.exportParam.deptId = []
- }
- },
- //获取我的项目列表
- 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 = {stateKey: 1};
- if (this.exportParam.dateRange != null) {
- param = {startDate:this.exportParam.dateRange[0], endDate: this.exportParam.dateRange[1],stateKey: 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.radio == '项目分类'){
- fileName = '项目分类工时成本统计.xls';
- url = '/project/exportTimeCostByCategory'
- if(this.exportParam.projectCategoryId){
- param.projectCategoryId = this.exportParam.projectCategoryId
- }
- }
- if(this.radio == '部门'){
- fileName = '部门工时成本统计.xls'
- url = '/department/exportDeptStatistic'
- }
-
- if (this.exportParam.projectId && this.radio != '人员' && this.radio != '项目分类') {
- param.projectId = this.exportParam.projectId;
- }
- if (this.exportParam.userId) {
- if(this.radio == '项目' || this.radio == '部门' || this.radio == '人员' || this.radio == '项目分类'){
- param.userId = this.exportParam.userId;
- }
- }
- if (this.exportParam.type == 1) {
- this.exportParam.projectSum = null
- }
- if (this.exportParam.projectSum != null) {
- if(this.radio == '项目' || this.radio == '部门' || this.radio == '项目分类'){
- param.projectSum = this.exportParam.projectSum;
- }
- }
- if(!this.theCustomListFlg) {
- param.type = this.exportParam.type*1
- }
- if(this.theCustomListFlg) {
- url = '/project/exportTimeCostByUserCustom'
- fileName = this.radio + '统计.xls'
- // param.subCustomName = this.customName
- param.customId = this.theCustomListId
- param.fieldName = this.theCustomListPlant
- }
- if(this.exportParam.deptId) {
- if(this.exportParam.deptId.length > 0) {
- param.deptId = this.exportParam.deptId[this.exportParam.deptId.length - 1]
- }
- }
- 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, '获取人员成本统计列表')
- console.log(this.user.timeType.fixMonthcost)
- console.log(Boolean(this.dateRange))
- let startDateNum = ''
- let endDateNum = ''
- if(this.dateRange) {
- startDateNum = this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange
- endDateNum = this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange
- }
- // return
- 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
- startDate: startDateNum,
- endDate: endDateNum
- },
- 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]) {
- let item = {
- "value": this.yAxisValue==0?project[k].money:project[k].time,
- }
- if(this.permissions.countCost){
- item.money = project[k].money
- }
- if(this.permissions.countHours){
- item.cost = project[k].time
- totalHours += parseFloat(project[k].time);
- }
- dataList.push(item)
-
- } 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+'小时',
- text: '工时成本总计:' +
- ((this.permissions.countCost) ? '成本' + totalMoneyCost.toFixed(2) + '元,' : '') +
- ((this.permissions.countHours) ? '时长' + 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/>" +
- ((_this.permissions.countCost) ? "工作成本 : " + params[i].data.money + "元<br/>" : '') +
- ((_this.permissions.countHours) ? "工作时长 : " + 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/>总计: ' +
- ((_this.permissions.countHours) ? totalTime.toFixed(1) + '小时 ' : '') +
- ((_this.permissions.countCost) ? 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(e){
- var that = this
- // 更具选中的名字筛选出对应的自定义id
- that.theCustomListFlg = false
- let ints = null
- for(var i in that.theCustomList) {
- if(that.radio == that.theCustomList[i].name) {
- that.theCustomListId = that.theCustomList[i].id
- that.theCustomListPlant = that.theCustomListPlantLIst[i]
- that.theCustomListFlg = true
- ints = i
- }
- }
- if(that.theCustomListFlg) {
- that.customList = that.theCustomList[ints].subUserCustomList
- that.customName = that.theCustomList[ints].subUserCustomList[0].name
- // that.getCusTom()
- }
- that.jieliu()
- },
- getCusTom() {
- this.http.post('/sub-user-custom/list',{
- userCustomId: this.theCustomListId
- },res => {
- if(res.code == 'ok'){
- this.customList = res.data
- this.customName = res.data[0].name
- }else {
- this.$message({
- message: res.msg,
- type: 'error'
- })
- }
- },error => {
- this.$message({
- message: error,
- type: 'error'
- })
- })
- },
- getCategoryList(){
- this.http.post('/project-category/list',{},
- res => {
- if(res.code == 'ok'){
- this.categoryList = res.data
- }else {
- this.$message({
- message: res.msg,
- type: 'error'
- })
- }
- },err => {
- this.$message({
- message: err,
- type: 'error'
- })
- })
- },
- 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 = '/project/getTimeCostByMainProject'
- // param.userId = this.user.id
- }else if (this.radio=='项目分类') {
- url = '/project/getTimeCostByCategory';
- // param.parentDeptId = this.parentDeptId;
- // param.userId = this.user.id
- } 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'
- } else if (this.theCustomListFlg) {
- url = '/project/getTimeCostByUserCustom'
- // param.subCustomName = this.customName
- param.customId = this.theCustomListId
- param.fieldName = this.theCustomListPlant
- console.log(param, '要传的数据')
- }
- this.http.post(url, param,
- res => {
- if (res.code == "ok") {
- // 更具数据的长度去加每个柱子的间距
- for(var i in res.data.costList) {
- if(i>20) {
- this.widthHtval = +this.widthHtval + 40
- } else {
- this.widthHtval = document.body.clientWidth - 230
- }
- }
- // console.log(this.dayjs().add('0','day').format("YYYY-MM-DD HH:mm:ss"), '结束处理')
- // if(res.data.costList.length > 20) {
- // for(var i in res.data.costList) {
- // 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 == '项目分类' || this.radio=='部门' || this.radio == '主项目') {
- list = res.data.costList
- totalMoneyCost = ((this.radio=='项目' || this.radio == '项目分类')?res.data.totalMoneyCost:res.data.totalCostMoney);
- for(var i in list) {
- if(this.radio=='项目' || this.radio == '主项目') {
- if(this.radio == '项目'){
- xList.push(list[i].project);
- }else{
- xList.push(list[i].mainProjectName);
- }
-
- let item = {
- "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),
- "id": list[i].id || i,
- }
- if(this.permissions.countCost){
- // item.money = list[i].costMoney.toFixed(2)
- item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
- }
- if(this.permissions.countHours){
- item.cost = list[i].cost
- totalHours += parseFloat(list[i].cost);
- }
- yList.push(item);
-
- } else if(this.radio == '部门'){
- xList.push(list[i].departmentName);
- let item = {
- // "value": this.yAxisValue==0 ? list[i].costMoney.toFixed(2) || list[i].costMoney: list[i].costTime.toFixed(1),
- "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),
- "id": list[i].departmentId,
- "hasSubDept": list[i].hasSubDept
- }
- if(this.permissions.countCost){
- // item.money = list[i].costMoney.toFixed(2)
- item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
- }
- if(this.permissions.countHours){
- item.cost = list[i].costTime
- totalHours += parseFloat(list[i].costTime);
- }
- yList.push(item);
-
- }else {
- xList.push(list[i].categoryName);
- let item = {
- // "value": this.yAxisValue==0?list[i].costMoney.toFixed(2) || list[i].costMoney:list[i].cost.toFixed(1),
- "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),
- "id": list[i].id || i,
- }
- if(this.permissions.countCost){
- // item.money = list[i].costMoney.toFixed(2)
- item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
- }
- if(this.permissions.countHours){
- item.cost = list[i].cost
- totalHours += parseFloat(list[i].cost);
- }
- yList.push(item);
- }
- }
- }
- else if(this.theCustomListFlg) {
- list = res.data.list
-
- for(var i in list) {
- // console.log(list[i].name, list[i].costMoney, list[i].cost)
- xList.push(list[i].name);
- let item = {
- "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
- "id": list[i].id || i,
- }
- if(this.permissions.countCost){
- // item.money = list[i].costMoney.toFixed(2)
- item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
- totalMoneyCost += parseFloat(list[i].costMoney);
- }
- if(this.permissions.countHours){
- item.cost = list[i].cost
- totalHours += parseFloat(list[i].cost);
- }
- yList.push(item);
-
- }
- }
- else {
- list = res.data
-
- for(var i in list) {
- // console.log(list[i].name, list[i].costMoney, list[i].cost)
- xList.push(list[i].name);
- let item = {
- "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
- "id": list[i].id || i,
- }
- if(this.permissions.countCost){
- // item.money = list[i].costMoney.toFixed(2)
- item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
- totalMoneyCost += parseFloat(list[i].costMoney);
- }
- if(this.permissions.countHours){
- item.cost = list[i].cost
- totalHours += parseFloat(list[i].cost);
- }
- yList.push(item);
-
- }
- }
- 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 == '人员' || this.radio == '项目分类' || this.radio=='部门') {
- var option = {
- title: {
- text: '工时成本总计:' + ((this.permissions.countCost) ? '成本' + this.zhishin + '元,' : '') + ((this.permissions.countHours) ? '时长' + 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;
- var res = params[0].name + "<br/>" +
- ((_this.permissions.countCost) ? "工作成本"+" : " + params[0].data.money
- + "元 <br/>" : '') +
- ((_this.permissions.countHours) ? "工作时长"+" : " + params[0].data.cost + "小时" : '');
- 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,
- }],
- grid: {
- left: '100px',
- }
- };
- } else {
- var option = {
- title: {
- // text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
- text: '工时成本总计:' + ((this.permissions.countCost) ? '成本' + this.zhishin + '元,' : '') + ((this.permissions.countHours) ? '时长' + 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/>" +
- ((_this.permissions.countCost) ? "工作成本"+" : " + params[0].data.money
- + "元 <br/>" : '') +
- ((_this.permissions.countHours) ? "工作时长"+" : " + 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,
- }],
- grid: {
- left: '100px',
- }
- };
- }
-
- 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
- },
- // 判断后端给的字段
- // 获取自定义
- getZDY() {
- this.http.post('/user-custom/getUserCustomTitle',{},res => {
- if(res.code == 'ok'){
- console.log(res, '数据来源')
- this.theCustomList = res.data.result
- this.theCustomListPlantLIst = res.data.field
- }else {
- this.$message({
- message: res.msg,
- type: 'error'
- })
- }
- },error => {
- this.$message({
- message: error,
- type: 'error'
- })
- })
- },
- // 获取部门
- getDepartmentList() {
- this.http.post( this.port.manage.depList, {},
- res => {
- if (res.code == "ok") {
- let dptlist = JSON.parse(JSON.stringify(res.data));
- this.departmentList = this.changeArr(dptlist);
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },error => {
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- changeArr(arr) {
- for (var i = 0; i < arr.length; i++) {
- if(arr[i].id != -1 && arr[i].id != 0) {
- if (arr[i].children != null && arr[i].children.length>0) {
- arr[i].children = this.changeArr(arr[i].children);
- }
- arr[i].id && (arr[i].value = arr[i].id);
- delete arr[i].id;
- }
- }
- for(var i in arr) {
- if(arr[i].id == -1 || arr[i].id == 0) {
- arr.splice(i,1)
- }
- }
- return arr;
- },
- },
- created() {
- this.myChart = null
- },
- 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.permissions.countCost){
- this.yAxisValue = '0'
- }else{
- this.yAxisValue = '1'
- }
- 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()
- // 判断
- if(this.user.timeType.userCustomStatic) {
- this.getZDY()
- }
- this.getDepartmentList()
- },
- beforeDestroy () {
- var myChart = echarts.init(document.getElementById("container"));
- myChart.clear()
- },
- };
- </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>
|