<template>
  <div>
    <el-input v-model="data" :placeholder="placeholder" clearable @blur="updateDiyEvent">
      <template slot="append">
        <el-button @click.native="onClick">随机</el-button>
      </template>
    </el-input>
  </div>
</template>

<script>
import VueBus from '../../../../../utils/vue-bus'
export default {
  name: 'DkEventCreateInput',
  props: {
    value: {
      default: '',
      type: String
    },
    placeholder: {
      default: '',
      type: String
    },
    label: {
      default: '',
      type: String
    }
  },
  data() {
    return {
      data: ''
    }
  },
  computed: {},
  watch: {
    data() {
      this.$emit('input', this.data)
      this.updateDiyEvent()
    }
  },
  mounted() {
    this.data = this.value || ''
    if (!this.data) {
      this.onClick()
    }
  },
  methods: {
    updateDiyEvent() {
      VueBus.$emit('updateDiyEvent')
    },
    onClick() {
      this.data = this.randomString(6)
    },
    randomString(e) {
      e = e || 32
      var t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
      var a = t.length
      var n = ''
      for (var i = 0; i < e; i++) {
        n += t.charAt(Math.floor(Math.random() * a))
      }
      return n
    }
  }
}
</script>

<style scoped lang="scss">

</style>
