1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<a-tree-select
v-model="value"
tree-data-simple-mode
allowClear
:tree-data="treeData"
placeholder="请选择"
:load-data="onLoadData"
/>
</template>
<script>
/**
* 所有地区选择控件
*/
export default {
name: "allAreaSelect",
created() {
this.getDataList(53);
},
data() {
return {
value: undefined,
treeData: [],
};
},
watch: {
value(value) {
this.$emit('input', value);
},
},
methods: {
getDataList(areaCode) {
let treeData = [];
this.$api.common.fetchAreaByCode(areaCode).then(({code, data}) => {
if (code === "SUCCESS") {
data.forEach(x => {
let item = {
id: x.areaCode,
pId: 0,
value: x.areaCode,
title: x.areaName,
isLeaf: x.areaLevel == 5 ? true : false
};
treeData.push(item);
});
this.treeData = treeData;
}
});
},
onLoadData(treeNode) {
let that = this;
return new Promise(resolve => {
this.$api.common.fetchAreaByCode(treeNode.value).then(({code, data}) => {
let treeData = [];
if (code === "SUCCESS") {
if (this.$api.utils.isNoBlank(data)) {
data.forEach(x => {
let item = {
id: x.areaCode,
pId: treeNode.value,
value: x.areaCode,
title: x.areaName,
isLeaf: x.areaLevel == 5 ? true : false
};
treeData.push(item);
});
that.treeData = that.treeData.concat(treeData);
}
resolve();
}
});
});
},
},
}
</script>
<style scoped>
</style>