/*
 *请求获取省市区
 *已提供给地区选择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 address = handleCitys(item);
		provinceData.push(item);
		cityData.push(address.e);
		areaData.push(address.f);
	})
	//获取市后继续处理
	function handleCitys(data) {
	    const x = [];
	    const s = [];
	    if (data.children.length) {
	        data.children.forEach(item => {
				let city = handleTowns(item);
				s.push(city);
				x.push(item)
	        })
	    }else{
			s.push([{name:''}]);
			x.push([{name:''}]);
		}
	    return {
	        e: x,
	        f: s,
	    };
	}
	//获取区后继续处理
	function handleTowns(data) {
	    const x = [];
	    data.children.forEach(item => {
	        x.push(item)
	    })
	    return x;
	}
})
module.exports = {
	provinceData,
	cityData,
	areaData
}