| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <template>
- <el-card>
- <div slot="header" class="clearfix">
- <span>学员变动</span>
- <el-button
- @click="isHistogram = !isHistogram"
- style="float: right; padding: 3px 0"
- type="text"
- >{{isHistogram ? '学员转化漏斗图' : '学员柱状图'}}</el-button>
- </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=".3" placement="top">
- <i style="margin-left: 5px;cursor: pointer;" class="el-icon-warning-outline"/>
- </el-tooltip>
- </span>
- <span>
- <count-to :endVal="item.percent"/>{{key === 'STUDENT_CONVERSION' ? '%' : ''}}
- </span>
- </statistic-item>
- </statistic>
- <ve-histogram v-if="isHistogram" style="width: 100%;" height="345px" :data="chartData"></ve-histogram>
- <ve-funnel v-else style="width: 100%;" height="345px" :data="funnelData"></ve-funnel>
- </el-card>
- </template>
- <script>
- import countTo from 'vue-count-to'
- import veHistogram from 'v-charts/lib/histogram.common'
- import veFunnel from 'v-charts/lib/funnel.common'
- export default {
- props: ['data'],
- components: {
- 've-funnel': veFunnel,
- 've-histogram': veHistogram,
- 'count-to': countTo
- },
- computed: {
- items() {
- return {
- NEWLY_STUDENT_NUM: this.data['NEWLY_STUDENT_NUM'] || {},
- QUIT_MUSIC_GROUP_STUDENT_NUM: this.data['QUIT_MUSIC_GROUP_STUDENT_NUM'] || {},
- STUDENT_CONVERSION: this.data['STUDENT_CONVERSION'] || {},
- }
- },
- chartData() {
- const data = this.data[this.active] || {}
- 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).month() + 1 + '月'
- if (!months[key]) {
- months[key] = {
- '月份': key,
- }
- }
- months[key][item.title] = row.percent
- }
- }
- return {
- columns: ['月份', ...values.map(item => item.title)],
- rows: Object.values(months)
- }
- },
- funnelData() {
- return {
- columns: ['状态', '数值'],
- rows: [
- { '状态': '展示', '数值': 900 },
- { '状态': '访问', '数值': 600 },
- { '状态': '点击', '数值': 300 },
- { '状态': '订单', '数值': 100 }
- ]
- }
- }
- },
- data () {
- return {
- active: 'NEWLY_STUDENT_NUM',
- isHistogram: true,
- }
- },
- }
- </script>
- <style lang="less" scoped>
- // .statistic{
- // /deep/ .statistic-content{
- // cursor: pointer;
- // &.active > span{
- // color: #14928a !important;
- // }
- // }
- // }
- </style>
|