detail_1.js 5.3 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: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log(options)
        this.setData({
            detail_id: options.id,
            id: options.id
        })
        this.detaiFun(options.id)
        this.assessFun();
    },
    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)
            that.setData({
                detailCon: res.data,
                content: res.content,
                now_time: res.data.now_time,
            })
            WxParse.wxParse('content', 'html', this.data.content, this, 5);
            that.countDown()
        }).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)
            that.setData({
                assess: res.data.list
            })
        }).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: res.msg,
                icon: "none",
                duration: 1500
            })

            // }     
        }).catch((err) => {
            console.log(err)
        })
    },
    goy(e) {
        this.setData({
            index: e.currentTarget.dataset.id,
        })
    },
    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,
        });
    },
    timeFormat(param) { //小于10的格式化函数
        return param < 10 ? '0' + param : param;
    },

    //团购倒计时
    countDown() {
        let that = this;
        let detail = that.data.detailCon;
        let now_time = parseInt(new Date().getTime())
        // console.log(now_time)
        let end_time = detail.end_time * 1000
        // console.log(end_time)
        let open_time = detail.open_time * 1000
        if (now_time < open_time) {
            // console.log(333)
            //活动未开始
        } else if (now_time > end_time) {
            // console.log(222)
            //活动结束
        } else {
            // console.log(1111)
            let time = (end_time - now_time) / 1000;
            let day = parseInt(time / (60 * 60 * 24));
            let hou = parseInt(time % (60 * 60 * 24) / 3600);
            let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
            let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
            detail.day = that.timeFormat(day),
            detail.hou = that.timeFormat(hou),
            detail.min = that.timeFormat(min),
            detail.sec = that.timeFormat(sec)
        }
        that.setData({
            detailCon: detail
        })
        setTimeout(that.countDown, 1000);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})