const Apps = getApp();
const api = require('../../config/api.js');
const util = require('../../config/util.js');
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        listdata: [],
        baseurl: Apps.globalData.baseimgurl
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        Apps.islogin();
    },

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

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getviplist();
    },

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

    },

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

    },

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

    },
    vipclick: function () {
        wx.navigateTo({
            url: '/pages/viprecharge/viprecharge',
        })
    },

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

    },

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

    },
    payorderclick: function (params) {
        // console.log(baseUrl.globalData.wxopenid);
        // console.log(params.currentTarget.id);
        // return;
        Apps.islogin();
        const that = this;
        let url = Apps.globalData.baseUrl + '/wxpay/makerorder';
        var param = {
            id: params.currentTarget.id,
            openid: wx.getStorageSync('wxopenid'),
            paytypeid: 1, //会员充值
            user_id: wx.getStorageSync('wxuserid') == null ? 3 : wx.getStorageSync('wxuserid')
        };
        //此处为使用封装的post请求
        util.post(url, param).then((res) => {
            console.log(res);
            // that.setData({
            //   listdata: res.data
            // });

            console.log(res);
            var rest = res;
            // var orders = res.data.orders;
            // 调用支付接口开始
            wx.requestPayment({
                timeStamp: rest.timeStamp,
                nonceStr: rest.nonceStr,
                package: rest.package,
                signType: rest.signType,
                paySign: rest.paySign,
                success: function (res) {
                    console.log(res);

                    Toast('怼币充值成功');
                    // wx.navigateTo({
                    //   url: '/pages/goodlist/goodlist?orders=' + orders,
                    // })
                },
                fail: function (res) {
                    console.log(res)
                },
                complete: function (res) {
                    console.log(res)
                },
            })

        }).catch((errMsg) => {
            console.log(errMsg);
        });
    },
    getviplist: function (params) {
        const that = this;
        let url = Apps.globalData.baseUrl + '/vip/getviplist';
        var param = {
            id: '123456789'
        };
        //此处为使用封装的post请求
        util.get(url, param).then((res) => {
            console.log(res);
            that.setData({
                listdata: res.data
            });

        }).catch((errMsg) => {
            console.log(errMsg);
        });
    }
})