|
@@ -0,0 +1,238 @@
|
|
|
+/* eslint-disable */
|
|
|
+export var cityData =[]
|
|
|
+export var areaData =[]
|
|
|
+export var provinceData = []
|
|
|
+export var cityInfoList = []
|
|
|
+
|
|
|
+function appendProvinceData(province){
|
|
|
+ let index = findProvinceDataById(province.id);
|
|
|
+ if(index == -1)
|
|
|
+ {
|
|
|
+ province.value = province.id;
|
|
|
+ province.label = province.name;
|
|
|
+ province.index = provinceData.length;
|
|
|
+ provinceData.push(province);
|
|
|
+ cityData.push([])
|
|
|
+ areaData.push([])
|
|
|
+ }
|
|
|
+}
|
|
|
+function appendCityData(city,province){
|
|
|
+ /*let parentIndex = findProvinceDataById(city.parentId);
|
|
|
+ if(parentIndex<0)
|
|
|
+ {
|
|
|
+ console.log('未初始化城市数组');
|
|
|
+ return;
|
|
|
+ }*/
|
|
|
+ //console.log('city '+JSON.stringify(cityData))
|
|
|
+ let parentIndex = province.index;
|
|
|
+ let index = findCityDataById(parentIndex,city.id);
|
|
|
+ city.value = city.id;
|
|
|
+ city.label = city.name;
|
|
|
+ if(parentIndex>=cityData.length)
|
|
|
+ {
|
|
|
+ console.log('未初始化城市数组');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(index>=0)
|
|
|
+ return;
|
|
|
+
|
|
|
+
|
|
|
+ city.index = cityData[parentIndex].length;
|
|
|
+ //console.log('length '+ cityData[parentIndex].length);
|
|
|
+ cityData[parentIndex].push(city);
|
|
|
+ areaData[parentIndex].push([]);
|
|
|
+ //if(cityData[parentIndex].length>10)
|
|
|
+ // return;
|
|
|
+ //console.log('parentIndex '+parentIndex + JSON.stringify(cityData[parentIndex]))
|
|
|
+}
|
|
|
+function appendAreaData(area,province){
|
|
|
+
|
|
|
+ let provinceIndex = province.index;
|
|
|
+ //let provinceIndex = findProvinceDataById(province.id);
|
|
|
+ let parentIndex = findCityDataById(provinceIndex,area.parentId);
|
|
|
+ if(parentIndex<0)
|
|
|
+ {
|
|
|
+ console.log('未初始化城市数组' + JSON.stringify(province) + JSON.stringify(area));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let index = findAreaDataById(provinceIndex,parentIndex,area);
|
|
|
+ area.value = area.id;
|
|
|
+ area.label = area.name;
|
|
|
+ if(parentIndex>=areaData.length)
|
|
|
+ {
|
|
|
+ console.log('未初始化城市数组');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(index>=0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ area.index = areaData[parentIndex].length;
|
|
|
+ areaData[provinceIndex][parentIndex].push(area);
|
|
|
+}
|
|
|
+function findProvinceDataById(id){
|
|
|
+ for(let i = 0;i< provinceData.length;i++){
|
|
|
+ if(provinceData[i].id == id)
|
|
|
+ {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //console.log('not find '+id)
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+function findCityDataById(index,id){
|
|
|
+ if(index >= cityData.length)
|
|
|
+ return -1;
|
|
|
+ for(let i = 0;i< cityData[index].length;i++){
|
|
|
+ if(cityData[index][i].id == id)
|
|
|
+ {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //console.log('not find city' + id +JSON.stringify(cityData[index]))
|
|
|
+ return -2;
|
|
|
+}
|
|
|
+function findAreaDataById(parentIndex,index,id){
|
|
|
+ if(parentIndex >= areaData.length)
|
|
|
+ return -1;
|
|
|
+ if(index >= areaData[parentIndex].length)
|
|
|
+ return -2;
|
|
|
+
|
|
|
+ for(let i = 0;i< areaData[parentIndex][index].length;i++){
|
|
|
+ if(areaData[parentIndex][index][i].id == id)
|
|
|
+ {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -3;
|
|
|
+}
|
|
|
+function findProvinceData(province){
|
|
|
+ for(let i = 0;i< provinceData.length;i++){
|
|
|
+ if(provinceData[i].name == province.name)
|
|
|
+ {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+function findCityData(city){
|
|
|
+ let index = {provinceIndex:-1,cityIndex:-1};
|
|
|
+ for(let i = 0;i < cityData.length;i++)
|
|
|
+ {
|
|
|
+ if(cityData[i]){
|
|
|
+ for(let j=0;j< cityData[i].length;j++)
|
|
|
+ {
|
|
|
+ if(cityData[i].parentId != city.parentId)
|
|
|
+ break;
|
|
|
+
|
|
|
+ index.provinceIndex = i;
|
|
|
+ if(cityData[i].name == city.name)
|
|
|
+ {
|
|
|
+ index.cityIndex = j;
|
|
|
+ return index;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return index;
|
|
|
+}
|
|
|
+function findAreaData(area){
|
|
|
+ let index = {cityIndex:-1,areaIndex:-1};
|
|
|
+ for(let i = 0;i < areaData.length;i++)
|
|
|
+ {
|
|
|
+ if(areaData[i]){
|
|
|
+ for(let j=0;j< areaData[i].length;j++)
|
|
|
+ {
|
|
|
+ if(areaData[i].parentId != area.parentId)
|
|
|
+ break;
|
|
|
+
|
|
|
+ index.cityIndex = i;
|
|
|
+ if(areaData[i].name == area.name)
|
|
|
+ {
|
|
|
+ index.areaIndex = j;
|
|
|
+ return index;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return index;
|
|
|
+}
|
|
|
+
|
|
|
+export function getCityPosition(id){
|
|
|
+ let area = cityInfoList[id-1];
|
|
|
+ if(area == null)
|
|
|
+ return [0,0,0]
|
|
|
+ let city = cityInfoList[area.parentId-1];
|
|
|
+ if(city == null)
|
|
|
+ return [0,0,0]
|
|
|
+ let province = cityInfoList[city.parentId-1];
|
|
|
+ if(province == null)
|
|
|
+ return [0,0,0]
|
|
|
+ let pos =[0,0,0];
|
|
|
+ pos[0] = findProvinceDataById(province.id);
|
|
|
+ pos[1] = findCityDataById(pos[0],city.id);
|
|
|
+ pos[2] = findAreaDataById(pos[0],pos[1],area.id);
|
|
|
+ return pos
|
|
|
+ //return province.name +'-'+city.name +'-'+area.name;
|
|
|
+}
|
|
|
+export function getAeraData(id){
|
|
|
+ let area = cityInfoList[id-1];
|
|
|
+ if(area == null)
|
|
|
+ return ''
|
|
|
+ console.log('获取区域'+JSON.stringify(area))
|
|
|
+ return area.name;
|
|
|
+}
|
|
|
+export function getCityData(id){
|
|
|
+ let area = cityInfoList[id-1];
|
|
|
+ if(area == null)
|
|
|
+ return ''
|
|
|
+ let city = cityInfoList[area.parentId-1];
|
|
|
+ if(city == null)
|
|
|
+ return area.name;
|
|
|
+ let province = cityInfoList[city.parentId-1];
|
|
|
+ if(province == null)
|
|
|
+ return ''
|
|
|
+ let name = province.name +'-'+city.name +'-'+area.name;
|
|
|
+ console.log('name '+name);
|
|
|
+ return name;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+export function setCityData(cityList){
|
|
|
+// console.log('设置城市'+JSON.stringify(cityList))
|
|
|
+ cityInfoList = cityList
|
|
|
+
|
|
|
+ provinceData = [];
|
|
|
+ cityData = [];
|
|
|
+ areaData = [];
|
|
|
+ for(let i = 0;i<cityList.length;i++){
|
|
|
+ if(cityList[i].type == 1){
|
|
|
+ appendProvinceData(cityList[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //console.log('省份'+JSON.stringify(provinceData))
|
|
|
+ //cityData = new Array(provinceData.length).fill(new Array());
|
|
|
+ //console.log('省份'+JSON.stringify(cityData))
|
|
|
+ //return;
|
|
|
+
|
|
|
+ for(let i = 0;i<cityList.length;i++){
|
|
|
+ if(cityList[i].type == 2){
|
|
|
+ let province= cityList[cityList[i].parentId-1];
|
|
|
+ //console.log('省'+JSON.stringify(province)+'市'+JSON.stringify(cityList[i]))
|
|
|
+ appendCityData(cityList[i],province);
|
|
|
+ //appendCityData(cityList[i],province);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //console.log('城市'+JSON.stringify(cityData))
|
|
|
+ //return;
|
|
|
+ //areaData = new Array(cityData.length).fill([]);
|
|
|
+ for(let i = 0;i<cityList.length;i++){
|
|
|
+ if(cityList[i].type == 3){
|
|
|
+ let city= cityList[cityList[i].parentId-1];
|
|
|
+ let province = cityList[city.parentId-1];
|
|
|
+ appendAreaData(cityList[i],province);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //console.log('区'+JSON.stringify(areaData))
|
|
|
+}
|
|
|
+
|
|
|
+//export default {provinceData,setCityData};
|