<template>
	<view class="content">
		<scroll-view scroll-y="true" class="scroll-view">
			<view class="list-scroll-view">
				<view class="one">
					<view class="one_1">
						<swiper class="swiper" circular :indicator-dots="true" indicator-color="#ffffff"
							indicator-active-color="#007AFF" :interval="3000" :duration="1000">
							<swiper-item class="list" v-for="(item,index) in fileList" :key="index">
								<image class="image" :src="item.url" mode="aspectFit">
								</image>
							</swiper-item>
						</swiper>
					</view>
					<view class="one_2">
						<text class="money"><text>¥</text>{{info.money||0}}</text>
					</view>
					<view class="one_3">
						<text class="num">已售{{info&&info.sell_num||0}}件</text>
					</view>
					<view class="one_4">
						<view class="name">
							{{info&&info.name}}
						</view>
						<view class="brief">
							{{info&&info.brief||''}}
						</view>
					</view>
					<view class="one_5">
						<view class="list" v-for="(item,index) in fileList" :key="index">
							<image class="image" :src="item.url" mode="aspectFit">
							</image>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="bottom">
			<uni-goods-nav :fill="true" :options="options" :button-group="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" style="margin-top: 20px;" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 系统设置
				config: {},
				// 商品id
				id: '',
				// 当前用户信息
				user: {},
				// 商品详情
				info: {},
				// 轮播图
				fileList: [],
				// 底部商品导航
				options: [{
						icon: 'shop',
						text: '店铺'
					},
					{
						icon: 'cart',
						text: '购物车',
						info: 2,
						infoBackgroundColor: '#007aff',
						infoColor: "#f5f5f5"
					}
				],
				buttonGroup: [{
					text: '加入购物车',
					backgroundColor: 'linear-gradient(90deg, #1E83FF, #0053B8)',
					color: '#fff'
				}],
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e.id || '');
			that.searchConfig();
			await that.search();
		},
		onShow: async function() {
			const that = this;
			that.searchToken();
		},
		methods: {
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) that.$set(that, `user`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			searchConfig() {
				const that = this;
				try {
					const res = uni.getStorageSync('config');
					if (res) that.$set(that, `config`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			// 查询商品详情
			async search() {
				const that = this;
				let res;
				res = await that.$api(`/Good/${that.id}`, 'GET', {})
				if (res.errcode == '0') {
					const arr = await that.$api(`/Specs`, 'GET', {
						goods: res.data._id,
						is_use: '0'
					})
					if (arr.errcode == '0') {
						let data = arr.data.sort((a, b) => {
							return a.money - b.money
						})
						if (data) res.data.money = data[0].money
						that.$set(that, `info`, res.data);
						that.$set(that, `fileList`, res.data.file);
					}
				}

			},
			onClick(e) {
				uni.showToast({
					title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			buttonClick(e) {
				console.log(e)
			}
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			position: relative;
			flex-grow: 1;

			.one_1 {
				border-bottom: 0.5vw solid var(--f9Color);

				swiper {
					height: 44vh !important;
				}

				.list {
					border-radius: 5px;

					.image {
						width: 100%;
						height: 100%;
						border-radius: 5px;
						background-color: #fff;
					}
				}
			}

			.one_2 {
				border-bottom: 0.5vw solid var(--f9Color);
				padding: 2vw;

				.money {
					font-size: 20px;
					padding: 0 1vw 0 0;
					color: var(--fF0Color);
					font-weight: bold;

					text {
						font-size: 14px;
					}
				}
			}

			.one_3 {
				display: flex;
				flex-wrap: wrap;
				padding: 1vw;
				border-bottom: 0.5vw solid var(--f9Color);
			}


			.one_4 {
				border-bottom: 0.5vw solid var(--f9Color);
				padding: 2vw;

				.name {
					width: 100%;
					overflow: hidden;
					text-overflow: ellipsis;
					word-break: break-all;
					font-size: 17px;
					font-weight: bold;
					margin: 0 0 2vw 0;
				}

				.brief {
					font-size: 14px;
					color: var(--f85Color);
					margin: 0 0 1vw 0;
				}
			}

			.one_5 {
				text-align: center;
				margin: 0 0 15vw 0;

				.list {

					.image {
						border-radius: 5px;
						background-color: #fff;
					}
				}
			}
		}

		.bottom {
			width: 100vw;
			position: fixed;
			bottom: 0;
			left: var(--window-left);
			right: var(--window-right);
		}
	}

	.scroll-view {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.list-scroll-view {
			display: flex;
			flex-direction: column;
		}
	}
</style>
