<template>
   <div class="control has-icons-left">
  <input :class="`input ${error? 'is-danger' : ''} ${disabled? 'has-text-black' : ''}`" type="text" 
  :placeholder="placeholder || ''" v-model="value" @keyup="doCheck" :disabled="disabled || false">
  <span class="icon is-left">
    <SvgIcon v-bind="{name: 'phone.png', type: 'gray', size: 20}"></SvgIcon>
  </span>
</div>
</template>
<script>
export default {
  props: ['record', 'attr', 'placeholder', 'disabled'],
  data() {
    return {
      value: this.record[this.attr]? this.$copy(this.record[this.attr]) : undefined,
      error: undefined
    }
  },
  watch: {
    record: function(newVal) {
      this.value = this.record[this.attr]? this.$copy(this.record[this.attr]) : undefined
    }
  },
  methods: {
    doCheck() {
      if(this.$empty(this.value)) {
        this.value = undefined
        this.error = false
        return this.$emit('phone', null)
      }
      let check = this.$errPhone(this.value)
      this.error = check? true : false
      this.$emit('phone', this.value)
    }
  }
}
</script>