index.vue 18 KB

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