Commit 7302113c9a30c4b2dd729b44babf1c0f9a6715e4
1 parent
386a5629
fix: 客户管理省市接口报错
Showing
1 changed file
with
15 additions
and
12 deletions
src/pages/Client/Client/Components/ClientDrawer.tsx
... | ... | @@ -213,20 +213,22 @@ export default ({ optType, record, onFinish }) => { |
213 | 213 | ]} |
214 | 214 | request={async () => { |
215 | 215 | let cityOptions = []; |
216 | + const idValue = form.getFieldValue('id'); | |
217 | + console.log('Form ID Value:', idValue); | |
216 | 218 | console.log(form.getFieldValue('id')); |
217 | - if (form.getFieldValue('id')) { | |
219 | + if (idValue) { | |
218 | 220 | const resp = await postDistrictSelOrderProvince({ |
219 | - data: form.getFieldValue('id'), | |
221 | + data: { id: idValue }, | |
220 | 222 | }); |
221 | 223 | if ( |
222 | - resp.data.province !== null && | |
223 | - resp.data.province !== undefined | |
224 | + resp?.data?.province !== null && | |
225 | + resp?.data?.province !== undefined | |
224 | 226 | ) { |
225 | 227 | console.log('province is ok'); |
226 | 228 | let res = await postDistrictSelectByNameAndLevel({ |
227 | 229 | data: { district: resp.data.province, level: 1 }, |
228 | 230 | }); |
229 | - if (res && res.data) { | |
231 | + if (res && res?.data) { | |
230 | 232 | cityOptions = res.data.map((item) => ({ |
231 | 233 | value: item.district, |
232 | 234 | label: item.district, |
... | ... | @@ -234,7 +236,7 @@ export default ({ optType, record, onFinish }) => { |
234 | 236 | } |
235 | 237 | } |
236 | 238 | } |
237 | - if (province !== '') { | |
239 | + if (province) { | |
238 | 240 | console.log(province); |
239 | 241 | console.log('province is okk'); |
240 | 242 | let res = await postDistrictSelectByNameAndLevel({ |
... | ... | @@ -271,15 +273,16 @@ export default ({ optType, record, onFinish }) => { |
271 | 273 | ]} |
272 | 274 | request={async () => { |
273 | 275 | let districtOptions = []; |
274 | - if (form.getFieldValue('id')) { | |
276 | + const idValue = form.getFieldValue('id'); | |
277 | + if (idValue) { | |
275 | 278 | const resp = await postDistrictSelOrderProvince({ |
276 | - data: form.getFieldValue('id'), | |
279 | + data: { id: idValue }, | |
277 | 280 | }); |
278 | - if (resp.data.city !== null && resp.data.city !== undefined) { | |
281 | + if (resp?.data?.city !== null && resp.data.city !== undefined) { | |
279 | 282 | let res = await postDistrictSelectByNameAndLevel({ |
280 | 283 | data: { district: resp.data.city, level: 2 }, |
281 | 284 | }); |
282 | - if (res && res.data) { | |
285 | + if (res && res?.data) { | |
283 | 286 | districtOptions = res.data.map((item) => ({ |
284 | 287 | value: item.district, |
285 | 288 | label: item.district, |
... | ... | @@ -287,11 +290,11 @@ export default ({ optType, record, onFinish }) => { |
287 | 290 | } |
288 | 291 | } |
289 | 292 | } |
290 | - if (city !== '') { | |
293 | + if (city) { | |
291 | 294 | let res = await postDistrictSelectByNameAndLevel({ |
292 | 295 | data: { district: city, level: 2 }, |
293 | 296 | }); |
294 | - if (res && res.data) { | |
297 | + if (res && res?.data) { | |
295 | 298 | districtOptions = res.data.map((item) => ({ |
296 | 299 | value: item.district, |
297 | 300 | label: item.district, | ... | ... |