123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- const WXAPI = require('apifm-wxapi')
- const wxpay = require('../../utils/pay.js')
- const AUTH = require('../../utils/auth')
- Page({
- data: {
- payType: 'wxpay'
- },
- onLoad: function (options) {
- this.payBillDiscounts()
- this.setData({
- balance_pay_pwd: wx.getStorageSync('balance_pay_pwd')
- })
- },
- onShow () {
- AUTH.checkHasLogined().then(isLogined => {
- if (!isLogined) {
- AUTH.openLoginDialog()
- } else {
- this.userAmount()
- }
- })
- },
- async payBillDiscounts() {
- const res = await WXAPI.payBillDiscounts()
- if (res.code === 0) {
- this.setData({
- rechargeSendRules: res.data
- })
- }
- },
- async userAmount() {
- const res = await WXAPI.userAmount(wx.getStorageSync('token'))
- if (res.code === 0) {
- this.setData({
- balance: res.data.balance
- })
- }
- },
- async bindSave() {
- const amount = this.data.amount;
- if (!amount) {
- wx.showToast({
- title: '请填写正确的消费金额',
- icon: 'none'
- })
- return
- }
- if (this.data.payType == 'balance') {
- if (this.data.balance_pay_pwd && !this.data.pwd) {
- wx.showToast({
- title: '请输入交易密码',
- icon: 'none'
- })
- return
- }
- }
- const res = await WXAPI.payBillV2({
- token: wx.getStorageSync('token'),
- money: amount,
- calculate: true
- })
- if (res.code != 0) {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- return
- }
- const amountReal = res.data.realMoney
- const _msg = `您本次消费${amount},优惠后只需支付${amountReal}`
-
- wx.showModal({
- title: '请确认消费金额',
- content: _msg,
- confirmText: "确认支付",
- cancelText: "取消支付",
- success: res => {
- if (res.confirm) {
- this.goPay(amount, amountReal)
- }
- }
- });
- },
- async goPay(amount, wxpayAmount){
- if (this.data.payType == 'balance') {
- const res = await WXAPI.payBillV2({
- token: wx.getStorageSync('token'),
- money: amount,
- pwd: this.data.pwd
- })
- if (res.code != 0) {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- return
- }
- wx.showModal({
- title: '成功',
- content: '买单成功,欢迎下次光临!',
- showCancel: false
- })
- } else {
- wxpay.wxpay('paybill', wxpayAmount, 0, "/pages/asset/index", { money: amount});
- }
- },
- processLogin(e) {
- if (!e.detail.userInfo) {
- wx.showToast({
- title: '已取消',
- icon: 'none',
- })
- return;
- }
- AUTH.register(this);
- },
- payTypeChange(event) {
- this.setData({
- payType: event.detail,
- });
- },
- payTypeClick(event) {
- const { name } = event.currentTarget.dataset;
- this.setData({
- payType: name,
- });
- },
- })
|