getConsume.js 3.28 KB
// pack-activity/pack/getConsume.js
import util from '../../utils/util';
import App from '../../utils/api';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        sellerid: '',
        amount: '',
        purePhoneNumber: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('options---',options);
        this.setData({
            sellerid: options.sellerid || '',
            amount: options.amount ? (options.amount * 1).toFixed(2) : '',
        })
        if (options.sellerid) {
            this.getSellerDetailFun(options.sellerid)
        }
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getCheckUserHavePhone()
    },
    // 检测用户是否绑定手机号
    getCheckUserHavePhone() {
        App.Wechat.CheckUserHavePhone({
            openid: getApp().openid,
        }).then((json) => {
            if (json.ret == 200) {
                let data = json.data;
                if (data) {
                    this.setData({
                        purePhoneNumber: data.phone,
                    })
                } else {
                    this.setData({
                        purePhoneNumber: '',
                    })
                }
            }
        })
    },
    // 跳转登录页
    gotoLogin(event) {
        wx.navigateTo({
            url: util.http_build_query({
                types: event.currentTarget.dataset.types
            }, '/pages/customer/login')
        })
    },
    // 为用户增加消费金
    getConsumeFun() {
        App.Activity.SetConsumeByOpenid({
            phone: this.data.purePhoneNumber,
            openid: getApp().openid,
            amount: this.data.amount,
            sellerid: this.data.sellerid
        }).then(res => {
            if (res.data == '0') {
                wx.showToast({
                    title: '领取失败,请稍后再试!',
                    duration: 1000,
                    icon: 'none',
                    mask: true
                });
            } else {
                wx.showToast({
                    title: '领取成功!',
                    duration: 1000,
                    icon: 'none',
                    mask: true
                });
            }
            wx.exitMiniProgram({});
        })
    },
    // 获取店铺名称
    getSellerDetailFun(sellerid) {
        App.Customer.GetSellerDetail({
            sid:sellerid
        }).then(res => {
            let data = res.data;
            this.setData({
                seller: {
                    seller_image: data.seller_image,
                    sellername: data.sellername,
                    sid: data.id
                }
            })
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})