index.vue 21 KB

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