student.vue 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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: 0px 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="350px" :data="chartData" :data-empty="dataEmpty"></ve-histogram>
  25. <ve-funnel v-else style="width: 100%;" height="350px" :data="funnelData" :data-empty="dataEmpty"></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).filter(item => item.dataType !== 'STUDENT_CONVERSION')
  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. const { indexMonthData = [] } = this.data['STUDENT_CONVERSION'] || {}
  69. return {
  70. columns: ['类型', '数值'],
  71. rows: indexMonthData.map(item => ({
  72. '类型': item.title,
  73. '数值': item.percent
  74. }))
  75. }
  76. },
  77. dataEmpty() {
  78. return !this.chartData.rows.length
  79. },
  80. },
  81. data () {
  82. return {
  83. active: 'NEWLY_STUDENT_NUM',
  84. isHistogram: true,
  85. }
  86. },
  87. }
  88. </script>
  89. <style lang="less" scoped>
  90. // .statistic{
  91. // /deep/ .statistic-content{
  92. // cursor: pointer;
  93. // &.active > span{
  94. // color: #14928a !important;
  95. // }
  96. // }
  97. // }
  98. </style>