userCoursePeriod.vue 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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="periodName">
  5. <el-input v-model="queryParams.periodName" placeholder="请输入营期名称" clearable size="small"
  6. @keyup.enter.native="handleQuery" />
  7. </el-form-item>
  8. <el-form-item label="公司" prop="companyIdList">
  9. <el-select v-model="queryParams.companyIdList" placeholder="请选择公司" clearable size="small" multiple>
  10. <el-option v-for="item in companyOptions" :key="item.companyId" :label="item.companyName"
  11. :value="item.companyId" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="开营日期开始" prop="periodStartingTime" label-width="120px">
  15. <el-date-picker clearable size="small" style="width: 200px" v-model="queryParams.periodStartingTime"
  16. type="date" value-format="yyyy-MM-dd" placeholder="请选择开营日期开始时间">
  17. </el-date-picker>
  18. </el-form-item>
  19. <el-form-item label="开营日期结束" prop="periodEndTime" label-width="120px">
  20. <el-date-picker clearable size="small" style="width: 300px" v-model="queryParams.periodEndTime"
  21. type="date" value-format="yyyy-MM-dd" placeholder="请选择开营日期结束时间">
  22. </el-date-picker>
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery"
  26. v-hasPermi="['course:period:list']">搜索</el-button>
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. <el-table v-loading="loading" :data="periodList" @selection-change="handleSelectionChange" border>
  31. <el-table-column type="selection" width="55" align="center" />
  32. <el-table-column label="营期名称" align="center" prop="periodName" />
  33. <el-table-column label="公司名称" align="center" prop="companyName" />
  34. <el-table-column label="营期状态" align="center" prop="periodStatus" width="100"
  35. :formatter="periodStatusFormatter" />
  36. <el-table-column label="营期线" align="center" prop="periodLine" width="180" />
  37. <el-table-column label="开营开始时间" align="center" prop="periodStartingTime" width="180" />
  38. <el-table-column label="开营结束时间" align="center" prop="periodEndTime" width="180" />
  39. <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
  40. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  41. <template slot-scope="scope">
  42. <el-button size="mini" type="text" icon="el-icon-setting"
  43. @click="handlePeriodSettings(scope.row)">选择视频</el-button>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
  48. :limit.sync="queryParams.pageSize" @pagination="getList" />
  49. <!-- 营期相关设置抽屉 -->
  50. <el-drawer title="营期相关设置" :visible.sync="periodSettingsVisible" direction="rtl" size="74%"
  51. :destroy-on-close="true" append-to-body custom-class="period-settings-drawer">
  52. <div class="drawer-content" style="margin-left: 25px">
  53. <el-tabs v-model="activeTab" @tab-click="handleTabClick">
  54. <el-tab-pane label="课程管理" name="course">
  55. <el-table ref="courseTable" v-loading="course.loading" :data="course.list"
  56. @selection-change="handleSelectionCourseChange" border>
  57. <el-table-column type="selection" width="55" align="center" />
  58. <el-table-column label="课程" align="center" prop="courseName" width="180" />
  59. <el-table-column label="小节" align="center" prop="videoName" />
  60. <el-table-column label="开课状态" align="center" prop="status" width="100"
  61. :formatter="courseStatusFormatter" />
  62. <el-table-column label="营期时间" align="center" prop="dayDate" width="100" />
  63. <el-table-column label="开始时间" align="center" prop="startDateTime" width="100">
  64. <!-- <template slot-scope="scope">-->
  65. <!-- <el-tag>{{scope.row.startDateTime}}</el-tag>-->
  66. <!-- </template>-->
  67. </el-table-column>
  68. <el-table-column label="结束时间" align="center" prop="endDateTime" width="100">
  69. <!-- <template slot-scope="scope">-->
  70. <!-- <el-tag type="success">{{parseTime(scope.row.endDateTime, '{h}:{i}:{s}')}}</el-tag>-->
  71. <!-- </template>-->
  72. </el-table-column>
  73. <el-table-column label="领取红包时间" align="center" prop="lastJoinTime" width="160">
  74. <template slot-scope="scope">
  75. <el-tag type="danger">{{ scope.row.lastJoinTime }}</el-tag>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  79. <template slot-scope="scope">
  80. <el-button size="mini" type="text" @click="handleSend(scope.row)"
  81. v-hasPermi="['course:period:courseMove']">发送</el-button>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. <pagination v-show="course.total > 0" :total="course.total"
  86. :page.sync="course.queryParams.pageNum" :limit.sync="course.queryParams.pageSize"
  87. @pagination="getCourseList" style="height: 40px" />
  88. </el-tab-pane>
  89. </el-tabs>
  90. </div>
  91. </el-drawer>
  92. <el-dialog title="IM发送" :visible.sync="imOpen" width="800px" append-to-body>
  93. <el-form ref="imSendForm" :model="imSendForm" :rules="imRules" label-width="220px">
  94. <el-form-item label="标题" prop="title">
  95. <el-input v-model="imSendForm.title" placeholder="请输入标题" />
  96. </el-form-item>
  97. <el-form-item label="发送消息时间" prop="sendTime">
  98. <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="imSendForm.sendTime" type="datetime" placeholder="选择日期时间">
  99. </el-date-picker>
  100. </el-form-item>
  101. <el-form-item label="有效时长(分钟)" prop="effectiveDuration">
  102. <el-input-number v-model="imSendForm.effectiveDuration" :min="0"
  103. label="链接有效时长(分钟)"></el-input-number>
  104. </el-form-item>
  105. </el-form>
  106. <div slot="footer" class="dialog-footer">
  107. <el-button type="primary" @click="imSubmit">确 定</el-button>
  108. <el-button @click="imCancel">取 消</el-button>
  109. </div>
  110. </el-dialog>
  111. </div>
  112. </template>
  113. <script>
  114. import { addPeriod, delPeriod, exportPeriod, getPeriod, pagePeriod, updatePeriod, getDays, addCourse, delPeriodDay, updateCourseTime, updateCourseDate, updateListCourseData, periodCourseMove, closePeriod } from "@/api/course/userCoursePeriod";
  115. import { getCompanyList } from "@/api/company/company";
  116. import { batchSendCourse } from "@/api/user/fsUser";
  117. import { listCamp, addCamp, editCamp, delCamp, copyCamp } from "@/api/course/userCourseCamp";
  118. import { courseList, videoList } from '@/api/course/courseRedPacketLog'
  119. import Da from "element-ui/src/locale/lang/da";
  120. import { getConfigByKey } from '@/api/system/config'
  121. export default {
  122. props: {
  123. userIds: {
  124. type: Array,
  125. default: () => []
  126. },
  127. companyId: {
  128. type: Number,
  129. default: 0
  130. },
  131. companyUserId: {
  132. type: Number,
  133. default: 0
  134. }
  135. },
  136. name: "Period",
  137. components: {
  138. },
  139. data() {
  140. return {
  141. imSendForm: {
  142. },
  143. imOpen: false,
  144. // 遮罩层
  145. loading: true,
  146. updateDateOpen: false,
  147. // 左侧遮罩层
  148. leftLoading: true,
  149. // 选中数组
  150. ids: [],
  151. // 非单个禁用
  152. single: true,
  153. // 非多个禁用
  154. multiple: true,
  155. // 显示搜索条件
  156. showSearch: true,
  157. // 总条数
  158. total: 0,
  159. // 左侧总条数
  160. leftTotal: 0,
  161. // 会员营期表格数据
  162. periodList: [],
  163. // 左侧列表数据
  164. leftList: [],
  165. videoList: [],
  166. // 弹出层标题
  167. title: "",
  168. isDisabledDateRange: false, //是否禁用开营日期
  169. // 是否显示弹出层
  170. open: false,
  171. // 查询参数
  172. queryParams: {
  173. pageNum: 1,
  174. pageSize: 10,
  175. periodName: null,
  176. periodStartingTime: null,
  177. periodEndTime: null,
  178. companyIdList: []
  179. },
  180. // 左侧查询参数
  181. leftQueryParams: {
  182. pageNum: 1,
  183. pageSize: 10,
  184. hasNextPage: false,
  185. scs: 'order_number(desc),training_camp_id(desc)',
  186. trainingCampName: null
  187. },
  188. // 表单参数
  189. form: {},
  190. // 课程相关数据
  191. course: {
  192. open: false,
  193. row: {},
  194. list: [],
  195. queryParams: {
  196. pageNum: 1,
  197. pageSize: 10,
  198. },
  199. loading: true,
  200. total: 0,
  201. addOpen: false,
  202. form: {},
  203. },
  204. //修改营期时间参数
  205. updatePeriodDate: {
  206. open: false,
  207. loading: true,
  208. ids: [],
  209. form: {},
  210. },
  211. joinTimeSwitch: true,
  212. updateCourse: {
  213. open: false,
  214. loading: true,
  215. ids: [],
  216. form: {
  217. timeRange: null,
  218. joinTime: null
  219. },
  220. },
  221. imRules: {
  222. title: [
  223. { required: true, message: "发送标题不能为空", trigger: "blur" }
  224. ],
  225. },
  226. // 表单校验
  227. rules: {
  228. periodName: [
  229. { required: true, message: '营期名称不能为空', trigger: 'blur' }
  230. ],
  231. companyId: [
  232. { required: true, message: '公司不能为空', trigger: 'change' }
  233. ],
  234. courseStyle: [
  235. { required: true, message: '课程风格不能为空', trigger: 'change' }
  236. ],
  237. // redPacketGrantMethod: [
  238. // { required: true, message: '红包发放方式不能为空', trigger: 'change' }
  239. // ],
  240. periodType: [
  241. { required: true, message: '营期类型不能为空', trigger: 'change' }
  242. ],
  243. maxViewNum: [
  244. { required: true, message: '销售可查看天数不能为空', trigger: 'blur' }
  245. ],
  246. periodStartingTime: [
  247. { required: true, message: '开营日期不能为空', trigger: 'change' }
  248. ]
  249. },
  250. // 公司选项
  251. companyOptions: [],
  252. // 训练营列表
  253. campList: [],
  254. // 激活的训练营索引
  255. activeCampIndex: null,
  256. // 训练营对话框是否显示
  257. campDialogVisible: false,
  258. courseList: false,
  259. // 训练营表单
  260. campForm: {
  261. trainingCampId: null,
  262. trainingCampName: ''
  263. },
  264. // 训练营表单校验
  265. campRules: {
  266. trainingCampName: [
  267. { required: true, message: '训练营名称不能为空', trigger: 'blur' },
  268. { min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
  269. ]
  270. },
  271. // 添加课程表单校验
  272. courseAddRules: {
  273. courseId: [
  274. { required: true, message: '请选择课程', trigger: 'change' }
  275. ],
  276. videoIds: [
  277. { required: true, message: '请选择小节', trigger: 'change' },
  278. { type: 'array', min: 1, message: '请至少选择一个小节', trigger: 'change' }
  279. ]
  280. },
  281. // 修改看课时间表单校验
  282. courseUpdateRules: {
  283. timeRange: [
  284. {
  285. required: true,
  286. validator: (rule, value, callback) => {
  287. if (!value || !Array.isArray(value) || value.length !== 2) {
  288. callback(new Error('请选择完整的看课时间范围'));
  289. } else {
  290. // 检查时间格式是否正确(yyyy-MM-dd HH:mm:ss)
  291. const timeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
  292. if (!timeRegex.test(value[0]) || !timeRegex.test(value[1])) {
  293. callback(new Error('时间格式不正确'));
  294. } else if (value[0] >= value[1]) {
  295. callback(new Error('结束时间必须大于开始时间'));
  296. } else {
  297. callback();
  298. }
  299. }
  300. },
  301. trigger: 'change'
  302. }
  303. ],
  304. joinTime: [
  305. {
  306. required: true,
  307. validator: (rule, value, callback) => {
  308. if (!value) {
  309. callback(new Error('请选择领取红包时间'));
  310. } else {
  311. // 检查时间格式是否正确(yyyy-MM-dd HH:mm:ss)
  312. const timeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
  313. if (!timeRegex.test(value)) {
  314. callback(new Error('时间格式不正确'));
  315. } else {
  316. // 检查领取红包时间是否在看课时间范围内
  317. const timeRange = this.updateCourse.form.timeRange;
  318. if (timeRange && Array.isArray(timeRange) && timeRange.length === 2) {
  319. if (value < timeRange[0] || value > timeRange[1]) {
  320. callback(new Error('领取红包时间必须在看课时间范围内'));
  321. } else {
  322. callback();
  323. }
  324. } else {
  325. callback();
  326. }
  327. }
  328. }
  329. },
  330. trigger: 'change'
  331. }
  332. ]
  333. },
  334. // 滚动节流标志
  335. scrollThrottle: false,
  336. // 加载更多状态
  337. loadingMore: false,
  338. // 设置红包对话框
  339. redPacketVisible: false,
  340. periodCompanyList: [],
  341. currentRedPacketData: {
  342. periodId: '',
  343. videoId: ''
  344. },
  345. // 营期相关设置抽屉
  346. periodSettingsVisible: false,
  347. activeTab: 'course',
  348. periodSettingsData: {},
  349. companyList: [],
  350. courseDialogVisible: false,
  351. redPacketList: [],
  352. currentCompany: null,
  353. // 选中的营期数据
  354. selectedPeriods: [],
  355. // 批量设置红包按钮是否禁用
  356. batchSetRedPacketDisabled: true,
  357. };
  358. },
  359. created() {
  360. courseList().then(response => {
  361. this.courseList = response.list;
  362. });
  363. // this.getList();
  364. this.getLeftList();
  365. this.getCompanyList();
  366. },
  367. methods: {
  368. imSubmit() {
  369. console.log("imSendForm:",this.imSendForm)
  370. this.$refs["imSendForm"].validate(valid => {
  371. batchSendCourse(this.imSendForm).then(res=>{
  372. this.imCancel();
  373. this.$message.success('发送成功')
  374. })
  375. });
  376. },
  377. handleSend(row) {
  378. this.imOpen = true;
  379. this.imSendForm = {
  380. userIds:this.userIds,
  381. companyUserId: this.companyUserId,
  382. companyId: this.companyId,
  383. id:row.id,
  384. periodId:row.periodId,
  385. courseId:row.courseId,
  386. videoId:row.videoId
  387. }
  388. },
  389. imCancel() {
  390. this.imOpen = false;
  391. this.imRest();
  392. },
  393. imRest() {
  394. this.imSendForm = {
  395. userIds: [],
  396. companyUserId: null,
  397. companyId: null,
  398. periodId: null,
  399. courseId: null,
  400. videoId: null,
  401. tagIds: [],
  402. sendTime: null,
  403. title: null,
  404. effectiveDuration: null,
  405. id: null,
  406. };
  407. this.resetForm("imSendForm")
  408. },
  409. /** 删除按钮操作 */
  410. async handleDeleteCourse(row) {
  411. const periodDayIds = row.id || this.updateCourse.ids;
  412. try {
  413. await this.$confirm('是否确认删除该课程?', "提示", {
  414. confirmButtonText: "确定",
  415. cancelButtonText: "取消",
  416. type: "warning"
  417. });
  418. const res = await delPeriodDay(periodDayIds);
  419. if (res && res.code === 200) {
  420. this.getCourseList();// 刷新列表
  421. this.$message.success('删除成功');
  422. } else {
  423. this.$message.error(res.msg);
  424. }
  425. } catch (error) {
  426. }
  427. },
  428. /** 查询会员营期列表 */
  429. getList() {
  430. this.loading = true;
  431. const params = { ...this.queryParams };
  432. params.trainingCampId = null,
  433. pagePeriod(params).then(response => {
  434. this.periodList = response.rows;
  435. this.total = response.total;
  436. this.loading = false;
  437. });
  438. },
  439. /** 查询左侧列表 */
  440. getLeftList() {
  441. this.leftLoading = true;
  442. // 重置页码和加载更多状态
  443. this.leftQueryParams.pageNum = 1;
  444. this.loadingMore = false;
  445. // 训练营数据
  446. listCamp(this.leftQueryParams).then(response => {
  447. if (response && response.code === 200) {
  448. this.campList = response.data.list || [];
  449. this.leftQueryParams.hasNextPage = response.data.hasNextPage;
  450. this.activeCampIndex = this.campList.length > 0 ? 0 : null;
  451. this.selectCamp(this.activeCampIndex);
  452. // 如果当前显示的列表高度不足以触发滚动,但还有更多数据,自动加载下一页
  453. this.$nextTick(() => {
  454. const scrollEl = this.$refs.campList;
  455. if (scrollEl && this.leftQueryParams.hasNextPage && scrollEl.scrollHeight <= scrollEl.clientHeight) {
  456. this.loadMoreCamps();
  457. }
  458. });
  459. } else {
  460. this.$message.error(response.msg || '获取训练营列表失败');
  461. this.campList = [];
  462. this.leftQueryParams.hasNextPage = false;
  463. }
  464. this.leftLoading = false;
  465. }).catch(error => {
  466. console.error('获取训练营列表失败:', error);
  467. this.$message.error('获取训练营列表失败');
  468. this.campList = [];
  469. this.leftQueryParams.hasNextPage = false;
  470. this.leftLoading = false;
  471. });
  472. },
  473. /** 搜索按钮操作 */
  474. handleQuery() {
  475. this.queryParams.pageNum = 1;
  476. this.getList();
  477. },
  478. /** 左侧搜索按钮操作 */
  479. handleLeftQuery() {
  480. // 重置页码和列表
  481. this.leftQueryParams.pageNum = 1;
  482. this.campList = [];
  483. this.getLeftList();
  484. },
  485. /** 重置按钮操作 */
  486. resetQuery() {
  487. this.resetForm("queryForm");
  488. this.queryParams.companyIdList = [];
  489. this.handleQuery();
  490. },
  491. /** 多选框选中数据 */
  492. handleSelectionChange(selection) {
  493. this.ids = selection.map(item => item.periodId)
  494. this.single = selection.length !== 1
  495. this.multiple = !selection.length
  496. // 更新批量设置红包相关数据
  497. this.selectedPeriods = selection;
  498. this.batchSetRedPacketDisabled = selection.length === 0;
  499. },
  500. handleSelectionCourseChange(selection) {
  501. this.updateCourse.ids = selection.map(item => item.id)
  502. },
  503. /** 获取公司下拉列表*/
  504. getCompanyList() {
  505. this.loading = true;
  506. getCompanyList().then(response => {
  507. this.companyOptions = response.data;
  508. this.loading = false;
  509. });
  510. },
  511. // 取消按钮
  512. cancel() {
  513. this.open = false;
  514. this.reset();
  515. },
  516. // 表单重置
  517. reset() {
  518. this.form = {
  519. periodId: null,
  520. periodName: null,
  521. companyId: null,
  522. courseId: null,
  523. videoId: null,
  524. trainingCampId: null,
  525. createTime: null,
  526. updateTime: null,
  527. courseStyle: null,
  528. liveRoomStyle: null,
  529. redPacketGrantMethod: 1,
  530. periodType: 1,
  531. periodStartingTime: null,
  532. dateRange: [],
  533. date: null,
  534. days: [],
  535. maxViewNum: 0,
  536. periodEndTime: null,
  537. timeRange: [], // 看课时间范围
  538. viewStartTime: null, // 看课开始时间
  539. viewEndTime: null, // 看课结束时间
  540. lastJoinTime: null // 领取红包时间
  541. };
  542. this.resetForm("form");
  543. },
  544. /** 重置训练营表单 */
  545. resetCampForm() {
  546. this.campForm = {
  547. trainingCampId: null,
  548. trainingCampName: ''
  549. };
  550. // 如果表单已经创建,则重置校验结果
  551. if (this.$refs.campForm) {
  552. this.$refs.campForm.resetFields();
  553. }
  554. },
  555. /** 选中训练营 */
  556. selectCamp(index) {
  557. if (index == null || index == undefined) return;
  558. this.activeCampIndex = index;
  559. // 加载对应的训练营营期数据
  560. const selectedCamp = this.campList[index];
  561. this.queryParams.trainingCampId = selectedCamp.trainingCampId;
  562. this.getList();
  563. },
  564. /** 处理滚动事件,实现滚动到底部加载更多 */
  565. handleScroll() {
  566. // 如果正在节流中或者正在加载中,则不处理
  567. if (this.scrollThrottle || this.loadingMore) return;
  568. // 设置节流,200ms内不再处理滚动事件
  569. this.scrollThrottle = true;
  570. setTimeout(() => {
  571. this.scrollThrottle = false;
  572. }, 200);
  573. const scrollEl = this.$refs.campList;
  574. if (!scrollEl) return;
  575. // 判断是否滚动到底部:滚动高度 + 可视高度 >= 总高度 - 30(添加30px的容差,提前触发加载)
  576. const isBottom = scrollEl.scrollTop + scrollEl.clientHeight >= scrollEl.scrollHeight - 30;
  577. // 如果滚动到底部,且有下一页数据,且当前不在加载中,则加载更多
  578. if (isBottom && this.leftQueryParams.hasNextPage && !this.leftLoading && !this.loadingMore) {
  579. this.loadMoreCamps();
  580. }
  581. },
  582. /** 加载更多训练营数据 */
  583. loadMoreCamps() {
  584. // 已在加载中,防止重复加载
  585. if (this.leftLoading || this.loadingMore) return;
  586. // 设置加载状态
  587. this.loadingMore = true;
  588. // 页码加1
  589. this.leftQueryParams.pageNum += 1;
  590. // 加载下一页数据
  591. listCamp(this.leftQueryParams).then(response => {
  592. if (response && response.code === 200) {
  593. // 将新数据追加到列表中
  594. const newList = response.data.list || [];
  595. if (newList.length > 0) {
  596. this.campList = [...this.campList, ...newList];
  597. }
  598. // 更新是否有下一页的标志
  599. this.leftQueryParams.hasNextPage = response.data.hasNextPage;
  600. // 如果当前显示的列表高度不足以触发滚动,但还有更多数据,自动加载下一页
  601. this.$nextTick(() => {
  602. const scrollEl = this.$refs.campList;
  603. if (scrollEl && this.leftQueryParams.hasNextPage && scrollEl.scrollHeight <= scrollEl.clientHeight) {
  604. // 延迟一点再加载下一页,避免过快加载
  605. setTimeout(() => {
  606. this.loadMoreCamps();
  607. }, 300);
  608. }
  609. });
  610. } else {
  611. this.$message.error(response.msg || '加载更多训练营失败');
  612. }
  613. this.loadingMore = false;
  614. }).catch(error => {
  615. console.error('加载更多训练营失败:', error);
  616. this.$message.error('加载更多训练营失败');
  617. this.loadingMore = false;
  618. });
  619. },
  620. timeChange(type) {
  621. if (type == 1) {
  622. this.form.periodStartingTime = this.form.dateRange[0];
  623. this.form.periodEndTime = this.form.dateRange[1];
  624. if (!Array.isArray(this.form.days)) {
  625. this.form.days = [];
  626. }
  627. this.form.days = [];
  628. let days = this.getDiff(this.form.periodStartingTime, this.form.periodEndTime);
  629. for (let i = 0; i < days; i++) {
  630. this.form.days.push({ lesson: i + 1 });
  631. }
  632. }
  633. if (type == 2) {
  634. this.form.periodStartingTime = this.form.date;
  635. this.form.periodEndTime = this.form.date;
  636. this.form.days = [];
  637. }
  638. },
  639. getDiff(start, end) {
  640. if (start == null || start == undefined || start == '') return 0;
  641. if (end == null || end == undefined || end == '') return 0;
  642. if (start == end) 1;
  643. const startDate = this.getUTCDate(start);
  644. const endDate = this.getUTCDate(end);
  645. const timeDiff = endDate - startDate;
  646. return (Math.floor(timeDiff / (1000 * 3600 * 24))) + 1; // 直接取整
  647. },
  648. getUTCDate(dateStr) {
  649. const [year, month, day] = dateStr.split('-').map(Number);
  650. return new Date(Date.UTC(year, month - 1, day)); // 月份从0开始
  651. },
  652. getCourseList() {
  653. this.course.loading = true;
  654. getDays(this.course.queryParams).then(e => {
  655. this.course.list = e.rows;
  656. this.course.total = e.total;
  657. this.course.loading = false;
  658. });
  659. },
  660. handlePeriodSettings(row) {
  661. console.log("公司id:",this.companyId,this.companyUserId)
  662. this.periodSettingsData = row;
  663. this.periodSettingsVisible = true;
  664. // 初始化课程列表
  665. this.course.queryParams.periodId = row.periodId;
  666. // 根据当前激活的tab加载对应数据
  667. this.handleTabClick({ name: this.activeTab });
  668. },
  669. /** 处理tab切换 */
  670. handleTabClick(tab) {
  671. if (tab.name === 'course') {
  672. this.getCourseList();
  673. } else if (tab.name === 'company') {
  674. this.redPacketVisible = true;
  675. }
  676. },
  677. /** 营期状态格式化 */
  678. periodStatusFormatter(row) {
  679. const statusMap = {
  680. 1: '未开始',
  681. 2: '进行中',
  682. 3: '已结束'
  683. };
  684. return statusMap[row.periodStatus] || '未知状态';
  685. },
  686. /** 开课状态格式化 */
  687. courseStatusFormatter(row) {
  688. const statusMap = {
  689. 0: '未开始',
  690. 1: '进行中',
  691. 2: '已结束'
  692. };
  693. return statusMap[row.status] || '未知状态';
  694. },
  695. },
  696. };
  697. </script>
  698. <style scoped>
  699. .left-aside {
  700. background-color: #fff;
  701. border-right: 1px solid #EBEEF5;
  702. padding: 0;
  703. display: flex;
  704. flex-direction: column;
  705. height: 800px;
  706. }
  707. .left-header {
  708. padding: 10px;
  709. border-bottom: 1px solid #EBEEF5;
  710. }
  711. .left-header-top {
  712. display: flex;
  713. justify-content: space-between;
  714. align-items: center;
  715. margin-bottom: 10px;
  716. }
  717. .search-btn {
  718. width: 50%;
  719. height: 36px;
  720. background-color: #409EFF;
  721. color: white;
  722. border: none;
  723. }
  724. .search-input-wrapper {
  725. margin-bottom: 10px;
  726. }
  727. .sort-wrapper {
  728. display: flex;
  729. align-items: center;
  730. margin-bottom: 10px;
  731. }
  732. .sort-label {
  733. width: 70px;
  734. font-size: 14px;
  735. font-weight: 600;
  736. color: #909399;
  737. }
  738. .sort-select {
  739. margin-left: 10px;
  740. width: 280px;
  741. }
  742. .color-wrapper {
  743. display: flex;
  744. align-items: center;
  745. margin-bottom: 10px;
  746. }
  747. .color-label {
  748. width: 70px;
  749. color: #606266;
  750. }
  751. .color-hint {
  752. margin-left: 10px;
  753. color: #606266;
  754. font-size: 12px;
  755. }
  756. .color-help {
  757. margin-left: 5px;
  758. color: #909399;
  759. cursor: pointer;
  760. }
  761. .hint-text {
  762. color: #606266;
  763. font-size: 12px;
  764. margin-top: 5px;
  765. }
  766. .camp-list {
  767. flex: 1;
  768. overflow-y: auto;
  769. padding: 3px;
  770. }
  771. .camp-item {
  772. margin-bottom: 5px;
  773. padding: 15px;
  774. background-color: #ffffff;
  775. position: relative;
  776. cursor: pointer;
  777. display: flex;
  778. justify-content: space-between;
  779. border: 1px solid #eaedf2;
  780. }
  781. .camp-item:last-child {
  782. margin-bottom: 0;
  783. }
  784. .camp-item:hover {
  785. background-color: #f5f9ff;
  786. }
  787. .camp-item.active {
  788. background-color: #eaf4ff;
  789. border-left: 1px solid #75b8fc;
  790. }
  791. .camp-content {
  792. flex: 1;
  793. padding-right: 10px;
  794. }
  795. .camp-title {
  796. font-weight: bold;
  797. font-size: 16px;
  798. margin-bottom: 8px;
  799. color: #333;
  800. display: flex;
  801. align-items: center;
  802. }
  803. .camp-icon {
  804. font-size: 16px;
  805. margin-right: 6px;
  806. color: #409EFF;
  807. }
  808. .camp-info {
  809. display: flex;
  810. justify-content: space-between;
  811. margin-bottom: 8px;
  812. font-size: 12px;
  813. color: #c4c1c1;
  814. line-height: 1.5;
  815. }
  816. .camp-stats {
  817. display: flex;
  818. justify-content: space-between;
  819. font-size: 12px;
  820. color: #666;
  821. background-color: #f5f9ff;
  822. padding: 6px 10px;
  823. border-radius: 4px;
  824. line-height: 1.5;
  825. }
  826. .stat-item {
  827. display: flex;
  828. align-items: center;
  829. }
  830. .stat-item i {
  831. margin-right: 4px;
  832. font-size: 14px;
  833. color: #409EFF;
  834. }
  835. .camp-actions {
  836. display: flex;
  837. flex-direction: column;
  838. justify-content: center;
  839. align-items: flex-end;
  840. gap: 8px;
  841. border-left: 1px dashed #eaedf2;
  842. padding-left: 12px;
  843. min-width: 50px;
  844. }
  845. .action-btn {
  846. padding: 2px 5px;
  847. font-size: 12px;
  848. border-radius: 4px;
  849. transition: all 0.2s;
  850. }
  851. .action-btn:hover {
  852. background-color: rgba(255, 255, 255, 0.8);
  853. }
  854. .delete-btn {
  855. color: #f56c6c;
  856. }
  857. .delete-btn:hover {
  858. background-color: rgba(245, 108, 108, 0.1);
  859. }
  860. .copy-btn {
  861. color: #409EFF;
  862. }
  863. .copy-btn:hover {
  864. background-color: rgba(64, 158, 255, 0.1);
  865. }
  866. .warning-icon {
  867. color: #E6A23C;
  868. font-size: 16px;
  869. margin-left: 5px;
  870. }
  871. .el-main {
  872. padding: 10px;
  873. }
  874. /* 添加训练营表单样式 */
  875. .drawer-footer {
  876. /* position: absolute; */
  877. bottom: 0;
  878. left: 0;
  879. right: 0;
  880. padding: 20px;
  881. background: #fff;
  882. text-align: right;
  883. border-top: 1px solid #e8e8e8;
  884. }
  885. .el-input-number {
  886. width: 100%;
  887. }
  888. /* 加载更多样式 */
  889. .loading-more {
  890. display: flex;
  891. align-items: center;
  892. justify-content: center;
  893. padding: 12px 0;
  894. color: #909399;
  895. font-size: 14px;
  896. }
  897. .loading-more i {
  898. margin-right: 5px;
  899. font-size: 16px;
  900. }
  901. /* 无更多数据提示 */
  902. .no-more-data {
  903. display: flex;
  904. align-items: center;
  905. justify-content: center;
  906. padding: 12px 0;
  907. color: #c0c4cc;
  908. font-size: 13px;
  909. }
  910. .no-more-data span {
  911. position: relative;
  912. display: flex;
  913. align-items: center;
  914. }
  915. </style>