statistics.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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>
  72. <pagination
  73. v-show="total>0"
  74. :total="total"
  75. :page.sync="queryParams.pageNum"
  76. :limit.sync="queryParams.pageSize"
  77. @pagination="getList"
  78. />
  79. </div>
  80. </template>
  81. <script>
  82. import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog,statisticsList,statisticsExport } from "@/api/course/qw/courseWatchLog";
  83. import { courseList,videoList } from '@/api/course/courseRedPacketLog'
  84. import { getDateRange } from '@/utils/common'
  85. export default {
  86. name: "CourseWatchLog",
  87. data() {
  88. return {
  89. activeName:"00",
  90. createTime:null,
  91. courseLists:[],
  92. videoList:[],
  93. logTypeOptions:[],
  94. // 遮罩层
  95. loading: true,
  96. // 导出遮罩层
  97. exportLoading: false,
  98. // 选中数组
  99. ids: [],
  100. // 非单个禁用
  101. single: true,
  102. // 非多个禁用
  103. multiple: true,
  104. // 显示搜索条件
  105. showSearch: true,
  106. // 总条数
  107. total: 0,
  108. // 短链课程看课记录表格数据
  109. courseWatchLogList: [],
  110. // 弹出层标题
  111. title: "",
  112. // 是否显示弹出层
  113. open: false,
  114. // 查询参数
  115. queryParams: {
  116. pageNum: 1,
  117. pageSize: 10,
  118. userId: null,
  119. nickName: null,
  120. videoId: null,
  121. logType: null,
  122. qwExternalContactId: null,
  123. duration: null,
  124. qwUserId: null,
  125. companyUserId: null,
  126. companyId: null,
  127. courseId: null,
  128. sTime:null,
  129. eTime:null,
  130. scheduleStartTime: null,
  131. scheduleEndTime: null,
  132. },
  133. // 表单参数
  134. form: {},
  135. // 表单校验
  136. rules: {
  137. },
  138. scheduleTime: null,
  139. };
  140. },
  141. created() {
  142. // // 设置默认时间范围为最近7天
  143. // this.createTime = getDateRange(7);
  144. // // 设置查询参数的时间
  145. // this.queryParams.sTime = this.createTime[0];
  146. // this.queryParams.eTime = this.createTime[1];
  147. courseList().then(response => {
  148. this.courseLists = response.list;
  149. });
  150. this.getList();
  151. this.getDicts("sys_course_watch_log_type").then(response => {
  152. this.logTypeOptions = response.data;
  153. });
  154. },
  155. methods: {
  156. getSummaries(param) {
  157. let totalNum = 0;
  158. const { columns, data } = param;
  159. const sums = [];
  160. let totalOnline = 0;
  161. let totalFinishCourse = 0;
  162. columns.forEach((column, index) => {
  163. if (index === 0) {
  164. sums[index] = "总计";
  165. return;
  166. }
  167. const values = data.map((item) => Number(item[column.property]));
  168. if (!values.every((value) => isNaN(value))) {
  169. sums[index] = values.reduce((prev, curr) => {
  170. const value = Number(curr);
  171. if (!isNaN(value)) {
  172. return prev + curr;
  173. } else {
  174. return prev;
  175. }
  176. }, 0);
  177. if(index > 3 && totalNum != 0){
  178. sums[index] = sums[index] + "("+ ((sums[index] / totalNum) * 100).toFixed(2) + "%)"
  179. }
  180. if( column.property=="videoName"){
  181. sums[index] = "";
  182. }
  183. if (
  184. column.property === "type3" ||
  185. column.property === "type1" ||
  186. column.property === "type2" ||
  187. column.property === "type4" ||
  188. column.property === "sendNumber" ||
  189. column.property === "isUserWaitNumber" ||
  190. column.property === "noUserWaitNumber" ||
  191. column.property === "onLineRate" ||
  192. column.property === "finishedRate" ||
  193. column.property === "redAmount"
  194. ) {
  195. }
  196. } else {
  197. sums[index] = "";
  198. if(index === 12 || index === 13){
  199. // let numbers = data.map(item => {
  200. // return parseFloat(item[column.property].replace('%', '')) || 0; // 处理空值或无效值
  201. // });
  202. // let sumRates = numbers.reduce((acc, curr) => acc + curr, 0);
  203. // console.log("index:" + index + " rates:" + sumRates + " data.length:" + data.length);
  204. if(index === 12 && !!sums[9]){
  205. let sumsNum = sums[6] + sums[7] + sums[8];
  206. sums[index] = (sumsNum * 100 / sums[9]).toFixed(2) + '%';
  207. } else if(index === 13 && !!sums[9]){
  208. sums[index] = (sums[7] * 100 / sums[9]).toFixed(2) + '%';
  209. }
  210. }
  211. }
  212. });
  213. console.log(sums);
  214. return sums;
  215. },
  216. courseChange(row){
  217. this.queryParams.videoId=null;
  218. if(row === ''){
  219. this.videoList=[];
  220. return
  221. }
  222. videoList(row).then(response => {
  223. this.videoList=response.list
  224. });
  225. },
  226. change() {
  227. if (this.createTime != null) {
  228. this.queryParams.sTime = this.createTime[0];
  229. this.queryParams.eTime = this.createTime[1];
  230. } else {
  231. this.queryParams.sTime = null;
  232. this.queryParams.eTime = null;
  233. }
  234. },
  235. handleClickX(tab,event){
  236. this.activeName=tab.name;
  237. if(tab.name=="00"){
  238. this.queryParams.logType=null;
  239. }else{
  240. this.queryParams.logType=tab.name;
  241. }
  242. this.getList()
  243. },
  244. /** 查询短链课程看课记录列表 */
  245. getList() {
  246. this.loading = true;
  247. statisticsList(this.queryParams).then(response => {
  248. this.courseWatchLogList = response.rows;
  249. this.total = response.total;
  250. this.loading = false;
  251. });
  252. },
  253. // 取消按钮
  254. cancel() {
  255. this.open = false;
  256. this.reset();
  257. },
  258. // 表单重置
  259. reset() {
  260. this.form = {
  261. logId: null,
  262. userId: null,
  263. videoId: null,
  264. logType: null,
  265. createTime: null,
  266. updateTime: null,
  267. qwExternalContactId: null,
  268. duration: null,
  269. qwUserId: null,
  270. companyUserId: null,
  271. companyId: null,
  272. courseId: null
  273. };
  274. this.resetForm("form");
  275. },
  276. /** 搜索按钮操作 */
  277. handleQuery() {
  278. if (!this.queryParams.sTime || !this.queryParams.eTime) {
  279. this.$message.warning("请选择创建时间");
  280. return;
  281. }
  282. this.queryParams.pageNum = 1;
  283. this.getList();
  284. },
  285. /** 重置按钮操作 */
  286. resetQuery() {
  287. this.resetForm("queryForm");
  288. this.createTime = null;
  289. this.scheduleTime = null;
  290. this.queryParams.sTime = null;
  291. this.queryParams.eTime = null;
  292. this.queryParams.scheduleStartTime = null;
  293. this.queryParams.scheduleEndTime = null;
  294. this.handleQuery();
  295. },
  296. // 多选框选中数据
  297. handleSelectionChange(selection) {
  298. this.ids = selection.map(item => item.logId)
  299. this.single = selection.length!==1
  300. this.multiple = !selection.length
  301. },
  302. /** 新增按钮操作 */
  303. handleAdd() {
  304. this.reset();
  305. this.open = true;
  306. this.title = "添加短链课程看课记录";
  307. },
  308. /** 修改按钮操作 */
  309. handleUpdate(row) {
  310. this.reset();
  311. const logId = row.logId || this.ids
  312. getCourseWatchLog(logId).then(response => {
  313. this.form = response.data;
  314. this.open = true;
  315. this.title = "修改短链课程看课记录";
  316. });
  317. },
  318. /** 提交按钮 */
  319. submitForm() {
  320. this.$refs["form"].validate(valid => {
  321. if (valid) {
  322. if (this.form.logId != null) {
  323. updateCourseWatchLog(this.form).then(response => {
  324. this.msgSuccess("修改成功");
  325. this.open = false;
  326. this.getList();
  327. });
  328. } else {
  329. addCourseWatchLog(this.form).then(response => {
  330. this.msgSuccess("新增成功");
  331. this.open = false;
  332. this.getList();
  333. });
  334. }
  335. }
  336. });
  337. },
  338. /** 删除按钮操作 */
  339. handleDelete(row) {
  340. const logIds = row.logId || this.ids;
  341. this.$confirm('是否确认删除短链课程看课记录编号为"' + logIds + '"的数据项?', "警告", {
  342. confirmButtonText: "确定",
  343. cancelButtonText: "取消",
  344. type: "warning"
  345. }).then(function() {
  346. return delCourseWatchLog(logIds);
  347. }).then(() => {
  348. this.getList();
  349. this.msgSuccess("删除成功");
  350. }).catch(() => {});
  351. },
  352. /** 导出按钮操作 */
  353. handleExport() {
  354. // 检查是否选择了时间范围
  355. if (!this.queryParams.sTime || !this.queryParams.eTime) {
  356. this.$message.warning("请选择创建时间后才能导出");
  357. return;
  358. }
  359. const queryParams = this.queryParams;
  360. this.$confirm('是否确认导出所有企微看课记录数据项?', "警告", {
  361. confirmButtonText: "确定",
  362. cancelButtonText: "取消",
  363. type: "warning"
  364. }).then(() => {
  365. this.exportLoading = true;
  366. return statisticsExport(queryParams);
  367. }).then(response => {
  368. this.download(response.msg);
  369. this.exportLoading = false;
  370. }).catch(() => {});
  371. },
  372. handleScheduleTimeChange(val) {
  373. if (val) {
  374. this.queryParams.scheduleStartTime = val[0];
  375. this.queryParams.scheduleEndTime = val[1];
  376. } else {
  377. this.queryParams.scheduleStartTime = null;
  378. this.queryParams.scheduleEndTime = null;
  379. }
  380. },
  381. }
  382. };
  383. </script>