<template>
	<view class="medicine-box box">
		<view class="title-box">
			<view class="title">推荐药品</view>
			<view class="more" @click="navTo('/pages_shopping/home/productList')">
				<view class="text">更多药品</view>
				<image src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/arrow_gray.png"></image>
			</view>
		</view>
		<medicineItem v-for="(item, index) in list" :key="index" :item="item"></medicineItem>
		<Loading :loaded="loaded" :loading="loading"></Loading>
	</view>
</template>

<script>
	import medicineItem from "@/components/medicineItem";
	import {getTuiProducts} from '@/api/index.js'
	import Loading from "@/components/Loading";
	export default {
		components: {
			Loading,
			medicineItem
		},
		name: "likeProduct",
		data() {
			return {
				page: {
					page: 1,
					pageSize: 4
				},
				total: 0,
				list: [],
				loaded: false,
				loading: false
			};
		},
		created() {},
		mounted() {
			this.getTuiProducts();
		},

		methods: {
			getTuiProducts() {
				var that = this;
				if (that.loaded == true || that.loading == true) return;
				that.loading = true;
				getTuiProducts(that.page).then(
					res => {
						if (res.code == 200) {
							that.total = res.data.total;
							that.list.push.apply(that.list, res.data.list);
							that.loading = false;
							that.loaded = that.list.length < that.total ? false : true;
							that.page.page = that.page.page + 1;
							uni.hideLoading()
						}
					},
					err => {
						uni.hideLoading()
						uni.showToast({
							title: err.msg,
							icon: 'none',
							duration: 2000
						});
					}
				)
			},
			navTo(url){
				uni.navigateTo({
					url: url
				})
			},
		}

	};
</script>
<style lang="scss" scoped>
	.box {
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 24rpx;
		box-sizing: border-box;

		.title-box {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			padding: 28rpx 0 8rpx 0;
			box-sizing: border-box;

			.title {
				font-size: 32upx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #111111;
			}

			.more {
				display: flex;
				align-items: center;
				justify-content: flex-end;

				.text {
					font-size: 24rpx;
					font-family: PingFang SC;
					color: #9B9B9B;
				}

				image {
					margin-left: 10rpx;
					width: 15rpx;
					height: 20rpx;
				}

			}
		}
	}

	.medicine-box {
		padding: 0 24rpx 10rpx 24rpx;
	}
</style>