curriculum.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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>
  35. <count-to :endVal="item.percent" />
  36. </span>
  37. </statistic-item>
  38. </statistic>
  39. <div class="wrap">
  40. <div class="chioseBox">
  41. <el-radio-group v-model="timer" size="mini">
  42. <el-radio-button label="day">按天</el-radio-button>
  43. <el-radio-button label="month">按月</el-radio-button>
  44. </el-radio-group>
  45. </div>
  46. <ve-line
  47. :settings="{
  48. area: true,
  49. }"
  50. :data="timer == 'day'?chartData:chartDataForMoth"
  51. height="350px"
  52. :data-empty="dataEmpty"
  53. :data-zoom="dataZoom"
  54. :legend="legend"
  55. />
  56. </div>
  57. </el-card>
  58. </template>
  59. <script>
  60. import "echarts/lib/component/dataZoom";
  61. import countTo from "vue-count-to";
  62. import veLine from "v-charts/lib/line.common";
  63. import searchHeader from "./modals/searchHeader";
  64. import { getIndex } from "../api";
  65. import { getTimes } from "@/utils";
  66. import { descs, chioseNum } from "../constant";
  67. export default {
  68. props: ["data","search"],
  69. components: {
  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. MUSIC_GROUP_COURSE: this.data["MUSIC_GROUP_COURSE"] || {},
  83. VIP_GROUP_COURSE: this.data["VIP_GROUP_COURSE"] || {},
  84. PRACTICE_GROUP_COURSE: this.data["PRACTICE_GROUP_COURSE"] || {},
  85. };
  86. },
  87. dataZoom() {
  88. return [
  89. {
  90. type: "slider",
  91. start: 50,
  92. end: 100,
  93. },
  94. ];
  95. },
  96. chartData() {
  97. const values = Object.values(this.items);
  98. const months = {};
  99. for (const item of values) {
  100. for (const row of item.indexMonthData || []) {
  101. const key = this.$helpers.dayjs(row.month).format("YYYY-MM-DD");
  102. if (!months[key]) {
  103. months[key] = {
  104. 日期: key,
  105. };
  106. }
  107. months[key][item.title] = row.percent;
  108. }
  109. }
  110. return {
  111. columns: ["日期", ...values.map((item) => item.title)],
  112. rows: Object.values(months),
  113. };
  114. },
  115. chartDataForMoth(){
  116. const values = Object.values(this.items);
  117. console.log(values)
  118. const months = {};
  119. for (const item of values) {
  120. for (const row of item.indexMonthData || []) {
  121. const key = this.$helpers.dayjs(row.month).format("YYYY-MM");
  122. if (!months[key]) {
  123. months[key] = {
  124. '月份': key,
  125. };
  126. months[key][item.title] = row.percent;
  127. }else{
  128. if( months[key][item.title]){
  129. months[key][item.title] +=parseFloat(row.percent);
  130. }else{
  131. months[key][item.title]=row.percent
  132. }
  133. }
  134. }
  135. }
  136. return {
  137. columns: ["月份", ...values.map((item) => item.title)],
  138. rows: Object.values(months),
  139. };
  140. },
  141. dataEmpty() {
  142. return !this.chartData.rows.length;
  143. },
  144. },
  145. data() {
  146. return {
  147. active: "MUSIC_GROUP_COURSE",
  148. timer: "day",
  149. mdate: this.search?.dates,
  150. loading:false
  151. };
  152. },
  153. methods:{
  154. changeValue(date) {
  155. // 请求更改数据
  156. this.mdate = date;
  157. this.isDayOrMoth(date)
  158. this.FetchDetail();
  159. },
  160. async FetchDetail() {
  161. this.loading = true
  162. const data = this.data;
  163. try {
  164. const { dates, ...rest } = this.search;
  165. const res = await getIndex({
  166. ...rest,
  167. ...getTimes(this.mdate, ["startDate", "endDate"]),
  168. });
  169. for (const item of res.data) {
  170. // 再循环一遍
  171. for (const key in this.items) {
  172. // console.log(key);
  173. if (item.dataType == key) {
  174. data[item.dataType] = {
  175. ...item,
  176. desc: descs[item.dataType],
  177. };
  178. }
  179. }
  180. }
  181. } catch (error) {
  182. console.log(error);
  183. }
  184. console.log(data)
  185. this.loading = false
  186. this.dataInfo = data;
  187. this.$emit("resetDate", data);
  188. },
  189. isDayOrMoth(arr){
  190. console.log(arr)
  191. if(!arr || arr.length<1){
  192. this.timer = 'day'
  193. }else {
  194. const count = this.$helpers.dayjs(arr[0]).diff(this.$helpers.dayjs(arr[1]),'day')
  195. Math.abs(count)>chioseNum?this.timer = 'month':this.timer = 'day'
  196. }
  197. }
  198. }
  199. };
  200. </script>
  201. <style lang="less" scoped>
  202. // .statistic{
  203. // /deep/ .statistic-content{
  204. // cursor: pointer;
  205. // &.active > span{
  206. // color: #14928a !important;
  207. // }
  208. // }
  209. // }
  210. .chioseBox {
  211. position: absolute;
  212. right: 20px;
  213. z-index: 1000;
  214. }
  215. .wrap {
  216. position: relative;
  217. }
  218. </style>