| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <template>
- <div class="now-year-container">
- <div class="now-year-title">
- <img src="@/assets/images/qst.png" class="title-icon" />
- 实施服务(今年数据)
- </div>
- <div id="nowYearChart" class="chart"></div>
- </div>
- </template>
- <script>
- import { mapState } from "vuex"
- import * as echarts from "echarts"
- export default {
- name: "NowYearServices",
- props: {
- data: {
- type: Object,
- default: () => ({}),
- },
- },
- data() {
- return {
- chartInstance: null,
- chartData: {
- categories: [
- "签约户数",
- "合同份数",
- "服务小区",
- "服务企业",
- "履约城市",
- ],
- },
- }
- },
- computed: {
- ...mapState(["entCode", "communityId"]),
- },
- watch: {
- data: {
- handler(newVal, oldVal) {
- if (newVal) {
- this.initChart()
- }
- },
- deep: true,
- },
- },
- mounted() {
- this.init()
- window.addEventListener("resize", this.handleResize)
- },
- beforeDestroy() {
- if (this.chartInstance) {
- this.chartInstance.dispose()
- }
- window.removeEventListener("resize", this.handleResize)
- },
- methods: {
- // 初始化组件
- init() {
- this.initChart()
- },
- // 初始化图表
- initChart() {
- this.chartInstance = echarts.init(
- document.getElementById("nowYearChart")
- )
- const option = {
- tooltip: {
- trigger: "axis",
- axisPointer: {
- type: "shadow",
- },
- backgroundColor: "rgba(17, 28, 49, 0.9)",
- borderColor: "rgba(64, 158, 255, 0.2)",
- textStyle: {
- color: "#ffffff",
- },
- },
- legend: {
- data: ["进行中", "上月完成", "今年累计"],
- textStyle: {
- color: "#a0b3d6",
- },
- itemWidth: 16,
- itemHeight: 8,
- top: 10,
- },
- grid: {
- left: "3%",
- right: "4%",
- bottom: "3%",
- top: 50,
- containLabel: true,
- },
- xAxis: {
- type: "log",
- show: false, // 隐藏x轴
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- },
- yAxis: {
- type: "category",
- data: this.chartData.categories,
- show: true, // 隐藏y轴
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- show: true,
- color: "#a1a1a1",
- fontSize: 14,
- },
- },
- series: [
- {
- name: "进行中",
- type: "bar",
- stack: "total",
- // barMinHeight: 10,
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
- { offset: 0, color: "#1620D4" },
- { offset: 0.8, color: "#3AB3E3" },
- ]),
- borderRadius: [20, 0, 0, 20],
- },
- label: {
- show: true,
- color: "#fff",
- },
- barGap: "0%",
- barCategoryGap: "20%",
- data: this.data.service_ing,
- },
- {
- name: "上月完成",
- type: "bar",
- stack: "total",
- // barMinHeight: 10,
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
- { offset: 0, color: "#192FC9" },
- { offset: 0.8, color: "#6D44BC" },
- ]),
- borderRadius: [0, 0, 0, 0],
- },
- label: {
- show: true,
- color: "#fff",
- },
- barGap: "0%",
- data: this.data.service_last_month,
- },
- {
- name: "今年累计",
- type: "bar",
- stack: "total",
- // barMinHeight: 10,
- label: {
- show: true,
- color: "#fff",
- },
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
- { offset: 0, color: "#F7897D" },
- { offset: 0.8, color: "#F66C89" },
- ]),
- borderRadius: [0, 20, 20, 0],
- },
- barGap: "0%",
- data: this.data.year_summary,
- },
- ],
- }
- this.chartInstance.setOption(option)
- this.chartInstance.resize()
- },
- // 处理窗口大小变化
- handleResize() {
- if (this.chartInstance) {
- this.chartInstance.resize()
- }
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- @import "@/assets/css/theme.scss";
- .now-year-container {
- background: var(--content-bg);
- border-radius: halfW(4);
- display: flex;
- flex-direction: column;
- }
- .now-year-title {
- font-size: halfW(16);
- border-radius: halfW(4);
- color: var(--title-primary);
- background: var(--title-bg);
- padding: halfH(4) halfW(10);
- display: flex;
- align-items: center;
- }
- .chart {
- width: 100%;
- height: 100%;
- }
- </style>
|