Commit bfb32226 by 陈超

T

parent 574e3caa
......@@ -22,7 +22,8 @@
</div>
<van-popup v-model="showPicker" round position="bottom">
<van-picker
<van-picker
ref="picker"
show-toolbar
title="收货地址"
:columns="columns"
......@@ -152,7 +153,7 @@
showPicker: false,
loading: false,
columns: [],
selected: []
selected: ['', '', '']
}
},
created:function(){
......@@ -171,35 +172,58 @@
}
},
methods: {
//当选择省变化
onProvinceChange: function(picker, p) {
let that = this
if(p.children.length == 0) {
that.getCity(p.id, r => {
p.children = r.map(r => { return { text: r.title, id: r.area_id, children: [] } })
if(p.children.length > 0) {
that.onCityChange(picker, p.children[0])
} else {
that.columns = [].concat(that.columns)
}
})
} else {
picker.setColumnValues(1, p.children)
}
},
//当选择市变化
onCityChange: function(picker, c) {
let that = this
if(c.children.length == 0) {
that.getArea(c.id, r => {
c.children = r.map(r => { return { text: r.title, id: r.area_id } })
picker.setColumnValues(2, c.children)
})
} else {
picker.setColumnValues(2, c.children)
}
},
onArea: function() {
let that = this
that.showPicker = true
if(that.selected.length == 0) {
let p = that.columns[0]
if(p.children.length == 0) {
that.loading = true
that.getCity(p.id)
}
if(that.columns[0].children.length == 0) {
that.onProvinceChange(that.$refs.picker, that.columns[0])
}
},
onAreaConfirm: function(r, values) {
onAreaConfirm: function(picker, values) {
},
onAreaCancel: function(r, values) {
onAreaCancel: function(picker, values) {
},
onAreaChange: function(r, values) {
let selected = values.filter(r => { return r != undefined })
console.log(selected)
console.log(this.columns)
onAreaChange: function(picker, values) {
},
saveAddress: function() {
},
//Helper
getCity: function(id) {
getCity: function(id, call) {
let that = this
that.loading = true
$.ajax({
type:'POST',
url:"{:U('home/User/getAreaList')}",
......@@ -208,33 +232,23 @@
success:function(res){
that.loading = false
if(res.status == 1) {
let found = that.columns.filter(r => { return r.id == id })
if(found.length > 0) {
let province = found[0]
province.children = res.data.map( r => { return { text: r.title, id: r.area_id, children: [] } })
if(province.children.length > 0) {
that.getArea(province, province.children[0].id)
}
}
call && call(res.data)
}
}
})
},
getArea: function(p, id) {
getArea: function(id, call) {
let that = this
that.loading = true
$.ajax({
type:'POST',
url:"{:U('home/User/getAreaList')}",
data:{ id: id },
dataType:'json',
success:function(res){
that.loading = false
if(res.status == 1) {
let found = p.children.filter( r => { return r.id == id })
if(found.length > 0) {
let city = found[0]
city.children = res.data.map( r => { return { text: r.title, id: r.area_id } })
}
that.columns = [].concat(that.columns)
call && call(res.data)
}
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment