yudao-init/src/views/copilot/efficiency/components/sub/chip/ChipRateItem.vue

366 lines
12 KiB
Vue
Raw Normal View History

2024-05-07 13:51:11 +08:00
<!--
2024-04-29 16:00:07 +08:00
filename: ChipRateItem.vue
author: liubin
date: 2024-04-29 14:25:18
2024-05-07 13:51:11 +08:00
description:
2024-04-29 16:00:07 +08:00
-->
<template>
<div class="chip-rate-item">
<div class="cities">
<CopilotButtons :options="cities" @update:active="handleCityUpdate" />
</div>
2024-05-10 11:10:42 +08:00
<!-- <div style="flex:1;padding: 0 20%;"> -->
2024-05-20 10:20:37 +08:00
<div class="chart" ref="chart"></div>
2024-05-10 11:10:42 +08:00
<!-- </div> -->
2024-06-07 11:13:59 +08:00
<div class="legend">
2024-04-30 16:22:15 +08:00
<div class="legend-item" v-for="lgd in legend" :key="lgd.label">
<span class="legend-item__label">{{ lgd.label }}</span>
2024-06-07 11:13:59 +08:00
<span class="legend-item__value">{{ lgd.value }}</span>
2024-04-29 16:00:07 +08:00
</div>
</div>
</div>
</template>
<script>
import CopilotButtons from "@/views/copilot/components/select.vue";
import chartMixin from "@/mixins/chart.js";
import fullscreenMixin from "@/mixins/fullscreen.js";
import getOptions from "../../../options/chipOptions.js";
2024-04-30 16:22:15 +08:00
import { mapGetters } from "vuex";
2024-04-29 16:00:07 +08:00
export default {
name: "ChipRateItem",
components: { CopilotButtons },
mixins: [chartMixin, fullscreenMixin],
props: {
cities: {
type: Array,
default: () => [],
},
color: {
type: Number,
default: 1,
},
2024-04-30 16:22:15 +08:00
period: {
type: String,
default: "日",
},
2024-05-29 17:05:55 +08:00
than: {
type: String,
default: '同比',
}
2024-04-29 16:00:07 +08:00
},
data() {
return {
2024-04-30 16:22:15 +08:00
factoryId: 0,
count: 1,
2024-04-29 16:00:07 +08:00
};
},
computed: {
2024-04-30 16:22:15 +08:00
chipRate() {
return this.$store.getters.copilot.efficiency.chipRate;
},
valueTuple() {
const getter = this.chipRate;
2024-05-11 16:40:29 +08:00
// console.log(getter)
2024-04-30 16:22:15 +08:00
if (this.period === "日" || this.period === "周") {
return [
getter.previous[this.factoryId],
getter.current[this.factoryId],
0,
];
}
// [100, 200, 200]
return [
getter.previous[this.factoryId],
getter.current[this.factoryId],
getter.target[this.factoryId],
];
},
2024-04-29 16:00:07 +08:00
options() {
2024-06-03 08:23:40 +08:00
// const single = this.period === "日" || this.period === "周";
const today = new Date().getDate();
2024-04-29 16:00:07 +08:00
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
const vt = this.valueTuple;
2024-06-03 08:23:40 +08:00
let items = [];
var day1 = new Date();
day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000);
var yesterday = (day1.getMonth() + 1) + "月" + day1.getDate()
//今天的时间
// var day2 = new Date();
// day2.setTime(day2.getTime());
// var s2 = (day2.getMonth() + 1) + "月" + day2.getDate() + '日';
// const today = new Date().getDate();
// let yesterday = new Date().getDate() -1;
// const month = new Date().getMonth() + 1;
const lastMonth = new Date().getMonth() + 1 === 12 ? 1 : new Date().getMonth() + 1 - 1;
// const year = new Date().getFullYear();
if (this.period === '日' && this.than === '同比') {
items = [
{ label: `${month}${today}日良率`, },
2024-06-07 11:13:59 +08:00
{ label: `${year-1}${month}${today}日良率` },
2024-06-03 08:23:40 +08:00
];
} else if (this.period === '日' && this.than === '环比') {
items = [
{ label: `${month}${today}日良率` },
{ label: `${yesterday}日良率` },
];
} else if (this.period === '周' && this.than === '同比') {
items = [
{ label: `本周良率`, },
2024-06-07 11:13:59 +08:00
{ label: `${year-1}年本周良率` },
2024-06-03 08:23:40 +08:00
];
} else if (this.period === '周' && this.than === '环比') {
items = [
{ label: `本周良率`, },
{ label: `上周良率`, },
];
} else if (this.period === '月' && this.than === '同比') {
items = [
{ label: `${month}月良率`, },
2024-06-07 11:13:59 +08:00
{ label: `${year-1}${month}月良率`, },
2024-06-03 08:23:40 +08:00
{ label: `${month}月目标良率`, },
];
} else if (this.period === '月' && this.than === '环比') {
items = [
{ label: `${month}月良率`, },
{ label: `${lastMonth}月良率`, },
{ label: `${month}月目标良率`, },
];
} else {
items = [
{ label: `${year}年良率`, },
{ label: `${year - 1}年良率` },
{ label: `${year}年目标良率` },
];
}
let titleValue = vt[1] === null ? 0 + '%' : this.formatNumber(vt[1]) + '%',
2024-04-30 16:22:15 +08:00
subtitle = {
: "本日良率",
: "本周良率",
: `${month}月良率`,
: `${year}良率`,
}[this.period];
2024-06-07 11:13:59 +08:00
console.log(vt[1]);
2024-04-30 16:22:15 +08:00
const t = getOptions({
2024-06-03 08:23:40 +08:00
// single,
2024-04-29 16:00:07 +08:00
color: this.color == 1 ? "#4CF0E8" : "#1065ff",
titleValue,
subtitle,
2024-06-03 08:23:40 +08:00
currentName: items[0].label,
preName: items[1].label,
2024-04-30 16:22:15 +08:00
previousSum: vt[0],
currentSum: vt[1],
targetSum: vt[2],
2024-04-29 16:00:07 +08:00
});
2024-04-30 16:22:15 +08:00
return t;
},
legend() {
2024-05-29 17:05:55 +08:00
let items = [];
var day1 = new Date();
day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000);
var yesterday = (day1.getMonth() + 1) + "月" + day1.getDate()
//今天的时间
// var day2 = new Date();
// day2.setTime(day2.getTime());
// var s2 = (day2.getMonth() + 1) + "月" + day2.getDate() + '日';
const today = new Date().getDate();
// let yesterday = new Date().getDate() -1;
2024-04-30 16:22:15 +08:00
const month = new Date().getMonth() + 1;
2024-05-29 17:05:55 +08:00
const lastMonth = new Date().getMonth() + 1 === 12 ? 1 : new Date().getMonth() + 1 - 1;
const year = new Date().getFullYear();
if (this.period === '日' && this.than === '同比') {
items = [
2024-06-07 11:13:59 +08:00
{ label: `${year-1}${month}${today}日良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[0]) ) + "%" },
2024-06-03 08:23:40 +08:00
{ label: `${month}${today}日良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[1])) + "%" },
2024-05-29 17:05:55 +08:00
];
} else if (this.period === '日' && this.than === '环比') {
items = [
2024-06-03 08:23:40 +08:00
{ label: `${yesterday}日良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[0])) + "%" },
{ label: `${month}${today}日良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[1])) + "%" },
2024-05-29 17:05:55 +08:00
];
} else if (this.period === '周' && this.than === '同比') {
items = [
2024-06-07 11:13:59 +08:00
{ label: `${year-1}年本周良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[0])) + "%" },
2024-06-03 08:23:40 +08:00
{ label: `本周良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[1])) + "%" },
2024-05-29 17:05:55 +08:00
];
} else if (this.period === '周' && this.than === '环比') {
items = [
2024-06-03 08:23:40 +08:00
{ label: `上周良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[0])) + "%" },
{ label: `本周良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[1])) + "%" },
2024-05-29 17:05:55 +08:00
];
} else if (this.period === '月' && this.than === '同比') {
items = [
2024-06-07 11:13:59 +08:00
{ label: `${year-1}${month}月良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[0])) + "%" },
2024-06-03 08:23:40 +08:00
{ label: `${month}月良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[1])) + "%" },
2024-06-07 11:13:59 +08:00
{ label: `${month}月目标`, value: isNaN(this.valueTuple[2]) || this.valueTuple[2] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[2])) + "%" },
2024-05-29 17:05:55 +08:00
];
} else if (this.period === '月' && this.than === '环比') {
items = [
2024-06-03 08:23:40 +08:00
{ label: `${lastMonth}月良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[0])) + "%" },
{ label: `${month}月良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[1])) + "%" },
2024-06-07 11:13:59 +08:00
{ label: `${month}月目标`, value: isNaN(this.valueTuple[2]) || this.valueTuple[2] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[2])) + "%" },
2024-05-29 17:05:55 +08:00
];
} else {
items = [
2024-06-07 11:13:59 +08:00
{ label: `${year - 1}年良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[0])) + "%" },
2024-06-03 08:23:40 +08:00
{ label: `${year}年良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[1])) + "%" },
2024-06-07 11:13:59 +08:00
{ label: `${year}年目标`, value: isNaN(this.valueTuple[2]) || this.valueTuple[2] == null ? 0 + "%" : (this.formatNumber(this.valueTuple[2])) + "%" },
2024-05-29 17:05:55 +08:00
];
}
return items
// [
// {
// label:
// this.period == "月"
// ? `${year - 1}年${month}月良率`
// : `${year - 1}年良率`,
// value: isNaN((this.valueTuple[0] * 100).toFixed(0)) ? 0 + "%" : (this.valueTuple[0] * 100).toFixed(0) + "%"
// },
// {
// label: this.period == "月" ? `${month}月良率` : `${year}年良率`,
// value: isNaN((this.valueTuple[1] * 100).toFixed(0)) ? 0 + "%" : (this.valueTuple[1] * 100).toFixed(0) + "%"
// },
// ];
2024-04-29 16:00:07 +08:00
},
},
mounted() {
this.initOptions(this.options);
},
2024-04-30 16:22:15 +08:00
watch: {
period() {
2024-05-10 11:10:42 +08:00
console.log(this.$store.getters.copilot.efficiency)
2024-04-30 16:22:15 +08:00
this.initOptions(this.options);
},
factoryId() {
this.initOptions(this.options);
},
chipRate() {
this.initOptions(this.options);
},
},
2024-04-29 16:00:07 +08:00
methods: {
2024-06-03 08:23:40 +08:00
formatNumber(num) {
2024-06-07 11:13:59 +08:00
console.log(num);
2024-06-03 08:23:40 +08:00
// 判断是否为整数
if (Number.isInteger(num)) {
return num; // 如果是整数,直接转换为字符串
} else {
// 如果不是整数,保留两位小数并转换为字符串
return num.toFixed(2);
}
},
2024-04-30 16:22:15 +08:00
handleCityUpdate(id) {
this.factoryId = id;
2024-04-29 16:00:07 +08:00
},
2024-04-30 16:22:15 +08:00
fullscreenCallback(isFullscreen) {},
2024-04-29 16:00:07 +08:00
},
};
</script>
<style scoped lang="scss">
2024-05-20 10:20:37 +08:00
.chip-rate-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
2024-06-07 11:13:59 +08:00
// padding: 0 3px;
2024-06-03 16:42:28 +08:00
// justify-content: center;
2024-05-20 10:20:37 +08:00
gap: 3px;
backdrop-filter: blur(24px);
2024-04-29 16:00:07 +08:00
.cities {
height: 40px;
}
2024-05-20 10:20:37 +08:00
.chart {
// margin-left: 5%;
// width: 290px;
2024-06-03 08:23:40 +08:00
flex: 1 1 auto;
2024-06-07 11:13:59 +08:00
padding: 0 20%;
2024-05-20 10:20:37 +08:00
/* margin: 10%; */
2024-06-03 16:42:28 +08:00
height: 16vh;
2024-05-20 10:20:37 +08:00
/* min-width: 300px; */
2024-06-03 08:23:40 +08:00
align-self: stretch;
2024-05-20 10:20:37 +08:00
}
2024-04-29 16:00:07 +08:00
.legend {
height: 80px;
display: flex;
2024-06-07 11:13:59 +08:00
color: #fff;
justify-content: flex-end;
gap:20px;
// justify-content: space-between;
2024-04-29 16:00:07 +08:00
}
2024-06-07 11:13:59 +08:00
// .legend:nth-child(3){
// margin-left: 30px;
// }
2024-04-29 16:00:07 +08:00
.legend-item {
2024-06-07 11:13:59 +08:00
margin-left: 15px;
2024-04-29 16:00:07 +08:00
display: flex;
flex-direction: column;
2024-06-07 11:13:59 +08:00
// align-items: center;
align-items: flex-start;
2024-04-29 16:00:07 +08:00
gap: 3px;
&:first-child {
2024-06-07 11:13:59 +08:00
// margin-left: 5px;
2024-04-29 16:00:07 +08:00
.legend-item__value {
color: #0e61f5;
}
}
&:nth-child(2) {
.legend-item__value {
color: #0fd5d1;
}
}
}
2024-06-07 11:13:59 +08:00
.legend-item__label {
position: relative;
}
.legend-item__label::before {
content: "";
position: absolute;
width: 12px;
height: 12px;
background: #ccc;
border-radius: 2px;
top: 6px;
left: -18px;
}
2024-04-29 16:00:07 +08:00
2024-06-07 11:13:59 +08:00
.legend-item:nth-child(2) .legend-item__label::before {
background: #12fff5;
}
.legend-item:nth-child(2) .legend-item__value {
color: #12fff5;
}
.legend-item:nth-child(1) .legend-item__label::before {
background: #0f65ff;
}
.legend-item:nth-child(1) .legend-item__value {
color: #0f65ff;
}
.legend-item:nth-child(3) .legend-item__label::before {
background: #003982;
}
2024-04-29 16:00:07 +08:00
.legend-item__value {
font-size: 24px;
font-weight: 600;
}
}
</style>
2024-05-08 16:38:05 +08:00