From e4a22af8918eba8079600174679ce84c92a2b3b1 Mon Sep 17 00:00:00 2001
From: qiaomu <3520484422@qq.com>
Date: Mon, 15 Jul 2024 14:16:06 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=85=85=E5=80=BC=E6=94=B9?=
=?UTF-8?q?=E9=80=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app.json | 3 +-
pages/home/index.js | 30 +---
pages/invoiceList/components/notyet/index.js | 1 -
pages/rechargeWay/index.js | 140 +++++++++++++++++++
pages/rechargeWay/index.json | 11 ++
pages/rechargeWay/index.wxml | 25 ++++
pages/rechargeWay/index.wxss | 23 +++
utils/request.js | 2 +-
8 files changed, 206 insertions(+), 29 deletions(-)
create mode 100644 pages/rechargeWay/index.js
create mode 100644 pages/rechargeWay/index.json
create mode 100644 pages/rechargeWay/index.wxml
create mode 100644 pages/rechargeWay/index.wxss
diff --git a/app.json b/app.json
index 4621cdb..2d31885 100644
--- a/app.json
+++ b/app.json
@@ -21,7 +21,8 @@
"pages/editInvoice/index",
"pages/rechargeDetail/index",
"pages/agreements/index",
- "pages/updateInvoice/index"
+ "pages/updateInvoice/index",
+ "pages/rechargeWay/index"
],
"tabBar": {
"list": [
diff --git a/pages/home/index.js b/pages/home/index.js
index 64c22bb..9681a60 100644
--- a/pages/home/index.js
+++ b/pages/home/index.js
@@ -4,7 +4,7 @@ import { alertInfo, alertSuccess } from "../../utils/index";
import request from '../../utils/request';
import { getDot } from "../../utils/system";
import { getUserInfo } from "../../service/user"
-import { requestRecharge } from "../../service/recharge";
+
const { OK } = request;
// pages/home/index.js
Page({
@@ -148,32 +148,10 @@ Page({
alertInfo("最少为1分")
return
}
- const { code, message, data } = await requestRecharge({ money: Number(money), id: meter.id, tenement: tenement.id, park: park.id })
- if (code !== OK) {
- alertInfo(message)
- return;
- }
- wx.requestPayment({
- timeStamp: data?.time,
- nonceStr: data?.nonceStr,
- package: "prepay_id=" + data?.prepay_id,
- paySign: data?.paySign,
- signType: 'RSA',
- success: (res) => {
- alertSuccess("充值成功")
- that.setData({
- money: null
- })
- },
- fail: (res) => {
- console.log('fail', res)
- alertInfo("请稍后重试")
- },
- complete: (res) => {
- console.log('complete')
- that.handleGetMeterDetail(meter.id)
- }
+ wx.navigateTo({
+ url: `/pages/rechargeWay/index?money=${money}&address=${meter.address}&id=${meter?.id}&tenement=${tenement?.id}&park=${park.id}`,
})
+
},
jumpToInvoice() {
wx.navigateTo({
diff --git a/pages/invoiceList/components/notyet/index.js b/pages/invoiceList/components/notyet/index.js
index 246de48..36cff76 100644
--- a/pages/invoiceList/components/notyet/index.js
+++ b/pages/invoiceList/components/notyet/index.js
@@ -96,7 +96,6 @@ Component({
})
},
onAllChecked(e) {
- // console.log('e', e.detail)
const { list } = this.data;
if (e.detail) {
const newSelectList = Array.from({ length: list.length }, () => true)
diff --git a/pages/rechargeWay/index.js b/pages/rechargeWay/index.js
new file mode 100644
index 0000000..257a4dc
--- /dev/null
+++ b/pages/rechargeWay/index.js
@@ -0,0 +1,140 @@
+// pages/rechargeWay/index.js
+import { requestRecharge } from "../../service/recharge";
+import { alertInfo } from "../../utils/index";
+import request from '../../utils/request';
+const { OK } = request;
+
+Page({
+
+ /**
+ * 页面的初始数据
+ */
+ data: {
+ money: 0,
+ address: "",
+ rechargeWay: 0,
+ id: "",
+ tenement: "",
+ park: "",
+ rechargeLoading: false,
+ },
+
+ /**
+ * 生命周期函数--监听页面加载
+ */
+ onLoad(options) {
+ const { money, address, id, tenement, park } = options
+ this.setData({ money: Number(money), address, id, tenement, park })
+ },
+ onChangeRechargeWay(e) {
+ this.setData({ rechargeWay: e.detail })
+ },
+ onClickCell(e) {
+ const { name } = e.currentTarget.dataset;
+ this.setData({ rechargeWay: name })
+ },
+ async recharge() {
+ const { rechargeWay } = this.data;
+ await this.setLoading(true)
+ try {
+ switch(rechargeWay) {
+ case 1:
+ alertInfo("开发中")
+ break;
+ default:
+ await this.wxRecharge();
+ break;
+ }
+ } catch(err) {
+
+ } finally {
+ await this.setLoading(false)
+ }
+ },
+ async wxRecharge() {
+ const { money, id, tenement, park } = this.data;
+ const { code, message, data } = await requestRecharge({ money: Number(money), id, tenement, park })
+ if (code !== OK) {
+ alertInfo(message)
+ return;
+ }
+ wx.requestPayment({
+ timeStamp: data?.time,
+ nonceStr: data?.nonceStr,
+ package: "prepay_id=" + data?.prepay_id,
+ paySign: data?.paySign,
+ signType: 'RSA',
+ success: (res) => {
+ alertSuccess("充值成功")
+ that.setData({
+ money: null
+ })
+ },
+ fail: (res) => {
+ console.log('fail', res)
+ alertInfo("请稍后重试")
+ },
+ complete: (res) => {
+ console.log('complete')
+ that.handleGetMeterDetail(meter.id)
+ }
+ })
+ },
+ async setLoading(flag) {
+ return new Promise((res) => {
+ this.setData({
+ rechargeLoading: flag,
+ }, () => {
+ res()
+ })
+ })
+ },
+ /**
+ * 生命周期函数--监听页面初次渲染完成
+ */
+ onReady() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面显示
+ */
+ onShow() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面隐藏
+ */
+ onHide() {
+
+ },
+
+ /**
+ * 生命周期函数--监听页面卸载
+ */
+ onUnload() {
+
+ },
+
+ /**
+ * 页面相关事件处理函数--监听用户下拉动作
+ */
+ onPullDownRefresh() {
+
+ },
+
+ /**
+ * 页面上拉触底事件的处理函数
+ */
+ onReachBottom() {
+
+ },
+
+ /**
+ * 用户点击右上角分享
+ */
+ onShareAppMessage() {
+
+ }
+})
\ No newline at end of file
diff --git a/pages/rechargeWay/index.json b/pages/rechargeWay/index.json
new file mode 100644
index 0000000..752198a
--- /dev/null
+++ b/pages/rechargeWay/index.json
@@ -0,0 +1,11 @@
+{
+ "usingComponents": {
+ "navigator": "/components/navigator/index",
+ "van-radio": "@vant/weapp/radio/index",
+ "van-radio-group": "@vant/weapp/radio-group/index",
+ "van-cell": "@vant/weapp/cell/index",
+ "van-cell-group": "@vant/weapp/cell-group/index",
+ "van-button": "@vant/weapp/button/index"
+ },
+ "navigationStyle": "custom"
+}
\ No newline at end of file
diff --git a/pages/rechargeWay/index.wxml b/pages/rechargeWay/index.wxml
new file mode 100644
index 0000000..ed8a2b9
--- /dev/null
+++ b/pages/rechargeWay/index.wxml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ ¥
+ {{ money }}
+
+ 地址:{{address}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 支付
+
\ No newline at end of file
diff --git a/pages/rechargeWay/index.wxss b/pages/rechargeWay/index.wxss
new file mode 100644
index 0000000..a160ea6
--- /dev/null
+++ b/pages/rechargeWay/index.wxss
@@ -0,0 +1,23 @@
+/* pages/rechargeWay/index.wxss */
+.rechargeInfoWrapper {
+ margin-top: 10vw;
+ margin-bottom: 10vw;
+ text-align: center;
+}
+
+.money {
+ font-weight: 700;
+ font-size: 60rpx;
+ margin-left: 10rpx;
+}
+
+.address {
+ font-size: 28rpx;
+ margin-top: 20rpx;
+}
+
+.rechargeBtn {
+ margin-top: 10vh;
+ margin-left: 32rpx;
+ margin-right: 32rpx;
+}
\ No newline at end of file
diff --git a/utils/request.js b/utils/request.js
index c24b138..deb7ad5 100644
--- a/utils/request.js
+++ b/utils/request.js
@@ -78,12 +78,12 @@ const request = async function (options, config = {}) {
// 处理返回结果,默认直接返回数据
const parseResponse = function (response, url) {
- console.log('url', url, 'response', response)
if (!response) {
alertError("服务异常")
return
}
const { statusCode } = response;
+ console.log('url', url, 'response.status', statusCode, 'response.data', response.data)
if (statusCode === 401) {
wx.redirectTo({
url: '/pages/login/index',