1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- // pages/commodity/index.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- activationModal: false,
- checkedId: '1'
- },
- onLoad(options) {
- },
- onShow() {
- },
- checked({
- currentTarget
- }) {
- console.log(currentTarget);
- this.setData({
- checkedId: currentTarget.dataset.id
- })
- },
- activation() {
- this.setData({
- activationModal: true
- })
- },
- closeModal() {
- this.setData({
- activationModal: false
- })
- },
- async toBuy({
- currentTarget
- }) {
- let productId = currentTarget.dataset.type
- wx.showLoading({
- title: '提交中',
- mask: true
- })
- let res = ''
- if (productId == '1001') {
- res = await buyVip({
- productId
- }).finally(() => {
- wx.hideLoading()
- })
- } else if (productId == '1010') {
- res = await buyNum({
- productId
- }).finally(() => {
- wx.hideLoading()
- })
- } else {
- wx.hideLoading()
- wx.showToast({
- title: "支付失败,请重试",
- icon: "none",
- duration: 3000
- })
- }
- let {
- timeStamp,
- nonceStr,
- signType,
- paySign
- } = res
- // package保留字
- wx.requestPayment({
- timeStamp,
- nonceStr,
- package: res.package,
- signType,
- paySign,
- success(res) {
- wx.showToast({
- title: "支付成功",
- duration: 2500
- })
- setTimeout(() => {
- this.setUserInfo()
- }, 1500)
- },
- fail(res) {
- wx.showToast({
- title: "支付失败",
- icon: "none",
- duration: 3000
- })
- }
- })
- },
- })
|