@@ -2,8 +2,8 @@ import {
request
} from "../utils/request";
module.exports = {
- //获取充值配置信息
+ //获取商品信息
- getProducts: data => request('/v3/product', 'get', data),
+ getProducts: data => request('/v3/product/learn', 'get', data),
// 领取代金卷
getVoucher: data => request('/v3/activity/voucher', 'post', data),
// 获取轮播图列表
@@ -15,8 +15,6 @@ module.exports = {
setUserInfo: (data, method = 'post') => request('/user', method, data),
// 购买vip
buyVip: data => request('/order', 'post', data, true),
- // 购买次数
- buyNum: data => request('/v3/pay', 'post', data),
//获取是否vip及过期时间
getVipInfo: data => request('/auth', 'get', data),
//获取自己朗读的作品
@@ -1,25 +1,34 @@
-// pages/commodity/index.js
+import {
+ buyVip,
+} from '~/api/user'
+ getProducts
+} from '~/api/global'
Page({
-
- /**
- * 页面的初始数据
- */
data: {
+ products: [],
+ selected: {},
activationModal: false,
- checkedId: '1'
},
onLoad(options) {
+ this.getProducts()
onShow() {
+ async getProducts() {
+ let products = await getProducts()
+ console.log(products);
+ this.setData({
+ products,
+ selected: products[0]
+ })
+ },
checked({
currentTarget
}) {
- console.log(currentTarget);
this.setData({
- checkedId: currentTarget.dataset.id
+ selected: currentTarget.dataset.product
})
activation() {
@@ -32,35 +41,17 @@ Page({
activationModal: false
- async toBuy({
+ async toBuy() {
- currentTarget
- }) {
- let productId = currentTarget.dataset.type
wx.showLoading({
title: '提交中',
mask: true
- let res = ''
+ let res = await buyVip({
- if (productId == '1001') {
+ productId: this.data.selected.id
- res = await buyVip({
+ }).finally(() => {
- productId
- }).finally(() => {
- wx.hideLoading()
- })
- } else if (productId == '1010') {
- res = await buyNum({
- } else {
wx.hideLoading()
- wx.showToast({
- title: "支付失败,请重试",
+ console.log(res);
- icon: "none",
- duration: 3000
- }
let {
timeStamp,
nonceStr,
@@ -15,12 +15,20 @@
-webkit-box-reflect: below 4rpx -webkit-linear-gradient(top, rgba(255, 0, 0, 0), rgba(255, 0, 0, 0.24));
}
+ .bg1 {
+ background-image: url(http://reader-wx.ai160.com/images/reader/v3/learn/svip.png);
+ }
+
+ .bg2 {
+ background-image: url(http://reader-wx.ai160.com/images/reader/v3/learn/vip.png);
.selectBtn {
position: absolute;
bottom: 10rpx;
right: 10rpx;
- width: 52rpx;
+ width: 48rpx;
- height: 50rpx;
+ height: 46rpx;
line-height: 50rpx;
text-align: center;
border-radius: 50%;
@@ -1,17 +1,14 @@
+<wxs src="../../utils/filter.wxs" module="filters" />
<view class="commodity">
<view class="cardBox">
- <view class="vipBox" style="background-image: url(http://reader-wx.ai160.com/images/reader/v3/learn/svip.png);"
+ <view wx:for="{{products}}" wx:key="id" class="vipBox {{item.payType=='LIFELONG'?'bg1':'bg2'}}" bindtap="checked"
- bindtap="checked" data-id="1">
+ data-product="{{item}}">
- <view class="selectBtn {{checkedId=='1'?'checked':''}}">✔</view>
+ <view class="selectBtn {{selected.id==item.id?'checked':''}}">✔</view>
- </view>
- <view class="vipBox" style="background-image: url(http://reader-wx.ai160.com/images/reader/v3/learn/vip.png);"
- bindtap="checked" data-id="2">
- <view class="selectBtn {{checkedId=='2'?'checked':''}}">✔</view>
</view>
<view class="introduce">
- <view class="title">朗读小咖秀 SVIP终身学习卡</view>
+ <view class="title">{{selected.title}}</view>
- <view class="price">¥299.00</view>
+ <view class="price">¥{{filters.twoDecimal(selected.price)}}</view>
<view class="entry">
<view class="title">运费</view>
@@ -33,9 +30,9 @@
<view class="payBox">
<view class="left">
- 合计 <text>¥299.00</text>
+ 合计 <text>¥{{filters.twoDecimal(selected.price)}}</text>
- <view class="buyBtn" bindtap="toBuy" bindtap="activation">
+ <view class="buyBtn" bindtap="toBuy">
立即购买
@@ -13,12 +13,18 @@
-webkit-box-reflect: below 0rpx linear-gradient(top, rgba(255, 0, 0, 0), rgba(255, 0, 0, 0.24));
+.commodity .cardBox .bg1 {
+}
+.commodity .cardBox .bg2 {
.commodity .cardBox .selectBtn {
@@ -1,9 +1,4 @@
import {
- getProducts,
-} from '~/api/global'
-import {
- buyVip,
- buyNum,
getMyInfo,
getVipInfo,
} from '~/api/user'
@@ -20,12 +15,9 @@ Page({
vipTime: '',
tasks: [],
isIos: app.globalData.isIOS,
- productNum: {},
- productVip: {},
onLoad() {
- this.getProducts()
// 手工绑定
this.storeBindings = createStoreBindings(this, {
store,
@@ -59,80 +51,7 @@ Page({
vipTime,
- async getProducts() {
- let products = await getProducts()
- let productVip = products.find(item => {
- return item.type == 1
- let productNum = products.find(item => {
- return item.type == 2
- this.setData({
- productNum,
- productVip
- },
- //购买vip和购买次数不是一个接口 type 1001是vip,1010是次数
- wx.showLoading({
- title: '提交中',
- mask: true
- let {
- timeStamp,
- nonceStr,
- signType,
- paySign
- } = res
- // package保留字
- wx.requestPayment({
- package: res.package,
- paySign,
- success(res) {
- title: "支付成功",
- duration: 2500
- setTimeout(() => {
- this.setUserInfo()
- }, 1500)
- fail(res) {
- title: "支付失败",
activationCode() {
wx.showModal({
title: '请输入激活码',
@@ -74,36 +74,9 @@
<image src="/static/lollipop.png" class="close" catchtap="closeModal" />
- <!-- 支付 -->
- <!-- <view class="payBox">
- <view class="title">
- 付费购
- <view class="pay vipPay">
- <view class="payLeft">
- <view class="pLTitle vipTitle">
- {{productVip.title}}
- <view class="pLcontent vipContent">
- {{vipTime?filters.formatDate(vipTime,4)+'过期':'购买VIP会员,即可有权使用全部资源'}}
- <view class="payRight vipBtn" bindtap="toBuy" data-type="{{productVip.id}}">
- {{vipTime?'立即续费':'立即开通'}}
- <view class="pay buyPay">
- {{productNum.title}}
- <view class="payRight buyBtn" bindtap="toBuy" data-type="{{productNum.id}}">
- 立即购买
- </view> -->
- <view class="copywriting">开通<text>SVIP</text>/<text>VIP</text> 会员权益</view>
+ <view class="copywriting" wx:if="{{!vipTime}}">开通<text>SVIP</text>/<text>VIP</text> 会员权益</view>
- <view class="goPay" bindtap='jump' data-url="/pages/commodity/index">
+ <view class="goPay" bindtap='jump' data-url="/pages/commodity/index" wx:if="{{!vipTime}}">
立即开通
@@ -58,8 +58,13 @@ function numFilter(num) {
return Math.floor(num / 100) / 100 + 'w'
+// 四舍五入保留两位小数
+function twoDecimal(num) {
+ return (num / 100).toFixed(2)
formatDate: formatDate,
gradeFilter: gradeFilter,
- numFilter: numFilter
+ numFilter: numFilter,
+ twoDecimal: twoDecimal
@@ -16,7 +16,8 @@ if (envVersion == 'develop') {
function request(url, method, data, oldBaseUrl = false) {
let header = {
- 'uid': wx.getStorageSync('uid') || ''
+ 'uid': wx.getStorageSync('uid') || '',
+ 'channelCode': '3001'
return new Promise((reslove, reject) => {
wx.request({