12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import {
- buyVip,
- } from '~/api/user'
- import {
- getProducts
- } from '~/api/global'
- Page({
- data: {
- products: [],
- selected: {},
- activationModal: false,
- },
- onLoad(options) {
- this.getProducts()
- },
- async getProducts() {
- let products = await getProducts()
- console.log(products);
- this.setData({
- products,
- selected: products[0]
- })
- },
- checked({
- currentTarget
- }) {
- this.setData({
- selected: currentTarget.dataset.product
- })
- },
- closeModal() {
- this.setData({
- activationModal: false
- })
- wx.navigateBack()
- },
- async toBuy() {
- wx.showLoading({
- title: '提交中',
- mask: true
- })
- let res = await buyVip({
- productId: this.data.selected.id
- }).finally(() => {
- wx.hideLoading()
- })
- let {
- timeStamp,
- nonceStr,
- signType,
- paySign
- } = res
- // package保留字
- wx.requestPayment({
- timeStamp,
- nonceStr,
- package: res.package,
- signType,
- paySign,
- success: (res) => {
- console.log(res);
- this.setData({
- activationModal: true
- })
- /* setTimeout(() => {
- this.setUserInfo()
- }, 1500) */
- },
- fail(res) {
- wx.showToast({
- title: "支付失败",
- icon: "none",
- duration: 3000
- })
- }
- })
- },
- /* // 设置用户信息及vip状态
- async setUserInfo() {
- let userInfo = await getMyInfo()
- let vipTime = await getVipInfo()
- this.setUser(userInfo.user)
- this.setData({
- userInfo,
- vipTime,
- })
- }, */
- })
|