/*
 *请求获取省市区
 *已提供给地区选择picker组件使用
 */
import ajaxService from '@/services/ajax.service.js'
import PublicService from '@/services/public.service'

const _PublicService = new PublicService(ajaxService)

const provinceData = []
const cityData = []
const areaData = []

_PublicService.GetAllAddressData().then(res => {
    let list = res.data
    list.forEach(item => {
        let xxx = handleCitys(item)
        provinceData.push(item)
        cityData.push(xxx.e)
        areaData.push(xxx.f)
        let list = res.data
        list.forEach(item => {
            let xxx = handleCitys(item)
            provinceData.push(item)
            cityData.push(xxx.e)
            areaData.push(xxx.f)
        })
    })
    //获取市后继续处理
    function handleCitys(data) {
        const x = []
        const s = []
        if (data.cityList.length) {
            data.cityList.forEach(item => {
                let xxx = handleTowns(item)
                s.push(xxx)
                x.push(item)
            })
        } else {
            s.push([{
                name: ''
            }])
            x.push([{
                name: ''
            }])
        }
        return {
            e: x,
            f: s,
        }
    }
    //获取区后继续处理
    function handleTowns(data) {
        const x = []
        data.townList.forEach(item => {
            x.push(item)
        })
        return x
    }

    function handleData3(data) {
        const xxx = []
        data.forEach(item => {
            const ooo = []
            item.forEach(opt => {
                opt.forEach(z => {
                    ooo.push(z)
                })
            })
            xxx.push(ooo)
        })
        return xxx
    }
})
module.exports = {
    provinceData,
    cityData,
    areaData
}
