curriculum.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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" :col="5">
  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. VIP_GROUP_ONLINE_COURSE: this.data["VIP_GROUP_ONLINE_COURSE"] || {},
  81. VIP_GROUP_OFFLINE_COURSE: this.data["VIP_GROUP_OFFLINE_COURSE"] || {},
  82. PRACTICE_GROUP_COURSE: this.data["PRACTICE_GROUP_COURSE"] || {},
  83. };
  84. },
  85. dataZoom() {
  86. return [
  87. {
  88. type: "slider",
  89. start: 50,
  90. end: 100,
  91. },
  92. ];
  93. },
  94. chartData() {
  95. const values = Object.values(this.items);
  96. const months = {};
  97. for (const item of values) {
  98. for (const row of item.indexMonthData || []) {
  99. const key = this.$helpers.dayjs(row.month).format("YYYY-MM-DD");
  100. if (!months[key]) {
  101. months[key] = {
  102. 日期: key,
  103. };
  104. }
  105. months[key][item.title] = row.percent;
  106. }
  107. }
  108. return {
  109. columns: ["日期", ...values.map((item) => item.title)],
  110. rows: Object.values(months),
  111. };
  112. },
  113. chartDataForMoth() {
  114. const values = Object.values(this.items);
  115. // console.log(values)
  116. // values['VIP_GROUP_COURSE'].forEach(item=>{
  117. // console.log(item.month)
  118. // })
  119. const months = {};
  120. for (const item of values) {
  121. for (const row of item.indexMonthData || []) {
  122. const key = this.$helpers.dayjs(row.month).format("YYYY-MM");
  123. if (!months[key]) {
  124. months[key] = {
  125. 月份: key,
  126. };
  127. months[key][item.title] = row.percent;
  128. } else {
  129. if (months[key][item.title]) {
  130. months[key][item.title] += parseFloat(row.percent);
  131. } else {
  132. months[key][item.title] = row.percent;
  133. }
  134. }
  135. }
  136. }
  137. console.log(Object.values(months));
  138. return {
  139. columns: ["月份", ...values.map((item) => item.title)],
  140. rows: Object.values(months),
  141. };
  142. },
  143. dataEmpty() {
  144. return !this.chartData.rows.length;
  145. },
  146. chartExtend() {
  147. return {
  148. series: {
  149. smooth: false,
  150. },
  151. yAxis: {
  152. //纵轴标尺固定
  153. minInterval: 1,
  154. type: "value",
  155. scale: true,
  156. min: 0,
  157. axisLabel: {
  158. formatter: "{value}节",
  159. },
  160. },
  161. tooltip: {
  162. axisPointer: {
  163. type: "shadow",
  164. shadowStyle: {
  165. color: "rgba(150,150,150,0.2)",
  166. },
  167. },
  168. formatter: (item) => {
  169. let strArr = [];
  170. let dotStr =
  171. '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;opacity:0;"></span>';
  172. let array = [
  173. ...item.map(
  174. (d) => `<br/>${d.marker}${d.seriesName}: ${d.value[1]}节`
  175. ),
  176. ];
  177. if (this.timer == "day") {
  178. strArr = this.setVipDayDetail(item);
  179. } else {
  180. let vipDEtail = this.setVipMonthDetail();
  181. item.forEach((i) => {
  182. if (i.seriesName == "VIP课") {
  183. for (let items in vipDEtail[i.name]) {
  184. strArr.push({ name: items, num: vipDEtail[i.name][items] });
  185. }
  186. }
  187. });
  188. strArr.sort(function (item1, item2) {
  189. return item1.name.localeCompare(item2.name, "zh-CN");
  190. });
  191. }
  192. let vipIndex = 0;
  193. item.forEach((i, indx) => {
  194. if (i.seriesName == "VIP课") {
  195. vipIndex = indx;
  196. }
  197. });
  198. array.splice(
  199. vipIndex + 1,
  200. 0,
  201. ...strArr.map((d) => `<br/>${dotStr}${d.name}: ${d.num}节`)
  202. );
  203. return [item[0].axisValueLabel, ...array].join("");
  204. },
  205. },
  206. };
  207. },
  208. },
  209. data() {
  210. return {
  211. active: "MUSIC_GROUP_COURSE",
  212. timer: "day",
  213. mdate: this.search?.dates,
  214. loading: false,
  215. };
  216. },
  217. watch: {},
  218. methods: {
  219. changeValue(date) {
  220. // 请求更改数据
  221. this.mdate = date;
  222. this.isDayOrMoth(date);
  223. this.FetchDetail();
  224. },
  225. async FetchDetail() {
  226. this.loading = true;
  227. let data = [];
  228. try {
  229. const { dates, ...rest } = this.search;
  230. const res = await getIndex({
  231. ...rest,
  232. ...getTimes(this.mdate, ["startDate", "endDate"]),
  233. dataTypes:
  234. "MUSIC_GROUP_COURSE,VIP_GROUP_COURSE,PRACTICE_GROUP_COURSE,VIP_GROUP_OFFLINE_COURSE,VIP_GROUP_ONLINE_COURSE",
  235. });
  236. for (const item of res.data) {
  237. // 再循环一遍
  238. for (const key in this.items) {
  239. if (item.dataType == key) {
  240. data[item.dataType] = {
  241. ...item,
  242. desc: descs[item.dataType],
  243. };
  244. }
  245. }
  246. }
  247. } catch (error) {
  248. console.log(error);
  249. }
  250. this.loading = false;
  251. this.$emit("resetDate", data);
  252. },
  253. isDayOrMoth(arr) {
  254. if (!arr || arr.length < 1) {
  255. this.timer = "day";
  256. } else {
  257. const count = this.$helpers
  258. .dayjs(arr[0])
  259. .diff(this.$helpers.dayjs(arr[1]), "day");
  260. Math.abs(count) > chioseNum
  261. ? (this.timer = "month")
  262. : (this.timer = "day");
  263. }
  264. },
  265. setVipMonthDetail() {
  266. console.log("调用");
  267. const vipdetail = {};
  268. let datas = this.items["VIP_GROUP_COURSE"]["indexMonthData"];
  269. datas.forEach((item) => {
  270. let str = item.extendInfo;
  271. let strArr = [];
  272. let strObj = {};
  273. str.replace("/", "");
  274. if (str) {
  275. try {
  276. strObj = JSON.parse(str);
  277. // for (let item in strObj) {
  278. // strArr.push({ name: item, num: parseFloat(strObj[item]) });
  279. // }
  280. } catch (e) {
  281. console.log(e);
  282. str = "";
  283. }
  284. }
  285. const key = this.$helpers.dayjs(item.month).format("YYYY-MM");
  286. if (!vipdetail[key]) {
  287. vipdetail[key] = strObj;
  288. } else {
  289. for (let element in strObj) {
  290. if (vipdetail[key].hasOwnProperty(element)) {
  291. vipdetail[key][element] += strObj[element];
  292. } else {
  293. vipdetail[key][element] = strObj[element];
  294. }
  295. }
  296. }
  297. });
  298. return vipdetail;
  299. },
  300. setVipDayDetail(item) {
  301. let strArr = [];
  302. let str = "";
  303. if (
  304. this.items["VIP_GROUP_COURSE"]["indexMonthData"][item[0].dataIndex]
  305. ?.extendInfo
  306. ) {
  307. str = this.items["VIP_GROUP_COURSE"]["indexMonthData"][
  308. item[0].dataIndex
  309. ]?.extendInfo;
  310. str.replace("/", "");
  311. try {
  312. let strObj = JSON.parse(str);
  313. for (let item in strObj) {
  314. strArr.push({ name: item, num: strObj[item] });
  315. }
  316. // console.log(strArr)
  317. } catch (e) {
  318. console.log(e);
  319. str = "";
  320. }
  321. // console.log(lodash.valuesIn(str))
  322. }
  323. return strArr;
  324. },
  325. },
  326. };
  327. </script>
  328. <style lang="less" scoped>
  329. // .statistic{
  330. // /deep/ .statistic-content{
  331. // cursor: pointer;
  332. // &.active > span{
  333. // color: #14928a !important;
  334. // }
  335. // }
  336. // }
  337. .chioseBox {
  338. position: absolute;
  339. right: 20px;
  340. z-index: 1000;
  341. }
  342. .wrap {
  343. position: relative;
  344. }
  345. </style>