Jelajahi Sumber

北京存在:优化复制营期功能

liupeng 3 minggu lalu
induk
melakukan
abbe057169
1 mengubah file dengan 56 tambahan dan 20 penghapusan
  1. 56 20
      src/views/course/userCoursePeriod/index.vue

+ 56 - 20
src/views/course/userCoursePeriod/index.vue

@@ -740,9 +740,25 @@
           label="选择其他营期"
           prop="periodId"
         >
+          <el-select
+            v-model="createCampPeriodForm.trainingCampId"
+            placeholder="请选择训练营"
+            :loading="loadingNew"
+            clearable
+            filterable
+            @change="handleTrainingCampChange"
+          >
+            <el-option
+              v-for="item in trainingCampList"
+              :key="item.trainingCampId"
+              :label="item.trainingCampName"
+              :value="item.trainingCampId"
+            />
+          </el-select>
+
           <el-select
             v-model="createCampPeriodForm.periodId"
-            placeholder="请选择其他营期"
+            placeholder="请选择营期"
             :loading="loadingNew"
             clearable
             filterable
@@ -754,6 +770,7 @@
               :value="item.periodId"
             />
           </el-select>
+
           <div v-if="loadingNew" class="loading-text">
             <i class="el-icon-loading"></i> 加载中...
           </div>
@@ -1033,6 +1050,7 @@ export default {
       otherCampPeriods: [],      // 其他训练营的期数列表
       // 缓存数据避免重复请求
       periodDataCache: new Map(),
+      trainingCampList:[],
     };
   },
   created() {
@@ -2065,39 +2083,39 @@ export default {
     },
     /** 加载其他训练营期数列表 */
     async loadOtherCampPeriods() {
-      if (this.trainingCampIdValue == null) {
-        this.$message.error('缺少训练营ID,无法查询数据');
-        return;
-      }
-      // 检查缓存
-      const cacheKey = `otherCampPeriods_${this.trainingCampIdValue}`;
-      if (this.periodDataCache.has(cacheKey)) {
-        this.otherCampPeriods = this.periodDataCache.get(cacheKey);
-        return;
-      }
-      this.loading = true;
+      // 清空营期数据和选中项,避免显示旧数据
+      this.otherCampPeriods = [];
+      this.createCampPeriodForm.periodId = ''; // 清空已选营期
+      this.createCampPeriodForm.trainingCampId = ''; // 清空已选训练营
+
+      // 检查缓存 - 使用固定键名,因为训练营列表不依赖当前训练营ID
+      // const cacheKey = 'trainingCampList';
+      // if (this.periodDataCache.has(cacheKey)) {
+      //   this.trainingCampList = this.periodDataCache.get(cacheKey);
+      //   return;
+      // }
+
+      this.loadingNew = true;
       try {
         const requestParams = {
           periodId: this.trainingCampIdValue,
           campPeriodType: this.createCampPeriodForm.campPeriodType
         };
-
         const response = await getScreeningCampPeriod(requestParams);
-
         if (response && Array.isArray(response.resultList)) {
-          this.otherCampPeriods = response.resultList;
-          // 缓存数据
-          this.periodDataCache.set(cacheKey, response.resultList);
+          this.trainingCampList = response.resultList;
+          // 缓存数据 - 使用固定键名
+          //this.periodDataCache.set(cacheKey, response.resultList);
         } else {
           console.warn('接口返回格式异常:', response);
-          this.otherCampPeriods = [];
+          this.trainingCampList = [];
         }
       } catch (error) {
         console.error('接口请求失败:', error);
         this.$message.error('查询失败,请重试');
-        this.otherCampPeriods = [];
+        this.trainingCampList = [];
       } finally {
-        this.loading = false;
+        this.loadingNew = false;
       }
     },
 
@@ -2189,6 +2207,7 @@ export default {
 
       this.currentCampPeriods = [];
       this.otherCampPeriods = [];
+      this.trainingCampList=[]
       this.loading = false;
       this.submitLoading = false;
 
@@ -2197,6 +2216,23 @@ export default {
         this.$refs.createCampPeriodForm.clearValidate();
       }
     },
+    handleTrainingCampChange(trainingCampId){
+      this.otherCampPeriods = [];
+      this.createCampPeriodForm.periodId = '';
+      const params = {
+        ...this.queryParams,
+        trainingCampId: trainingCampId  // 更新训练营ID
+      };
+      pagePeriod(params).then(response => {
+        if (response.code === 200) {
+          this.otherCampPeriods = response.rows;
+        } else {
+          this.$message.error(response.msg || '查询营期失败');
+        }
+      }).catch(error => {
+        this.$message.error('查询营期失败: ' + (error.message || '查询营期失败'));
+      });
+    }
   },
 };
 </script>