Commit bfb32226 by 陈超

T

parent 574e3caa
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<van-popup v-model="showPicker" round position="bottom"> <van-popup v-model="showPicker" round position="bottom">
<van-picker <van-picker
ref="picker"
show-toolbar show-toolbar
title="收货地址" title="收货地址"
:columns="columns" :columns="columns"
...@@ -152,7 +153,7 @@ ...@@ -152,7 +153,7 @@
showPicker: false, showPicker: false,
loading: false, loading: false,
columns: [], columns: [],
selected: [] selected: ['', '', '']
} }
}, },
created:function(){ created:function(){
...@@ -171,35 +172,58 @@ ...@@ -171,35 +172,58 @@
} }
}, },
methods: { methods: {
onArea: function() { //当选择省变化
onProvinceChange: function(picker, p) {
let that = this let that = this
that.showPicker = true
if(that.selected.length == 0) {
let p = that.columns[0]
if(p.children.length == 0) { if(p.children.length == 0) {
that.loading = true that.getCity(p.id, r => {
that.getCity(p.id) 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)
} }
}, },
onAreaConfirm: function(r, values) { //当选择市变化
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.columns[0].children.length == 0) {
that.onProvinceChange(that.$refs.picker, that.columns[0])
}
},
onAreaConfirm: function(picker, values) {
}, },
onAreaCancel: function(r, values) { onAreaCancel: function(picker, values) {
}, },
onAreaChange: function(r, values) { onAreaChange: function(picker, values) {
let selected = values.filter(r => { return r != undefined })
console.log(selected)
console.log(this.columns)
}, },
saveAddress: function() { saveAddress: function() {
}, },
//Helper //Helper
getCity: function(id) { getCity: function(id, call) {
let that = this let that = this
that.loading = true
$.ajax({ $.ajax({
type:'POST', type:'POST',
url:"{:U('home/User/getAreaList')}", url:"{:U('home/User/getAreaList')}",
...@@ -208,33 +232,23 @@ ...@@ -208,33 +232,23 @@
success:function(res){ success:function(res){
that.loading = false that.loading = false
if(res.status == 1) { if(res.status == 1) {
let found = that.columns.filter(r => { return r.id == id }) call && call(res.data)
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)
}
}
} }
} }
}) })
}, },
getArea: function(p, id) { getArea: function(id, call) {
let that = this let that = this
that.loading = true
$.ajax({ $.ajax({
type:'POST', type:'POST',
url:"{:U('home/User/getAreaList')}", url:"{:U('home/User/getAreaList')}",
data:{ id: id }, data:{ id: id },
dataType:'json', dataType:'json',
success:function(res){ success:function(res){
that.loading = false
if(res.status == 1) { if(res.status == 1) {
let found = p.children.filter( r => { return r.id == id }) call && call(res.data)
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)
} }
} }
}) })
......
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