1234567891011121314151617 |
- import { getDict } from '@/hooks/web/useDictionaries'
- // 根据市获取省份
- export const cityToProvince = async (cityId, query, parentList = []) => { // cityToProvince(workAreaId, {}, province.items || [])
- if (!cityId) return cityId
- query = { pid: true, cityList: true, ...query }
- const obj = {}
- if (query.cityList || query.pid) {
- const areaMap = await getDict('areaMap', {}, 'areaMap')
- obj.pid = areaMap?.data && areaMap?.data[cityId]?.parentId
- if (query.cityList && obj.pid) {
- const parent = parentList.find(pv => pv.id === obj.pid)
- obj.cityList = parent?.children.length ? parent.children : []
- }
- }
- return obj
- }
|