<template>
    <a-cascader v-model:value="checkList" :options="options" v-bind="$attrs">
    </a-cascader>
</template>
<script>
import { getOptions } from '@/api/common'
export default {
    name: 'ProCascader',
    watch: {
        //判断下拉框的值是否有改变
        checkList (val, oldVal) {
            console.log('watch:', this.$emit)
            if (val != oldVal) {
                this.$emit('input', this.checkList)
            }
        },
    },
    mounted () {
        //初始话下拉框的值
        const { optionData, url } = this.$attrs
        //静态变量直接赋值
        if (optionData) {
            this.options = optionData
        } else {
            let queyUrl = ''
            let params
            // //通过字段和表名查tbl
            // if(colName && tableName){
            //     queyUrl = '/system/cascader/options/load'
            //     params = {colName, tableName}
            // } else
            if (url) {//自定义查询
                queyUrl = url
                params = {}
            }
            if (queyUrl) {
                getOptions(queyUrl, params)
                    .then((response) => {
                        if (response.success) {
                            this.options = response.data
                        }
                    })
            }
        }
    },
    data () {
        return {
            options: [],
            checkList: this.$attrs.value || []
        }
    }
}
</script>
<style></style>
