切换汇邦云用户借呗
This commit is contained in:
parent
6203c2746e
commit
e16966f31c
|
|
@ -66,6 +66,9 @@ export async function getBalanceApi(corpid: string, openid: string) {
|
||||||
export async function getBalanceByQyUserid(corpid: string, userid: string) {
|
export async function getBalanceByQyUserid(corpid: string, userid: string) {
|
||||||
return await http.get<GetBalanceResponse>("payment/getBalanceByQyUserid", { corpid, userid });
|
return await http.get<GetBalanceResponse>("payment/getBalanceByQyUserid", { corpid, userid });
|
||||||
}
|
}
|
||||||
|
export async function getUserBalance(corpid: string, ab98UserId: number) {
|
||||||
|
return await http.get<GetBalanceResponse>("payment/getUserBalance", { corpid, ab98UserId });
|
||||||
|
}
|
||||||
|
|
||||||
export async function getShopListApi(corpid: string, mode?: number) {
|
export async function getShopListApi(corpid: string, mode?: number) {
|
||||||
const params: any = {
|
const params: any = {
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ export interface SubmitOrderRequestData {
|
||||||
openid: string;
|
openid: string;
|
||||||
/** 系统用户ID */
|
/** 系统用户ID */
|
||||||
userid: string;
|
userid: string;
|
||||||
|
/** 汇邦云用户ID */
|
||||||
|
ab98UserId: number;
|
||||||
/** 企业ID */
|
/** 企业ID */
|
||||||
corpid: string;
|
corpid: string;
|
||||||
/** 支付类型 wechat:微信 balance:余额 */
|
/** 支付类型 wechat:微信 balance:余额 */
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@ const rentingCabinetStore = useRentingCabinetStore();
|
||||||
const { rentingCartItems, rentingCartTotalPrice } = storeToRefs(rentingCabinetStore);
|
const { rentingCartItems, rentingCartTotalPrice } = storeToRefs(rentingCabinetStore);
|
||||||
|
|
||||||
const wxStore = useWxStore();
|
const wxStore = useWxStore();
|
||||||
const { openid, balance, corpidLogin, userid: qyUserid, name: qyName } = storeToRefs(wxStore);
|
const { openid, balance, corpidLogin, userid: qyUserid, name: qyName, ab98UserId } = storeToRefs(wxStore);
|
||||||
|
|
||||||
const ab98UserStore = useAb98UserStore();
|
const ab98UserStore = useAb98UserStore();
|
||||||
const { tel, userid: ab98Userid, name } = storeToRefs(ab98UserStore);
|
const { tel, name } = storeToRefs(ab98UserStore);
|
||||||
|
|
||||||
const productStore = useProductStore();
|
const productStore = useProductStore();
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ async function handleSubmit() {
|
||||||
// 2 - 企业微信用户
|
// 2 - 企业微信用户
|
||||||
// 1 - 汇邦云用户
|
// 1 - 汇邦云用户
|
||||||
// 0 - 外部用户
|
// 0 - 外部用户
|
||||||
const isInternal = corpidLogin.value ? 2 : ab98Userid.value ? 1 : 0;
|
const isInternal = corpidLogin.value ? 2 : ab98UserId.value ? 1 : 0;
|
||||||
|
|
||||||
// 根据模式组织 goodsList
|
// 根据模式组织 goodsList
|
||||||
let goodsListToSend;
|
let goodsListToSend;
|
||||||
|
|
@ -157,6 +157,7 @@ async function handleSubmit() {
|
||||||
const requestData: SubmitOrderRequestData = {
|
const requestData: SubmitOrderRequestData = {
|
||||||
openid: openid.value,
|
openid: openid.value,
|
||||||
userid: wxStore.userid,
|
userid: wxStore.userid,
|
||||||
|
ab98UserId: ab98UserId.value,
|
||||||
corpid: wxStore.corpid,
|
corpid: wxStore.corpid,
|
||||||
goodsList: goodsListToSend,
|
goodsList: goodsListToSend,
|
||||||
// 根据选中的支付方式value获取对应的类型
|
// 根据选中的支付方式value获取对应的类型
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ const shopId = ref<number>(0)
|
||||||
|
|
||||||
// 页面加载
|
// 页面加载
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// await wxStore.fakeQyLogin();
|
|
||||||
uni.login({
|
uni.login({
|
||||||
provider: 'weixin', //使用微信登录
|
provider: 'weixin', //使用微信登录
|
||||||
success: function (loginRes) {
|
success: function (loginRes) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { pinia } from "@/pinia"
|
import { pinia } from "@/pinia"
|
||||||
import { getOpenIdApi, getBalanceApi, qyLogin, getBalanceByQyUserid, fakeQyLoginApi } from "@/api/shop"
|
import { getOpenIdApi, getBalanceApi, qyLogin, getBalanceByQyUserid, fakeQyLoginApi, getUserBalance } from "@/api/shop"
|
||||||
import { ab98UserDTO, GetBalanceResponse } from "@/api/shop/types"
|
import { ab98UserDTO, GetBalanceResponse } from "@/api/shop/types"
|
||||||
import { useAb98UserStore } from "./ab98-user"
|
import { useAb98UserStore } from "./ab98-user"
|
||||||
import { defineStore } from "pinia"
|
import { defineStore } from "pinia"
|
||||||
|
|
@ -34,6 +34,8 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
// 汇邦云用户信息
|
// 汇邦云用户信息
|
||||||
const ab98User = ref<ab98UserDTO | null>(null);
|
const ab98User = ref<ab98UserDTO | null>(null);
|
||||||
|
|
||||||
|
const ab98UserId = ref<number | null>(null);
|
||||||
|
|
||||||
const isFakeQyLogin = ref<boolean>(false);
|
const isFakeQyLogin = ref<boolean>(false);
|
||||||
// handleWxCallback 是否完成
|
// handleWxCallback 是否完成
|
||||||
const isHandleWxCallbackComplete = ref<boolean>(true);
|
const isHandleWxCallbackComplete = ref<boolean>(true);
|
||||||
|
|
@ -53,6 +55,10 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
isCabinetAdmin.value = isAdmin;
|
isCabinetAdmin.value = isAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setAb98UserId = (id: number) => {
|
||||||
|
ab98UserId.value = id;
|
||||||
|
}
|
||||||
|
|
||||||
const setAb98User = (user: ab98UserDTO) => {
|
const setAb98User = (user: ab98UserDTO) => {
|
||||||
ab98User.value = user;
|
ab98User.value = user;
|
||||||
const ab98UserStore = useAb98UserStore();
|
const ab98UserStore = useAb98UserStore();
|
||||||
|
|
@ -68,8 +74,8 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshBalance = async () => {
|
const refreshBalance = async () => {
|
||||||
if (corpid.value && userid.value) {
|
if (corpid.value && ab98UserId.value) {
|
||||||
const res = await getBalanceByQyUserid(corpid.value, userid.value);
|
const res = await getUserBalance(corpid.value, ab98UserId.value);
|
||||||
if (res && res.code == 0) {
|
if (res && res.code == 0) {
|
||||||
balance.value = res.data.balance;
|
balance.value = res.data.balance;
|
||||||
useBalance.value = res.data.useBalance;
|
useBalance.value = res.data.useBalance;
|
||||||
|
|
@ -82,7 +88,7 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleWxCallback = async (params: { corpid?: string; code?: string; state?: string; }) => {
|
/* const handleWxCallback = async (params: { corpid?: string; code?: string; state?: string; }) => {
|
||||||
console.log('handleWxCallback:', params)
|
console.log('handleWxCallback:', params)
|
||||||
isHandleWxCallbackComplete.value = false; // 开始处理,标记为未完成
|
isHandleWxCallbackComplete.value = false; // 开始处理,标记为未完成
|
||||||
if (params.code) {
|
if (params.code) {
|
||||||
|
|
@ -134,9 +140,6 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
if (!ab98User.value && balanceRes.data.ab98User) {
|
if (!ab98User.value && balanceRes.data.ab98User) {
|
||||||
setAb98User(balanceRes.data.ab98User);
|
setAb98User(balanceRes.data.ab98User);
|
||||||
}
|
}
|
||||||
/* if (!corpid.value) {
|
|
||||||
corpid.value = balanceRes.data.corpid;
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -148,9 +151,9 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
} else {
|
} else {
|
||||||
isHandleWxCallbackComplete.value = true; // 没有code参数,直接标记为已完成
|
isHandleWxCallbackComplete.value = true; // 没有code参数,直接标记为已完成
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
const fakeQyLogin = async () => {
|
/* const fakeQyLogin = async () => {
|
||||||
isFakeQyLogin.value = true;
|
isFakeQyLogin.value = true;
|
||||||
corpid.value = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw";
|
corpid.value = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw";
|
||||||
corpidLogin.value = true;
|
corpidLogin.value = true;
|
||||||
|
|
@ -167,7 +170,7 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isHandleWxCallbackComplete.value = true
|
isHandleWxCallbackComplete.value = true
|
||||||
}
|
} */
|
||||||
|
|
||||||
// 检测 handleWxCallback 是否完成的异步函数
|
// 检测 handleWxCallback 是否完成的异步函数
|
||||||
const waitForHandleWxCallbackComplete = async (timeout = 30000): Promise<boolean> => {
|
const waitForHandleWxCallbackComplete = async (timeout = 30000): Promise<boolean> => {
|
||||||
|
|
@ -186,6 +189,7 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
corpid.value = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw";
|
corpid.value = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw";
|
||||||
openid.value = userDTO.openid || openid.value;
|
openid.value = userDTO.openid || openid.value;
|
||||||
wxUserDTO.value = userDTO;
|
wxUserDTO.value = userDTO;
|
||||||
|
ab98UserId.value = userDTO.ab98UserId || ab98UserId.value;
|
||||||
if (userDTO.qyUserId) {
|
if (userDTO.qyUserId) {
|
||||||
qyUserId.value = userDTO.qyUserId;
|
qyUserId.value = userDTO.qyUserId;
|
||||||
}
|
}
|
||||||
|
|
@ -197,8 +201,8 @@ export const useWxStore = defineStore("wx", () => {
|
||||||
|
|
||||||
return { code, state, openid, corpid, userid, balance, useBalance,
|
return { code, state, openid, corpid, userid, balance, useBalance,
|
||||||
balanceLimit, isCabinetAdmin, corpidLogin, name, ab98User, qyUserId, isFakeQyLogin,
|
balanceLimit, isCabinetAdmin, corpidLogin, name, ab98User, qyUserId, isFakeQyLogin,
|
||||||
isHandleWxCallbackComplete, wxUserDTO, setOpenid, setBalance, handleWxCallback, setIsCabinetAdmin,
|
isHandleWxCallbackComplete, wxUserDTO, ab98UserId, setOpenid, setBalance, setIsCabinetAdmin,
|
||||||
refreshBalance, setAb98User, fakeQyLogin, waitForHandleWxCallbackComplete, wxMpCallback }
|
refreshBalance, setAb98User, waitForHandleWxCallbackComplete, wxMpCallback, setAb98UserId }
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue