选择省市区
<view class="">
<view class="" @click="handleSheng()" v-if="shengZi==''">
选择省
</view>
<view class="" v-else @click="handleSheng()">
{{shengZi}}
</view>
</view>
<view class="" v-if="selectioncitys">
<view class="" v-if="shiZi==''" @click="handleShi">
选择市
</view>
<view class="" v-else @click="handleShi">
{{shiZi}}
</view>
</view>
<view class="" v-if="selectiondQu">
<view class="" v-if="QuZi==''" @click="handleQu">
选择区
</view>
<view class="" v-else @click="handleQu">
{{QuZi}}
</view>
</view>
<u-popup :show="showHide" closeable :round="10" @close="close" @open="open">
<view class="popupConter">
<view class="popupTitle">
选择城市
</view>
<view class="popupFixed" v-if="selection">
<view class="popupProvince" @click="handleProvince1(index,item,0)"
v-for="(item,index) in newProvinceDataList[0]" :key="index">
{{item}}
</view>
</view>
<view class="popupFixed" v-if="selectioncity">
<view class="popupProvince" @click="handleProvince1(index,item,1)"
v-for="(item,index) in newProvinceDataList[1]" :key="index">
{{item}}
</view>
</view>
<!-- 区 -->
<view class="popupFixed" v-if="selectiondistrict">
<view class="popupProvince" @click="handleProvince1(index,item,2)"
v-for="(item,index) in newProvinceDataList[2]" :key="index">
{{item}}
</view>
</view>
</view>
</u-popup>
multiIndex: [0, 0, 0],
oldpProvinceDataList: provinceData.data,
newProvinceDataList: [
[],
[],
[]
],
onLoad(){
// 省
for (let i = 0; i < that.oldpProvinceDataList.length; i++) {
that.newProvinceDataList[0].push(that.oldpProvinceDataList[i].name)
}
console.log(that.newProvinceDataList[0])
// 市
for (let i = 0; i < that.oldpProvinceDataList[0].children.length; i++) {
that.newProvinceDataList[1].push(that.oldpProvinceDataList[0].children[i].name)
}
// 区县
for (let i = 0; i < that.oldpProvinceDataList[0].children[0].children.length; i++) {
that.newProvinceDataList[2].push(that.oldpProvinceDataList[0].children[0].children[i].name)
}
}
// 选择省
handleSheng() {
this.showHide = true,
this.selection = true
},
// 选择市
handleShi() {
this.showHide = true
// 市弹窗
this.selectioncity = true
},
// 选择区
handleQu() {
this.showHide = true
this.selectiondistrict = true
},
handleProvince1(index, items, column) {
// 省框
if (column == 0) {
this.shengZi = items
this.selectioncitys = true
this.shiZi = ''
this.QuZi = ''
} else if (column == 1) {
this.shiZi = items
this.selectiondQu = true
this.QuZi = ''
} else {
this.QuZi = items
}
this.showHide = false
// 省
this.selection = false
// 市
this.selectioncity = false
// 区
this.selectiondistrict = false
this.handleProvince(index, column)
},
// 省
handleProvince(index, column) {
console.log(index, column, '市份选择');
var that = this
// 第一列滑动
if (column === 0) {
that.multiIndex[0] = index
// 第二列更新相应的数据
that.newProvinceDataList[1] = that.oldpProvinceDataList[that.multiIndex[0]].children.map((
item,
index) => {
return item.name
})
if (that.oldpProvinceDataList[that.multiIndex[0]].children.length === 1) {
that.newProvinceDataList[2] = that.oldpProvinceDataList[that.multiIndex[0]].children[0]
.children
.map((
item,
index) => {
return item.name
})
} else {
that.newProvinceDataList[2] = that.oldpProvinceDataList[that.multiIndex[0]].children[
that
.multiIndex[
1]].children.map((item, index) => {
return item.name
})
}
// 第一列滑动 第二列 和第三列 都变为第一个
that.multiIndex.splice(1, 1, 0)
that.multiIndex.splice(2, 1, 0)
}
// 第二列滑动
if (column === 1) {
that.multiIndex[1] = index
that.newProvinceDataList[2] = that.oldpProvinceDataList[that.multiIndex[0]].children[that
.multiIndex[
1]].children.map((item, index) => {
return item.name
})
// 第二列 滑动 第三列 变成第一个
that.multiIndex.splice(2, 1, 0)
}
// 第三列滑动
if (column === 2) {
that.multiIndex[2] = index
}
}