|
|
@ -2,12 +2,14 @@
|
|
|
|
<div class="payment">
|
|
|
|
<div class="payment">
|
|
|
|
<nav-bar title="购物车" />
|
|
|
|
<nav-bar title="购物车" />
|
|
|
|
<!-- closeable 模式,在右侧显示关闭按钮 -->
|
|
|
|
<!-- closeable 模式,在右侧显示关闭按钮 -->
|
|
|
|
<van-notice-bar mode="closeable">请在半小时内完成付款,否则系统自动取消订单</van-notice-bar>
|
|
|
|
<van-notice-bar
|
|
|
|
|
|
|
|
mode="closeable"
|
|
|
|
|
|
|
|
>请在半小时内完成付款,否则系统自动取消订单</van-notice-bar>
|
|
|
|
|
|
|
|
|
|
|
|
<van-cell-group class="payment_group">
|
|
|
|
<van-cell-group class="payment_group">
|
|
|
|
<van-cell title="订单编号" :value="order.orderSn" />
|
|
|
|
<van-cell title="订单编号" :value="orderSn" />
|
|
|
|
<van-cell title="实付金额">
|
|
|
|
<van-cell title="实付金额">
|
|
|
|
<span class="red">{{ order.actualPrice | yuan }}</span>
|
|
|
|
<span class="red">{{ actualPrice | yuan }}</span>
|
|
|
|
</van-cell>
|
|
|
|
</van-cell>
|
|
|
|
</van-cell-group>
|
|
|
|
</van-cell-group>
|
|
|
|
|
|
|
|
|
|
|
@ -17,13 +19,23 @@
|
|
|
|
<van-cell-group>
|
|
|
|
<van-cell-group>
|
|
|
|
<van-cell>
|
|
|
|
<van-cell>
|
|
|
|
<template slot="title">
|
|
|
|
<template slot="title">
|
|
|
|
<img src="../../../assets/images/ali_pay.png" alt="支付宝" width="82" height="29">
|
|
|
|
<img
|
|
|
|
|
|
|
|
src="../../../assets/images/ali_pay.png"
|
|
|
|
|
|
|
|
alt="支付宝"
|
|
|
|
|
|
|
|
width="82"
|
|
|
|
|
|
|
|
height="29"
|
|
|
|
|
|
|
|
>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
<van-radio name="ali" />
|
|
|
|
<van-radio name="ali" />
|
|
|
|
</van-cell>
|
|
|
|
</van-cell>
|
|
|
|
<van-cell>
|
|
|
|
<van-cell>
|
|
|
|
<template slot="title">
|
|
|
|
<template slot="title">
|
|
|
|
<img src="../../../assets/images/wx_pay.png" alt="微信支付" width="113" height="23">
|
|
|
|
<img
|
|
|
|
|
|
|
|
src="../../../assets/images/wx_pay.png"
|
|
|
|
|
|
|
|
alt="微信支付"
|
|
|
|
|
|
|
|
width="113"
|
|
|
|
|
|
|
|
height="23"
|
|
|
|
|
|
|
|
>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
<van-radio name="wx" />
|
|
|
|
<van-radio name="wx" />
|
|
|
|
</van-cell>
|
|
|
|
</van-cell>
|
|
|
@ -31,12 +43,21 @@
|
|
|
|
</van-radio-group>
|
|
|
|
</van-radio-group>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<van-button class="pay_submit" type="primary" bottom-action @click="pay">去支付</van-button>
|
|
|
|
<van-button
|
|
|
|
|
|
|
|
class="pay_submit"
|
|
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
|
|
bottom-action
|
|
|
|
|
|
|
|
@click="pay"
|
|
|
|
|
|
|
|
>去支付</van-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import { orderDetail, orderPrepay, orderH5pay, testPayNotify } from '@/api/order'
|
|
|
|
import {
|
|
|
|
|
|
|
|
orderPrepay,
|
|
|
|
|
|
|
|
orderH5pay,
|
|
|
|
|
|
|
|
testPayNotify
|
|
|
|
|
|
|
|
} from '@/api/order'
|
|
|
|
import _ from 'lodash'
|
|
|
|
import _ from 'lodash'
|
|
|
|
import { getLocalStorage, setLocalStorage } from '@/utils/localStorage'
|
|
|
|
import { getLocalStorage, setLocalStorage } from '@/utils/localStorage'
|
|
|
|
|
|
|
|
|
|
|
@ -46,92 +67,110 @@ export default {
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
payWay: 'wx',
|
|
|
|
payWay: 'wx',
|
|
|
|
order: {},
|
|
|
|
orderSn: undefined,
|
|
|
|
orderId: 0
|
|
|
|
actualPrice: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
created() {
|
|
|
|
if (_.has(this.$route.params, 'orderId')) {
|
|
|
|
if (_.has(this.$route.params, 'orderSn')) {
|
|
|
|
this.orderId = this.$route.params.orderId
|
|
|
|
this.orderSn = this.$route.params.orderSn
|
|
|
|
this.getOrder(this.orderId)
|
|
|
|
this.actualPrice = this.$route.params.actualPrice
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
getOrder(orderId) {
|
|
|
|
|
|
|
|
orderDetail({ orderId }).then((res) => {
|
|
|
|
|
|
|
|
this.order = res.map.data
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
pay() {
|
|
|
|
pay() {
|
|
|
|
this.$dialog.alert({
|
|
|
|
this.$dialog
|
|
|
|
message:
|
|
|
|
.alert({
|
|
|
|
'你选择了' + (this.payWay === 'wx' ? '微信支付' : '支付宝支付')
|
|
|
|
message:
|
|
|
|
}).then(() => {
|
|
|
|
'你选择了' + (this.payWay === 'wx' ? '微信支付' : '支付宝支付')
|
|
|
|
if (this.payWay === 'wx') {
|
|
|
|
})
|
|
|
|
const ua = navigator.userAgent.toLowerCase()
|
|
|
|
.then(() => {
|
|
|
|
const isWeixin = ua.indexOf('micromessenger') !== -1
|
|
|
|
if (this.payWay === 'wx') {
|
|
|
|
if (isWeixin) {
|
|
|
|
const ua = navigator.userAgent.toLowerCase()
|
|
|
|
orderPrepay({ orderId: this.orderId })
|
|
|
|
const isWeixin = ua.indexOf('micromessenger') !== -1
|
|
|
|
.then((res) => {
|
|
|
|
if (isWeixin) {
|
|
|
|
const data = res.map.result
|
|
|
|
orderPrepay({ orderSn: this.orderSn })
|
|
|
|
const prepayData = JSON.stringify({
|
|
|
|
.then((res) => {
|
|
|
|
appId: data.appId,
|
|
|
|
const data = res.map.result
|
|
|
|
timeStamp: data.timeStamp,
|
|
|
|
const prepayData = JSON.stringify({
|
|
|
|
nonceStr: data.nonceStr,
|
|
|
|
appId: data.appId,
|
|
|
|
package: data.packageValue,
|
|
|
|
timeStamp: data.timeStamp,
|
|
|
|
signType: 'MD5',
|
|
|
|
nonceStr: data.nonceStr,
|
|
|
|
paySign: data.paySign
|
|
|
|
package: data.packageValue,
|
|
|
|
})
|
|
|
|
signType: 'MD5',
|
|
|
|
setLocalStorage({ prepay_data: prepayData })
|
|
|
|
paySign: data.paySign
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
setLocalStorage({ prepay_data: prepayData })
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof WeixinJSBridge === 'undefined') {
|
|
|
|
if (typeof WeixinJSBridge === 'undefined') {
|
|
|
|
if (document.addEventListener) {
|
|
|
|
if (document.addEventListener) {
|
|
|
|
document.addEventListener(
|
|
|
|
document.addEventListener(
|
|
|
|
'WeixinJSBridgeReady',
|
|
|
|
'WeixinJSBridgeReady',
|
|
|
|
this.onBridgeReady,
|
|
|
|
this.onBridgeReady,
|
|
|
|
false
|
|
|
|
false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else if (document.attachEvent) {
|
|
|
|
} else if (document.attachEvent) {
|
|
|
|
document.attachEvent(
|
|
|
|
document.attachEvent(
|
|
|
|
'WeixinJSBridgeReady',
|
|
|
|
'WeixinJSBridgeReady',
|
|
|
|
this.onBridgeReady
|
|
|
|
this.onBridgeReady
|
|
|
|
)
|
|
|
|
)
|
|
|
|
document.attachEvent(
|
|
|
|
document.attachEvent(
|
|
|
|
'onWeixinJSBridgeReady',
|
|
|
|
'onWeixinJSBridgeReady',
|
|
|
|
this.onBridgeReady
|
|
|
|
this.onBridgeReady
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.onBridgeReady()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
})
|
|
|
|
this.onBridgeReady()
|
|
|
|
.catch((err) => {
|
|
|
|
}
|
|
|
|
this.$dialog.alert({ message: err.map.msg })
|
|
|
|
})
|
|
|
|
this.$router.replace({
|
|
|
|
.catch((err) => {
|
|
|
|
name: 'paymentStatus',
|
|
|
|
this.$dialog.alert({ message: err.map.msg })
|
|
|
|
params: {
|
|
|
|
|
|
|
|
status: 'failed'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
orderH5pay({ orderSn: this.orderSn })
|
|
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
|
|
const data = res.map.data
|
|
|
|
|
|
|
|
window.location.replace(
|
|
|
|
|
|
|
|
data.mwebUrl +
|
|
|
|
|
|
|
|
'&redirect_url=' +
|
|
|
|
|
|
|
|
encodeURIComponent(
|
|
|
|
|
|
|
|
window.location.origin +
|
|
|
|
|
|
|
|
'/#/?orderSn=' +
|
|
|
|
|
|
|
|
this.orderSn +
|
|
|
|
|
|
|
|
'&tip=yes'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
|
|
console.log(err)
|
|
|
|
|
|
|
|
// this.$dialog.alert({ message: '支付失败' })
|
|
|
|
|
|
|
|
this.$router.replace({
|
|
|
|
|
|
|
|
name: 'PayStatus',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
|
|
|
|
status: 'failed'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// todo : alipay
|
|
|
|
|
|
|
|
testPayNotify(this.orderSn)
|
|
|
|
|
|
|
|
.then((res) => {
|
|
|
|
this.$router.replace({
|
|
|
|
this.$router.replace({
|
|
|
|
name: 'paymentStatus',
|
|
|
|
name: 'PayStatus',
|
|
|
|
params: {
|
|
|
|
params: {
|
|
|
|
status: 'failed'
|
|
|
|
status: 'success'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
|
|
|
|
orderH5pay({ orderId: this.orderId })
|
|
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
|
|
const data = res.map.data
|
|
|
|
|
|
|
|
window.location.replace(
|
|
|
|
|
|
|
|
data.mwebUrl +
|
|
|
|
|
|
|
|
'&redirect_url=' +
|
|
|
|
|
|
|
|
encodeURIComponent(
|
|
|
|
|
|
|
|
window.location.origin +
|
|
|
|
|
|
|
|
'/#/?orderId=' +
|
|
|
|
|
|
|
|
this.orderId +
|
|
|
|
|
|
|
|
'&tip=yes'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err)
|
|
|
|
console.log(err)
|
|
|
|
// this.$dialog.alert({ message: '支付失败' })
|
|
|
|
|
|
|
|
this.$router.replace({
|
|
|
|
this.$router.replace({
|
|
|
|
name: 'PayStatus',
|
|
|
|
name: 'PayStatus',
|
|
|
|
params: {
|
|
|
|
params: {
|
|
|
@ -140,28 +179,7 @@ export default {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
})
|
|
|
|
// todo : alipay
|
|
|
|
|
|
|
|
testPayNotify(this.orderId)
|
|
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
|
|
this.$router.replace({
|
|
|
|
|
|
|
|
name: 'PayStatus',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
|
|
|
|
status: 'success'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
|
|
console.log(err)
|
|
|
|
|
|
|
|
this.$router.replace({
|
|
|
|
|
|
|
|
name: 'PayStatus',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
|
|
|
|
status: 'failed'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onBridgeReady() {
|
|
|
|
onBridgeReady() {
|
|
|
|
const that = this
|
|
|
|
const that = this
|
|
|
@ -198,7 +216,6 @@ export default {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
@ -209,11 +226,11 @@ $mb2vw: 2vw;
|
|
|
|
background: #f5f5f5;
|
|
|
|
background: #f5f5f5;
|
|
|
|
|
|
|
|
|
|
|
|
.van-notice-bar {
|
|
|
|
.van-notice-bar {
|
|
|
|
margin-bottom: $mb2vw
|
|
|
|
margin-bottom: $mb2vw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.payment_group {
|
|
|
|
.payment_group {
|
|
|
|
margin-bottom: $mb2vw
|
|
|
|
margin-bottom: $mb2vw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pay_submit {
|
|
|
|
.pay_submit {
|
|
|
|