<template>
	<view class="userMeal">
		<view class="header">
			<view style="display: flex;justify-content: center;width: 50%;">
				<view :class="barType == 1?'bar-select':'bar'" @click="barType=1">
					生效中
					<image v-if="barType==1" :src="require('../../static/sel.png')" alt="">
				</view>
				<span v-if="barNum>0 && barType==1">{{barNum}}</span>
			</view>
			<view style="display: flex;justify-content: center;width: 50%;border-left: 1px solid #E6E6E6;">
				<view :class="barType == 2?'bar-select':'bar'" @click="barType=2">
					已失效
					<image v-if="barType==2" :src="require('../../static/sel.png')" alt="">
				</view>
				<span v-if="barNum>0 && barType==2">{{barNum}}</span>
			</view>
		</view>
		<view class="body" v-for="(item, index) in setMealList" :key="index" @click="toPath(item.id)">
			<image :src="baseImagePath + item.imgUrl" mode=""></image>
			<view class="cont">
				<view class="title">
					{{item.packageName}}
				</view>
				<view class="content">
					<view class="times">
						{{item.createTime}}
					</view>
					<view class="services" v-if="item.status === 1">
						{{item.num}}/{{item.allNum}}<span>个项目可用</span>
					</view>
					<image v-else :src="require('../../static/shixiao.png')" mode=""></image>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		userPackageList
	} from "@/api/myApi.js"
	const app = getApp()
	export default {
		components: {},
		data: function() {
			return {
				barType: 1,
				barNum: 0,
				pageNo:1,
				pageSize:10,
				setMealList: [],
				baseImagePath: this.baseImagePath,
			}
		},
		onLoad(e) {
			app.globalData.requestToken = e.token;
			uni.setStorageSync('token',e.token)
			this.getList()
		},
		watch:{
			barType(){
				this.setMealList = []
				this.pageNo = 1
				this.getList()
			}
		},
		onReachBottom() {
			this.pageNo += 1
			this.getList()
		},
		onBackPress(options) {
		    // 这里可以自定义返回逻辑，比如下面跳转其他页面
		  // #ifdef APP-PLUS
		  if (plus.os.name.toLowerCase() === 'android') {
		      plus.runtime.quit();
		  } else {
		      plus.runtime.quit();
		  }
		  // #endif
		    // return true 表示禁止默认返回
		   return true;
		},
		methods: {
			toPath(item){
				console.log(item);
				this.$yrouter.push({
					path: "/pages/userMeal/userMealDetail/index?id="+item + "&type=my"
				});
			},
			getList(){
				let data = {
					pageNo:this.pageNo,
					pageSize:this.pageSize,
					status:this.barType
				}
				userPackageList(data).then(res=>{
					console.log(res);
					this.setMealList = [...this.setMealList,...res.data.rows]
					this.barNum = this.setMealList.length
				})
			}
		},
	}
</script>

<style lang="less">
	page {
		background: #F5F5F5;
	}

	.body {
		height: 178rpx;
		background: #FFFFFF;
		border-radius: 5rpx;
		margin: 10rpx;
		display: flex;
		padding: 29rpx 23rpx 0 25rpx;

		image {
			width: 120rpx;
			height: 120rpx;
		}

		.cont {
			width: 76%;
			padding: 16rpx 0 16rpx 30rpx;

			.title {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 31rpx;
			}

			.content {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 33rpx;

				.times {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #005BFF;
					line-height: 31rpx
				}

				.services {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					line-height: 31rpx;

					span {
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						line-height: 31rpx;
					}
				}

				image {
					width: 142rpx;
					height: 107rpx;
					margin-top: -74rpx;
				}
			}
		}
	}

	.header {
		width: 100%;
		height: 86rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;

		.bar {
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #666666;
		}

		span {
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #005BFF;
			padding-left: 12rpx;
		}
	}

	.bar-select {
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;

		image {
			width: 34rpx;
			height: 11rpx;
		}
	}
</style>
