<template>
	<view class="goods_content">
		<view v-if="style_setting.arrange == 1" class="goods_box" :class="dataList.length % style_setting.listType !== 0 ? 'needAfter' : ''" :style="{'background-color': style_setting.bg_color}">
			<view v-for="(item, key) in dataList" :key="key" class="goods_item" :style="width ? {'width':width} : ''">
				<view :class="style_setting.listType === 2 ? 'image_box2' : 'image_box'">
					<image v-if="style_setting.sign_show" class="logo" :style="{'width': style_setting.sign_size*2+'rpx','height': style_setting.sign_size*2+'rpx'}" :src="style_setting.sign_url"></image>
					<image class="goods_img" :src="item.default_image || $noGoodsImg" @click="$jumpGoodDetail(item.goods_id)"></image>
				</view>
				<text class="goods_name" v-if="style_setting.title_show">{{item.goods_name}}</text>
				<text class="goods_sub_name" v-if="style_setting.sub_title_show">{{item.goods_subname || ' '}}</text>
				<view class="goods_price">
					<text v-if="style_setting.price_show">¥{{item.price}}</text>
					<i v-if="style_setting.cart_show" @click="$addCart(item.spec_id)"></i>
				</view>
			</view>
		</view>
		
		<swiper v-else indicator-dots="true" class="swiper_content">
			<swiper-item v-for="(val, index) in dataList" :key="index" class="goods_box2" :class="val.length < style_setting.listType ? 'needAfter' : ''">
				<view v-for="(item, key) in val" :key="key" class="goods_item" :style="width ? {'width':width} : ''">
					<view :class="style_setting.listType === 2 ? 'image_box2' : 'image_box'">
						<image v-if="style_setting.sign_show" class="logo" :style="{'width': style_setting.sign_size*2+'rpx','height': style_setting.sign_size*2+'rpx'}" :src="style_setting.sign_url"></image>
						<image class="goods_img" :src="item.default_image || $noGoodsImg" @click="$jumpGoodDetail(item.goods_id)"></image>
					</view>
					<text class="goods_name" v-if="style_setting.title_show">{{item.goods_name}}</text>
					<text class="goods_sub_name" v-if="style_setting.sub_title_show">{{item.goods_subname || ' '}}</text>
					<view class="goods_price">
						<text v-if="style_setting.price_show">¥{{item.price}}</text>
						<i v-if="style_setting.cart_show" @click="$addCart(item.spec_id)"></i>
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		props: {
			wrapper_props: {
				type: Object
			}
		},
		data() {
			return {
				dataList: [],
				style_setting: this.wrapper_props.style_setting,
				width: ''
			}
		},
		mounted() {
			const { listType, arrange, goods_data_type } = this.style_setting;
			const { goods_list, cate_goods_list } =this.wrapper_props;
			if(listType == 2) {
				this.width = '320rpx';
			} else if (listType == 3 ) {
				this.width = '210rpx';
			} else {
				this.width = '150rpx';
			}
			let list = [];
			if(goods_data_type === 3) {
				list = goods_list;
			} else {
				list = cate_goods_list.concat(goods_list)
			}
			this.dataList = list;
			if(arrange == 2) {
				let array = [];
				for (var i = 0, j = list.length; i < j; i += listType) {
				    array.push(list.slice(i, i + listType));
				}
				this.dataList = array;
			}
		}
	}
</script>

<style lang="less" scoped>
	.swiper_content {
		height: 320rpx;
		width: 702rpx;
		margin: 0 auto;
		padding: 24rpx;
		box-sizing: border-box;
	}
	.goods_box, .goods_box2 {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		width: 702rpx;
		margin: 0 auto;
		padding: 24rpx;
		box-sizing: border-box;
		.goods_item {
			margin-bottom: 20rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
		}
	}
	.needAfter::after {
		// content: '';
		flex: auto;
	}
	.image_box, .image_box2 {
		width: 160rpx;
		height: 160rpx;
		position: relative;
		margin-bottom: 8rpx;
		.logo {
			position: absolute;
			left: 0;
			top: 0;
			z-index: 2;
		}
		.goods_img {
			width: 100%;
			height: 100%;
		}
	}
	.image_box2 {
		width:320rpx;
		height: 320rpx;
	}
	.goods_name {
		font-size: 22rpx;
		color: #212121;
		font-weight: 500;
		display: block;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		height: 32rpx;
		line-height: 32rpx;
		margin-bottom: 6rpx;
		width: 90%;
	}
	.goods_sub_name {
		font-size: 22rpx;
		color: #6e6e6e;
		display: block;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 90%;
	}
	.goods_price {
		width: 90%;
		position: relative;
		top: -4rpx;
		height: 40rpx;
		line-height: 40rpx;
		display: flex;
		justify-content: space-between;
		text {
			font-size: 24rpx;
			color: #c3a070;
		}
		i {
			display: inline-block;
			width: 40rpx;
			height: 40rpx;
			background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADgAAAA4CAAAAACN7WTCAAABfElEQVRIx2P4TyZgGNU4qnFUIxEafx87+eYvORqvVFRUbiTLxstTSktW/yHHj7/2FRa9ICtw/kzM2wa2/MTmzZs2gTAEbL3yi0Co7sye/A9IfcpGBVlZU/7i1/g4o/gryObzEJtgdm4uyliDX+PXgpQn2Ly0LaUNv8Z/PYl7sGlcnTiRQMpZETsXm8aJccsJaDwTXfULU9/3ouiDBDS+j4z5jKnxU3T4IwIaf+SFXMXUeCsk+jOh3NEfuBpT4+bAwl+ENK7x68bUOMOvl2B+vOmd8h1d7F+F9xKCGj/5e75DF/sc6X6MoMbfOS7oiv6/dnF5SbjomODYhV4O7HIM+ExY4z5b+1lr1gPBurVr16xZs3rVipnetpV/CWv8XmiFAbzuElPKfd4wpb8PCPr7+yeAwMRJK14Mt5L822ZQmJ6FhOOHTSDOub/EaFwVCwYfwJxFYHbcR2I03stJTk5OgqaC6xkgTjdRNv7//R0I/sEKaWTOaI08qnHoaQQAAyi97TBEkioAAAAASUVORK5CYII=) no-repeat;
			background-size: 100% 100%;
		}
	}
</style>