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

  /**
   * 页面的初始数据
   */
  data: {
    num: 1, //数量
    current: 0,
    status: 0,
    nav: ['商品介绍', '规格参数', '售后保障'],
    mask: false,
    taocanlist:[]
  },
  num_change(e) {
    let num = Number(this.data.num)
    let type = e.currentTarget.dataset.type
    if (type == 1) {
      num++
      if (num > Number(this.data.info.sold)) {
        wx.showToast({
          title: '已到最大库存',
          icon: 'none'
        })
        return
      }
    } else {
      num--
      if (num < 1) {
        wx.showToast({
          title: '不能再少了',
          icon: 'none'
        })
        return
      }
    }
    this.setData({
      num: num
    })
  },

  // 跳到商品详情页
  look_more(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/shop_detail/shop_detail?id=' + id
    })
  },
  //添加购物车
  addshop() {
    let that = this
    let url = app.interface.addshop
    let params = {
      num: that.data.num,
      product_id: that.data.info.id
    }
    app.post(url, params).then((res) => {
      that.setData({
        "info.shop": Number(that.data.info.shop) + that.data.num,
        num: 1
      })
      wx.showToast({
        title: '加入成功',
        duration: 1500
      })
    })
  },
  // 立即购买
  purchaseNow() {
    let that = this
    let info = {
      shop_id: that.data.info.id,
      num: that.data.num
    }
    wx.navigateTo({
      url: '/pages/taocanpay/taocanpay?' + '&info=' + JSON.stringify(info) + '&id=' + that.data.info.id
    })
  },
  //去查看购物车
  go_car() {
    wx.switchTab({
      url: '/pages/shop_cart/shop_cart'
    })
  },
  //收藏
  colloct() {
    let url = app.interface.collect
    app.post(url, {
      id: this.data.info.id
    }).then((res) => {
      wx.showToast({
        title: !this.data.info.colloct ? '已收藏' : '取消收藏',
        icon: 'none',
        duration: 1000
      })
      this.setData({
        "info.colloct": !this.data.info.colloct
      })
    })
  },
  //轮播点
  getCurrent(e) {
    var current = e.detail.current
    this.setData({
      current
    })
  },
  //点击下面的导航
  clickNav(e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      status: index
    })
  },

  change_cover(e) {
    if (e.currentTarget.dataset.type) {
      this.setData({
        btn_type: e.currentTarget.dataset.type
      })
    }
    this.setData({
      mask: !this.data.mask
    })
  },



  // 获取页面信息
  get_info(id) {
    let url = '/combo/detail'
    let params = {
      combo_id: id
    }
    app.post(url, params).then((res) => {
      this.setData({
        info: res.msg.data,
        taocanlist:res.msg.product
      })
      WxParse.wxParse('contenta', 'html', res.msg.maincontent, this, 5)
      WxParse.wxParse('contenb', 'html', res.msg.guigecontent, this, 5)
      WxParse.wxParse('contenc', 'html', res.msg.shouhoucontent, this, 5)
    })
  },
  //去登录
  go_login() {
    wx.showModal({
      title: '提示',
      content: '请先登录',
      success(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/register/register',
          })
        } else if (res.cancel) {
        }
      }
    })
  },

  //判断是否登录
  judge_login() {
    if (!wx.getStorageSync("token") && (wx.getStorageSync('login') == 0 || !wx.getStorageSync('login'))) {
      this.setData({
        no_login: true
      })
    } else {
      this.setData({
        no_login: false
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_info(options.id)
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 登录判断
    this.judge_login()


  },

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

  },

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

  },

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

  },

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

  },

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

  }
})