<template>
  <div :class="inline ? 'inline' : ''" class="QdmInputMain">
    <div v-if="type === 'text'" class="QdmInput">
      <span :style="'width:' + colSpan + 'px;text-align:' + align + ';'"><i v-if="must">*</i>{{ name }}</span>
      <el-input
      	v-if="onkeyupNumber"
        :class="col"
        :placeholder="placeholder"
        :disabled="disabled"
        v-model="inputValue"
        @keyup.enter.native="keyupEnter"
        onkeyup="value=value.replace(/[^\d.]/g,'')"
        :maxlength="maxlength"
        @change="inputChange">
      </el-input>
      <el-input
      	v-else
        :class="col"
        :placeholder="placeholder"
        :disabled="disabled"
        v-model="inputValue"
        :maxlength="maxlength"
        @keyup.enter.native="keyupEnter"
        @change="inputChange">
      </el-input>
    </div>
    <div v-if="type === 'textarea'" class="QdmInput QdmInputTextarea">
      <span :style="'width:' + colSpan + 'px;text-align:' + align + ';'"><i v-if="must">*</i>{{ name }}</span>
      <el-input
        :class="col"
        :placeholder="placeholder"
        type="textarea"
        :disabled="disabled"
        v-model="inputValue"
        :maxlength="maxlength"
        @change="inputChange">
      </el-input>
    </div>
  </div>
</template>
<script>
export default {
  name: "QdmInput",
  props: {
    name: {
      type: String,
      default: ''
    },
    value: {
      type: [ Number, String ],
      default: ''
    },
    placeholder: {
      type: String,
      default: '请输入'
    },
    col: {
      type: String,
      default: 'small'
    },
    colSpan: {
      type: Number,
      default: 60
    },
    align: {
    	type: String,
      default: 'right'
    },
    inline: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'text'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    must: {
      type: Boolean,
      default: false
    },
    onkeyupNumber: {
    	type: Boolean,
      default: false
    },
    maxlength: {
    	type: Number,
      default: 50
    }
  },
  data() {
    return {
      inputValue: this.value
    }
  },
  methods: {
    inputChange(val) {
      this.$emit('inputReturn', val)
    },
    keyupEnter() {
    	this.$emit('keyupEnterReturn')
    }
  },
  watch: {
  	value(val) {
  		this.inputValue = val
  	}
  }
}
</script>
<style lang="less">
.inline {
  float: left;
}
.QdmInputMain {
	margin-bottom: 8px;
	height: 30px;
}
.QdmInput {
  margin-right: 10px;
  height: 30px;
  &.QdmInputTextarea {
    min-height: 48px;
  }
  >span {
    display: block;
    height: 30px;
    float: left;
    line-height: 30px;
    padding-right: 8px;
    font-size: 12px;
    >i {
      color: #F5222D;
      margin-right: 5px;
      padding-left: 3px;
    }
  }
  .el-input, .el-textarea {
    float: left;
    font-size: 12px;
    line-height: 30px;
    .el-input__inner {
      height: 30px;
      line-height: 30px;
    }
    &.large {
      width: 320px;
    }
    &.medium {
      width: 250px;
    }
    &.small {
      width: 180px;
    }
    &.mini {
      width: 100px;
    }
  }
}
</style>