<template>
	<mobile-frame>
		<view class="main">
			<view class="one">
				<view class="list" @tap="toView">
					<image class="image" :src="goodsInfo.file&&goodsInfo.file.length>0?goodsInfo.file[0].url:''"
						mode="">
					</image>
					<view class="list_1_1">
						<view class="name">
							{{goodsInfo.name||'暂无'}}
						</view>
						<view class="money">
							<text>￥</text>
							<text>{{specsInfo.sell_money}}</text>
						</view>
						<view class="other">
							<view class="other_1">
								{{goodsInfo.view_num||0}}人浏览
							</view>
							<view class="other_2">
								<text @tap.stop="toDel" class="iconfont icon-del"></text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				query: {},
				user: {},
				// 商品详情
				goodsInfo: {},
				// 规格详情
				specsInfo: {},
			};
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `query`, {
				goods_id: e.goods_id || '6343878989bdcb128d846990',
				specs_id: e.specs_id || '634394bc32c3065a80eb14ad'
			});
		},
		onShow: function() {
			const that = this;
			that.watchLogin();
			that.search();
		},
		methods: {
			// 监听用户是否登录
			watchLogin() {
				const that = this;
				uni.getStorage({
					key: 'token',
					success: function(res) {
						let user = that.$jwt(res.data);
						that.$set(that, `user`, user);
					},
					fail: function(err) {}
				})
			},
			// 查询列表
			async search() {
				const that = this;
				let res;
				res = await that.$api(`/goods/${that.query.goods_id}`, 'GET')
				if (res.errcode == '0') {
					that.$set(that, `goodsInfo`, res.data);
				}
				res = await that.$api(`/goodsSpec/${that.query.specs_id}`, 'GET')
				if (res.errcode == '0') {
					that.$set(that, `specsInfo`, res.data);
				}
			},
		}
	}
</script>

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

		.one {
			.list {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				width: 91vw;
				border: 1px solid var(--f1Color);
				margin: 2vw 2vw 0 2vw;
				padding: 2vw;
				border-radius: 5px;

				.image {
					width: 25vw;
					height: 25vw;
					border-radius: 5px;
					margin: 0 2vw 0 0;
				}

				.list_1_1 {
					display: flex;
					flex-direction: column;
					flex-grow: 1;
					padding: 2vw 0;

					.name {
						font-size: var(--font16Size);
						margin: 0 0 1vw 0;
					}

					.money {
						color: var(--fFB1Color);
						font-size: var(--font14Size);
						margin: 0 0 1vw 0;
					}

					.other {
						display: flex;
						justify-content: space-between;

						.name {
							font-size: var(--font16Size);
							font-weight: bold;
						}

						.other_1 {
							font-size: var(--font14Size);
							color: var(--f85Color);

							text {
								font-weight: bold;
								padding: 0 2vw;
								color: var(--ff0Color);
							}
						}
					}
				}
			}
		}
	}
</style>
