初步完成网页充值金币功能
This commit is contained in:
parent
4e087353d6
commit
cc7d6e63d2
|
@ -22,14 +22,14 @@ export default function Recharge() {
|
||||||
const [customCoin, setCustomCoin] = useState({ selected: false, num: 1000 });
|
const [customCoin, setCustomCoin] = useState({ selected: false, num: 1000 });
|
||||||
|
|
||||||
//查询用户信息
|
//查询用户信息
|
||||||
const [selectedUser, setSelectedUser] = useState({});
|
const [user, setUser] = useState({ isSelected: false, data: {} });
|
||||||
const querryUserData = async () => {
|
const querryUserData = async () => {
|
||||||
const base = baseRequest();
|
const base = baseRequest();
|
||||||
const body = { ...base, user_id: parseInt(userId, 10) };
|
const body = { ...base, user_id: parseInt(userId, 10) };
|
||||||
const signature = generateSignature(body);
|
const signature = generateSignature(body);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/account/list_others_by_user_id?signature=${signature}`,
|
`/api/account/list_others_by_user_id_without_token?signature=${signature}`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -39,18 +39,25 @@ export default function Recharge() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log(data);
|
|
||||||
if (data.ret === -1) {
|
if (data.ret === -1) {
|
||||||
Toast.show({
|
Toast.show({
|
||||||
content: data.msg,
|
content: data.msg,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setUser({ isSelected: false, data: data.data.list[0] });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//选中用户
|
||||||
|
const handleSelectUser = () => {
|
||||||
|
setUser((prev) => {
|
||||||
|
return { ...prev, isSelected: !prev.isSelected };
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
//任意金额充值的金币数量
|
//任意金额充值的金币数量
|
||||||
const handleChangeCustomCoin = (e) => {
|
const handleChangeCustomCoin = (e) => {
|
||||||
let newValue = parseInt(e.target.value, 10);
|
let newValue = parseInt(e.target.value, 10);
|
||||||
|
@ -101,6 +108,12 @@ export default function Recharge() {
|
||||||
//创建充值订单
|
//创建充值订单
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const createOrder = async (type = "alipay_h5") => {
|
const createOrder = async (type = "alipay_h5") => {
|
||||||
|
if (!user.isSelected || !user.data?.mid) {
|
||||||
|
Toast.show({
|
||||||
|
content: "请选择要充值的账号",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!selectedPrice.id && !customCoin.selected) {
|
if (!selectedPrice.id && !customCoin.selected) {
|
||||||
Toast.show({
|
Toast.show({
|
||||||
content: "请选择充值档位",
|
content: "请选择充值档位",
|
||||||
|
@ -117,10 +130,11 @@ export default function Recharge() {
|
||||||
const base = baseRequest();
|
const base = baseRequest();
|
||||||
const body = {
|
const body = {
|
||||||
...base,
|
...base,
|
||||||
|
mid: 1,
|
||||||
product_id: customCoin.selected ? "h5_custom_coin" : selectedPrice.id,
|
product_id: customCoin.selected ? "h5_custom_coin" : selectedPrice.id,
|
||||||
custom_coins: customCoin.selected ? customCoin.num : 0,
|
custom_coins: customCoin.selected ? customCoin.num : 0,
|
||||||
pay_type: type,
|
pay_type: type,
|
||||||
from: "app",
|
from: "wx_pub",
|
||||||
};
|
};
|
||||||
|
|
||||||
//如果是微信jsapi支付直接跳转到中间页
|
//如果是微信jsapi支付直接跳转到中间页
|
||||||
|
@ -134,7 +148,7 @@ export default function Recharge() {
|
||||||
const signature = generateSignature(body);
|
const signature = generateSignature(body);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`/api/vas/create_order?signature=${signature}`,
|
`/api/vas/create_order_wx_pub?signature=${signature}`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -144,6 +158,7 @@ export default function Recharge() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log(data);
|
||||||
if (data.ret === -1) {
|
if (data.ret === -1) {
|
||||||
Toast.show({
|
Toast.show({
|
||||||
content: data.msg,
|
content: data.msg,
|
||||||
|
@ -243,29 +258,37 @@ export default function Recharge() {
|
||||||
搜索
|
搜索
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="flex flex-row justify-between items-center py-2 border-b-2 border-neutral">
|
{user.data?.mid && (
|
||||||
|
<div
|
||||||
|
className={`flex flex-row my-2 p-4 justify-between items-center rounded-lg border ${
|
||||||
|
user.isSelected ? "border-primary" : "border-neutral"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
<div className="flex flex-row items-center">
|
<div className="flex flex-row items-center">
|
||||||
<img
|
<img
|
||||||
className="w-12 h-12 rounded-full"
|
className="w-12 h-12 rounded-full"
|
||||||
src={item.account?.avatar?.images[0].urls[0]}
|
src={user?.data?.avatar?.images[0].urls[0]}
|
||||||
alt=""
|
alt=""
|
||||||
/>
|
/>
|
||||||
<div className="flex flex-col ml-2">
|
<div className="flex flex-col ml-2">
|
||||||
<p className="text-base text-white font-medium">
|
<p className="text-base text-white font-medium">
|
||||||
{item.account?.name}
|
{user?.data?.name}
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-secondary font-medium">
|
||||||
|
{user?.data?.user_id}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-secondary font-medium">{orderLabel}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{item.lock_type === 0 && item.order_status !== 6 && (
|
|
||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-primary text-white rounded-full"
|
className={`btn text-white ${
|
||||||
onClick={handleClick}
|
user.isSelected ? "btn-neutral" : "btn-primary"
|
||||||
|
}`}
|
||||||
|
onClick={handleSelectUser}
|
||||||
>
|
>
|
||||||
查看微信
|
{user.isSelected ? "取消" : "选中"}
|
||||||
</button>
|
</button>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</div> */}
|
|
||||||
<p className="text-white text-base font-semibold my-2">选择充值金额</p>
|
<p className="text-white text-base font-semibold my-2">选择充值金额</p>
|
||||||
<div className="flex flex-wrap">
|
<div className="flex flex-wrap">
|
||||||
{productList?.map((item) => (
|
{productList?.map((item) => (
|
||||||
|
|
Loading…
Reference in New Issue