123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- // pages/discountDetail/discountDetail.js
- var http = require('../../utils/http.js');
- var util = require('../../utils/util.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- discountDetail: {}, //活动详情
- discountId: '',
- hour: 0, //时
- min: 0, //分
- second: 0, //秒
- discountProdList: [], //限时特惠商品列表
- current: 1, // 当前页数
- pages: 1, // 总页数
- endTime: '', //结束时间
- timer: ''
- },
- // 获取活动详情
- getDiscountDet () {
- // 请求详情数据
- var _this = this;
- http.request({
- url: "/marking/discount/getDiscountByDiscountId/" + this.data.discountId,
- method: "GET",
- callBack: (res) => {
- _this.setData({
- discountDetail: res,
- endTime: res.endTime
- })
- _this.countTime()
- }
- })
- },
- // 获取限时特惠商品列表
- getDiscountProdList (cur) {
- wx.showLoading();
- var ths = this;
- http.request({
- url: "/marking/discount/prodList",
- data: {
- discountId: this.data.discountId, //活动id
- current: cur, //当前页
- size: 20
- },
- method: "GET",
- callBack: (res) => {
- var list = [];
- if (res.current == 1) {
- list = res.records;
- } else {
- list = ths.data.discountProdList;
- Array.prototype.push.apply(list, res.records);
- }
- this.setData({
- discountProdList: list,
- pages: res.pages,
- current: res.current
- })
- wx.hideLoading()
- }
- })
- },
- // 倒计时
- countTime () {
- // 获取当前时间
- let date = new Date()
- let now = date.getTime()
- // 设置截止时间
- let end = util.dateToTimestamp(this.data.endTime)
- // 时间差
- let leftTime = end - now
- // 定义变量 d,h,m,s保存倒计时的时间
- if (leftTime >= 0) {
- // 时
- let h = Math.floor(leftTime / 1000 / 60 / 60)
- // 分
- let m = Math.floor(leftTime / 1000 / 60 % 60)
- // 秒
- let s = Math.floor(leftTime / 1000 % 60)
- this.setData({
- hour: h < 10 ? '0' + h : h,
- min: m < 10 ? '0' + m : m,
- second: s < 10 ? '0' + s : s
- })
- } else {
- this.setData({
- hour: '00',
- min: '00',
- second: '00'
- })
- }
- // 等于0的时候不调用
- if (Number(this.data.hour) === 0 && Number(this.data.min) === 0 && Number(this.data.second) === 0) {
- return
- } else {
- // 递归每秒调用countTime方法,显示动态时间效果,
- this.setData({
- timer: setTimeout(this.countTime, 1000)
- })
- }
- },
- //跳转商品详情
- toDiscountProdDet (e) {
- var prodid = e.currentTarget.dataset.prodid;
- if (prodid) {
- wx.navigateTo({
- url: '/pages/prod/prod?prodid=' + prodid,
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const {
- discountId
- } = options
- this.setData({
- discountId
- })
- this.getDiscountDet()
- this.getDiscountProdList(1) //默认加载第一页
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- clearTimeout(this.data.timer)
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- if (this.data.current < this.data.pages) {
- this.getDiscountProdList(this.data.current + 1);
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|