<template>
	<page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
	<view>
		<view class="image-box">
			<image style="width: 100%;height: 100%;" :src="dashesData.imageUrl"></image>
			<!-- <image style="width: 100%;height: 100%;" src="../../static/images/code.png"></image> -->
		</view>
		<view class="menuContent">
			<view class="menuInfo">
				<view style="color:#DD7D3C;font-size: 36rpx;font-weight: 600;margin-bottom: 10px;margin-left: 20px;">￥{{(menuData.dishesDetailList[0].prefPrice/100).toFixed(2)}}</view>
				<view style="width: 100%;height: 30px;display: flex;align-items: center;justify-content: space-between;">
					<view style="font-size: 36rpx;font-weight: 600;margin-left: 20px;">{{dashesData.dishesName}}</view>
					<view class="star-icon" style="display: flex;" @click="addCollect" v-if="dashesData.isFavorites==2">
						<u-icon name="star" size="22" color="#ccc"></u-icon><text style="font-size: 30rpx;">收藏</text>
					</view>
					<view class="star-icon" style="display: flex;" @click="cancelCollect" v-if="dashesData.isFavorites==1">
						<u-icon name="star-fill" size="22" color="#ff9900"></u-icon><text style="font-size: 30rpx;">已收藏</text>
					</view>
				</view>
			</view>
			<view class="tab-navigation">
				<Tabs :tabList="tabList" @changeTab="changeTab" />
			</view>
			<view class="tab-content">
				<view class="info-box" v-if="hIndex==0">
					<view style="margin-bottom: 20px;">
						<text style="color: #959FA4;">菜品简介</text>
						<text style="margin-left: 20px;word-break: break-all;">-</text>
					</view>
					<view style="margin-bottom: 20px;">
						<text style="color: #959FA4;">主料</text>
						<text style="margin-left: 20px;word-break: break-all;">-</text>
					</view>
					<view style="margin-bottom: 20px;">
						<text style="color: #959FA4;">辅料</text>
						<text style="margin-left: 20px;word-break: break-all;">-</text>
					</view>
					<view style="margin-bottom: 20px;">
						<text style="color: #959FA4;">口味</text>
						<text style="margin-left: 20px;word-break: break-all;">-</text>
					</view>
				</view>
				<view class="nutrition-box" v-if="hIndex==1">
					<view class="nutrition-box-item">
						<view>项目(份)</view>
						<view>热量(份)</view>
						<view>蛋白质(份)</view>
						<view>脂肪(份)</view>
						<view>碳水化合物(份)</view>
						<view>膳食纤维(份)</view>
						<view>胆固醇(份)</view>
						<view>钙(份)</view>
						<view>钠(份)</view>
					</view>
					<view class="nutrition-box-item">
						<view>含量</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
					</view>
					<view class="nutrition-box-item">
						<view>NRV%</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
						<view>-</view>
					</view>
				</view>
				<view class="evaluate-box" v-if="hIndex==2">
					<view style="width: 100%;height: 30vh;display: flex;justify-content: center;align-items: center;" v-if="totalCount==0">
						暂无评论...
					</view>
					<view style="width: 92%;height: 30px;margin: 10rpx auto; display: flex;justify-content: space-between;align-items: center;" v-if="totalCount>0">
						<text style="font-size: 28rpx;font-weight: bold;margin-left: 20rpx;">评价</text>
						<text style="font-size: 24rpx;margin-left: 20rpx;" @click="goAllEvaluate">查看全部{{totalCount}}个></text>
					</view>
					<view style="width: 100%;height: 40vh;padding: 20rpx;" v-if="totalCount>0">
						<view v-for="(item,index) in evaluaList" :key="index" style="width: 100%;height: auto;border-bottom: 1px solid #ccc;">
							<view style="width: 94%;margin: 10rpx auto;display: flex;">
								<view style="width: 100rpx;height: 100rpx;margin: 10rpx;">
									<image :src="item.custPhotoUrl? item.custPhotoUrl:'../../static/images/user.png'" mode="" style="width: 100rpx;height: 100rpx;"></image>
								</view>
								<view style="width: 80%;height: 100rpx;">
									<view style="width: 100%;display: flex;align-items: center;justify-content: space-between;margin-bottom: 20rpx;padding-top: 10rpx;">
										<text>{{item.custName}}</text>
										<text>{{item.evaluaTime}}</text>
									</view>
									<view style="display: flex;margin-bottom: 10rpx;">
										<u-icon v-for="n in 5" :key="n" :name="n <= item.starLevel ? 'star-fill' : 'star-fill'"
											:color="n <= item.starLevel ? '#ff9933' : '#ccc'" size="20"></u-icon>
									</view>
								</view> 
							</view>
							<view style="width: 100%;padding: 10rpx;padding-left: 20rpx;display: flex;align-items: center;" v-if="item.pictureList&&item.pictureList.length>0">
								<view v-for="(imgItem,imgIndex) in item.pictureList" :key="imgIndex" style="margin-bottom: 10rpx;">
									<image :src="item" mode="" style="width: 100rpx;height: 100rpx;"></image>
								</view>
							</view> 
							<view style="width: 100%;padding: 10rpx;padding-left: 20rpx;">
								{{item.description||"该用户没做评价"}}
							</view> 
						</view> 
					</view> 
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getMenudishesDetailAPI,addCollectionDishesAPI,delCollectionDishesAPI,getMenuEvaluaorderAPI,getMenuEvaluaCountAPI } from '../../api/week-menu/index'
import Tabs from '@/pages/components/Tabs.vue'
export default {
	components: { Tabs },
	data() {
		return {
			fontValue:uni.getStorageSync('fontSize') || 8,
			menuData:{},
			dashesData:{},
			tabList: ["菜品信息","营养信息","评价"],//tab列表
			hIndex:0,
			evaluaList:[],
			totalCount:0
		}
	},
	onLoad(options) {
		options = JSON.parse(options.params) 
		console.log(options)
		this.menuData = options
		this.getMenudishesDetail()
		// this.getMenuEvaluaorderList()
		// this.getMenuEvaluaCount()
		
	},
	methods: {
		//获取菜品详情
		async getMenudishesDetail(){
			let param = {
				"userId": uni.getStorageSync('userId') ,
				"detailId": this.menuData.detailId,
				"baseDishesId": this.menuData.baseDishesId,
				// "delFlag": 2
			}
			const res = await getMenudishesDetailAPI(param)
			if(res.code==200){
				this.dashesData = res.data;
				this.$forceUpdate()
				// this.$modal.msgError("收藏成功")
			}
			console.log(res) 
		},
		async getMenuEvaluaCount() {
			let param = { 
				"dishesId": this.menuData.baseDishesId, 
			}
		    const res = await getMenuEvaluaCountAPI(param)
			console.log(res)
			this.totalCount = res.totalCount
		},
		//获取菜品评价
		async getMenuEvaluaorderList(){
			console.log(this.menuData)
			let param = { 
				  "current": 1,
				  "size": 10,
				  "mealId": this.menuData.baseDishesId,
				  // "mealId": "383143288183459840",
				  "shopstallId": this.menuData.stallId,
				  // "shopstallId": "379082300370980864",
				  "searchType": "3",
				  "mealType": "1"
			}
			const res = await getMenuEvaluaorderAPI(param)
			if(res.code==200){
				this.evaluaList = res.data.evaluaList||[]
				// this.dashesData = res.data;
				// this.$forceUpdate()
			}
			console.log(res) 
		},
		goAllEvaluate(){
			console.log(this.menuData)
			uni.navigateTo({
			  url: `/pages/weeklyMenu/evaluateCenter?params=${JSON.stringify(this.menuData)}`
			})
		},
		changeTab(index) { 
			this.hIndex=index
			console.log(this.hIndex)
		},
		//收藏
		async addCollect(){
			let param = {
				"baseDishesId":this.dashesData.baseDishesId,
				"userId":uni.getStorageSync('userId'),
				"shopstallId":this.menuData.stallId
			}
			const res = await addCollectionDishesAPI(param)
			console.log(res) 
			if(res.code==200){
				// this.$modal.msgError("收藏成功")
				uni.$u.toast('收藏成功')
				this.getMenudishesDetail()
			}
			
		},
		//取消收藏
		async cancelCollect(){
			let param = {
				"dishesIdList":[this.dashesData.baseDishesId],
				"userId":uni.getStorageSync('userId'),
			}
			const res = await delCollectionDishesAPI(param)
			console.log(res) 
			if(res.code==200){
				// this.$modal.msgError("收藏成功")
				uni.$u.toast('取消藏成功')
				this.getMenudishesDetail()
			}
		}
		 
		// goMenuList(item){
		// 	uni.navigateTo({
		// 	  url: `/pages/weeklyMenu/menuList?params=${JSON.stringify(item)}`
		// 	})
		// }
  }
}
</script>

<style lang="scss" scoped>
page {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background-color: #fff;
  min-height: 100%;
  height: auto;
}
.image-box{
	width: 100%;
	height: 30vh;
	// background-color: #666;
}
.menuContent{
	width: 100%;
	height: 64vh;
	background-color: #fff;
	// border-top-right-radius: 20px;
	// border-top-left-radius: 20px;
	// background-color: #DD7D3C;
	// z-index: 999;
	// margin-top: -2.5vh;
}
.menuInfo{
	width: 94%;
	margin: 10rpx auto;
	height: auto;
}
.star-icon {
	padding: 8px;
}


.tab-navigation {
  display: flex;
  background-color: white;
  padding: 0px 16px 0 16px;
  margin-bottom: 10px;
}

.tab-content{
	width: 94%;
	margin: 10rpx auto;
	height: 50vh;
	.info-box{
		width: 94%;
		margin: 10rpx auto;
		height: 100%;
	}
	.nutrition-box{
		width: 94%;
		margin: 10rpx auto;
		height: 100%;
		color: #959FA4;
		// background-color: #DD7D3C;
		display: flex;
		justify-content: space-between;
		
		.nutrition-box-item{
			width: 28%;
			margin: 0 2%;
			height: 100%;
			text-align: center;
			// background-color: #DD7D3C;
			view{
				margin-bottom: 10px;
			}
		}
		
	}
} 









.content-left{
	width: 20%;
	height: 82vh;
} 
.active2 {
	color: #DD7D3C;
	font-weight: bolder;
	font-size: 26rpx;
}

.content-right{
	width: 80%;
	height: 82vh;
}
.scroll-right-item{
	width: 100%;
	height: 300rpx;
	// background-color: #959FA4;
}
.image {
  width: 200rpx;
  height: 200rpx;
  border-radius: 10rpx;
  margin: 20rpx;
}

 
</style>
