index.vue 2.29 KB
<template>
  <div>
    <div class="input-number-range" :class="{ 'is-disabled': disabled }">
      <div class="flex">
        <div class="from">
          <el-input ref="input_from" v-model="formData[keyObj.from]" :disabled="disabled" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" placeholder="" @input="handleInputChangeFrom"></el-input>
        </div>
        <div class="center">
          <span>至</span>
        </div>
        <div class="to">
          <el-input ref="input_to" v-model="formData[keyObj.to]" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" :disabled="disabled" placeholder="" @input="handleInputChangeTo"></el-input>
        </div>
        <div class="unit">
          <span>元</span>
        </div>
      </div>
    </div>
  </div>
</template>

  <script>
export default {
  name: 'InputNumberRange',

  props: {
    // 是否禁用
    disabled: {
      type: Boolean,
      default: false
    },

    formData: {
      type: Object,
      default: () => {
        return {}
      }
    },

    keyObj: {
      type: Object,
      default: () => {
        return {
          from: 'a',
          to: 'b'
        }
      }
    }
  },

  data() {
    return {}
  },

  methods: {
    // from输入框change事件
    handleInputChangeFrom(value) {
      // let from = this.formData[this.keyObj.from]
      // let to = this.formData[this.keyObj.to]
      // if(from > to){
      //   this.formData[this.keyObj.to] = from
      // }
    },

    // to输入框change事件
    handleInputChangeTo(value) {
      // let from = this.formData[this.keyObj.from]
      // let to = this.formData[this.keyObj.to]
      // if(from > to){
      //   this.formData[this.keyObj.to] = from
      // }
    }
  }
}
</script>
  <style lang="scss" scoped>
.input-number-range {
  background-color: #fff;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
}
.flex {
  display: flex;
  flex-direction: row;
  width: 100%;
  justify-content: center;
  align-items: center;
  /deep/ .el-input .el-input__inner {
    border: 0px;
    margin: 0;
    padding: 0 10px;
    background-color: transparent;
  }
  .center {
    margin-top: 1px;
    color: #666;
  }
  .unit {
    margin-right: 10px;
    color: #666;
  }
}
.is-disabled {
  background-color: #eef0f6;
  border-color: #e4e7ed;
  color: #c0c4cc;
  cursor: not-allowed;
}
</style>