statistics.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="课程" prop="courseId">
  5. <el-select filterable v-model="queryParams.courseId" placeholder="请选择课程" clearable size="small" @change="courseChange(queryParams.courseId)">
  6. <el-option
  7. v-for="dict in courseLists"
  8. :key="dict.dictValue"
  9. :label="dict.dictLabel"
  10. :value="dict.dictValue"
  11. />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="小节" prop="videoId">
  15. <el-select filterable v-model="queryParams.videoId" placeholder="请选择小节" clearable size="small">
  16. <el-option
  17. v-for="dict in videoList"
  18. :key="dict.dictValue"
  19. :label="dict.dictLabel"
  20. :value="dict.dictValue"
  21. />
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="企微昵称" prop="nickName">
  25. <el-input
  26. v-model="queryParams.nickName"
  27. placeholder="请输入企微昵称"
  28. clearable
  29. size="small"
  30. @keyup.enter.native="handleQuery"
  31. />
  32. </el-form-item>
  33. <el-form-item label="创建时间" prop="createTime">
  34. <el-date-picker v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  38. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  39. </el-form-item>
  40. </el-form>
  41. <el-row :gutter="10" class="mb8">
  42. <el-col :span="1.5">
  43. <el-button
  44. type="warning"
  45. plain
  46. icon="el-icon-download"
  47. size="mini"
  48. :loading="exportLoading"
  49. @click="handleExport"
  50. v-hasPermi="['qw:user:export']"
  51. >导出</el-button>
  52. </el-col>
  53. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  54. </el-row>
  55. <el-table border v-loading="loading" :data="courseWatchLogList" @selection-change="handleSelectionChange" show-summary :summary-method="getSummaries" >
  56. <el-table-column type="selection" width="55" align="center" />
  57. <el-table-column label="企微员工名称" align="center" prop="qwUserName" />
  58. <el-table-column label="发课时间" align="center" prop="createTime"/>
  59. <el-table-column label="课程名称" align="center" prop="courseName" />
  60. <el-table-column label="小节名称" align="center" prop="videoName" />
  61. <el-table-column label="待看课" align="center" prop="type3" />
  62. <el-table-column label="看课中" align="center" prop="type1" />
  63. <el-table-column label="已完课" align="center" prop="type2" />
  64. <el-table-column label="看课中断" align="center" prop="type4" />
  65. <el-table-column label="发课数" align="center" prop="sendNumber" />
  66. <el-table-column label="注册用户待看课数" align="center" prop="isUserWaitNumber" />
  67. <el-table-column label="未注册用户待看课数" align="center" prop="noUserWaitNumber" />
  68. <el-table-column label="上线率" align="center" prop="onLineRate" />
  69. <el-table-column label="完课率" align="center" prop="finishedRate" />
  70. <!-- <el-table-column label="消耗红包金额" align="center" prop="redAmount" />-->
  71. <el-table-column label="上线客户完播率" align="center" prop="onLineCompleteRate" />
  72. <!-- <el-table-column label="流失人数" align="center" prop="onLineNum" />-->
  73. </el-table>
  74. <pagination
  75. v-show="total>0"
  76. :total="total"
  77. :page.sync="queryParams.pageNum"
  78. :limit.sync="queryParams.pageSize"
  79. @pagination="getList"
  80. />
  81. </div>
  82. </template>
  83. <script>
  84. import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog,statisticsList,statisticsExport } from "@/api/course/qw/courseWatchLog";
  85. import { courseList,videoList } from '@/api/course/courseRedPacketLog'
  86. import { getDateRange } from '@/utils/common'
  87. export default {
  88. name: "CourseWatchLog",
  89. data() {
  90. return {
  91. activeName:"00",
  92. createTime:null,
  93. courseLists:[],
  94. videoList:[],
  95. logTypeOptions:[],
  96. // 遮罩层
  97. loading: true,
  98. // 导出遮罩层
  99. exportLoading: false,
  100. // 选中数组
  101. ids: [],
  102. // 非单个禁用
  103. single: true,
  104. // 非多个禁用
  105. multiple: true,
  106. // 显示搜索条件
  107. showSearch: true,
  108. // 总条数
  109. total: 0,
  110. // 短链课程看课记录表格数据
  111. courseWatchLogList: [],
  112. // 弹出层标题
  113. title: "",
  114. // 是否显示弹出层
  115. open: false,
  116. // 查询参数
  117. queryParams: {
  118. pageNum: 1,
  119. pageSize: 10,
  120. userId: null,
  121. nickName: null,
  122. videoId: null,
  123. logType: null,
  124. qwExternalContactId: null,
  125. duration: null,
  126. qwUserId: null,
  127. companyUserId: null,
  128. companyId: null,
  129. courseId: null,
  130. sTime:null,
  131. eTime:null,
  132. scheduleStartTime: null,
  133. scheduleEndTime: null,
  134. },
  135. // 表单参数
  136. form: {},
  137. // 表单校验
  138. rules: {
  139. },
  140. scheduleTime: null,
  141. };
  142. },
  143. created() {
  144. // // 设置默认时间范围为最近7天
  145. // this.createTime = getDateRange(7);
  146. // // 设置查询参数的时间
  147. // this.queryParams.sTime = this.createTime[0];
  148. // this.queryParams.eTime = this.createTime[1];
  149. courseList().then(response => {
  150. this.courseLists = response.list;
  151. });
  152. this.getList();
  153. this.getDicts("sys_course_watch_log_type").then(response => {
  154. this.logTypeOptions = response.data;
  155. });
  156. },
  157. methods: {
  158. bfGetSummaries(param) {//以前的代码备份
  159. let totalNum = 0;
  160. const { columns, data } = param;
  161. const sums = [];
  162. let totalOnline = 0;
  163. let totalFinishCourse = 0;
  164. columns.forEach((column, index) => {
  165. if (index === 0) {
  166. sums[index] = "总计";
  167. return;
  168. }
  169. const values = data.map((item) => Number(item[column.property]));
  170. if (!values.every((value) => isNaN(value))) {
  171. sums[index] = values.reduce((prev, curr) => {
  172. const value = Number(curr);
  173. if (!isNaN(value)) {
  174. return prev + curr;
  175. } else {
  176. return prev;
  177. }
  178. }, 0);
  179. if(index > 3 && totalNum !== 0){
  180. sums[index] = sums[index] + "("+ ((sums[index] / totalNum) * 100).toFixed(2) + "%)"
  181. }
  182. if( column.property=="videoName"){
  183. sums[index] = "";
  184. }
  185. if (
  186. column.property === "type3" ||
  187. column.property === "type1" ||
  188. column.property === "type2" ||
  189. column.property === "type4" ||
  190. column.property === "sendNumber" ||
  191. column.property === "isUserWaitNumber" ||
  192. column.property === "noUserWaitNumber" ||
  193. column.property === "onLineRate" ||
  194. column.property === "finishedRate" ||
  195. column.property === "redAmount" ||
  196. column.property === "onLineCompleteRate"
  197. ) {
  198. }
  199. } else {
  200. sums[index] = "";
  201. if(index === 12 || index === 13 || index===14){
  202. // let numbers = data.map(item => {
  203. // return parseFloat(item[column.property].replace('%', '')) || 0; // 处理空值或无效值
  204. // });
  205. // let sumRates = numbers.reduce((acc, curr) => acc + curr, 0);
  206. // console.log("index:" + index + " rates:" + sumRates + " data.length:" + data.length);
  207. if(index === 12 && !!sums[9]){
  208. let sumsNum = sums[6] + sums[7] + sums[8];
  209. sums[index] = (sumsNum * 100 / sums[9]).toFixed(2) + '%';
  210. } else if(index === 13 && !!sums[9]){
  211. sums[index] = (sums[7] * 100 / sums[9]).toFixed(2) + '%';
  212. }
  213. else if(index === 14 && !!sums[9]){
  214. sums[index] = (sums[7] * 100 / sums[9]).toFixed(2) + '%';
  215. }
  216. }
  217. }
  218. });
  219. console.log(sums);
  220. return sums;
  221. },
  222. getSummaries(param) {
  223. const { columns, data } = param;
  224. const sums = [];
  225. // 计算各种总数
  226. let totalSendNumber = 0;
  227. let totalType1 = 0;
  228. let totalType2 = 0;
  229. let totalType3 = 0;
  230. let totalType4 = 0;
  231. let totalIsUserWaitNumber = 0;
  232. let totalNoUserWaitNumber = 0;
  233. let totalOnLineNum = 0;
  234. // 百分比直接累加(不是平均)
  235. let totalOnLineRate = 0; // 上线率合计
  236. let totalFinishedRate = 0; // 完课率合计
  237. let totalOnLineCompleteRate = 0; // 上线客户完播率合计
  238. // 遍历数据
  239. data.forEach(item => {
  240. // 数字字段累加
  241. totalSendNumber += Number(item.sendNumber) || 0;
  242. totalType1 += Number(item.type1) || 0;
  243. totalType2 += Number(item.type2) || 0;
  244. totalType3 += Number(item.type3) || 0;
  245. totalType4 += Number(item.type4) || 0;
  246. totalIsUserWaitNumber += Number(item.isUserWaitNumber) || 0;
  247. totalNoUserWaitNumber += Number(item.noUserWaitNumber) || 0;
  248. // 计算本行的上线人数
  249. const itemOnLineNum = (Number(item.type1) || 0) + (Number(item.type2) || 0) + (Number(item.type4) || 0);
  250. totalOnLineNum += itemOnLineNum;
  251. // 提取百分比字段的值(去除%号)
  252. const parsePercentage = (value) => {
  253. if (!value && value !== 0) return 0;
  254. if (typeof value === 'string') {
  255. // 处理"5.00%"格式
  256. const num = parseFloat(value.replace('%', ''));
  257. return isNaN(num) ? 0 : num;
  258. }
  259. return Number(value) || 0;
  260. };
  261. // 累加上线率
  262. totalOnLineRate += parsePercentage(item.onLineRate);
  263. // 累加完课率
  264. totalFinishedRate += parsePercentage(item.finishedRate);
  265. // 累加上线客户完播率
  266. totalOnLineCompleteRate += parsePercentage(item.onLineCompleteRate);
  267. });
  268. columns.forEach((column, index) => {
  269. if (index === 0) {
  270. sums[index] = "总计";
  271. return;
  272. }
  273. const property = column.property;
  274. // 处理特殊字段
  275. if (property === "videoName" || property === "courseName" ||
  276. property === "qwUserName" || property === "createTime") {
  277. sums[index] = "";
  278. return;
  279. }
  280. // 处理百分比字段 - 直接累加的结果
  281. if (property === "onLineRate") {
  282. sums[index] = totalOnLineRate.toFixed(2) + '%';
  283. return;
  284. } else if (property === "finishedRate") {
  285. sums[index] = totalFinishedRate.toFixed(2) + '%';
  286. return;
  287. } else if (property === "onLineCompleteRate") {
  288. sums[index] = totalOnLineCompleteRate.toFixed(2) + '%';
  289. return;
  290. }
  291. // 处理普通数字字段
  292. switch (property) {
  293. case "type1":
  294. sums[index] = totalType1;
  295. break;
  296. case "type2":
  297. sums[index] = totalType2;
  298. break;
  299. case "type3":
  300. sums[index] = totalType3;
  301. break;
  302. case "type4":
  303. sums[index] = totalType4;
  304. break;
  305. case "sendNumber":
  306. sums[index] = totalSendNumber;
  307. break;
  308. case "isUserWaitNumber":
  309. sums[index] = totalIsUserWaitNumber;
  310. break;
  311. case "noUserWaitNumber":
  312. sums[index] = totalNoUserWaitNumber;
  313. break;
  314. case "redAmount":
  315. // 如果需要计算红包金额总和
  316. const redAmounts = data.map(item => Number(item.redAmount) || 0);
  317. sums[index] = redAmounts.reduce((sum, curr) => sum + curr, 0);
  318. break;
  319. default:
  320. sums[index] = "";
  321. }
  322. });
  323. console.log("统计结果:", {
  324. 发课数: totalSendNumber,
  325. 看课中: totalType1,
  326. 已完课: totalType2,
  327. 待看课: totalType3,
  328. 看课中断: totalType4,
  329. 上线人数: totalOnLineNum,
  330. 上线率合计: totalOnLineRate.toFixed(2) + '%',
  331. 完课率合计: totalFinishedRate.toFixed(2) + '%',
  332. 上线完播率合计: totalOnLineCompleteRate.toFixed(2) + '%'
  333. });
  334. return sums;
  335. },
  336. courseChange(row){
  337. this.queryParams.videoId=null;
  338. if(row === ''){
  339. this.videoList=[];
  340. return
  341. }
  342. videoList(row).then(response => {
  343. this.videoList=response.list
  344. });
  345. },
  346. change() {
  347. if (this.createTime != null) {
  348. this.queryParams.sTime = this.createTime[0];
  349. this.queryParams.eTime = this.createTime[1];
  350. } else {
  351. this.queryParams.sTime = null;
  352. this.queryParams.eTime = null;
  353. }
  354. },
  355. handleClickX(tab,event){
  356. this.activeName=tab.name;
  357. if(tab.name=="00"){
  358. this.queryParams.logType=null;
  359. }else{
  360. this.queryParams.logType=tab.name;
  361. }
  362. this.getList()
  363. },
  364. /** 查询短链课程看课记录列表 */
  365. getList() {
  366. this.loading = true;
  367. statisticsList(this.queryParams).then(response => {
  368. this.courseWatchLogList = response.rows;
  369. this.total = response.total;
  370. this.loading = false;
  371. });
  372. },
  373. // 取消按钮
  374. cancel() {
  375. this.open = false;
  376. this.reset();
  377. },
  378. // 表单重置
  379. reset() {
  380. this.form = {
  381. logId: null,
  382. userId: null,
  383. videoId: null,
  384. logType: null,
  385. createTime: null,
  386. updateTime: null,
  387. qwExternalContactId: null,
  388. duration: null,
  389. qwUserId: null,
  390. companyUserId: null,
  391. companyId: null,
  392. courseId: null
  393. };
  394. this.resetForm("form");
  395. },
  396. /** 搜索按钮操作 */
  397. handleQuery() {
  398. if (!this.queryParams.sTime || !this.queryParams.eTime) {
  399. this.$message.warning("请选择创建时间");
  400. return;
  401. }
  402. this.queryParams.pageNum = 1;
  403. this.getList();
  404. },
  405. /** 重置按钮操作 */
  406. resetQuery() {
  407. this.resetForm("queryForm");
  408. this.createTime = null;
  409. this.scheduleTime = null;
  410. this.queryParams.sTime = null;
  411. this.queryParams.eTime = null;
  412. this.queryParams.scheduleStartTime = null;
  413. this.queryParams.scheduleEndTime = null;
  414. this.handleQuery();
  415. },
  416. // 多选框选中数据
  417. handleSelectionChange(selection) {
  418. this.ids = selection.map(item => item.logId)
  419. this.single = selection.length!==1
  420. this.multiple = !selection.length
  421. },
  422. /** 新增按钮操作 */
  423. handleAdd() {
  424. this.reset();
  425. this.open = true;
  426. this.title = "添加短链课程看课记录";
  427. },
  428. /** 修改按钮操作 */
  429. handleUpdate(row) {
  430. this.reset();
  431. const logId = row.logId || this.ids
  432. getCourseWatchLog(logId).then(response => {
  433. this.form = response.data;
  434. this.open = true;
  435. this.title = "修改短链课程看课记录";
  436. });
  437. },
  438. /** 提交按钮 */
  439. submitForm() {
  440. this.$refs["form"].validate(valid => {
  441. if (valid) {
  442. if (this.form.logId != null) {
  443. updateCourseWatchLog(this.form).then(response => {
  444. this.msgSuccess("修改成功");
  445. this.open = false;
  446. this.getList();
  447. });
  448. } else {
  449. addCourseWatchLog(this.form).then(response => {
  450. this.msgSuccess("新增成功");
  451. this.open = false;
  452. this.getList();
  453. });
  454. }
  455. }
  456. });
  457. },
  458. /** 删除按钮操作 */
  459. handleDelete(row) {
  460. const logIds = row.logId || this.ids;
  461. this.$confirm('是否确认删除短链课程看课记录编号为"' + logIds + '"的数据项?', "警告", {
  462. confirmButtonText: "确定",
  463. cancelButtonText: "取消",
  464. type: "warning"
  465. }).then(function() {
  466. return delCourseWatchLog(logIds);
  467. }).then(() => {
  468. this.getList();
  469. this.msgSuccess("删除成功");
  470. }).catch(() => {});
  471. },
  472. /** 导出按钮操作 */
  473. handleExport() {
  474. // 检查是否选择了时间范围
  475. if (!this.queryParams.sTime || !this.queryParams.eTime) {
  476. this.$message.warning("请选择创建时间后才能导出");
  477. return;
  478. }
  479. const queryParams = this.queryParams;
  480. this.$confirm('是否确认导出所有企微看课记录数据项?', "警告", {
  481. confirmButtonText: "确定",
  482. cancelButtonText: "取消",
  483. type: "warning"
  484. }).then(() => {
  485. this.exportLoading = true;
  486. return statisticsExport(queryParams);
  487. }).then(response => {
  488. this.download(response.msg);
  489. this.exportLoading = false;
  490. }).catch(() => {});
  491. },
  492. handleScheduleTimeChange(val) {
  493. if (val) {
  494. this.queryParams.scheduleStartTime = val[0];
  495. this.queryParams.scheduleEndTime = val[1];
  496. } else {
  497. this.queryParams.scheduleStartTime = null;
  498. this.queryParams.scheduleEndTime = null;
  499. }
  500. },
  501. }
  502. };
  503. </script>