mkl_power_box/components/amplify/Company/laowuyonggong/amplify-gzzb.js

471 lines
19 KiB
JavaScript

var vms = Vue.component("Company-amplify-gzzb", {
template: `
<div>
<div class="amplify-title-icon">
<img src="https://fileimg.makalu.cc/WEB_DBD5893450984E50AFF356EF44FF4139.png" @click="openAmplify">
</div>
<transition name="el-zoom-in-top">
<div class="amplify-fixed" v-show="show" style="display: none" @click="closeAmplifyAll">
<div class="amplify-max">
<div class="amplify-title">
<div>工种占比</div>
<div class="amplify-close" @click="closeAmplify"><i class="el-icon-close"></i></div>
</div>
<div class="amplify-content">
<!--内容区域-->
<el-row>
<el-col :span="11" >
<div style="position: relative">
<div :style="{'height': height+'px'}" ref="warningPieChart">
</div>
<div class="amplify-chart-gif chart-work-gif" v-if="typedata.length > 0" style="position: absolute;top: 128px;left: 108px"></div>
</div>
</el-col>
<el-col :span="13" >
<div :style="{'height': height+'px'}" ref="chart"> </div>
</el-col>
</el-row>
</div>
</div>
</div>
</transition>
</div>
`,
props: {
},
data() {
return {
show:false,
typedata:[],
active:0,
option:{},
height:460,
width:280
}
},
mounted(){
},
methods: {
openAmplify(){
this.show = true
this.getGZData() //工种占比
},
closeAmplify(){
this.show = false
},
closeAmplifyAll(e){
if(e.target.className == 'amplify-fixed'){
this.show = false
}
},
//工种占比
getGZData(){
axios.post("https://smz.makalu.cc/mkl/screenApi/getWorkTypeData?token=00e650bb50854f54b146e83f73500ca8&deptId=123&typtDeptId="+JSON.parse(localStorage.getItem("data")).dept_id, {
}).then(res => {
var workPropData = [];
var data = res.data.workTypeData;
for (let i = 0; i < data.length; i++) {
workPropData.push({text:data[i].name,value:data[i].value,prop: data[i].percent})
}
this.typedata = workPropData;
this.getChartData()
this.getChartData1()
this
}).catch(err => {
})
},
// 左边饼图展示
getChartData(){
//品类金额占比 饼图
var chChartPie = echarts.init(this.$refs.warningPieChart);
this.echartPie(chChartPie,this.typedata)
},
echartPie(chChart,chartData){
let newPromise = new Promise((resolve) => {
resolve()
})
//然后异步执行echarts的初始化函数
newPromise.then(() => {
var total_datas = 0;
var data = [];
var legendData = [];
var color = ['#4974ff','#52aef7','#6863d7','#1d5d89','#20e6ff','#67feef']
for (let i = 0; i <chartData.length ; i++) {
total_datas += Number(chartData[i].value);
legendData.push(chartData[i].text)
data.push(
{
value: chartData[i].value,
name: chartData[i].text,
itemStyle: {
normal: {
//颜色渐变
color: color[i]
},
},
},
)
}
/* let total = chartData.reduce((a, b) => {
return a + b.value;
}, 0);*/
this.option = {
title: {
text: total_datas,
subtext: "总人数",
x: "center",
y: "193",
textStyle: {
color: "#0dd2fd",
fontSize: 36,
fontWeight: "normal",
align: "center",
width: "200px",
},
subtextStyle: {
color: "#a5b5f0",
fontSize: 18,
fontWeight: "normal",
align: "center",
},
},
tooltip: {
trigger: 'item',
formatter: "{b} <br/>{c} ({d}%)"
},
series: [
{
name: "品类金额占比",
type: "pie",
center: ["50%", "50%"],
radius: ["53%", "70%"],
data: data,
label: {
show: false,
},
itemStyle: {
normal: {
borderWidth: 5,
borderColor: "#051a36"
}
},
},
{
name: "外边框",
type: "pie",
clockWise: false, //顺时加载
hoverAnimation: false, //鼠标移入变大
center: ["50%", "50%"],
radius: ["78%", "78%"],
label: {
normal: {
show: false,
},
},
data: [
{
value: 9,
name: "",
itemStyle: {
normal: {
borderWidth: 3,
borderColor: "#152c65",
},
},
},
],
},
],
}
chChart.setOption(this.option);
window.onresize = chChart.resize;
})
},
// 右边echarts
//分类及工时情况
getChartData1(){
var chChartBar = echarts.init(this.$refs.chart);
this.echartBar(chChartBar,this.typedata)
},
echartBar(chChart,chartData){
var that = this
let newPromise = new Promise((resolve) => {
resolve()
})
//然后异步执行echarts的初始化函数
newPromise.then(() => {
var value = [];
var prop = [];
var text = [];
var zero = []
var total = 0
for (let i = chartData.length-1; i >=0; i--) {
total += chartData[i].value;
value.push(chartData[i].value)
prop.push(chartData[i].prop.toFixed(2))
text.push(chartData[i].text)
zero.push(0)
}
var data = []
var data_all = new Array(prop.length)
for (let i = 0; i <prop.length ; i++) {
let tmp = new Array(prop.length).fill(0)
tmp[i] = prop[i]
data.push(tmp)
let tmp_all = 0
for(let j = i;j<prop.length;j++){
tmp_all+= prop[j];
}
data_all[i] = tmp_all;
}
data_all.splice(0,1)
data_all.push(0)
var color = ['#4974ff','#52aef7','#6863d7','#1d5d89','#20e6ff','#67feef']
var series =[
//背景色--------------------我是分割线君------------------------------//
{
show: true,
type: 'bar',
barGap: '-100%',
barWidth: '6', //统计条宽度
itemStyle: {
normal: {
color: 'rgba(27, 61, 133,0.5)',
},
},
z: 1,
data: [100, 100, 100, 100, 100, 100]
},
//数据条--------------------我是分割线君------------------------------//
{
show: true,
type: 'bar',
xAxisIndex: 1, //代表使用第二个X轴刻度!!!!!!!!!!!!!!!!!!!!!!!!
barGap: '-100%',
barWidth: '6', //统计条宽度
itemStyle: {
normal: {
color: 'rgba(22,203,115,0.05)'
},
},
label: {
normal: {
show: true,
//label 的position位置可以是top bottom left,right,也可以是固定值
//在这里需要上下统一对齐,所以用固定值
position: [0, '-25'],
rich: { //富文本
prop: { //自定义颜色
color: '#c6d9fa',
fontSize:'14',
},
value: { //自定义颜色
color: '#6cbbfe',
fontSize:'14',
},
index:{
color: '#fcbc02',
fontStyle: 'italic',
padding:[0,0,0,5],
fontSize:'14',
},
name: {
width: this.width,
color: '#c6d9fa',
padding:[0,0,0,10],
fontSize:'12',
},
color:{
color: '#8ca2be',
fontSize:'12',
},
arrow1:{
width:10,
height:10,
backgroundColor: '#4974ff',
borderRadius:50
},
arrow2:{
width:10,
height:10,
backgroundColor: '#52aef7',
borderRadius:50
},
arrow3:{
width:10,
height:10,
backgroundColor: '#6863d7',
borderRadius:50
},
arrow4:{
width:10,
height:10,
backgroundColor: '#1d5d89',
borderRadius:50
},
arrow5:{
width:10,
height:10,
backgroundColor: '#20e6ff',
borderRadius:50
},
arrow6:{
width:10,
height:10,
backgroundColor: '#67feef',
borderRadius:50
},
},
formatter: function(data) {
//富文本固定格式{colorName|这里填你想要写的内容}
if (data.dataIndex == 5) {
return '{arrow1|}{name|' + text[data.dataIndex] + '}{value|' + value[data.dataIndex] + '}{color| 人} {prop|' + prop[data.dataIndex] + '} {color| %}';
}else if(data.dataIndex == 4){
return '{arrow2|}{name|' + text[data.dataIndex] + '}{value|' + value[data.dataIndex] + '}{color| 人} {prop|' + prop[data.dataIndex] + '} {color| %}';
}else if(data.dataIndex == 3){
return '{arrow3|}{name|' + text[data.dataIndex] + '}{value|' + value[data.dataIndex] + '}{color| 人} {prop|' + prop[data.dataIndex] + '} {color| %}';
}else if(data.dataIndex == 2){
return '{arrow4|}{name|' + text[data.dataIndex] + '}{value|' + value[data.dataIndex] + '}{color| 人} {prop|' + prop[data.dataIndex] + '} {color| %}';
}else if(data.dataIndex == 1){
return '{arrow5|}{name|' + text[data.dataIndex] + '}{value|' + value[data.dataIndex] + '}{color| 人} {prop|' + prop[data.dataIndex] + '} {color| %}';
}else if(data.dataIndex == 0){
return '{arrow6|}{name|' + text[data.dataIndex] + '}{value|' + value[data.dataIndex] + '}{color| 人} {prop|' + prop[data.dataIndex] + '} {color| %}';
}
},
}
},
data: value
},
{
type: "bar",
stack: "总",
barWidth: 6,
itemStyle: {
normal: {
barBorderColor: 'rgba(0,0,0,0)',
color: 'rgba(0,0,0,0)'
}
},
data: data_all
},
]
for (let i = 0; i < data.length; i++) {
series.push({
type: "bar",
barWidth: 6,
stack: "总",
itemStyle: {
normal: {
color: color[data.length-1-i]
}
},
/*itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
{
offset: 0,
color: "#41adf5",
},
{
offset: 1,
color: "#175eac",
},
]),
barBorderRadius: [5,5,5,5],
},
},*/
data: data[i]
})
}
this.option = {
grid: {
left: '2%',
right: '10%',
bottom: '-8%',
top: '3%',
containLabel: true
},
yAxis: {
type: 'category',
axisLabel: {
show: false, //让Y轴数据不显示
},
itemStyle: {
},
axisTick: {
show: false, //隐藏Y轴刻度
},
axisLine: {
show: false, //隐藏Y轴线段
},
data: text,
},
xAxis: [{
show: false,
},
//由于下边X轴已经是百分比刻度了,所以需要在顶部加一个X轴,刻度是金额,也隐藏掉
{
show: false,
}
],
series: series
};
chChart.setOption(this.option);
window.onresize = chChart.resize;
chChart.off('click')
chChart.on('click', function (params) {
for(let i= 0;i<chartData.length;i++){
if(params.name == chartData[i].text){
that.$emit('personnel',chartData[i]);
break
}
}
})
})
},
},
watch:{
},
})