<template>
	<block>
		<view class="choose-product-item"
		v-for="(item, dix) in list"
		:key="item.id" 
		>
			<view class="choose-product-item-check" @click="checkItem(item.id)">
				<image style="width: 24px;height: 24px;" mode="aspectFill" :src="'../static/'+(item.checked?'round_check_fill':'round')+'.png'"></image>
			</view>
			 <view>
				 <view class="choose-product-item-img">
					<image mode="aspectFit" :src="item.productImage+'?x-oss-process=image/resize,p_30'" style="width: 100%;height: 180rpx;"></image>
					<!-- <view class="back-price" v-if="item.promoRuleValue">返<text>{{item.promoRuleValue}}</text>元</view> -->
					<view class="choose-product-item-left-info-code ellipsis-one">{{item.productCode}}</view>
				 </view>
				 <view class="choose-product-item-info">
					<view class="choose-product-item-left-info-name ellipsis-two">{{item.productName}}</view>
					<view class="choose-product-item-left-info-guige">
						<text class="ellipsis-two" max-lines="2" overflow="ellipsis">{{item.productOrigCode}}</text>
					</view>
					<view class="choose-product-item-left-info-price">
						<view class="price-txt">￥<text>{{item.cost}}</text></view>
						<view>
							<view :style="{opacity:!item.edit?1:0,width:!item.edit?'auto':0}">
								<view class="flex align_center qty-box">
									<view class="qty-btn" @click="changeQty(item.qty-1,item.id,1)" :class="(item.qty <= 1)?'qty-disabled':''">-</view>
									<view class="qty-num"><input type="number" @blur="changeQty(item.qty,item.id,0)" v-model="item.qty"/></view>
									<view class="qty-btn" @click="changeQty(item.qty+1,item.id,1)" :class="(item.qty >= 999999)?'qty-disabled':''">+</view>
								</view>
							</view>
							<view v-if="item.edit" class="edit-qty">
								X <text>{{item.qty}}</text>
								<image style="width: 24px;height: 24px;" mode="aspectFill" :src="'../static/ashbin.png'" @click="remove(item.id)"></image>
							</view>
						</view>
					</view>
				 </view>
			 </view>
		</view>
	</block>
</template>

<script>
	export default {
		name: 'productItem',
		props: {
			index: {
				type: Number,
				default: 0
			},
			list: {
				type: Array,
				default: () => []
			},
		},
		data() {
			return {
			}
		},
		methods: {
			changeQty(e, id) {
				if(e<=0 || e>=999999){
					return
				}
				this.$emit('changeQty', e, id)
			},
			remove(id){
				this.$emit('remove', id, false)
			},
			checkItem(id){
				this.$emit('check',id)
			}
		}
	}
</script>

<style lang="less" scoped>
	.qty-box{
		display: flex;
		.qty-btn{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 22px;
			height: 22px;
			border-radius: 50px;
			font-size: 18px;
			background-color: #066cff;
			color: #fff;
			&.qty-disabled{
				background-color: #c0c0c0;
			}
		}
		.qty-num{
			width: 30px;
			height: 22px;
			line-height: 22px;
			padding:0 3px;
			input{
				width: 100%;
				height: 100%;
				text-align: center;
				color: #333;
			}
		}
	}
	.choose-product-item{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10px;
		background: #fff;
		margin: 8px 8px 0 8px;
		border-radius: 10px;
		.price-txt{
			color: red;
			display: flex;
			align-items: center;
			text{
				font-size: 36rpx;
			}
		}
		> view{
			 display: flex;
			 align-items: center;
			 justify-content: space-between;
			 &:last-child{
				 flex-grow: 1;
				 width: 80%;
			 }
		}
		.choose-product-item-check{
			padding: 0 20rpx 0 0;
			width: 24px;
		}
		.choose-product-item-img{
			margin-right: 20rpx;
			width: 30%;
			position: relative;
			overflow: hidden;
			border: 1px solid #eee;
			padding: 10rpx;
			.back-price{
				zoom: calc(0.8);
				padding: 6rpx 65rpx;
				background: rgba(255 ,87 ,34 , 1);
				position: absolute;
				top: 18rpx;
				right: -45rpx;
				color: #fff;
				z-index: 2;
				font-size: 20rpx;
				text-align: center;
				transform: rotate(40deg);
				display: flex;
				align-items: center;
				text{
					font-size: 28rpx;
					margin: 0 5rpx;
				}
			}
			.choose-product-item-left-info-code{
				color: #666;
				position: absolute;
				width: 100%;
				left:0;
				bottom:0;
				background: rgba(255,255,255,0.7);
				text-align: center;
			}
		}
		.choose-product-item-info{
			width: 70%;
			flex-grow: 1;
			.choose-product-item-left-info-price{
				display: flex;
				align-items:center;
				justify-content: space-between;
				>view{
					&:last-child{
						display: flex;
						align-items:center;
					}
				}
				.edit-qty{
					display: flex;
					align-items:center;
					justify-content: space-between;
					color: #999;
					font-size: 12px;
					> text{
						color: #666;
						font-size: 14px;
						margin-right: 20px;
					}
				}
			}
			.choose-product-item-left-info-name{
				font-size: 28rpx;
				color: #666;
			}
			.choose-product-item-left-info-guige{
				color: #2196F3;
				margin: 10rpx 0;
				text{
					margin-right: 10rpx;
				}
			}
		}
	}
</style>