<template>
	<view class="goods" :style="{height:getGoodsHeight + 'rpx!important'}">
		<view class="top">
			<h3>商品列表</h3>
			<u-search placeholder="搜索" v-model="keyword" :showAction="false"></u-search>
		</view>
		<view class="goodsBox">
			<view class="left">
				<view class="a1">111</view>
				<view class="a2">222</view>
			</view>
			<view class="right">
				<view class="goodsLi" v-for="(item,index) in goodsList" :key="index" @click="activeGoods(item)"
					:class="activeList.some(i => i.goodsId === item.goodsId)?'activeGoodsLi':''">
					<view class="title">
						{{item.goodsName}}
					</view>
					<view class="priceA">
						￥{{item.priceB}} + {{item.internage}}积分
					</view>
					<view class="priceB">
						原价：<text>{{item.priceA}}元</text>
					</view>
					<img v-if="activeList.some(i => i.goodsId === item.goodsId)" class="icon"
						src="@/static/images/icon_gx@2x.png" alt="">
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from "vuex"
	export default {
		data() {
			return {
				keyword: "",
				goodsList: [{
					goodsId: 1,
					goodsName: "A鲁花花生油鲁花花生油鲁花花生油花生油",
					priceA: 2200.58,
					priceB: 2045.99,
					internage: 200,
				}, {
					goodsId: 2,
					goodsName: "B鲁花花生油鲁花花生油鲁花花生油花生油",
					priceA: 2200.58,
					priceB: 2045.99,
					internage: 200,
				}, {
					goodsId: 3,
					goodsName: "C鲁花花生油鲁花花生油鲁花花生油花生油",
					priceA: 2200.58,
					priceB: 2045.99,
					internage: 200,
				}],
				activeList: [],
			}
		},
		computed: {
			...mapGetters(['getGoodsHeight'])
		},
		onLoad() {
			console.log()
		},
		methods: {
			activeGoods(row) {
				const CheckExistInt = this.activeList.findIndex(i => i.goodsId === row.goodsId)
				if (CheckExistInt === -1) {
					this.activeList.push(row)
				} else {
					this.activeList.splice(CheckExistInt, 1)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goods {
		border-top-left-radius: 32rpx;
		border-top-right-radius: 32rpx;
		background-color: #fff;
		margin-top: -52rpx;
		display: flex;
		flex-direction: column;

		&>.top {
			height: 144rpx;
			padding: 32rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			&>h3 {
				font-weight: bold;
				color: #222;
				font-size: 32rpx;
				margin-right: 50rpx;
			}
		}

		&>.goodsBox {
			flex: 1;
			height: 1px;
			display: flex;

			&>.left {
				overflow: auto;
				width: 192rpx;
				height: 100%;
				background-color: #a4a4a4;
				flex-shrink: 0;

				&>.a1 {
					height: 600rpx;
					background-color: red;
				}

				&>.a2 {
					height: 600rpx;
					background-color: skyblue;
				}
			}

			&>.right {
				overflow: auto;
				margin: 0rpx 24rpx 0rpx 40rpx;
				height: 100%;
				flex: 1;

				&>.activeGoodsLi {
					border: 2rpx solid #F57737 !important;
				}

				&>.goodsLi {
					position: relative;
					padding: 28rpx 36rpx 32rpx 28rpx;
					background-color: #F9F9F9;
					border-radius: 28rpx;
					overflow: hidden;
					margin-bottom: 32rpx;
					border: 2rpx solid transparent;

					&>.icon {
						width: 32rpx;
						height: 32rpx;
						position: absolute;
						bottom: 0;
						right: 0;
					}

					&>.title {
						margin-bottom: 24rpx;
						color: #222;
						font-size: 28rpx;
						font-weight: 500;
						overflow: hidden;
						-webkit-line-clamp: 1;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;

					}

					&>.priceA {
						flex: 1;
						color: #EB5757;
						font-weight: bold;
						font-size: 32rpx;
						margin-bottom: 8rpx;
					}

					&>.priceB {
						flex: 1;
						font-size: 24rpx;
						color: #828282;

						&>text {
							text-decoration: line-through;
						}
					}
				}
			}
		}
	}
</style>
