bayi пре 2 година
родитељ
комит
32b83214bb

+ 2 - 2
api/global.js

@@ -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),
   // 获取轮播图列表

+ 0 - 2
api/user.js

@@ -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),
   //获取自己朗读的作品

+ 24 - 33
pages/commodity/index.js

@@ -1,25 +1,34 @@
-// pages/commodity/index.js
+import {
+  buyVip,
+} from '~/api/user'
+import {
+  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({
-    currentTarget
-  }) {
-    let productId = currentTarget.dataset.type
+  async toBuy() {
     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 {
+    let res = await buyVip({
+      productId: this.data.selected.id
+    }).finally(() => {
       wx.hideLoading()
-      wx.showToast({
-        title: "支付失败,请重试",
-        icon: "none",
-        duration: 3000
-      })
-    }
+    })
+    console.log(res);
     let {
       timeStamp,
       nonceStr,

+ 10 - 2
pages/commodity/index.less

@@ -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;
-      height: 50rpx;
+      width: 48rpx;
+      height: 46rpx;
       line-height: 50rpx;
       text-align: center;
       border-radius: 50%;

+ 8 - 11
pages/commodity/index.wxml

@@ -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);"
-      bindtap="checked" data-id="1">
-      <view class="selectBtn {{checkedId=='1'?'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 wx:for="{{products}}" wx:key="id" class="vipBox {{item.payType=='LIFELONG'?'bg1':'bg2'}}" bindtap="checked"
+      data-product="{{item}}">
+      <view class="selectBtn {{selected.id==item.id?'checked':''}}">✔</view>
     </view>
   </view>
   <view class="introduce">
-    <view class="title">朗读小咖秀 SVIP终身学习卡</view>
-    <view class="price">¥299.00</view>
+    <view class="title">{{selected.title}}</view>
+    <view class="price">¥{{filters.twoDecimal(selected.price)}}</view>
   </view>
   <view class="entry">
     <view class="title">运费</view>
@@ -33,9 +30,9 @@
   </view>
   <view class="payBox">
     <view class="left">
-      合计 <text>¥299.00</text>
+      合计 <text>¥{{filters.twoDecimal(selected.price)}}</text>
     </view>
-    <view class="buyBtn" bindtap="toBuy" bindtap="activation">
+    <view class="buyBtn" bindtap="toBuy">
       立即购买
     </view>
   </view>

+ 8 - 2
pages/commodity/index.wxss

@@ -13,12 +13,18 @@
   -webkit-box-reflect: below 0rpx linear-gradient(top, rgba(255, 0, 0, 0), rgba(255, 0, 0, 0.24));
   -webkit-box-reflect: below 4rpx -webkit-linear-gradient(top, rgba(255, 0, 0, 0), rgba(255, 0, 0, 0.24));
 }
+.commodity .cardBox .bg1 {
+  background-image: url(http://reader-wx.ai160.com/images/reader/v3/learn/svip.png);
+}
+.commodity .cardBox .bg2 {
+  background-image: url(http://reader-wx.ai160.com/images/reader/v3/learn/vip.png);
+}
 .commodity .cardBox .selectBtn {
   position: absolute;
   bottom: 10rpx;
   right: 10rpx;
-  width: 52rpx;
-  height: 50rpx;
+  width: 48rpx;
+  height: 46rpx;
   line-height: 50rpx;
   text-align: center;
   border-radius: 50%;

+ 1 - 82
pages/my/index.js

@@ -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: {},
     activationModal: false
   },
   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是次数
-  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
-        })
-      }
-    })
-  },
+
   activationCode() {
     wx.showModal({
       title: '请输入激活码',

+ 2 - 29
pages/my/index.wxml

@@ -74,36 +74,9 @@
       <image src="/static/lollipop.png" class="close" catchtap="closeModal" />
     </view>
   </view>
-  <!-- 支付 -->
-  <!--   <view class="payBox">
-    <view class="title">
-      付费购
-    </view>
-    <view class="pay vipPay">
-      <view class="payLeft">
-        <view class="pLTitle vipTitle">
-          {{productVip.title}}
-        </view>
-        <view class="pLcontent vipContent">
-          {{vipTime?filters.formatDate(vipTime,4)+'过期':'购买VIP会员,即可有权使用全部资源'}}
-        </view>
-      </view>
-      <view class="payRight vipBtn" bindtap="toBuy" data-type="{{productVip.id}}">
-        {{vipTime?'立即续费':'立即开通'}}
-      </view>
-    </view>
-    <view class="pay buyPay">
-      <view class="payLeft">
-        {{productNum.title}}
-      </view>
-      <view class="payRight buyBtn" bindtap="toBuy" data-type="{{productNum.id}}">
-        立即购买
-      </view>
-    </view>
-  </view> -->
   <view class="payBox">
-    <view class="copywriting">开通<text>SVIP</text>/<text>VIP</text> 会员权益</view>
-    <view class="goPay" bindtap='jump' data-url="/pages/commodity/index">
+    <view class="copywriting" wx:if="{{!vipTime}}">开通<text>SVIP</text>/<text>VIP</text> 会员权益</view>
+    <view class="goPay" bindtap='jump' data-url="/pages/commodity/index" wx:if="{{!vipTime}}">
       立即开通
     </view>
   </view>

+ 6 - 1
utils/filter.wxs

@@ -58,8 +58,13 @@ function numFilter(num) {
   }
   return Math.floor(num / 100) / 100 + 'w'
 }
+// 四舍五入保留两位小数
+function twoDecimal(num) {
+  return (num / 100).toFixed(2)
+}
 module.exports = {
   formatDate: formatDate,
   gradeFilter: gradeFilter,
-  numFilter: numFilter
+  numFilter: numFilter,
+  twoDecimal: twoDecimal
 }

+ 2 - 1
utils/request.js

@@ -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({