Kaynağa Gözat

模态框关闭表单清空验证

wxy 4 ay önce
ebeveyn
işleme
f3b1f5748b

+ 16 - 12
src/views/tariffManagement/customer/NewCustomerForm.vue

@@ -202,9 +202,9 @@
             </a-input-number>
           </a-form-item>
           <a-form-item field="warnEmail" :label="$t('forewarning.WarningMailbox')" required validate-trigger="blur">
-            <a-input-number v-model="formData.warnEmail" :style="{ width: '320px' }"
-              :placeholder="$t('form.datapoolForm.pleaseEnter')" allow-clear hide-button>
-            </a-input-number>
+            <a-input v-model="formData.warnEmail" :style="{ width: '320px' }"
+              :placeholder="$t('form.datapoolForm.pleaseEnter')" allow-clear>
+            </a-input>
           </a-form-item>
         </a-form>
       </a-tab-pane>
@@ -237,7 +237,7 @@ const roles = ref([])
 watch(
   () => props.editData,
   (newVal) => {
-    if (newVal && props.editMode ) {
+    if (newVal && props.editMode) {
       // 深拷贝编辑数据
       const editDataCopy = JSON.parse(JSON.stringify(newVal));
       delete editDataCopy.alert.id
@@ -250,7 +250,7 @@ watch(
       let flasAlert = {}
       if (editDataCopy.info) {
         flattenedFormData = { ...editDataCopy.info }; // 展平 info 的键值对
-        flasAlert = {...editDataCopy.alert}
+        flasAlert = { ...editDataCopy.alert }
         delete editDataCopy.info; // 删除原始 info 字段
         delete editDataCopy.alert; // 删除原始 info 字段
       }
@@ -356,9 +356,6 @@ const handleSubmit = () => {
       }
       if (response.code === 200) {
         Message.success(props.editMode ? t('customer.updateSuccess') : t('customer.addSuccess'));
-        Object.keys(formData.value).forEach(key => {
-          formData.value[key] = ''
-        })
         emit('submit', true);
         emit('update:visible', false);
       } else {
@@ -406,10 +403,17 @@ const getRolesData = async () => {
     roles.value = res.data
   }
 }
-onMounted(() => {
-  getRolesData()
-  getDistList()
-})
+
+watch(() => props.visible, val => {
+  if (!val) {
+    Object.keys(formData.value).forEach(key => {
+      formData.value[key] = ''
+    })
+  } else {
+    getRolesData()
+    getDistList()
+  }
+},{immediate:true})
 
 </script>