|
@@ -18,25 +18,7 @@ import { defineComponent, PropType } from 'vue'
|
|
|
|
|
|
import styles from './index.module.less'
|
|
|
import { state } from '@/state'
|
|
|
-import { orderStatus } from '../orderStatus'
|
|
|
-
|
|
|
-interface IOrderInfo {
|
|
|
- orderNo: string | number
|
|
|
- actualPrice: string | number
|
|
|
-}
|
|
|
-
|
|
|
-const urlFix =
|
|
|
- state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student'
|
|
|
-const urlType = {
|
|
|
- goodsPay: {
|
|
|
- cancelUrl: '/api-mall-portal/order/cancelUserOrder',
|
|
|
- payUrl: '/api-mall-portal/payment/orderPay'
|
|
|
- },
|
|
|
- orderPay: {
|
|
|
- cancelUrl: urlFix + '/userOrder/orderCancel',
|
|
|
- payUrl: urlFix + '/userOrder/orderPay'
|
|
|
- }
|
|
|
-}
|
|
|
+import { validStudentUrl } from '@/helpers/utils'
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'payment',
|
|
@@ -46,10 +28,9 @@ export default defineComponent({
|
|
|
default: false
|
|
|
},
|
|
|
orderInfo: {
|
|
|
- type: Object as PropType<IOrderInfo>,
|
|
|
- default: {
|
|
|
- orderNo: '',
|
|
|
- actualPrice: 0
|
|
|
+ type: Object,
|
|
|
+ default: () => {
|
|
|
+ return {}
|
|
|
}
|
|
|
},
|
|
|
onBackOut: {
|
|
@@ -67,9 +48,6 @@ export default defineComponent({
|
|
|
pay_channel: ''
|
|
|
}
|
|
|
},
|
|
|
- unmounted() {
|
|
|
- removeListenerMessage('paymentOperation', this.paymentOperation)
|
|
|
- },
|
|
|
methods: {
|
|
|
onClose() {
|
|
|
Dialog.confirm({
|
|
@@ -83,20 +61,8 @@ export default defineComponent({
|
|
|
})
|
|
|
},
|
|
|
async onCancel(noBack?: boolean) {
|
|
|
- try {
|
|
|
- await request.post(urlType[this.paymentType].cancelUrl, {
|
|
|
- data: {
|
|
|
- orderNo: this.orderInfo.orderNo
|
|
|
- }
|
|
|
- })
|
|
|
- } catch {}
|
|
|
// 不管接口是否报错,都返回
|
|
|
this.$emit('update:modelValue', false)
|
|
|
- // 为了单独处理支付 曲目购买
|
|
|
- if (!noBack && orderStatus.orderObject.orderType == 'MUSIC') {
|
|
|
- postMessage({ api: 'back', content: {} })
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
!noBack && this.$router.go(-1)
|
|
|
this.onBackOut && this.onBackOut()
|
|
@@ -104,83 +70,72 @@ export default defineComponent({
|
|
|
async onSubmit() {
|
|
|
// 支付...
|
|
|
try {
|
|
|
- const params = {
|
|
|
- orderNo: this.orderInfo.orderNo,
|
|
|
- payChannel: this.payType,
|
|
|
- paymentClient: null as any
|
|
|
- }
|
|
|
- if (this.paymentType === 'goodsPay') {
|
|
|
- params.paymentClient = state.platformType
|
|
|
- }
|
|
|
- const res = await request.post(urlType[this.paymentType].payUrl, {
|
|
|
- data: {
|
|
|
- ...params
|
|
|
- }
|
|
|
- })
|
|
|
- postMessage({
|
|
|
- api: 'paymentOrder',
|
|
|
- content: {
|
|
|
- orderNo: this.orderInfo.orderNo,
|
|
|
- payChannel: this.payType,
|
|
|
- // payInfo: `alipays://platformapi/startapp?saId=10000007&qrcode=${res.data.pay_info}`
|
|
|
- payInfo: res.data.pay_info
|
|
|
- }
|
|
|
- })
|
|
|
+ console.log(this.orderInfo, 'orderInfo payment')
|
|
|
Toast.loading({
|
|
|
message: '支付中...',
|
|
|
forbidClick: true,
|
|
|
duration: 3000,
|
|
|
loadingType: 'spinner'
|
|
|
})
|
|
|
- Toast.clear()
|
|
|
+
|
|
|
+ const pt = this.payType,
|
|
|
+ ua = window.navigator.userAgent.toLowerCase()
|
|
|
+ // 判断当前浏览器
|
|
|
+ if (ua.match(/MicroMessenger/i) + '' == 'micromessenger') {
|
|
|
+ // 微信浏览器
|
|
|
+ if (pt == 'ali_app') {
|
|
|
+ this.pay_channel = 'alipay_qr'
|
|
|
+ this.getCodePay('qrCode')
|
|
|
+ } else if (pt == 'wx_app') {
|
|
|
+ this.pay_channel = 'wx_pub'
|
|
|
+ this.getCodePay('pay')
|
|
|
+ }
|
|
|
+ } else if (ua.match(/AlipayClient/i) + '' == 'alipayclient') {
|
|
|
+ // 支付宝浏览器
|
|
|
+ if (pt == 'ali_app') {
|
|
|
+ this.pay_channel = 'alipay_wap'
|
|
|
+ // 支付宝 H5 支付
|
|
|
+ this.getCodePay('pay')
|
|
|
+ } else if (pt == 'wx_app') {
|
|
|
+ this.pay_channel = 'wx_pub'
|
|
|
+ this.getCodePay('qrCode')
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (pt == 'ali_app') {
|
|
|
+ this.pay_channel = 'alipay_qr'
|
|
|
+ } else if (pt == 'wx_app') {
|
|
|
+ this.pay_channel = 'wx_pub'
|
|
|
+ }
|
|
|
+ this.getCodePay('qrCode')
|
|
|
+ }
|
|
|
this.$emit('update:modelValue', false)
|
|
|
- // 唤起支付时状态
|
|
|
- listenerMessage('paymentOperation', result => {
|
|
|
- console.log(result, 'init paymentOperation')
|
|
|
- this.paymentOperation(result?.content)
|
|
|
- })
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ Toast.clear()
|
|
|
+ }, 1000)
|
|
|
} catch (e: any) {
|
|
|
console.log(e)
|
|
|
}
|
|
|
},
|
|
|
- paymentOperation(res: any) {
|
|
|
- console.log(res, 'paymentOperation', this.paymentType, this.orderInfo)
|
|
|
-
|
|
|
- // 支付状态
|
|
|
- // paymentOperation 支付成功:success 支付失败:error 支付取消:cancel 未安装:fail
|
|
|
- // error 只有安卓端有
|
|
|
- if (res.status === 'success' || res.status === 'error') {
|
|
|
- Toast.clear()
|
|
|
- this.$emit('update:modelValue', false)
|
|
|
- if (this.paymentType === 'goodsPay') {
|
|
|
- this.$router.replace({
|
|
|
- path: '/shopTrade',
|
|
|
- query: {
|
|
|
- orderNo: this.orderInfo.orderNo
|
|
|
- }
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- this.$router.replace({
|
|
|
- path: '/tradeDetail',
|
|
|
- query: {
|
|
|
- orderNo: this.orderInfo.orderNo
|
|
|
- }
|
|
|
- })
|
|
|
- } else if (res.status === 'cancel') {
|
|
|
- Toast.clear()
|
|
|
- this.$emit('update:modelValue', false)
|
|
|
- } else if (res.status === 'fail') {
|
|
|
- const message =
|
|
|
- this.payType === 'ali_app' ? '您尚未安装支付宝' : '您尚未安装微信'
|
|
|
- Dialog.alert({
|
|
|
- title: '提示',
|
|
|
- message
|
|
|
- }).then(() => {
|
|
|
- Toast.clear()
|
|
|
- this.$emit('update:modelValue', false)
|
|
|
- })
|
|
|
+ getCodePay(code) {
|
|
|
+ // 二维码页面, 唤起支付页面
|
|
|
+ let url = validStudentUrl()
|
|
|
+ if (code == 'qrCode') {
|
|
|
+ url += `/#/payQRCode`
|
|
|
+ } else {
|
|
|
+ url += `/#/payResult`
|
|
|
}
|
|
|
+ const orderInfo = this.orderInfo
|
|
|
+ orderInfo.payMap.returnUrl = orderInfo.payMap.returnUrl.replace(
|
|
|
+ /&/gi,
|
|
|
+ '^^'
|
|
|
+ )
|
|
|
+ const navHeight = sessionStorage.getItem('navHeight') || 0
|
|
|
+ // p 表示是商品购买,需要单独去学生端处理
|
|
|
+ url += `?payType=${this.pay_channel}&payment=${JSON.stringify(
|
|
|
+ this.orderInfo
|
|
|
+ )}&navHeight=${navHeight}'&platform=goods`
|
|
|
+ window.location.href = url
|
|
|
}
|
|
|
},
|
|
|
render() {
|
|
@@ -192,7 +147,9 @@ export default defineComponent({
|
|
|
<div class={styles.payAmount}>
|
|
|
<p>应付金额</p>
|
|
|
<div class={styles.amount}>
|
|
|
- {(this as any).$filters.moneyFormat(this.orderInfo.actualPrice)}
|
|
|
+ {(this as any).$filters.moneyFormat(
|
|
|
+ this.orderInfo.payMap.amount || 0
|
|
|
+ )}
|
|
|
<span>元</span>
|
|
|
</div>
|
|
|
</div>
|