|
|
@@ -18,28 +18,29 @@ class Pay extends Component {
|
|
|
constructor(props) {
|
|
|
super(props)
|
|
|
this.state = {
|
|
|
- checked:true,
|
|
|
+ checked: true,
|
|
|
payOrder: JSON.parse(sessionStorage.getItem('payOrder'))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
changeCheckedStatus = (e) => {
|
|
|
this.setState({
|
|
|
- checked:e.target.checked
|
|
|
+ checked: e.target.checked
|
|
|
})
|
|
|
}
|
|
|
|
|
|
pay = () => {
|
|
|
Toast.info('支付成功', 2);
|
|
|
this.props.history.push({
|
|
|
- pathname:'/my'
|
|
|
+ pathname: '/my'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// prepay_id微信生成的预支付会话标识,用于后续接口调用中使用,该值有效期为2小时
|
|
|
- jsApiPay = (args,id,update_order) => {
|
|
|
+ jsApiPay = (args, id, update_order) => {
|
|
|
// console.log('jsApiPay params', args);
|
|
|
let $this = this
|
|
|
+
|
|
|
function onBridgeReady() {
|
|
|
window.WeixinJSBridge.invoke(
|
|
|
'getBrandWCPayRequest', args,
|
|
|
@@ -54,60 +55,63 @@ class Pay extends Component {
|
|
|
orderStatus: '1',
|
|
|
updatedAt
|
|
|
}
|
|
|
- update_order({variables:updateContent})
|
|
|
+ update_order({variables: updateContent})
|
|
|
$this.props.history.push({
|
|
|
- pathname:'/my'
|
|
|
+ pathname: '/my'
|
|
|
})
|
|
|
}
|
|
|
else {
|
|
|
- if(res.err_msg === "get_brand_wcpay_request:cancel"){
|
|
|
+ if (res.err_msg === "get_brand_wcpay_request:cancel") {
|
|
|
message.warning('您的支付已经取消')
|
|
|
- }else if(res.err_msg === "get_brand_wcpay_request:fail"){
|
|
|
+ } else if (res.err_msg === "get_brand_wcpay_request:fail") {
|
|
|
message.error('支付失败,请稍后重试')
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
message.error('支付失败,请稍后重试')
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
- if (typeof window.WeixinJSBridge === "undefined"){
|
|
|
- if( document.addEventListener ){
|
|
|
+
|
|
|
+ if (typeof window.WeixinJSBridge === "undefined") {
|
|
|
+ if (document.addEventListener) {
|
|
|
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
|
|
|
- }else if (document.attachEvent){
|
|
|
+ } else if (document.attachEvent) {
|
|
|
document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
|
|
|
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
onBridgeReady()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- getBridgeReady = (update_order,id,needPay) => {
|
|
|
+ getBridgeReady = (update_order, id, needPay) => {
|
|
|
// console.log('getBridgeReady params',id,needPay)
|
|
|
let isWechat = getIsWechatBrowser()
|
|
|
- if(clicktag === 1 && isWechat) {
|
|
|
+ if (clicktag === 1 && isWechat) {
|
|
|
clicktag = 0 //进行标志,防止多次点击
|
|
|
let openid = getCookie('openid')
|
|
|
|
|
|
let $this = this
|
|
|
axios.get('/payinfo', {
|
|
|
- params: {
|
|
|
- needPay:parseInt(needPay * 100,10),
|
|
|
- openid,
|
|
|
- tradeNo:id
|
|
|
- }
|
|
|
- })
|
|
|
- .then((res) =>{
|
|
|
+ params: {
|
|
|
+ needPay: parseInt(needPay * 100, 10),
|
|
|
+ openid,
|
|
|
+ tradeNo: id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
// console.log('onBridgeReady res',res)
|
|
|
- $this.jsApiPay(res.data,id,update_order)
|
|
|
- setTimeout(()=> {clicktag = 1}, 5000)
|
|
|
+ $this.jsApiPay(res.data, id, update_order)
|
|
|
+ setTimeout(() => {
|
|
|
+ clicktag = 1
|
|
|
+ }, 5000)
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
message.warning('网络或系统故障,请稍后重试')
|
|
|
- console.log('onBridgeReady error',error)
|
|
|
+ console.log('onBridgeReady error', error)
|
|
|
})
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
message.info('当前只支持在微信中打开')
|
|
|
}
|
|
|
}
|
|
|
@@ -122,7 +126,9 @@ class Pay extends Component {
|
|
|
className='pay-navbar'
|
|
|
mode="light"
|
|
|
icon={<Icon type="left"/>}
|
|
|
- onLeftClick={() => {this.props.history.goBack()}}
|
|
|
+ onLeftClick={() => {
|
|
|
+ this.props.history.goBack()
|
|
|
+ }}
|
|
|
>订单支付</NavBar>
|
|
|
</div>
|
|
|
<div className='pay-content-wrap content-wrap'>
|
|
|
@@ -136,25 +142,31 @@ class Pay extends Component {
|
|
|
<img src="https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/wechat.png" alt=''/>
|
|
|
<span>微信支付</span>
|
|
|
<span>
|
|
|
- <Checkbox checked={checked} onChange={(e)=>this.changeCheckedStatus(e)}/>
|
|
|
+ <Checkbox checked={checked} onChange={(e) => this.changeCheckedStatus(e)}/>
|
|
|
</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div className="confirm-footer">
|
|
|
<Mutation mutation={gql(update_order)}
|
|
|
- onError={error=>console.log('error',error)}
|
|
|
+ onError={error => console.log('error', error)}
|
|
|
>
|
|
|
- {(update_order,{ loading, error }) => (
|
|
|
+ {(update_order, {loading, error}) => (
|
|
|
<button
|
|
|
className={classNames({
|
|
|
'confirm-button': true,
|
|
|
'pay-disabled': !checked
|
|
|
})}
|
|
|
- onClick={()=>{
|
|
|
- if(checked){
|
|
|
+ onClick={() => {
|
|
|
+ if (checked) {
|
|
|
// this.pay()
|
|
|
- this.getBridgeReady(update_order,id,orderTotalPay)
|
|
|
+ // const updateContent = {
|
|
|
+ // id,
|
|
|
+ // orderStatus: '1',
|
|
|
+ // updatedAt: '123'
|
|
|
+ // }
|
|
|
+ // update_order({variables: updateContent})
|
|
|
+ this.getBridgeReady(update_order, id, orderTotalPay)
|
|
|
}
|
|
|
}}>
|
|
|
<span>确认支付</span>
|