<template>
<div>
	<el-tree-select v-bind="$attrs" :data="treeData" check-strictly :render-after-expand="false" :default-expand-all="true" :props="defaultProps" clearable style="min-width: 240px;" />
</div>
</template>

<script>
import config from '@/config/select.js'

export default {
	props: {
		apiObj: { type: Object, default: () => {} },
		props: { type: Object, default: () => {} },
		hasTop: { type: Boolean, default: false }
	},
	data(){
		return {
			treeData: [],
			defaultProps: {label: config.props.label, value: config.props.value}
		}
	},
	mounted(){
		this.defaultProps = Object.assign(this.defaultProps, this.props);
		this.$nextTick(() => {
			this.getData()
		})
	},
	methods:{
		async getData(){
			let data = {}
			data[this.defaultProps.label] = '顶级'
			data[this.defaultProps.value] = 0
			let res = await this.apiObj.get({is_tree: 1})
			if(res.code == 1){
				this.treeData = this.hasTop ? [data, ...res.data] : res.data
			}else{
				this.treeData = this.hasTop ? [data] : []
			}
		},
	}
}
</script>

<style scoped>
</style>
