<template>
  <div class="module">
    <div :class="className">
      <span class="spanTitle1">{{ title }}</span>
      <van-field
        ref="inp"
        rows="1"
        autosize
        v-model="internalValue"
        v-bind="$attrs"
        type="textarea"
        @focus="focus"
        @blur="blur"
        @input="ins"
      />
      <b v-if="verify" class="verify">*</b>
    </div>
    <p class="reminder" v-if="reminder">当前项为必填项</p>
  </div>
</template>

<script>
export default {
  props: ['title', 'value', 'verify'],
  name: 'Input',
  watch: {
    value (cur, old) {
      if (!cur && this.verify) {
        this.reminder = true
        this.internalValue = ''
        this.className = 'el_input_focusTrue'
      }
      if (cur) {
        this.internalValue = cur
        this.blur()
      }
    }
  },
  data () {
    return {
      className: 'el_input_focus',
      internalValue: this.value,
      reminder: false
    }
  },

  mounted () {
    if (this.value) {
      this.className = 'el_input_focus1'
      this.reminder = false
    }
  },

  methods: {
    ins (val) {
      this.$emit('input', val)
    },
    focus () {
      if (!this.value || this.value === '@#%__+!') {
        this.className = 'el_input_blur'
      }
    },
    blur () {
      if (this.verify) {
        if (this.value) {
          this.className = 'el_input_focus1'
          this.reminder = false
        } else {
          this.reminder = true
          this.className = 'el_input_focusTrue'
        }
      } else {
        if (this.value) {
          this.className = 'el_input_focus1'
        } else {
          this.className = 'el_input_focus'
        }
      }
    }
  }
}
</script>

<style lang="less" scoped></style>
