onShowMixin.js 1.18 KB
export default {
  data () {
    return {
      initStatus: false,
      searchTimeStatus: false
    }
  },
  props: {
    show: Boolean,
    searchTime: {
      type: Object,
      default: () => { }
    },
    pageId: {
      type: String,
      default: ''
    },
    pageData: {
      type: Object,
      default: () => { }
    },
  },
  computed: {
    businessType () {
      return this.pageData.businessType
    }
  },
  mounted () {
    let getData = this.getData
    this.getData = function () {
      getData.apply(this, arguments), this.searchTimeStatus = false
    }
  },
  watch: {
    show: {
      async handler (newVal) {
        if (newVal) {
          if (!this.initStatus || this.searchTimeStatus) {
            await this.getData()
            this.initStatus = true
          }
        }
      },
      immediate: true,
      deep: true
    },
    searchTime (n) {
      if (this.initStatus) {
        if (this.show) this.getData()
        else this.searchTimeStatus = true
      }
    },
    businessType: {
      handler (newVal) {
        if (this.show) {
          if (newVal && this.initStatus) this.getData()
        } else this.initStatus = false
      }
    }
  },
  methods: {
  }
}