<template>
  <div class="input-number">
    <div class="sub" @click="sub">-</div>
    <input class="input" type="number" @change="changeInput" v-model="number">
    <div class="add" @click="add">+</div>
  </div>
</template>

<script>
  export default {
    props: {
      value:{
        type:Number,
        default:0
      },
      max: {
        type:Number,
        default:1000000
      },
      min: {
        type:Number,
        default:0
      }
    },
    data () {
      return {
        number: this.value
      }
    },
    methods: {
      add () {
        if(this.number > this.max) {
          return
        }
        this.number ++
        this.$emit('input', this.number)
      },
      sub () {
        if(this.number <= this.min) {
          return
        }
        this.number --
        this.$emit('input', this.number)
      },
      changeInput() {
        this.$emit('input', Number(this.number))
      }
    }
  }
</script>

<style scoped>
.input-number {
  display: flex;
}
.input {
  width: 40px;
  height: 25px;
  border-top: 1px solid #DDDDDD;
  border-bottom: 1px solid #DDDDDD;
  border-left: none;
  border-right: none;
  text-align: center;
}
.sub, .add {
  width: 25px;
  height: 25px;
  border: 1px solid #DDDDDD;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #AAAAAA;
  font-size: 20px;
  user-select:none;
}
</style>