- app.js 通过 wx.getSystemInfoSync 获取 statusBarHeight 存入 globalData
- 所有12个自定义导航页面的 JS 读取 statusBarHeight
- WXML 通过 style="padding-top: {{statusBarHeight + 24}}px" 动态适配
- 普通手机和灵动岛手机都能正确显示
48 行
1.2 KiB
JavaScript
48 行
1.2 KiB
JavaScript
var http = require('../../utils/request')
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
plans: [
|
|
{ plan: 'monthly', price: '¥99', desc: '约3.3元/天' },
|
|
{ plan: 'yearly', price: '¥899', desc: '省¥289' }
|
|
],
|
|
selected: 'yearly',
|
|
purchasing: false
|
|
},
|
|
|
|
onLoad: function () {
|
|
var app = getApp()
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
|
|
},
|
|
|
|
onSelect: function (e) {
|
|
this.setData({ selected: e.currentTarget.dataset.plan })
|
|
},
|
|
|
|
onPurchase: function () {
|
|
var self = this
|
|
if (!self.data.selected) {
|
|
wx.showToast({ title: '请选择套餐', icon: 'none' })
|
|
return
|
|
}
|
|
self.setData({ purchasing: true })
|
|
|
|
http.post('/api/v1/subscription/purchase', {
|
|
plan: self.data.selected,
|
|
payment_method: 'wechat'
|
|
}).then(function (data) {
|
|
return http.post('/api/v1/subscription/verify', {
|
|
order_id: data.order_id,
|
|
plan: self.data.selected
|
|
})
|
|
}).then(function () {
|
|
self.setData({ purchasing: false })
|
|
wx.redirectTo({ url: '/pages/subscribe-success/subscribe-success' })
|
|
}).catch(function () {
|
|
self.setData({ purchasing: false })
|
|
wx.showToast({ title: '购买失败', icon: 'none' })
|
|
})
|
|
}
|
|
})
|