From a0e1caed60ccb0b084137532a7114f685c728dba Mon Sep 17 00:00:00 2001 From: XiaoXinPro 14 IAH5R <568170040@qq.com> Date: Thu, 24 Aug 2023 18:21:05 +0800 Subject: [PATCH] upload --- src/api/coin.js | 2 +- src/pages/index/buyCoin.vue | 44 ++++++++++++++++++++++++++++++----- src/store/modules/userInfo.js | 6 ++++- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/api/coin.js b/src/api/coin.js index c2ad2c6..d4abc2d 100644 --- a/src/api/coin.js +++ b/src/api/coin.js @@ -28,7 +28,7 @@ export function createOrder(productId) { } /** -* @description:获取收银台数据 +* @description:获取订单数据 * @param data * @return: data */ diff --git a/src/pages/index/buyCoin.vue b/src/pages/index/buyCoin.vue index 89fe580..5a166f3 100644 --- a/src/pages/index/buyCoin.vue +++ b/src/pages/index/buyCoin.vue @@ -22,9 +22,9 @@ //#region 导入 import { ref, reactive } from "vue"; import { getCoinList, createOrder, createPay } from "../../api/coin.js"; -//#endregion -------------- +import { userInfoModules } from "@/store/modules/userInfo"; +const userInfoModulesPinia = userInfoModules(); -//#region 列表数据 const active = ref(""); const coinList = ref([]); function select(item) { @@ -36,6 +36,7 @@ const goPro = () => { }); }; +// 获取金币价格列表 const getList = async () => { try { const res = await getCoinList(5, 1); @@ -46,25 +47,56 @@ const getList = async () => { } }; +// 创建订单 const createProductOrder = async () => { try { const res = await createOrder(1); - console.log(res, "res"); - // createProductPay() + console.log(res.data, "res"); + createProductPay(res.data); } catch (error) { console.log(error, "error"); } }; -const createProductPay = async () => { +// 获取订单数据 +const createProductPay = async (orderNumber) => { + const openId = userInfoModulesPinia.openId; try { - const res = await createPay(1); + const data = { + orderNumber, + openId, + payVendor: 1, //Number,1:微信;2:抖音 + }; + const res = await createPay(data); console.log(res, "res"); } catch (error) { console.log(error, "error"); } }; +// 拉起收银台 +const startPay = (data) => { + var orderInfo = { + appid: "wx499********7c70e", + partnerid: "148*****52", + prepayid: "wx202254********************fbe90000", + package: "Sign=WXPay", + noncestr: "c5sEwbaNPiXAF3iv", + timestamp: 1597935292, + sign: "A842B45937F6EFF60DEC7A2EAA52D5A0", + }; + uni.requestPayment({ + provider: "wxpay", //固定值为"wxpay" + orderInfo: orderInfo, + success: function (res) { + console.log(res, "res"); + }, + fail: function (err) { + console.log("支付失败", err); + }, + }); +}; + getList(); diff --git a/src/store/modules/userInfo.js b/src/store/modules/userInfo.js index 4a95363..53984a8 100644 --- a/src/store/modules/userInfo.js +++ b/src/store/modules/userInfo.js @@ -1,5 +1,9 @@ import { defineStore } from "pinia"; import { ref, reactive } from "vue"; + +/** +* @description:用户信息持久化数据 +*/ export const userInfoModules = defineStore("userInfoStore", () => { // state const userInfo = ref(null) @@ -31,7 +35,7 @@ export const userInfoModules = defineStore("userInfoStore", () => { function loginOut(params) { } - return { userInfo, platForm, hostSystem, getUserInfo, loginOut }; + return { userInfo, openId, platForm, hostSystem, getUserInfo, loginOut }; }, { persist: true,