Commit 09595810f07a908df63814b39e3882db0c26adc6
Merge branch 'ww' into 'main'
perf: 企业信息所在城市接口新增查询参数 See merge request yunteng/thingskit-front!511
Showing
1 changed file
with
75 additions
and
114 deletions
| ... | ... | @@ -2,6 +2,13 @@ import type { FormSchema } from '/@/components/Form/index'; |
| 2 | 2 | import { getAreaList } from '/@/api/oem/index'; |
| 3 | 3 | import { emailRule, phoneRule } from '/@/utils/rules'; |
| 4 | 4 | |
| 5 | +export enum Level { | |
| 6 | + PROVINCE = 'PROVINCE', | |
| 7 | + CITY = 'CITY', | |
| 8 | + COUNTY = 'COUNTY', | |
| 9 | + TOWN = 'TOWN', | |
| 10 | +} | |
| 11 | + | |
| 5 | 12 | export const schemas: FormSchema[] = [ |
| 6 | 13 | { |
| 7 | 14 | field: 'name', |
| ... | ... | @@ -201,150 +208,104 @@ export const provSchemas: FormSchema[] = [ |
| 201 | 208 | colProps: { |
| 202 | 209 | span: 6, |
| 203 | 210 | }, |
| 204 | - componentProps({ formModel, formActionType }) { | |
| 205 | - const { updateSchema } = formActionType; | |
| 211 | + componentProps({ formActionType }) { | |
| 212 | + const { setFieldsValue } = formActionType; | |
| 206 | 213 | return { |
| 207 | 214 | api: getAreaList, |
| 208 | 215 | labelField: 'name', |
| 209 | 216 | valueField: 'code', |
| 210 | 217 | placeholder: '省份', |
| 211 | - params: { parentId: 1 }, | |
| 212 | - async onChange(value) { | |
| 213 | - if (value === undefined) { | |
| 214 | - formModel.nameCity = undefined; // reset city value | |
| 215 | - formModel.nameCoun = undefined; | |
| 216 | - formModel.nameTown = undefined; | |
| 217 | - updateSchema([ | |
| 218 | - { | |
| 219 | - field: 'nameCity', | |
| 220 | - componentProps: { | |
| 221 | - options: [], | |
| 222 | - placeholder: '城市', | |
| 223 | - }, | |
| 224 | - }, | |
| 225 | - { | |
| 226 | - field: 'nameCoun', | |
| 227 | - componentProps: { | |
| 228 | - options: [], | |
| 229 | - placeholder: '区/县', | |
| 230 | - }, | |
| 231 | - }, | |
| 232 | - { | |
| 233 | - field: 'nameTown', | |
| 234 | - componentProps: { | |
| 235 | - options: [], | |
| 236 | - placeholder: '城镇/街道', | |
| 237 | - }, | |
| 238 | - }, | |
| 239 | - ]); | |
| 240 | - } else { | |
| 241 | - const nameCity = await getAreaList({ parentId: value }); | |
| 242 | - nameCity.forEach((item) => { | |
| 243 | - item.label = item.name; | |
| 244 | - item.value = item.code; | |
| 245 | - }); | |
| 246 | - formModel.nameCity = undefined; // reset city value | |
| 247 | - formModel.nameCoun = undefined; | |
| 248 | - formModel.nameTown = undefined; | |
| 249 | - updateSchema({ | |
| 250 | - field: 'nameCity', | |
| 251 | - componentProps: { | |
| 252 | - options: nameCity, | |
| 253 | - placeholder: '城市', | |
| 254 | - async onChange(value) { | |
| 255 | - if (value === undefined) { | |
| 256 | - formModel.nameCoun = undefined; // reset city value | |
| 257 | - formModel.nameTown = undefined; | |
| 258 | - updateSchema([ | |
| 259 | - { | |
| 260 | - field: 'nameCoun', | |
| 261 | - componentProps: { | |
| 262 | - options: [], | |
| 263 | - }, | |
| 264 | - }, | |
| 265 | - { | |
| 266 | - field: 'nameTown', | |
| 267 | - componentProps: { | |
| 268 | - options: [], | |
| 269 | - }, | |
| 270 | - }, | |
| 271 | - ]); | |
| 272 | - } else { | |
| 273 | - // 获取区数据 | |
| 274 | - const nameCoun = await getAreaList({ parentId: value }); | |
| 275 | - nameCoun.forEach((item) => { | |
| 276 | - item.label = item.name; | |
| 277 | - item.value = item.code; | |
| 278 | - }); | |
| 279 | - updateSchema({ | |
| 280 | - field: 'nameCoun', | |
| 281 | - componentProps: { | |
| 282 | - // 请选择区 | |
| 283 | - options: nameCoun, | |
| 284 | - async onChange(value) { | |
| 285 | - if (value === undefined) { | |
| 286 | - formModel.nameTown = undefined; | |
| 287 | - updateSchema({ | |
| 288 | - field: 'nameTown', | |
| 289 | - componentProps: { | |
| 290 | - placeholder: '城镇/街道', | |
| 291 | - options: [], | |
| 292 | - }, | |
| 293 | - }); | |
| 294 | - } else { | |
| 295 | - const nameTown = await getAreaList({ parentId: value }); | |
| 296 | - nameTown.forEach((item) => { | |
| 297 | - item.label = item.name; | |
| 298 | - item.value = item.code; | |
| 299 | - }); | |
| 300 | - updateSchema({ | |
| 301 | - field: 'nameTown', | |
| 302 | - componentProps: { | |
| 303 | - placeholder: '城镇/街道', | |
| 304 | - options: nameTown, | |
| 305 | - }, | |
| 306 | - }); | |
| 307 | - } | |
| 308 | - }, | |
| 309 | - }, | |
| 310 | - }); | |
| 311 | - } | |
| 312 | - }, | |
| 313 | - }, | |
| 314 | - }); | |
| 315 | - } | |
| 218 | + params: { parentId: 1, level: Level.PROVINCE }, | |
| 219 | + onChange: () => { | |
| 220 | + setFieldsValue({ nameCity: null, nameCoun: null, nameTown: null }); | |
| 316 | 221 | }, |
| 317 | 222 | }; |
| 318 | 223 | }, |
| 319 | 224 | }, |
| 320 | 225 | { |
| 321 | 226 | field: 'nameCity', |
| 322 | - component: 'Select', | |
| 227 | + component: 'ApiSelect', | |
| 323 | 228 | label: '', |
| 324 | 229 | colProps: { |
| 325 | 230 | span: 6, |
| 326 | 231 | }, |
| 232 | + componentProps: ({ formActionType, formModel }) => { | |
| 233 | + const nameProv = Reflect.get(formModel, 'nameProv'); | |
| 234 | + const { setFieldsValue } = formActionType; | |
| 235 | + return { | |
| 236 | + api: async (params: Recordable) => { | |
| 237 | + try { | |
| 238 | + if (!nameProv) return; | |
| 239 | + const result = await getAreaList(params); | |
| 240 | + return result; | |
| 241 | + } catch (error) { | |
| 242 | + return []; | |
| 243 | + } | |
| 244 | + }, | |
| 245 | + labelField: 'name', | |
| 246 | + valueField: 'code', | |
| 247 | + placeholder: '城市', | |
| 248 | + params: { parentId: nameProv, level: Level.CITY }, | |
| 249 | + onChange: () => { | |
| 250 | + setFieldsValue({ nameCoun: null, nameTown: null }); | |
| 251 | + }, | |
| 252 | + }; | |
| 253 | + }, | |
| 327 | 254 | }, |
| 328 | 255 | { |
| 329 | 256 | field: 'nameCoun', |
| 330 | - component: 'Select', | |
| 257 | + component: 'ApiSelect', | |
| 331 | 258 | label: '', |
| 332 | 259 | colProps: { |
| 333 | 260 | span: 6, |
| 334 | 261 | }, |
| 335 | - componentProps: { | |
| 336 | - placeholder: '区/县', | |
| 262 | + componentProps: ({ formActionType, formModel }) => { | |
| 263 | + const nameCity = Reflect.get(formModel, 'nameCity'); | |
| 264 | + const { setFieldsValue } = formActionType; | |
| 265 | + return { | |
| 266 | + api: async (params: Recordable) => { | |
| 267 | + try { | |
| 268 | + if (!nameCity) return; | |
| 269 | + const result = await getAreaList(params); | |
| 270 | + return result; | |
| 271 | + } catch (error) { | |
| 272 | + return []; | |
| 273 | + } | |
| 274 | + }, | |
| 275 | + labelField: 'name', | |
| 276 | + valueField: 'code', | |
| 277 | + placeholder: '区/县', | |
| 278 | + params: { parentId: nameCity, level: Level.COUNTY }, | |
| 279 | + onChange: () => { | |
| 280 | + setFieldsValue({ nameTown: null }); | |
| 281 | + }, | |
| 282 | + }; | |
| 337 | 283 | }, |
| 338 | 284 | }, |
| 339 | 285 | { |
| 340 | 286 | field: 'nameTown', |
| 341 | - component: 'Select', | |
| 287 | + component: 'ApiSelect', | |
| 342 | 288 | label: '', |
| 343 | 289 | colProps: { |
| 344 | 290 | span: 6, |
| 345 | 291 | }, |
| 346 | - componentProps: { | |
| 347 | - placeholder: '城镇/街道', | |
| 292 | + componentProps: ({ formModel }) => { | |
| 293 | + const nameCoun = Reflect.get(formModel, 'nameCoun'); | |
| 294 | + return { | |
| 295 | + api: async (params: Recordable) => { | |
| 296 | + try { | |
| 297 | + if (!nameCoun) return; | |
| 298 | + const result = await getAreaList(params); | |
| 299 | + return result; | |
| 300 | + } catch (error) { | |
| 301 | + return []; | |
| 302 | + } | |
| 303 | + }, | |
| 304 | + labelField: 'name', | |
| 305 | + valueField: 'code', | |
| 306 | + placeholder: '城镇/街道', | |
| 307 | + params: { parentId: nameCoun, level: Level.TOWN }, | |
| 308 | + }; | |
| 348 | 309 | }, |
| 349 | 310 | }, |
| 350 | 311 | ]; | ... | ... |