123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <template v-loading="loading"
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)">
- <el-card>
- <div slot="header" class="clearfix">
- <searchHeader
- :dates="mdate"
- :title="'课程数据'"
- @changeValue="changeValue"
- :isShowQuert="true"
- />
- </div>
- <statistic class="statistic" :cols="0">
- <statistic-item
- v-for="(item, key) in items"
- :key="key"
- :class="{ active: active === key }"
- @click="active = key"
- >
- <span>
- {{ item.title }}
- <el-tooltip
- v-if="item.desc"
- :content="item.desc"
- :open-delay="0.3"
- placement="top"
- >
- <i
- style="margin-left: 5px; cursor: pointer"
- class="el-icon-warning-outline"
- />
- </el-tooltip>
- </span>
- <span> <count-to :endVal="item.percent" />节 </span>
- </statistic-item>
- </statistic>
- <div class="wrap">
- <div class="chioseBox">
- <el-radio-group v-model="timer" size="mini">
- <el-radio-button label="day">按天</el-radio-button>
- <el-radio-button label="month">按月</el-radio-button>
- </el-radio-group>
- </div>
- <!-- :data-zoom="dataZoom" -->
- <ve-line
- :data="timer == 'day' ? chartData : chartDataForMoth"
- height="350px"
- :data-empty="dataEmpty"
- :extend="chartExtend"
- :legend="legend"
- />
- </div>
- </el-card>
- </template>
- <script>
- import "echarts/lib/component/dataZoom";
- import countTo from "vue-count-to";
- import veLine from "v-charts/lib/line.common";
- import searchHeader from "./modals/searchHeader";
- import { getIndex } from "../api";
- import { getTimes } from "@/utils";
- import { descs, chioseNum } from "../constant";
- export default {
- props: ["data", "search"],
- components: {
- "ve-line": veLine,
- "count-to": countTo,
- searchHeader,
- },
- computed: {
- legend() {
- return {
- left: "10px",
- };
- },
- items() {
- return {
- MUSIC_GROUP_COURSE: this.data["MUSIC_GROUP_COURSE"] || {},
- VIP_GROUP_COURSE: this.data["VIP_GROUP_COURSE"] || {},
- PRACTICE_GROUP_COURSE: this.data["PRACTICE_GROUP_COURSE"] || {},
- };
- },
- dataZoom() {
- return [
- {
- type: "slider",
- start: 50,
- end: 100,
- },
- ];
- },
- chartData() {
- const values = Object.values(this.items);
- const months = {};
- for (const item of values) {
- for (const row of item.indexMonthData || []) {
- const key = this.$helpers.dayjs(row.month).format("YYYY-MM-DD");
- if (!months[key]) {
- months[key] = {
- 日期: key,
- };
- }
- months[key][item.title] = row.percent;
- }
- }
- return {
- columns: ["日期", ...values.map((item) => item.title)],
- rows: Object.values(months),
- };
- },
- chartDataForMoth() {
- const values = Object.values(this.items);
- const months = {};
- for (const item of values) {
- for (const row of item.indexMonthData || []) {
- const key = this.$helpers.dayjs(row.month).format("YYYY-MM");
- if (!months[key]) {
- months[key] = {
- 月份: key,
- };
- months[key][item.title] = row.percent;
- } else {
- if (months[key][item.title]) {
- months[key][item.title] += parseFloat(row.percent);
- } else {
- months[key][item.title] = row.percent;
- }
- }
- }
- }
- return {
- columns: ["月份", ...values.map((item) => item.title)],
- rows: Object.values(months),
- };
- },
- dataEmpty() {
- return !this.chartData.rows.length;
- },
- chartExtend() {
- return {
- series: {
- smooth: false,
- },
- yAxis: {
- //纵轴标尺固定
- minInterval:1,
- type: "value",
- scale: true,
- min: 0,
- axisLabel:{
- formatter:'{value}节'
- }
- },
- tooltip: {
- axisPointer: {
- type: "shadow",
- shadowStyle: {
- color: "rgba(150,150,150,0.2)",
- },
- },
- formatter: (item) => {
- return [
- item[0].axisValueLabel,
- ...item.map(
- (d) => `<br/>${d.marker}${d.seriesName}: ${d.value} %`
- ),
- ].join("");
- },
- },
- };
- },
- },
- data() {
- return {
- active: "MUSIC_GROUP_COURSE",
- timer: "day",
- mdate: this.search?.dates,
- loading: false,
- };
- },
- methods: {
- changeValue(date) {
- // 请求更改数据
- this.mdate = date;
- this.isDayOrMoth(date);
- this.FetchDetail();
- },
- async FetchDetail() {
- this.loading = true;
- const data = this.data;
- try {
- const { dates, ...rest } = this.search;
- const res = await getIndex({
- ...rest,
- ...getTimes(this.mdate, ["startDate", "endDate"]),
- dataTypes:
- "MUSIC_GROUP_COURSE,VIP_GROUP_COURSE,PRACTICE_GROUP_COURSE",
- });
- for (const item of res.data) {
- // 再循环一遍
- for (const key in this.items) {
- if (item.dataType == key) {
- data[item.dataType] = {
- ...item,
- desc: descs[item.dataType],
- };
- }
- }
- }
- } catch (error) {
- console.log(error);
- }
- this.loading = false;
- this.dataInfo = data;
- this.$emit("resetDate", data);
- },
- isDayOrMoth(arr) {
- if (!arr || arr.length < 1) {
- this.timer = "day";
- } else {
- const count = this.$helpers
- .dayjs(arr[0])
- .diff(this.$helpers.dayjs(arr[1]), "day");
- Math.abs(count) > chioseNum
- ? (this.timer = "month")
- : (this.timer = "day");
- }
- },
- },
- };
- </script>
- <style lang="less" scoped>
- // .statistic{
- // /deep/ .statistic-content{
- // cursor: pointer;
- // &.active > span{
- // color: #14928a !important;
- // }
- // }
- // }
- .chioseBox {
- position: absolute;
- right: 20px;
- z-index: 1000;
- }
- .wrap {
- position: relative;
- }
- </style>
|