<template>
	<view class="cnb adfac">
		<view class="cnb-btn l" @click="valueChange(1)">-</view>
		<view class="cnb-input">
			<u-input :min="min" v-model="value" @change="e=>valueChange(3,e)" @blur="valueBlur" border="none" fontSize="30rpx" color="#002846"></u-input>
		</view>
		<view class="cnb-btn r" @click="valueChange(2)">+</view>
	</view>
</template>

<script>
	export default {
		props:{
			min:{
				typeof:Number,
				default:0
			},
			number:{
				typeof:Number,
				default:0
			}
		},
		data(){
			return {
				value:0
			}
		},
		mounted() {
			this.value = this.number;
		},
		methods:{
			valueChange(type,e){
				if(type===1){
					if(this.value<=this.min) return this.$showToast(`当前限制最小值为${this.min}`)
					this.value--;
				} 
				else if(type===2) this.value++;
				else if(type===3) this.value = e;
				this.$emit('valChange',this.value)
			},
			valueBlur(e){
				if(e<=this.min){
					this.value = this.min;
					return this.$showToast(`当前限制最小值为${this.min}`)
				} 
				this.value = e;
				this.$emit('valChange',this.value)
			}
		}
	}
</script>

<style scoped lang="scss">
	
	.cnb{
		background: #FFFFFF;
		height: 64rpx;
		border-radius: 10rpx;
		border: 2rpx solid #E5E7EB;
		&-btn{
			width: 54rpx;
			height: 64rpx;
			background: #F5F8FA;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 30rpx;
			color: #002846;
			line-height: 64rpx;
			text-align: center;
			&.l{
				border-radius: 10rpx 0rpx 0rpx 10rpx;
			}
			&.r{
				border-radius: 0rpx 10rpx 10rpx 0rpx;
			}
		}
		&-input{
			width: 70rpx;
			padding: 0 20rpx;
		}
	}
</style>