import {object} from "@/uni_modules/uv-ui-tools/libs/function/test";

export default {
    props: {
        defaultIndex: {
            // 只需要提供默认索引，组件内部为u-picker自动进行了包装
            type: Number, // | Function, // TODO: support function mode if needed.
            default: 0
        }
    },
    data() {
        return {
            columns: []
        }
    },
    computed: {
        pickerValue() {
            return this.modelValue
        },
        selected() {
            return this.columns.find(i => this.getValue(i) == this.pickerValue)
        },
        selectedIndex() {
            const idx = this.columns.findIndex(i => this.getValue(i) == this.pickerValue)
            return idx == -1 ? this.defaultIndex : idx
        }
    },
    created() {
        this.initColumns()
    },
    methods: {
        initColumns() {
            // to be overridden
            // 这里只需要给this.columns提供单选列表1维数组，组件内部已经自动为u-picker进行了2维包装
        },
        getLabel(item) {
            // can be overridden by need
            return object(item) ? item.text : item
        },
        getValue(item) {
            // can be overridden by need
            return object(item) ? item.value : item
        }
    }
}