student.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <el-card>
  3. <div slot="header" class="clearfix">
  4. <span>学员变动</span>
  5. <el-button
  6. @click="isHistogram = !isHistogram"
  7. style="float: right; padding: 3px 0"
  8. type="text"
  9. >{{isHistogram ? '学员转化漏斗图' : '学员柱状图'}}</el-button>
  10. </div>
  11. <statistic class="statistic" :cols="0">
  12. <statistic-item v-for="(item, key) in items" :key="key" :class="{active: active === key}" @click="active = key">
  13. <span>
  14. {{item.title}}
  15. <el-tooltip v-if="item.desc" :content="item.desc" :open-delay=".3" placement="top">
  16. <i style="margin-left: 5px;cursor: pointer;" class="el-icon-warning-outline"/>
  17. </el-tooltip>
  18. </span>
  19. <span>
  20. <count-to :endVal="item.percent"/>{{key === 'STUDENT_CONVERSION' ? '%' : ''}}
  21. </span>
  22. </statistic-item>
  23. </statistic>
  24. <ve-histogram v-if="isHistogram" style="width: 100%;" height="345px" :data="chartData"></ve-histogram>
  25. <ve-funnel v-else style="width: 100%;" height="345px" :data="funnelData"></ve-funnel>
  26. </el-card>
  27. </template>
  28. <script>
  29. import countTo from 'vue-count-to'
  30. import veHistogram from 'v-charts/lib/histogram.common'
  31. import veFunnel from 'v-charts/lib/funnel.common'
  32. export default {
  33. props: ['data'],
  34. components: {
  35. 've-funnel': veFunnel,
  36. 've-histogram': veHistogram,
  37. 'count-to': countTo
  38. },
  39. computed: {
  40. items() {
  41. return {
  42. NEWLY_STUDENT_NUM: this.data['NEWLY_STUDENT_NUM'] || {},
  43. QUIT_MUSIC_GROUP_STUDENT_NUM: this.data['QUIT_MUSIC_GROUP_STUDENT_NUM'] || {},
  44. STUDENT_CONVERSION: this.data['STUDENT_CONVERSION'] || {},
  45. }
  46. },
  47. chartData() {
  48. const data = this.data[this.active] || {}
  49. const values = Object.values(this.items)
  50. const months = {}
  51. for (const item of values) {
  52. for (const row of (item.indexMonthData || [])) {
  53. const key = this.$helpers.dayjs(row.month).month() + 1 + '月'
  54. if (!months[key]) {
  55. months[key] = {
  56. '月份': key,
  57. }
  58. }
  59. months[key][item.title] = row.percent
  60. }
  61. }
  62. return {
  63. columns: ['月份', ...values.map(item => item.title)],
  64. rows: Object.values(months)
  65. }
  66. },
  67. funnelData() {
  68. return {
  69. columns: ['状态', '数值'],
  70. rows: [
  71. { '状态': '展示', '数值': 900 },
  72. { '状态': '访问', '数值': 600 },
  73. { '状态': '点击', '数值': 300 },
  74. { '状态': '订单', '数值': 100 }
  75. ]
  76. }
  77. }
  78. },
  79. data () {
  80. return {
  81. active: 'NEWLY_STUDENT_NUM',
  82. isHistogram: true,
  83. }
  84. },
  85. }
  86. </script>
  87. <style lang="less" scoped>
  88. // .statistic{
  89. // /deep/ .statistic-content{
  90. // cursor: pointer;
  91. // &.active > span{
  92. // color: #14928a !important;
  93. // }
  94. // }
  95. // }
  96. </style>