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

261 lines
8.4 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-05-29 17:05:55 +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__value">{{ lgd.value }}</span>
<span class="legend-item__label">{{ lgd.label }}</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-04-30 16:22:15 +08:00
const single = this.period === "日" || this.period === "周";
2024-04-29 16:00:07 +08:00
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
const vt = this.valueTuple;
2024-04-30 16:22:15 +08:00
let titleValue = single
? (vt[1] != null && `${vt[1] * 100}%`) || "0%"
: vt[0] != null && vt[2] != null && vt[2] !== 0
? `${((vt[1] / vt[2]) * 100).toFixed(0)}%`
: "0%",
subtitle = {
: "本日良率",
: "本周良率",
: `${month}月良率`,
: `${year}良率`,
}[this.period];
2024-04-29 16:00:07 +08:00
2024-04-30 16:22:15 +08:00
const t = getOptions({
single,
2024-04-29 16:00:07 +08:00
color: this.color == 1 ? "#4CF0E8" : "#1065ff",
titleValue,
subtitle,
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 = [
{ label: `${month}${today}日良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.valueTuple[1]) + "%" },
{ label: `去年${month}${today}日良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.valueTuple[0]) + "%" },
];
} else if (this.period === '日' && this.than === '环比') {
items = [
{ label: `${month}${today}日良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.valueTuple[1]) + "%" },
{ label: `${yesterday}日良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.valueTuple[0]) + "%" },
];
} else if (this.period === '周' && this.than === '同比') {
items = [
{ label: `本周良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.valueTuple[1]) + "%" },
{ label: `去年本周良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.valueTuple[0]) + "%" },
];
} else if (this.period === '周' && this.than === '环比') {
items = [
{ label: `本周良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.valueTuple[1]) + "%" },
{ label: `上周良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.valueTuple[0]) + "%" },
];
} else if (this.period === '月' && this.than === '同比') {
items = [
{ label: `${month}月良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.valueTuple[1]) + "%" },
{ label: `去年${month}月良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.valueTuple[0]) + "%" },
{ label: `${month}月目标良率`, value: isNaN(this.valueTuple[2]) || this.valueTuple[2] == null ? 0 + "%" : (this.valueTuple[2]) + "%" },
];
} else if (this.period === '月' && this.than === '环比') {
items = [
{ label: `${month}月良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.valueTuple[1]) + "%" },
{ label: `${lastMonth}月良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.valueTuple[0]) + "%" },
{ label: `${month}月目标良率`, value: isNaN(this.valueTuple[2]) || this.valueTuple[2] == null ? 0 + "%" : (this.valueTuple[2]) + "%" },
];
} else {
items = [
{ label: `${year}年良率`, value: isNaN(this.valueTuple[1]) || this.valueTuple[1] == null ? 0 + "%" : (this.valueTuple[1]) + "%" },
{ label: `${year - 1}年良率`, value: isNaN(this.valueTuple[0]) || this.valueTuple[0] == null ? 0 + "%" : (this.valueTuple[0]) + "%" },
{ label: `${year}年目标良率`, value: isNaN(this.valueTuple[2]) || this.valueTuple[2] == null ? 0 + "%" : (this.valueTuple[2]) + "%" },
];
}
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-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;
justify-content: center;
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;
align-self: stretch;
// flex: 1 1 auto;
2024-05-30 16:00:18 +08:00
// align-items: center;
2024-05-29 17:05:55 +08:00
// margin:0 auto;
// padding: 0 10%;;
2024-05-20 10:20:37 +08:00
/* margin: 10%; */
/* min-width: 300px; */
height: 200px;
}
2024-04-29 16:00:07 +08:00
.legend {
height: 80px;
display: flex;
gap: 40px;
justify-content: space-around;
}
.legend-item {
display: flex;
flex-direction: column;
align-items: center;
gap: 3px;
&:first-child {
.legend-item__value {
color: #0e61f5;
}
}
&:nth-child(2) {
.legend-item__value {
color: #0fd5d1;
}
}
}
.legend-item__value {
font-size: 24px;
font-weight: 600;
}
}
</style>
2024-05-08 16:38:05 +08:00