<template>
	<view class="product-item">
		<view>
			<u-image :src="item.productImage+'?x-oss-process=image/resize,p_30'" height="140px" width="100%"></u-image>
			<view class="back-price" v-if="item.promoRuleValue">返<text>{{item.promoRuleValue}}</text>元</view>
			<view class="product-code ellipsis-one">{{item.productCode}}</view>
		</view>
		<view>
			<view class="product-name ellipsis-two">{{item.productName}}</view>
			<view class="product-guige ellipsis-two">{{item.productOrigCode}}</view>
			<view class="product-button">
				<view class="price-txt">￥<text>{{item.cost}}</text></view>
				<view>
					<u-button v-if="!checked" @click="addToCat(item)" :throttle-time="50" size="mini" type="primary" shape="circle"><u-icon name="plus"></u-icon></u-button>
					<u-button v-else :throttle-time="50" @click="addToCat(item)" size="mini" type="success" shape="circle"><u-icon name="plus"></u-icon>{{item.qty}}</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'productItem',
		props: {
			item: {
				type: Object,
				default: () => ({})
			},
			checked:{
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				
			}
		},
		methods: {
			addToCat(item){
				this.$emit('chooseProduct',item)
			}
		},
	}
</script>

<style lang="less">
.product-item{
	background: #ffffff;
	border-radius: 10upx;
	box-shadow: 1px 1px 3px #EEEEEE;
	height: 100%;
	display: flex;
	flex-direction: column;
	> view{
		&:first-child{
			position: relative;
			overflow: hidden;
			border-bottom: 1px solid #eee;
			.product-code{
				color: #666;
				position: absolute;
				width: 100%;
				left:0;
				bottom:0;
				background: rgba(255,255,255,0.7);
				text-align: center;
			}
		}
		&:last-child{
			padding: 20rpx 20rpx 70rpx 20rpx;
			position: relative;
			flex-grow: 1;
			.product-name{
				font-size: 28rpx;
				font-weight: 900;
				color: #666;
			}
			.product-guige{
				margin: 10rpx 0 20rpx 0;
				color: #2196F3;
				text{
					margin-right: 10rpx;
				}
			}
		}
		.product-button{
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: absolute;
			bottom: 20rpx;
			left: 0;
			width: 100%;
			padding: 0 20rpx;
		}
		.cart-add{
			padding: 6rpx 15rpx;
			border-radius: 30rpx;
			background: #2196F3;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 24rpx;
		}
		.colr-add{
			background: #2196F3;
			padding: 10rpx 20rpx;
		}
		.colr-checks{
			background: #00aa00;
		}
	}
	}
</style>
