allEquity.js 2.81 KB


Page({
  /**
   * 页面的初始数据
   */
  data: {
    cHeight: 600,
    curIndex: 0,
    equityList: [],
    to: 'to-0'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let system = wx.getSystemInfoSync()
    this.getAllMerchantList()
    this.setData({
        cHeight: system.windowHeight
      })
    if (options.showToast) {
      setTimeout(()=>{
         wx.p.wxApi.showToast('原商品及品牌均已下架,您可查看其他权益商品')
      },500)
    }
  },
  computerHeight() {
    let query = wx.createSelectorQuery().in(this)
    let heightArr = []
    let s = 0
    query
      .selectAll('.scroll_item_wrap')
      .boundingClientRect(react => {
        react.forEach(item => {
          s += item.height
          heightArr.push(s)
        })
        this.data.heightArr = heightArr
      })
      .exec()
    query
      .select('.right_wrap')
      .boundingClientRect(res => {
        this.data.rightHeight = res.height
      })
      .exec()
  },
  scrollViewFn(e) {
    let scrollTop = e.detail.scrollTop
    let scrollArr = this.data.heightArr
    if (this.data.isClickLeft) {
      this.data.isClickLeft = false
      return
    }
    if (scrollTop >= scrollArr[scrollArr.length - 1] - this.data.rightHeight) {
      return
    } else {
      for (let i = 0; i < scrollArr.length; i++) {
        if (scrollTop >= 0 && scrollTop < scrollArr[0]) {
          this.setData({
            curIndex: 0
          })
        } else if (scrollTop >= scrollArr[i - 1] - 110 && scrollTop < scrollArr[i] - 110) {
          this.setData({
            curIndex: i
          })
        }
      }
    }
  },
  slectLeftItem(e) {
    const { index } = e.currentTarget.dataset
    this.setData({
      curIndex: index,
      to: `to-${index}`,
      isClickLeft: true
    })
  },
  getAllMerchantList() {
    let {merchantId} = wx.p.storage.get('merchant_info')
    let para = {
      merchantId
    }
    wx.p.api.equityApi.getAllEquity(para).then(res => {
      let tempArr = res.goodsServiceList
      this.setData(
        {
          equityList: tempArr
        },
        () => {
          this.computerHeight()
        }
      )
    })
  },
  toNewPage(e) {
    const { item } = e.currentTarget.dataset
    let url = ''
   if (item.appearance == 1) {
      let param = {
        supplier: item.supplier,
        brandName: item.brandName,
        location: true
      }
      wx.p.router.go('/packageEquity/pages/commodity/detail/detail',{
        param,
        notIntercept: true
      })
    } else if (item.appearance == 2) {
      let param = {
        supplier: item.supplier,
        brandName: item.brandName,
        icon: item.equityIcon
      }
      wx.p.router.go('/packageEquity/pages/commodity/chargeDetail/chargeDetail',{
        param,
        notIntercept: true
      })
    }
  }
})