let modules;

modules = {
  props: ["value"],
  data() {
    return {
      snStatus: false,
      editSn: ''
    };
  },
  computed: {
    showSn: {
      get() {
        let value = this.value || [];
        return value.join(',');
      },
      set(val) {
        let value = val ? val.split('\n').filter(item => item) : [];
        this.$emit('input', value);
      }
    }
  },
  created() {},
  methods: {
    open() {
      this.editSn = this.value && this.value.length ? this.value.join('\n') : '';
      // this.snStatus = true;
      this.$nextTick(() => {
        this.$refs.textarea.focus();
      });
    },
    textareaBlur(event) {
      if (event.relatedTarget && event.relatedTarget.__vue__ == this.$refs.confirmBtn) {
        this.confirm();
      } else {
        this.cancle();
      }
    },
    cancle(event) {
      this.snStatus = false;
    },
    confirm(event) {
      let value = this.editSn.split('\n').filter(item => item);
      this.snStatus = false;
      this.$nextTick(() => {
        this.$emit('input', value);
        this.$emit('confirm', value);
      })
    },
    clear() {
      this.snStatus = false;
      this.$nextTick(() => {
        this.$emit('input', []);
        this.$emit('clear');
      });
    }
  }
};

export default modules;
