<template>
	<view class="container product clearfix">
		<view class="club-search clearfix">
			<view class="club-search-form">
				<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="userReportVisitorRemarks"
						placeholder="搜索商品名称 / 报备关键词"
						maxlength="16"
					/>
					<text class="iconfont icon-shanchu1" v-if="isShowClose" @click="delInputText()"></text>
				</view>
			</view>
		</view>
		<view class="remarks-content" :style="{ paddingBottom: isIphoneX ? '220rpx' : '148rpx' }">
			<view :class="{ 'tui-order-list': scrollTop >= 0 }" class="clearfix">
				<!-- 空白页 -->
				<view class="empty-container" v-if="isEmpty">
					<image class="empty-container-image" :src="StaticUrl + '/icon/icon-remarks-empty@2x.png'"></image>
					<text class="error-text">暂无任何记录~</text>
				</view>
				<template v-else>
					<!-- 列表 -->
					<view
						class="tui-remarks-cell  tui-mtop clearfix"
						v-for="(report, index) in reportList"
						:key="index"
						@click.stop="details(report.reportId)"
					>
						<view class="tui-remarks-title">
							<view class="tui-remarks-title-top">
								<view class="tui-remarks-time tt">{{ report.questionMan }}</view>
							</view>
							<view class="tui-remarks-title-bot">
								<view class="tui-remarks-text-view">
									<view class="tui-remarks-text h"></text>报备人：{{ report.reportName }}</view>
									<view class="tui-remarks-text y">
										{{ report.addTime }}
									</view>
								</view>
							</view>
							<view class="tui-remarks-title-icon" :class="{
										reviewed: report.status == 1,
										approved: report.status == 2,
										failed: report.status == 3
									}">
							</view>
						</view> 
						<view class="tui-remarks-content">
							<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>
						<view class="tui-remarks-button" v-if="report.serviceProviderId === listQuery.serviceProviderId" >
							<view class="btn edit" @click.stop="handReportDetails(report.reportId)">查看关联咨询记录</view>
							<view class="btn del" @click.stop="deleteReport(report.reportId)"> 删除</view>
						</view>
						<view class="tui-remarks-button" v-else>
							<view class="btn none" @click.stop="handReportDetails(report.reportId)">查看关联咨询记录</view>
						</view>
					</view>
					<!--加载loadding-->
					<tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
					<tui-nomore :visible="!pullUpOn" :backgroundColor="'#F7F7F7'" :text="nomoreText"></tui-nomore>
					<!--加载loadding-->
				</template>
			</view>
		</view>
		<!-- 弹窗提示 -->
		<tui-modal
			:show="modal"
			@click="handleClick"
			@cancel="hideMobel"
			:content="contentModalText"
			:button="modalButton"
			color="#333"
			:size="32"
			shape="circle"
			:maskClosable="false"
		>
		</tui-modal>
	</view>
</template>
<script>
import { mapState, mapMutations } from 'vuex'

const defaultListQuery = {
	manager:0,
	keyWord:'',
	serviceProviderId: 0,
	pageNum: 1,
	pageSize: 10
}
export default {
	data() {
		return {
			StaticUrl: this.$Static,
			isIphoneX: this.$store.state.isIphoneX,
			modalButton: [
				{
					text: '取消',
					type: 'gray',
					plain: true //是否空心
				},
				{
					text: '确认',
					customStyle: {
						color: '#fff',
						bgColor: 'linear-gradient(90deg, #F28F31 0%, #E15616 100%)'
					},
					plain: false
				}
			],
			totalRecord: 0,
			listQuery: Object.assign({}, defaultListQuery),
			reportList: [],
			scrollTop: 0,
			isEmpty: false,
			loadding: false,
			pullUpOn: true,
			pullFlag: true,
			hasNextPage: false,
			navbarHeight: '',
			nomoreText: '上拉显示更多',
			contentModalText: '', //操作文字提示语句
			modal: false,
			questionMan: '',
			questionManId: '',
			handleReportId: 0,
		}
	},
	onLoad(option) {
		
	},
	computed: {
		...mapState(['hasLogin', 'userInfo'])
	},
	methods: {
		...mapMutations(['login', 'logout']),
		async initGetlist() {
			const userInfo = await this.$api.getStorage()
			this.listQuery.serviceProviderId = userInfo.serviceProviderId ? userInfo.serviceProviderId : 0
			this.listQuery.manager = userInfo.manager ? userInfo.manager : 0
			this.userReportVisitorRemarks()
		},
		userReportVisitorRemarks() {
			this.reportList = []
			this.listQuery.pageNum = 1
			this.UserService.userReportVisitorRemarks(this.listQuery)
				.then(response => {
					let data = response.data
					if (data.results && data.results.length > 0) {
						this.isEmpty = false
						this.hasNextPage = data.hasNextPage
						this.totalRecord = data.totalRecord
						this.reportList = data.results
						this.pullFlag = false
						setTimeout(() => {
							this.pullFlag = true
						}, 500)
						if (this.hasNextPage) {
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						} else {
							if (this.reportList.length < 8) {
								this.pullUpOn = true
							} else {
								this.pullUpOn = false
								this.loadding = false
								this.nomoreText = '已至底部'
							}
						}
					} else {
						this.isEmpty = true
					}
					this.isRequest = true
				})
				.catch(error => {
					console.log('=======>查询列表异常~')
				})
		},
		GetOnReachBottomData(index) {
			//上拉加载
			this.listQuery.pageNum += 1
			this.UserService.userReportVisitorRemarks(this.listQuery)
				.then(response => {
					let data = response.data
					if (data.results && data.results.length > 0) {
						this.hasNextPage = data.hasNextPage
						this.reportList = this.reportList.concat(data.results)
						this.pullFlag = false // 防上拉暴滑
						setTimeout(() => {
							this.pullFlag = true
						}, 500)
						if (this.hasNextPage) {
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						} else {
							this.pullUpOn = false
							this.loadding = false
							this.nomoreText = '已至底部'
						}
					}
				})
				.catch(error => {
					console.log('=======>查询列表异常~')
				})
		},
		deleteReport(reportId) {
			this.handleReportId = reportId
			this.modal = true
			this.contentModalText = '确定删除该报备吗？'
		},
		handReportDetails(reportId) {
			//跳转报备关联记录
			this.$api.navigateTo(`/pages/seller/remarks/relation-visitor-list?reportId=${reportId}`)
		},
		handSearchConfirmData(data){
			//确定筛选
			this.listQuery.startAddTime = data.startAddTime
			this.listQuery.endAddTime = data.endAddTime
			this.listQuery.consult = data.consult
			this.listQuery.leaderId = data.leaderId
			this.listQuery.groupId = data.groupId
			this.listQuery.pinceSensitve = data.pinceSensitve
			this.listQuery.satisfied = data.satisfied
			this.listQuery.followup = data.followup
			console.log('确定筛选',this.listQuery)
			this.userReportVisitorRemarks()
		},
		handleClick(e) {
			//取消收藏
			if (e.index == 1) {
				this.handleDeleteUserLike()
			}
			this.modal = false
		},
		handleDeleteUserLike() {
			//操作删除资料备注
			this.UserService.userClubReportDelete({
				reportId: this.handleReportId
			})
				.then(response => {
					this.$util.msg('已删除', 2000, true, 'success')
					setTimeout(() => {
						this.userReportVisitorRemarks()
					}, 2000)
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		onShowClose() {
			//输入框失去焦点时触发
			if (this.listQuery.keyWord != '') {
				this.isShowClose = true
			} else {
				this.isShowClose = false
				this.listQuery.pageNum = 1
				this.userReportVisitorRemarks()
			}
		},
		delInputText() {
			//清除输入框内容
			this.listQuery.keyWord = ''
			this.isShowClose = false
			this.listQuery.pageNum = 1
			this.userReportVisitorRemarks()
		},
		hideMobel() {
			this.modal = false
		},
		details(reportId) {
			this.$api.navigateTo(`/pages/seller/remarks/report-details?reportId=${reportId}`)
		}
	},
	onPageScroll(e) {
		//实时获取到滚动的值
	},
	onReachBottom() {
		if (this.hasNextPage) {
			this.loadding = true
			this.pullUpOn = true
			this.GetOnReachBottomData()
		}
	},
	onPullDownRefresh() {
		setTimeout(() => {
			this.listQuery.pageNum = 1
			uni.stopPullDownRefresh()
		}, 200)
	},
	
	onShow() {
		this.initGetlist()
	}
}
</script>

<style lang="scss">
@import '@/uni.scss';
page {
	background: #f7f7f7;
}
.empty-container {
	z-index: 99;
}
.club-search {
	width: 100%;
	height: 112rpx;
	background: #ffffff;
	box-sizing: border-box;
	position: fixed;
	top: 0;
	left: 0;
	z-index: 100;
	.club-search-form {
		width: 100%;
		height: 112rpx;
		background: #ffffff;
		box-sizing: border-box;
		padding: 24rpx;
		float: left;
		.search-from {
			width: 100%;
			height: 100%;
			background: #f7f7f7;
			border-radius: 32rpx;
			float: left;
			position: relative;
			.input {
				width: 600rpx;
				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;
			}
		}
	}
}
.remarks-content {
	width: 100%;
	height: auto;
	position: relative;
	padding: 0;
	box-sizing: border-box;
	padding: 24rpx;
	padding-top: 134rpx;
	.empty-container-image {
		width: 260rpx;
		height: 260rpx;
		margin-top: -300rpx;
	}
	.tui-remarks-cell {
		width: 100%;
		border-radius: 16rpx;
		margin-bottom: 24rpx;
		background: #FFFFFF;
		box-sizing: border-box;
		padding:0 24rpx 24rpx 24rpx;
		.tui-remarks-title {
			width: 100%;
			height: auto;
			box-sizing: border-box;
			padding: 20rpx 0;
			position: relative;
			.tui-remarks-title-icon{
				width: 128rpx;
				height: 128rpx;
				position: absolute;
				top: 0;
				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;
				}
			}
			.tui-remarks-title-top {
				width: 100%;
				height: 56rpx;
				line-height: 56rpx;
				.tui-remarks-time {
					float: left;
					&.tt {
						width: 70%;
						font-size: $font-size-32;
						color: #333333;
						text-align: left;
						text-overflow: ellipsis;
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						line-clamp: 1;
						-webkit-box-orient: vertical;
						font-weight: bold;
						.tags{
							display: inline-block;
							padding: 0 10rpx;
							border-radius: 8rpx;
							line-height: 36rpx;
							font-size: 22rpx;
							background-color: #F94B4B;
							color: #ffffff;
							text-align: center;
							float: left;
							margin-right: 10rpx;
							margin-top: 10rpx;
							font-weight: normal;
						}
					}
				}
			}
			.tui-remarks-title-bot {
				width: 100%;
				height: auto;
				.tui-remarks-text-view{
					width: 100%;
					height: 48rpx;
					.tui-remarks-text {
						width: 50%;
						height: 48rpx;
						line-height: 48rpx;
						box-sizing: border-box;
						text-align: left;
						font-size: $font-size-26;
						color: #999999;
						float: left;
						text-overflow: ellipsis;
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						line-clamp: 1;
						-webkit-box-orient: vertical;
						&.a{
							width: 100%;
						}
						&.y {
							text-align: right;
						}
					}
				}
			}
		}
		.tui-remarks-content {
			width: 100%;
			height: auto;
			box-sizing: border-box;
			padding-bottom: 32rpx;
			.tui-remarks-text{
				width: 100%;
				height: 180rpx;
				box-sizing: border-box;
				background-color: #F7F7F7;
				padding: 26rpx;
				border-radius: 6rpx;
				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: 30rpx;
			}
			.tui-remarks-goods{
				width: 100%;
				height: 180rpx;
				box-sizing: border-box;
				background-color: #F7F7F7;
				padding: 26rpx;
				border-radius: 6rpx;
				.goods-image{
					width: 128rpx;
					height: 128rpx;
					float: left;
					image{
						width: 128rpx;
						height: 128rpx;
						display: block;
						border-radius: 4rpx;
					}
				}
				.goods-main{
					width: 475rpx;
					height: 128rpx;
					box-sizing: border-box;
					padding-left: 24rpx;
					float: right;
					.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: 26rpx;
					}
				}
			}
		}
		.tui-remarks-button {
			width: 100%;
			height: 68rpx;
			border-top: 1px solid #E1E1E1;
			padding-top: 20rpx;
			.btn {
				width: 50%;
				line-height: 48rpx;
				box-sizing: border-box;
				text-align: center;
				font-size: $font-size-34;
				float: left;
				font-weight: bold;
				&.none{
					width: 100%;
					color: #1890F9;
				}
				&.edit{
					color: #1890F9;
					border-right: 1px solid #E1E1E1;
				}
				&.del{
					color: #F94B4B;
				}
			}
		}
	}
}
.tui-popup-box {
	position: relative;
	box-sizing: border-box;
	min-height: 100rpx;
	padding: 6rpx 24rpx;
	.tui-popup-content {
		padding-top: 30rpx;
	}
}
.tui-popup-btn {
	width: 100%;
	height: auto;
	float: left;
	box-sizing: border-box;
	margin-top: 30rpx;
	.tui-flex-1 {
		width: 100%;
		height: 84rpx;
		display: flex;
		.tui-button {
			flex: 1;
			line-height: 84rpx;
			font-size: $font-size-28;
			text-align: center;
			border-radius: 42rpx;
			padding: 0;
			margin: 0 15rpx;
			box-sizing: border-box;
			&.cancel {
				background: #ffe6dc;
				color: #e15616;
			}
			&.disabled {
				background: #e1e1e1;
				color: #ffffff;
			}
			&.confirm {
				background: $btn-confirm;
				color: #ffffff;
			}
		}
		.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>
