<template>
	<view
		class="her-scoller"
		:style="{
			'background-color': goodsInfo.backgroundColor,
			'background-image': goodsInfo.backgroundPicUrl,
			'border-color': goodsInfo.goodsStyle == 2 ? 'rgb(226, 226, 226)' : ''
		}"
	>
		<view
			class="good-five"
			@click="openGood(item)"
			v-for="(item, gli) in goodList"
			:key="gli"
			:style="{
				border: goodsInfo.goodsStyle == 2 ? '1px solid rgb(226, 226, 226)' : '',
				background: goodsInfo.goodsStyle == 1 || goodsInfo.goodsStyle == 2 ? '#FFF' : ''
			}"
		>
			<view class="tips" v-if="goodsInfo.showGoodsTag"><image :src="goodsInfo.goodsTagPicUrl" mode="widthFix" style="width:100%" /></view>
			<view class="img-box">
				<view class="img-show">
					<image style="width: 100%; height: 100%; border-radius: 10rpx 10rpx 0 0;" :mode="goodsInfo.fill == 1 ? 'aspectFill' : 'aspectFit'" :src="item.picUrl" />
				</view>
			</view>
			<view class="good-info">
				<view class="good-name" v-if="goodsInfo.showGoodsName">{{ item.name }}</view>
				<view class="good-price-info">
					<view class="price" :style="{ color: mainColor }">
						<span>
							{{ goodsInfo.showGoodsPrice ? getPrice(item.price) : '' }}
						</span>
						<span style='text-decoration: line-through;font-size: 10px;color: gray;font-family: aa;'>原价:{{goodsInfo.showGoodsPrice ? getPrice(item.OriginalPrice) : ''}}</span>
					</view>
					<view class="buy" v-if="goodsInfo.showBuyBtn" @click.stop="showSkuHandler(item)">
						<u-icon name="cart-o" size="40" :color="mainColor" v-if="goodsInfo.buyBtn == 'cart'" />
						<u-icon name="add-o" size="40" :color="mainColor" v-else-if="goodsInfo.buyBtn == 'add'" />
						<u-button
							type="primary"
							size="mini"
							:ripple="true"
							:color="goodsInfo.buttonColor"
							:custom-style="
								`backgroundColor:${goodsInfo.buttonColor},color:${goodsInfo.buyBtnStyle == 2 || goodsInfo.buyBtnStyle == 4 ? goodsInfo.buttonColor : '#FFF'}`
							"
							:plain="goodsInfo.buyBtnStyle == 2 || goodsInfo.buyBtnStyle == 4"
							:shape="goodsInfo.buyBtnStyle == 3 || goodsInfo.buyBtnStyle == 4 ? 'circle' : 'square'"
							v-else
						>
							{{ goodsInfo.buyBtnText }}
						</u-button>
					</view>
				</view>
			</view>
		</view>
		<good-sku v-if="showSku" :option-type="2" borderRadius="20" v-model="showSku" :good="sku"></good-sku>
		<auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth="gbAuth"></auth>
	</view>
</template>
<script>
import goodSku from '../goods/goodsku';
import auth from '@/components/auth/index.vue';
export default {
	components: {
		goodSku,
		auth
	},
	props: ['goodList', 'goodsInfo'],
	data() {
		return {
			mainColor: '',
			activeKey: 0,
			showSku: false,
			sku: {},
			showAuth: false,
			u: {}
		};
	},
	created() {
		this.mainColor = this.$uiConfig.mainColor;
	},
	methods: {
		openGood(item) {
			uni.navigateTo({ url: '/pages/goods/goods?GoodsId=' + item.id });
		},
		showSkuHandler(g) {
			this.sku = g;
			this.u = uni.getStorageSync('mall_UserInfo');
			if (!this.u) {
				this.u = {
					nickName: '未登录',
					avatarUrl: ''
				};
				this.showAuth = true;
			} else {
				this.showSku = true;
			}
		},
		reloadUserinfo() {
			this.u = uni.getStorageSync('mall_UserInfo');
			// this.showAuth = false;
		},
		//关闭登录窗口
		gbAuth() {
			this.showAuth = false;
		}
	}
};
</script>

<style>
.her-scoller {
	overflow-x: auto !important;
	padding: 12px;
	/* display: flex; */
	white-space: nowrap;
}
/* .her-scoller::after {
  clear: both;
  content: " ";
  display: block;
} */
.her-scoller .good-five {
	position: relative;
	margin-right: 12px;
	width: 30%;
	border: 1rpx solid transparent;
	border-radius: 10rpx;
	padding-bottom: 10rpx;
	display:inline-block;
	/* float: left; */
}
.her-scoller .good-five .tips {
	width: 64rpx;
	height: 64rpx;
	position: absolute;
	top: 0;
	left: 0;
	z-index: 4;
}
.her-scoller .good-five .img-box {
	width: 100%;
	height: 0;
	padding-top: 100%;
	position: relative;
}
.her-scoller .good-five .img-box .img-show {
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	z-index: 2;
}
.her-scoller .good-five .guding {
	position: relative;
}
.her-scoller .good-five .guding .img-box {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	top: 0;
}
.her-scoller .good-five .good-info {
	padding: 6rpx;
	padding-bottom: 0;
}
.her-scoller .good-five .good-info .good-name {
	overflow: hidden;
	text-overflow: ellipsis;
	display: block;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	margin-bottom: 4rpx;
	font-size: 13px;
	width: 100%;
}
.her-scoller .good-five .good-info .good-price-info {
	display: flex;
	justify-items: center;
	align-items: center;
}
.her-scoller .good-five .good-info .good-price-info .price {
	color: #ff4544;
	flex: 1;
	font-size: 14px;
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}
.her-scoller .good-five .good-info .good-price-info .buy {
	width: 24px;
	text-align: right;
}
</style>
