You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.3 KiB
74 lines
1.3 KiB
1 week ago
|
const _app = getApp<IAppOption>()
|
||
|
|
||
|
Component({
|
||
|
properties: {
|
||
|
level: {
|
||
|
type: Number,
|
||
|
value: 3,
|
||
|
},
|
||
|
value: {
|
||
|
type: String,
|
||
|
value: '',
|
||
|
},
|
||
|
},
|
||
|
|
||
|
data: {
|
||
|
show: false,
|
||
|
options: [],
|
||
|
fieldNames: {
|
||
|
text: 'label',
|
||
|
value: 'value',
|
||
|
children: 'children',
|
||
|
},
|
||
|
},
|
||
|
lifetimes: {
|
||
|
attached() {
|
||
|
this.getArea()
|
||
|
},
|
||
|
},
|
||
|
methods: {
|
||
|
handleShow() {
|
||
|
this.setData({
|
||
|
show: true,
|
||
|
})
|
||
|
},
|
||
|
getArea() {
|
||
|
const { level } = this.data
|
||
|
wx.ajax({
|
||
|
method: 'GET',
|
||
|
url: '/js/area.json',
|
||
|
data: {},
|
||
|
isJSON: true,
|
||
|
}).then((res) => {
|
||
|
if (level === 1) {
|
||
|
res.forEach((item: any) => {
|
||
|
delete item.children
|
||
|
})
|
||
|
}
|
||
|
if (level === 2) {
|
||
|
res.forEach((item: any) => {
|
||
|
item.children.forEach((child: any) => {
|
||
|
delete child.children
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
this.setData({
|
||
|
options: res,
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
onFinish(e) {
|
||
|
this.triggerEvent('change', e.detail.selectedOptions)
|
||
|
this.setData({
|
||
|
show: false,
|
||
|
})
|
||
|
},
|
||
|
onClose() {
|
||
|
this.setData({
|
||
|
show: false,
|
||
|
})
|
||
|
this.triggerEvent('cancel')
|
||
|
},
|
||
|
},
|
||
|
})
|