123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- import OHeader from '@/components/o-header'
- import { computed, defineComponent, onMounted, reactive, ref } from 'vue'
- import styles from './order-detail.module.less'
- import Addres from './component/addres'
- import OSticky from '@/components/o-sticky'
- import { Button, Cell, CellGroup, Image, Popup, showConfirmDialog, showToast, Tag } from 'vant'
- import Payment from '@/views/adapay/payment'
- import { useRoute, useRouter } from 'vue-router'
- import OQrcode from '@/components/o-qrcode'
- import request from '@/helpers/request'
- import { browser, moneyFormat } from '@/helpers/utils'
- import OProtocol from '@/components/o-protocol'
- export default defineComponent({
- name: 'order-detail',
- setup() {
- const route = useRoute()
- const router = useRouter()
- const state = reactive({
- orderTimer: null as any,
- paymentStatus: false,
- showQrcode: false,
- qrCodeUrl: '',
- pay_channel: '',
- orderNo: route.query.orderNo,
- orderInfo: {} as any, // 订单信息
- goodsInfos: [] as any, // 订单信息列表
- config: route.query.config ? JSON.parse(route.query.config as any) : {},
- hasFreight: route.query.hf ? false : true, // 是否显示
- freight: '', // 运费
- agreeStatus: true, //是否勾选协议
- showHeader: false
- })
- const orderType = computed(() => {
- return state.orderInfo.orderType
- })
- const addressDetails = ref<any>({})
- const getOrderDetails = async () => {
- try {
- const { data } = await request.get('/api-student/userPaymentOrder/detail/' + state.orderNo)
- const goodsInfos = data.goodsInfos || []
- state.orderInfo = data
- let hasInstrument = false // 是否有乐器
- let hasTextbook = false // 是否购买教材
- goodsInfos.forEach((item: any) => {
- const img = item.goodsUrl ? item.goodsUrl.split(',')[0] : ''
- item.goodsUrl = img
- if (item.goodsType === 'INSTRUMENTS') {
- hasInstrument = true
- } else if (item.goodsType === 'TEXTBOOK') {
- hasTextbook = true
- }
- })
- state.goodsInfos = goodsInfos
- if (!addressDetails.value.id) {
- addressDetails.value = data.addresses || {}
- }
- // 判断运费状态
- // 如果没有购买商品,有购买教材则『到付』 其它则免运费
- console.log(hasInstrument, hasTextbook)
- if (!hasInstrument && hasTextbook) {
- state.freight = '到付'
- } else {
- state.freight = '免运费'
- }
- // 判断订单状态,如果不是待支付则返回
- // WAIT_PAY: '待支付',
- // PAYING: '支付中',
- // PAID: '已付款',
- // TIMEOUT: '订单超时',
- // FAIL: '支付失败',
- // CLOSED: '订单关闭',
- // REFUNDING: '退款中',
- // REFUNDED: '已退款'
- if (data.status !== 'WAIT_PAY' && data.status !== 'PAYING') {
- // status
- showConfirmDialog({
- message: '订单处理中,请稍等',
- showCancelButton: false
- }).then(() => {
- router.replace({
- path: '/payment-result',
- query: {
- orderNo: state.orderNo
- }
- })
- })
- }
- } catch {
- //
- }
- }
- const onConfirm = (val: any) => {
- const config: any = state.config
- state.pay_channel = val.pay_channel
- if (val.payCode === 'payResult') {
- router.push({
- path: '/payResult',
- query: {
- pay_channel: val.pay_channel,
- wxAppId: config.wxAppId,
- body: config.body,
- price: config.price,
- orderNo: config.merOrderNo,
- userId: config.userId
- }
- })
- } else {
- state.qrCodeUrl =
- window.location.origin +
- '/orchestra-student/#/payDefine?pay_channel=' +
- val.pay_channel +
- '&wxAppId=' +
- config.wxAppId +
- '&body=' +
- config.body +
- '&price=' +
- config.price +
- '&orderNo=' +
- config.merOrderNo +
- '&userId=' +
- config.userId
- console.log(state.qrCodeUrl, 'qrCodeUrl')
- state.showQrcode = true
- state.paymentStatus = false
- setTimeout(() => {
- getPaymentOrderStatus()
- }, 300)
- }
- }
- const getPaymentOrderStatus = async () => {
- // 循环查询订单
- // const orderNo = state.orderNo
- const orderTimer = setInterval(async () => {
- // 判断是否在当前路由,如果不是则清除定时器
- if (route.name != 'orderDetail') {
- clearInterval(orderTimer)
- return
- }
- state.orderTimer = orderTimer
- try {
- const { data } = await request.post(
- '/api-student/open/userOrder/paymentStatus/' + state.orderNo,
- {
- hideLoading: true
- }
- )
- // console.log(data)
- if (data.status !== 'WAIT_PAY' && data.status !== 'PAYING') {
- clearInterval(orderTimer)
- window.location.replace(
- window.location.origin +
- '/orchestra-student/#/payment-result?orderNo=' +
- state.orderNo
- )
- }
- } catch {
- //
- clearInterval(orderTimer)
- }
- }, 5000)
- }
- const beforeSubmit = () => {
- const pt = state.pay_channel
- let payCode = 'qrCode'
- // 判断当前浏览器
- if (browser().weixin) {
- // 微信浏览器
- if (pt == 'alipay_qr' || pt == 'alipay_wap') {
- payCode = 'qrCode'
- } else if (pt == 'wx_pub') {
- payCode = 'pay'
- }
- } else if (browser().alipay) {
- // 支付宝浏览器
- if (pt == 'alipay_wap') {
- // 支付宝 H5 支付
- payCode = 'pay'
- } else {
- payCode = 'qrCode'
- }
- } else {
- payCode = 'qrCode'
- }
- onConfirm({
- payCode: payCode == 'qrCode' ? 'payDefine' : 'payResult',
- pay_channel: pt
- })
- }
- const onSubmit = async () => {
- clearInterval(state.orderTimer)
- if (orderType.value === 'VIP') {
- // onCallback()
- buyVip(onCallback)
- } else {
- buyOrchestra(onCallback)
- }
- }
- const onCallback = () => {
- const pt = state.pay_channel
- // 判断是否有支付方式
- if (pt) {
- beforeSubmit()
- } else {
- state.paymentStatus = true
- }
- }
- const buyVip = async (callback?: any) => {
- try {
- const { data } = await request.get('/api-student/userPaymentOrder/detail/' + state.orderNo)
- console.log(data)
- state.pay_channel = data.paymentChannel
- if (data.status === 'PAID') {
- showConfirmDialog({
- message: '该订单已支付成功',
- showCancelButton: false
- }).then(() => {
- router.replace({
- path: '/payment-result',
- query: {
- orderNo: state.orderNo
- }
- })
- })
- } else {
- callback && callback()
- }
- } catch {
- //
- }
- }
- const buyOrchestra = async (callback: any) => {
- // 请选择收货地址
- if (!addressDetails.value.id) {
- showToast('请选择收货地址')
- return
- }
- try {
- const { data } = await request.post('/api-student/userPaymentOrder/updateReceiveAddress', {
- data: {
- orderNo: state.orderNo,
- orderType: 'ORCHESTRA',
- receiveAddress: addressDetails.value.id
- }
- })
- console.log(data)
- state.pay_channel = data.paymentChannel
- if (data.status === 'PAID') {
- showConfirmDialog({
- message: '该订单已支付成功',
- showCancelButton: false
- }).then(() => {
- router.replace({
- path: '/payment-result',
- query: {
- orderNo: state.orderNo
- }
- })
- })
- } else {
- callback && callback()
- }
- } catch {
- //
- }
- }
- // 放弃支付时,则取消订单
- const onBackOut = async () => {
- try {
- await request.post('/api-student/userPaymentOrder/cancelPayment/' + state.orderNo)
- router.back()
- } catch {
- //
- }
- }
- onMounted(() => {
- if (browser().isApp) {
- state.showHeader = true
- } else {
- state.showHeader = false
- }
- // 获取收货地址
- let details = sessionStorage.getItem('addressDetails')
- details = details ? JSON.parse(details) : {}
- addressDetails.value = details
- sessionStorage.removeItem('addressDetails')
- getOrderDetails()
- })
- return () => (
- <>
- {browser().isApp && <OHeader border={false} />}
- <div class={styles.cartConfirm}>
- {/* 只有乐团购买的时候显示收货地址 */}
- {orderType.value === 'ORCHESTRA' && (
- <div class={styles.cartConfirmBox}>
- <Addres item={addressDetails.value} />
- </div>
- )}
- <CellGroup style={{ margin: 0 }}>
- {state.goodsInfos &&
- state.goodsInfos.map((goods: any) => (
- <Cell class={styles.cellItem} center>
- {{
- icon: () => <Image class={styles.img} src={goods.goodsUrl} />,
- title: () => (
- <div class={styles.goodsContent}>
- <h2>{goods.goodsName}</h2>
- <Tag type="primary">{goods.brandName}</Tag>
- <p class={styles.goodsNum}>{goods.goodsType === 'VIP' ? '6个月' : 'x 1'}</p>
- </div>
- ),
- value: () => (
- <span class={styles.cellPrice}>
- {goods.currentPrice > 0 ? '¥' + moneyFormat(goods.currentPrice) : '赠送'}
- </span>
- )
- }}
- </Cell>
- ))}
- </CellGroup>
- {orderType.value === 'ORCHESTRA' && (
- <Cell class={styles.freight} title="运费" value={state.freight}></Cell>
- )}
- <div class={styles.protocol}>
- <OProtocol
- v-model:modelValue={state.agreeStatus}
- showHeader={state.showHeader}
- style={{ paddingLeft: 0, paddingRight: 0 }}
- />
- </div>
- </div>
- <OSticky position="bottom" background="white">
- <div class={styles.paymentContainer}>
- <div class={styles.payemntPrice}>
- <p class={styles.needPrice}>
- 共需支付:<span>¥{moneyFormat(state.orderInfo.currentPrice)}</span>
- </p>
- </div>
- <div class={styles.paymentBtn}>
- <Button
- color="linear-gradient(135deg, #FF8C4A 0%, #FF531C 100%)"
- round
- onClick={onSubmit}
- >
- 立即购买
- </Button>
- </div>
- </div>
- </OSticky>
- <Popup
- show={state.paymentStatus}
- closeOnClickOverlay={false}
- position="bottom"
- round
- closeOnPopstate
- safeAreaInsetBottom
- style={{ minHeight: '30%' }}
- >
- <Payment
- paymentConfig={state.orderInfo}
- onClose={() => (state.paymentStatus = false)}
- onBackOut={onBackOut}
- onConfirm={(val: any) => onConfirm(val)}
- />
- </Popup>
- <Popup
- v-model:show={state.showQrcode}
- style={{ background: 'transparent', overflow: 'initial' }}
- safeAreaInsetBottom={true}
- class={styles.popupCode}
- closeable
- onClose={() => {
- // 二维码关闭时清除订单器
- clearInterval(state.orderTimer)
- }}
- >
- <div class={styles.codeContainer}>
- {/* <i class={styles.codeClose} onClick={() => (state.showQrcode = false)}></i> */}
- <div class={styles.codeImg}>
- <div class={styles.codeContent}>
- <h2 class={styles.codeTitle}>乐团报名</h2>
- <div class={styles.codeName}>
- 请截图下方二维码 登录{state.pay_channel === 'wx_pub' ? '微信' : '支付宝'}
- 扫码支付
- </div>
- <div class={styles.codeQr}>
- <OQrcode text={state.qrCodeUrl} size={'400'} />
- </div>
- <div style={{ textAlign: 'center' }}>
- <span class={styles.codeBtnText}>请在30分钟内扫码支付</span>
- </div>
- <div class={styles.codeTips}>
- <div class={styles.tipsTitle}>使用说明:</div>
- <div class={styles.tipsContent}>
- 1.长按二维码保存图片到相册(或截屏保存到相册)
- <br />
- 2.打开{state.pay_channel === 'wx_pub' ? '微信' : '支付宝'}扫一扫
- <br />
- 3.选择相册中的二维码
- <br />
- 4.请在30分钟内扫码支付
- </div>
- </div>
- </div>
- </div>
- </div>
- </Popup>
- </>
- )
- }
- })
|