<template>
  <div id="verify">
    <span v-html="pic" @click="toCreated"></span>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex';
export default {
  name: 'verify',
  props: {
    value: { type: null, default: '' },
  },
  model: {
    prop: 'value',
    event: 'change', // 默认为input时间，此处改为change
  },
  components: {},
  data: () => ({
    pic: '',
    code: '',
  }),
  created() {
    this.toCreated();
  },
  computed: {},
  methods: {
    ...mapActions(['verifyOperation']),
    async toCreated() {
      this.$set(this, `code`, new Date().getTime());
      this.$emit('change', this.code);
      let result = await this.verifyOperation({ type: 'verify', data: { code: this.code } });
      if (`${result.errcode}` === '0') {
        this.$set(this, `pic`, result.data);
      }
    },
  },
};
</script>

<style lang="less" scoped>
img {
  width: 100%;
  height: 47px;
}
</style>
