// pages/productDetail/productDetail.js
var app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showHtml: false,
    reachBottom: false, // 标识是否触底
    showSkuPopup: false,
    btnText: '立即购买',
    baseImgUrl: app.globalData.imageUrl,
    swiperCurrent: 0,

    imageData: [{
      desc: "string",
      imageUrl: "/group3/M00/00/0B/Cv6CBF0RvcuAXoDUAA5M5vbNswU382.png",
      link: { linkId: "10", brandId: "2711", name: "会员服务", url: "5", type: 2, status: 0 },
      number: 1,
      redirectId: "10",
      type: 0
    }, {
      desc: "string",
      imageUrl: "/group3/M00/00/0B/Cv6CBF0RvcuAXoDUAA5M5vbNswU382.png",
      link: { linkId: "10", brandId: "2711", name: "会员服务", url: "5", type: 2, status: 0 },
      number: 1,
      redirectId: "10",
      type: 0
    },
      {
        desc: "string",
        imageUrl: "/group3/M00/00/0B/Cv6CBF0RvcuAXoDUAA5M5vbNswU382.png",
        link: { linkId: "10", brandId: "2711", name: "会员服务", url: "5", type: 2, status: 0 },
        number: 1,
        redirectId: "10",
        type: 0
      },
      {
        desc: "string",
        imageUrl: "/group3/M00/00/0B/Cv6CBF0RvcuAXoDUAA5M5vbNswU382.png",
        link: { linkId: "10", brandId: "2711", name: "会员服务", url: "5", type: 2, status: 0 },
        number: 1,
        redirectId: "10",
        type: 0
      }],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  swiperChange(e) {
    console.log(e)
    this.setData({
      swiperCurrent: e.detail.current
    })
  },

  addCart: function (event) {
    this.setData({
      showSkuPopup: true,
      showSkuPopupType: 'cart'
    })
    // 商品加入购物车
    // xm_bi.Event.stat("skuAddToCart", { "amount":"666","skuId":'abcd1234'});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 页面touchstart事件
  pageTouchStart: function (e) {
    if (this.data.showHtml) {
      return
    }
    this.setData({
      reachBottom: false,
      startTouchY: null
    })
  },

  // 页面touchend事件
  pageMoveEnd: function (e) {
    if (this.data.showHtml) {
      return
    }
    if (this.data.startTouchY - e.changedTouches[0].pageY >= 50) {
      this.setData({
        showHtml: true,
        scrollTips: ''
      })
    }
  },

  // 页面touchmove事件
  pageMove: function (e) {
    if (this.data.showHtml) {
      return
    }
    wx.createSelectorQuery().selectViewport().scrollOffset((pageRes) => {
      wx.createSelectorQuery().select('.product-container').fields({
        size: true
      }, (res) => {
        if (res.height >= app.globalData.systemInfo.windowHeight + pageRes.scrollTop) {
          this.setData({
            reachBottom: true
          })
        } else {
          if (this.data.reachBottom) {
            this.setData({
              reachBottom: false
            })
          }
        }
        if (this.data.startTouchY == null) {
          this.setData({
            startTouchY: e.changedTouches[0].pageY
          })
        }
      }).exec()
    }).exec()
  },



})