charge.js 3.66 KB

Page({
  data: {
    loadOver: false,
    commodityList: [],
    loadingMore: false,
    pageParam: {
      appearance: 2,
      pageSize: 0,
      pageCount: 10
    }
  },

  onLoad: function (options) {
    this.toGetCommodity()
  },

  // 获取直充数据
  toGetCommodity() {
    let { pageParam, loadingMore, commodityList, loadOver } = this.data

    if (loadOver) {
      return
    }
    wx.p.wxApi.showLoading()
    wx.p.api.equityApi.lasteCommodity(pageParam).then(res => {
      if (!res) {
        this.setData({
          loadOver: true
        })
        wx.hideLoading()
        return
      }
      let tempArr = []
      res.map(item => {
        let newArr = []
        if (item && item.chargeGoddsList) {
          item.chargeGoddsList.forEach(ele => {
            ele.denominationList.forEach(info => {
              let tempObj = {
                productName: ele.productName,
                ...info
              }
              newArr.push(tempObj)
            })
          })
        }
        item.couponsGoodsList = newArr
        item.bgurl = this.matchImage(item.brandName)
        if (item.couponsGoodsList) {
          tempArr.push(item)
        }
        return item
      })
      if (loadingMore) {
        commodityList = commodityList.concat(tempArr)
      }
      this.setData({
        commodityList: loadingMore ? commodityList : tempArr,
        loadingMore: false,
        loadOver: false
      })
      wx.hideLoading()
    })
  },

  onReachBottom: function () {
    if (this.data.unauthorized) {
      return
    }
    let { pageParam } = this.data
    pageParam.pageSize++
    this.setData(
      {
        pageParam,
        loadingMore: true
      },
      () => {
        this.toGetCommodity()
      }
    )
  },
  // 直充品牌对应的图标
  matchImage(brandName){
    const commonBaseURL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/hmd/'
    const  ImageConfig = [{
      name: `qq音乐`,
      url: `${commonBaseURL}equity/QQ_music.png`
    }, {
      name: `WPS`,
      url: `${commonBaseURL}equity/WPS.png`
    }, {
      name: `qq阅读`,
      url: `${commonBaseURL}equity/QQ_read.png`
    }, {
      name: `爱奇艺`,
      url: `${commonBaseURL}equity/aiqiyi.png`
    }, {
      name: `百度网盘`,
      url: `${commonBaseURL}equity/baiduwp.png`
    }, {
      name: `哔哩哔哩`,
      url: `${commonBaseURL}equity/bili.png`
    }, {
      name: `凯叔讲故事`,
      url: `${commonBaseURL}equity/kaishu.png`
    }, {
      name: `酷狗音乐`,
      url: `${commonBaseURL}equity/kugou.png`
    }, {
      name: `芒果TV`,
      url: `${commonBaseURL}equity/mgTv.png`
    }, {
      name: `美团`,
      url: `${commonBaseURL}equity/mtdc.png`
    }, {
      name: `奈雪`,
      url: `${commonBaseURL}equity/naixue.png`
    }, {
      name: `瑞幸`,
      url: `${commonBaseURL}equity/ruixin.png`
    }, {
      name: `腾讯视频`,
      url: `${commonBaseURL}equity/tenxun.png`
    }, {
      name: `网易云`,
      url: `${commonBaseURL}equity/wangyiyun.png`
    }, {
      name: `优酷`,
      url: `${commonBaseURL}equity/youku.png`
    }, {
      name: `知乎`,
      url: `${commonBaseURL}equity/zhihu.png`
    }, {
      name: `作业帮`,
      url: `${commonBaseURL}equity/workjob.png`
    }, {
      name: `喜马拉雅`,
      url: `${commonBaseURL}equity/ximalaya.png`
    }, {
      name: `e袋洗`,
      url: `${commonBaseURL}equity/edaixi.png`
    }]
    brandName = brandName.toLowerCase()
    let url = 'https://img01.glsx.com.cn/weapp/resource/equity-h5-new/aiqiyi.png'
    ImageConfig.forEach(item => {
      if (brandName.indexOf(item.name.toLowerCase()) != -1) {
        url = item.url
      }
    })
    return url
  },
})