Ver Fonte

feat: 创建订单支付调试

liangan há 2 semanas atrás
pai
commit
1bf7660540

+ 15 - 1
src/api/order.ts

@@ -1,6 +1,13 @@
 import { qs } from '@/utils'
 import { http } from '@/utils/http'
 
+/**
+ * 去拼团-加入
+ * @returns
+ */
+export function joinPink(data: any) {
+  return http.post<any>(`/mall/combination/pink`, data)
+}
 /**
  * 商品预下单
  * @returns
@@ -23,9 +30,16 @@ export function computedPrice(data: any) {
   return http.post<any>(`/mall/order/computed/price`, data)
 }
 /**
- * 支付-创建订单
+ * 创建订单
  * @returns
  */
 export function createOrder(data: any) {
   return http.post<any>(`/mall/order/add`, data)
 }
+/**
+ * 支付
+ * @returns
+ */
+export function payOrder(data: any) {
+  return http.post<any>(`/mall/order/goPay?${qs(data)}`)
+}

+ 1 - 1
src/api/product.ts

@@ -23,5 +23,5 @@ export function getDetail(data: any) {
  * @returns data.list[]
  */
 export function pinkList(data: any) {
-  return http.post<any>(`/mall/pink/list`, data)
+  return http.post<any>(`/mall/pink/ongoing/list`, data)
 }

+ 14 - 4
src/pages/productDetail/checkOut.vue

@@ -10,13 +10,13 @@
 </route>
 
 <script lang="ts" setup>
-import { computedPrice, createOrder, loadPre } from '@/api/order'
+import { computedPrice, createOrder, loadPre, payOrder } from '@/api/order'
 import { getWalletInfo } from '@/api/wallet'
 import DialogBox from '@/components/DialogBox/DialogBox.vue'
 import { DialogUtils } from '@/components/DialogBox/utils'
 import { useUserStore } from '@/store'
 import { formatNumber } from '@/utils'
-import { getPageParams } from '@/utils/page'
+import { getPageParams, toPage } from '@/utils/page'
 
 defineOptions({
   name: 'CheckOut', // 结账页面
@@ -144,8 +144,18 @@ async function handlePlaceOrder() {
     preOrderNo: orderId.value,
     userId: userInfo.value.userId,
   }
-  const res = await createOrder(params)
-  console.log(res)
+  const orderRes = await createOrder(params)
+  console.log(orderRes)
+  if (orderRes.code === '200') {
+    const payRes = await payOrder({ orderId: 5 })
+    console.log(payRes)
+    if (payRes.code === '8000') {
+      showInsufficientBalanceDialog()
+    }
+    else {
+      toPage('/pages/myOrders/myOrders', {}, true)
+    }
+  }
 }
 
 // 处理对话框确认事件

+ 23 - 9
src/pages/productDetail/productDetail.vue

@@ -12,7 +12,7 @@
 // eslint-disable-next-line unused-imports/no-unused-imports
 import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
 import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
-import { preOrder as _preOrder } from '@/api/order'
+import { preOrder as _preOrder, joinPink } from '@/api/order'
 import { getDetail, pinkList } from '@/api/product'
 import { formatNumber } from '@/utils/index'
 import { getPageParams, goBack, toPage } from '@/utils/page'
@@ -97,12 +97,15 @@ const avatarList = ref([
 
 // 拼团类型 join-加团 open-开团
 const groupType = ref('open')
+const pinkId = ref('') // 拼团id
 
 // sku 逻辑
 const showSku = ref(false)
-function openSku(type: string) {
+function openSku(type: string, id?: string) {
   showSku.value = true
   groupType.value = type
+  if (id)
+    pinkId.value = id
 }
 const formData = ref({
   productNum: 1,
@@ -250,6 +253,13 @@ async function preOrder() {
   if (!requireLogin()) {
     return
   }
+  if (groupType.value === 'join') {
+    await joinPink({
+      cid: id.value,
+      pinkId: pinkId.value,
+      userId: userInfo.value.userId,
+    })
+  }
   const data = {
     orderDetails: {
       attrValueId: matchedAttrValue.value.id,
@@ -260,8 +270,10 @@ async function preOrder() {
     userId: userInfo.value.userId,
   }
   const res = await _preOrder(data)
-  console.log(res)
-  toPage('/pages/productDetail/checkOut', { orderId: res.data })
+  if (res.code === '200') {
+    showSku.value = false
+    toPage('/pages/productDetail/checkOut', { orderId: res.data })
+  }
 }
 
 // 商品详情初始化
@@ -269,6 +281,8 @@ onLoad((options) => {
   console.log(options)
   const params = getPageParams(options)
   id.value = params.id
+})
+onShow(() => {
   queryDetail()
   queryPinkInfo()
 })
@@ -371,14 +385,14 @@ onLoad((options) => {
           <view class="flex items-center">
             <view>
               <!-- 头像组 最多五个 -->
-              <view class="mr-16rpx flex items-center">
+              <view class="mr-16rpx min-w-220rpx flex items-center">
                 <view
-                  v-for="(e, i) in avatarList.slice(0, 5)"
+                  v-for="(e, i) in item.successAvatar.slice(0, 5)"
                   :key="i"
                   :style="{ marginLeft: i !== 0 ? '-20rpx' : '0', zIndex: 10 - i }"
                   class="h-56rpx w-56rpx overflow-hidden border-2rpx border-white rounded-full border-solid"
                 >
-                  <image :src="e" class="h-full w-full" mode="aspectFill" />
+                  <image :src="e ? e : '/static/images/default-avatar.png'" class="h-full w-full" mode="aspectFill" />
                 </view>
               </view>
             </view>
@@ -386,13 +400,13 @@ onLoad((options) => {
               <view class="text-28rpx">
                 Need
                 <text class="text-[var(--wot-color-theme)]">
-                  5
+                  {{ item.remainNum }}
                 </text>
                 More
               </view>
             </view>
           </view>
-          <wd-button size="small" @click="openSku('join')">
+          <wd-button size="small" @click="openSku('join', item.id)">
             Join Group
           </wd-button>
         </view>