diff --git a/src/views/components/CityOptions/index.vue b/src/views/components/CityOptions/index.vue index 5561177..1dcc947 100644 --- a/src/views/components/CityOptions/index.vue +++ b/src/views/components/CityOptions/index.vue @@ -3,7 +3,7 @@ ref="formRef" :model="modelValue" :rules="rules" - :label-width="labelWidth + 'px'" + :label-width="`${labelWidth}px`" > @@ -14,7 +14,9 @@ @@ -50,6 +54,8 @@ { const resp = await provinceList(); - provinceSelectList.value = resp.data; + provinceSelectList.value = resp.data.map((el) => { + return { ...el, provinceCode: el.provinceCode.toString() }; + }); }; // 获取市列表 const getCityListByProvinceId = async (provinceId) => { const { data } = await cityList(provinceId); - citySelectList.value = data; + citySelectList.value = data.map((el) => { + return { + ...el, + cityCode: el.cityCode.toString(), + }; + }); }; // 根据市id获取县区列表 const getAreaListByCityId = async (cityId) => { const { data } = await districtList(cityId); - districtSelectList.value = data; + districtSelectList.value = data.map((el) => { + return { + ...el, + areaCode: el.areaCode.toString(), + }; + }); }; // 当省改变时 const provinceChanged = () => { @@ -132,9 +150,25 @@ const cityChanged = () => { }; const validateForm = async () => { - return await formRef.value.validate(); + try { + return await formRef.value.validate(); + } catch (error) { + return false; + } }; +// watch(modelValue, (val) => { +// console.log(val); +// }); + getProvinceList(); +watch(modelValue, (val) => { + if (val.province) { + getCityListByProvinceId(val.province); + } + if (val.city) { + getAreaListByCityId(val.city); + } +}); defineExpose({ validateForm, diff --git a/src/views/components/ExpertForm/index.vue b/src/views/components/ExpertForm/index.vue index e16b341..13070a3 100644 --- a/src/views/components/ExpertForm/index.vue +++ b/src/views/components/ExpertForm/index.vue @@ -1,5 +1,4 @@