index.js 4.51 KB
import {
  kfMixin,
} from '~/mixins/index'
Page({
  behaviors: [kfMixin],
  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    goodsIndex: 0,
    customerlist: [],
    navStyle : "background-color: transparent;",
    animationData: {},
    specialSaleArr: [{
      id: 1,
      url: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/points-mall/index/index-bg.png',
      saleName: '九阳专场'
    }, {
      id: 2,
      url: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/points-mall/login/login-bg.png',
      saleName: '维达专场'
    }],
    tab: [{
      id: '1',
      label: '我能兑换'
    }, {
      id: '',
      label: '全部'
    }, {
      id: '2',
      label: '100积分以下'
    }, {
      id: '3',
      label: '100-200积分'
    }, {
      id: '4',
      label: '200-300积分'
    }],
    subTab: [{
      id: '',
      label: '全部品类'
    }, {
      id: '1',
      label: '汽车保养'
    }, {
      id: '2',
      label: '车载设备'
    }, {
      id: '3',
      label: '个护清洁'
    }, {
      id: '4',
      label: '休闲零食'
    }],
    goodsList: [{
      goodsId: '1',
      goodsUrl: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/points-mall/login/login-img.png',
      goodsName: 'Tempo得宝手帕纸',
      salePoints: '10',
      marketPrice: '15.9'
    }, {
      goodsId: '2',
      goodsUrl: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/points-mall/login/login-img.png',
      goodsName: '维达抽纸超韧整箱M码家用实惠装面巾纸',
      salePoints: '69.9',
      marketPrice: '79.9'
    }, {
      goodsId: '3',
      goodsUrl: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/points-mall/index/index-bg.png',
      goodsName: '5100西藏冰川矿泉水整箱',
      salePoints: '10',
      marketPrice: '15.9'
    }, {
      goodsId: '4',
      goodsUrl: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/points-mall/login/login-img.png',
      goodsName: '洁柔Face纸巾抽纸3层',
      salePoints: '10',
      marketPrice: '15.9'
    }]
  },

  onReady() {
    this.startAnimation();
  },
  // 顶部公告动画
  startAnimation: function() {
    const query = wx.createSelectorQuery()
    query.select('.text-container').boundingClientRect()
    query.select('.text').boundingClientRect()
    query.exec((res) => {
      const containerWidth = res[0]?.width
      const textWidth = res[1]?.width
      // 只有文字宽度超过容器宽度时才滚动
      if (textWidth > containerWidth) {
        const animation = wx.createAnimation({
          duration: (textWidth / 30) * 1000, // 根据文字长度调整滚动时间
          timingFunction: 'linear',
          delay: 0
        })
        animation.translateX(-textWidth).step()
        this.setData({
          animationData: animation.export()
        })
        // 设置循环
        setTimeout(() => {
          this.resetAnimation();
        }, (textWidth / 30) * 1000)
      }
    })
  },
  
  resetAnimation: function() {
    const animation = wx.createAnimation({
      duration: 0,
      timingFunction: 'linear',
      delay: 0
    })
    animation.translateX(0).step()
    this.setData({
      animationData: animation.export()
    })
    setTimeout(() => {
      this.startAnimation()
    }, 50)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  // 跳转积分中心
  handleToPointCenter() {
    wx.p.router.go('/packageIndex/pages/integral/index/index')
  },
  // 查看公告政策详情
  policyDetail() {
    wx.p.router.jumpH5(`https://fgk.chinatax.gov.cn/zcfgk/c100012/c5241472/content.html`)
  },
  // 跳转专场
  handleSpecialSale(e) {
    console.log(e, 2222)
    let { target } = e.currentTarget.dataset
    wx.p.router.go('/packageIndex/pages/SpecialSale/SpecialSale', target)
  },
  changeTab(e) {
    this.setData({
      goodsIndex: e.detail
    })
  },
  toIntegral(){
    wx.p.router.go('/packageIndex/pages/integral/index/index')
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

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

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

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onReachBottom() {
    let {
      pageNum,
      total
    } = this.data
    wx.p.util.onReachBottom({
      pageNum,
      total,
    }, () => {
      this.getActivityList()
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})