groupBuyDetail.js 4.6 KB
// pages/groupBuyDetail/groupBuyDetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isFolded: true,
    imgUrls: ['../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png', '../../../images/img1.png'],
    id: '',
    list_info: {},
    rule: [],
    countdown: '',
    endDate2: '',
    banner:''
  },


  //获取banner
  getBanner() {
    let url = '/portal/Group/banner'
    app.post(url, {}, {}).then((res) => {
      // console.log('获取banner',res)
      this.setData({
        banner: res.info
      });
    })
  },

  //查看全部
  listMore(e) {
    this.setData({
      isFolded: !this.data.isFolded,
    })
  },

  listDetail() {
    let url = '/portal/Group/group_detail'
    let params = {
      id: this.data.id
    }
    let header = {
      "XX-Token": wx.getStorageSync('token')
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      this.setData({
        list_info: res.info,
        endDate2: res.info.over_time.replace(/-/g, "/")
      })
      this.countTime()
    })
  },

  countTime() {
    var that = this;
    var date = new Date();
    var now = date.getTime();
    var endDate = new Date(that.data.endDate2); //设置截止时间
    var end = endDate.getTime();
    var leftTime = end - now; //时间差                              
    var d, h, m, s, ms;
    if (leftTime >= 0) {
      d = Math.floor(leftTime / 1000 / 60 / 60 / 24);
      h = Math.floor(leftTime / 1000 / 60 / 60 % 24);
      m = Math.floor(leftTime / 1000 / 60 % 60);
      s = Math.floor(leftTime / 1000 % 60);
      ms = Math.floor(leftTime % 1000);
      ms = ms < 100 ? "0" + ms : ms
      s = s < 10 ? "0" + s : s
      m = m < 10 ? "0" + m : m
      h = h < 10 ? "0" + h : h
      that.setData({
        countdown: h + ":" + m + ":" + s,
      })
      //递归每秒调用countTime方法,显示动态时间效果
      setTimeout(that.countTime, 100);
    } else {
      console.log('已截止')
      that.setData({
        countdown: '00:00:00'
      })
    }

  },

  //团购规则
  getRule() {
    let url = '/wxapp/public/arc_group'
    let params = {}
    let header = {
      "XX-Token": wx.getStorageSync('token')
    }
    app.post(url, {}, {}).then((res) => {
      // console.log('团购规则', res)
      this.setData({
        rule: res
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      id: options.id
    })
    this.listDetail()
    this.getRule()
    this.getBanner()
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    let that = this;
    var group_id = this.data.id
    console.log(group_id)
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    var shareObj = {
      title: '科学队长', // 默认是小程序的名称(可以写slogan等)
      path: '/pages/my/takeGroupBuy/takeGroupBuy?group_id=' + group_id, // 默认是当前页面,必须是以‘/’开头的完整路径
      imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
      success: function(res) {
        if (res.errMsg == 'shareAppMessage:ok') {}
      },
      fail: function() {
        // 转发失败之后的回调
        if (res.errMsg == 'shareAppMessage:fail cancel') {
          // 用户取消转发
        } else if (res.errMsg == 'shareAppMessage:fail') {
          // 转发失败,其中 detail message 为详细失败信息
        }
      },
      complete: function() {
        // 转发结束之后的回调(转发成不成功都会执行)
      }
    }

    // 来自页面内的按钮的转发
    // if (option.from == 'button') {
    //   // 此处可以修改 shareObj 中的内容
    //   // shareObj.imageUrl = '/pages/shareimg/share.png'
    // }   // 返回shareObj

    return shareObj;
  },
})