<template>
	<view class="box">
		<!-- 选择器 -->
		<view class="boxtittab">
			<view class="tabbox" @click="taptimeisshow">
				{{ timeText }}
				<u-icon name="arrow-down" size="24" style="padding-left: 12rpx;"></u-icon>
			</view>
			<view class="tabbox" @click="selectshow = true">
				{{ guwenText }}
				<u-icon name="arrow-down" size="24" style="padding-left: 12rpx;"></u-icon>
			</view>

			<view class="tabbox" @click="tapsoltishow">
				{{ steyStatus }}
				<u-icon name="arrow-down" size="24" style="padding-left: 12rpx;"></u-icon>
			</view>
			<view class="tabbox" @click="showIdent = true">
				{{ weijinTag }}
				<u-icon name="arrow-down" size="24" style="padding-left: 12rpx;"></u-icon>
			</view>

		</view>
		<view class="count" v-if="recordList.length > 0">
			筛选结果：<text>{{totalRecords}} </text>条
		</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-top: 200rpx;">
					<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>
			<view v-if="recordList.length!=0" class="content-tips" v-for="(item,index) in recordList" :key='index'
				@click="tapThevisiting(item, index)">
				<view class="content-first">
					<view class="left">
						<view class="img">顾</view>
						<view class="name">{{item.agentName}}</view>
						<view class="status" v-if="item.replaceReception==1">代接待</view>
					</view>
					<view class="right">
						<view class="">
							{{ item.violatedStatus | ViolatedStatus }}|{{ item.disposeStatus | DisposeStatus }}
						</view>
					</view>
				</view>

				<view class="content-last">
					<view class="item">
						<image src="@/static/images/img/time.png" mode=""></image>
						<text>{{item.createTime}}</text>
					</view>
					<view class="item">
						<image src="@/static/images/img/voice.png" mode=""></image>
						<text>{{item.mm || '0'}}min</text>
					</view>
					<view class="item">
						<image src="@/static/images/img/hit.png" mode=""></image>
						<text>{{item.violatedFrequency || '0'}}</text>
					</view>
				</view>
			</view>
		</view>


		<!-- 选择顾问的选择框 -->
		<u-select v-model="selectshow" :list="freeList" @confirm="actionSelectCallback"></u-select>
		<u-calendar v-model="totalTimeShow" mode="range" @change="totalTimeChange"></u-calendar>
		<u-popup v-model="timeshow" mode="bottom">
			<block v-for="(data, index) in activeList" :key="index">
				<view class="timeview" :style="{ color: activeTotal == data.id ? '#2B6EFF' : '#333333' }"
					@click="tabtimetap(data.id, data.title)">{{ data.title }}</view>
			</block>
		</u-popup>
		<u-select v-model="soltishow" :list="orderBylist" @confirm="selectCallback2"></u-select>

		<u-select v-model="showIdent" :list="identList" @confirm="selectIdent"></u-select>


		<!-- 加载组件  -->
		<loading v-model="LOADING"></loading>
	</view>
</template>

<script>
	import loading from "@/components/loading/index.vue"
	export default {
		components: {
			loading
		},
		data() {
			return {
				orderBylist: [{
					label: '全部',
					value: null
				}, {
					label: '待处理',
					value: 0
				}, {
					label: '已处理',
					value: 1
				}],
				activeTotal: 5,
				activeList: [ // 时间筛选数组
					{
						title: '全部',
						id: 5,
					},
					{
						title: '今天',
						id: 0,
					},
					{
						title: '昨天',
						id: 1,
					},
					{
						title: '近7天',
						id: 2,
					},
					{
						title: '近30天',
						id: 3,
					},
					{
						title: '自定义',
						id: 4,
					},
				],
				showIdent: false, // 显示选择违禁标识列表
				identList: [ // 违禁标识列表
					{
						label: '全部',
						value: null
					},
					{
						label: '有效',
						value: 1
					},
					{
						label: '无效',
						value: 2
					},
				],
				violatedStatus: null, // 违禁状态
				selectshow: false,
				totalTimeShow: false,
				screen: {
					agentId: '', //顾问id
					record: '0',
				},
				freeList: [], //顾问
				recordList: [],
				buildingID: '',
				nextPage: 1,
				totalRecord: "",
				staTime: '',
				endtime: '',
				isnorefresh: '',
				activeTotal2: 0,
				timeshow: false,
				soltishow: false,
				orderBy: null,
				userInfo: {},
				totalRecords: '', // 列表全部的条数
				isRefresh: false,
				nextPageObj: {}, // 跳转详情页面的参数


				// 页面文字展示内容
				timeText: '接待时间', // 
				guwenText: '顾问', // 
				steyStatus: '处理状态', // 
				weijinTag: '违禁标识', // 违禁标识

			}
		},
		onLoad(options) {
			this.LOADING = true
			this.isnorefresh = options.refresh;
			if (options.activeTotal) {
				this.activeTotal = options.activeTotal
			}
			if (options.staTime) {
				this.staTime = options.staTime;
				this.endtime = options.endtime;
				this.timeText = `${options.staTime}-${options.endtime}`
			}
			if (options.violatedStatus) {
				this.violatedStatus = options.violatedStatus
				this.weijinTag = this.identList[options.violatedStatus].label
			}
		},
		onShow() {
			this.userInfo = uni.getStorageSync('weapp_session_userInfo_data');
			if (this.isnorefresh == 'refresh') {
				this.buildingID = uni.getStorageSync('buildingID').id;
				this.recordList = [];
				this.nextPage = 1;
				this.isRefresh = false;
				this.getMyCustom()
				this.getFreeList();
				this.isnorefresh = '';
			}
			var pages = getCurrentPages();
			pages[0].$vm.path = '/pages/index/index'
			console.log(pages[0].$vm.path)
		},
		onPullDownRefresh() {
			this.nextPage = 1;
			this.isRefresh = true;
			this.getMyCustom()
			this.resetRefreshParams()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			if (this.totalRecord == this.nextPage) {
				uni.showToast({
					icon: 'none',
					title: '到底了',
					duration: 2000
				});
				return
			} else {
				this.nextPage += 1;
				this.isRefresh = false;
				this.getMyCustom();
			}
		},
		methods: {
			// 重置参数
			resetRefreshParams() {
				this.timeText = '接待时间'
				this.activeTotal = 5
				this.guwenText = '顾问'
				this.screen.agentId = '' // 顾问id
				this.steyStatus = '处理状态'
				this.orderBy = null
				this.weijinTag = '违禁标识'
				this.violatedStatus = null // 违禁状态
			},

			tapsoltishow() {
				this.soltishow = true;
			},

			taptimeisshow() {
				this.timeshow = true;
			},

			//选择标签
			selectCallback2(e) {
				this.orderBy = e[0].value;
				this.steyStatus = e[0].label;
				this.nextPage = 1;
				this.recordList = [];
				this.isRefresh = false;
				this.getMyCustom();
			},

			// 选择违禁标识
			selectIdent(e) {
				this.violatedStatus = e[0].value
				this.weijinTag = e[0].label
				this.nextPage = 1;
				this.recordList = [];
				this.isRefresh = false;
				this.getMyCustom();
			},

			//时间选择
			tabtimetap(index, title) {
				this.timeshow = false;
				if (index == 4) {
					this.totalTimeShow = true;
				} else {
					this.timeText = title
					this.activeTotal = index;
					this.staTime = '';
					this.endtime = '';
					this.nextPage = 1;
					this.recordList = [];
					this.isRefresh = false;
					this.getMyCustom();
				}
			},
			//自定义时间
			totalTimeChange(e) {
				this.staTime = e.startDate;
				this.endtime = e.endDate;
				this.timeText = `${e.startDate}-${e.endDate}`
				this.activeTotal = 4;
				this.nextPage = 1;
				this.recordList = [];
				this.isRefresh = false;
				this.getMyCustom();
			},

			// 跳转违禁详情
			tapThevisiting(item, index) {
				if (item.status == 0) {
					uni.showToast({
						icon: "none",
						title: "排队中"
					})
					return
				} else {
					const parames = {
						pageNum: 1,
						pageSize: 100,
						query: {
							customerId: item.id,
						}
					}
					this.$u.post("/customer/prohibitedMatch", {
						customerId: item.id
					}).then(res => {
						let newweijin = res[0];
						newweijin.transferContent = JSON.parse(newweijin.transferContent)
						var item = {
							bg: newweijin.transferContent.bg,
							customerId: newweijin.corpusId,
						}
						uni.setStorageSync("searchobj", item); //写入缓存
						this.$u.post("/corpus/findByPage", parames).then(res => {
							if (res == null) {
								uni.showToast({
									icon: "none",
									title: "暂无音频"
								})
								return
							} else {
								let newobj = res[0];

								let obj = {
									pageSize: index + 1,
									num: this.totalRecords,
									query: {
										...this.nextPageObj
									}
								}

								uni.setStorageSync('nextPageObj', JSON.stringify(obj))
								uni.navigateTo({
									url: `/pages/center/prohibited/details?customerId=${newobj.customerId}&status=${newobj.status}&stateisshow=${"2"}&index=${index}&isMerge=${res[0].merge}`
								})

								// if (res[0].merge == 0) {
								// }
								//  else {
								// 	uni.navigateTo({
								// 		url: `/pages/mine/details?customerId=${newobj.customerId}&status=${newobj.status}&stateisshow=${"2"}`
								// 	})
								// }
							}
						})
					})
				}

			},

			// 获取围巾列表
			getMyCustom() {
				let dateType = 0;
				if (this.activeTotal == 5) {
					dateType = null;
				} else if (this.activeTotal == 4) {
					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,
						taboo: 1,
						dateType: dateType,
						disposeStatus: this.orderBy, // 处理状态
						violatedStatus: this.violatedStatus, // 违禁状态
					}
				};
				if (this.screen.agentId) {
					parames.query.agentId = this.screen.agentId
				}

				this.$u.post("/customer/findbypage", parames).then(data => {
					this.LOADING = false
					var list = data.results || [];
					if (this.isRefresh) {
						this.recordList = list;
					} else {
						this.recordList = [...this.recordList, ...list];
					}
					this.totalRecord = data.totalPage;
					this.totalRecords = data.totalRecord;
					this.nextPageObj = parames.query
				}).catch(e => {
					this.LOADING = false
				})
			},
			//获取顾问列表
			getFreeList() {
				this.$u.post("/cusLvStatistics/selectAllAccountIdByHouseId", {
					houseId: this.buildingID
				}).then(res => {
					this.freeList = res;
					this.freeList.forEach(item => {
						item.label = item.name;
						item.value = item.accountId
					})
					this.freeList.unshift({
						label: '全部',
						value: null,
					})
				})
			},
			//顾问确认
			actionSelectCallback(e) {
				this.screen.agentId = e[0].value;
				this.guwenText = e[0].label;
				this.recordList = [];
				this.nextPage = 1;
				this.selectshow = false;
				this.isRefresh = false;
				this.getMyCustom();
			},
		},


		filters: {
			// violatedStatus 
			ViolatedStatus(status) {
				let str = '';
				switch (status) {
					case 0:
						str = '有效违禁'
						break;
					case 1:
						str = '有效违禁'
						break;
					case 2:
						str = '无效违禁'
						break;
				}
				return str
			},

			// DisposeStatus
			DisposeStatus(status) {
				let str = '';
				switch (status) {
					case 0:
						str = '待处理'
						break;
					case 1:
						str = '已处理'
						break;
				}
				return str
			},
		}
	}
</script>

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

	.count {
		width: 100%;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #FBE4E4;

		text {
			color: #F71616;
		}
	}

	.timeview {
		height: 80rpx;
		line-height: 80rpx;
		width: 100%;
		text-align: center;
		border-bottom: 1px solid #F8F8F8;
	}

	//时间切换的样式
	.boxtittab {
		position: sticky;
		top: var(--window-top);
		z-index: 100;
		width: 100;
		height: 92rpx;
		background: #FFFFFF;
		border: 1px solid #E0E0E0;
		display: flex;
		align-items: center;

		.tabbox {
			flex: 1;
			height: 100%;
			text-align: center;
			line-height: 92rpx;
			color: #666666;
			font-size: 28rpx;
			overflow: hidden;
			/* 超出一行文字自动隐藏 */
			text-overflow: ellipsis;
			/*文字隐藏后添加省略号*/
			white-space: nowrap;
			/*强制不换行*/
		}
	}

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

		.search {
			width: 94%;
			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: 0 0 20rpx 0;
			background: #fff;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;

			.content-first {
				padding: 20rpx 30rpx;
				display: flex;
				justify-content: space-between;
				background-color: #EEF4FD;

				.left {
					display: flex;

					.img {
						margin-right: 10rpx;
						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;
						// margin-left: 20rpx;
						margin-top: 11rpx;
					}

					.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;
					}
				}

				.right {
					display: flex;
					margin-top: 11rpx;

					.point {
						width: 12rpx;
						height: 12rpx;
						background: #2B6EFF;
						border-radius: 50%;
						margin-right: 9rpx;
						margin-top: 16rpx;

					}
				}
			}


			.content-last {
				padding: 24rpx 30rpx;
				font-size: 30rpx;
				font-weight: 400;
				color: #666666;
				display: flex;
				justify-content: space-between;

				.item {
					flex-shrink: 0;
					display: flex;
					align-items: center;

					image {
						margin-right: 10rpx;
						width: 32rpx;
						height: 32rpx;
					}

					text {
						font-size: 28rpx;
					}
				}
			}
		}
	}

	// 这是弹出层
	.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>
