/**version-1.0*/
let tmixins = {};
import PopupManager from 'element-ui/src/utils/popup/popup-manager.js'
tmixins = {
  name: 'baseAlert',
  props: {},
  created() {
    if(this.$baseEventBus.isMobile){
      this.zIndex = PopupManager.nextZIndex();
    }
  },
  data() {
    return {
      title: this.$t2('提示', 'components.baseAlert.title'),
      content: "",
      showWrap: false,
      zIndex:null
    }
  },
  beforeDestroy() {
    this.removeEnterEvent();
  },
  methods: {
    closeDialog() {
      this.showWrap = false;
      this.removeEnterEvent();
      this.resolve();
    },
    keyDown(e) {
      e.stopPropagation();
      if (e.keyCode === 13 || e.keyCode === 27) {
        this.closeDialog();
      }
    },
    addEnterEvent() {
      window.addEventListener('keydown', this.keyDown, true);
    },
    removeEnterEvent() {
      window.removeEventListener('keydown', this.keyDown, true);
    },
    showMsgBox: function () {
      let content = (this.content ?? "") + "";
      if(content){
        this.content = content.replace(/(\r\n|\n|\r)/gm, "<br/>");
      }
      this.showWrap = true;
      this.removeEnterEvent();
      this.addEnterEvent();
      this.$nextTick(() => {
        if (this.$refs.hbtn) {
          this.$refs.hbtn.focus();
          this.$refs.hbtn.blur();
        }
      });
      this.promise = new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
      // 返回promise对象
      return this.promise;
    }
  }
};

export const mixins = tmixins
