<template>
	<view>
		<uni-easyinput class="uni-mt-5" @blur="onInput" v-model="code" :placeholder="placeholder" suffixIcon="scan"
			@iconClick="onScan">
		</uni-easyinput>
	</view>
</template>

<script setup>
	const code = defineModel({
		type: String
	});
	const props = defineProps(["placeholder"]);
	const emit = defineEmits(['scan-change']);

	//扫描
	const onScan = () => {
		uni.scanCode({
			onlyFromCamera: true, //只能扫码
			scanType: ["qrCode"],
			success(res) {
				const {
					result
				} = res;
				code.value = result;
				emit('scan-change', result);
			},
			fail(res) {}
		})
	};
	const onInput = (value) => {
		if (value.detail.value == "") return;
		code.value = value.detail.value;
		emit('scan-change', value.detail.value);
	}
</script>

<style>
</style>