<template>
	<view class="main">
		<uni-icons type="minus-filled" size="20" color="#A67A54" @click="numReduce"></uni-icons>
		<!-- <text class="buy-select">{{number}}</text> -->
		<!-- <u-input
		  v-model="number"
		  type="number"
		  height="40"
		  :placeholder="placeholder"
		  :clearable="false"
		  :disabled="isDisabled"
		  input-align="center"
		  :custom-style="{width:'45px'}"
		  @input="onKeyInput"/> -->
		 <input class="uni-input" v-model="number" :type="isInt?'number' : 'digit'" :disabled="isDisabled" :placeholder="placeholder" @input="onKeyInput" >
		<uni-icons type="plus-filled" size="20" color="#A67A54" @click="numPlus"></uni-icons>
	</view>
</template>

<script>
	export default {
		props: {
			// number: {
			// 	default: 1
			// },
			isDisabled: {
				default: false
			},
			isInt: {
				default: true
			},
			placeholder: {
				default: ''
			},
			step: {
				default: 1
			},
			minNum: {
				default: 0.01
			}
		},
		data() {
			return {
			    number: 1,
			}
		},
		methods: {
			onKeyInput(event) {
				// uniapp的input用这个
				let i = event.target.value
				// u-view的input用这个
				// let i = event
				let num = i.charAt(i.length-1)
				var reg=new RegExp("^[0-9]*$")
				if(!reg.test(num)) {
					this.number =  i.slice(0,-1)
				} else {
					this.number = i
				}
				this.$emit('getNum',this.number);
			},
			numPlus() {
			    this.number = (Number(this.number) + Number(this.step))
				this.$emit('getNum',this.number);
			},
			numReduce() {
			    if ((Number(this.number) - Number(this.step)) >= Number(this.minNum)) {
				    this.number = (Number(this.number) - Number(this.step))
			    }
				this.$emit('getNum',this.number);
			}
		}
	}
</script>

<style>
</style>
<style lang="less" scoped>
	.main {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		.uni-input {
			height: 40px;
			width: 45px;
			text-align: center;
		}
	}
</style>
