<template>
	<view @click="handlePlay">
		{{YItem.cigen}}
	</view>
</template>

<script setup>
	// pindu
	import {
		reactive,
		computed,
		onUnmounted
	} from 'vue';
	import {
		onLoad
	} from "@dcloudio/uni-app"

	const props = defineProps({
		YItem: {
			type: Object,
		},
	})

	const emits = defineEmits(['play-audio'])

	const data = reactive({
		code: null
	})

	onLoad(() => {
		uni.$on('danci-audio-ended', (code) => {
			data.isPlaying = false;
		})
		uni.$on('danci-audio-play', (code) => {
			if (data.code == code) {
				data.isPlaying = true;
			} else {
				data.isPlaying = false;
			}
		})
	})

	onUnmounted(() => {
		uni.$off('danci-audio-ended')
		uni.$off('danci-audio-play')
	})

	function handlePlay() {
		data.code = new Date().getTime()
		emits('play-audio', {
			url: props.YItem.yinpin,
			code: data.code
		})
	}
</script>

<style>
</style>