appWatchCourseStatistics.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
  4. <el-form-item label="课程" prop="courseId">
  5. <el-select filterable v-model="queryParams.courseId" placeholder="请选择课程"
  6. clearable size="small" @change="courseChange(queryParams.courseId)">
  7. <el-option
  8. v-for="dict in courseList"
  9. :key="dict.dictValue"
  10. :label="dict.dictLabel"
  11. :value="dict.dictValue"
  12. />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="课程小节" prop="videoId">
  16. <el-select filterable v-model="queryParams.videoId" placeholder="请选择课程小节"
  17. clearable size="small">
  18. <el-option
  19. v-for="dict in videoList"
  20. :key="dict.dictValue"
  21. :label="dict.dictLabel"
  22. :value="dict.dictValue"
  23. />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="销售名称" prop="salesName">
  27. <el-input v-model="queryParams.salesName" placeholder="请输入销售名称" clearable size="small" />
  28. </el-form-item>
  29. <el-form-item label="创建时间" prop="createTime">
  30. <el-date-picker
  31. v-model="createTime"
  32. size="small" style="width: 240px"
  33. value-format="yyyy-MM-dd"
  34. type="date"
  35. placeholder="选择日期"
  36. :disabled-date="disabledDate"
  37. @change="handleCreateTimeChange"></el-date-picker>
  38. </el-form-item>
  39. <el-form-item>
  40. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  41. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  42. </el-form-item>
  43. </el-form>
  44. <el-row :gutter="10" class="mb8">
  45. <el-col :span="1.5">
  46. <el-button
  47. type="warning"
  48. plain
  49. icon="el-icon-download"
  50. size="mini"
  51. :loading="exportLoading"
  52. @click="handleExport"
  53. >导出</el-button>
  54. </el-col>
  55. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  56. </el-row>
  57. <el-table
  58. v-loading="loading"
  59. border
  60. :data="packageList"
  61. show-summary
  62. :summary-method="getSummaries"
  63. height="600"
  64. >
  65. <el-table-column label="销售名称" align="center" prop="salesName" />
  66. <el-table-column label="APP 会员数" align="center" prop="appUserCount" />
  67. <el-table-column label="新注册 APP 会员数" align="center" prop="newAppUserCount" />
  68. <el-table-column label="课程名称" align="center" prop="courseName" />
  69. <el-table-column label="课程小节" align="center" prop="videoTitle" />
  70. <el-table-column label="完课数" align="center" prop="finishedCount" />
  71. <el-table-column label="完课率" align="center" prop="completionRate">
  72. <template slot-scope="scope">
  73. <span v-if="typeof scope.row.completionRate === 'number'">
  74. {{ (scope.row.completionRate * 100).toFixed(2) }}%
  75. </span>
  76. <span v-else>
  77. {{ scope.row.completionRate || '0.00%' }}
  78. </span>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="未看课数" align="center" prop="notWatchedCount" />
  82. <el-table-column label="中断数" align="center" prop="interruptCount" />
  83. <el-table-column label="看课中数" align="center" prop="watchingCount" />
  84. <el-table-column label="答题数" align="center" prop="answeredCount" />
  85. <el-table-column label="答题正确数" align="center" prop="correctCount" />
  86. <el-table-column label="答题正确率" align="center" prop="correctRate">
  87. <template slot-scope="scope">
  88. <span v-if="typeof scope.row.correctRate === 'number'">
  89. {{ (scope.row.correctRate * 100).toFixed(2) }}%
  90. </span>
  91. <span v-else>
  92. {{ scope.row.correctRate || '0.00%' }}
  93. </span>
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="红包个数" align="center" prop="redPacketCount" />
  97. <el-table-column label="红包金额" align="center" prop="redPacketAmount" />
  98. </el-table>
  99. </div>
  100. </template>
  101. <script>import { courseList, videoList } from '@/api/course/courseRedPacketLog';
  102. import { appWatchCourseStatistics, appWatchCourseStatisticsExport } from "@/api/app/statistics/appStatistics";
  103. export default {
  104. name: "appWatchCourseStatistics",
  105. components: {},
  106. data() {
  107. return {
  108. courseList: [],
  109. videoList: [],
  110. // 遮罩层
  111. loading: true,
  112. // 导出遮罩层
  113. exportLoading: false,
  114. // 显示搜索条件
  115. showSearch: true,
  116. // 总条数
  117. total: 0,
  118. createTime: null,
  119. // 表格数据
  120. packageList: [],
  121. // 查询参数
  122. queryParams: {
  123. pageNum: 1,
  124. pageSize: 1000,
  125. courseId: null,
  126. videoId: null,
  127. salesName: null,
  128. sTime: null,
  129. eTime: null
  130. }
  131. };
  132. },
  133. created() {
  134. this.initDefaultDate();
  135. this.getList();
  136. courseList().then(response => {
  137. this.courseList = response.list;
  138. });
  139. },
  140. methods: {
  141. /** 初始化默认日期为今天 */
  142. initDefaultDate() {
  143. const today = this.parseTime(new Date(), '{y}-{m}-{d}');
  144. this.createTime = today;
  145. this.queryParams.sTime = today;
  146. this.queryParams.eTime = today;
  147. },
  148. /** 禁用日期选择 - 只能选择今天及之前的日期 */
  149. disabledDate(time) {
  150. return time.getTime() > Date.now();
  151. },
  152. /** 课程变更处理 */
  153. courseChange(row) {
  154. this.queryParams.videoId = null;
  155. if (row === '') {
  156. this.videoList = [];
  157. return;
  158. }
  159. videoList(row).then(response => {
  160. this.videoList = response.list;
  161. });
  162. },
  163. /** 创建时间变更处理 */
  164. handleCreateTimeChange(val) {
  165. if (val) {
  166. this.queryParams.sTime = val;
  167. this.queryParams.eTime = val;
  168. } else {
  169. this.queryParams.sTime = null;
  170. this.queryParams.eTime = null;
  171. }
  172. },
  173. /** 搜索按钮操作 */
  174. handleQuery() {
  175. this.queryParams.pageNum = 1;
  176. this.getList();
  177. },
  178. /** 重置按钮操作 */
  179. resetQuery() {
  180. this.resetForm("queryForm");
  181. this.initDefaultDate();
  182. this.queryParams.courseId = null;
  183. this.queryParams.videoId = null;
  184. this.queryParams.salesName = null;
  185. this.videoList = [];
  186. this.handleQuery();
  187. },
  188. /** 获取表格合计方法 */
  189. getSummaries(param) {
  190. const { columns, data } = param;
  191. const sums = [];
  192. columns.forEach((column, index) => {
  193. if (index === 0) {
  194. sums[index] = '合计';
  195. return;
  196. }
  197. const values = data.map(item => Number(item[column.property]));
  198. if (['appUserCount', 'newAppUserCount', 'finishedCount', 'notWatchedCount', 'interruptCount', 'watchingCount', 'answeredCount', 'correctCount', 'redPacketCount'].includes(column.property)) {
  199. if (!values.every(value => isNaN(value))) {
  200. sums[index] = values.reduce((prev, curr) => {
  201. const value = Number(curr);
  202. if (!isNaN(value)) {
  203. return prev + value;
  204. } else {
  205. return prev;
  206. }
  207. }, 0);
  208. } else {
  209. sums[index] = 'N/A';
  210. }
  211. } else if (column.property === 'redPacketAmount') {
  212. if (!values.every(value => isNaN(value))) {
  213. const total = values.reduce((prev, curr) => {
  214. const value = Number(curr);
  215. if (!isNaN(value)) {
  216. return prev + value;
  217. } else {
  218. return prev;
  219. }
  220. }, 0);
  221. sums[index] = total.toFixed(2);
  222. } else {
  223. sums[index] = 'N/A';
  224. }
  225. } else if (column.property === 'completionRate') {
  226. const totalFinished = data.reduce((sum, item) => sum + (Number(item.finishedCount) || 0), 0);
  227. const totalCount = totalFinished + data.reduce((sum, item) => sum + (Number(item.notWatchedCount) || 0), 0);
  228. if (totalCount > 0) {
  229. const rate = (totalFinished / totalCount * 100).toFixed(2);
  230. sums[index] = `${rate}%`;
  231. } else {
  232. sums[index] = '0.00%';
  233. }
  234. } else if (column.property === 'correctRate') {
  235. const totalAnswered = data.reduce((sum, item) => sum + (Number(item.answeredCount) || 0), 0);
  236. const totalCorrect = data.reduce((sum, item) => sum + (Number(item.correctCount) || 0), 0);
  237. if (totalAnswered > 0) {
  238. const rate = (totalCorrect / totalAnswered * 100).toFixed(2);
  239. sums[index] = `${rate}%`;
  240. } else {
  241. sums[index] = '0.00%';
  242. }
  243. } else {
  244. sums[index] = '';
  245. }
  246. });
  247. return sums;
  248. },
  249. /** 查询列表 */
  250. getList() {
  251. this.loading = true;
  252. appWatchCourseStatistics(this.queryParams).then(response => {
  253. this.packageList = response.rows;
  254. this.total = response.total;
  255. this.loading = false;
  256. }).catch(() => {
  257. this.loading = false;
  258. });
  259. },
  260. /** 导出按钮操作 */
  261. handleExport() {
  262. this.$confirm('是否确认导出 APP 看课统计数据项?', "警告", {
  263. confirmButtonText: "确定",
  264. cancelButtonText: "取消",
  265. type: "warning"
  266. }).then(() => {
  267. this.exportLoading = true;
  268. return appWatchCourseStatisticsExport(this.queryParams);
  269. }).then(response => {
  270. this.download(response.msg);
  271. this.exportLoading = false;
  272. }).catch(() => {
  273. this.exportLoading = false;
  274. });
  275. },
  276. /** 时间格式化 */
  277. parseTime(time, pattern) {
  278. if (!time) return null;
  279. const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}';
  280. let date;
  281. if (typeof time === 'string') {
  282. date = new Date(time.replace(/-/g, '/'));
  283. } else {
  284. date = new Date(time);
  285. }
  286. const year = date.getFullYear();
  287. const month = date.getMonth() + 1;
  288. const day = date.getDate();
  289. const hour = date.getHours();
  290. const minute = date.getMinutes();
  291. const second = date.getSeconds();
  292. const obj = {
  293. '{y}': year,
  294. '{m}': month < 10 ? '0' + month : month,
  295. '{d}': day < 10 ? '0' + day : day,
  296. '{h}': hour < 10 ? '0' + hour : hour,
  297. '{i}': minute < 10 ? '0' + minute : minute,
  298. '{s}': second < 10 ? '0' + second : second
  299. };
  300. return format.replace(/\{(\w+)\}/g, (match, key) => obj[`{${key}}`] || match);
  301. }
  302. }
  303. };
  304. </script>
  305. <style scoped>.mb8 {
  306. margin-bottom: 8px;
  307. }
  308. ::v-deep .el-table .el-table__header th {
  309. background-color: #f5f7fa;
  310. }
  311. ::v-deep .el-table__body-wrapper {
  312. overflow-y: auto;
  313. }
  314. </style>