155 lines
4.5 KiB
JavaScript
155 lines
4.5 KiB
JavaScript
// pages/copyright/payment/payment.js
|
|
import PayService from '../../../net/api/payApi';
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
paySumOptions: [100, 300, 500, 1000, 2000, 5000],
|
|
currentTab: 0, //充值金额选项
|
|
payMoney: 100, //支付金额
|
|
currentBagTab: 'MATERIAL', //当前套餐包tab
|
|
bagList: [], //套餐包列表
|
|
payWay: 1, //支付方式 1微信 2对公
|
|
showError: false,
|
|
errorHint: '',
|
|
listLoading: 'loading',
|
|
selectBag: {}, //选中的套餐包
|
|
},
|
|
onLoad(options) {
|
|
const _self = this
|
|
_self.doGetPackageList(_self.data.currentBagTab)
|
|
},
|
|
//获取可以购买的套餐包
|
|
doGetPackageList(path) {
|
|
const _self = this
|
|
_self.setData({
|
|
listLoading: 'loading'
|
|
})
|
|
const data = {
|
|
page: 1,
|
|
rows: 10
|
|
}
|
|
PayService.doGetBuyPackageList(path, data)
|
|
.then(res => {
|
|
wx.hideLoading()
|
|
console.log(res)
|
|
_self.setData({
|
|
listLoading: res.rows && res.rows.length > 0 ? 'success' : 'empty'
|
|
})
|
|
_self.setData({
|
|
bagList: res.rows
|
|
})
|
|
}, err => {
|
|
wx.hideLoading()
|
|
console.log(err)
|
|
_self.setData({
|
|
listLoading: 'error'
|
|
})
|
|
_self.setData({
|
|
showError: true,
|
|
errorHint: '未获取到套餐数据,请重试'
|
|
})
|
|
})
|
|
},
|
|
//监听充值金额选项
|
|
doChangePayMoney(e) {
|
|
this.setData({
|
|
payMoney: e.currentTarget.dataset.value,
|
|
selectBag: {},
|
|
currentTab: e.currentTarget.dataset.index
|
|
})
|
|
},
|
|
//监听充值金额变化
|
|
obMoney(e) {
|
|
console.log(e)
|
|
var _self = this
|
|
const inputValue = e.detail.value
|
|
const regex = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
|
|
if (regex.test(inputValue)) {
|
|
//数字
|
|
_self.setData({
|
|
payMoney: e.detail.value,
|
|
selectBag: {}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: '请输入数字',
|
|
icon: 'error',
|
|
success: () => {
|
|
setTimeout(() => {
|
|
_self.setData({
|
|
payMoney: 100,
|
|
selectBag: {}
|
|
})
|
|
}, 1000);
|
|
}
|
|
})
|
|
}
|
|
},
|
|
//切换套餐包
|
|
doChangeBagTab(e) {
|
|
this.setData({
|
|
currentBagTab: e.currentTarget.dataset.value
|
|
})
|
|
this.doGetPackageList(this.data.currentBagTab)
|
|
},
|
|
//切换支付方式
|
|
doChangePayWay(e) {
|
|
console.log(e)
|
|
this.setData({
|
|
payWay: e.currentTarget.dataset.value
|
|
})
|
|
},
|
|
//选中套餐包
|
|
chooseBag(e) {
|
|
console.log(e)
|
|
const _self = this
|
|
const selItem = e.currentTarget.dataset.value
|
|
_self.setData({
|
|
payMoney: selItem.packageMoney / 100,
|
|
currentTab: -1,
|
|
selectBag: selItem
|
|
})
|
|
wx.pageScrollTo({
|
|
scrollTop: 0,
|
|
duration: 300
|
|
})
|
|
},
|
|
//TODO 调用微信支付
|
|
toWeChatPay() {
|
|
const _self = this
|
|
wx.showLoading({
|
|
title: '支付中...',
|
|
})
|
|
const data = {
|
|
rechargeMoney: _self.data.payMoney,
|
|
packageInfoId: _self.data.selectBag.packageInfoId ? _self.data.selectBag.packageInfoId : ''
|
|
}
|
|
PayService.doGetWxPayParams(data)
|
|
.then(res => {
|
|
wx.hideLoading()
|
|
console.log(res)
|
|
})
|
|
.catch(err => {
|
|
wx.hideLoading()
|
|
console.log(err)
|
|
})
|
|
},
|
|
//去支付
|
|
doPay() {
|
|
const _self = this
|
|
if (_self.data.payWay == '1') {
|
|
//微信
|
|
_self.toWeChatPay()
|
|
} else {
|
|
//对公 需要传递参数 选中套餐 or 直接冲钱
|
|
const id = _self.data.selectBag.packageInfoId
|
|
const name = _self.data.selectBag.packageName
|
|
wx.redirectTo({
|
|
url: '/pages/copyright/publicPay/publicPay?packageId=' + id + '&name=' + name + '&money=' + _self.data.payMoney,
|
|
})
|
|
}
|
|
}
|
|
}) |