userCoursePeriod.vue 34 KB

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