提交 3bdada40 authored 作者: matian's avatar matian

updates

上级 a960cf42
...@@ -17,5 +17,7 @@ ...@@ -17,5 +17,7 @@
<body> <body>
<div id="app"></div> <div id="app"></div>
<script type="module" src="/src/main.ts"></script> <script type="module" src="/src/main.ts"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</body> </body>
</html> </html>
...@@ -43,7 +43,7 @@ export default { ...@@ -43,7 +43,7 @@ export default {
} }
.rigth-aside { .rigth-aside {
position: fixed; position: fixed;
top: 50%; top: 70%;
right: 16px; right: 16px;
z-index: 99; z-index: 99;
transform: translateY(-50%); transform: translateY(-50%);
......
...@@ -3,11 +3,10 @@ import { ElMessage } from 'element-plus' ...@@ -3,11 +3,10 @@ import { ElMessage } from 'element-plus'
import { Check } from '@element-plus/icons-vue' import { Check } from '@element-plus/icons-vue'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { useDevice } from '@/composables/useDevice' import { useDevice } from '@/composables/useDevice'
import { wxJSPay } from '@/utils/wxpay' import { wxJSPay, getOpenId } from '@/utils/wxpay'
import { createOrder, getOrderList } from '../api' import { createOrder, getOrderList } from '../api'
import { getOpenId } from '@/api/base' import queryString from 'query-string'
const router = useRouter() const router = useRouter()
const route = useRoute()
const { mobile, wechat, alipay } = useDevice() const { mobile, wechat, alipay } = useDevice()
const user = useUserStore() const user = useUserStore()
const props = defineProps({ const props = defineProps({
...@@ -15,13 +14,12 @@ const props = defineProps({ ...@@ -15,13 +14,12 @@ const props = defineProps({
type: Object type: Object
} }
}) })
const openId: any = ref(window.localStorage.getItem('openId'))
const payment_method = ref('') const orderInfo: any = ref({})
const orderInfoDetail: any = ref([])
const payMode = ref(1) const payMode = ref(1)
const isAgree = ref(false) const isAgree = ref(false)
const currentCheck = ref('12') const currentCheck = ref('4')
const timer = ref() const orderInfoDetail: any = ref([])
function getDateTime(dayNum: any) { function getDateTime(dayNum: any) {
const dateDay = new Date() const dateDay = new Date()
dateDay.setDate(dateDay.getDate() + dayNum) //获取dayNum天后的日期 dateDay.setDate(dateDay.getDate() + dayNum) //获取dayNum天后的日期
...@@ -36,82 +34,23 @@ function getDateTime(dayNum: any) { ...@@ -36,82 +34,23 @@ function getDateTime(dayNum: any) {
} }
const start_time = getDateTime(0) const start_time = getDateTime(0)
const end_time = getDateTime(90) const end_time = getDateTime(90)
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'success', params: object): void (e: 'success', params: object): void
}>() }>()
const checkdChange = (val: string) => { const checkdChange = (val: string) => {
currentCheck.value = val currentCheck.value = val
} }
// const optionParams = reactive({
// shop_id: '6998523899570814976',
// spu_id: '6998525810348916736',
// sku_id: '6998525810365693952',
// redirect_url: '',
// buy_count: '1',
// payment_method: '',
// notify_url: `https://ep-lms-api.ezijing.com/v2/student/push?tenant=paa&sso_id=${user.user?.id}&class_id=${props.shopItem?.class_id}&course_flag=1&course_id=${props.shopItem?.course_id}`
// })
// 获取订单
const getOrder = (val: any) => {
getOrderList({ order_detail_id: val }).then((resp) => {
orderInfoDetail.value = resp.data[0]
const params = {
status: 'success',
orderId: orderInfoDetail.value.order_id,
payPrice: orderInfoDetail.value.payment_money,
payStatus: orderInfoDetail.value.order_status
}
clearInterval(timer.value)
emit('success', params)
})
}
// 创建订单
const handleCreateOrder = () => {
const params: any = {
shop_id: '6998523899570814976',
spu_id: '6998525810348916736',
sku_id: '6998525810365693952',
redirect_url: '',
buy_count: '1',
notify_url: `https://ep-lms-api.ezijing.com/v2/student/push?tenant=paa&sso_id=${user.user?.id}&class_id=${props.shopItem?.class_id}&course_flag=1&course_id=${props.shopItem?.course_id}`
}
if (wechat && currentCheck.value === '4') {
if (openId.value) {
params.open_id = openId.value
params.payment_method = '3'
fetchPlaceOrder(params)
}
} else if (alipay && currentCheck.value === '12') {
params.payment_method = '12'
fetchPlaceOrder(params)
}
}
const fetchPlaceOrder = (params: any) => {
createOrder(params).then((res) => {
placeOrderCallback(res)
})
}
const placeOrderCallback = (res: any) => {
const payType = payment_method.value
if (payType === '3') {
// 微信内支付
if (typeof res.payment_more_info === 'string') {
const payInfo = JSON.parse(res.payment_more_info)
if (payInfo.appId) {
wxJSPay(res, getOrder)
}
}
} else if (payType === '4') {
// 微信外微信h5支付
window.location.href =
res.payment_url +
'&redirect_url=' +
encodeURIComponent(res.order_details_url)
timer.value = setInterval(() => {
// 通过定时器每间隔一会去请求查询微信支付状态(具体参数根据项目需要而定)
getOrder(res.order_detail_id)
}, 2000)
} else if (payType === '12') {
// 支付宝网页支付
window.location.href = res.payment_url
timer.value = setInterval(() => {
// 通过定时器每间隔一会去请求查询微信支付状态(具体参数根据项目需要而定)
getOrder(res.order_detail_id)
}, 2000)
}
}
// 点击立即购买 // 点击立即购买
const handlePay = () => { const handlePay = () => {
if (isAgree.value === false) { if (isAgree.value === false) {
...@@ -119,14 +58,17 @@ const handlePay = () => { ...@@ -119,14 +58,17 @@ const handlePay = () => {
} else { } else {
if (user.isLogin) { if (user.isLogin) {
if (!mobile.value) { if (!mobile.value) {
//pc
const params = { const params = {
payMode: payMode.value, payMode: payMode.value,
status: 'order' status: 'order'
} }
emit('success', params) emit('success', params)
} else { } else {
// H5创建订单 //H5
handleCreateOrder() if (mobile && (wechat || alipay)) {
pay()
}
} }
} else { } else {
window.location.href = `${ window.location.href = `${
...@@ -136,6 +78,71 @@ const handlePay = () => { ...@@ -136,6 +78,71 @@ const handlePay = () => {
} }
} }
// 去支付
// const pay = () => {
// createOrderHandle().then((order: any) => {
// orderInfo.value = order
// if (wechat) {
// wxJSPay(order, payCallback(optionParams))
// } else {
// location.href = order.payment_url // '4' \ '12'
// getOrder()
// }
// })
// }
// // 支付回调
// const payCallback = async (options: any) => {
// const { callback } = options
// const order = await getOrder()
// callback && callback(order)
// const params = {
// status: 'success',
// orderId: order.order_id,
// payPrice: order.payment_money,
// payStatus: order.order_status
// }
// orderInfoDetail.value = order.order_status
// emit('success', params)
// }
// // 创建订单
// const createOrderHandle = () => {
// let defaultParams = {}
// // 微信内
// if (wechat) {
// const openId = localStorage.getItem('openId')
// if (!openId) {
// getOpenId(
// queryString.parse(location.search, { parseBooleans: true }).code,
// pay
// )
// return Promise.reject('openId不存在')
// }
// defaultParams = { open_id: openId, payment_method: '3' }
// }
// // 支付宝网页支付
// if (currentCheck.value === '12') {
// defaultParams = { payment_method: '12' }
// }
// //微信外微信h5支付
// if (currentCheck.value === '4') {
// defaultParams = { payment_method: '4' }
// }
// const params = Object.assign(optionParams, defaultParams)
// return createOrder(params).then((resp: any) => resp.data)
// }
// // 获取订单
// function getOrder() {
// return getOrderList({
// order_detail_id: orderInfo.value.order_detail_id
// }).then((resp) => {
// return resp.data[0]
// })
// }
const handlePrev = () => { const handlePrev = () => {
router.push({ router.push({
path: `/shop/detail/${props.shopItem?.id}`, path: `/shop/detail/${props.shopItem?.id}`,
...@@ -144,38 +151,7 @@ const handlePrev = () => { ...@@ -144,38 +151,7 @@ const handlePrev = () => {
} }
}) })
} }
const fetchOpenId = (code: any) => {
getOpenId({ code, identity: 'ezijing' }).then((res: any) => {
if (res.openid) {
openId.value = res.openid || ''
window.localStorage.setItem('openId', res.openid || '')
} else {
window.localStorage.removeItem('openId')
getCode()
}
})
}
const getCode = () => {
const redirectURI = `https://pages.ezijing.com/given/auth.html?redirect_uri=${encodeURIComponent(
window.location.href
)}`
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx451c01d40d090d7a&redirect_uri=${redirectURI}&response_type=code&scope=snsapi_base#wechat_redirect`
}
if (
(openId.value === '' ||
openId.value === null ||
openId.value === undefined) &&
wechat
) {
const { code } = route.query
if (code) {
fetchOpenId(code)
} else {
getCode()
}
}
</script> </script>
<template> <template>
<div> <div>
<div class="main_con" v-if="!mobile"> <div class="main_con" v-if="!mobile">
...@@ -386,11 +362,11 @@ if ( ...@@ -386,11 +362,11 @@ if (
color: #333333; color: #333333;
} }
.info_date { .info_date {
height: 0.22rem;
font-size: 0.22rem; font-size: 0.22rem;
font-weight: 400; font-weight: 400;
line-height: 0.3rem; line-height: 0.3rem;
color: #999999; color: #999999;
white-space: nowrap;
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论