<template>
	<view class="starting bx">

		<view class="bg">
			<image :src="appScroll || '@/static/starting/banner.png'" mode="widthFix"></image>
		</view>

		<view class="user-info">
			<view class="top">
				<view class="current-balance">{{ $t('page.starting.balance') }}</view>
				<view class="money">
					<view class="number">{{ userInfo.money }}</view>
					<view class="unit">{{ $store.state.unit }}</view>
				</view>
			</view>

			<view class="todoy-info">
				<view class="todoy-info-main">
					
					<!-- v-if="userInfo.isOpen == 'Y' && userInfo.orderNum == userInfo.encourageNum + 1" -->
					<!-- <view class="today-info-l">
						<view class="today-income">{{ $t('page.starting.today-income') }}</view>
						<div class="money">
							-
							<text class="number">{{ userInfo.belece }}</text>
							<text class="unit">{{ $store.state.unit }}</text>
						</div>
					</view> -->

					<div class="booking-info-r">
						<view class="booking-income">{{ $t('page.starting.completed') }}</view>
						<div class="booking-data">
							<text class="number">{{ userInfo.encourageNum }}/{{ userInfo.encourageSum }}</text>
						</div>
					</div>
				</view>
			</view>

			<view class="btn">
				<view @click="submit" class="submit">{{ $t('page.starting.auto-match') }}</view>
			</view>
		</view>

		<view class="steps">
			<!-- <view class="steps-title">The steps</view>
			<view class="steps-content">
				<view>1. Click the "Auto-match" button and follow the instructions to complete the task.</view>
				<view>2. After completing the task, you can settle the commission to the balance.</view>
			</view> -->
			<view class="steps-title">{{ $t('page.starting.steps-title') }}</view>
			<view class="steps-content" v-html="$t('page.starting.steps-content')"></view>
		</view>
		
		<sTabbar select="2" />
		
		<prizeDraw ref="prizeDraw" @orderPay="orderPay"></prizeDraw>

	</view>
</template>

<script>
	import sTabbar from '@/components/base/tabBar.vue'
	import prizeDraw from '@/components/prizeDraw/prizeDraw.vue'
	
	export default {
		name: 'Starting',
		components : { sTabbar , prizeDraw },
		data() {
			return {
				userInfo : {},
				appScroll : ''
			}
		},
		onShow(){
			this.getUserInfo()
			this.getAppScroll()
		},
		methods: {
			//点击抽奖按钮
			submit(){
				let self = this
				self.request('getRandomImage').then(a => {
					if(a.code == 200){
						self.request('createOrder', {}, {
							image : a.result.iamge,
						}).then(res => {
							if(res.code == 200){
								res.result.image = a.result.iamge
								self.$refs.prizeDraw.toggle(res.result)
							}
						})
					}
				})
				
			},
			
			//获取用户信息
			getUserInfo() {
				this.request('userInfo').then(res => {
					if (res.code == 200) {
						this.userInfo = res.result.userInfo
					}
				})
			},
			
			getAppScroll() {
				this.request('getAppScroll').then(res => {
					if (res.code == 200) {
						this.appScroll = res.result.title || res.result[0].title
					}
				})
			},
			
			//订单支付
			orderPay(id){
				this.request('pay',{},{ id }).then(res => {
					if (res.code == 200) {
						uni.showToast({
							icon: "none",
							title: this.$t(`message.${res.message}`)
						});
						this.getUserInfo()
						this.$refs.prizeDraw.close()
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.starting {
		height: 100vh;
		padding-bottom: 300px;

		.bg {
			border-bottom-left-radius: 60% 60rpx;
			border-bottom-right-radius: 60% 60rpx;
			overflow: hidden;

			image {
				width: 100%;
			}
		}

		.user-info {
			position: relative;
			z-index: 1;
			width: 90%;
			margin: -120rpx auto 0rpx auto;
			background: white;
			border-radius: 20rpx;
			box-shadow: aqua 0.5px 0.5px 5px 0px;

			.top {
				box-sizing: border-box;
				padding: 0rpx 15rpx;

				.current-balance {
					display: flex;
					align-items: center;
					height: 60rpx;
					color: #8e8e98;
					font-size: 30rpx;
				}

				.money {
					display: flex;
					    color: rgb(0, 208, 234);
					font-size: 50rpx;
					font-weight: bold;

					.number {}

					.unit {
						margin-left: 20rpx;
					}
				}
			}

			.todoy-info {
				box-sizing: border-box;
				padding: 0rpx 20rpx;
				height: 140rpx;

				.todoy-info-main {
					display: flex;
					flex-wrap: wrap;
					height: 100%;
					background-color: rgba(0, 208, 234, 0.1);
					border-radius: 20rpx;
					margin: 20rpx 0rpx;
					box-sizing: border-box;
					padding: 0rpx 30rpx;

					.today-info-l,
					.booking-info-r {
						display: flex;
						flex-direction: column;
						justify-content: center;
						width: 50%;
						font-size: 28rpx;

						.today-income,
						.booking-income {
							// color: #8e8e98;
						}

						.money,
						.booking-data {
							font-weight: bold;
							margin-top: 10rpx;
						}
					}
				}
			}

			.btn {
				padding: 20rpx;

				.submit {
					background-color: rgb(0, 208, 234);
					color: white;
					padding: 20rpx 0;
					text-align: center;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 40rpx;
					font-weight: bold;
					border-radius: 20rpx;
				}
			}

		}

		.steps {
			width: 90%;
			margin: 0rpx auto;
			padding-top: 80rpx;

			.steps-title {
				font-size: 36rpx;
				font-weight: bold;
			}

			.steps-content {
				color: #8e8e98;
				font-size: 30rpx;
				margin-top: 20rpx;
			}
		}
	}
</style>