index.vue 21 KB

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