<template>
	<view class="keyborder-panel">
		<view class="key-group" v-for="(item,index) in keyGroup" :key="item.id">
			<template v-for="(child,cindex) in item.children" :key="child.id">
				<view @click="tapKey(child.value)" hover-class="key-active"
					:class="{'key-group-item':item.children.length >1}">
					<text>{{child.value}}</text>
				</view>
			</template>
		</view>
		<view class="key-group">
			<view @click="tapKey('0')" hover-class="key-active" class="key-group-item">
				<text>0</text>
			</view>
			<view @click="onComplete" hover-class="key-active" class="key-group-item keyboard">
				<text class="keyboard key-complete" />
			</view>
			<view @click="tapKey('delete')" hover-class="key-active" class="key-group-item keyboard">
				<text class="keyboard key-back" />
			</view>
		</view>
	</view>
</template>

<script>
	import "./style.css";
	export default {
		name: "number-keybord",
		props: {
			refKey: {
				type: String
			}
		},
		emits: {
			"typeCharacter": null,
			"typeComplete": null
		},
		data() {
			return {
				keyGroup: []
			};
		},
		created() {
			const keyGroup = [{
					id: 0,
					children: [{
						id: 0,
						value: "1"
					}, {
						id: 1,
						value: "2"
					}, {
						id: 2,
						value: "3"
					}]
				},
				{
					id: 1,
					children: [{
						id: 0,
						value: "4"
					}, {
						id: 1,
						value: "5"
					}, {
						id: 2,
						value: "6"
					}]
				},
				{
					id: 2,
					children: [{
						id: 0,
						value: "7"
					}, {
						id: 1,
						value: "8"
					}, {
						id: 2,
						value: "9"
					}]
				}
			];
			this.keyGroup = keyGroup;
		},
		methods: {
			tapKey(character) {
				//console.log(this);
				this.$emit("typeCharacter", character);
			},
			onComplete() {
				this.$emit("typeComplete");
			}
		}
	}
</script>

<style scoped lang="scss">
	.keyborder-panel {
		border-radius: 16px 16px 0 0;
	}

	.key-group {
		display: flex;
		justify-content: space-around;
		align-items: center;

		.key-group-item {
			padding-top: 25rpx;
			padding-bottom: 25rpx;
			background-color: #FFFFFF;
			width: 33%;
			text-align: center;
		}

		.key-group-item:nth-child(2n) {
			border-left: 1px dashed #C0C0C0;
			border-right: 1px dashed #C0C0C0;
		}

		.key-active {
			background-color: #d4e9ff;
		}
	}

	.key-group:nth-child(n+2) {
		border-top: 1px dashed #C0C0C0;
	}
</style>
