Browse Source

课程统计营期课程调整营期下拉框

yfh 10 hours ago
parent
commit
7d199d6c1f
1 changed files with 88 additions and 28 deletions
  1. 88 28
      src/views/course/userCoursePeriod/statistics.vue

+ 88 - 28
src/views/course/userCoursePeriod/statistics.vue

@@ -13,6 +13,7 @@
             :loading="courseLoading"
             :loading="courseLoading"
             placeholder="请输入关键词搜索营期课程"
             placeholder="请输入关键词搜索营期课程"
             style="width: 400px"
             style="width: 400px"
+            @visible-change="handleCourseDropdownVisible"
           >
           >
             <el-option
             <el-option
               v-for="item in courseOptions"
               v-for="item in courseOptions"
@@ -20,6 +21,13 @@
               :label="item.videoName"
               :label="item.videoName"
               :value="item.videoId"
               :value="item.videoId"
             />
             />
+            <!-- 分页加载更多选项 -->
+            <el-option v-if="hasMoreCourses" key="load-more" disabled class="load-more-option">
+              <div class="load-more" @click="loadMoreCourses">
+                <span>加载更多</span>
+                <i class="el-icon-loading" v-if="loadingMore"></i>
+              </div>
+            </el-option>
           </el-select>
           </el-select>
         </el-form-item>
         </el-form-item>
 
 
@@ -151,10 +159,19 @@ export default {
       // 遮罩层
       // 遮罩层
       loading: false,
       loading: false,
       courseLoading: false,
       courseLoading: false,
+      loadingMore: false,
       // 总条数
       // 总条数
       total: 0,
       total: 0,
       // 课程选项
       // 课程选项
       courseOptions: [],
       courseOptions: [],
+      courseTotal: 0,
+      courseQueryParams: {
+        pageNum: 1,
+        pageSize: 10, // 默认每页10条
+        videoName: '',
+        periodId: ''
+      },
+      hasMoreCourses: false,
       companyOptions: [],
       companyOptions: [],
       // 统计数据
       // 统计数据
       statistics: {
       statistics: {
@@ -184,6 +201,7 @@ export default {
     periodId: {
     periodId: {
       handler(newVal) {
       handler(newVal) {
         this.queryParams.periodId = newVal;
         this.queryParams.periodId = newVal;
+        this.courseQueryParams.periodId = newVal;
         if (this.active && !this.initialized) {
         if (this.active && !this.initialized) {
           this.initializeData();
           this.initializeData();
         }
         }
@@ -216,47 +234,66 @@ export default {
     },
     },
 
 
     /** 获取课程选项 */
     /** 获取课程选项 */
-    getCourseOptions() {
-      this.courseLoading = true;
-      getDays(this.queryParams).then(r => {
+    getCourseOptions(isLoadMore = false) {
+      if (!isLoadMore) {
+        this.courseLoading = true;
+        this.courseQueryParams.pageNum = 1; // 重置页码
+      } else {
+        this.loadingMore = true;
+      }
+
+      getDays(this.courseQueryParams).then(r => {
         if (r.code === 200) {
         if (r.code === 200) {
-          this.courseOptions = r.rows;
-          this.loading = false;
+          if (isLoadMore) {
+            // 加载更多时,追加数据
+            this.courseOptions = [...this.courseOptions, ...r.rows];
+          } else {
+            // 首次加载或搜索时,替换数据
+            this.courseOptions = r.rows;
+          }
+
+          this.courseTotal = r.total || 0;
+
+          // 计算是否还有更多数据
+          const loadedCount = this.courseOptions.length;
+          this.hasMoreCourses = loadedCount < this.courseTotal;
+
+          this.courseLoading = false;
+          this.loadingMore = false;
         } else {
         } else {
           this.$message.error(r.msg || '获取数据失败');
           this.$message.error(r.msg || '获取数据失败');
+          this.courseLoading = false;
+          this.loadingMore = false;
         }
         }
-        this.courseLoading = false;
       }).catch(() => {
       }).catch(() => {
         this.courseLoading = false;
         this.courseLoading = false;
+        this.loadingMore = false;
       });
       });
     },
     },
 
 
-    /** 营期课程搜索 */
-    handleCourseSearch(query) {
-      if (query !== '') {
-        this.courseLoading = true;
-        // 这里可以根据实际接口调整搜索参数
-        getDays({
-          periodId: this.queryParams.periodId,
-          pageNum: 1,
-          pageSize: 100,
-          videoName: query // 假设接口支持按课程名称搜索
-        }).then(r => {
-          if (r.code === 200) {
-            this.courseOptions = r.rows;
-          } else {
-            this.$message.error(r.msg || '搜索失败');
-          }
-          this.courseLoading = false;
-        }).catch(() => {
-          this.courseLoading = false;
-        });
-      } else {
-        // 如果搜索词为空,重新加载所有课程
+    /** 加载更多课程 */
+    loadMoreCourses() {
+      if (this.loadingMore) return;
+
+      this.courseQueryParams.pageNum += 1;
+      this.getCourseOptions(true);
+    },
+
+    /** 处理下拉框显示/隐藏 */
+    handleCourseDropdownVisible(visible) {
+      if (visible && this.courseOptions.length === 0) {
+        // 当下拉框显示且没有数据时,加载初始数据
         this.getCourseOptions();
         this.getCourseOptions();
       }
       }
     },
     },
 
 
+    /** 营期课程搜索 */
+    handleCourseSearch(query) {
+      this.courseQueryParams.videoName = query;
+      this.courseQueryParams.pageNum = 1; // 搜索时重置页码
+      this.getCourseOptions();
+    },
+
     /** 查询按钮操作 */
     /** 查询按钮操作 */
     handleQuery() {
     handleQuery() {
       this.queryParams.pageNum = 1;
       this.queryParams.pageNum = 1;
@@ -392,4 +429,27 @@ export default {
   font-weight: bold;
   font-weight: bold;
   color: #303133;
   color: #303133;
 }
 }
+
+/* 加载更多选项样式 */
+.load-more-option {
+  text-align: center;
+  padding: 8px 0;
+}
+
+.load-more {
+  color: #409EFF;
+  cursor: pointer;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  gap: 5px;
+}
+
+.load-more:hover {
+  color: #66b1ff;
+}
+
+:deep(.el-select-dropdown__list) {
+  padding-bottom: 0 !important;
+}
 </style>
 </style>