index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  4. <!-- <el-form-item label="销售公司" prop="companyId">-->
  5. <!-- <el-select filterable v-model="queryParams.companyId" clearable placeholder="请选择公司名" size="small">-->
  6. <!-- <el-option-->
  7. <!-- v-for="item in companyList"-->
  8. <!-- :key="item.companyId"-->
  9. <!-- :label="item.companyName"-->
  10. <!-- :value="item.companyId"-->
  11. <!-- />-->
  12. <!-- </el-select>-->
  13. <!-- </el-form-item>-->
  14. <el-form-item label="公司名" prop="companyId">
  15. <select-tree
  16. v-model="selectedCompanyList"
  17. :raw-data="deptList"
  18. placeholder="请选择销售"
  19. :parentSelectable="true"
  20. :multiple="true"
  21. component-width="300px"
  22. :max-display-tags="3"
  23. :check-strictly="false"
  24. :return-leaf-only="false"
  25. ></select-tree>
  26. </el-form-item>
  27. <el-form-item label="课程" prop="courseId">
  28. <el-select filterable v-model="queryParams.courseId" placeholder="请选择课程" clearable size="small" @change="courseChange(queryParams.courseId)">
  29. <el-option
  30. v-for="dict in courseLists"
  31. :key="dict.dictValue"
  32. :label="dict.dictLabel"
  33. :value="dict.dictValue"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="小节" prop="videoId">
  38. <el-select filterable v-model="queryParams.videoId" placeholder="请选择小节" clearable size="small">
  39. <el-option
  40. v-for="dict in videoList"
  41. :key="dict.dictValue"
  42. :label="dict.dictLabel"
  43. :value="dict.dictValue"
  44. />
  45. </el-select>
  46. </el-form-item>
  47. <el-form-item label="营期时间" prop="scheduleTime">
  48. <el-date-picker
  49. v-model="scheduleTime"
  50. type="daterange"
  51. size="small"
  52. style="width: 240px"
  53. value-format="yyyy-MM-dd"
  54. range-separator="-"
  55. start-placeholder="开始日期"
  56. end-placeholder="结束日期"
  57. @change="handleScheduleTimeChange">
  58. </el-date-picker>
  59. </el-form-item>
  60. <!-- <el-form-item label="创建时间" prop="createTime">-->
  61. <!-- <el-date-picker v-model="createTime" size="small" style="width: 220px" value-format="yyyy-MM-dd"-->
  62. <!-- type="daterange"-->
  63. <!-- :required="true"-->
  64. <!-- range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="createChange"></el-date-picker>-->
  65. <!-- </el-form-item>-->
  66. <el-form-item label="创建时间" prop="createTime">
  67. <el-date-picker
  68. v-model="createTime"
  69. type="datetimerange"
  70. range-separator="至"
  71. start-placeholder="开始日期"
  72. end-placeholder="结束日期"
  73. value-format="yyyy-MM-dd HH:mm:ss"
  74. @change="createChange"
  75. :default-time="['00:00:00', '23:59:59']"
  76. />
  77. </el-form-item>
  78. <el-form-item label="最新更新时间" prop="updateTime">
  79. <el-date-picker v-model="updateTime" size="small" style="width: 220px" value-format="yyyy-MM-dd" type="daterange"
  80. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="updateChange"></el-date-picker>
  81. </el-form-item>
  82. <el-form-item>
  83. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  84. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  85. </el-form-item>
  86. </el-form>
  87. <el-row :gutter="10" class="mb8">
  88. <el-col :span="1.5">
  89. <el-button
  90. type="warning"
  91. plain
  92. icon="el-icon-download"
  93. size="mini"
  94. :loading="exportLoading"
  95. @click="handleExport"
  96. v-hasPermi="['course:courseWatchLog:export']"
  97. >导出</el-button>
  98. </el-col>
  99. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  100. </el-row>
  101. <el-tabs type="card" v-model="activeName" @tab-click="handleClickX">
  102. <el-tab-pane label="全部" name="00"></el-tab-pane>
  103. <el-tab-pane v-for="(item,index) in logTypeOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
  104. </el-tabs>
  105. <el-table border v-loading="loading" :data="courseWatchLogList" @selection-change="handleSelectionChange">
  106. <el-table-column type="selection" width="55" align="center" />
  107. <el-table-column label="记录编号" align="center" prop="logId" />
  108. <el-table-column label="用户账号" align="center" prop="qwUserName" />
  109. <el-table-column label="企微客户" align="center" prop="externalUserName">
  110. <template slot-scope="scope">
  111. <div style="display: flex;white-space: nowrap">
  112. <div style="margin: auto">
  113. {{scope.row.externalUserName}}
  114. </div>
  115. <el-popover
  116. placement="right"
  117. title=""
  118. trigger="hover">
  119. <img slot="reference" :src="scope.row.externalUserAvatar" style="width: 30px;height: 30px">
  120. <img :src="scope.row.externalUserAvatar" style="max-width: 200px;max-height: 200px">
  121. </el-popover>
  122. </div>
  123. </template>
  124. </el-table-column>
  125. <el-table-column label="会员昵称" align="center" prop="fsNickName">
  126. <template slot-scope="scope">
  127. <div style="display: flex;white-space: nowrap">
  128. <div style="margin: auto">
  129. {{scope.row.fsNickName}}
  130. </div>
  131. <el-popover
  132. placement="right"
  133. title=""
  134. trigger="hover">
  135. <img slot="reference" :src="scope.row.fsAvatar" style="width: 30px;height: 30px">
  136. <img :src="scope.row.fsAvatar" style="max-width: 200px;max-height: 200px">
  137. </el-popover>
  138. </div>
  139. </template>
  140. </el-table-column>
  141. <el-table-column label="项目" align="center" prop="projectName" />
  142. <el-table-column label="课程名称" align="center" prop="courseName" />
  143. <el-table-column label="小节名称" align="center" prop="videoName" />
  144. <el-table-column label="企微员工名称" align="center" prop="qwUserName" v-if="queryParams.sourceType == 2"/>
  145. <el-table-column label="记录类型" align="center" prop="logType">
  146. <template slot-scope="scope">
  147. <dict-tag :options="logTypeOptions" :value="scope.row.logType"/>
  148. </template>
  149. </el-table-column>
  150. <el-table-column label="播放时长" align="center" prop="duration" />
  151. <el-table-column label="所属销售" align="center" prop="companyUserName" />
  152. <!-- <el-table-column label="所属公司" align="center" prop="companyName" />-->
  153. <!-- <el-table-column label="企微员工名称" align="center" prop="qwUserName" />-->
  154. <el-table-column label="所属发送方式" align="center" prop="sendType" />
  155. <el-table-column label="创建时间" align="center" prop="createTime" />
  156. <el-table-column label="更新时间" align="center" prop="updateTime" />
  157. <el-table-column label="完课时间" align="center" prop="finishTime" />
  158. <el-table-column label="营期时间" align="center" prop="campPeriodTime" />
  159. </el-table>
  160. <pagination
  161. v-show="total>0"
  162. :total="total"
  163. :page.sync="queryParams.pageNum"
  164. :limit.sync="queryParams.pageSize"
  165. @pagination="getList"
  166. />
  167. </div>
  168. </template>
  169. <script>
  170. import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog } from "@/api/course/courseWatchLog";
  171. import { allList, getCompanyList } from '@/api/company/company'
  172. import { courseList,videoList } from '@/api/course/courseRedPacketLog'
  173. import {getUserList} from "@/api/company/companyUser";
  174. import {getFsUserList} from "@/api/users/user";
  175. import SelectTree from '@/components/TreeSelect/index.vue'
  176. import { getDeptData } from '@/api/system/employeeStats'
  177. export default {
  178. name: "CourseWatchLog",
  179. components: { SelectTree },
  180. data() {
  181. return {
  182. selectedCompanyList: [],
  183. deptList: [],
  184. userSourceTypeOptions: [],
  185. activeName:"00",
  186. createTime:null,
  187. updateTime:null,
  188. courseLists:[],
  189. videoList:[],
  190. logTypeOptions:[],
  191. companyList: [],
  192. queryUserLoading: false,
  193. // 遮罩层
  194. loading: true,
  195. // 导出遮罩层
  196. exportLoading: false,
  197. // 选中数组
  198. ids: [],
  199. // 非单个禁用
  200. single: true,
  201. // 非多个禁用
  202. multiple: true,
  203. // 显示搜索条件
  204. showSearch: true,
  205. // 总条数
  206. total: 0,
  207. companyUserList: [],
  208. // 短链课程看课记录表格数据
  209. courseWatchLogList: [],
  210. fsUserList: [],
  211. // 弹出层标题
  212. title: "",
  213. // 是否显示弹出层
  214. open: false,
  215. // 查询参数
  216. queryParams: {
  217. pageNum: 1,
  218. pageSize: 10,
  219. userId: null,
  220. nickName: null,
  221. videoId: null,
  222. logType: null,
  223. qwExternalContactId: null,
  224. externalUserName:null,
  225. duration: null,
  226. qwUserId: null,
  227. companyUserId: null,
  228. companyId: null,
  229. courseId: null,
  230. sTime:null,
  231. eTime:null,
  232. upSTime:null,
  233. upETime:null,
  234. scheduleStartTime: null,
  235. scheduleEndTime: null,
  236. sourceType: 1
  237. },
  238. // 表单参数
  239. form: {},
  240. // 表单校验
  241. rules: {
  242. },
  243. scheduleTime: null,
  244. };
  245. },
  246. created() {
  247. getDeptData().then(response => {
  248. this.deptList = response.data;
  249. })
  250. courseList().then(response => {
  251. this.courseLists = response.list;
  252. });
  253. getCompanyList().then(response => {
  254. this.companyList = response.data;
  255. });
  256. this.getDicts("sys_course_watch_log_type").then(response => {
  257. this.logTypeOptions = response.data;
  258. });
  259. this.getDicts('user_source_type').then(response => {
  260. this.userSourceTypeOptions = response.data;
  261. })
  262. // 设置默认当天时间 xgb 防止频繁查询大量数据
  263. this.setToday();
  264. this.getList();
  265. this.loading = false;
  266. },
  267. computed: {
  268. sourceTypeModel: {
  269. get() {
  270. return this.queryParams.sourceType !== null && this.queryParams.sourceType !== undefined ? this.queryParams.sourceType.toString() : null;
  271. },
  272. set(newVal) {
  273. this.queryParams.sourceType = newVal;
  274. }
  275. }
  276. },
  277. methods: {
  278. setToday(){
  279. const today = new Date();
  280. const todayStart = new Date(today);
  281. todayStart.setHours(0, 0, 0, 0);
  282. const todayEnd = new Date(today);
  283. todayEnd.setHours(23, 59, 59, 999);
  284. this.createTime = [this.formatDate(todayStart), this.formatDate(todayEnd)];
  285. this.queryParams.sTime = this.formatDate(todayStart);
  286. this.queryParams.eTime = this.formatDate(todayEnd);
  287. },
  288. formatDate(date) {
  289. if (!date) return ''
  290. // 确保 date 是 Date 对象
  291. let dateObj = date
  292. if (typeof date === 'string') {
  293. dateObj = new Date(date)
  294. }
  295. // 如果转换失败,返回空字符串
  296. if (!(dateObj instanceof Date) || isNaN(dateObj.getTime())) {
  297. return ''
  298. }
  299. // 使用更安全的格式化方法
  300. const year = dateObj.getFullYear()
  301. const month = String(dateObj.getMonth() + 1).padStart(2, '0')
  302. const day = String(dateObj.getDate()).padStart(2, '0')
  303. const hours = String(dateObj.getHours()).padStart(2, '0')
  304. const minutes = String(dateObj.getMinutes()).padStart(2, '0')
  305. const seconds = String(dateObj.getSeconds()).padStart(2, '0')
  306. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  307. },
  308. handleClear(){
  309. this.queryUserLoading = false;
  310. this.fsUserList = [];
  311. },
  312. remoteGetFsUserList(query){
  313. if(query){
  314. this.queryUserLoading = true;
  315. const isNumeric = /^\d+$/.test(query);
  316. let payload = {
  317. username: query,
  318. nickname: query
  319. }
  320. if(isNumeric) {
  321. payload = {
  322. userId: query,
  323. username: query,
  324. phone: query
  325. }
  326. }
  327. getFsUserList(payload).then(res=>{
  328. if(res.code === 200) {
  329. this.fsUserList = res.data
  330. }
  331. }).finally(()=>{
  332. this.queryUserLoading = false;
  333. })
  334. }
  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. checkDateRangeLimit(dateRange) {
  347. if (dateRange && dateRange.length >= 2) {
  348. const startDate = new Date(dateRange[0]);
  349. const endDate = new Date(dateRange[1]);
  350. // 设置时间为当天开始,避免时间部分影响计算
  351. startDate.setHours(0, 0, 0, 0);
  352. endDate.setHours(0, 0, 0, 0);
  353. const timeDiff = Math.abs(endDate - startDate);
  354. const diffDays = Math.ceil(timeDiff / (1000 * 60 * 60 * 24));
  355. if (diffDays > 31) { // maxDays-1 因为包含起始日
  356. this.$message.warning('时间区间不能超过一个月');
  357. return false;
  358. }
  359. }
  360. return true;
  361. },
  362. createChange(createTime) {
  363. if (createTime && createTime.length >= 2) {
  364. if(!this.checkDateRangeLimit(createTime)){
  365. this.createTime = null;
  366. this.queryParams.sTime=null;
  367. this.queryParams.eTime=null;
  368. return;
  369. }
  370. // this.createTimeText = this.formatDateRange(createTime);
  371. this.queryParams.sTime = this.formatDate(createTime[0]) || null;
  372. this.queryParams.eTime = this.formatDate(createTime[1]) || null;
  373. } else {
  374. this.createTimeText = '';
  375. this.queryParams.sTime = null;
  376. this.queryParams.eTime = null;
  377. }
  378. },
  379. updateChange(updateTime){
  380. if (updateTime && updateTime.length >= 2) {
  381. if(!this.checkDateRangeLimit(updateTime)){
  382. this.updateTime = null;
  383. this.queryParams.upSTime=null;
  384. this.queryParams.upETime=null;
  385. return;
  386. }
  387. // this.updateTime = this.formatDateRange(updateTime);
  388. this.queryParams.upSTime = updateTime[0] || null;
  389. this.queryParams.upETime = updateTime[1] || null;
  390. } else {
  391. this.updateTime = [];
  392. this.queryParams.upSTime = null;
  393. this.queryParams.upETime = null;
  394. }
  395. },
  396. handleClickX(tab,event){
  397. this.activeName=tab.name;
  398. if(tab.name=="00"){
  399. this.queryParams.logType=null;
  400. }else{
  401. this.queryParams.logType=tab.name;
  402. }
  403. this.getList()
  404. },
  405. /** 查询短链课程看课记录列表 */
  406. getList() {
  407. // xgb 看课数据量太大必须限制时间if (this.isEmptyArray(this.createTime) &&
  408. if (this.isEmptyArray(this.createTime) &&
  409. this.isEmptyArray(this.updateTime) &&
  410. this.isEmptyArray(this.scheduleTime)) {
  411. this.$message.warning('请选择创建时间或营期时间或最新更新时间');
  412. return;
  413. }
  414. this.loading = true;
  415. if(this.queryParams.logType == "10"){
  416. this.queryParams.logType = null;
  417. }
  418. if(this.selectedCompanyList != null && this.selectedCompanyList.length > 0) {
  419. this.queryParams.userIds = this.selectedCompanyList;
  420. }else {
  421. this.queryParams.userIds = [];
  422. }
  423. listCourseWatchLog(this.queryParams).then(response => {
  424. this.courseWatchLogList = response.rows;
  425. this.total = response.total;
  426. this.loading = false;
  427. }).catch(() => {
  428. this.loading = false;
  429. }
  430. );
  431. },
  432. // 取消按钮
  433. cancel() {
  434. this.open = false;
  435. this.reset();
  436. },
  437. // 表单重置
  438. reset() {
  439. this.form = {
  440. logId: null,
  441. userId: null,
  442. videoId: null,
  443. logType: null,
  444. createTime: null,
  445. updateTime: null,
  446. qwExternalContactId: null,
  447. externalUserName:null,
  448. duration: null,
  449. qwUserId: null,
  450. companyUserId: null,
  451. companyId: null,
  452. courseId: null,
  453. scheduleStartTime: null,
  454. scheduleEndTime: null,
  455. };
  456. this.scheduleTime=null;
  457. this.resetForm("form");
  458. },
  459. /** 搜索按钮操作 */
  460. handleQuery() {
  461. this.queryParams.pageNum = 1;
  462. this.getList();
  463. },
  464. /** 重置按钮操作 */
  465. resetQuery() {
  466. this.resetForm("queryForm");
  467. // this.createTime = null;
  468. this.selectedCompanyList=[];
  469. this.scheduleTime = null;
  470. // this.queryParams.sTime = null;
  471. // this.queryParams.eTime = null;
  472. this.queryParams.upSTime = null;
  473. this.queryParams.upETime = null;
  474. this.queryParams.scheduleStartTime = null;
  475. this.queryParams.scheduleEndTime = null;
  476. this.scheduleTime=null;
  477. this.updateTime=null;
  478. // 重置时间当天
  479. this.setToday();
  480. this.handleQuery();
  481. },
  482. // 多选框选中数据
  483. handleSelectionChange(selection) {
  484. this.ids = selection.map(item => item.logId)
  485. this.single = selection.length!==1
  486. this.multiple = !selection.length
  487. },
  488. /** 新增按钮操作 */
  489. handleAdd() {
  490. this.reset();
  491. this.open = true;
  492. this.title = "添加短链课程看课记录";
  493. },
  494. /** 修改按钮操作 */
  495. handleUpdate(row) {
  496. this.reset();
  497. const logId = row.logId || this.ids
  498. getCourseWatchLog(logId).then(response => {
  499. this.form = response.data;
  500. this.open = true;
  501. this.title = "修改短链课程看课记录";
  502. });
  503. },
  504. /** 提交按钮 */
  505. submitForm() {
  506. this.$refs["form"].validate(valid => {
  507. if (valid) {
  508. if (this.form.logId != null) {
  509. updateCourseWatchLog(this.form).then(response => {
  510. this.msgSuccess("修改成功");
  511. this.open = false;
  512. this.getList();
  513. });
  514. } else {
  515. addCourseWatchLog(this.form).then(response => {
  516. this.msgSuccess("新增成功");
  517. this.open = false;
  518. this.getList();
  519. });
  520. }
  521. }
  522. });
  523. },
  524. /** 删除按钮操作 */
  525. handleDelete(row) {
  526. const logIds = row.logId || this.ids;
  527. this.$confirm('是否确认删除短链课程看课记录编号为"' + logIds + '"的数据项?', "警告", {
  528. confirmButtonText: "确定",
  529. cancelButtonText: "取消",
  530. type: "warning"
  531. }).then(function() {
  532. return delCourseWatchLog(logIds);
  533. }).then(() => {
  534. this.getList();
  535. this.msgSuccess("删除成功");
  536. }).catch(() => {});
  537. },
  538. // 添加辅助方法
  539. isEmptyArray(arr) {
  540. return !arr || arr.length === 0;
  541. },
  542. /** 导出按钮操作 */
  543. handleExport() {
  544. // xgb 看课数据量太大必须限制时间
  545. if (this.isEmptyArray(this.createTime) &&
  546. this.isEmptyArray(this.updateTime) &&
  547. this.isEmptyArray(this.scheduleTime)) {
  548. this.$message.warning('请选择创建时间或营期时间或最新更新时间');
  549. return;
  550. }
  551. const queryParams = this.queryParams;
  552. this.$confirm('是否确认导出所有短链课程看课记录数据项?', "警告", {
  553. confirmButtonText: "确定",
  554. cancelButtonText: "取消",
  555. type: "warning"
  556. }).then(() => {
  557. this.exportLoading = true;
  558. return exportCourseWatchLog(queryParams);
  559. }).then(response => {
  560. this.download(response.msg);
  561. this.exportLoading = false;
  562. }).catch(() => {});
  563. },
  564. handleScheduleTimeChange(scheduleTime) {
  565. if (scheduleTime && scheduleTime.length >= 2) {
  566. if(!this.checkDateRangeLimit(scheduleTime)){
  567. this.scheduleTime = null;
  568. this.queryParams.scheduleStartTime=null;
  569. this.queryParams.scheduleStartTime=null;
  570. return;
  571. }
  572. // this.scheduleTime = this.formatDateRange(scheduleTime);
  573. this.queryParams.scheduleStartTime = scheduleTime[0] || null;
  574. this.queryParams.scheduleEndTime = scheduleTime[1] || null;
  575. } else {
  576. this.scheduleTime = [];
  577. this.queryParams.scheduleStartTime = null;
  578. this.queryParams.scheduleEndTime = null;
  579. }
  580. },
  581. }
  582. };
  583. </script>