index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!-- -->
  2. <template>
  3. <div class="py-3" style="max-width: 900px; margin: 0 auto;min-width: 900px;">
  4. <v-card class=" pa-5">
  5. <v-btn class="mb-1" variant="text" size="x-large" prepend-icon="mdi-chevron-triple-left" color="primary" @click.stop="goBack">返回</v-btn>
  6. <div v-if="skuInfo">
  7. <confirm ref="confirmRef" :data="skuInfo" @orderCreated="orderCreated"></confirm>
  8. <div class="text-center">
  9. <v-btn color="primary" width="200" @click="onBuy">{{ confirmWord }}</v-btn>
  10. </div>
  11. </div>
  12. <div v-else>
  13. <Empty :elevation="false" message="结算已失效" />
  14. <div class="text-center my-5">
  15. <v-btn color="primary" width="200" to="/mall">返回商城首页</v-btn>
  16. </div>
  17. </div>
  18. <!-- 支付 -->
  19. <CtDialog :visible="showPay" titleClass="text-h6" :widthType="3" title="收银台" :footer="false" @close="payCancel">
  20. <pay ref="payRef" :id="payOrderId" @paySuccess="paySuccess"></pay>
  21. </CtDialog>
  22. </v-card>
  23. </div>
  24. </template>
  25. <script setup>
  26. defineOptions({name: 'confirm_order-index'})
  27. import Confirm from '@/plugins/confirm'
  28. import Snackbar from '@/plugins/snackbar'
  29. import { useI18n } from '@/hooks/web/useI18n'
  30. import { useRouter, useRoute } from 'vue-router'; const router = useRouter()
  31. import { ref } from 'vue'
  32. import confirm from './confirm.vue'
  33. import pay from './pay.vue'
  34. const { t } = useI18n()
  35. const route = useRoute()
  36. const { spuId } = route.query
  37. const skuInfo = ref(localStorage.getItem('confirm_order_data')) // 购买商品规格信息
  38. const confirmRef = ref()
  39. // onMounted(() => {
  40. // confirmRef.value.onConfirm()
  41. // })
  42. const onBuy = () => {
  43. if (payOrderId.value) {
  44. showPay.value = true
  45. } else {
  46. confirmRef.value.onConfirm()
  47. }
  48. }
  49. // 创建订单完成
  50. const payRef = ref()
  51. const showPay = ref(false)
  52. const payOrderId = ref('')
  53. const orderId = ref('')
  54. const orderCreated = (id, order) => {
  55. payOrderId.value = id
  56. orderId.value = order
  57. showPay.value = true
  58. }
  59. const confirmWord = ref('立即支付') // '立即购买' : '立即支付'
  60. let closeConfirm = false // 关闭路由拦截
  61. const paySuccess = (e) => {
  62. closeConfirm = true
  63. closeConfirm = true
  64. router.replace({ path: '/mall/payOver', query: { price: e.price, orderId: orderId.value, spuId } })
  65. // setTimeout(() => { router.replace('/recruit/personal/personalCenter/tradeOrder?key=1') }, 500);
  66. }
  67. const payCancel = () => {
  68. Snackbar.warning('您已取消支付!')
  69. showPay.value = false
  70. closeConfirm = true
  71. setTimeout(() => { router.replace('/recruit/personal/personalCenter/tradeOrder?key=1') }, 500);
  72. }
  73. const goBack = () => {
  74. if (!orderId.value) return router.go(-1)
  75. // 已经提交订单了则跳转到订单中心
  76. router.replace('/recruit/personal/personalCenter/tradeOrder?key=1')
  77. }
  78. router.beforeEach((to, from, next) => {
  79. if (!orderId.value || closeConfirm) {
  80. next()
  81. return
  82. }
  83. Confirm(t('common.confirmTitle'), '您尚未支付成功,是否确定离开?').then(async () => {
  84. closeConfirm = true
  85. router.replace('/recruit/personal/personalCenter/tradeOrder?key=1')
  86. })
  87. })
  88. </script>
  89. <style lang="scss" scoped>
  90. </style>