<u-picker @confirm="getcitydata" @cancel="show=false" keyName="name" :show="show" ref="uPicker"
:columns="columns" @change="changeHandler"></u-picker>
changeHandler(e) {
var that = this;
const {
columnIndex,
index,
// 微信小程序无法将picker实例传出来,只能通过ref操作
picker = this.$refs.uPicker
} = e
if (columnIndex === 0) {
this.loading = true
console.log(e)
getcity(e.value[0].id, {
custom: {
auth: true
}
}).then(res => {
if (res.code == 0) {
console.log(res.data)
// that.columns.push(res.data)
picker.setColumnValues(1, res.data)
this.loading = false
}
}).catch(err => {
})
// 模拟网络请求
// uni.$u.sleep(1500).then(() => {
// picker.setColumnValues(1, this.columnData[index])
// this.loading = false
// })
}
},
province() {
var that = this
that.columns = []
province({}, {
custom: {
auth: true
}
}).then(res => {
if (res.code == 0) {
console.log(res.data)
that.columns.push(res.data)
that.getcity(res.data[0])
}
}).catch(err => {
})
},
getcity(e) {
var picker = this.$refs.uPicker
getcity(e.id, {
custom: {
auth: true
}
}).then(res => {
if (res.code == 0) {
console.log(res.data)
// that.columns.push(res.data)
picker.setColumnValues(1, res.data)
this.loading = false
}
}).catch(err => {
})
},
getcitydata(e) {
console.log(e.value[1].name)
console.log(e.value[1].id)
this.formdata.cityname = e.value[1].name
this.formdata.cityId = e.value[1].cityId
this.show = false
}