<template>
  <div class="input-label">
    <div class="label">{{label}}</div>
    <input
      v-if="!isText"
      class="input"
      :type="type"
      placeholder-class="placeholder"
      :placeholder="placeholder"
      @input="handleInput"
      :maxlength="maxlength"
      :disabled="disabled"
      :value="currentValue"
    >
    <div v-if="isText" :class="{
      'isText': true,
      'placeholder': !currentValue
    }">{{currentValue || placeholder}}</div>
    <div class="icon-right-aw" v-if="suffix"></div>
  </div>
</template>

<script>
export default {
  props: {
    label: {
      type: String,
      default: ''
    },
    value: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: 'text'
    },
    placeholder: {
      type: String,
      default: '请填写'
    },
    maxlength: {
      type: Number,
      default: 140
    },
    disabled: {
      type: Boolean,
      default: false
    },
    suffix: {
      type: Boolean,
      default: false
    },
    isText: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      currentValue: this.value
    }
  },
  watch: {
    value (val) {
      this.currentValue = val
    }
  },
  methods: {
    handleInput(e) {
      let value = e.target.value
      this.currentValue = value
      this.$emit('update:value',value)
    }
  }
}
</script>

<style lang="scss">
@import './input-label.scss';
</style>