<template>
	<view class="content">
		<view class="onecontent">
			<image class="onecontentimage" :src="datas.toplist.coverImg" mode="aspectFill"></image>
			<!-- 小内切圆 -->
			<view class="after"></view>
			<view class="onecontentabsolute">
			</view>
		</view>
		<view class="twocontent" v-for="(item, index) in datas.list" :key="index" @click="clickproduct(item)">
			<view class="df twoBox">
				<view class="df ">
					<image :src="item.logo" style="width: 50rpx;height: 50rpx;margin-right: 10rpx;" mode="">
					</image>
					<view class="">
						{{ item.shopName }}
					</view>
				</view>
				<view class="">
					{{ item.distance }}m
				</view>
			</view>
			<view class="df" style="    justify-content: space-between;    flex-wrap: wrap;    padding: 30rpx 0rpx;">
				<image :src="item.coverImg" style="width: 192rpx;height: 192rpx;" mode=""></image>
				<view style="margin-left: 24rpx;    flex: auto;">
					<view class="df" style="justify-content: space-between;    flex-wrap: wrap;">
						<view style="font-weight: 500;    font-size: 28rpx;    color: #333333;">{{ item.name }}</view>
						<view style="    font-weight: 400;    font-size: 24rpx;    color: #999999;">已抢{{ item.saleNum
						}}份
						</view>
					</view>
					<view class="indexboxitemleftthere " style="">
						<view class="df" style="align-items: normal;">
							<view class="df">
								<text
									style="    font-family: Source Han Sans CN, Source Han Sans CN;    font-weight: 500;    font-size: 16rpx;    color: #FF7127;">
									到手
								</text>
								<text
									style="font-weight: 500;    font-size: 24rpx;    color: #FF7127;">￥{{item.salePrice}}</text>
								<view style="    margin-left: 4rpx;
    padding: 2rpx 10rpx;
    border-radius: 4rpx 4rpx 4rpx 4rpx;
    border: 2rpx solid #FF7127;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 500;
    font-size: 16rpx;
    color: #FF7127;">
									{{item.discount}}折
								</view>
								<text style="    margin-left: 6rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 400;
    font-size: 16rpx;
    color: #999999;
    text-decoration-line: line-through;">￥{{item.originPrice}}</text>
							</view>
							<view style="    position: absolute;
    top: 16rpx;
    right: 12rpx;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: bold;
    font-size: 24rpx;
    color: #FFFFFF;">
								马上抢
							</view>
						</view>
						<view class="df" style="justify-content: space-between;">
							<view
								style="font-family: Source Han Sans CN, Source Han Sans CN;    font-weight: 400;    font-size: 24rpx;    color: #999999;    padding-bottom: 8rpx;">
								共省{{item.originPrice-item.salePrice}}元
							</view>
							<view
								style="    font-family: Source Han Sans CN, Source Han Sans CN;    font-weight: bold;    font-size: 16rpx;margin-right: 12rpx;    color: #FFFFFF;">
								<uni-countdown :show-day="false" :hour="convertMilliseconds(item.endTime).hours"
									:minute="convertMilliseconds(item.endTime).minutes"
									:second="convertMilliseconds(item.endTime).seconds" :indexs='index' color="#FFFFFF"
									border-color="#00B26A" splitorColor="#FFFFFF" :font-size="7"></uni-countdown>

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



	</view>
</template>
<script setup>
	import uniCountdown from '@/uni_modules/uni-countdown/components/uni-countdown/uni-countdown.vue';

	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		APIhome,
		userdict
	} from "@/common/api/index/index.js"
	import {
		reactive
	} from 'vue';
	let datas = reactive({
		titlename: '咖啡',
		opacitys: false,
		toplist: "",
		list: []
	})
	onLoad(() => {
		getList()
	})

	function clickproduct(item) {
		uni.pro.navigateTo('product/index', {
			id: item.id
		})
	}
	async function getList() {
		let ele = await userdict({
			type: "group"
		})
		datas.toplist = ele
		let res = await APIhome({
			lng: uni.cache.get('getLocationstorage').lng,
			lat: uni.cache.get('getLocationstorage').lat,
			address: uni.cache.get('getLocationstorage').address, //地址
			categoryId: 1,
			orderType: 0,
			name: '',
			page: 1, //页数
			size: 10, //页容量
			distanceType: ''
		})
		datas.list = res.records
	}

	function convertMilliseconds(milliseconds) {
		// 计算天数
		const days = Math.floor(milliseconds / 86400000);
		// 计算剩余的毫秒数
		milliseconds %= 86400000;
		// 计算小时数
		const hours = Math.floor(milliseconds / 3600000);
		// 计算剩余的毫秒数
		milliseconds %= 3600000;
		// 计算分钟数
		const minutes = Math.floor(milliseconds / 60000);
		// 计算剩余的毫秒数
		milliseconds %= 60000;
		// 计算秒数
		const seconds = Math.floor(milliseconds / 1000);

		return {
			days,
			hours,
			minutes,
			seconds
		};
	}
</script>

<style scoped lang="scss">
	page {
		background-color: #f9f9f9;

	}

	.content {

		.onecontent {
			width: 100%;
			height: 492rpx;
			position: relative;

			.onecontentimage {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
			}

			.after {
				position: absolute;
				bottom: 32rpx;
				right: 0;
				width: 40rpx;
				height: 40rpx;
				line-height: 40rpx;
				text-align: center;
				background-image: radial-gradient(160rpx at 0px 0px, rgba(0, 0, 0, 0) 40rpx, #fff 40rpx);
			}

			.onecontentabsolute {
				position: absolute;
				width: 100%;
				padding: 0 52rpx;
				bottom: 64rpx;

				.onecontentabsoluteitem {
					padding: 8rpx 16rpx;
					background: #FFFFFF;
					border-radius: 12rpx 12rpx 12rpx 12rpx;

					image {
						width: 24.16rpx;
						height: 29.31rpx;
					}

					input {
						padding: 0 16rpx;
						flex: auto;
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
					}

					.onecontentabsoluteitembotton {
						width: 120rpx;
						height: 56rpx;
						line-height: 56rpx;
						text-align: center;
						background: linear-gradient(109deg, #FF9D84 0%, #FFFFFF 100%);
						border-radius: 28rpx 28rpx 28rpx 28rpx;
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: bold;
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}

		.twocontent {
			padding: 20rpx 40rpx;

			.twoBox {
				background-color: #fff;
				justify-content: space-between;
				padding: 30rpx 0rpx;
				border-bottom: 1rpx solid #ccc;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: 400;
				font-size: 24rpx;
				color: #666666;
			}
		}

		.indexboxitemleftthere {
			position: relative;
			margin-top: 30rpx;
			padding: 16rpx 0;
			padding-left: 16rpx;
			width: 100%;
			background: url(https://czg-qr-order.oss-cn-beijing.aliyuncs.com/index/qinggou.png) no-repeat;
			background-size: 100% 100%;

		}

		.df {
			display: flex;
			align-items: center;
		}
	}
</style>