riku
2022-09-15 bd3a9d7086f5a428b385599ba2cb08299b22c0df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const Province = {
  "上海市": ["上海市"]
}
const City = {
  "上海市": ['金山区', '徐汇区', '静安区', '普陀区', '长宁区', '虹口区', '杨浦区', '闵行区', '宝山区', '嘉定区', '浦东新区', '黄浦区', '松江区', '青浦区', '奉贤区', '崇明区']
}
const District = {
  //上海市
  '金山区': ['石化街道', '金山工业区', '金山第二工业区', '朱泾镇', '枫泾镇', '张堰镇', '亭林镇', '吕巷镇', '廊下镇', '金山卫镇', '漕泾镇', '山阳镇'],
  '徐汇区': [],
  '长宁区': [],
  '静安区': [],
  '普陀区': [],
  '虹口区': [],
  '杨浦区': [],
  '闵行区': [],
  '宝山区': [],
  '嘉定区': [],
  '浦东新区': [],
  '黄浦区': [],
  '松江区': [],
  '青浦区': [],
  '奉贤区': [],
  '崇明区': []
}
 
const locations = function (indexs) {
  var names = []
  var selecteds = []
  if (indexs.length > 0) {
    //省份列表
    var pList = Object.keys(Province)
    //省份名称
    var pName = pList[indexs[0]]
    names.push(pList)
    selecteds.push(pName)
 
    if (indexs.length > 1) {
      //城市列表
      var cList = Province[pName]
      //城市名称
      var cName = cList[indexs[1]]
      names.push(cList)
      selecteds.push(cName)
 
      if (indexs.length > 2) {
        //区县列表
        var dList = City[cName]
        //区县名称
        var dName = dList[indexs[2]]
        names.push(dList)
        selecteds.push(dName)
 
        if (indexs.length > 3) {
          //街镇列表
          var tList = District[dName]
          //街镇名称
          var tName = tList[indexs[3]]
          names.push(tList)
          selecteds.push(tName)
        }
      }
    }
  }
  var selectedDes = ""
  selecteds.forEach(str => {
    if (str != undefined && selectedDes != str) {
      if (selectedDes != "") {
        selectedDes += "-"
      }
      selectedDes += str
    }
  })
 
  return {
    names: names,
    values: indexs,
    selected: selecteds,
    des: selectedDes
  }
}
 
const multiIndex = function (selecteds) {
  var indexs = []
  var names = []
  if (selecteds.length > 0) {
    //省份列表
    var pList = Object.keys(Province)
    //省份名称
    var pIndex = pList.indexOf(selecteds[0])
    names.push(pList)
    if (pIndex != -1) {
      indexs.push(pIndex)
    } else {
      indexs.push(0)
    }
 
    if (selecteds.length > 1) {
      //城市列表
      var cList = Province[selecteds[0]]
      //城市名称
      var cIndex = cList.indexOf(selecteds[1])
      names.push(cList)
      if (cIndex != -1) {
        indexs.push(cIndex)
      } else {
        indexs.push(0)
      }
 
      if (selecteds.length > 2) {
        //区县列表
        var dList = City[selecteds[1]]
        //区县名称
        var dIndex = dList.indexOf(selecteds[2])
        names.push(dList)
        if (dIndex != -1) {
          indexs.push(dIndex)
        } else {
          indexs.push(0)
        }
 
        if (selecteds.length > 3) {
          //街镇列表
          var tList = District[selecteds[2]]
          //街镇名称
          var tIndex = tList.indexOf(selecteds[3])
          names.push(tList)
          if (tIndex != -1) {
            indexs.push(tIndex)
          } else {
            indexs.push(0)
          }
        }
      }
    }
  }
  var selectedDes = ""
  selecteds.forEach(str => {
    if (str != undefined && selectedDes != str) {
      if (selectedDes != "") {
        selectedDes += "-"
      }
      selectedDes += str
    }
  })
 
  return {
    names: names,
    values: indexs,
    selected: selecteds,
    des: selectedDes
  }
}
 
module.exports = {
  locations: locations,
  multiIndex: multiIndex
}