business.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template
  2. >
  3. <el-card header="">
  4. <div slot="header" class="clearfix">
  5. <searchHeader
  6. v-if="mdate.length > 0"
  7. :dates="mdate"
  8. :title="'业务数据'"
  9. :isShowQuert="false"
  10. @changeValue="changeValue"
  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" :decimals="2" />% </span>
  35. </statistic-item>
  36. </statistic>
  37. <!-- :data-zoom="dataZoom" -->
  38. <ve-line
  39. style="width: 100%"
  40. height="350px"
  41. :data="chartData"
  42. :data-empty="dataEmpty"
  43. :extend="chartExtend"
  44. :legend="legend"
  45. ></ve-line>
  46. </el-card>
  47. </template>
  48. <script>
  49. import "v-charts/lib/style.css";
  50. import "echarts/lib/component/dataZoom";
  51. import countTo from "vue-count-to";
  52. import veLine from "v-charts/lib/line.common";
  53. import searchHeader from "./modals/searchHeader";
  54. import { getTimes } from "@/utils";
  55. import { getIndex } from "../api";
  56. import { descs, chioseNum } from "../constant";
  57. import { getNowDateAndSunday, getNowDateAndMonday } from "@/utils/date";
  58. export default {
  59. props: ["data", "search"],
  60. components: {
  61. "count-to": countTo,
  62. "ve-line": veLine,
  63. searchHeader,
  64. },
  65. computed: {
  66. legend() {
  67. return {
  68. left: "10px",
  69. };
  70. },
  71. items() {
  72. return {
  73. HOMEWORK_CREATE_RATE: this.data["HOMEWORK_CREATE_RATE"] || {},
  74. HOMEWORK_SUBMIT_RATE: this.data["HOMEWORK_SUBMIT_RATE"] || {},
  75. HOMEWORK_COMMENT_RATE: this.data["HOMEWORK_COMMENT_RATE"] || {},
  76. };
  77. },
  78. chartExtend() {
  79. return {
  80. series: {
  81. smooth: false,
  82. },
  83. yAxis: {
  84. //纵轴标尺固定
  85. type: "value",
  86. scale: true,
  87. min: 0,
  88. max:100,
  89. axisLabel:{
  90. formatter:'{value}%'
  91. }
  92. },
  93. tooltip: {
  94. axisPointer: {
  95. type: "shadow",
  96. shadowStyle: {
  97. color: "rgba(150,150,150,0.2)",
  98. },
  99. },
  100. formatter: (item) => {
  101. return [
  102. item[0].axisValueLabel,
  103. ...item.map(
  104. (d) => `<br/>${d.marker}${d.seriesName}: ${d.value} %`
  105. ),
  106. ].join("");
  107. },
  108. },
  109. };
  110. },
  111. dataZoom() {
  112. return [
  113. {
  114. grid: {
  115. left: "0%",
  116. },
  117. type: "slider",
  118. start: 40,
  119. end: 100,
  120. },
  121. ];
  122. },
  123. chartData() {
  124. const values = Object.values(this.items);
  125. const months = {};
  126. for (const item of values) {
  127. for (const row of item.indexMonthData || []) {
  128. const key = this.$helpers.dayjs(row.month).format("YYYY-MM-DD");
  129. if (!months[key]) {
  130. months[key] = {
  131. 日期: key + "/" + getNowDateAndSunday(key),
  132. };
  133. }
  134. months[key][item.title] = row.percent;
  135. }
  136. }
  137. return {
  138. columns: [
  139. "日期",
  140. ...values.map((item) => {
  141. return item.title;
  142. }),
  143. ],
  144. rows: Object.values(months),
  145. };
  146. },
  147. dataEmpty() {
  148. return !this.chartData.rows.length;
  149. },
  150. },
  151. data() {
  152. return {
  153. active: "ACTIVATION_RATE",
  154. mdate: [],
  155. loading: false,
  156. };
  157. },
  158. mounted() {
  159. let nowTiem = this.$helpers.dayjs(new Date()).format("YYYY-MM-DD");
  160. let startTime = this.$helpers
  161. .dayjs(getNowDateAndMonday(nowTiem))
  162. .subtract(56, "day")
  163. .format("YYYY-MM-DD");
  164. let endTime = getNowDateAndSunday(nowTiem);
  165. this.mdate = [startTime, endTime];
  166. this.FetchDetail();
  167. },
  168. methods: {
  169. changeValue(date) {
  170. // 请求更改数据
  171. this.mdate = date;
  172. // this.isDayOrMoth(date)
  173. this.FetchDetail();
  174. },
  175. async FetchDetail() {
  176. this.loading = true;
  177. const data = this.data;
  178. try {
  179. const { dates, ...rest } = this.search;
  180. const res = await getIndex({
  181. ...rest,
  182. ...getTimes(this.mdate, ["startDate", "endDate"]),
  183. dataTypes:
  184. "HOMEWORK_CREATE_RATE,HOMEWORK_SUBMIT_RATE,HOMEWORK_COMMENT_RATE",
  185. });
  186. for (const item of res.data) {
  187. // 再循环一遍
  188. for (const key in this.items) {
  189. if (item.dataType == key) {
  190. data[item.dataType] = {
  191. ...item,
  192. desc: descs[item.dataType],
  193. };
  194. }
  195. }
  196. }
  197. } catch (error) {
  198. console.log(error);
  199. }
  200. this.loading = false;
  201. this.dataInfo = data;
  202. this.$emit("resetDate", data);
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="less" scoped>
  208. // .statistic{
  209. // /deep/ .statistic-content{
  210. // cursor: pointer;
  211. // &.active > span{
  212. // color: #14928a !important;
  213. // }
  214. // }
  215. // }
  216. .chioseBox {
  217. position: absolute;
  218. right: 20px;
  219. z-index: 1000;
  220. }
  221. .wrap {
  222. position: relative;
  223. }
  224. </style>