jichoi / lms_front star
이은진 이은진 2024-08-14
240814 이은진 학습일정 충돌 수정
@307c1a2e2159f4bd3b8c86418159859b55b427e8
client/views/pages/main/MyPlan.vue
--- client/views/pages/main/MyPlan.vue
+++ client/views/pages/main/MyPlan.vue
@@ -26,11 +26,11 @@
                                     <!-- <p class="title2">wirte a</p> -->
                                 </div>
                                 <button v-if="schedule.finish == 'T'" type="button" title="바로가기" class="yellow-btn"
-                                    @click="goToPage('Dashboard')">
+                                    @click="goToPage('Dashboard', schedule.schdl_id)">
                                     학습완료
                                 </button>
                                 <button v-else type="button" title="바로가기" class="yellow-btn"
-                                    @click="goToPage('Dashboard')">
+                                    @click="goToPage('Dashboard', schedule.schdl_id)">
                                     바로가기
                                 </button>
                                 <div><img src="../../../resources/img/img214_19s.png" alt=""></div>
@@ -49,7 +49,7 @@
                         <p class="title">오늘 공부를 계획해봅시다.</p>
                         <p class="title1 mt20"> 스스로 학습 일정을 바꿔볼까요?</p>
                     </div>
-                    <button type="button" title="바로가기" class="yellow-btn" @click="goToPage('MyPlan2')">
+                    <button type="button" title="바로가기" class="yellow-btn" @click="goToPage2('MyPlan2')">
                         바로가기
                     </button>
                 </div>
@@ -102,7 +102,49 @@
         }
     },
     methods: {
-        goToPage(page) {
+        goToPage(page, scheduleId) {
+            const startScheduleIndex = this.schedules.findIndex(schedule => schedule.schdl_id === scheduleId);
+
+            if (startScheduleIndex === -1) {
+                console.error("해당 스케줄을 찾을 수 없습니다.");
+                return;
+            }
+
+            const updates = [];
+            const currentSchedule = this.schedules[startScheduleIndex];
+            if (currentSchedule.finish === null || currentSchedule.finish === "T") {
+                updates.push(
+                    axios.post("/schedule/scheduleUpdate.json", { scheduleId: currentSchedule.schdl_id, finish: "F" }, {
+                        headers: {
+                            "Content-Type": "application/json; charset=UTF-8",
+                        }
+                    })
+                );
+            }
+
+            for (let i = startScheduleIndex + 1; i < this.schedules.length; i++) {
+                const nextSchedule = this.schedules[i];
+                if (nextSchedule.finish === "T") {
+                    updates.push(
+                        axios.post("/schedule/scheduleUpdate.json", { scheduleId: nextSchedule.schdl_id, finish: "F" }, {
+                            headers: {
+                                "Content-Type": "application/json; charset=UTF-8",
+                            }
+                        })
+                    );
+                }
+            }
+
+            Promise.all(updates)
+                .then(() => {
+                    this.$router.push({ name: page });
+                })
+                .catch(error => {
+                    console.error("Error updating schedules:", error);
+                    alert("학습 계획을 업데이트하는 중 오류가 발생했습니다.");
+                });
+        },
+        goToPage2(page) {
             this.$router.push({ name: page });
         },
         showConfirm(type) {
Add a comment
List