input-price.vue 2.13 KB
<template>
  <div class="input-comp">
    <div class="input-wrapper">
     <div class="price-symbol">¥</div>
     <input ref="input" :value="value" class="tip" type="text" placeholder="定价需以9结尾,例如¥1299" @blur="onBlur"
            @change="onChange"></input>
    </div>
    <div class="num-wrapper" v-if="superSell">
     <i class="iconfont iconplus-minus icon-class" @click="onMinus"></i>
     <span class="icon-class count">{{num}}</span>
     <i class="iconfont iconi-add icon-class" @click="onAdd"></i>
   </div>
  </div>
</template>

<script>
export default {
  name: 'InputPrice',
  props: {
    value: {
      type: [Number, String],
      default: ''
    },
    num: {
      type: Number,
      default: 1
    },
    superSell: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      val: this.value
    };
  },
  methods: {
    onBlur() {
      this.$emit('on-blur');
    },
    onChange() {
      this.$emit('input', this.$refs.input.value);
    },
    onMinus() {
      if (this.num > 1) {
        const count = this.num - 1;

        this.$emit('on-num-change', { count, type: 'minus' });
      }
    },
    onAdd() {
      const count = this.num + 1;

      this.$emit('on-num-change', { count, type: 'add' });
    }
  },
  watch: {
    value(newVal) {
      this.val = newVal;
    },
  }
};
</script>

<style lang="scss" scoped>

.input-comp {
  display: flex;
}

.input-wrapper {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
  height: 120px;
  background: #f5f5f5;
}

.price-symbol {
  width: 40px;
  margin-left: 20px;
  margin-right: 10px;
  font-size: 40px;
  font-weight: bolder;
  line-height: 120px;
}

.tip {
  flex: 1;
  font-size: 56px;
  font-weight: 500;
  line-height: 80px;
  background: #f5f5f5;
}

::placeholder {
  color: #ccc;
  font-size: 28px;
  opacity: 1; /* Firefox */
}

.num-wrapper {
  width: 240px;
  height: 120px;
  margin-left: 10px;
  background: #f5f5f5;
  display: flex;
  justify-content: space-around;
  align-items: center;

  .icon-class {
    font-size: 40px;
    color: #999;
    font-weight: bold;
  }

  .count {
    color: black;
  }
}

</style>