<template>
	<view class="bg-white">
		<u-dropdown>
			<u-dropdown-item @change="classtype" v-model="value" :title="options1[value].label" :options="options1"></u-dropdown-item>
			<u-dropdown-item @change="pricetype" v-model="price" :title="options3[price].label" :options="options3"></u-dropdown-item>
			<u-dropdown-item @change="recomtype" v-model="recommend" :title="options2[recommend].label" :options="options2"></u-dropdown-item>
		</u-dropdown>
		<view class="padding-lr-sm">
			<u-search :clearabled="false" shape="round" :show-action="false" placeholder="搜索疫苗名称" v-model="keyword"></u-search>
		</view>
		<view class="margin-sm">
			<view v-for="(item,index) in vaccineList" :key="index" @click="xuanzephone(item)" class="padding bg-white margin-top-sm flex justify-between align-center"
			 style="border-radius: 16rpx;box-shadow: 0 0 50rpx 0 rgba(0, 0, 0, 0.1);">
				<view class="">
					<view class="text-bold" style="color: #333333;font-size: 30rpx;">
						{{item.name}}
					</view>
					<view class="flex align-center margin-top-xs">
						<view class="mianfei margin-right-xs" style="font-size:22rpx;color: #EEAA3F;">
							{{item.type==1?'免费':'￥'+item.price/100}}
						</view>
						<view class="typestyle" style="font-size:22rpx;color: #0B73B9;">
							{{item.type==1?'I类':'II类'}}
						</view>
					</view>
					<view class="margin-top-xs" style="color: #999999; font-size: 26rpx;">
						备注：<text style="color: #666666;">{{item.remark}}</text>
					</view>
					<view class="margin-top-xs" style="color: #999999; font-size: 26rpx;">
						厂家：<text style="color: #666666;">{{item.supplier}}</text>
					</view>
				</view>
				<view class="">
					<u-radio-group v-model="danxuan">
						<u-radio @change="radioChange" :key="index" :name="item.id">
						</u-radio>
					</u-radio-group>
				</view>
			</view>
		</view>
		<u-empty text="暂无数据" mode="order" :show="show" margin-top="250"></u-empty>
		<view class="cu-tabbar-height"></view>
		<view class="cu-tabbar-height"></view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.getvaccinesList()
		},
		onShow() {

		},
		data() {
			return {
				vaccineList: [],
				keyword: "",
				value: 0, //种类
				price: 0, //价格
				recommend: 0, //推荐
				options1: [{
					value: 0,
					label: "全部种类"
				}, {
					value: 1,
					label: "I类"
				}, {
					value: 2,
					label: "II类"
				}, ],
				options2: [{
					value: 0,
					label: "推荐排序"
				}, {
					value: 1,
					label: "低价优先"
				}, {
					value: 2,
					label: "高价优先"
				}, ],
				options3: [{
					value: 0,
					label: "全部价格"
				}, {
					value: 1,
					label: "免费"
				}, {
					value: 2,
					label: "收费"
				}, ],
				danxuan: "",
				show: false,
				pageindex: 1
			}
		},
		methods: {
			//种类下拉
			classtype(value) {
				this.value = value
				this.pageindex = 1
				this.vaccineList = []
				this.getvaccinesList()
			},
			//价格下拉
			pricetype(value) {
				this.price = value
				this.pageindex = 1
				this.vaccineList = []
				this.getvaccinesList()
			},
			//推荐下拉
			recomtype(value) {
				this.recommend = value
				this.pageindex = 1
				this.vaccineList = []
				this.getvaccinesList()
			},
			getvaccinesList: async function() {
				let res = await this.$request.post("/api/v1/vaccine/vaccineList", {
					page: this.pageindex,
					name: this.keyword,
					type: this.value,
					sort_type: this.recommend
				})
				if (res.status == 0) {
					if (this.pageindex > res.data.last_page) {
						uni.showToast({
							title: "没有更多了",
							icon: "none"
						})
					} else {
						this.vaccineList = this.vaccineList.concat(res.data.data)
						this.pageindex++
					}
				}
				if (this.vaccineList.length == 0) {
					this.show = true
				} else {
					this.show = false
				}
			},
			xuanzephone(item) {
				this.danxuan = item.id
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.yimiaoInfo = item
				uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.main {}

	.mianfei {
		width: 60rpx;
		height: 30rpx;
		background: #FFF0D9;
		// border-radius: 16rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.typestyle {
		width: 44rpx;
		height: 30rpx;
		background: #E5F5FF;
		// border-radius: 16rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
