<template>
<section class="wrap">
<dlr-city ref="dlrCity"
v-model="ui.showCity"
:show-header="true"
:before-back="onBeforeBack"
:before-select="onBeforSelect"
:title-text="'选择城市'"
:selected-id="currentCityId"
:show-location="ui.showLocation"
@on-location="locationHandler"
@on-select-city="selectCityHandler">
<dlr-city-group slot="dlrCityGroup" v-for="(item) in cityData" :key="item.id"
:alpha="item.alpha" >
<dlr-city-group-item slot="dlrCityGroupItem" v-for="(si,giIndex) in item.list" :key="si.id"
:data="si"
:item-id="si.id"
:item-name="si.name">
</dlr-city-group-item>
</dlr-city-group>
</dlr-city>
</section>
</template>
<script>
export default {
data () {
return {
currentCityId: 101,
ui: {
showLocation: true,
showCity: false
},
cityData: []
}
},
mounted () {
},
methods: {
onBeforeBack () {
return true
},
onBeforSelect (data) {
console.log('onBeforSelect', data)
return true
},
openCity () {
this.ui.showCity = true
setTimeout(() => {
this.loadCityData()
this.ui.titleSelect = ''
}, 1500)
},
loadCityData () {
let arr = []
for (let i = 1; i < 6; i++) {
let p = { id: i, name: '市' + i, alpha: i, list: [] }
arr.push(p)
for (let m = 100; m < 120; m++) {
let item = { id: (i * m + i), name: '城市名' + (i * m + i) }
p.list.push(item)
}
}
this.cityData = arr
},
getCityData () {
this.$refs.dlrCity.getCityData(this.currentCityId, (data) => {
console.log('city-data:', data)
})
},
selectCityHandler (data) {
this.currentCityId = data.id
console.log('city-selected-data:', data)
},
locationHandler (fnCall) {
setTimeout(() => {
fnCall()
}, 3000)
}
}
}
</script>