<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>
		<view class="medicine-item x-f" v-for="(item, index) in list" :key="index" @click="showProduct(item)">
			<view class="medicine">
				<image :src="item.image" mode="aspectFill"></image>
				<!-- {{$getDictLabelName("storeProductType",product.productType)}} -->
				<!-- <image class="otc" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/index/blue_lable_otc.svg" mode="aspectFill"></image> -->
			</view>
			<view class="medicine-r">
				<view class="ellipsis" style="white-space: normal;">{{ item.productName || '' }}</view>
				<view class="desc">包装规格：{{ item.unitName || '--' }}</view>
				<view class="desc" v-show="item.storecount">共有 <text style="color: #2583EB;margin: 0 10rpx;">{{item.storecount||0}}</text> 个商家销售 </view>
				<view class="price-box">
					<text class="price-box-unit">￥</text>
					<text class="price-box-integer">{{splitPrice(item.price || 0).intPart}}</text>
					<text class="price-box-decimal">.{{splitPrice(item.price || 0).decPart}}</text>
					<!-- <text class="price-box-text">/日</text> -->
					<text class="old" v-show="item.price!=item.otPrice&&item.otPrice!==null&&item.otPrice!==undefined">¥{{item.otPrice.toFixed(2)}}</text>
				</view>
			</view>
		</view>
		<Loading :loaded="loaded" :loading="loading"></Loading>
	</view>
</template>

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

		methods: {
			splitPrice(num) {
			  const [intPart = '0', decPart = '00'] = String(num||0).split('.');
			  return { intPart, decPart: decPart.padEnd(2, '0').slice(0, 2) };
			},
			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
						});
					}
				)
			},
			showProduct(item) {
				uni.navigateTo({
					url: '/pages_shopping/productDetails?productId=' + item.productId
				})
			},
			navTo(url){
				uni.navigateTo({
					url: url
				})
			},
		}

	};
</script>
<style lang="scss" scoped>
	.old{
		margin-left: 14rpx;
		font-size: 26upx;
		font-family: PingFang SC;
		font-weight: 500;
		text-decoration: line-through;
		color: #BBBBBB;
		line-height: 1.1;
	}
	.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;
			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;
				}

			}
		}

		.price-box {
			font-family: Roboto, Roboto;
			font-weight: bold;
			font-size: 36rpx;
			color: #FF5C03;
			margin-top: 22rpx;

			&-unit {
				font-weight: 600;
				font-size: 26rpx;
			}

			&-decimal {
				font-weight: 600;
				font-size: 26rpx;
			}

			&-text {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
			}
		}
	}

	.medicine-box {
		padding: 0 24rpx 32rpx 24rpx;

		.medicine {
			width: 200rpx;
			height: 200rpx;
			flex-shrink: 0;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			overflow: hidden;
			position: relative;
			margin-right: 24rpx;
			.otc {
				position: absolute;
				top: 0;
				left: 0;
				width: 96rpx;
				height: 40rpx;
				border-radius: 0;
			}

			image {
				width: 100%;
				height: 100%;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
			}

			&-r {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #191A1B;
				flex: 1;
				overflow: hidden;
			}

			&-item {
				align-items: flex-start !important;
				margin-bottom: 40rpx;

				&:last-child {
					margin-bottom: 0;
				}
			}
		}

		.desc {
			margin-top: 12rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #939599;
		}
	}
</style>