|
@@ -35,25 +35,41 @@ export default {
|
|
|
const currProvince = yield select(state =>
|
|
const currProvince = yield select(state =>
|
|
|
state.district.data.find(item => item.id === provinceId)
|
|
state.district.data.find(item => item.id === provinceId)
|
|
|
)
|
|
)
|
|
|
|
|
+ const currCity = currProvince?.children?.find(item => item.id === cityId)
|
|
|
// 判断市的数据是否拉取过了
|
|
// 判断市的数据是否拉取过了
|
|
|
- if (currProvince && !currProvince.children?.length) {
|
|
|
|
|
- const { code = -1, data = [] } = yield call(queryDistrict, { parentId: provinceId })
|
|
|
|
|
- if (code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
|
|
+ if (currProvince) {
|
|
|
|
|
+ if (!currCity) {
|
|
|
|
|
+ const { code = -1, data = [] } = yield call(queryDistrict, { parentId: provinceId })
|
|
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
+ const response = yield call(queryDistrict, { parentId: cityId })
|
|
|
|
|
+ if (response?.code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
+ const newData = data.map(item => {
|
|
|
|
|
+ const newItem = { ...item }
|
|
|
|
|
+ if (item.id === cityId) {
|
|
|
|
|
+ newItem.children = response.data
|
|
|
|
|
+ }
|
|
|
|
|
+ return newItem
|
|
|
|
|
+ })
|
|
|
|
|
+ yield put({
|
|
|
|
|
+ type: 'changeState',
|
|
|
|
|
+ payload: {
|
|
|
|
|
+ data: newData,
|
|
|
|
|
+ parentId: provinceId,
|
|
|
|
|
+ level: 1
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (currCity && !currCity.children) {
|
|
|
|
|
+ // 说明city存在,但是对应的children不存在
|
|
|
const response = yield call(queryDistrict, { parentId: cityId })
|
|
const response = yield call(queryDistrict, { parentId: cityId })
|
|
|
if (response?.code === consts.RET_CODE.SUCCESS) {
|
|
if (response?.code === consts.RET_CODE.SUCCESS) {
|
|
|
- const newData = data.map(item => {
|
|
|
|
|
- const newItem = { ...item }
|
|
|
|
|
- if (item.id === cityId) {
|
|
|
|
|
- newItem.children = response.data
|
|
|
|
|
- }
|
|
|
|
|
- return newItem
|
|
|
|
|
- })
|
|
|
|
|
yield put({
|
|
yield put({
|
|
|
type: 'changeState',
|
|
type: 'changeState',
|
|
|
payload: {
|
|
payload: {
|
|
|
- data: newData,
|
|
|
|
|
- parentId: provinceId,
|
|
|
|
|
- level: 1
|
|
|
|
|
|
|
+ data: response.data,
|
|
|
|
|
+ parentId: cityId,
|
|
|
|
|
+ level: 2
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|