|
@@ -11,21 +11,53 @@ export default {
|
|
|
const response = yield call(queryDistrict, payload)
|
|
const response = yield call(queryDistrict, payload)
|
|
|
if (response && response.code === consts.RET_CODE.SUCCESS) {
|
|
if (response && response.code === consts.RET_CODE.SUCCESS) {
|
|
|
yield put({
|
|
yield put({
|
|
|
- type: 'show',
|
|
|
|
|
- payload: response.data
|
|
|
|
|
|
|
+ type: 'changeState',
|
|
|
|
|
+ payload: {
|
|
|
|
|
+ data: response.data,
|
|
|
|
|
+ parentId: payload && payload.parentId ? payload.parentId : '',
|
|
|
|
|
+ level: payload && payload.level ? payload.level : ''
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
- // console.log(response)
|
|
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
// reducers:用于处理同步操作,由action触发,可修改state
|
|
// reducers:用于处理同步操作,由action触发,可修改state
|
|
|
reducers: {
|
|
reducers: {
|
|
|
// action:是由reducers及effects的触发器,一般是第一个对象,如:{type:'add',payload:todo}
|
|
// action:是由reducers及effects的触发器,一般是第一个对象,如:{type:'add',payload:todo}
|
|
|
- show(state, action) {
|
|
|
|
|
|
|
+ changeState(state, action) {
|
|
|
|
|
+ const pid = action.payload && action.payload.parentId
|
|
|
|
|
+ const level = action.payload && action.payload.level
|
|
|
|
|
+ if (pid) {
|
|
|
|
|
+ const newData = state.data && state.data.map(item => {
|
|
|
|
|
+ const newItem = item
|
|
|
|
|
+ if (level === item.level) {
|
|
|
|
|
+ // 第一层
|
|
|
|
|
+ if (item.id === pid) {
|
|
|
|
|
+ newItem.loading = false
|
|
|
|
|
+ newItem.children = action.payload.data
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 第二层
|
|
|
|
|
+ newItem.children = item.children && item.children.map(secondItem => {
|
|
|
|
|
+
|
|
|
|
|
+ const newSecondItem = secondItem
|
|
|
|
|
+ if (secondItem.id === pid) {
|
|
|
|
|
+ newItem.loading = false
|
|
|
|
|
+ newSecondItem.children = action.payload.data
|
|
|
|
|
+ }
|
|
|
|
|
+ return newSecondItem
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ return newItem
|
|
|
|
|
+ })
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...state,
|
|
|
|
|
+ data: newData
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return {
|
|
return {
|
|
|
...state,
|
|
...state,
|
|
|
- data: action.payload
|
|
|
|
|
|
|
+ data: action.payload.data
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|