vip_index.js 6.8 KB
// pages/vip/vip_index/vip_index.js
const app=getApp();
Page({

        /**
         * 页面的初始数据
         */
        data: {
                imgUrl: app.globalData.imgUrl,
                flag:false,
                mask:false, 
                back_shop:false,
                imgUrls: [],
                current:0,
                id:1,
                customer_service:false,
                coupons:false,
                more:false,
                user:{},
                slide:[],
        },
        //跳转尊享会员说明
        jump_detail_vip(){
                wx.navigateTo({
                        url: '../detail_vip/detail_vip',
                })
        },
        //get_my返回按钮
        get_my(){
                wx.navigateBack({ })
        },
        //取消弹框
        cancel_mask(){
                this.setData({
                        mask:!this.data.mask
                });
        },
        opposite_mask() {
                this.setData({
                        mask:false
                });
        },
        //购买会员
        pay_vip(){
                let url ='/wxapp/pay/vip'
                let params={
                        id:this.data.id
                }
                app.post(url,params).then(r=>{
                        console.log(r)
                        wx.requestPayment({
                                timeStamp: r.data.jsApiParameters.timeStamp,
                                nonceStr: r.data.jsApiParameters.nonceStr,
                                package: r.data.jsApiParameters.package,
                                signType: r.data.jsApiParameters.signType,
                                paySign: r.data.jsApiParameters.paySign,
                                success(res) {
                                        console.log(res);
                                },
                                fail(res) {
                                        console.log(res);
                                }
                        })
                })
        },
        //成为月度会员
        becomeMonthVip(){
                let url ='/wxapp/pay/vip'
                let params={
                        id:1
                }
                let that=this
                app.post(url,params).then(r=>{
                        console.log(r)
                        console.log(that.data.user.user.is_vip);
                        if(that.data.user.user.is_vip==1){
                                wx.showToast({
                                        title: '您已经是会员了',
                                        icon:'none'
                                })
                        }else{
                        wx.requestPayment({
                                timeStamp: r.data.jsApiParameters.timeStamp,
                                nonceStr: r.data.jsApiParameters.nonceStr,
                                package: r.data.jsApiParameters.package,
                                signType: r.data.jsApiParameters.signType,
                                paySign: r.data.jsApiParameters.paySign,
                                success(res) {
                                        console.log(res);
                                },
                                fail(res) {
                                        console.log(res);
                                }
                        })
                        }
                })
        },
        //fetchVip
        fetchVip(){
                let url = '/wxapp/user/vip';
                app.post(url).then(r=>{
                        console.log(r);
                        // var slide = r.data.slide.slice(0,3);
                        var slide=r.data.slide
                        console.log(slide);
                        r.data.user.vip_expire_time = app.timeFormate(r.data.user.vip_expire_time,'YYMMDDHHMM')
                        this.setData({
                                user:r.data,
                                slide:slide,
                        });
                });
        },
        // fetchimg(){
        //         let url = '/portal/index/index';
        //         app.post(url).then(r => {
        //                 this.setData({
        //                         imgUrls: r.data.special
        //                 });
        //         });
        // },
//修改id实现效果
change_vip_id(e){
        let id=e.currentTarget.dataset.id;
        this.setData({
                id:id
        });
},
//bindChange
        bindChange(e){
                console.log(e.detail.current);
                let current=e.detail.current;
                this.setData({
                        current:current
                });
        },
//显示购物返现
show_back_shop(e){
        this.setData({
                back_shop:!this.data.back_shop,
                current:e.currentTarget.dataset.index
        });
},
//隐藏购物返现
hide_back_shop(){
        this.setData({
                back_shop:!this.data.back_shop
        });
},
//显示专享客服
show_customer_service(){
        this.setData({
        customer_service:!this.data.customer_service
        });
},
        //隐藏专享客服
        hide_customer_service(){
          this.setData({
              customer_service:!this.data.customer_service
          });
        },
        //显示无门槛券
        show_coupons(){
          this.setData({
            coupons:!this.data.coupons
          });
        },
        //隐藏无门槛券
        hide_coupons(){
          this.setData({
            coupons:!this.data.coupons
          });
        },
        //显示更多权益
        show_more(){
          this.setData({
            more:!this.data.more
          });
        },
        //隐藏更多权益
        hide_more(){
          this.setData({
            more:!this.data.more
          });
        },
        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function (options) {
                this.fetchVip();
                // this.fetchimg();
        },

        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady: function () {

        },

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

        },

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

        },

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

        },

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

        },

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

        },

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

        }
})