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

  },

  options: {
    styleIsolation: 'shared'
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMGURL: IMG_URL,
    pMerchantId: '',
    totalProfit: 0,
    pageObj: {
      currentPage: 1,
      pageSize: 10
    },
    totalPages: -1,
    list: []
  },
  lifetimes: {
    attached() {
      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()
      this.setData({
        ['pageObj.currentPage']: 1,
        list: []
      })
      this.getClientApi(isPull)
    },
    getClientApi(isPull = false) {
      this.getProfit()
      this.getList()
      isPull && wx.$api.showToast('刷新成功')
      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')
    },
    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('packageOutput.summary', params)
    }
  }
})