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

87 lines
2.0 KiB
Vue

<template>
<SelectTree
:props="defaultProps"
:options="dataTree"
:value="svalue"
:clearable="true"
:accordion="true"
@onNodeClick="handleNodeClick($event)"
style="width:100%"
/>
</template>
<script>
import { treeselect } from "@/api/system/dept";
// import Treeselect from "@riophae/vue-treeselect";
// import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import SelectTree from "@/components/SelectTree/index.vue";
export default {
name: "DeptmentSelectPicker",
components: { SelectTree },
props: {
value: {
type: [String,Number],
required: false
},
placeholder:{
type: [String],
required: false
}
},
data() {
return {
optionItems: [],
svalue: this.value,
filterName:"",
dataTree:[],
defaultProps: {
// 配置项(必选)
value: "id",
label: "deptName",
children: "children"
// disabled:true
},
queryParams:{
},
};
},
watch: {
value(newVal) {
this.svalue = newVal;
},
svalue(newVal, oldVal) {
this.$emit("input", this.svalue);
},
// 根据名称筛选部门树
filterName(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;
treeselect().then(response => {
this.loading = false;
this.dataTree = response.data;
console.log(this.dataTree);
});
},
}
};
</script>