emis-frontend/src/views/emis/EmisBaseTools/CountryTreePicker.vue
2024-04-22 13:35:19 +08:00

111 lines
2.6 KiB
Vue

<template>
<div>
<div class="head-container">
<el-input
v-model="countryName"
:placeholder="placeholder"
clearable
size="mini"
prefix-icon="el-icon-search"
style="margin-bottom: 10px"
/>
</div>
<div class="head-container" >
<el-tree
ref="tree"
size="mini"
class="filter-tree tree"
:data="countryTree"
:props="defaultProps"
:expand-on-click-node="false"
:filter-node-method="filterNode"
node-key="id"
highlight-current
default-expand-all
@node-click="handleNodeClick"
style="max-height:900px;overflow-y:hidden"
>
</el-tree>
</div>
</div>
</template>
<script>
import { listSimpleEmisCountry} from "@/api/emis/emisCountry";
export default {
name: "CountryTreePicker",
props: {
value: {
type: [String],
required: false
},
placeholder:{
type: [String],
required: false
}
},
data() {
return {
optionItems: [],
svalue: this.value,
countryName:"",
countryTree:[],
defaultProps: {
children: "children",
label: "label"
},
queryParams:{
},
};
},
watch: {
value(newVal) {
this.svalue = newVal;
},
svalue(newVal, oldVal) {
this.$emit("input", this.svalue);
},
// 根据名称筛选部门树
countryName(val) {
this.$refs.tree.filter(val);
},
},
created() {
this.initData();
},
methods: {
// 筛选节点
filterNode(value, data) {
if (!value) return true;
return data.label.toLowerCase().indexOf(value.toLowerCase()) !== -1 ;
},
// 节点单击事件
handleNodeClick(data) {
this.svalue = data.id;
this.$emit("input", this.svalue);
this.$emit("onNodeClick");
},
initData() {
this.loading = true;
let queryParams = {
orderByColumn:'orderNum',
isAsc:'descending'
}
listSimpleEmisCountry(queryParams).then(response => {
this.loading = false;
this.countryTree = [];
var cTree={"id":"","label":"国家列表","children":[]};
response.rows.forEach(item =>{
var treeItem={"id":item.code,"label":item.name+'('+item.nameEn+')'};
cTree.children.push(treeItem);
});
this.countryTree.push(cTree);
});
},
}
};
</script>