<template>
	<view class="pageLineUpTop">
		<view :class="[[datas.selecttopType==''?'active':'']]" @tap="gettypeevent('')">
			<view style="border-bottom: 1px dashed #ccc;line-height: 70rpx;">全部</view>
			<view style="line-height: 50rpx;">{{datas.list.totalCount}}桌</view>
		</view>
		<view v-for='item in datas.list.records' :key="item.id" @tap="gettypeevent(item.id)"
			:class="[[datas.selecttopType==item.id?'active':'']]">
			<view style="border-bottom: 1px dashed #ccc;line-height: 70rpx;">{{item.name}}</view>
			<view style="line-height: 50rpx;color: #999;">{{item.totalCount}}桌({{item.note}})</view>
		</view>
	</view>
	<view class="userinfo">
		<view>用户</view>
		<span>号码</span>
		<span>等待</span>
	</view>
	<view class="userinfoBox" v-for="item in datas.listType.records" :key="item.id">
		<view class="userinfo1">
			<view>
				<image src="./avation.svg" style="width: 64rpx;height: 64rpx;margin-right: 16rpx;" mode=""></image>
				<view>
					<view>
						{{item.phone}}
					</view>
					<view>
						{{item.callTime}}
					</view>
				</view>
			</view>
			<span>{{item.callNum}}</span>
			<span>{{item.waitingCount}}桌</span>
		</view>
		<view class="userinfo2">
			<view>{{item.name}}{{item.note}}</view>
			<button type="primary" class="mini-btn" size="mini" style="border-radius: 200rpx;" @tap="quxiaoevent(item)"
				plain="true">取消</button>
			<button class="mini-btn" type="primary" style="border-radius: 200rpx;" @tap="profilepicture(item)"
				size="mini">播报</button>
		</view>
	</view>
	<view class="bottomBUtton">
		<button class="mini-btn" type="primary" @tap="showFalse">取号</button>
		<button type="text" class="mini-btn" plain="true" @tap="toUrl">叫号记录</button>
	</view>
	<!-- 播报弹窗 -->
	<uni-popup ref="alertDialog" type="dialog">
		<uni-popup-dialog :type="datas.msgType" cancelText="完成" confirmText="过号" confirmText-color="#000" title="播报"
			@confirm="dialogConfirm(1)" @close="dialogConfirm(2)">
			<view class="">
				<view class="">
					正在叫号请稍后
				</view>
				<view style="font-size: 24rpx; text-align:center;color: #52C41A;"
					v-if="datas.profilepicturedata.state==1">
					已发送至用户
				</view>
				<view style="font-size: 24rpx;text-align:center;color: #F02C45;" v-else>
					用户未订阅消息
				</view>
			</view>
		</uni-popup-dialog>
	</uni-popup>
	<!-- 取号遮罩层 -->
	<up-popup :show="datas.show" :round="18" mode="center" @close="close" @open="open">
		<view class="zhezhaopop">
			<view class="">
				<span></span>
				<span>取号</span>
				<up-icon @tap="confirm" name="close-circle-fill"></up-icon>
			</view>
			<view class="">
				选择桌型
			</view>
			<view class="pageLineUpTop">
				<view v-for='item in datas.list.records' :key="item.id"
					:class="[datas.selectTabletype.id==item.id?'active':'']" @tap="selectTypeEvent(item)">
					<view style="border-bottom: 1px dashed #ccc;line-height: 70rpx;">{{item.name}}</view>
					<view style="line-height: 50rpx;">等待{{item.totalCount}}桌</view>
				</view>

			</view>
			<view class="">
				手机号码
			</view>
			<view style="margin-bottom: 48rpx;">
				<input v-model="datas.phone" type="text" placeholder="填写号码" />
			</view>
			<up-button text="确认取号" @tap="callTabletakeNumberEvent" type="primary" class="buttomStyle"
				shape="circle"></up-button>
		</view>
	</up-popup>
	<!-- 取号成功 -->
	<up-popup :show="datas.showtwo" :round="18" mode="center" @close="close" @open="open">
		<view class="zhezhaopops">
			<view class="">
				<span></span>
				<span>取号成功</span>
				<up-icon @tap="confirmtow" name="close-circle-fill"></up-icon>
			</view>
			<view class="">
				{{datas.showtowData.callNum}}
			</view>
			<view style="margin-bottom: 48rpx;">
				{{datas.showtowData.tableName}} ({{datas.showtowData.tableNote}})
			</view>
			<up-button text="确认" @tap="confirmtow" type="primary" class="buttomStyle" shape="circle"></up-button>
		</view>
	</up-popup>
	<!-- <up-toast ref="uToastRef"></up-toast> -->
</template>

<script setup>
	import {
		reactive,
		getCurrentInstance,
		onMounted
	} from 'vue';
	import {
		callTable,
		callTablequeue,
		callTabletakeNumber,
		callTableput,
		callTablecall
	} from '@/http/yskApi/requestAll.js';
	import go from '@/commons/utils/go.js'
	let getrefs = getCurrentInstance()
	let datas = reactive({
		msgType: "",
		// 关闭取号弹窗
		show: false,
		showtwo: false,
		showtowData: "",
		// 桌形列表
		list: [],
		// 正在排号
		listType: [],
		// 选中的桌型
		selectTabletype: undefined,
		// 手机号
		phone: null,
		// 顶部全部\大桌选择
		selecttopType: '',
		// 选中拨号的id
		dialId: "",
		// 拨号是否订阅
		profilepicturedata: ""

	})
	onMounted(() => {
		getList()
	})
	const confirm = () => {
		datas.show = false;
	};
	const confirmtow = () => {
		datas.showtwo = false;
	};

	function dialogConfirm(value) {
		if (value == 1) {
			callTableput({
				shopId: uni.getStorageSync('shopId'),
				state: 3,
				callQueueId: datas.dialId
			}).then((res) => {
				getList()
			})
		} else {
			// value=2完成
			callTableput({
				shopId: uni.getStorageSync('shopId'),
				state: 2,
				callQueueId: datas.dialId
			}).then((res) => {
				getList()
			})
		}
	}

	function gettypeevent(d) {
		datas.selecttopType = d
		getList()
	}

	function getList() {
		callTable({
			shopId: uni.getStorageSync('shopId'),
			page: 1,
			size: 10,
		}).then((res) => {
			datas.list = res
			datas.selectTabletype = res.records[0]
		})
		callTablequeue({
			shopId: uni.getStorageSync('shopId'),
			page: 1,
			size: 9999,
			callTableId: datas.selecttopType,
			state: 0
		}).then((res) => {
			datas.listType = res
		})
	}

	function quxiaoevent(item) {
		callTableput({
			shopId: uni.getStorageSync('shopId'),
			state: -1,
			callQueueId: item.id
		}).then((res) => {
			getList()
		})
	}

	function selectTypeEvent(d) {
		datas.selectTabletype = d
	}

	function callTabletakeNumberEvent() {
		callTabletakeNumber({
			callTableId: datas.selectTabletype.id,
			shopId: uni.getStorageSync('shopId'),
			phone: datas.phone,
			note: datas.selectTabletype.note,
			name: datas.selectTabletype.name,
		}).then((res) => {
			if (res) {
				datas.show = false;
				datas.showtwo = true;
				datas.showtowData = res
				datas.phone = ''
				getList()

			}
		})

	}

	function showFalse() {
		datas.show = true;
	}

	function profilepicture(item) {
		datas.dialId = item.id
		callTablecall({
			shopId: uni.getStorageSync('shopId'),
			callQueueId: item.id
		}).then((res) => {
			datas.profilepicturedata = res
			getrefs.ctx.$refs.alertDialog.open()
		})

	}

	function toUrl() {
		go.to('PAGES_CALLRE_CORD')
	}
</script>

<style scoped lang="less">
	page {
		height: 100%;
		background-color: #f9f9f9;
	}

	.pageLineUpTop {
		.df;
		justify-content: space-around;
		flex-wrap: wrap;
		margin: 36rpx 0;

		>view {
			width: 208rpx;
			height: 136rpx;
			background: #FFFFFF;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 2rpx solid #E5E5E5;
			margin-top: 20rpx;
			>view {
				text-align: center;
			}
		}

		.active {
			border: 2rpx solid #318AFE;

			>view:first-child {
				color: #318AFE;
			}
		}
	}

	.userinfo {
		width: 750rpx;
		height: 84rpx;
		background: #E9E9E9;
		border-radius: 12rpx 12rpx 0rpx 0rpx;
		padding: 0 44rpx;
		.df;
		justify-content: space-between;

		>view:first-child {
			width: 300rpx;
		}
	}

	.userinfoBox {
		margin-bottom: 32rpx;

		.userinfo1 {
			width: 750rpx;
			height: 84rpx;
			background: #fff;
			border-radius: 12rpx 12rpx 0rpx 0rpx;
			padding: 0 44rpx;
			.df;
			justify-content: space-between;
			padding-top: 32rpx;

			>view:first-child {
				width: 280rpx;
				.df;
			}
		}

		.userinfo2 {
			width: 750rpx;
			height: 84rpx;
			background: #fff;
			border-radius: 12rpx 12rpx 0rpx 0rpx;
			padding: 58rpx 0;
			padding-left: 44rpx;
			.df;
			justify-content: space-between;
			background-color: #fff;
			// margin-top: 32rpx;

			>view:first-child {
				margin-right: 260rpx;
				background: #E5E5E5;
				width: 130rpx;
				height: 32rpx;
				line-height: 32rpx;
				text-align: center;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: 400;
				font-size: 22rpx;
				color: #999999;

			}
		}
	}

	.bottomBUtton {
		width: 100%;
		height: 200rpx;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 50%;
		transform: translate(-50%);
		padding-top: 24rpx;

		>button {
			width: 530rpx;
			background: #318AFE;
			border-radius: 200rpx;
		}

		>button:last-child {
			background-color: rgba(0, 0, 0, 0);
			border: none;
			color: #318AFE;
		}
	}

	.zhezhaopop {
		padding: 34rpx 32rpx;
		width: 594rpx;
		// height: 668rpx;
		background: #FFFFFF;
		// border-radius: 18rpx 18rpx 18rpx 18rpx;

		>view:first-child {

			.df;
			justify-content: space-between;

			>span:nth-child(2) {
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}
		}

		>view:nth-child(2) {
			margin-top: 48rpx;
		}

		>view:nth-child(3) {
			margin-top: 32rpx;
		}

		>view:nth-child(4) {
			font-family: Source Han Sans CN, Source Han Sans CN;
			font-weight: 500;
			font-size: 28rpx;
			color: #333333;
		}

		>view:nth-child(5) {
			margin-top: 22rpx;

			>input {
				width: 500rpx;
				height: 84rpx;
				padding-left: 24rpx;
				background: #FFFFFF;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				border: 2rpx solid #E5E5E5;
				// margin-top: 32rpx;
			}
		}

		.buttomStyle {
			margin-top: 48rpx;
			width: 506rpx;
			height: 80rpx;
		}
	}

	.zhezhaopops {
		padding: 34rpx 32rpx;
		width: 594rpx;
		background: #FFFFFF;
		// border-radius: 18rpx 18rpx 18rpx 18rpx;
		border-radius: 18rpx 18rpx 18rpx 18rpx;

		>view:first-child {
			border-radius: 18rpx 18rpx 18rpx 18rpx;
			.df;
			justify-content: space-between;

			>span:nth-child(2) {
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}
		}

		>view:nth-child(2) {

			font-family: Source Han Sans CN, Source Han Sans CN;
			font-weight: bold;
			font-size: 80rpx;
			color: #333333;
			margin-top: 64rpx;
			margin-left: 34%;
		}

		>view:nth-child(3) {
			margin-top: 48rpx;
			margin-left: 34%;
		}



		.buttomStyle {
			margin-top: 48rpx;
			width: 506rpx;
			height: 80rpx;
		}
	}

	.df {
		display: flex;
		align-items: center;
	}
</style>