<template>
  <md-field :class="{messageClass,isInput:type==undefined,isTextArea:type=='textarea'}">
    <label>{{label}}</label>
    <span class="md-prefix" v-if="isSearch"><img src="../../../assets/currency/search.svg" class="searchImg"
                                                 @click="searchInfo"></span>
    <md-textarea v-model="currentValue" @input="inputload" :required="required" v-if="type=='textarea'" @blur="blurs"
                 :placeholder="placeholder" :disabled="disabled"></md-textarea>
    <md-input v-model="currentValue" @input="inputload" :required="required" v-if="type=='number'" type="number"
              @blur="blurs" :placeholder="placeholder" :disabled="disabled"></md-input>
    <md-input v-model="currentValue" @input="inputload" :required="required" v-if="type==undefined" @blur="blurs"
              :placeholder="placeholder" :disabled="disabled"></md-input>
    <span class="md-suffix" v-if="isSuffix">{{isSuffix}}</span>
    <span class="md-error">{{error}}</span>
  </md-field>
</template>

<script>
  import Vue from 'vue'
  import {MdField} from 'vue-material/dist/components'
  Vue.use(MdDialog)
  import {
    postApi,
    getApi
  } from "../../../api/commonApi"
  export default {
    name: "lbButton",
    props: {
      value: {
        type: [String, Number], // 必须要使用value
        default: '',
      },
      label: {},
      type: {},
      required: {},
      error: {},
      placeholder: {},
      isSearch: {},
      isSuffix: {},
      disabled: {}
    },
    data() {
      return {

        currentValue: this.value,
        hasMessages: false
      }
    },
    components: {},
    watch: {
      value(val) {
        // this.setCurrentValue(val);
        this.currentValue = val;

      }
    },
    computed: {
      messageClass() {
        return {
          'md-invalid': this.hasMessages
        }
      }
    },
    mounted() {
    },
    created() {
    },
    methods: {
      inputload(event){
        // let value = event.target.value;
        this.$emit('input', this.currentValue)
      },
      blurs() {
        this.$emit('blurs')
      },
      setCurrentValue(value) {
        console.log(value)
        if (value === this.currentValue) return;
        this.currentValue = value;
      },

      //点击搜索
      searchInfo() {
        this.$emit('searchInfo')
      }

    }
  }
</script>

<style scoped>
  @import 'lbInput.css';
</style>
