Long 1 månad sedan
förälder
incheckning
387c11bfbb
2 ändrade filer med 85 tillägg och 30 borttagningar
  1. 9 0
      src/api/course/userCourseCamp.js
  2. 76 30
      src/views/course/userCoursePeriod/index.vue

+ 9 - 0
src/api/course/userCourseCamp.js

@@ -18,6 +18,15 @@ export function addCamp(data) {
   })
 }
 
+// 修改训练营
+export function editCamp(data) {
+  return request({
+    url: '/course/trainingCamp',
+    method: 'put',
+    data: data
+  })
+}
+
 // 删除训练营
 export function delCamp(trainingCampId) {
   return request({

+ 76 - 30
src/views/course/userCoursePeriod/index.vue

@@ -7,10 +7,7 @@
         <div class="left-header">
           <div class="left-header-top">
             <el-button type="primary" class="search-btn" @click="handleLeftQuery">搜索</el-button>
-            <div class="btn-group">
-              <el-button type="text" @click="showWarning">展示预警训练营</el-button>
-              <el-button type="primary" icon="el-icon-plus" @click="handleAddTrainingCamp">新建训练营</el-button>
-            </div>
+            <el-button type="primary" style="width: 50%" icon="el-icon-plus" @click="handleAddTrainingCamp">新建训练营</el-button>
           </div>
           <div class="search-input-wrapper">
             <el-input
@@ -68,6 +65,7 @@
             <div class="camp-actions">
               <el-button type="text" class="action-btn delete-btn" @click.stop="handleDeleteCamp(item)">删除</el-button>
               <el-button type="text" class="action-btn copy-btn" @click.stop="handleCopyCamp(item)">复制</el-button>
+              <el-button type="text" class="action-btn copy-btn" @click.stop="handleEditCamp(item)">编辑</el-button>
             </div>
           </div>
           <!-- 底部加载更多提示 -->
@@ -274,7 +272,7 @@
     </el-dialog>
 
     <!-- 添加训练营对话框 -->
-    <el-dialog :title="'新建训练营'" :visible.sync="campDialogVisible" width="500px" append-to-body>
+    <el-dialog :title="campForm.trainingCampId ? '修改训练营' : '新建训练营'" :visible.sync="campDialogVisible" width="500px" append-to-body>
       <el-form ref="campForm" :model="campForm" :rules="campRules" label-width="100px">
         <el-form-item label="训练营名称" prop="trainingCampName">
           <el-input v-model="campForm.trainingCampName" placeholder="请输入训练营名称" />
@@ -383,7 +381,7 @@
 <script>
 import {addPeriod, delPeriod, exportPeriod, getPeriod, pagePeriod, updatePeriod, getDays, addCourse, updateListCourseData} from "@/api/course/userCoursePeriod";
 import {getCompanyList} from "@/api/company/company";
-import { listCamp, addCamp, delCamp, copyCamp } from "@/api/course/userCourseCamp";
+import { listCamp, addCamp, editCamp, delCamp, copyCamp } from "@/api/course/userCourseCamp";
 import { courseList,videoList } from '@/api/course/courseRedPacketLog'
 
 export default {
@@ -461,6 +459,7 @@ export default {
       courseList: false,
       // 训练营表单
       campForm: {
+        trainingCampId: null,
         trainingCampName: ''
       },
       // 训练营表单校验
@@ -725,9 +724,25 @@ export default {
         this.$message.error('复制训练营失败: ' + error.message);
       });
     },
-    /** 展示预警训练营 */
-    showWarning() {
-      console.log('展示预警训练营')
+    /** 修改训练营按钮操作 */
+    handleEditCamp(item) {
+      this.resetCampForm();
+      this.leftLoading = true;
+      
+      // 获取最新的训练营数据
+      const trainingCampId = item.trainingCampId;
+      // 应该调用获取训练营详情的API
+      setTimeout(() => {
+        // 填充表单数据
+        this.campForm = {
+          trainingCampId: item.trainingCampId,
+          trainingCampName: item.trainingCampName,
+          orderNumber: item.orderNumber || 1,
+          status: item.status !== undefined ? item.status : 1
+        };
+        this.campDialogVisible = true;
+        this.leftLoading = false;
+      }, 300);
     },
     /** 新建训练营按钮操作 */
     handleAddTrainingCamp() {
@@ -737,6 +752,7 @@ export default {
     /** 重置训练营表单 */
     resetCampForm() {
       this.campForm = {
+        trainingCampId: null,
         trainingCampName: ''
       };
       // 如果表单已经创建,则重置校验结果
@@ -755,21 +771,55 @@ export default {
         if (valid) {
           // 显示加载中
           this.leftLoading = true;
-          // 提交数据
-          addCamp(this.campForm).then(response => {
-            if (response.code === 200) {
-              this.$message.success('新建训练营成功');
-              this.campDialogVisible = false;
-              // 重新加载训练营列表
-              this.getLeftList();
-            } else {
-              this.$message.error(response.msg || '新建训练营失败');
+          
+          // 准备提交的数据
+          const submitData = JSON.parse(JSON.stringify(this.campForm));
+          
+          // 判断是新增还是修改
+          if (submitData.trainingCampId) {
+            // 修改训练营
+            editCamp(submitData).then(response => {
+              if (response.code === 200) {
+                this.$message.success('修改训练营成功');
+                this.campDialogVisible = false;
+                
+                // 更新列表中的数据
+                const index = this.campList.findIndex(camp => camp.trainingCampId === submitData.trainingCampId);
+                if (index !== -1) {
+                  this.campList[index] = { ...this.campList[index], ...submitData };
+                  // 如果修改的是当前选中的训练营,更新右侧列表
+                  if (this.activeCampIndex === index) {
+                    this.selectCamp(index);
+                  }
+                }
+                
+                // 重新加载训练营列表
+                this.getLeftList();
+              } else {
+                this.$message.error(response.msg || '修改训练营失败');
+                this.leftLoading = false;
+              }
+            }).catch(error => {
+              this.$message.error('修改训练营失败: ' + (error.message || '未知错误'));
               this.leftLoading = false;
-            }
-          }).catch(error => {
-            this.$message.error('新建训练营失败: ' + error.message);
-            this.leftLoading = false;
-          });
+            });
+          } else {
+            // 新增训练营
+            addCamp(submitData).then(response => {
+              if (response.code === 200) {
+                this.$message.success('新建训练营成功');
+                this.campDialogVisible = false;
+                // 重新加载训练营列表
+                this.getLeftList();
+              } else {
+                this.$message.error(response.msg || '新建训练营失败');
+                this.leftLoading = false;
+              }
+            }).catch(error => {
+              this.$message.error('新建训练营失败: ' + (error.message || '未知错误'));
+              this.leftLoading = false;
+            });
+          }
         }
       });
     },
@@ -784,7 +834,7 @@ export default {
     /** 选中训练营 */
     selectCamp(index) {
       this.activeCampIndex = index;
-      // TODO:加载对应的训练营营期数据
+      // 加载对应的训练营营期数据
       const selectedCamp = this.campList[index];
       this.queryParams.trainingCampId = selectedCamp.trainingCampId;
       this.getList();
@@ -975,17 +1025,13 @@ export default {
 }
 
 .search-btn {
-  padding: 7px 15px;
+  width: 50%;
+  height: 36px;
   background-color: #409EFF;
   color: white;
   border: none;
 }
 
-.btn-group {
-  display: flex;
-  gap: 10px;
-}
-
 .search-input-wrapper {
   margin-bottom: 10px;
 }