|
@@ -1,45 +1,47 @@
|
|
|
<template>
|
|
<template>
|
|
|
<view class="cart-page">
|
|
<view class="cart-page">
|
|
|
- <!-- 购物车列表 -->
|
|
|
|
|
- <view class="cart-list">
|
|
|
|
|
- <!-- <u-swipe-action :show="item.show" :index="index" v-for="(item, index) in cartList" :key="item.id"
|
|
|
|
|
- @click="clickAction" @open="openAction" @touchstart="swipeStart" :options="actionOptions">
|
|
|
|
|
- <cart-item :item="item" @check="handleCheck" @changeNum="handleChangeNum" @reduce="handleReduce"
|
|
|
|
|
- @selectCondition="onSelectCondition"></cart-item>
|
|
|
|
|
- </u-swipe-action> -->
|
|
|
|
|
- <uni-swipe-action>
|
|
|
|
|
- <uni-swipe-action-item v-for="(item, index) in cartList" :key="item.id" :right-options="uniActionOptions" @click="uniClickAction($event, index)" @change="uniSwipeChange($event, index)" :show="item.show">
|
|
|
|
|
- <cart-item :item="item" @check="handleCheck" @changeNum="handleChangeNum" @reduce="handleReduce"
|
|
|
|
|
- @selectCondition="onSelectCondition"></cart-item>
|
|
|
|
|
- </uni-swipe-action-item>
|
|
|
|
|
- </uni-swipe-action>
|
|
|
|
|
- </view>
|
|
|
|
|
-
|
|
|
|
|
- <!-- 品相切换弹窗 -->
|
|
|
|
|
- <condition-popup ref="conditionPopup" @select="handleConditionUpdate"></condition-popup>
|
|
|
|
|
-
|
|
|
|
|
- <!-- 空状态 -->
|
|
|
|
|
- <view class="empty-cart" v-if="cartList.length === 0 && !loading" style="margin:15% 0">
|
|
|
|
|
- <u-empty text="购物车空空如也" mode="car"></u-empty>
|
|
|
|
|
- </view>
|
|
|
|
|
-
|
|
|
|
|
- <!-- 为你推荐 -->
|
|
|
|
|
- <view class="recommend-section" v-if="recommendList.length > 0">
|
|
|
|
|
- <view class="section-title">
|
|
|
|
|
- <text class="line"></text>
|
|
|
|
|
- <text class="text">为你推荐</text>
|
|
|
|
|
- <text class="line"></text>
|
|
|
|
|
|
|
+ <page-scroll
|
|
|
|
|
+ ref="pageRef"
|
|
|
|
|
+ url="/token/shop/cart/list"
|
|
|
|
|
+ method="post"
|
|
|
|
|
+ :page-size="10"
|
|
|
|
|
+ :immediate="false"
|
|
|
|
|
+ slotEmpty
|
|
|
|
|
+ emptyText="购物车空空如也"
|
|
|
|
|
+ height="100vh"
|
|
|
|
|
+ bgColor="#f5f5f5"
|
|
|
|
|
+ @updateList="handleUpdateList"
|
|
|
|
|
+ >
|
|
|
|
|
+ <view class="cart-list" v-if="cartList.length > 0">
|
|
|
|
|
+ <uni-swipe-action>
|
|
|
|
|
+ <uni-swipe-action-item v-for="(item, index) in cartList" :key="item.id" :right-options="uniActionOptions" @click="uniClickAction($event, index)" @change="uniSwipeChange($event, index)" :show="item.show">
|
|
|
|
|
+ <cart-item :item="item" @check="handleCheck" @changeNum="handleChangeNum" @reduce="handleReduce"
|
|
|
|
|
+ @selectCondition="onSelectCondition"></cart-item>
|
|
|
|
|
+ </uni-swipe-action-item>
|
|
|
|
|
+ </uni-swipe-action>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="recommend-grid">
|
|
|
|
|
- <view class="grid-item" v-for="(item, index) in recommendList" :key="index">
|
|
|
|
|
- <image :src="item.cover" mode="aspectFill" class="cover"></image>
|
|
|
|
|
- <view class="title">{{ item.title }}</view>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 为你推荐 -->
|
|
|
|
|
+ <view class="recommend-section" v-if="recommendList.length > 0">
|
|
|
|
|
+ <view class="section-title">
|
|
|
|
|
+ <text class="line"></text>
|
|
|
|
|
+ <text class="text">为你推荐</text>
|
|
|
|
|
+ <text class="line"></text>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <view class="recommend-grid">
|
|
|
|
|
+ <view class="grid-item" v-for="(item, index) in recommendList" :key="index">
|
|
|
|
|
+ <image :src="item.cover" mode="aspectFill" class="cover"></image>
|
|
|
|
|
+ <view class="title">{{ item.title }}</view>
|
|
|
|
|
+ </view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
- </view>
|
|
|
|
|
|
|
|
|
|
- <!-- 底部占位 -->
|
|
|
|
|
- <view style="height: 120rpx;"></view>
|
|
|
|
|
|
|
+ <!-- 底部占位,避免被结算栏遮挡 -->
|
|
|
|
|
+ <view style="height: 120rpx;"></view>
|
|
|
|
|
+ </page-scroll>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 品相切换弹窗 -->
|
|
|
|
|
+ <condition-popup ref="conditionPopup" @select="handleConditionUpdate"></condition-popup>
|
|
|
|
|
|
|
|
<!-- 悬浮清空按钮 -->
|
|
<!-- 悬浮清空按钮 -->
|
|
|
<!-- <view class="floating-clear-btn" v-if="cartList.length > 0" @click="handleClearCart">
|
|
<!-- <view class="floating-clear-btn" v-if="cartList.length > 0" @click="handleClearCart">
|
|
@@ -89,6 +91,7 @@
|
|
|
import ReduceQrcode from '@/components/reduce-qrcode/reduce-qrcode.vue';
|
|
import ReduceQrcode from '@/components/reduce-qrcode/reduce-qrcode.vue';
|
|
|
import CommonDialog from '@/components/common-dialog.vue';
|
|
import CommonDialog from '@/components/common-dialog.vue';
|
|
|
import ConditionPopup from '../components/condition-popup.vue';
|
|
import ConditionPopup from '../components/condition-popup.vue';
|
|
|
|
|
+ import pageScroll from '@/components/pageScroll/index.vue';
|
|
|
import { eventBus } from '@/utils/event-bus.js';
|
|
import { eventBus } from '@/utils/event-bus.js';
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
@@ -97,11 +100,11 @@
|
|
|
PriceReductionPopup,
|
|
PriceReductionPopup,
|
|
|
ReduceQrcode,
|
|
ReduceQrcode,
|
|
|
CommonDialog,
|
|
CommonDialog,
|
|
|
- ConditionPopup
|
|
|
|
|
|
|
+ ConditionPopup,
|
|
|
|
|
+ pageScroll
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
- loading: true,
|
|
|
|
|
currentItem: null,
|
|
currentItem: null,
|
|
|
isAllSelected: false,
|
|
isAllSelected: false,
|
|
|
cartList: [],
|
|
cartList: [],
|
|
@@ -214,10 +217,27 @@
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
refreshCartPage() {
|
|
refreshCartPage() {
|
|
|
- this.loadData();
|
|
|
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
|
+ this.$refs.pageRef?.loadData(true);
|
|
|
|
|
+ });
|
|
|
this.getShippingText();
|
|
this.getShippingText();
|
|
|
this.$updateCartBadge();
|
|
this.$updateCartBadge();
|
|
|
},
|
|
},
|
|
|
|
|
+ handleUpdateList(list) {
|
|
|
|
|
+ const storageCheckedIds = uni.getStorageSync('cartCheckedIds') || [];
|
|
|
|
|
+ const prevCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
|
|
|
+ const checkedIds = [...new Set([...storageCheckedIds, ...prevCheckedIds])];
|
|
|
|
|
+
|
|
|
|
|
+ this.cartList = (list || []).map(item => ({
|
|
|
|
|
+ ...item,
|
|
|
|
|
+ checked: checkedIds.includes(item.id),
|
|
|
|
|
+ show: 'none'
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ const finalCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
|
|
|
+ uni.setStorageSync('cartCheckedIds', finalCheckedIds);
|
|
|
|
|
+ eventBus.emit('cartPageLoadDone');
|
|
|
|
|
+ },
|
|
|
getShippingText() {
|
|
getShippingText() {
|
|
|
this.$u.api.getShippingTempleteAjax().then(res => {
|
|
this.$u.api.getShippingTempleteAjax().then(res => {
|
|
|
if (res.code === 200) {
|
|
if (res.code === 200) {
|
|
@@ -272,44 +292,6 @@
|
|
|
if (index != idx) this.cartList[idx].show = false;
|
|
if (index != idx) this.cartList[idx].show = false;
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- loadData() {
|
|
|
|
|
- this.loading = true;
|
|
|
|
|
- // 获取购物车列表
|
|
|
|
|
- this.$u.api.getShopCartListAjax({}).then(res => {
|
|
|
|
|
- this.loading = false;
|
|
|
|
|
-
|
|
|
|
|
- // 获取本地缓存的选中状态,和当前列表的选中状态合并
|
|
|
|
|
- let storageCheckedIds = uni.getStorageSync('cartCheckedIds') || [];
|
|
|
|
|
- const currentCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
|
|
|
-
|
|
|
|
|
- // 合并并去重
|
|
|
|
|
- let checkedIds = [...new Set([...storageCheckedIds, ...currentCheckedIds])];
|
|
|
|
|
-
|
|
|
|
|
- // 本地添加选中状态属性
|
|
|
|
|
- const list = res.rows || [];
|
|
|
|
|
- this.cartList = list.map(item => {
|
|
|
|
|
- return {
|
|
|
|
|
- ...item,
|
|
|
|
|
- checked: checkedIds.includes(item.id),
|
|
|
|
|
- show: 'none'
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 更新缓存中存在的且当前在购物车里的项
|
|
|
|
|
- const finalCheckedIds = this.cartList.filter(i => i.checked).map(i => i.id);
|
|
|
|
|
- uni.setStorageSync('cartCheckedIds', finalCheckedIds);
|
|
|
|
|
-
|
|
|
|
|
- }).catch(() => {
|
|
|
|
|
- this.loading = false;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 获取推荐列表
|
|
|
|
|
- // this.$u.api.getSearchRecommendAjax().then(res => {
|
|
|
|
|
- // if (res.code == 200) {
|
|
|
|
|
- // this.recommendList = res.data || [];
|
|
|
|
|
- // }
|
|
|
|
|
- // });
|
|
|
|
|
- },
|
|
|
|
|
handleCheck({ id, checked }) {
|
|
handleCheck({ id, checked }) {
|
|
|
const item = this.cartList.find(i => i.id === id);
|
|
const item = this.cartList.find(i => i.id === id);
|
|
|
if (item) {
|
|
if (item) {
|
|
@@ -492,7 +474,7 @@
|
|
|
uni.hideLoading();
|
|
uni.hideLoading();
|
|
|
this.$u.toast('更新成功');
|
|
this.$u.toast('更新成功');
|
|
|
|
|
|
|
|
- this.loadData();
|
|
|
|
|
|
|
+ this.$refs.pageRef?.loadData(true);
|
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
|
uni.hideLoading();
|
|
uni.hideLoading();
|
|
|
});
|
|
});
|