<template>
    <div>
        <a-tree-select
                v-model="breedId"
                show-search
                style="width: 180px"
                :tree-data="medicalTypeList"
                :replaceFields="replaceFields"
                treeNodeFilterProp="title"
                :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                placeholder="请选择"
                allow-clear
                :disabled="disabled"
                @change="changeType"
                @click="getMedicalType"
        ></a-tree-select>
    </div>
</template>
<script>
    import {toTree} from '../../utils/common.js'

    export default {
        data() {
            return {
                breedId: undefined,
                medicalTypeList: [],
                replaceFields: {
                    title: 'typeName',
                    key: 'id',
                    value: 'id',
                    children: 'children',
                },
                disabled: false
            }
        },
        created() {
            this.getMedicalType();
        },
        methods: {
            getMedicalType() {
                let params = {};
                this.$api.common.fetchMedicalType(params).then(({code, data}) => {
                    this.medicalTypeList = toTree(data, '0', 'parentId', 'id');
                    // this.medicalTypeList.unshift({
                    //     id: '',
                    //     typeName: '全部',
                    // });
                });
            },
            changeType() {
                this.$emit('getBreedId', this.breedId);
            },
            setValue(breedId, isDisabled = false) {
                this.disabled = isDisabled;
                this.breedId = breedId;
            },
        },
    }
</script>
