<template>
    <view style="width: 100%">
        <u--input :value="valueEnum[value]" disabledColor="#ffffff" :placeholder="placeholder"></u--input>
        <u-picker :show="visibel" :keyName="labelName" :columns="columns" @confirm="skillConfirm" @cancel="skillClose"
            @close="skillClose"></u-picker>
    </view>
</template>

<script>
    import {
        keys
    } from 'lodash'
    export default {
        data() {
            return {
                valueEnum: {}
            }
        },
        props: {
            valueName: {
                type: String,
                default: 'value'
            },
            labelName: {
                type: String,
                default: 'label'
            },
            placeholder: {
                type: String,
                require: ''
            },
            visibel: {
                type: Boolean,
                default: false,
            },
            columns: {
                type: Array,
                require: true
            },
            value: {
                type: String,
                require: ''
            },
        },
        created() {
            if (Array.isArray(this.columns)) {
                this.init(this.columns)
            }
        },
        watch: {
            columns(val) {
                if (Array.isArray(val)) {
                    this.init(val)
                }
            }
        },
        methods: {
            init(val) {
                val.map((item) => {
                    item.map((child) => {
                        this.valueEnum[child[this.valueName]] = child[this.labelName]
                    })
                })
            },
            skillConfirm({
                index,
                value,
                values
            }) {
                console.log(String(value[0][this.valueName]))
                this.$emit("input", String(value[0][this.valueName]));
                this.$emit("cancel");
            },
            skillClose() {
                this.$emit("cancel");
            }
        },

    }
</script>

<style>
</style>