<template name="coupon">
	<view class="coupon-template">
		<!-- 选择商品 -->
		<tui-bottom-popup :radius="true" :show="show" @close="hidePopup">
			<view class="tui-popup-box clearfix">
				<view class="title">选择商品</view>
				<view class="title-search">
					<view class="search-from name">
						<text class="iconfont icon-iconfonticonfontsousuo1"></text>
						<input
							class="input"
							type="text"
							confirm-type="search"
							v-model="listQuery.keyWord"
							@input="onShowClose"
							@confirm="userReportProductList()"
							placeholder="搜索商品名称"
							maxlength="16"
						/>
						<text class="iconfont icon-shanchu1" v-if="isShowClose" @click="delInputText()"></text>
					</view>
				</view>
				<view class="tui-popup-main coupon">
					<scroll-view class="tui-popup-scroll" scroll-y="true">
						<view
							v-for="(pros, index) in dataList"
							:key="index"
							class="list"
							@click.stop="checkedCoupon(index)"
						>
							<view class="list-cell-le">
								<image
									class="logo"
									:src="pros.image"
									mode=""
								></image>
							</view>
							<view class="list-cell-ri">
								<view class="list-text">{{ pros.name }}</view>
								<view class="list-text small"> <text class="none">供应商：</text>{{ pros.shopName }}</view>
								<view class="list-text red">￥{{ pros.price }}</view>
							</view>
							<view class="list-cell-btn">
								<view
									class="checkbox iconfont"
									:class="[pros.ischecked ? 'icon-yixuanze' : 'icon-weixuanze']"
								>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
				<view class="tui-right-flex tui-popup-btn" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
					<view class="tui-flex-1"> <view class="tui-button" @click="confirmPopup">确定</view> </view>
				</view>
			</view>
		</tui-bottom-popup>
	</view>
</template>

<script>
export default {
	name: 'cmgoodspopup',
	props: {
		show: {
			type: Boolean,
			default: false
		}
	},
	data() {
		return {
			isIphoneX: this.$store.state.isIphoneX,
			checkedIndex: 0,
			isShowClose: false,
			listQuery: {
				keyWord:'',
				pageNum: 1,
				pageSize: 100,
			},
			dataList: []
		}
	},
	created() {
		this.userReportProductList()
	},
	methods: {
		async userReportProductList() {
			this.UserService.userReportProductList(this.listQuery)
			.then(response => {
				let data = response.data
				if (data.results && data.results.length > 0) {
					 this.dataList = data.results.map((el,index)=>{
						el.ischecked = false
						return el
					})
				}
			})
			.catch(error => {
				this.$util.msg(error.msg, 2000)
			})
		},
		checkedCoupon(idx) {
			// 选择商品
			this.checkedIndex = idx
			this.dataList.forEach((el, index) => {
				if (this.checkedIndex == index) {
					el.ischecked = !el.ischecked
				} else {
					el.ischecked = false
				}
			})
		},
		onShowClose() {
			//输入框失去焦点时触发
			if (this.listQuery.name != '') {
				this.isShowClose = true
			} else {
				this.isShowClose = false
			}
		},
		delInputText() {
			//清除输入框内容
			this.listQuery.name = ''
			this.isShowClose = false
		},
		hidePopup(){
			this.$parent.isGoodspopup = false
		},
		confirmPopup() {
			let goods = null
			let checkedData = false
			this.dataList.forEach((el, index) => {
				if (el.ischecked) {
					goods = el
					checkedData = true
				}
			})
			if(!checkedData){
				this.$util.msg('请选择商品~', 2000)
				return
			}
			this.$emit('handleChoiceaGoods', goods)
			this.$parent.isGoodspopup = false
		}
	}
}
</script>

<style lang="scss">
.coupon-template {
	width: 100%;
	height: auto;
	background: #ffffff;
	float: left;
	margin-top: 24rpx;
	.coupon-title {
		width: 702rpx;
		padding: 0 24rpx;
		height: 88rpx;
		line-height: 88rpx;
		position: relative;
		.text {
			font-size: $font-size-28;
			color: $text-color;
		}
		.text-coupon {
			display: inline-block;
			float: right;
			padding-right: 30rpx;
			line-height: 88rpx;
			font-size: 28rpx;
			color: #f94b4b;
		}
		.iconfont {
			width: 50rpx;
			height: 88rpx;
			line-height: 88rpx;
			color: #999999;
			display: block;
			position: absolute;
			right: 0;
			top: 0;
		}
	}
}
.tui-popup-box {
	position: relative;
	box-sizing: border-box;
	min-height: 220rpx;
	padding: 24rpx 32rpx 0 32rpx;
	.title {
		font-size: $font-size-32;
		color: $text-color;
		line-height: 68rpx;
		text-align: center;
		float: left;
		width: 100%;
		height: 68rpx;
		box-sizing: border-box;
		padding: 0 24rpx;
	}
	.title-search {
		width: 100%;
		height: 66rpx;
		background: #ffffff;
		box-sizing: border-box;
		float: left;
		.search-from {
			width: 100%;
			height: 100%;
			background: #f7f7f7;
			border-radius: 32rpx;
			float: left;
			position: relative;
			.input {
				width: 500rpx;
				height: 64rpx;
				float: left;
				line-height: 64rpx;
				color: $text-color;
				font-size: $font-size-24;
			}
			.icon-iconfonticonfontsousuo1 {
				width: 64rpx;
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				display: block;
				font-size: $font-size-38;
				float: left;
				color: #999999;
			}
			.icon-shanchu1 {
				font-size: $font-size-32;
				color: #999999;
				position: absolute;
				width: 64rpx;
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				top: 0;
				right: 0;
				z-index: 10;
			}
		}
	}
	.tui-popup-main {
		width: 100%;
		float: left;
		padding-top: 10rpx;
		.tui-popup-scroll {
			width: 100%;
			height: 800rpx;
			.list {
				width: 100%;
				height: 176rpx;
				box-sizing: border-box;
				padding: 24rpx 0;
				background-size: cover;
				.list-cell-le {
					width: 128rpx;
					height: 100%;
					box-sizing: border-box;
					float: left;
					border: 1px dashed #e1e1e1;
					.logo {
						width: 125rpx;
						height: 125rpx;
						border-radius: 8rpx;
					}
				}
				.list-cell-ri {
					width: 470rpx;
					height: 100%;
					box-sizing: border-box;
					float: left;
					margin-left: 24rpx;
					.list-text{
						width: 100%;
						height: 42rpx;
						float: left;
						line-height: 42rpx;
						text-align: left;
						font-size: $font-size-26;
						color: #333333;
						text-overflow: ellipsis;
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						line-clamp: 1;
						-webkit-box-orient: vertical;
						&.small{
							font-size: 24rpx;
							.none{
								color: #999;
							}
						}
						&.red{
							color: #F94B4B;
						}
					}
				}
				.list-cell-btn {
					width: 40rpx;
					height: 100%;
					float: right;
					.checkbox {
						width: 40rpx;
						line-height: 128rpx;
						float: right;
						box-sizing: border-box;
						text-align: center;
						text-decoration: none;
						-webkit-tap-highlight-color: transparent;
						overflow: hidden;
						font-size: $font-size-34;
						&.icon-weixuanze {
							color: #b2b2b2;
						}
						&.icon-yixuanze {
							color: #FF5B00;
						}
					}
				}
			}
		}
		.tui-popup-coupon {
			width: 100%;
			height: 500rpx;
			box-sizing: border-box;
			padding: 30rpx 20rpx;
			.tui-popup-h1 {
				width: 100%;
				height: 66rpx;
				display: flex;
				align-items: center;
				.tui-popup-text {
					flex: 1;
					height: 66rpx;
					line-height: 66rpx;
					font-size: $font-size-30;
					color: #333333;
					&.red {
						color: #f94b4b;
					}
					&.bold {
						font-weight: bold;
					}
					&.left {
						text-align: left;
					}
					&.right {
						text-align: right;
					}
				}
			}
		}
	}
	.tui-popup-btn {
		width: 100%;
		height: auto;
		float: left;
		margin-top: 24rpx;
		.tui-button {
			width: 100%;
			height: 88rpx;
			background: $btn-confirm;
			line-height: 88rpx;
			text-align: center;
			color: #ffffff;
			font-size: $font-size-28;
			border-radius: 44rpx;
		}
	}
}
</style>
