<template>
	<text class="w-form-input-rv" v-if="readonly">{{_value}}</text>
	<uni-data-checkbox v-else-if="formProps.expanding" v-model="_value" :disabled="readonly" :localdata="options" />
	<picker v-else @change="ok" mode="selector" :value="index" :range="formProps.options" :disabled="readonly">
		<click-input :value="modelValue ? formProps.options[index]:null" :disabled="readonly"
			:placeholder="formProps.placeholder || '请选择'" />
	</picker>
</template>

<script setup>
	import { computed, ref } from 'vue'
	import ClickInput from '@/components/ClickInput.vue'

	const props = defineProps({
		formProps: {
			type: Object,
			default: () => {
				return {}
			}
		},
		modelValue: String,
		readonly: Boolean
	})

	const options = computed(() => {
		return props.formProps.options.map(v => {
			return { text: v, value: v }
		})
	})

	const index = ref(0)

	const _value = computed({
		get() {
			return props.modelValue
		},
		set(val) {
			emits('update:modelValue', val)
		}
	})

	const emits = defineEmits(['update:modelValue'])

	function ok(e) {
		index.value = e.detail.value
		_value.value = props.formProps.options[index.value]
	}
</script>

<style>
</style>