discovery.js 3.12 KB
// pages/tab/discovery/discovery.js
import { discoveryApi, commonApi, indexApi } from '../../../api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: ['直播广场'],
    count: 0,
    pageNum: 1,
    zoneList: []
  },
  changeTab(e) {
    let { zoneList } = this.data
    let count = e.detail
    this.setData({
      count,
      list: [],
      pageNum: 1,
      flag: false,
      zoneId: count != 0 ? zoneList[count - 1].id : ''
    })
    wx.nextTick(() => {
      wx.$util.showLoading('加载中...')
      if (count != 0) this.getZoneGoodsPage()
      else this.getLiveList()
    })
  },
  jump(e) {
    let item = e.detail
    if (item.dataType == 3) {

    } else {
      wx.$router.go('postsDetail', item.share.id)
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.$util.showLoading('加载中...')
    this.getZoneInfo()
    this.getLiveList()
  },
  getZoneInfo() {
    discoveryApi.getZoneInfo(1).then(data => {
      let { tab, zoneList } = this.data
      data.map(e => {
        tab.push(e.zoneName)
        zoneList.push(e)
      })
      this.setData({
        tab,
        zoneList
      })
    })
  },
  getLiveList() {
    indexApi.getLiveList().then(data => {
      this.setData({
        list: data.list,
        flag: true
      })
      wx.hideLoading()
    })

  },
  getZoneGoodsPage() {
    let params = {
      zoneIdList: [this.data.zoneId],
      pageNum: this.data.pageNum,
      dataTypeList: [3, 4]
    }
    let { list } = this.data
    let total = 0
    commonApi.search(params).then(data => {
      total = data.total
      this.setData({
        list: [...list, ...data.list],
        total,
        flag: true
      })
      wx.hideLoading()
    })
  },
  intoLiveRoom(e) {
    console.log(e)
    let { item: {
      roomId
    } } = e.currentTarget.dataset
    let customParams = encodeURIComponent(JSON.stringify())
    wx.navigateTo({
      url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}`//&customParams=${customParams}
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let { pageNum, total, } = this.data
    wx.$util.onReachBottom({
      pageNum,
      total
    }, () => {
      this.getZoneGoodsPage()
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const merchantId = wx.$util.getStorageSync('srcm_shopmall_merchant_id')
    let storeCode = wx.$util.getStorageSync('srcm_shopmall_store_code')
    let path = this.route
    if (merchantId) path = `${path}?merchantId=${merchantId}&storeCode=${storeCode || ''}`
    return {
      path
    }
  }
})