ソースを参照

更改购物车sku

dxz1228 2 年 前
コミット
e2ebe2e54c
共有3 個のファイルを変更した142 個の追加14 個の削除を含む
  1. 5 0
      src/apis/model/order.model.ts
  2. 15 1
      src/apis/order.api.ts
  3. 122 13
      src/pages/order_addcart/index.vue

+ 5 - 0
src/apis/model/order.model.ts

@@ -275,6 +275,11 @@ export interface OrderCreateShoppingModel {
275
     cart_id: string
275
     cart_id: string
276
 }
276
 }
277
 
277
 
278
+export interface ProductSkuModel {
279
+    cart_id: string,
280
+    unique : string
281
+}
282
+
278
 export interface OrderCheckModel {
283
 export interface OrderCheckModel {
279
     order_price: string
284
     order_price: string
280
     total_price: string
285
     total_price: string

+ 15 - 1
src/apis/order.api.ts

@@ -2,7 +2,7 @@ import {defHttp} from "~/utils/http"
2
 
2
 
3
 import type {
3
 import type {
4
     IntegralOrderCreateModel, OrderCheckModel, OrderCreateModel,
4
     IntegralOrderCreateModel, OrderCheckModel, OrderCreateModel,
5
-    OrderCreateShoppingModel, OrderListDataModel, OrderListObligationResult, OrderListResult, OrderQuantityModel
5
+    OrderCreateShoppingModel, ProductSkuModel, OrderListDataModel, OrderListObligationResult, OrderListResult, OrderQuantityModel
6
 } from "~/apis/model/order.model"
6
 } from "~/apis/model/order.model"
7
 import type {ThirdOrderResult} from "~/apis/model/third-order.model";
7
 import type {ThirdOrderResult} from "~/apis/model/third-order.model";
8
 import type {CommentProductRequest} from "~/apis/model/comment-product";
8
 import type {CommentProductRequest} from "~/apis/model/comment-product";
@@ -33,6 +33,8 @@ enum API {
33
     ORDER_CHECK = '/api/order/check',
33
     ORDER_CHECK = '/api/order/check',
34
     // 修改购物车数量
34
     // 修改购物车数量
35
     USER_CART_CHANGE = '/api/user/cart/change',
35
     USER_CART_CHANGE = '/api/user/cart/change',
36
+    // 修改购物车商品的sku属性
37
+    CHANGE_PRODUCT_SKU = '/api/user/cart/changeUnique',
36
     // 创建订单 | 积分创建订单
38
     // 创建订单 | 积分创建订单
37
     ORDER_CREATE = '/api/order/create',
39
     ORDER_CREATE = '/api/order/create',
38
     // 获取支付宝路径
40
     // 获取支付宝路径
@@ -206,6 +208,18 @@ export function createShopping(params: {
206
     })
208
     })
207
 }
209
 }
208
 
210
 
211
+/**
212
+ * 改变购物车商品sku
213
+ */
214
+export function changeProdoctSku(cart_id:string,unique:string): Promise<ProductSkuModel> {
215
+    console.log(unique,'order的api接收的unique')
216
+    return defHttp.post({
217
+        url:API.CHANGE_PRODUCT_SKU + `/${cart_id}?unique=${unique}`,
218
+        data:{
219
+            unique
220
+        }
221
+    })
222
+}
209
 
223
 
210
 /**
224
 /**
211
  * 选择订单商品
225
  * 选择订单商品

+ 122 - 13
src/pages/order_addcart/index.vue

@@ -1,7 +1,7 @@
1
 <script lang="ts" setup>
1
 <script lang="ts" setup>
2
-import {getRecommendList} from "~/apis/merchant";
2
+import {getRecommendList ,getProductDetail} from "~/apis/merchant";
3
 import MerchantProductCard from "~/pages/store/home/components/MerchantProductCard.vue";
3
 import MerchantProductCard from "~/pages/store/home/components/MerchantProductCard.vue";
4
-import {deleteCartItem, getCartCount, getCartList} from "~/apis/user";
4
+import {deleteCartItem, getCartCount, getCartList,xcxBanding} from "~/apis/user";
5
 import type {ShoppingResult} from "~/apis/model/shopping.model";
5
 import type {ShoppingResult} from "~/apis/model/shopping.model";
6
 import FPrice from "~/components/FPrice/FPrice.vue";
6
 import FPrice from "~/components/FPrice/FPrice.vue";
7
 import FButton from "~/components/FButton/FButton.vue";
7
 import FButton from "~/components/FButton/FButton.vue";
@@ -13,11 +13,13 @@ import {
13
   TaobaoProductThirdPartyWaresModel, VipProductModel
13
   TaobaoProductThirdPartyWaresModel, VipProductModel
14
 } from "~/apis/model/product.model";
14
 } from "~/apis/model/product.model";
15
 import {DcProductModel} from "~/apis/model/dacang.model";
15
 import {DcProductModel} from "~/apis/model/dacang.model";
16
+import {createShopping , changeProdoctSku} from "~/apis/order.api";
16
 import {encodeBase64} from "~/utils/http/helper";
17
 import {encodeBase64} from "~/utils/http/helper";
17
 import {CDN_URL} from "~/config/app";
18
 import {CDN_URL} from "~/config/app";
18
 import {uniq} from "lodash-es";
19
 import {uniq} from "lodash-es";
19
 import {cartChange} from "~/apis/order.api";
20
 import {cartChange} from "~/apis/order.api";
20
 import type CXBBackTop from "~/components/CXBBackTop/CXBBackTop.vue";
21
 import type CXBBackTop from "~/components/CXBBackTop/CXBBackTop.vue";
22
+import CXBSkuPopup from "~/components/CXBSkuPopup/CXBSkuPopup.vue";
21
 const gouwucheImage = CDN_URL + '/static/assets/gouwuche.png'
23
 const gouwucheImage = CDN_URL + '/static/assets/gouwuche.png'
22
 const like_adorn_220628Image = CDN_URL + '/static/assets/like_adorn_220628.png'
24
 const like_adorn_220628Image = CDN_URL + '/static/assets/like_adorn_220628.png'
23
 const pageStore = usePageStoreWidthOut()
25
 const pageStore = usePageStoreWidthOut()
@@ -36,11 +38,73 @@ const state = reactive({
36
   selectAllIndeterminate: false,
38
   selectAllIndeterminate: false,
37
 
39
 
38
   cart_id: [],
40
   cart_id: [],
41
+  changeSkuCart_id:'0',
39
   isManage: true,
42
   isManage: true,
40
 
43
 
41
   currentType: '',
44
   currentType: '',
45
+
46
+  isShowSku: false,
47
+  cartNum: 1,
48
+  currentSku: {},
42
 })
49
 })
43
 
50
 
51
+const detail: any = ref(null)
52
+
53
+
54
+function onSelectedSku(item) {
55
+  state.currentSku = item
56
+}
57
+
58
+function handleCreateShopping() {
59
+  // console.log(state.flag)
60
+  console.log(state.currentSku.unique,'切换sku展示的商品',state)
61
+  changeProdoctSku(
62
+    // product_attr_unique: JSON.stringify(state.currentSku),
63
+    // detail.value.unique
64
+    state.changeSkuCart_id,
65
+    state.currentSku.unique
66
+  ).then(res => {
67
+    console.log(res)
68
+    // if (res.cart_id) {
69
+    //   // console.log(state.flag)
70
+    //   if (state.flag == '1' || state.flag == '3') {
71
+    //     uni.navigateTo({
72
+    //       url: `/pages/order-confirm/index?cartId=${res.cart_id}&type=${state.flag}&product_id=${detail.value.product_id}`
73
+    //     })
74
+    //   } else {
75
+    //     uni.$emit('cart-reload')
76
+
77
+    //     uni.showToast({
78
+    //       title: '添加购物车成功',
79
+    //       icon: 'none'
80
+    //     })
81
+    //     loadCartCount()
82
+    //     state.isShowSku = false
83
+    //   }
84
+    // }
85
+    // if(res.status === 200){
86
+    //   state.isShowSku = false
87
+    // }
88
+    state.isShowSku = false
89
+    uni.$on('cart-reload', () => {
90
+      // console.log('新商品添加...')
91
+      state.cart_id = []
92
+      loadCartList()
93
+    })
94
+
95
+    state.cart_id = []
96
+    loadCartList()
97
+  })
98
+}
99
+
100
+function handleCountChange(val) {
101
+  // console.log(val)
102
+  // detail.value.
103
+  // if (val > 0) {
104
+    state.cartNum = val
105
+  // }
106
+}
107
+
44
 // 距离顶部距离
108
 // 距离顶部距离
45
 let Scroll_X = ref(0)
109
 let Scroll_X = ref(0)
46
 
110
 
@@ -440,23 +504,58 @@ onPageScroll((page) => {
440
     headerClass.value = ''
504
     headerClass.value = ''
441
   }
505
   }
442
 })
506
 })
443
-const changeSku = ref(false)
444
-const openTestLog = ()=>{
507
+const openTestLog1 = (a)=>{
508
+  console.log('商品的id',a.product_id)
445
   console.log('测试点击sku,多规模');
509
   console.log('测试点击sku,多规模');
446
-  changeSku.value = true
510
+  state.isShowSku = true
447
   
511
   
448
 }
512
 }
513
+
514
+function openTestLog(element) {
515
+  state.isShowSku = true
516
+  state.changeSkuCart_id = element.cart_id
517
+console.log('用户点击sku,展示商品id和购物车id',element.product_id,element.cart_id)
518
+getProductDetail(element.product_id).then(res => {
519
+  console.log(res.sku,'点击sku,展示返回的res')
520
+  detail.value = res
521
+  // console.log(detail.value,'点击sku获取的商品信息,存储的detail')
522
+  state.shareImage = detail.value.image
523
+  if (res && res.mer_id && res.mer_id === '148') {
524
+    if (detail.value && detail.value.price ) {
525
+      detail.value.price = detail.value.price * 30
526
+    }
527
+  }
528
+  state.isRelation = res.isRelation
529
+  if (res.merchant_type == 2) {
530
+    xcxBanding({
531
+      mer_id: res.mer_id,
532
+      share_id: state.shareId
533
+    }).then(res => {
534
+      console.info(res)
535
+    })
536
+  }
537
+
538
+  // if (detail.value.mer_id === '148') {
539
+  // }
540
+  uni.hideLoading()
541
+}).catch(error => {
542
+  // console.log(error)
543
+  uni.showToast({
544
+    icon: "none",
545
+    title: error
546
+  }).then( () => {
547
+    setTimeout(() => {
548
+      uni.navigateBack()
549
+    }, 500)
550
+  })
551
+})
552
+}
449
 const closeTestLog = ()=>{
553
 const closeTestLog = ()=>{
450
   console.log('测试点击sku,多规模');
554
   console.log('测试点击sku,多规模');
451
-  changeSku.value = false
452
 
555
 
453
 }
556
 }
454
 </script>
557
 </script>
455
 <template>
558
 <template>
456
-  <div v-if="changeSku" style="width: 100%; height: 100%; background-color: skyblue; margin-top: 100px;">
457
-    <p>sku信息</p>
458
-    <button @click="closeTestLog">关闭</button>
459
-  </div>
460
   <div class="">
559
   <div class="">
461
     <div
560
     <div
462
         v-if="hasShopping"
561
         v-if="hasShopping"
@@ -529,8 +628,8 @@ const closeTestLog = ()=>{
529
                   class="text-overflow line-clamp-2 text-xs">{{ goodItem.product.store_name }}</div>
628
                   class="text-overflow line-clamp-2 text-xs">{{ goodItem.product.store_name }}</div>
530
               <div class="flex flex-col justify-start gap-1">
629
               <div class="flex flex-col justify-start gap-1">
531
                 <div
630
                 <div
532
-                    class="text-[10px] text-gray min-w-5  p-1  items-center flex" @click="openTestLog">
533
-                  {{ goodItem.productAttr.sku }}
631
+                    class="text-[10px] text-gray min-w-5  p-1  items-center flex skushadow" v-if="goodItem.productAttr.sku" @click="openTestLog(goodItem)">
632
+                  {{ goodItem.productAttr.sku +' V'}}
534
                 </div>
633
                 </div>
535
                 <div class="flex">
634
                 <div class="flex">
536
                   <CXBYaojinTag :amount="goodItem.yanglao"/>
635
                   <CXBYaojinTag :amount="goodItem.yanglao"/>
@@ -584,7 +683,13 @@ const closeTestLog = ()=>{
584
       </div>
683
       </div>
585
     </div>
684
     </div>
586
   </div>
685
   </div>
587
-
686
+  <CXBSkuPopup 
687
+  v-model:show="state.isShowSku"
688
+      :detail="detail"
689
+      @selected:item="onSelectedSku"
690
+      @submit="handleCreateShopping"
691
+      @count-change="handleCountChange"
692
+  />
588
   <div v-if="hasShopping"
693
   <div v-if="hasShopping"
589
        class="fixed bottom-0 w-full z-3">
694
        class="fixed bottom-0 w-full z-3">
590
     <div class="bg-white h-10 flex justify-between" v-if="shopping && shopping.list">
695
     <div class="bg-white h-10 flex justify-between" v-if="shopping && shopping.list">
@@ -618,6 +723,10 @@ const closeTestLog = ()=>{
618
 page {
723
 page {
619
   background-color: #f8f8f8;
724
   background-color: #f8f8f8;
620
 }
725
 }
726
+.skushadow{
727
+  background-color: rgb(240, 240, 240);
728
+  border-radius: 10px;
729
+}
621
 </style>
730
 </style>
622
 <route lang="yaml">
731
 <route lang="yaml">
623
 style:
732
 style: