From e0143ad80f9c78ac1eb1bd06782567ebffb67b8f Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期一, 04 十一月 2024 10:28:25 +0800
Subject: [PATCH] 充值金额从后台获取
---
pages/rechargeMoney/rechargMoney.js | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 157 insertions(+), 22 deletions(-)
diff --git a/pages/rechargeMoney/rechargMoney.js b/pages/rechargeMoney/rechargMoney.js
index dfc163e..497a378 100644
--- a/pages/rechargeMoney/rechargMoney.js
+++ b/pages/rechargeMoney/rechargMoney.js
@@ -1,4 +1,10 @@
// pages/rechargeMoney/rechargMoney.js
+//鍏呭�肩晫闈�
+const {
+ get,
+ post
+} = require('../../api/request.js');
+const md5 = require('js-md5');
Page({
/**
@@ -10,37 +16,30 @@
userCode: "15584236",
balance: "1025鍏�",
activeIndex: -1,
- allRechargeList: [{
- time: "2024-05-12:20:20",
- type: "杩滅▼",
- morny: "500鍏�"
- }, {
- time: "2024-05-12:20:20",
- type: "杩滅▼",
- morny: "500鍏�"
- }, {
- time: "2024-05-12:20:20",
- type: "杩滅▼",
- morny: "500鍏�"
- }, {
- time: "2024-05-12:20:20",
- type: "杩滅▼",
- morny: "500鍏�"
- }]
+ isClickable: false,
+ allRechargeList: [],
+ vcId: "",
+ pageCurr: 1, //鍏呭�艰褰曞綋鍓嶉〉鐮�
+ pageSize: 20, //鍏呭�艰褰曟瘡椤佃褰曟暟
+ loading: false, //鏄惁姝e湪鍔犺浇
+ hasMore: true,
+ moneyList:[]//鍏呭�奸噾棰�
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
onLoad(options) {
-
+ this.setData({
+ vcId: options.vcId
+ })
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
*/
onReady() {
-
+ this.getRechargList()
},
/**
@@ -68,7 +67,10 @@
* 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
*/
onPullDownRefresh() {
-
+ this.setData({
+ pageCurr: 1,
+ })
+ this.getRechargList(true)
},
/**
@@ -90,10 +92,143 @@
if (index !== undefined) {
this.setData({
activeIndex: parseInt(index),
+ isClickable: true
});
}
},
- onPullDownRefresh() {
- console.log("onPullDownRefresh")
+ //鍒涘缓璁㈠崟骞惰皟璧锋敮浠�
+ creatOrder() {
+ if (!this.data.isClickable) {
+ return;
+ }
+ const data = {
+ sessionId: getApp().globalData.sessionId,
+ vcId: this.data.vcId, //铏氭嫙鍗D
+ rechargeAmount: this.data.moneyList[this.data.activeIndex]//锛堝崟浣嶆槸鍒嗭級
+ };
+ console.log("postCloseValaue" + data);
+ post({
+ url: "wx/payment/placeOrder",
+ data: data
+ }).then(response => {
+ // 澶勭悊鎴愬姛鍝嶅簲
+ console.log('璇锋眰鎴愬姛:', response);
+ this.getOrderSign(response.content.prepay_id)
+ }).catch(error => {
+ if (error.code === "1002") {}
+ // 澶勭悊閿欒鍝嶅簲
+ console.error('璇锋眰澶辫触:', error);
+ });
+ },
+ //鑾峰彇璁㈠崟杩斿洖鐨刾repay_id鐨勭鍚�
+ getOrderSign(id) {
+ const params = {
+ url: 'wx/payment/signAgain',
+ data: {
+ prepayId: id
+ }
+ };
+ get(params).then(data => {
+ // 璋冭捣鏀粯
+ wx.requestPayment({
+ timeStamp: data.content.timeStamp,
+ nonceStr: data.content.nonceStr,
+ package: data.content.package,
+ signType: data.content.signType,
+ paySign: data.content.paySign,
+ success(res) {
+ wx.showToast({
+ title: "鍏呭�兼垚鍔�",
+ icon: 'success',
+ duration: 3000
+ })
+ console.log('鏀粯鎴愬姛', res);
+ this. getRechargList(true);
+ },
+ fail(err) {
+ console.log('鏀粯澶辫触', err);
+ }
+ });
+ }).catch(err => {
+ wx.showToast({
+ title: err.msg,
+ icon: 'error',
+ duration: 3000
+ })
+ });
+ },
+ //鑾峰彇鍏呭�艰褰�
+ getRechargList(isRefresh) {
+ const params = {
+ url: 'wx/virtual_card/getVcRechargeRecords',
+ data: {
+ vcId: this.data.vcId,
+ pageCurr: this.data.pageCurr,
+ pageSize: this.data.pageSize,
+ }
+ };
+ get(params).then(data => {
+ this.setData({
+ allRechargeList: isRefresh ? data.content.obj : this.data.allRechargeList.concat(data.content.obj),
+ isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+ loading: false,
+ hasMore: this.data.pageCurr < data.content.pageTotal
+ })
+ this.updateDisplayText();
+ }).catch(err => {
+ // 閿欒鍥炶皟
+ this.setData({
+ isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
+ loading: false
+ })
+ wx.showToast({
+ title: err.msg,
+ icon: 'error',
+ duration: 3000
+ })
+ });
+ },
+
+ //鍔犺浇鏇村
+ loadMore() {
+ if (this.data.hasMore && !this.data.loading) {
+ this.setData({
+ loading: true,
+ pageCurr: this.data.pageCurr + 1
+ })
+ this.getRechargList();
+ }
+ },
+ updateDisplayText() {
+ const updatedList = this.data.allRechargeList.map(item => {
+ let morny = item.rechargeAmount / 100 + "鍏�"
+ return {
+ ...item,
+ morny
+ }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁
+ });
+ // 鏇存柊鍒楄〃鏁版嵁
+ this.setData({
+ allRechargeList: updatedList
+ });
+ },
+ //鑾峰彇閲戦
+ getMorneyList(){
+ const params = {
+ url: 'wx/virtual_card/gerRechargeProfiles'
+ };
+ get(params).then(data => {
+ this.setData({
+ moneyList: data.content ,
+ })
+ this.updateDisplayText();
+ }).catch(err => {
+ // 閿欒鍥炶皟
+ wx.showToast({
+ title: err.msg,
+ icon: 'error',
+ duration: 3000
+ })
+ });
}
})
\ No newline at end of file
--
Gitblit v1.8.0