opinionSuccess.js 2.83 KB
// pages/pinglun/opinionSuccess.js
import App from '../../utils/api'
import util from '../../utils/util';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        options: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log('options', options);
        this.setData({
            options,
        })
    },
    seeCoupon() {
        wx.showLoading({
            title: '加载中',
        })
        let options = this.data.options
        // 金额大于0  需要购买券
        if (options.coupon == '1' && options.price * 1 > 0) {
            let url = util.http_build_query({
                id: options.couponId,
                name: options.sellerName,
                oid: options.oid,
                sid: options.sid,
                types: '1',
                use: options.use ? JSON.stringify(options.use) : '',
            }, '/pack-activity/pack/buyCoupon')
            wx.hideLoading()
            wx.redirectTo({
                url
            })
        } else { //金额为0  直接领券后跳转到我的券页面
            App.Activity.CreateNewRechargeOrder({
                recharge_id: options.couponId,
                sellerid: options.sid,
                number: '1',
                price: options.price,
                type: '1',
            }).then(res => {
                if (res.ret == '200') {
                    wx.hideLoading()
                    let price = res.data.price;
                    if (price == 0) {
                        wx.showToast({
                            icon: 'none',
                            title: '购买成功',
                        })
                        wx.reLaunch({
                            url: '/pages/me/coupon_news'
                        })
                        return
                    }
                } else {
                    wx.hideLoading()
                    wx.showToast({
                        title: res.msg,
                        duration: 2000,
                        mask: true
                    })
                }
            })
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})