<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="initclubList()"
							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="(shop, index) in shopDataList"
							:key="index"
							class="list"
							@click.stop="checkedCoupon(index)"
						>
							<view class="list-cell-ri">
								<view class="list-name">
									{{ shop.shopName }}
								</view>
								<view class="list-ntel">
									<text class="list-link">{{ shop.linkMan ? shop.linkMan : '' }}</text>
									<text class="list-texl">{{ shop.contractMobile ? shop.contractMobile : '' }}</text>
								</view>
							</view>
							<view class="list-cell-btn">
								<view
									class="checkbox iconfont"
									:class="[shop.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="hidePopup">确定</view> </view>
				</view>
			</view>
		</tui-bottom-popup>
	</view>
</template>

<script>
export default {
	name: 'coupon',
	props: {
		newReceiptType:{
			type:Number
		},
		show: {
			type: Boolean,
			default: false
		}
	},
	data() {
		return {
			isIphoneX: this.$store.state.isIphoneX,
			checkedIndex: 0,
			isShowClose: false,
			listQuery: {
				keyWord: '',
				newReceiptType: '',
				pageNum: 1,
				pageSize: 200
			},
			shopDataList: []
		}
	},
	created() {
		console.log('newReceiptType',this.newReceiptType)
		this.initclubList()
	},
	methods: {
		async initclubList() {
			const userInfo = await this.$api.getStorage()
			this.listQuery.newReceiptType = this.newReceiptType
			this.OrderService.orderNoReceiptShopList(this.listQuery)
				.then(response => {
					let data = response.data
					if (data.list && data.list.length > 0) {
						 this.shopDataList = data.list.map((el,index)=>{
							el.ischecked = false
							return el
						})
					}
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		checkedCoupon(idx) {
			// 选择供应商
			this.checkedIndex = idx
			this.shopDataList.forEach((el, index) => {
				if (this.checkedIndex == index) {
					el.ischecked = !el.ischecked
				} else {
					el.ischecked = false
				}
			})
		},
		onShowClose() {
			//输入框失去焦点时触发
			if (this.listQuery.keyWord != '') {
				this.isShowClose = true
			} else {
				this.isShowClose = false
			}
		},
		delInputText() {
			//清除输入框内容
			this.listQuery.keyWord = ''
			this.initclubList()
			this.isShowClose = false
			
		},
		hidePopup() {
			let shopInfo = null
			let checkedData = false
			this.shopDataList.forEach((el, index) => {
				if (el.ischecked) {
					shopInfo = el
					checkedData = true
				}
			})
			if (checkedData) {
				this.$emit('handleChoiceaShop', shopInfo)
			}
			this.$parent.isClubpopupShow = 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: 168rpx;
				box-sizing: border-box;
				padding: 30rpx 0 24rpx 0;
				background-size: cover;
				border-bottom: 1px solid #e1e1e1;
				.list-cell-ri {
					width: 580rpx;
					height: 100%;
					box-sizing: border-box;
					float: left;
					margin-left: 24rpx;
					.list-name {
						width: 100%;
						height: 40rpx;
						float: left;
						line-height: 40rpx;
						text-align: left;
						font-size: $font-size-28;
						color: #333333;
						margin-bottom: 24rpx;
						font-weight: bold;
						.tags {
							display: inline-block;
							width: 60rpx;
							height: 32rpx;
							border-radius: 8rpx;
							background: #f0cb72;
							font-size: $font-size-22;
							color: #4e4539;
							text-align: center;
							line-height: 32rpx;
							margin-left: 20rpx;
							&.sv {
								background: #333333;
								color: #f0cb72;
							}
						}
					}
					.list-ntel {
						width: 100%;
						height: 50rpx;
						float: left;
						line-height: 50rpx;
						text-align: left;
						font-size: $font-size-26;
						color: #666666;
						.list-link {
							display: inline-block;
							float: left;
							margin-right: 40rpx;
						}
						.list-texl {
							display: inline-block;
							float: left;
						}
					}
				}
				.list-cell-btn {
					width: 80rpx;
					height: 100%;
					float: right;
					.checkbox {
						width: 80rpx;
						line-height: 114rpx;
						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: #e15616;
						}
					}
				}
			}
		}
		.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>
