<template>
	<view :data-theme="theme">
		<view class="cart_nav" :style='"height:"+navH+"rpx;"'>
			<nav-bar iconColor='#fff' backgroundColor="#FF6702" ref="navBarRef" navTitle="今日吃啥">
			</nav-bar>
		</view>
		<view class="content" :style="{'background-image': `url(../static/img/背景.png)`}">
			<view class="items">
				<view class="item" v-for="(item,i) in items" :key="i" :class="item.checked ? 'active':'notActive'"
					@click="handleCheck(i)">
					<img :src="item.icon" alt="" style="height: 80rpx;width: 80rpx;margin-right: 19rpx;" />
					<view class="">
						{{item.label}}
					</view>
				</view>
			</view>
			<image class="start-btn" src="../static/img/开始按钮.png" mode="" @click="onStartBtnClick"></image>
		</view>
		<!-- 评论 -->
		<uni-popup type="center" animation ref="activate" :mask-click="false">
			<view class="model-container">
				<img @click="onClose" src="../static/img/关闭.png" alt="" style="height: 49rpx;width: 49rpx;"
					class="m-close" />
				<view class="goods-items">
					<view class="g-item" v-for="ite in productList" :key="ite">
						<img src="../static/img/甜点.png" alt="" style="height: 230rpx;width: 230rpx;" />
						<view class="g-title">
							{{ite.name||'-'}}
						</view>
						<view class="g-price">
							¥{{ite.price||'-'}}
						</view>
						
						<view class="choose-btn" @click="onChoose({id:ite.id})">
							选择
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {whattodayeatApi,whattodayeatProductApi} from '../what_to_eat_today.js'
	import navBar from '@/components/navBar';
	var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
	let app = getApp();
	export default {
		components: {
			navBar
		},
		data() {
			return {
				theme: app.globalData.theme,
				navH: '',
				statusBarHeight: app.globalData.statusBarHeight,
				navigationBarHeight: 0,
				loading: false,
				loadTitle: '',
				productList:[],
				items: []
				// [{
				// 		label: '我不挑食',
				// 		icon: require('../static/img/甜点.png'),
				// 		checked: true
				// 	},
				// 	{
				// 		label: '减肥套餐',
				// 		icon: require('../static/img/减肥餐.png'),
				// 		checked: true
				// 	},
				// 	{
				// 		label: '精致小食',
				// 		icon: require('../static/img/小食.png'),
				// 		checked: true
				// 	},
				// 	{
				// 		label: '豪华美食',
				// 		icon: require('../static/img/豪华餐.png'),
				// 		checked: true
				// 	}
				// ]
			}
		},
		//下拉刷新
		onPullDownRefresh() {

		},
		onLoad(options) {
			this.navH = 96;
			whattodayeatApi().then(res => {
				this.items = res.data.map((ite,i) => ({
					label:ite.tagName,
					icon:ite.icon,
					checked:i==0,
					...ite
				}))
			})
		},
		onShow() {

		},
		methods: {
			handleCheck(i) {
				this.items.forEach(ite => ite.checked = false)
				this.items[i].checked = true
			},
			handBack() {
				uni.navigateBack({
					delta: 1
				})
			},
		async onStartBtnClick() {
				uni.showLoading()
				let check = this.items.filter((ite) => ite.checked)
				const params = {
					latitude: uni.getStorageSync('user_latitude'),
					longitude: uni.getStorageSync('user_longitude'),
					tagId:check[0].id
				}
			const res =	await whattodayeatProductApi(params).finally(()=>uni.hideLoading())
			this.productList = res.data.splice(0,1)
			this.$refs.activate.open()
			},
			onClose() {
				this.$refs.activate.close()
			},
			onChoose(data) {
				uni.navigateTo({
					url: `/pages/goods/goods_details/index?id=${data.id}&mt=0`,
				})
			}
		},
		mounted() {

		},
	}
</script>

<style scoped>
	.order-nav {
		font-weight: 500;
		font-size: 35rpx;
		color: #FFFFFF;
		background-color: #FF6702;
		text-align: center;
		position: relative;
	}

	.back-button {

		width: 25rpx;

		height: 25rpx;

		border-right: 4rpx solid #fff;
		border-bottom: 4rpx solid #fff;

		transform: rotate(135deg);

		margin-left: 10rpx;

		display: inline-block;
		position: absolute;
		left: 40rpx;
		top: 25rpx;
	}


	.content {
		position: relative;
		height: calc(100vh - 49px);
		width: 100vw;
		padding-top: 135rpx;
		/* background-image: url('../static/img/背景.png'); */
		background-size: cover;
		background-repeat: no-repeat;
	}

	.items {
		display: grid;
		grid-template-columns: auto auto;
		grid-gap: 19.23rpx;
		margin: 0 57rpx;
	}

	.item {
		display: flex;
		align-items: center;
		color: #B16F22;
		font-size: 35rpx;
		font-weight: 500;
		font-family: PingFangSC, PingFang SC;
		width: 308rpx;
		height: 96rpx;
		background: linear-gradient(180deg, #FFE7CA 0%, #FFFFFF 100%);
		border-radius: 8rpx;
		border: 4rpx solid;
		border-image: linear-gradient(225deg, rgba(255, 194, 80, 1), rgba(255, 220, 107, 1), rgba(255, 225, 133, 1)) 4 4 !important;
		padding: 9rpx;
	}

	.active {
		border: 4rpx solid;
	}

	.notActive {
		border: none;
	}

	.start-btn {
		position: absolute;
		width: 153rpx;
		height: 80rpx;
		top: 55%;
		left: 50%;
		transform: translateX(-50%);
	}

	.model-container {
		position: relative;
		width: 712rpx;
		height: 654rpx;
		background-color: #fff;
		border-radius: 23rpx;
		padding-top: 96rpx;
	}

	.m-close {
		position: absolute;
		right: 39rpx;
		top: 20rpx;
	}

	.goods-items {
		margin: 0 39rpx;
		display: flex;
		gap: 20rpx;
	}

	.g-item {
		padding: 38.46rpx;
		background: linear-gradient(180deg, #FFF9F1 0%, #FFFFFF 100%);
		border-radius: 8rpx;
		border: 2rpx solid;
		border-image: linear-gradient(225deg, rgba(255, 194, 80, 1), rgba(255, 220, 107, 1), rgba(255, 225, 133, 1)) 2 2;
	}

	.g-title {
		margin-top: 19rpx;
		font-family: PingFangSC, PingFang SC;
		font-size: 27rpx;
		color: #141414;
		line-height: 38rpx;
		text-align: center;
	}

	.g-price {
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 31rpx;
		color: #FF9805;
		line-height: 42rpx;
		text-align: center;
		margin-bottom: 10rpx;
	}

	.choose-btn {
		width: 154rpx;
		height: 54rpx;
		background: linear-gradient(180deg, #FFAC3D 0%, #FF1E1D 100%);
		border-radius: 15rpx;
		border: 2rpx solid #FFD288;
		font-family: PingFangSC, PingFang SC;
		font-size: 27rpx;
		color: #FFFFFF;
		line-height: 54rpx;
		text-align: center;

		margin: auto;
	}
</style>