Browse Source

fix: 3277 3457 3455

sgc 1 tháng trước cách đây
mục cha
commit
469f98423f

+ 22 - 1
src/views/dynamicManagement/publishDynamic.vue

@@ -73,11 +73,13 @@
           <el-select
             v-model="formData.storePosition"
             filterable
+            clearable
             placeholder="请输入地址进行查询"
             remote
             reserve-keyword
             :remote-method="getLonAndLat"
             @change="selectAddress"
+            @clear="handleClearLocation"
           >
             <el-option v-for="item in addressList" :key="item.id" :label="item.name" :value="item.location">
               <span style="float: left">{{ item.name }}</span>
@@ -214,7 +216,13 @@ const getLonAndLat = async (keyword: string) => {
   }
 };
 const selectAddress = async (param: any) => {
-  if (!formData.storePosition || typeof formData.storePosition !== "string") {
+  // 如果清空了位置,清空相关字段
+  if (!formData.storePosition || formData.storePosition === "") {
+    handleClearLocation();
+    return;
+  }
+
+  if (typeof formData.storePosition !== "string") {
     ElMessage.warning("地址格式不正确,请重新选择");
     return;
   }
@@ -236,6 +244,19 @@ const selectAddress = async (param: any) => {
   formData.storePositionLatitude = locationList[1]?.trim();
 };
 
+// 清空位置
+const handleClearLocation = () => {
+  formData.storePosition = "";
+  formData.queryAddress = "";
+  formData.storePositionLongitude = "";
+  formData.storePositionLatitude = "";
+  formData.addressProvince = "";
+  formData.location = "";
+  formData.locationId = "";
+  formData.address = "";
+  addressList.value = [];
+};
+
 // 表单验证规则
 const rules = reactive<FormRules<FormData>>({
   title: [{ required: true, message: "请输入标题", trigger: "blur" }],

+ 68 - 12
src/views/storeDecoration/basicStoreInformation/index.vue

@@ -838,6 +838,10 @@ const formRef = ref<FormInstance>();
 const loading = ref(false);
 // 标记是否正在加载详情数据,用于防止触发 watch
 const isLoadingDetail = ref(false);
+// 保存原始的经营板块值,用于确认对话框
+const originalBusinessSection = ref<number | "">("");
+// 标记是否正在恢复原值,防止触发 watch 递归
+const isRestoringValue = ref(false);
 
 // 店铺评价三个输入框的独立变量
 const storeEvaluate1 = ref("");
@@ -1280,6 +1284,8 @@ const getStoreDetailData = async () => {
       if (storeData.businessSection) {
         formData.businessSection = storeData.businessSection;
         formData.businessSectionName = storeData.businessSectionName ?? "";
+        // 保存原始的经营板块值
+        originalBusinessSection.value = storeData.businessSection;
       }
       // 设置标签选择(仅当经营板块为生活服务时)
       if (storeData.businessSection === 3) {
@@ -1303,25 +1309,75 @@ const getStoreDetailData = async () => {
 // 监听经营板块变化,更新经营板块名称
 watch(
   () => formData.businessSection,
-  newValue => {
+  async (newValue, oldValue) => {
     // 如果正在加载详情数据,不触发 watch(避免重复请求)
     if (isLoadingDetail.value) {
       return;
     }
-    if (newValue) {
-      const selectedSection = businessSectionList.value.find(item => item.dictId === newValue);
-      formData.businessSectionName = selectedSection ? selectedSection.dictDetail : "";
-      // 当切换到生活服务时,如果经营类目是 0,清空它
-      if (newValue === 3 && formData.businessCategoryName === "0") {
-        formData.businessCategoryName = "";
+
+    // 如果正在恢复原值,不处理
+    if (isRestoringValue.value) {
+      return;
+    }
+
+    // 如果是首次加载或值没有变化,直接更新原始值
+    if (originalBusinessSection.value === "" || oldValue === undefined) {
+      originalBusinessSection.value = newValue;
+      if (newValue) {
+        const selectedSection = businessSectionList.value.find(item => item.dictId === newValue);
+        formData.businessSectionName = selectedSection ? selectedSection.dictDetail : "";
+        // 当切换到生活服务时,如果经营类目是 0,清空它
+        if (newValue === 3 && formData.businessCategoryName === "0") {
+          formData.businessCategoryName = "";
+        }
+        // 当切换到非生活服务时,清空标签选择
+        if (newValue !== 3) {
+          formData.storeTickets = "";
+        }
+      } else {
+        // 如果经营板块为空,也清空标签选择
+        formData.storeTickets = "";
       }
-      // 当切换到非生活服务时,清空标签选择
-      if (newValue !== 3) {
+      return;
+    }
+
+    // 如果值没有变化,不处理
+    if (newValue === oldValue) {
+      return;
+    }
+
+    // 弹出确认对话框
+    try {
+      await ElMessageBox.confirm("更改经营板块需要同步更换营业执照等信息,如不更换可能会导致审核不通过", "确认更改么?", {
+        confirmButtonText: "确认",
+        cancelButtonText: "取消",
+        type: "warning"
+      });
+
+      // 用户确认,更新值
+      originalBusinessSection.value = newValue;
+      if (newValue) {
+        const selectedSection = businessSectionList.value.find(item => item.dictId === newValue);
+        formData.businessSectionName = selectedSection ? selectedSection.dictDetail : "";
+        // 当切换到生活服务时,如果经营类目是 0,清空它
+        if (newValue === 3 && formData.businessCategoryName === "0") {
+          formData.businessCategoryName = "";
+        }
+        // 当切换到非生活服务时,清空标签选择
+        if (newValue !== 3) {
+          formData.storeTickets = "";
+        }
+      } else {
+        // 如果经营板块为空,也清空标签选择
         formData.storeTickets = "";
       }
-    } else {
-      // 如果经营板块为空,也清空标签选择
-      formData.storeTickets = "";
+    } catch {
+      // 用户取消,恢复原值
+      isRestoringValue.value = true;
+      formData.businessSection = originalBusinessSection.value;
+      nextTick(() => {
+        isRestoringValue.value = false;
+      });
     }
   }
 );