Browse Source

修改购物车下拉刷新问题

ext.liuqiwen3 1 month ago
parent
commit
3bd1aa833b
2 changed files with 42 additions and 17 deletions
  1. 2 1
      pages.json
  2. 40 16
      pages/order_addcart/order_addcart.vue

+ 2 - 1
pages.json

@@ -47,7 +47,8 @@
       "style": {
         "navigationBarTitleText": "购物车",
         "navigationBarBackgroundColor": "#fff",
-        "navigationBarTextStyle": "black"
+        "navigationBarTextStyle": "black",
+        "enablePullDownRefresh": true
       }
     },
     {

+ 40 - 16
pages/order_addcart/order_addcart.vue

@@ -1,5 +1,10 @@
 <template>
-  <view>
+<!--  <view style="min-height: 100%;">-->
+    <up-pull-refresh
+        :refreshing="refreshing"
+        :threshold="60"
+        @refresh="onRefresh"
+    >
     <view class="shoppingCart copy-data">
       <view class="borRadius14">
           <view
@@ -288,6 +293,7 @@
         </view>
       </view>
     </view>
+    </up-pull-refresh>
     <view
       class="footer acea-row row-between-wrapper"
       v-if="cartList.valid.length > 0"
@@ -338,20 +344,22 @@
       id="product-window"
     >
     </productWindow>
-    <!-- <view class="uni-p-b-96"></view> -->
+
+      <!-- <view class="uni-p-b-96"></view> -->
     <!-- <view class="uni-p-b-98"></view> -->
     <!-- #ifdef MP -->
     <!-- <authorize :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
     <!-- #endif -->
-    
+
     <!-- 自定义 tabBar -->
     <customTabBar :current="2" :showBackTop="false" />
-  </view>
+
+<!--  </view>-->
 </template>
 
 <script setup>
 import { ref, reactive, computed,watch } from "vue";
-import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
+import { onLoad, onShow, onReachBottom,onPullDownRefresh } from "@dcloudio/uni-app";
 import { useAppStore } from "@/stores/app.js";
 import {
   getCartList,
@@ -417,6 +425,8 @@ const isLogin = computed(()=>appStore.isLogin);
 // 添加全选的值控制
 const allCheckboxValue = ref([]);
 
+const refreshing = ref(false);
+
 // 监听isAllSelect的变化,同步到allCheckboxValue
 watch(isAllSelect, (newVal) => {
   if (newVal) {
@@ -430,24 +440,38 @@ onLoad((options) => {
   // if (!isLogin.value) {
   //   toLogin();
   // }
+  canShow.value = false;
+  if (isLogin.value) {
+
+    resetAllState();
+
+    Promise.allSettled([
+      getCartListFn(),
+      getInvalidList(),
+      getHostProduct()
+    ]).finally(() => {
+      // 添加一个短暂延迟,确保 DOM 更新完成
+      setTimeout(() => {
+        canShow.value = true;
+        uni.hideLoading();
+      }, 50);
+    });
+  }
 });
 
 onShow(() => {
   // 隐藏原生 tabBar
   uni.hideTabBar();
-  
+});
+
+const onRefresh = () => {
+  console.log('refresj=========')
+  refreshing.value = true;
   canShow.value = false;
   if (isLogin.value) {
     // 重置所有状态
     resetAllState();
-
-    // 设置加载状态
-    // uni.showLoading({
-    //   title: '加载中...',
-    //   mask: true
-    // });
-
-    // 使用 Promise.allSettled 避免单个失败影响整体
+    console.log('+++++++++++++=========')
     Promise.allSettled([
       getCartListFn(),
       getInvalidList(),
@@ -456,11 +480,12 @@ onShow(() => {
       // 添加一个短暂延迟,确保 DOM 更新完成
       setTimeout(() => {
         canShow.value = true;
+        refreshing.value = false;
         uni.hideLoading();
       }, 50);
     });
   }
-});
+};
 function resetAllState() {
   footerswitch.value = true;
   goodsHidden.value = false;
@@ -1111,7 +1136,6 @@ async function getCartListFn() {
 
     const c = await getCartCounts(true, "sum");
     cartCount.value = c.data.count;
-
     // 当没有商品时,获取推荐商品
     if (c.data.count === 0) {
       await getHostProduct();