<template>
	<view class="content">
		<view class="topView">
			<!-- 切换tab -->
			<view class="tabBox">
				<scroll-view scroll-x="true" class="scroll">
					<view class="tabCotn">
						<view class="tabLine" :class="{tabactive:tabIndex==0}" @click="tabClick(0)">全部</view>
						<view class="tabLine" :class="{tabactive:tabIndex==1}" @click="tabClick(1)">待提交</view>
						<view class="tabLine" :class="{tabactive:tabIndex==2}" @click="tabClick(2)">待作业</view>
						<view class="tabLine" :class="{tabactive:tabIndex==3}" @click="tabClick(3)">待点评</view>
						<view class="tabLine" :class="{tabactive:tabIndex==4}" @click="tabClick(4)">待回复</view>

					</view>
				</scroll-view>
			</view>


			<!-- 搜索 -->
			<!-- <view class="searchBox">
				<image src="../../static/img/icon_search.png" class="searchImg"></image>
				<input type="text" class="searchInput" placeholder="请输入门店名称、联系人、手机号" v-model="searchValue"
					@confirm="searchDone" />
			</view> -->
			<searchBox placeholder="请输入门店名称、联系人、手机号" @search='search($event)'></searchBox>

			<!-- 条件筛选 -->
			<view class="siftBg">

				<!-- 日期选择 -->
				<view class="timeChose">
					<view @click="timeClick">{{dateTime == null ? '日期筛选' : dateTime}}</view>
					<image class="downArrow" src="../../static/img/icon_downArrow.png"></image>
				</view>



				<picker :value="thirdIndex" mode="selector" :range="thirdArr"
					@change="bindPickerChange3">
					<view class="uni-input">{{thirdIndex == null ? '访问人' : thirdArr[thirdIndex]}}
						<image class="downArrow" src="../../static/img/icon_downArrow.png"></image>
					</view>
				</picker>
			</view>
		</view>
		<!-- 列表 -->
		<view class="shopList">
			<view v-for="(item,index) in shopData" :key="index">

				<!-- shopBox -->
				<view class="shopBox" @click="goAppraise(item)">
					<view class=" shopTop">

						<view class="shopName">{{item.ShopName}}</view>

						<!-- 订单状态 1 待提交 2 待作业 3 待点评 4 待回复 5 已完成 -->
						<view class="type" v-if="item.State == 1">待提交</view>
						<view class="type" v-if="item.State == 2">待作业</view>
						<view class="type" v-if="item.State == 3">待点评</view>
						<view class="type" v-if="item.State == 4">待回复</view>
						<view class="type" v-if="item.State == 5">已完成</view>

					</view>



					<!-- 第2行 -->
					<view class="bottomView">
						<!-- 运营经理 -->
						<view class="manager">{{item.ManagerName}} · {{item.CheckTime.slice(0,item.CheckTime.length-8)}}</view>
						<!-- 评分 -->
						<view class="score" v-if="item.ShopScore">{{item.ShopScore}}分</view>
					</view>


				</view>
			</view>
		</view>

		<!-- 上拉 加载更多 -->
		<view class="noMore" v-if="noMoreShow">没有更多数据</view>
		<!-- 无数据空白页 -->
		<nodata v-if="shopData.length==0"></nodata>

		<timeChose ref="timepop" @returnDate="returnDate" :isShow="timeShow"></timeChose>
		
	</view>
</template>

<script>
	import timeChose from '@/components/timeChose/timeChose.vue'
	import nodata from '../../components/nodata/nodata.vue'
	import searchBox from '@/components/searchBox/searchBox.vue'
	
	export default {
		components: {
			timeChose,
			nodata,
			searchBox
		},
		data() {
			return {
				tabIndex: 0,
				status: '', 
				searchValue: '',
				
				thirdIndex: null,
				thirdArr: ['请选择'],
				managerName: '',
				shopData: [],
				page: 1,
				noMoreShow: false,
				timeShow: false,
				starTime: '',
				endTime: '',
				dateTime: null,
				shopId:'',
			}
		},
		onShow() {
			this.page = 1
			this.getShopData()
		},
		onLoad(opt) {
			this.shopId = opt.shopId
			
			this.getVisitor()

			this.page = 1
			this.getShopData()
		},
		methods: {
			timeClick() {
				
				this.$refs.timepop.father();
			},
			returnDate(e) {
				console.log(e)
				this.starTime = e.startTime
				this.endTime = e.endTime
				if (e.startTime) {
					this.dateTime = e.startTime + '-' + e.endTime
				} else {
					this.dateTime = null
				}

				this.page = 1;
				this.getShopData()
			},
			tabClick(num) {
				this.tabIndex = num;

				if (num == 0) {
					this.status = ''
				} else {
					this.status = num;
				}
				this.page = 1;
				this.getShopData()
			},
			
			search(val){
							// console.log(val);
							this.searchValue = val
							this.page = 1
							this.getShopData()
						},
			
			bindPickerChange3(e) {
				this.thirdIndex = e.target.value
				this.managerName = this.thirdArr[this.thirdIndex]
				if(e.target.value == 0){
					this.thirdIndex = null
					this.managerName = ''
				}
				this.page = 1
				this.getShopData()
			},

			getVisitor() {
				uni.showLoading({
					title: '加载中'
				})
				let url = 'accompany/SuperAccounts/shopCheckManagerHistory',
					params = {
						shopId:this.shopId
					}
				this.$http(url, params, 'GET').then(res => {
					this.thirdArr = this.thirdArr.concat(res.data)
				})
			},
			getShopData() {
				uni.showLoading({
					title: '加载中'
				})
				let url = 'accompany/SuperAccounts/listShopInfoCheckPage',
					params = {
						page: this.page,
						limit: 20,
						managerName: this.managerName,
						shopName: this.searchValue,
						starTime: this.starTime,
						endTime: this.endTime,
						state: this.status,
						shopID:this.shopId,

					}
				this.$http(url, params, 'GET').then(res => {
					var list = res.data.Items

					// 处理 undefined和null转为空白字符串
					list.forEach((item, index) => {
						for (const key in item) {
							item[key] = this.$praseStrEmpty(item[key])
						}
					})

					
					if (this.page == 1) {
						this.shopData = list
					} else {
						this.shopData = this.shopData.concat(list)
					}
					
					if(list.length < 10){
						this.noMoreShow = false
					}
					else {
						this.noMoreShow = true
					}

				})
			},
			goAppraise(v) {
                 uni.navigateTo({
					url:'../reportManage/reportDetail?id='+v.ID
				})
			}

		},

		// 下拉刷新 上拉加载更多
		onPullDownRefresh() {
			this.page = 1
			this.getShopData()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.page++;
			this.getShopData()
		},

	}
</script>

<style>
	.content {
		background-color: #F4F5F7;
		min-height: 100vh;
	}

	.topView {
		width: 100%;
		height: 290rpx;
		background-color: #FFFFFF;
		left: 0rpx;
		top: 0rpx;
		position: fixed;
		z-index: 99;
	}

	/* #ifdef H5 */
	.topView {
		top: 44px;
	}

	/* #endif */

	.searchBox {
		height: 72rpx;
		margin: 24rpx;
		background-color: #F4F5F7;
		border-radius: 36rpx;
		display: flex;
	}

	.searchImg {
		margin-top: 20rpx;
		margin-left: 20rpx;
		width: 32rpx;
		height: 32rpx;
	}

	.searchInput {
		height: 72rpx;
		font-size: 28rpx;
		padding-left: 16rpx;
		width: 85%;
	}

	.siftBg {
		display: flex;
		justify-content: space-around;
		height: 80rpx;
		align-items: center;
	}

	.timeChose {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.downArrow {
		width: 16rpx;
		height: 12rpx;
		padding: 6rpx 8rpx;
	}

	.tabBox {
		width: 100%;
	}

	.tabCotn {
		display: flex;
	}

	.tabLine {
		width: 150rpx;
		text-align: center;
		color: #3C3C3C;
		font-size: 30rpx;
		line-height: 88rpx;
	}

	.tabactive {
		color: #FF4F00;
		border-bottom: 4rpx solid #FF4F00;
	}

	.shopList {
		background-color: #F4F5F7;
		padding: 0rpx 24rpx;
		padding-top: 290rpx;
	}

	.shopBox {
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin: 20rpx 0rpx;

	}

	.shopTop {
		display: flex;
		padding: 30rpx 20rpx 10rpx 20rpx;
		justify-content: space-between;

	}

	.shopName {
		font-size: 28rpx;
		color: #3C3C3C;
		font-weight: bold;
		width: 500rpx;
	}

	.type {
		font-size: 28rpx;
		color: #FF4F00;
		margin-left: 10rpx;
	}

	.bottomView {
		padding: 28rpx 20rpx;
		display: flex;
		justify-content: space-between;
	}

	.manager {
		font-size: 24rpx;
		color: #666666;
	}

	.score {
		font-size: 28rpx;
		color: #B98B5D;
	}

	/* 空白页css */
	.nodataBox {
		text-align: center;
	}

	.nodataImg {
		width: 400rpx;
		padding-top: 290rpx;
	}

	.noTxt {
		font-size: 30rpx;
		color: #999999;
		padding-top: 50rpx;
	}

	.noMore {
		text-align: center;
		line-height: 50rpx;
		color: #999999;
		font-size: 28rpx;
	}
</style>
