<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>
				<template v-if="dataList.length > 0">
					<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="userClubReportList()"
								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="(report, index) in dataList"
								:key="index"
								class="list clearfix"
								@click.stop="details(report.reportId)"
							>
								<view
									class="list-cell-icon"
									:class="{
										reviewed: report.status == 1,
										approved: report.status == 2,
										failed: report.status == 3
									}"
								>
								</view>
								<view class="list-cell-title">
									<view class="list-cell-h1" v-if="popupType === 1">{{ report.clubName }}</view>
									<view class="list-cell-h1" v-else>{{ report.questionMan }}</view>
									<view class="list-cell-p"> {{ report.addTime }} </view>
								</view>
								<view class="list-cell-content clearfix">
									<view class="tui-remarks-text" v-if="!report.productId">
										<view class="text">
											{{ report.reportText }}
										</view>
									</view>
									<view class="tui-remarks-goods" v-else>
										<view class="goods-image">
											<image :src="report.mainImage" mode=""></image>
										</view>
										<view class="goods-main">
											<view class="name"> {{ report.productName }} </view>
											<view class="shop">{{ report.reportText }}</view>
										</view>
									</view>
									
									<view class="list-cell-btn" @click.stop="checkedCoupon(index)">
										<view
											class="checkbox iconfont"
											:class="[report.ischecked ? 'icon-yixuanze' : 'icon-weixuanze']"
										>
										</view>
									</view>
								</view>
							</view>
						</scroll-view>
					</view>
				</template>
				<template v-else>
					<view class="tui-remarks-empty">
						暂无任何数据，请新建报备~
					</view>
				</template>
				<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 class="tui-flex-1">
						<view class="tui-button-text" @click="handleAddReport">新建报备 ></view>
					</view>
				</view>
			</view>
		</tui-bottom-popup>
	</view>
</template>

<script>
const defaultClubQuery = {
	keyWord: '',
	pageNum: 1,
	pageSize: 200,
	clubId: 0,
	serviceProviderId: 0
}
const defaultVisitQuery = {
	keyWord: '',
	pageNum: 1,
	pageSize: 200,
	questionManId: 0,
}
export default {
	name: 'cmreportpopup',
	props: {
		show: {
			type: Boolean,
			default: false
		},
		popupType:{
			type:Number,
		},
		reportInfo:{
			type:Object,
			default: {}
		}
	},
	data() {
		return {
			isIphoneX: this.$store.state.isIphoneX,
			checkedIndex: 0,
			isShowClose: false,
			listQuery: {},
			
			dataList: [],
		}
	},
	created() {
		if(this.popupType === 1){
			this.listQuery = Object.assign({}, defaultClubQuery)
			this.listQuery.clubId = this.reportInfo.clubId
			this.userClubReportList()
		}else{
			this.listQuery = Object.assign({}, defaultVisitQuery)
			this.listQuery.questionManId = this.reportInfo.questionManId
			this.userReportVisitorList()
		}
		
	},
	methods: {
		async userClubReportList() {// 单个机构报备记录
			const userInfo = await this.$api.getStorage()
			this.listQuery.serviceProviderId = userInfo.serviceProviderId
			this.UserService.userClubReportList(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)
			})
		},
		userReportVisitorList() {// 单个咨询人报备记录
			this.UserService.userReportVisitorList(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)
			})
		},
		details(reportId) {
			this.$api.navigateTo(`/pages/seller/remarks/report-details?type=${this.popupType}&reportId=${reportId}`)
		},
		checkedCoupon(idx) {
			// 选择商品
			this.checkedIndex = idx
			this.dataList.forEach((el, index) => {
				if (this.checkedIndex == index) {
					el.ischecked = !el.ischecked
				} else {
					el.ischecked = false
				}
			})
		},
		handleAddReport(){
			// 跳转新建报备
			this.$parent.isReportpopup = false
			this.$api.navigateTo(`/pages/seller/remarks/report-add?type=${this.popupType}&reportInfo=${JSON.stringify(this.reportInfo)}`)
		},
		onShowClose() {
			//输入框失去焦点时触发
			if (this.listQuery.name != '') {
				this.isShowClose = true
			} else {
				this.isShowClose = false
			}
		},
		delInputText() {
			//清除输入框内容
			this.listQuery.name = ''
			this.isShowClose = false
		},
		hidePopup(){// 隐藏弹窗
			this.$parent.isReportpopup = false
		},
		confirmPopup() {// 确认选择
			let report = null
			let checkedData = false
			this.dataList.forEach((el, index) => {
				if (el.ischecked) {
					report = el
					checkedData = true
				}
			})
			if(!checkedData){
				this.$util.msg('请选择报备~', 2000)
				return
			}
			this.$emit('handleChoiceaReport', report)
			this.$parent.isReportpopup = 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;
	}
	.tui-remarks-empty{
		width: 100%;
		height: 400rpx;
		line-height: 400rpx;
		font-size: 26rpx;
		color: #999999;
		text-align: center;
	}
	.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: 40rpx;
		.tui-popup-scroll {
			width: 100%;
			height: 800rpx;
			.list {
				width: 100%;
				padding-top: 20rpx;
				box-sizing: border-box;
				background-size: cover;
				position: relative;
				border-bottom: 1px solid #e1e1e1;
				.list-cell-icon {
					width: 128rpx;
					height: 128rpx;
					position: absolute;
					top: 30rpx;
					right: 32rpx;
					&.reviewed {
						background: url(https://static.caimei365.com/app/img/icon/icon-verify1@2x.png);
						background-size: cover;
					}
					&.failed {
						background: url(https://static.caimei365.com/app/img/icon/icon-verify2@2x.png);
						background-size: cover;
					}
					&.approved {
						background: url(https://static.caimei365.com/app/img/icon/icon-verify3@2x.png);
						background-size: cover;
					}
				}
				.list-cell-title {
					width: 100%;
					height: auto;
					height: 56rpx;
					line-height: 56rpx;
					box-sizing: border-box;
					.list-cell-h1 {
						float: left;
						width: 50%;
						font-size: $font-size-26;
						color: #333333;
						text-align: left;
						text-overflow: ellipsis;
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						line-clamp: 1;
						-webkit-box-orient: vertical;
					}
					.list-cell-p {
						float: right;
						width: 50%;
						font-size: $font-size-26;
						color: #999999;
						text-align: right;
					}
				}
				.list-cell-content {
					width: 100%;
					box-sizing: border-box;
					.tui-remarks-text {
						width: 570rpx;
						height: 168rpx;
						float: left;
						box-sizing: border-box;
						padding: 20rpx 20rpx 20rpx 0;
						border-radius: 6rpx;
						.text{
							width: 100%;
							height: 100%;
							box-sizing: border-box;
							line-height: 42rpx;
							color: #333333;
							text-overflow: ellipsis;
							overflow: hidden;
							display: -webkit-box;
							-webkit-line-clamp: 3;
							line-clamp: 3;
							-webkit-box-orient: vertical;
							font-size: 26rpx;
						}
					}
					.tui-remarks-goods {
						width: 606rpx;
						height: 168rpx;
						float: left;
						box-sizing: border-box;
						padding: 20rpx 0;
						border-radius: 6rpx;
						.goods-image {
							width: 128rpx;
							height: 128rpx;
							float: left;
							image {
								width: 128rpx;
								height: 128rpx;
								display: block;
								border-radius: 4rpx;
							}
						}
						.goods-main {
							width: 440rpx;
							height: 128rpx;
							box-sizing: border-box;
							padding-left: 24rpx;
							float: left;
							.name {
								width: 100%;
								height: 48rpx;
								box-sizing: border-box;
								line-height: 48rpx;
								color: #333333;
								text-overflow: ellipsis;
								overflow: hidden;
								display: -webkit-box;
								-webkit-line-clamp: 1;
								line-clamp: 1;
								-webkit-box-orient: vertical;
								font-size: 26rpx;
							}
							.shop {
								line-height: 36rpx;
								color: #999999;
								font-size: 26rpx;
								text-overflow: ellipsis;
								overflow: hidden;
								display: -webkit-box;
								-webkit-line-clamp: 2;
								line-clamp: 2;
								-webkit-box-orient: vertical;
								font-size: 24rpx;
							}
						}
					}
					.list-cell-btn {
						width: 80rpx;
						height: 168rpx;
						float: right;
						.checkbox {
							width: 40rpx;
							line-height: 168rpx;
							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-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;
		}
		.tui-button-text{
			width: 600rpx;
			height: 48rpx;
			line-height: 48rpx;
			text-align: center;
			color: #e15616;
			font-size: $font-size-26;
			margin: 0 auto;
			margin-top: 15rpx;
		}
	}
}
</style>
