<template>
	<view class="content-container detail-lucky">
		<detailLucky ref="_detailLucky" @end="onLuckyEnd" @luckyPlay="startCallBack" @luckyStop="endCallBack">
		</detailLucky>
		<detailGrandPrize ref="_detailGrandPrize" @end="onLuckyEnd1" />

	</view>
</template>

<script>

//超神特效
//#ifdef H5 || MP
import detailLucky from "./detail-lucky-canvas.vue";
//#endif
//#ifdef APP
import detailLucky from "./detail-lucky-web.vue";
//#endif
import detailGrandPrize from "@/components/detail-lucky/detail-grand-prize.vue";

import { sleep } from '@/common/util'

export default {
	components: {
		detailGrandPrize,
		detailLucky
	},
	data() {
		return {
			chaoShenIndex: -1,
			prizeList: null,
			mode: mode,
		};
	},
	computed: {

	},
	methods: {
		onLuckyEnd(isSkip) {
			// 发送中奖信息到父组件 
			this.hide();
			if (!isSkip && this.chaoShenIndex > -1) {
				this.$refs._detailGrandPrize.init();
				this.$refs._detailGrandPrize.show();
				return;
			}
			this.audioManager.stop();
			this.$emit("end", isSkip);
		},
		onLuckyEnd1() {
			this.audioManager.stop();
			this.$emit("end", false);
		},
		// 初始化抽奖特效组件
		init(prizeList, mode) {
			this.prizeList = prizeList;
			this.mode = mode;
			//#ifdef H5 || MP
			this.$refs._detailLucky.init(prizeList, mode);
			//#endif
		},
		// 显示抽奖特效组件
		show() {

			//#ifdef H5 || MP
			this.$refs._detailLucky.show();
			//#endif

		},

		// 隐藏抽奖特效组件
		hide() {

			//#ifdef H5 || MP
			this.$refs._detailLucky.hide();
			//#endif
		},
		// 抽奖特效开始回调
		startCallBack() {
			console.log('开始回调');
			this.audioManager.playSlotBgm();

		},

		// 抽奖结束回调
		endCallBack(prize) {
			this.audioManager.stop();
		},

		/**
		 * 开始抽奖并传入抽奖结果，2秒后自动停止
		 * @param {Array} resultIndices 抽奖结果索引数组
		 * @return {Object} this 返回组件实例，支持链式调用
		 */
		async startDrawWithResult(page, resultIndices, chaoShenIndex = -1) {

			this.chaoShenIndex = chaoShenIndex;
			console.log('开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖开始抽奖', this.prizeList, resultIndices,);
			//#ifdef H5 || MP
			await this.$refs._detailLucky.startDrawWithResult(resultIndices);
			//#endif
			//#ifdef APP
			this.$refs._detailLucky.init(this.prizeList, page, resultIndices);
			//#endif
		}
	},

	mounted() {
		// 不再自动初始化
	}
};
</script>

<style lang="scss" scoped></style>