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

    /**
     * 页面的初始数据
     */
    data: {
        options: {
            coupon:'',
            couponId:'',
            price:'',
            use:'',
            sid:'',
            StyleType:'',
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log('options', options);
        this.setData({
            options,
        })
        this.getSellerTemplateConfFun(options.sellid)
    },
    getSellerTemplateConfFun(sid) {
		console.log('sellid',sid);
		App.Seller.GetSellerTemplateConf({
			sid
		}).then(res => {
            if(res.ret==200){
                let data=res.data
                let marketing = util.determine(data.marketing);
                if (marketing) {
                    let info = marketing.coupon_data_comments ? util.determine(marketing.coupon_data_comments) : '';
                    let couponDataId = info && info.length > 0 ? info[0].id : {}
                    // 根据券ID获取评价赠送的券详情
                    if (couponDataId) this.getEvaluateFun(couponDataId, sid)
                }
                this.setData({
                    StyleType: data.type
                })
            }else{
                console.log('GetSellerTemplateConf请求失败');
            }
		})
    },
    // 根据券ID获取评价赠送的券详情
    getEvaluateFun(id,sid){
        App.Activity.GetActivityById({
            id
        }).then(res => {
            if (res.data.length > 0) {
                let couponData = res.data[0]
                this.setData({
                    'options.price':couponData.price || '',
                    'options.use':couponData.use || '',
                    'options.couponId':id || '',
                })
                setTimeout(() => {
                    // 金额为0  直接领券后
                    if (this.data.options.coupon == '1' && this.data.options.price * 1 == 0) {
                        App.Activity.CreateNewRechargeOrder({
                            recharge_id: this.data.options.couponId,
                            sellerid: sid,
                            number: '1',
                            price: this.data.options.price,
                            type: '1',
                        }).then(res => {
                            if (res.ret != '200') {
                                wx.showToast({
                                    title: '领券失败!',
                                    duration: 2000,
                                    mask: true
                                })
                            }
                        })
                    }
                }, 100);
            }
        })
    },
    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,
                oid: options.oid,
                sid: options.sellid,
                types: '1',
                StyleType:this.data.StyleType,
            }, '/pack-activity/pack/receiveCoupon')
            wx.hideLoading()
            wx.redirectTo({
                url
            })
        } else { //金额为0  跳转到我的券页面
            wx.hideLoading()
            wx.reLaunch({
                url: '/pages/me/coupon_news'
            })
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})