<template>
	<view class="cu-stepper flex align-center">
		<button :disabled="mindis" @click="handler(-1)" class="cu-btn text-xxl">
			<text >-</text>
		</button>
		<input @input="input" :value="value" type="number" />
		<button :disabled="maxdis" @click="handler(1)" class="cu-btn text-xxl">+</button>
	</view>
</template>

<script>
export default {
	props: {
		value: { type: Number/String, value: 1 },
		max: { type: Number / String, value: 1000000 },
		min: { type: Number / String, value: 1}
	},
	computed:{
		mindis(){
			let min =this.min || 1;
			return this.value==min
		},
		maxdis(){
			let max=this.max || 1000000;
			return this.value==max
		}
	},
	data() {
		return {
			
		};
	},
	methods: {
		input(e) {
			let value= e.detail.value * 1;
			if (this.max ) value = value > this.max * 1 ? this.max * 1 : value;
			if (this.min) value = value < this.min * 1 ? this.min * 1 : value;
			this.$emit('change', parseInt(value));
		},
		handler(val) {
			let value=  this.value*1 || 1;
			value += val*1;
			if (this.max) value = value > this.max * 1 ? this.max * 1 : value;
			if (this.min) value = value < this.min * 1 ? this.min * 1 : value;
			this.$emit('change', value);
		}
	}
};
</script>

<style lang="scss" scoped>
.cu-stepper {
	input {
		background-color: #f0f0f0;
		width: 120upx;
		margin: 0 5upx;
		padding:0 10rpx;
		box-sizing: border-box;
		text-align: center;
		line-height: 65upx;
		height: 65upx !important;
		border-radius: 5upx;
	}
	button{
		box-sizing: border-box;
		height: 65upx !important;
		line-height: 65upx;
	}
}
</style>
