Files
cardtest/pages/welfare/welfare.js
张慢慢 a7995d90bc [更新]
2021-05-24 13:56:00 +08:00

127 lines
3.6 KiB
JavaScript

Page({
/**
* 页面的初始数据
*/
data: {
noticeShow : false, //须知显示状态
pointMoreShow : false, //重要提示显示状态
groupId : '', //权益id
contData : '', //全局内容
rightData : '', //权益详情
content : '', //内容介绍
notification : '', //重要提示
remark : '', //使用须知
},
/**
* 生命周期函数--监听页面加载
*/
onLoad (options) {
this.setData({
groupId : options.id
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 获取详情
this.rightsInfo();
},
/**
* 详情
*/
rightsInfo() {
wx.$api.index.welfares(this.data.groupId).then(res=>{
this.setData({
contData : res.data,
rightData : res.data.right,
remark : res.data.remark.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"'),
content : res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
})
}).catch(err=>{
if(!err.login){
wx.showModal({
title : '用户登录已过期',
content : '请重新登录',
showCancel : false,
success : res => {
if (res.confirm) {
wx.redirectTo({
url: '/pages/login/login'
})
}
}
})
}
})
},
/**
* 须知展开收起状态
*/
noticeTap() {
this.setData({
noticeShow : !this.data.noticeShow
})
},
/**
* 重要提示展开收起状态
*/
pointMoreTap() {
this.setData({
pointMoreShow : !this.data.pointMoreShow
})
},
/**
* 普通商品支付提交
*/
ordinary() {
this.submitOrder();
this.setData({
disabled : true
})
},
/**
* 支付提交
*/
submitOrder() {
let welfareId = this.data.contData.welfare_id
wx.$api.index.fridayInfo(welfareId).then(res=>{
wx.$api.index.fridayPay(res.data.trade_no).then(res=>{
let payInfo = JSON.parse(res.data)
wx.requestPayment({
timeStamp: payInfo.timeStamp,
nonceStr : payInfo.nonceStr,
package : payInfo.package,
paySign : payInfo.paySign,
signType : payInfo.signType,
success : res=>{
if(res.errMsg == "requestPayment:ok"){
wx.showToast({
title: '支付成功',
icon : 'success'
})
setTimeout(()=>{
wx.reLaunch({
url: '/pages/coupon/coupon?type=couponPublic'
})
},3000)
}
},
fail : res=>{
wx.reLaunch({
url: '/pages/order/order?stateType=unpay'
})
}
})
})
})
}
})