You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xzjl-ui/pages/home/me/member/member.js

168 lines
4.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// pages/home/me/member/member.js
import Toast from 'tdesign-miniprogram/toast/index';
const app = getApp(); //新建页面时 默认引入
const req = app.xzjlReq(); //初始化一个的request() 实例
Page({
/**
* 页面的初始数据
*/
data: {
yhy:true,
openid:'',
showToast:false,
isChatVip:false,
deadline: ''
},
doKtHy() {
req.postRequest(`/api/v1/chat-service-order/prepare/${this.data.yhy?'2':'1'}`, {
openid: this.data.openid
}).then((res) => {
console.log(res);
// 调用微信支付方法
wx.requestPayment({
//成功之后,调用小程序微信支付
timeStamp: res.data.data.timeStamp,
nonceStr: res.data.data.nonceStr,
package: res.data.data.packageVal,
signType: 'MD5',
paySign: res.data.data.paySign,
success: res => {
console.log(res, '支付返回数据');
//支付成功的回调这里面写支付成功后跳转的路径
wx.showToast({
title: '支付成功', // 标题
icon: 'success', // 图标类型默认success 图标支持开发文档的icon
})
setTimeout(() => {
wx.switchTab({
url: '/pages/home/me/indexx',
})
}, 1000)
},
fail: () => {
wx.showToast({
icon: 'none',
title: '支付失败'
});
}
});
})
},
go2Month(){
this.setData({yhy: !this.data.yhy})
},
go2Reback(){
wx.switchTab({
url: '/pages/home/me/indexx',
})
},
tQuest(){
this.setData({showToast:true})
},
closeTaost(){
this.setData({showToast:false})
console.log('点击了');
},
getuserInfo(){
req.getRequest('/api/user/curt',{}).then(res => {
if (res.data.code === 200) {
console.log(res.data.data.isChatVip);
this.setData({isChatVip: res.data.data.isChatVip})
if (res.data.data.isChatVip) {
this.getVipDeadline(res.data.data.chatVipEndTime)
}
}
})
},
// 获取vip截止日期
getVipDeadline(time){
console.log(time);
const endTime = new Date(time)
const newTime = new Date()
// 判断时间是否已经到期
if (endTime > newTime) {
const year = endTime.getFullYear()
const mouth = endTime.getMonth() + 1
const day = endTime.getDate()
const deadline = `${year}${mouth}${day}`
this.setData({ deadline : deadline})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.login({
provider: 'weixin',
success: loginRes => {
//loginRes中有code拿着code再请求自己服务器以获取openid
req.getRequest(`/api/v1/chat-service-order/js-code2-session`, {
code: loginRes.code
}).then((res) => {
console.log(res);
// this.openid = res.data.openid
this.setData({
openid: res.data.data.openid
})
})
}
});
this.getuserInfo()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})