curriculum.vue 6.3 KB

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