detail_1.js 7.4 KB
// pages/kind/detail_1/detail_1.js
const app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    index: 1,
    showModal: false,
    hide: false,
    num: 1,
    detail_id: null,
    detailCon: {},
    assess: [],
    id:'',
    days: 0,
    hours: 0,
    minutes: 0,
    seconds: 0,
    over:true,
    short:[],
    seemore:true,
    images:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      detail_id: options.id,
      id:options.id
    })
    this.detaiFun(options.id)
    
  },
  slectpic(e){
    let that=this;
    console.log(e)
    let idx=e.currentTarget.dataset.idx;
    let newassess = that.data.assess;
    for (var i = 0; i < newassess.length;i++){
        if(i==idx){
           that.setData({
             images: newassess[i].img
           }) 
        }

    }

    console.log(that.data.images)
  },

  // 图片预览
  previewImage: function (e) {

    let that = this;
    console.log(e)
    let idx = e.currentTarget.dataset.idx;
    let newassess = that.data.assess;
    for (var i = 0; i < newassess.length; i++) {
      if (i == idx) {
        that.setData({
          images: newassess[i].img
        })
      }

    }
   
    var current = e.target.dataset.src
    wx.previewImage({
      current: current,
      urls: this.data.images
    })
  },

  //已成团
  group(){
    wx.showToast({
      title: '商品已成团,无法继续购买',
      icon:"none"
    })
  },
//结束
  gameover(){
    wx.showToast({
      title: '活动已结束',
      icon:"none"
    })
  },
  moresee(){
    let that = this;
    that.setData({
      seemore:false
    })

    
    let url = "home/index/shopMessage";
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    let params = {
      shop_id: that.data.detail_id,
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      let masarr = []
      
      that.setData({
        // short: masarr,
        //assess: res.data
        assess:res.data
      })
    }).catch((err) => {
      console.log(err)
    })
  },

  
 
  goFirm_order1(e) {
    wx.navigateTo({
      url: '../firm_order1/firm_order1?id=' + e.currentTarget.dataset.id + "&&num=" + this.data.num,
    })
  },

  // 商品详情数据
  detaiFun(id) {
    let that = this;
    let url = "home/index/shopEdit";
    let params = {
      shop_id: that.data.id
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res.data.content)
      that.setData({
        detailCon: res.data,
        content: res.content
      })

      
      // WxParse.wxParse('content', 'html', this.data.content, this, 5);
      WxParse.wxParse('article', 'html', res.data.content, that, 5)
      console.log(that.data.detailCon);

      let number = res.data.end_time - res.data.now_time;
      console.log(number)
      // let number = res.over_time;
      // 时间戳处理
      var totalSecond = number;
      console.log(totalSecond)

      var interval = setInterval(function () {
        // 秒数
        var second = totalSecond;
        // 天数位
        var day = Math.floor(second / 3600 / 24);
        var dayStr = day.toString();
        if (dayStr.length == 1) dayStr = '0' + dayStr;
        // 小时位
        var hr = Math.floor((second - day * 3600 * 24) / 3600);
        var hrStr = hr.toString();
        if (hrStr.length == 1) hrStr = '0' + hrStr;
        // 分钟位
        var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
        var minStr = min.toString();
        if (minStr.length == 1) minStr = '0' + minStr;
        // 秒位
        var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
        var secStr = sec.toString();
        if (secStr.length == 1) secStr = '0' + secStr;
        
        that.setData({
          days: dayStr,
          hours: hrStr,
           minutes: minStr,
          seconds: secStr,
        });
        totalSecond--;
       
        if (totalSecond <= 0) {
          that.setData({
            over:false
          })
          console.log(that.data.over)
          clearInterval(interval);
          // wx.showToast({
          //   title: '已结束',
          //   icon: 'none'
          // });
          // 倒计时结束
          //that.countDown();
          that.setData({
            days: '00',
            hours: '00',
            minutes: '00',
            seconds: '00',
          });
        }
      }.bind(this), 1000);
        

    }).catch((err) => {
      console.log(err)
    })
  },
  // 商品评价页面
  assessFun() {
    let that = this;
    let url = "home/index/shopMessage";
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    let params = {
      shop_id: that.data.detail_id,
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      let masarr=[]
      for (var i = 0; i < res.data.length;i++){
        if(i<5){
          masarr.push(res.data[i])
        }
        
      }
      that.setData({
        // short: masarr,
        //assess: res.data
        assess: masarr
      })

      console.log(that.data.assess)
    }).catch((err) => {
      console.log(err)
    })
  },
  // 加入收藏
  addFun() {
    let that = this;
    let url = "home/index/shopCollect";
    let params = {
      shop_id: that.data.detail_id,
    };
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    };
    app.post(url, params, header).then((res) => {
      console.log(res)
      // if(res.code == 20000){
      wx.showToast({
        title: '收藏成功',
        icon: "none",
        duration: 1500
      })

      setTimeout(function(){
        that.detaiFun()
      },1500)

      // }     
    }).catch((err) => {
      console.log(err)
      wx.showToast({
        title: err.msg,
        icon:'none'
      })

      setTimeout(function () {
        that.detaiFun()
      }, 1500)
    })
  },
  goy(e) {
    this.setData({
      index: e.currentTarget.dataset.id,
    })
    if (e.currentTarget.dataset.id==2){
      console.log(9909)
      this.assessFun()
    }else{
      this.detaiFun()
    }
  },
  goConfirm: function () {
    this.setData({
      showModal: true,
    })
  },
  m_close: function () {
    this.setData({
      showModal: false,
    })
  },
  // 点击加减
  bindMinus: function () {
    var num = this.data.num;
    if (num > 1) {
      num--;
    }
    this.setData({
      num: num,
    });
  },
  // 点击加
  bindPlus: function () {
    var num = this.data.num;
    num++;
    this.setData({
      num: num,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})