<template>
	<uni-easyinput :inputBorder="false" class="w-form-input" v-if="!readonly" v-model="_value"
		:prefixIcon="formProps.enableScan ? 'scan':null" @iconClick="scanCode"
		:placeholder="formProps.placeholder || '请输入内容'" />
	<text class="w-form-input-rv" v-else>{{_value}}</text>
</template>

<script setup>
	import { computed } from 'vue'

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

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

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

	function scanCode() {
		uni.scanCode({
			success: (res) => {
				console.log(res.result)
				_value.value = res.result
			},
			fail: (err) => {
				console.log(err)
				uni.showToast({
					icon: 'none',
					title: '扫码异常'
				})
			}
		})
	}
</script>

<style>
</style>