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