student.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template
  2. v-loading="loading"
  3. element-loading-spinner="el-icon-loading"
  4. element-loading-background="rgba(0, 0, 0, 0.8)">
  5. <el-card>
  6. <div slot="header" class="clearfix">
  7. <searchHeader
  8. :dates="mdate"
  9. :title="'学员变动'"
  10. @changeValue="changeValue"
  11. :isShowQuert="true"
  12. />
  13. </div>
  14. <statistic :col="6" class="statistic" :cols="0">
  15. <statistic-item
  16. v-for="(item, key) in items"
  17. :key="key"
  18. :class="{ active: active === key }"
  19. @click="active = key"
  20. >
  21. <span>
  22. {{ item.title }}
  23. <el-tooltip
  24. v-if="item.desc"
  25. :content="item.desc"
  26. :open-delay="0.3"
  27. placement="top"
  28. >
  29. <i
  30. style="margin-left: 5px; cursor: pointer"
  31. class="el-icon-warning-outline"
  32. />
  33. </el-tooltip>
  34. </span>
  35. <span> <count-to :endVal="item.percent" />人 </span>
  36. </statistic-item>
  37. </statistic>
  38. <div class="wrap">
  39. <div class="chioseBox">
  40. <el-radio-group v-model="timer" size="mini">
  41. <el-radio-button label="day">按天</el-radio-button>
  42. <el-radio-button label="month">按月</el-radio-button>
  43. </el-radio-group>
  44. </div>
  45. <!-- :data-zoom="dataZoom" -->
  46. <ve-line
  47. style="width: 100%"
  48. height="350px"
  49. :data="timer == 'day' ? chartData : chartDataForMoth"
  50. :data-empty="dataEmpty"
  51. :extend="chartExtend"
  52. :legend="legend"
  53. ></ve-line>
  54. </div>
  55. <!-- <ve-funnel v-else style="width: 100%;" height="350px" :data="funnelData" :data-empty="dataEmpty"></ve-funnel> -->
  56. </el-card>
  57. </template>
  58. <script>
  59. import countTo from "vue-count-to";
  60. import veLine from "v-charts/lib/line.common";
  61. import veFunnel from "v-charts/lib/funnel.common";
  62. import searchHeader from "./modals/searchHeader";
  63. import { getIndex } from "../api";
  64. import { getTimes } from "@/utils";
  65. import { descs, chioseNum } from "../constant";
  66. export default {
  67. props: ["data", "search"],
  68. components: {
  69. "ve-funnel": veFunnel,
  70. "ve-line": veLine,
  71. "count-to": countTo,
  72. searchHeader,
  73. },
  74. computed: {
  75. legend() {
  76. return {
  77. left: "10px",
  78. };
  79. },
  80. items() {
  81. return {
  82. ADD_STUDENT_REGISTRATION_NUM:
  83. this.data["ADD_STUDENT_REGISTRATION_NUM"] || {},
  84. MUSIC_GROUP_STUDENT: this.data["MUSIC_GROUP_STUDENT"] || {},
  85. NEWLY_STUDENT_NUM: this.data["NEWLY_STUDENT_NUM"] || {},
  86. QUIT_MUSIC_GROUP_STUDENT_NUM:
  87. this.data["QUIT_MUSIC_GROUP_STUDENT_NUM"] || {},
  88. VIP_PRACTICE_STUDENT_NUM: this.data["VIP_PRACTICE_STUDENT_NUM"] || {},
  89. VIP_PRACTICE_ADD_STUDENT_NUM:
  90. this.data["VIP_PRACTICE_ADD_STUDENT_NUM"] || {},
  91. };
  92. },
  93. chartExtend() {
  94. return {
  95. yAxis: {
  96. //纵轴标尺固定
  97. minInterval: 1,
  98. type: "value",
  99. scale: true,
  100. min: 0,
  101. axisLabel: {
  102. formatter: "{value}人",
  103. },
  104. },
  105. series: {
  106. smooth: false,
  107. },
  108. tooltip: {
  109. axisPointer: {
  110. type: "shadow",
  111. shadowStyle: {
  112. color: "rgba(150,150,150,0.2)",
  113. },
  114. },
  115. formatter: (item) => {
  116. return [
  117. item[0].axisValueLabel,
  118. ...item.map(
  119. (d) => `<br/>${d.marker}${d.seriesName}: ${d.value[1]}人`
  120. ),
  121. ].join("");
  122. },
  123. },
  124. };
  125. },
  126. dataZoom() {
  127. return [
  128. {
  129. type: "slider",
  130. start: 60,
  131. end: 100,
  132. },
  133. ];
  134. },
  135. chartData() {
  136. const values = Object.values(this.items);
  137. const months = {};
  138. for (const item of values) {
  139. for (const row of item.indexMonthData || []) {
  140. const key = this.$helpers.dayjs(row.month).format("YYYY-MM-DD");
  141. if (!months[key]) {
  142. months[key] = {
  143. 日期: key,
  144. };
  145. }
  146. months[key][item.title] = row.percent;
  147. }
  148. }
  149. return {
  150. columns: ["日期", ...values.map((item) => item.title)],
  151. rows: Object.values(months),
  152. };
  153. },
  154. chartDataForMoth() {
  155. const values = Object.values(this.items);
  156. const months = {};
  157. for (const item of values) {
  158. for (const row of item.indexMonthData || []) {
  159. const key = this.$helpers.dayjs(row.month).format("YYYY-MM");
  160. if (!months[key]) {
  161. months[key] = {
  162. 月份: key,
  163. };
  164. months[key][item.title] = row.percent;
  165. } else {
  166. if (months[key][item.title]) {
  167. months[key][item.title] += parseFloat(row.percent);
  168. } else {
  169. months[key][item.title] = row.percent;
  170. }
  171. }
  172. }
  173. }
  174. return {
  175. columns: ["月份", ...values.map((item) => item.title)],
  176. rows: Object.values(months),
  177. };
  178. },
  179. funnelData() {
  180. const { indexMonthData = [] } = this.data["STUDENT_CONVERSION"] || {};
  181. return {
  182. columns: ["类型", "数值"],
  183. rows: indexMonthData.map((item) => ({
  184. 类型: item.title,
  185. 数值: item.percent,
  186. })),
  187. };
  188. },
  189. dataEmpty() {
  190. return !this.chartData.rows.length;
  191. },
  192. },
  193. data() {
  194. return {
  195. active: "NEWLY_STUDENT_NUM",
  196. isHistogram: true,
  197. timer: "day",
  198. mdate: this.search?.dates,
  199. loading: false,
  200. };
  201. },
  202. methods: {
  203. changeValue(date) {
  204. // 请求更改数据
  205. this.mdate = date;
  206. this.isDayOrMoth(date);
  207. this.FetchDetail();
  208. },
  209. async FetchDetail() {
  210. this.loading = true;
  211. let data = [];
  212. try {
  213. const { dates, ...rest } = this.search;
  214. const res = await getIndex({
  215. ...rest,
  216. ...getTimes(this.mdate, ["startDate", "endDate"]),
  217. dataTypes:
  218. "ADD_STUDENT_REGISTRATION_NUM,MUSIC_GROUP_STUDENT,NEWLY_STUDENT_NUM,QUIT_MUSIC_GROUP_STUDENT_NUM,VIP_PRACTICE_STUDENT_NUM,VIP_PRACTICE_ADD_STUDENT_NUM",
  219. });
  220. for (const item of res.data) {
  221. // 再循环一遍
  222. for (const key in this.items) {
  223. // console.log(key);
  224. if (item.dataType == key) {
  225. data[item.dataType] = {
  226. ...item,
  227. desc: descs[item.dataType],
  228. };
  229. }
  230. }
  231. }
  232. } catch (error) {
  233. console.log(error);
  234. }
  235. this.loading = false;
  236. this.dataInfo = data;
  237. this.$emit("resetDate", data);
  238. },
  239. isDayOrMoth(arr) {
  240. if (!arr || arr.length < 1) {
  241. this.timer = "day";
  242. } else {
  243. const count = this.$helpers
  244. .dayjs(arr[0])
  245. .diff(this.$helpers.dayjs(arr[1]), "day");
  246. Math.abs(count) > chioseNum
  247. ? (this.timer = "month")
  248. : (this.timer = "day");
  249. }
  250. },
  251. },
  252. };
  253. </script>
  254. <style lang="less" scoped>
  255. // .statistic{
  256. // /deep/ .statistic-content{
  257. // cursor: pointer;
  258. // &.active > span{
  259. // color: #14928a !important;
  260. // }
  261. // }
  262. // }
  263. .chioseBox {
  264. position: absolute;
  265. right: 20px;
  266. z-index: 1000;
  267. }
  268. .wrap {
  269. position: relative;
  270. }
  271. </style>