<template>
	<u-popup :show="show"
	mode="center"
	bgColor="transparent"
	@close="$emit('close');$play()">
		<view class="box">
			<view class="turntable"
			:style="{transform: `rotate(${360 * rotate + link}deg)`}">
				<view class="item"
				:style="{transform: `translate(-50%) rotate(${(360 / 8) * index}deg)`}"
				v-for="(item, index) in list">
					<view>
						{{ $t(`page.turntable.${item.name}`)}}
					</view>
					<view style="margin-top: 20rpx;">
						USDT {{ item.money }}
					</view>
				</view>
			</view>
			<view class="z"
			@click="start">
				<view class="text">
					<view style="font-size: 28rpx;font-weight: 900;">
						{{ $t(`page.turntable.go`)}}
					</view>
					<view style="font-size: 20rpx;line-height: 30rpx;">
						<!-- 剩余{{ info.bigNum }}次 -->
						{{ $t(`page.turntable.num`, [info.bigNum])}}
					</view>
				</view>
			</view>
		</view>
		
	</u-popup>
</template>

<script>
	
	export default {
		name:"turntable",
		props : ['show', 'info'],
		data() {
			return {
				rotate : 0,
				list : [],
				link : 0,
				inter : null,
			};
		},
		created() {
			this.getTurntable()
		},
		methods : {
			start(){
				if(this.inter || this.info.bigNum <= 0){
					return
				}
				this.$play()
				this.request('clickTurntable').then(res => {
					if(res.code == 200){
						clearInterval(this.inter)
						
						this.list.forEach((n,i) => {
							if(n.id == res.result.id){
								this.link = -(360 / 8 * i)
							}
						})
						setTimeout(() => this.inter = null, 1500)
					}
					this.$emit('start')
				}).catch(err => {
					clearInterval(this.inter)
					setTimeout(() => this.inter = null, 1500)
				})
				this.link = 0
				this.rotate += 6
				this.inter = setInterval(() => {
					this.rotate += 1
				}, 200)
			},
			
			getTurntable(){
				this.request('getTurntableList').then(res => {
					if(res.code == 200){
						this.list = res.result
					}
				})
			},
			
			async asyncLoading() { //加载效果
				return new Promise((resolve, reject) => {
					uni.showLoading({
						title: this.$t('page.turntable.loading')
					});
					setTimeout(() => {
						uni.hideLoading();
						resolve()
					}, 500)
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.box{
	position: relative;
	.turntable{
		position: relative;
		width: 700rpx;
		height: 700rpx;
		background-image: url(/static/drone/5db810a1868a7230.png);
		background-size: 100% 100%;
		transition: transform 1.5s;
		.item{
			position: absolute;
			left: 50%;
			transform: translateX(-50%);
			top: 50rpx;
			transform-origin: 50% 300rpx;
			text-align: center;
			font-size: 22rpx;
			width: 180rpx;
		}
	}
	.z{
		position: absolute;
		top: 200rpx;
		left: 260rpx;
		width: 180rpx;
		height: 180rpx;
		// background-image: url(/static/drone/68a7230.png);
		background-image: url(/static/drone/230.png);
		background-size: 100% 100%;
		.text{
			position: absolute;
			top: 90rpx;
			margin-left: 10rpx;
			text-align: center;
			line-height: 50rpx;
			width: 160rpx;
		}
	}
}
</style>