getMerchantListMixin.js 1.9 KB
export default {
  data () {
    return {
      merchantObj: {
        nothing: false,
        data: [],
        currentPage: 1,
        name: '',
        loading: false,
        total: 0
      }
    }
  },
  mounted () {
  },
  methods: {
    selectFocus () {
      const { configForm } = this
      if (!configForm.merchantId) {
        this.merchantObj.data = []
        this.merchantObj.name = ''
        this.merchantObj.currentPage = 1
        this.getMerchantList()
      }
    },
    onReachBottom () {
      const { total, currentPage } = this.merchantObj
      if (Math.ceil(total / 50) > currentPage) {
        this.merchantObj.currentPage += 1
        this.getMerchantList()
      } else this.merchantObj.nothing = true
    },
    remoteMethod (val) {
      this.merchantObj.name = val
      if (val) {
        this.merchantObj.loading = true
        this.configForm.merchantId = ''
        this.merchantObj.nothing = false
        this.merchantObj.data = []
        this.merchantObj.currentPage = 1
        this.getMerchantList(val)
      }
    },
    async getMerchantList () {
      const { currentPage, data, name } = this.merchantObj,
        { list, total } = await this.$apis.redenvelope.getRedEnvelopeMerchantList({
          currentPage,
          merchantName: name
        })
      this.merchantObj.total = total
      list && list.map(e => {
        data.push({
          confId: e.merchantNo,
          confName: e.merchantName,
        })
      })
      this.merchantObj.data = data
      this.merchantObj.loading = false
    },
  },
  directives: {
    'reachbottom': {
      inserted (el, binding) {
        const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
        SELECTWRAP_DOM.addEventListener('scroll', function () {
          const condition = (this.scrollHeight - this.scrollTop) <= this.clientHeight
          if (condition) binding.value()
        })
      }
    }
  },
}