student.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. },
  116. };
  117. },
  118. dataZoom() {
  119. return [
  120. {
  121. type: "slider",
  122. start: 60,
  123. end: 100,
  124. },
  125. ];
  126. },
  127. chartData() {
  128. const values = Object.values(this.items);
  129. const months = {};
  130. for (const item of values) {
  131. for (const row of item.indexMonthData || []) {
  132. const key = this.$helpers.dayjs(row.month).format("YYYY-MM-DD");
  133. if (!months[key]) {
  134. months[key] = {
  135. 日期: key,
  136. };
  137. }
  138. months[key][item.title] = row.percent;
  139. }
  140. }
  141. return {
  142. columns: ["日期", ...values.map((item) => item.title)],
  143. rows: Object.values(months),
  144. };
  145. },
  146. chartDataForMoth() {
  147. const values = Object.values(this.items);
  148. console.log(values);
  149. const months = {};
  150. for (const item of values) {
  151. for (const row of item.indexMonthData || []) {
  152. const key = this.$helpers.dayjs(row.month).format("YYYY-MM");
  153. if (!months[key]) {
  154. months[key] = {
  155. 月份: key,
  156. };
  157. months[key][item.title] = row.percent;
  158. } else {
  159. if (months[key][item.title]) {
  160. months[key][item.title] += parseFloat(row.percent);
  161. } else {
  162. months[key][item.title] = row.percent;
  163. }
  164. }
  165. }
  166. }
  167. return {
  168. columns: ["月份", ...values.map((item) => item.title)],
  169. rows: Object.values(months),
  170. };
  171. },
  172. funnelData() {
  173. const { indexMonthData = [] } = this.data["STUDENT_CONVERSION"] || {};
  174. return {
  175. columns: ["类型", "数值"],
  176. rows: indexMonthData.map((item) => ({
  177. 类型: item.title,
  178. 数值: item.percent,
  179. })),
  180. };
  181. },
  182. dataEmpty() {
  183. return !this.chartData.rows.length;
  184. },
  185. },
  186. data() {
  187. return {
  188. active: "NEWLY_STUDENT_NUM",
  189. isHistogram: true,
  190. timer: "day",
  191. mdate: this.search?.dates,
  192. loading: false,
  193. };
  194. },
  195. methods: {
  196. changeValue(date) {
  197. // 请求更改数据
  198. this.mdate = date;
  199. this.isDayOrMoth(date);
  200. this.FetchDetail();
  201. },
  202. async FetchDetail() {
  203. this.loading = true;
  204. const data = this.data;
  205. try {
  206. const { dates, ...rest } = this.search;
  207. const res = await getIndex({
  208. ...rest,
  209. ...getTimes(this.mdate, ["startDate", "endDate"]),
  210. dataTypes:'ADD_STUDENT_REGISTRATION_NUM,MUSIC_GROUP_STUDENT,NEWLY_STUDENT_NUM,QUIT_MUSIC_GROUP_STUDENT_NUM,VIP_PRACTICE_STUDENT_NUM,VIP_PRACTICE_ADD_STUDENT_NUM'
  211. });
  212. for (const item of res.data) {
  213. // 再循环一遍
  214. for (const key in this.items) {
  215. // console.log(key);
  216. if (item.dataType == key) {
  217. data[item.dataType] = {
  218. ...item,
  219. desc: descs[item.dataType],
  220. };
  221. }
  222. }
  223. }
  224. } catch (error) {
  225. console.log(error);
  226. }
  227. console.log(data);
  228. this.loading = false;
  229. this.dataInfo = data;
  230. this.$emit("resetDate", data);
  231. },
  232. isDayOrMoth(arr) {
  233. console.log(arr);
  234. if (!arr || arr.length < 1) {
  235. this.timer = "day";
  236. } else {
  237. const count = this.$helpers
  238. .dayjs(arr[0])
  239. .diff(this.$helpers.dayjs(arr[1]), "day");
  240. Math.abs(count) > chioseNum
  241. ? (this.timer = "month")
  242. : (this.timer = "day");
  243. }
  244. },
  245. },
  246. };
  247. </script>
  248. <style lang="less" scoped>
  249. // .statistic{
  250. // /deep/ .statistic-content{
  251. // cursor: pointer;
  252. // &.active > span{
  253. // color: #14928a !important;
  254. // }
  255. // }
  256. // }
  257. .chioseBox {
  258. position: absolute;
  259. right: 20px;
  260. z-index: 1000;
  261. }
  262. .wrap {
  263. position: relative;
  264. }
  265. </style>