<template>
	<view class="box">
		<!-- 搜索框点击跳转 -->
		<view>
			<view class="search-box">
				<view class="search" @click="goSearch">
					<view class="search-img">
						<image class="search-img1" src="../../../static/images/search.png" mode=""></image>
					</view>
					<view class="search-text">输入客户姓名/手机号</view>
				</view>
				<view class="search-screen" @click="screenshow">
					<image class="search-screen1" src="../../../static/images/screen.png" mode=""></image>
				</view>
			</view>
		</view>
		<!-- 选择器 -->
		<view class="choose">
			<u-tabs :list="receptionList" :activeItemStyle="activeItemStyle" :isScroll="false" lineColor="#2671E2"  @change="reception" :current="current"></u-tabs>
		</view>
<!-- 		<view class="boxtittab">
			<view class="tabbox">
				<view :class="{ activecllasscet: activeTotal == 0 }" @click="tabtimetap(0)">今日</view>
			</view>
			<view class="tabbox">
				<view :class="{ activecllasscet: activeTotal == 1 }" @click="tabtimetap(1)">昨日</view>
			</view>
			<view class="tabbox">
				<view :class="{ activecllasscet: activeTotal == 2 }" @click="tabtimetap(2)">近一周</view>
			</view>
			<view class="tabbox">
				<view :class="{ activecllasscet: activeTotal == 3 }" @click="tabtimetap(3)">自定义</view>
			</view>
		</view> -->
		<view class="content">
			<view v-if="recordList.length==0"
				style="width: 100%;height: 100%;display: flex;align-items: center;background: #FFFFFF;">
				<view style="width: 100%;padding: 200rpx 0;">
					<view style="width: 100%;text-align: center;">
						<image style="width: 220rpx;height: 200rpx;"
							src="https://static.quhouse.com/zhikong_xcx_img/nodatalist.png" mode=""></image>
					</view>
					<view style="text-align: center;width: 100%;margin-top: 20rpx;color: #999999;">暂无数据</view>
				</view>
			</view>

			<template v-if="recordList.length != 0">
				<view class="content-tips" v-for="(item,index) in recordList" :key='index'
					@click="tapThevisiting(item)">
					<view class="content-first">
						<view class="left">
							<view class="tag-id">顾</view>
							<view class="name">{{item.agentName || '--'}}</view>
							<view class="status" v-if="item.replaceReception==1">代接待</view>
						</view>
						<view class="middle">自动结束{{ nowTime }}</view>
						<view class="right">
							<!-- 文字状态 -->
							<template v-if="false">
								<view v-if="item.markAdvisor==0" class="">未标记</view>
								<view v-if="item.markAdvisor==1" class="">已标记</view>
							</template>
							
							<!-- 文字状态 -->
							<template v-if="true">
								<image src="../static/image/note.png" class="img1" mode=""></image>
								<image src="../static/image/power.png" class="img2" mode=""></image>
								<image src="../../../static/images/Thtapedrive1.png" class="img3" mode=""></image>
							</template>
						</view>
					</view>
					<view class="content-sec">
						<view class="c-left">
							<view class="left">
								<view class="tag-id">客</view>
								<view class="cus">{{item.name || '--'}}</view>
								<view class="phone">{{ item.phone | encryptionPhone }}</view>
							</view>
							<template>
								<view class="percent">
									<image src="../static/image/percent.png" mode=""></image>
									{{item.fraction || '0'}}%
								</view>
							</template>
						</view>
						
						<view class="right">
							<view class="items">
								<image class="img" src="../static/image/people.png"></image>
								<text class="i-right">{{ item.visitRecord || "--" }}次到访</text>
							</view>
							<view class="items">
								<image class="img" src="../static/image/time.png"></image>
								<text class="i-right"> {{ item.createTime }} </text>
							</view>
							<view class="items">
								<image class="img" src="../static/image/voice.png"></image>
								<text class="i-right"> {{ item.mm || '0' }} </text>
							</view>
						</view>
					</view>
					<view class="content-last">
						<template v-if="true">
							<view class="btns">接待延迟</view>
						</template>
						
						<template v-if="false">
							<view class="btns">重新接待</view>
						</template>
						
						<template v-if="true">
							<view class="btns">结束接待</view>
						</template>
						
						<template v-if="false">
							<view class="btns">指派顾问</view>
						</template>
					</view>
				</view>
			</template>

		</view>



		<u-popup v-model="screenShow" mode="top" height="590">
			<view class="screen">
				<!-- 顾问选择 -->
				<view class="screen-counselor">
					<view class="screen-text">
						所属顾问
					</view>
					<view class="screen-sel">
						<u-input v-model="screen.counselorName" type="text" placeholder='请选择' @click="selectshow = true"
							class="screen-inp" disabled />
						<image class="screen-sel-img" src="../../../static/images/right.png" mode=""></image>
					</view>
				</view>

				<view class="screen-record">
					<view class="screen-record-text">
						标记顾问
					</view>
					<view class="screen-record-tab">
						<view :class="[screen.markAdvisor==1?'screen-record-chose':'screen-record-nochose']"
							@click="screenvisitRecord(1)">
							标记
						</view>
						<view :class="[screen.markAdvisor==0?'screen-record-chose':'screen-record-nochose']"
							@click="screenvisitRecord(0)">
							未标记
						</view>
					</view>
				</view>
				<view class="screen-record">
					<view class="screen-record-text">
						到访次数
					</view>
					<view class="screen-record-tab">
						<view :class="[screen.visitRecord==1?'screen-record-chose':'screen-record-nochose']"
							@click="recordclick(1)">
							首次到访
						</view>
						<view :class="[screen.visitRecord==2?'screen-record-chose':'screen-record-nochose']"
							@click="recordclick(2)">
							第二次
						</view>
						<view :class="[screen.visitRecord==3?'screen-record-chose':'screen-record-nochose']"
							@click="recordclick(3)">
							第三次
						</view>
						<view :class="[screen.visitRecord==4?'screen-record-chose':'screen-record-nochose']"
							@click="recordclick(4)">
							三次以上
						</view>
					</view>
				</view>
				<view class="screen-foot">
					<view class="screen-foot-reset" @click="reset">
						重置
					</view>
					<view class="screen-foot-sure" @click="screensure">
						确定
					</view>
				</view>
			</view>
		</u-popup>
		<!-- 选择顾问的选择框 -->
		<u-select v-model="selectshow" :list="freeList" @confirm="actionSelectCallback"></u-select>

		<u-calendar v-model="totalTimeShow" mode="range" @change="totalTimeChange"></u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeTotal: 2,
				value: '',
				screenShow: false,
				selectshow: false,
				totalTimeShow: false,
				screen: {
					agentId: '', //顾问id
					record: '0',
					markAdvisor: null,
					visitRecord: null

				},
				freeList: [], //顾问
				recordList: [],
				buildingID: '',
				nextPage: 1,
				totalRecord: "",
				staTime: '',
				endtime: '',
				isnorefresh: '',
				
				receptionList: [ // 接待类型列表
					{
						name: '接待中'
					},
					{
						name: '未标记'
					},
					{
						name: '已标记'
					}
				], 
				current: 0, // 当前选中项下标
				activeItemStyle: {
					fontWeight: '400',
					color: '#2671E2'
				},
				
				nowTime: new Date().getFullYear(), // 获取到的当前时间
			}
		},
		onLoad(options) {
			this.isnorefresh = options.refresh;
		},
		onShow() {
			if (this.isnorefresh == 'refresh') {
				this.buildingID = uni.getStorageSync('buildingID').id;
				this.recordList = [];
				this.nextPage = 1;
				this.getMyCustom()
				this.getFreeList();
				this.isnorefresh = '';
			}
		},
		onReachBottom() {
			if (this.totalRecord == this.nextPage) {
				uni.showToast({
					icon: 'none',
					title: '到底了',
					duration: 2000
				});
				return
			} else {
				this.nextPage += 1;
				this.getMyCustom();
			}
		},
		methods: {
			// 接待类型
			reception(e) {
				this.current = e
			},
			
			
			tapThevisiting(item) {
				if (item.status == 0) {
					uni.showToast({
						icon: "none",
						title: "排队中"
					})
					return
				} else {
					const parames = {
						pageNum: 1,
						pageSize: 100,
						query: {
							customerId: item.id,
						}
					}
					var item = {
						bg: 0,
						customerId: item.id,
					}
					this.$u.post("/corpus/findByPage", parames).then(res => {
						if (res == null) {
							uni.showToast({
								icon: "none",
								title: "暂无音频"
							})
							return
						} else {
							let newobj = res[0];
							if (res[0].merge == 0) {
								uni.navigateTo({
									url: `/pages/mine/details2?customerId=${newobj.customerId}&status=${newobj.status}&itemobj=${JSON.stringify(item)}&stateisshow=${"2"}`
								})
							} else {
								uni.navigateTo({
									url: `/pages/mine/details?customerId=${newobj.customerId}&status=${newobj.status}&itemobj=${JSON.stringify(item)}&stateisshow=${"1"}`
								})
							}
						}
					})
				}

			},
			getMyCustom() {
				let dateType = 0;
				if (this.activeTotal == 3) {
					dateType = null;
				} else {
					dateType = this.activeTotal
				}
				var parames = {
					pageNum: this.nextPage,
					pageSize: 10,
					query: {
						projectId: this.buildingID,
						time: 1,
						staTime: this.staTime,
						endtime: this.endtime,
						visitRecord: this.screen.visitRecord,
						markAdvisor: this.screen.markAdvisor,
						dateType: dateType

					}
				};
				if (this.screen.agentId) {
					parames.query.agentId = this.screen.agentId
				}


				this.$u.post("/customer/findbypage", parames).then(data => {
					var list = data.results || [];
					this.recordList = [...this.recordList, ...list];
					this.totalRecord = data.totalPage;
				})
			},
			//获取顾问列表
			getFreeList() {
				this.$u.get("/zkAgentPool/freeList?itemId=" + this.buildingID).then(res => {
					this.freeList = res;
					this.freeList.forEach(item => {
						item.label = item.name;
						item.value = item.agentId
					})
				})
			},

			tabtimetap(index) {
				if (index == 3) {
					this.totalTimeShow = true;
				} else {
					this.activeTotal = index;
					this.staTime = '';
					this.endtime = '';
					this.nextPage = 1;
					this.recordList = [];
					this.getMyCustom();
				}
			},
			//自定义时间
			totalTimeChange(e) {
				this.staTime = e.startDate;
				this.endtime = e.endDate;
				this.activeTotal = 3;
				this.nextPage = 1;
				this.recordList = [];
				this.getMyCustom();
			},
			// 筛选
			screenshow() {
				this.screenShow = true
			},
			actionSelectCallback(e) {
				this.screen.agentId = e[0].value;
				this.screenShow = false;
				this.recordList = [];
				this.nextPage = 1;
				this.getMyCustom();
			},
			reset() {
				this.screen = {
					counselorName: '',
					record: '0',
					markAdvisor: null,
					visitRecord: null
				}
				this.screenShow = false;
				this.nextPage = 1;
				this.recordList = [];
				this.getMyCustom();
			},
			recordclick(i) {
				if (this.screen.visitRecord == i) {
					this.screen.visitRecord = null
				} else {
					this.screen.visitRecord = i
				}
			},
			screenvisitRecord(i) {
				if (this.screen.markAdvisor == i) {
					this.screen.markAdvisor = null
				} else {
					this.screen.markAdvisor = i
				}
			},
			screensure() {
				this.screenShow = false;
				this.recordList = [];
				this.nextPage = 1;
				this.getMyCustom();
			},
			goSearch() {
				uni.navigateTo({
					url: '/pages/center/records/recordSearch'
				});
			},
		},
		
		filters: {
			// 加密手机号 中间四位
			encryptionPhone(phone) {
				if (!phone) return
				let reg=/(\d{3})\d{4}(\d{4})/; //正则表达式
				return phone.toString().replace(reg, "$1****$2")
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100%;
		min-height: calc(100vh - var(--window-top));
		background: #F8F8F8;

		.boxtittab {
			border-top: none;
			border-color: #E0E0E0;
		}
	}

	.search-box {
		width: 100%;
		height: 102rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;

		.search {
			width: 620rpx;
			height: 70rpx;
			display: flex;
			align-items: center;
			background: #F8F8F8;
			border-radius: 33rpx;

			.search-img {
				width: 26rpx;
				height: 30rpx;
				margin-left: 20rpx;

				.search-img1 {
					width: 100%;
					height: 100%;
					margin-top: 2rpx;
				}
			}

			.search-text {
				font-size: 28rpx;
				font-weight: 400;
				color: #999999;
				margin-left: 10rpx;
			}
		}

		.search-screen {
			width: 40rpx;
			height: 40rpx;
			margin-left: 30rpx;

			.search-screen1 {
				width: 100%;
				height: 100%;
			}
		}
	}

	.content {

		.content-tips {
			margin-top: 20rpx;
			box-sizing: border-box;
			overflow: hidden;
			background: #fff;

			.content-first {
				padding: 0 30rpx;
				width: 100%;
				height: 92rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.left,
				.middle,
				.right {
					flex: 1;
				}

				.left {
					display: flex;
					align-items: center;

					.tag-id {
						margin: 0 12rpx 0 0;
						padding: 5rpx 11rpx;
						font-size: 30rpx;
						color: #2671E2;
						line-height: 42rpx;
						border: 1rpx solid #2671E2;
						border-radius: 50%;
					}

					.img {
						width: 52rpx;
						height: 52rpx;
						background: #FFFFFF;
						border: 1px solid #C9C9C9;
						border-radius: 50%;
						text-align: center;
						line-height: 52rpx;
					}

					.name {
						font-weight: 600;
						color: #333333;
					}

					.status {
						width: 110rpx;
						height: 42rpx;
						background: #FFF9F5;
						border-radius: 4rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #EC8D49;
						line-height: 42rpx;
						text-align: center;
						margin-left: 19rpx;
						margin-top: 11rpx;
					}
				}

				.middle {
					color: #E7483C;
					font-size: 30rpx;
					text-align: center;
				}

				.right {
					display: flex;
					justify-content: flex-end;

					.point {
						width: 12rpx;
						height: 12rpx;
						background: #2B6EFF;
						border-radius: 50%;
						margin-right: 9rpx;
						margin-top: 16rpx;
					}
					
					.img1 {
						width: 24rpx;
						height: 32rpx;
					}
					
					.img2 {
						margin-left: 24rpx;
						width: 22rpx;
						height: 32rpx;
					}
					
					.img3 {
						margin-left: 24rpx;
						width: 28rpx;
						height: 32rpx;
					}
				}
			}


			.content-sec {
				padding: 28rpx 30rpx 24rpx;
				border: 1rpx solid #E0E0E0;
				border-left: none;
				border-right: none;
				
				.c-left {
					width: 100%;
					display: flex;
					
					.percent {
						flex-shrink: 0;
						display: flex;
						align-items: center;
						font-size: 30rpx;
						color: #333;
						
						image {
							margin-right: 10rpx;
							width: 32rpx;
							height: 32rpx;
						}
					}
				}

				.left {
					flex-grow: 1;
					display: flex;
					align-items: center;

					.tag-id {
						margin: 0 12rpx 0 0;
						padding: 5rpx 11rpx;
						font-size: 30rpx;
						color: #fff;
						line-height: 42rpx;
						border: 1rpx solid #2671E2;
						background: #2671E2;
						border-radius: 50%;
					}

					.cus {
						font-size: 30rpx;
						font-weight: 600;
						color: #333;
					}
					
					.phone {
						margin-left: 20rpx;
						font-size: 30rpx;
						color: #333;
					}

					.arriveNum {
						font-size: 30rpx;
						font-weight: 400;
						margin-left: 10rpx;
					}
				}

				.right {
					margin-top: 24rpx;
					display: flex;
					justify-content: space-between;

					.items {
						display: flex;
						align-items: center;

						.img {
							margin-right: 10rpx;
							width: 30rpx;
							height: 30rpx;
							flex-shrink: 0;
						}

						.i-right {
							flex-shrink: 0;
							color: #333;
							font-size: 28rpx;
						}
					}
				}
			}

			.content-last {
				padding: 0 30rpx;
				height: 108rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				
				.btns {
					margin-left: 30rpx;
					height: 60rpx;
					padding: 0 18rpx;
					border: 1rpx solid #999999;
					font-size: 30rpx;
					border-radius: 30rpx;
					line-height: 60rpx;
				}
			}

		}
	}

	// 这是弹出层
	.screen {
		// box-sizing: border-box;
		// padding: 0 30rpx;
		position: absolute;

		.screen-counselor {
			display: flex;
			height: 106rpx;
			// padding: 40rpx 30rpx 36rpx 30rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			border-bottom: 1px solid #EEEEEE;

			.screen-text {
				margin: 40rpx 0 36rpx 0;
				font-size: 30rpx;
				font-weight: 400;
				color: #333333;
				line-height: 30rpx;
			}

			.screen-sel {
				display: flex;
				justify-content: space-between;
				width: 500rpx;
				margin-left: 60rpx;

				.screen-sel-img {
					margin: 40rpx 0 36rpx 0;
					width: 14rpx;
					height: 30rpx;
				}

				.screen-inp {
					margin-top: 20rpx;
				}
			}
		}

		.screen-record {
			height: 192rpx;
			// width: 100%;
			overflow: hidden;
			padding: 0 30rpx;
			box-sizing: border-box;
			border-bottom: 1px solid #EEEEEE;

			.screen-record-text {
				margin-top: 36rpx;
				font-size: 30rpx;
				font-weight: 400;
				color: #333333;
				line-height: 30rpx;
			}

			.screen-record-tab {
				margin-top: 30rpx;
				display: flex;

				// justify-content: space-around;
				.screen-record-chose {
					width: 156rpx;
					height: 60rpx;
					background: #2671E2;
					border-radius: 4rpx;
					border: 1px solid #2671E2;
					text-align: center;
					line-height: 60rpx;
					margin-right: 22rpx;
					color: #FFFFFF;
				}

				.screen-record-nochose {
					width: 156rpx;
					height: 60rpx;
					background: #FFFFFF;
					border-radius: 4rpx;
					border: 1px solid #C9C9C9;
					text-align: center;
					line-height: 60rpx;
					margin-right: 22rpx;
				}

			}
		}

		.screen-foot {
			width: 100%;
			height: 100rpx;
			display: flex;

			.screen-foot-reset {
				width: 50%;
				text-align: center;
				height: 100rpx;
				line-height: 100rpx;
				font-size: 30rpx;
				font-weight: 400;
				color: #666666;
			}

			.screen-foot-sure {
				width: 50%;
				text-align: center;
				line-height: 100rpx;
				height: 100rpx;
				font-size: 30rpx;
				font-weight: 400;
				color: #FFFFFF;
				background: #2671E2;
			}
		}
	}
</style>
