Commit 1fa08769 authored by GuanHua's avatar GuanHua

feat:微信支付方式

parent a64504a4
...@@ -15,11 +15,12 @@ ...@@ -15,11 +15,12 @@
&_imgbox { &_imgbox {
padding: 20px; padding: 20px;
width: 180px;
height: 180px;
border: 1px solid rgba(245, 245, 245, 1); border: 1px solid rgba(245, 245, 245, 1);
&>img { &>img {
width: 200px; width: 200px;
height: 200px; height: 200px;
} }
} }
......
...@@ -2,10 +2,10 @@ import React, { useEffect } from 'react' ...@@ -2,10 +2,10 @@ import React, { useEffect } from 'react'
import { GetOrderOrderPayDetailsResponse } from '@/services/OrderApi' import { GetOrderOrderPayDetailsResponse } from '@/services/OrderApi'
import { LAYOUT_TYPE } from '@/constants' import { LAYOUT_TYPE } from '@/constants'
import wechatIcon from '@/assets/imgs/wechat_icon.png' import wechatIcon from '@/assets/imgs/wechat_icon.png'
import wechatImg from '@/assets/imgs/wechat.png'
import { priceFormat } from '@/utils/numberFomat' import { priceFormat } from '@/utils/numberFomat'
import { PublicApi } from '@/services/api' import { PublicApi } from '@/services/api'
import { message } from 'antd' import { message, Spin } from 'antd'
import QRCode from 'qrcode'
import styles from './index.less' import styles from './index.less'
import { useState } from 'react' import { useState } from 'react'
...@@ -20,12 +20,23 @@ interface WechatPayWayPropsType { ...@@ -20,12 +20,23 @@ interface WechatPayWayPropsType {
const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => { const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => {
const { payInfo, orderId, onChange, orderInfo, layoutType, shopUrlParam } = props const { payInfo, orderId, onChange, orderInfo, layoutType, shopUrlParam } = props
const [wechatPayUrl, setWechatPayUrl] = useState<string>('') const [wechatPayUrl, setWechatPayUrl] = useState<any>('')
const [pageLoading, setPageLoading] = useState<boolean>(true)
useEffect(() => { useEffect(() => {
pay() pay()
}, []) }, [])
const generateQrCode = (path: any) => {
// 生成二维码
QRCode.toDataURL(path).then((url: any) => {
setWechatPayUrl(url)
})
.catch((err: any) => {
console.error(err)
})
}
const pay = () => { const pay = () => {
let param = { let param = {
id: Number(orderId), id: Number(orderId),
...@@ -37,15 +48,18 @@ const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => { ...@@ -37,15 +48,18 @@ const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => {
PublicApi.postOrderPendingOrderPay(param).then(res => { PublicApi.postOrderPendingOrderPay(param).then(res => {
if(res.code === 1000) { if(res.code === 1000) {
message.destroy() message.destroy()
generateQrCode(res.data)
} }
setPageLoading(false)
// setWechatPayUrl(res.data) // setWechatPayUrl(res.data)
}).catch(() => { }).catch(() => {
onChange(false) onChange(false)
setPageLoading(false)
}) })
} }
return ( return (
<> <Spin spinning={pageLoading}>
<div className={styles.common_title}> <div className={styles.common_title}>
<div className={styles.common_title_icon}><img src={wechatIcon} /></div> <div className={styles.common_title_icon}><img src={wechatIcon} /></div>
<span>微信支付</span> <span>微信支付</span>
...@@ -53,7 +67,7 @@ const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => { ...@@ -53,7 +67,7 @@ const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => {
<div className={styles.wechat_payway}> <div className={styles.wechat_payway}>
<p className={styles.wechat_payway_title}>使用微信扫一扫下方二维码</p> <p className={styles.wechat_payway_title}>使用微信扫一扫下方二维码</p>
<div className={styles.wechat_payway_imgbox}> <div className={styles.wechat_payway_imgbox}>
<img src={wechatImg} /> {wechatPayUrl && <img src={wechatPayUrl} />}
</div> </div>
<div className={styles.wechat_payway_needpay}> <div className={styles.wechat_payway_needpay}>
<label>当前需支付:</label> <label>当前需支付:</label>
...@@ -61,7 +75,7 @@ const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => { ...@@ -61,7 +75,7 @@ const WechatPayWay: React.FC<WechatPayWayPropsType> = (props) => {
<label>RMB</label> <label>RMB</label>
</div> </div>
</div> </div>
</> </Spin>
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment