client.js 4.13 KB
// pages/tab/output/components/client/client.js
import outputApi from '~/api/outputApi/index'
import { IMG_URL } from '~/utils/constantData'
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true
  },
  properties: {},

  options: {
    styleIsolation: 'shared'
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMGURL: IMG_URL,
    pMerchantId: '',
    totalProfit: 0,
    pageObj: {
      currentPage: 1,
      pageSize: 10
    },
    totalPages: -1,
    list: []
  },
  lifetimes: {
    attached() {
      wx.$eventbus.on('clientRefresh', res => {
        this.clientRefresh()
      })
      this.getPMerchantInfo()
      this.getClientApi()
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getPMerchantInfo() {
      let { userInfo } = wx.$storage.get()
      this.setData({
        pMerchantInfo: userInfo,
        pMerchantId: userInfo.subLoginUser.merchantId
      })
    },
    onBindRefresh() {
      this.clientRefresh(true)
    },
    clientRefresh(isPull = false) {
      this.getPMerchantInfo()
      console.log('clientRefresh');
      this.setData({
        ['pageObj.currentPage']: 1,
        list: []
      })
      this.getClientApi(isPull)
    },
    getClientApi(isPull = false) {
      this.getProfit()
      this.getList()
      isPull &&
        wx.$api.showToast({
          title: '刷新成功',
          icon: 'success'
        })
      if (this.data.pageObj.currentPage == 1) {
        this.setData({
          scrollTop: 0,
          triggered: false
        })
      }
    },
    getProfit() {
      outputApi.getMerchantTotal({ merchantId: this.data.pMerchantId }).then(res => {
        this.setData({
          totalProfit: res
        })
      })
    },
    getList() {
      outputApi.getCustomerPageList({ merchantId: this.data.pMerchantId, ...this.data.pageObj }).then(res => {
        var list = this.data.list
        list = list.concat(res.list)
        list.forEach((item, index) => {
          item.sceneList.forEach((k, idx) => {
            item['scene' + (idx + 1)] = item.sceneList[idx].flag
          })
          item.isOpenScene = item.sceneList.map(item => item.flag).some(item => item == true)
        })
        this.setData({
          list: list,
          totalPages: res.pages
        })
      })
    },
    onReachBottom() {
      if (this.data.totalPages != -1 && this.data.pageObj.currentPage == this.data.totalPages) {
        return true
      }
      this.setData({
        ['pageObj.currentPage']: this.data.pageObj.currentPage + 1
      })
      this.getClientApi()
    },
    handleJumpIdx() {
      wx.$router.go('pages.index')
    },

    async handleShare(e) {
      let { idx } = e.currentTarget.dataset
      var item = {
        activityId: this.data.list[idx].activityLastUnSharedInfo.id,
        activityName: this.data.list[idx].activityLastUnSharedInfo.activityName
      }
      wx.$api.showLoading('加载中...')
      outputApi
        .getPosterUrl({
          id: item.activityId
        })
        .then(res => {
          item.posterUrl = res
          this.setData({
            posterItem: item,
            isShowTip: false
          })
        })
        .catch(() => {
          wx.$api.showToast('下载海报失败')
        })
    },
    /**长按海报 */
    async longtouch(e) {
      console.log('长按海报', e)
      this.clientRefresh()
      let { activityId } = e.detail
      const res = await outputApi.reportPosterTrack({
        activityId
      })
    },
    handleJump(e) {
      let { idx } = e.currentTarget.dataset
      var currentItem = this.data.list[idx]
      var params = {
        merchantId: currentItem.merchantId,
        merchantName: currentItem.merchantName,
        scene1: currentItem.scene1,
        scene2: currentItem.scene2,
        scene3: currentItem.scene3,
        scene4: currentItem.scene4,
        sceneCodeList: currentItem.sceneList.map(item => item.sceneCode),
        pMerchantId: this.data.pMerchantId,
        pMerchantName: this.data.pMerchantInfo.subLoginUser.merchantName,
        isSuper: this.data.pMerchantInfo.isSuper
      }
      wx.$router.go('/packagesList/packageOutput/pages/summary', params)
    }
  }
})