giftdetail.js 2.7 KB
// pages/goodtail/goodtail.js

var WxParse = require('../../wxParse/wxParse.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [

    ],
    indicatorDots: false,
    autoplay: false,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,
    ping: 1,
    goodid: '',
    goodtail: '',
    page: 1,
    commentlist: [],
    totalping:0

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goodid: options.goodid
    })
    this.getgoodtail();
    
  },

  getgoodtail() {
    let that = this;
    var url = 'goods/get_one';
    var params = {
      goods_id: that.data.goodid,

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        imgUrls: res.gift.images,
        goodtail: res
      })

      this.getgoodcomment()

      WxParse.wxParse('article', 'html', res.gift.content, that, 5);
    }).catch((err) => {

    })
  },

  //获取商品评论
  getgoodcomment() {
    let that = this;
    var url = 'comment/get_all';
    var params = {
      goods_id: that.data.goodtail.gift.id,
      page: that.data.page,
      pageNum: 10


    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        commentlist: that.data.commentlist.concat(res.data),
        totalping:res.total
      })



    }).catch((err) => {

    })
  },
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },

  comment(e) {
    this.setData({
      ping: e.currentTarget.dataset.id
    })

    if (this.data.ping == 1) {
      this.getgoodtail()
    } else {
      this.setData({
        page: 1,
        commentlist: []
      })

      this.getgoodcomment()

    }
  },

  //商品详情页
  gogood(){
    wx.redirectTo({
     
      url: '/pages/goodtail/goodtail?goodid='+this.data.goodid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let newpage = this.data.page;
    newpage++;
    this.setData({
      page: newpage
    })

    this.getgoodcomment()
  },

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

  }
})