checkOut.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. needLogin: true,
  5. style: {
  6. navigationBarTitleText: '%checkout.title%',
  7. navigationBarBackgroundColor: '#fff',
  8. },
  9. }
  10. </route>
  11. <script lang="ts" setup>
  12. import { computedPrice, createOrder, loadPre } from '@/api/order'
  13. import { getWalletAccountInfo } from '@/api/wallet'
  14. import { formatNumber } from '@/utils'
  15. import { getPageParams, toPage } from '@/utils/page'
  16. defineOptions({
  17. name: 'CheckOut', // 结账页面
  18. })
  19. const queryParams = ref<any>({})
  20. onLoad((options) => {
  21. const params = getPageParams(options)
  22. queryParams.value = params
  23. getPrice()
  24. })
  25. // 商品详情
  26. const orderDetail = ref<any>({})
  27. // 订单摘要
  28. const orderSummary = ref({
  29. SubTotal: 0,
  30. // Voucher: 0,
  31. Total: 0,
  32. })
  33. // 钱包余额
  34. const walletBalance = ref(0)
  35. async function getPrice() {
  36. // 预下单详情
  37. const preOrderRes = await loadPre({ preOrderNo: queryParams.value.preOrderId })
  38. console.log(preOrderRes)
  39. orderDetail.value = preOrderRes?.data?.orderInfoVo?.orderDetailList?.[0]
  40. // 计算价格
  41. const computedPriceRes = await computedPrice({ preOrderNo: queryParams.value.preOrderId, shippingType: 1 })
  42. console.log(computedPriceRes)
  43. orderSummary.value.SubTotal = computedPriceRes?.data?.proTotalFee
  44. orderSummary.value.Total = computedPriceRes?.data?.payFee
  45. // 获取钱包信息-查询余额
  46. const walletInfoRes = await getWalletAccountInfo()
  47. console.log(walletInfoRes)
  48. walletBalance.value = walletInfoRes?.data?.balance
  49. }
  50. const loading = ref<boolean>(false)
  51. // 下单处理
  52. async function handlePlaceOrder() {
  53. loading.value = true
  54. try {
  55. const params = {
  56. preOrderNo: queryParams.value.preOrderId,
  57. type: queryParams.value.groupType,
  58. pinkId: queryParams.value.pinkId,
  59. cid: queryParams.value.cid,
  60. groupType: queryParams.value.groupType,
  61. }
  62. const orderRes = await createOrder(params)
  63. console.log(orderRes)
  64. if (orderRes.code === '200') {
  65. toPage('/pages/myOrders/orderDetail', { id: orderRes?.data?.columns?.orderId, isPayOrder: true }, true)
  66. }
  67. }
  68. finally {
  69. loading.value = false
  70. }
  71. }
  72. </script>
  73. <template>
  74. <z-paging>
  75. <view class="pt-20rpx">
  76. <view class="mb-20rpx flex items-center gap-24rpx bg-white p-24rpx">
  77. <image
  78. :src="orderDetail.image"
  79. class="h-160rpx w-160rpx shrink-0"
  80. mode="aspectFit"
  81. />
  82. <view class="flex-1">
  83. <view class="line-clamp-2 h-80rpx text-28rpx">
  84. {{ orderDetail.productName }}
  85. </view>
  86. <view class="py-4rpx text-24rpx text-#3A444C">
  87. {{ $t('checkout.selected') }}: {{ orderDetail.sku }}
  88. </view>
  89. <view class="flex items-center justify-between text-24rpx">
  90. <view class="text-#FF0010">
  91. ৳ {{ formatNumber(orderDetail.price) }}
  92. </view>
  93. <view class="text-#3A444C">
  94. {{ $t('checkout.quantity') }}:{{ orderDetail.payNum }}
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. <view class="mb-20rpx bg-white p-24rpx">
  100. <view class="mb-12rpx text-28rpx">
  101. {{ $t('checkout.orderSummary') }}
  102. </view>
  103. <view class="flex flex-col gap-16rpx text-#3A444C">
  104. <template v-for="(item, key) in orderSummary" :key="key">
  105. <view class="flex items-center justify-between text-24rpx">
  106. <text>{{ key }}</text>
  107. <text>৳ {{ formatNumber(item) }}</text>
  108. </view>
  109. </template>
  110. </view>
  111. </view>
  112. <view class="bg-white p-24rpx">
  113. <view class="mb-12rpx text-28rpx">
  114. {{ $t('checkout.selectPaymentMethod') }}
  115. </view>
  116. <view class="flex flex-col gap-16rpx text-#3A444C">
  117. <view class="flex items-center justify-between text-24rpx">
  118. <view class="flex items-center">
  119. <image
  120. src="/static/icons/logo.png"
  121. class="mr-32rpx h-68rpx w-68rpx rounded-full"
  122. />
  123. <view class="text-24rpx">
  124. <text>{{ $t('orderDetail.bandhuBuyWallet') }}(</text>
  125. <text class="text-[var(--wot-color-theme)]">
  126. {{ $t('orderDetail.walletBalanceText') }}: ৳ {{ formatNumber(walletBalance) }}
  127. </text>
  128. <text>)</text>
  129. </view>
  130. </view>
  131. <view>
  132. <image
  133. src="/static/icons/circle-check.png"
  134. class="h-36rpx w-36rpx"
  135. />
  136. </view>
  137. </view>
  138. </view>
  139. </view>
  140. </view>
  141. <template #bottom>
  142. <view class="flex items-center justify-end bg-white/60 px-28rpx py-30rpx backdrop-blur-20">
  143. <view class="mr-16rpx text-24rpx">
  144. <text>{{ $t('checkout.total') }}:</text>
  145. <text class="text-[var(--wot-color-theme)]">
  146. ৳ {{ formatNumber(orderSummary.Total) }}
  147. </text>
  148. </view>
  149. <wd-button :loading="loading" @click="handlePlaceOrder">
  150. {{ $t('checkout.placeOrder') }}
  151. </wd-button>
  152. </view>
  153. </template>
  154. </z-paging>
  155. </template>
  156. <style lang="scss" scoped>
  157. .space-y-24rpx > * + * {
  158. margin-top: 24rpx;
  159. }
  160. </style>