Browse Source

完成关闭指挥功能

愿你天天开心 7 months ago
parent
commit
83391a87d3
1 changed files with 60 additions and 3 deletions
  1. 60 3
      src/views/emergencyCommandMap/LeftSection/CloseCommand.vue

+ 60 - 3
src/views/emergencyCommandMap/LeftSection/CloseCommand.vue

@@ -23,7 +23,9 @@
           <el-option v-for="item in events" :key="item.event_id" :label="item.event_title" :value="item.event_title"></el-option>
         </el-select>
       </el-form-item>
-      <span style="color: red; display: block; margin-top: 10px;margin-left: 10px">注意:本次指挥未关联事件,指挥记录将不会保留,若需要保留指挥记录,请关联事件</span>
+      <span style="color: red; display: block; margin-top: 10px; margin-left: 10px"
+        >注意:本次指挥未关联事件,指挥记录将不会保留,若需要保留指挥记录,请关联事件</span
+      >
     </el-form>
     <div v-else>{{ form.event_title }}</div>
   </Dialog>
@@ -33,6 +35,8 @@
 import { ref, reactive, toRefs, watch, onMounted } from 'vue';
 import { editEvent, registeredEvent, closeEvent, getEventDetail } from '@/api/duty/eventing';
 import { useRouter, useRoute } from 'vue-router';
+import { ElMessage } from 'element-plus'; // 确保已正确导入 ElMessage
+
 const proxy = getCurrentInstance()?.proxy;
 const router = useRouter();
 const buttonLoading = ref(false);
@@ -87,6 +91,7 @@ const fetchEventDetail = async (id: string) => {
     if (response && response.data) {
       form.value = response.data;
     }
+    console.log('Event detail:', form.value);
   } catch (error) {
     console.error('Failed to fetch event detail:', error);
   }
@@ -126,6 +131,7 @@ watch(
   }
 );
 
+// 关闭对话框
 const closeDialog = () => {
   emits('update:modelValue', false);
   if (eventFormRef.value) {
@@ -133,6 +139,8 @@ const closeDialog = () => {
   }
   // 不需要重置 form.value.event_id 和 form.value.event_title
 };
+
+// 结束指挥
 const endProcess = () => {
   // 如果 flag 为 false,则需要选择一个事件
   if (!props.flag) {
@@ -173,7 +181,8 @@ const endProcess = () => {
   }
 };
 
-const submitForm = async () => {
+// 提交表单
+/*const submitForm = async () => {
   return new Promise((resolve, reject) => {
     eventFormRef.value?.validate(async (valid) => {
       if (valid) {
@@ -186,7 +195,7 @@ const submitForm = async () => {
             latitude: form.value.latitude,
             longitude: form.value.longitude
           };
-          console.log('Sending request with params:', params); // 添加调试信息
+          console.log('使用参数发送请求:', params); // 添加调试信息
           // 提交关闭事件请求
           await closeEvent(params);
           proxy?.$modal.msgSuccess('已成功关闭');
@@ -205,8 +214,55 @@ const submitForm = async () => {
       }
     });
   });
+};*/
+
+// 提交选择的事件信息
+const submitForm = async () => {
+  // 仅在 props.flag 为 false 时进行表单验证
+  if (!props.flag) {
+    const valid = await eventFormRef.value?.validate();
+
+    if (!valid) {
+      ElMessage.error('表单验证失败,请检查您的输入');
+      throw new Error('Validation failed');
+    }
+  }
+
+  // 设置按钮加载状态
+  buttonLoading.value = true;
+
+  try {
+    // 构造请求参数
+    const params = {
+      eventId: form.value.event_id,
+      address: form.value.address,
+      latitude: form.value.latitude,
+      longitude: form.value.longitude
+    };
+    console.log('使用参数发送请求:', params); // 添加调试信息
+
+    // 提交关闭事件请求
+    await closeEvent(params);
+
+    // 显示成功消息
+    ElMessage.success('已成功关闭');
+
+    // 关闭对话框
+    closeDialog();
+
+    // 如果需要返回特定信息,可以在这里返回
+    return;
+  } catch (error) {
+    console.error('Failed to close event:', error);
+    ElMessage.error('关闭事件失败,请检查您的输入');
+    throw error; // 继续抛出错误以便上层处理
+  } finally {
+    // 重置按钮加载状态
+    buttonLoading.value = false;
+  }
 };
 
+// 提交选择的事件信息
 const submitSelectedEvent = async () => {
   // 提交选择的事件信息
   if (form.value.event_id) {
@@ -227,6 +283,7 @@ const submitSelectedEvent = async () => {
   }
 };
 
+// 选择事件
 const selectEvent = (eventTitle) => {
   const selectedItem = events.value.find((event) => event.event_title === eventTitle);
   if (selectedItem) {