2024-04-25 18:02:30 +08:00
|
|
|
<template>
|
|
|
|
<view>
|
2024-04-29 18:14:58 +08:00
|
|
|
<up-navbar placeholder :autoBack="true">
|
|
|
|
<template #center>
|
|
|
|
<view style="display: flex;align-items: center;width: 100%;justify-content: flex-start;margin-left: 100rpx;">
|
2024-04-26 18:04:56 +08:00
|
|
|
<view class="tabs" :class="{'tabs-active': tabsActive==index}" v-for="(item, index) in list" :key="index"
|
2024-04-25 18:02:30 +08:00
|
|
|
@click="changeTab(index)">
|
|
|
|
{{item}}
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
</up-navbar>
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
<swiper class="swiper-box" :current="swiperCurrent" @animationfinish="animationfinish">
|
|
|
|
<swiper-item class="swiper-item">
|
|
|
|
<scroll-view scroll-y style="height: 100%;width: 100%;">
|
|
|
|
<view class="page-box1">
|
|
|
|
<view class="total">
|
2024-04-29 18:14:58 +08:00
|
|
|
<view>共计<text style="color: #20B128;">{{cartList.length}}</text>件</view>
|
2024-04-25 18:02:30 +08:00
|
|
|
<view v-if="true">管理</view>
|
|
|
|
<view v-else>完成</view>
|
|
|
|
</view>
|
2024-04-26 18:04:56 +08:00
|
|
|
<view v-if="true" class="list" style="margin-top: 80rpx;">
|
2024-04-29 18:14:58 +08:00
|
|
|
<view class="shop-item" v-for="(item, index) in cartList" :key="index" @click="openGoodPopup(item)">
|
2024-04-25 18:02:30 +08:00
|
|
|
<view class="shop-check">
|
2024-04-29 18:14:58 +08:00
|
|
|
<image v-if="!item.check" src="@/static/icon/n-check.png"></image>
|
2024-04-25 18:02:30 +08:00
|
|
|
<image v-else src="@/static/icon/check.png"></image>
|
|
|
|
</view>
|
2024-04-29 18:14:58 +08:00
|
|
|
<image class="shop-img" :src="item.imgs"></image>
|
2024-04-25 18:02:30 +08:00
|
|
|
<view class="shop-content">
|
|
|
|
<view class="title">
|
2024-04-29 18:14:58 +08:00
|
|
|
<view class="name u-line-2">{{item.goods_name}}</view>
|
|
|
|
<view class="tip u-line-1">{{item.unit_name}}</view>
|
2024-04-25 18:02:30 +08:00
|
|
|
</view>
|
|
|
|
<view class="price-btn">
|
2024-04-29 18:14:58 +08:00
|
|
|
<view class="price">¥{{item.goods_total_price}}</view>
|
2024-04-25 18:02:30 +08:00
|
|
|
<view class="btn">
|
2024-04-29 18:14:58 +08:00
|
|
|
<view class="num">{{item.cart_num}}</view>
|
2024-04-25 18:02:30 +08:00
|
|
|
<u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
2024-04-26 18:04:56 +08:00
|
|
|
<view v-else style="margin-top: 100rpx;">
|
|
|
|
<up-empty text="购物车空空如也"
|
|
|
|
icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png">
|
|
|
|
</up-empty>
|
|
|
|
</view>
|
|
|
|
<view style="width: 100%;height: 200rpx;"></view>
|
|
|
|
</view>
|
|
|
|
</scroll-view>
|
|
|
|
</swiper-item>
|
|
|
|
<swiper-item class="swiper-item">
|
|
|
|
<scroll-view scroll-y style="height: 100%;width: 100%;">
|
|
|
|
<view class="page-box1">
|
|
|
|
<view v-if="true" class="list">
|
|
|
|
<view class="shop-item" v-for="(item, index) in 20" :key="index">
|
|
|
|
<image class="shop-img" src="https://cdn.uviewui.com/uview/album/1.jpg"></image>
|
|
|
|
<view class="shop-content" style="width: 490rpx;">
|
|
|
|
<view class="title">
|
|
|
|
<view class="name u-line-2">好吃的瓜果</view>
|
|
|
|
<view class="tip u-line-1">香味辛辣|葱香味浓|调味增香香味辛辣|葱香味浓|调味增香</view>
|
|
|
|
</view>
|
|
|
|
<view class="price-btn">
|
|
|
|
<view class="price">¥12.00</view>
|
|
|
|
<view class="btn">
|
|
|
|
<up-button size="small" plain color="#20b128" shape="circle">加入购物车</up-button>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<view v-else style="margin-top: 100rpx;">
|
|
|
|
<up-empty text="没有常买的商品"
|
|
|
|
icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png">
|
|
|
|
</up-empty>
|
|
|
|
</view>
|
2024-04-25 18:02:30 +08:00
|
|
|
<view style="width: 100%;height: 200rpx;"></view>
|
|
|
|
</view>
|
|
|
|
</scroll-view>
|
|
|
|
</swiper-item>
|
|
|
|
</swiper>
|
2024-04-26 18:04:56 +08:00
|
|
|
|
|
|
|
<up-transition :show="tabsActive==0">
|
|
|
|
<view class="cart-btn">
|
|
|
|
<view class="cart-check">
|
|
|
|
<image v-if="false" src="@/static/icon/n-check.png"></image>
|
|
|
|
<image v-else src="@/static/icon/check.png"></image>
|
|
|
|
<text style="font-size: 24rpx;">全选</text>
|
|
|
|
</view>
|
2024-04-28 18:08:57 +08:00
|
|
|
<view v-if="true" class="btn-boxs">
|
2024-04-26 18:04:56 +08:00
|
|
|
<view class="all-price">
|
|
|
|
<view style="width: 80rpx;">合计:</view>
|
|
|
|
<view class="price">
|
|
|
|
<text style="font-size: 24rpx;">¥</text>
|
2024-04-29 18:14:58 +08:00
|
|
|
<text style="font-size: 34rpx;">{{c_price(cartInfo.total_price, 0)}}</text>
|
|
|
|
<text style="font-size: 24rpx;">.{{c_price(cartInfo.total_price, 1)}}</text>
|
2024-04-26 18:04:56 +08:00
|
|
|
</view>
|
|
|
|
</view>
|
2024-04-27 18:02:43 +08:00
|
|
|
<up-button color="#20b128" shape="circle" :disabled="false" @click="settleAccounts">去结算<text>(2)</text></up-button>
|
2024-04-26 18:04:56 +08:00
|
|
|
</view>
|
2024-04-28 18:08:57 +08:00
|
|
|
<view v-else class="btn-boxs">
|
2024-04-27 18:02:43 +08:00
|
|
|
<!-- <view style="width: 100px;margin-right: 20rpx;"><up-button size="small" plain color="#989898" shape="circle">移入收藏夹</up-button></view> -->
|
2024-04-26 18:04:56 +08:00
|
|
|
<view style="width: 80px;"><up-button size="small" plain color="#989898" shape="circle">删除</up-button></view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</up-transition>
|
2024-04-29 18:14:58 +08:00
|
|
|
<goodPopup ref="goodRef" :show="showGoodPopup" @close="showGoodPopup=false" @change="changeGood" />
|
2024-04-25 18:02:30 +08:00
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2024-04-29 18:14:58 +08:00
|
|
|
import { onShow } from "@dcloudio/uni-app"
|
2024-04-25 18:02:30 +08:00
|
|
|
import { ref } from 'vue';
|
2024-04-29 18:14:58 +08:00
|
|
|
import { cartListApi, cartChangeApi } from "@/api/cart.js"
|
|
|
|
import goodPopup from "@/components/goodPopup.vue"
|
2024-04-25 18:02:30 +08:00
|
|
|
|
|
|
|
// 创建响应式数据
|
2024-04-26 18:04:56 +08:00
|
|
|
const list = ref(['购物车', '常买']);
|
2024-04-25 18:02:30 +08:00
|
|
|
const tabsActive = ref(0)
|
|
|
|
// 定义方法
|
|
|
|
const changeTab = (e) => {
|
|
|
|
tabsActive.value = e;
|
2024-04-26 18:04:56 +08:00
|
|
|
swiperCurrent.value = e;
|
2024-04-25 18:02:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const swiperCurrent = ref(0);
|
|
|
|
const animationfinish = ({ detail: { current } }) => {
|
|
|
|
swiperCurrent.value = current;
|
|
|
|
tabsActive.value = current;
|
|
|
|
}
|
2024-04-27 18:02:43 +08:00
|
|
|
|
|
|
|
// 结算
|
|
|
|
const settleAccounts = ()=>{
|
2024-04-28 18:08:57 +08:00
|
|
|
uni.navigateTo({
|
|
|
|
url: '/pagesOrder/settle/settle'
|
|
|
|
})
|
2024-04-27 18:02:43 +08:00
|
|
|
}
|
2024-04-28 18:08:57 +08:00
|
|
|
|
2024-04-29 18:14:58 +08:00
|
|
|
const addCart = (id, cart_num) => { //加入购物车
|
|
|
|
cartChangeApi({
|
|
|
|
cart_num: cart_num,
|
|
|
|
is_new: 0, // 是否直接购买0否1是
|
|
|
|
cart_id: id
|
|
|
|
}).then(res => {
|
|
|
|
getcartList();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const removeCart = (id) => {
|
|
|
|
let num = cartList.get(id) || 0;
|
|
|
|
if (num == 0) return;
|
|
|
|
cartChangeApi({
|
|
|
|
cart_id: id,
|
|
|
|
cart_num: num--
|
|
|
|
}).then(res => {
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 选择商品相关
|
|
|
|
const showGoodPopup = ref(false);
|
|
|
|
const goodRef = ref(null);
|
|
|
|
const goodData = ref({});
|
|
|
|
const openGoodPopup = (item) => { // 打开数量/重量弹窗
|
|
|
|
goodData.value = item;
|
|
|
|
goodRef.value.setData(item);
|
|
|
|
showGoodPopup.value = true;
|
|
|
|
};
|
|
|
|
const changeGood = (data)=>{ // 确定选择商品重量
|
|
|
|
showGoodPopup.value = false;
|
|
|
|
addCart(data.cart_id, data.cart_num);
|
|
|
|
}
|
|
|
|
|
2024-04-28 18:08:57 +08:00
|
|
|
const cartList = ref([]);
|
2024-04-29 18:14:58 +08:00
|
|
|
const cartInfo = ref({});
|
2024-04-28 18:08:57 +08:00
|
|
|
const getcartList = ()=>{
|
|
|
|
cartListApi().then(res=>{
|
2024-04-29 18:14:58 +08:00
|
|
|
res.data.lists = res.data.lists.map(item=>{
|
|
|
|
item.check = true;
|
|
|
|
return item;
|
|
|
|
})
|
|
|
|
cartList.value = res.data.lists;
|
|
|
|
cartInfo.value = res.data?.extend?.total_price || '0.00';
|
2024-04-28 18:08:57 +08:00
|
|
|
})
|
|
|
|
}
|
2024-04-29 18:14:58 +08:00
|
|
|
|
|
|
|
const c_price = (price=0, index=0)=>{
|
|
|
|
price = price + '';
|
|
|
|
return price.split('.')[index] || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
onShow(()=>{
|
|
|
|
getcartList();
|
|
|
|
})
|
2024-04-25 18:02:30 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.tabs {
|
|
|
|
color: #444444;
|
|
|
|
font-size: 32rpx;
|
|
|
|
margin-right: 30rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tabs-active {
|
|
|
|
color: #20B128;
|
2024-04-26 18:04:56 +08:00
|
|
|
// font-size: 34rpx;
|
2024-04-25 18:02:30 +08:00
|
|
|
transition: 300ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
.swiper-box {
|
|
|
|
flex: 1;
|
|
|
|
height: calc(100vh - var(--window-top) - var(--window-bottom));
|
|
|
|
/* #ifdef H5 */
|
|
|
|
height: calc(100vh - 96px);
|
|
|
|
/* #endif */
|
|
|
|
width: 100%;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.swiper-item {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-26 18:04:56 +08:00
|
|
|
.page-box1 {
|
2024-04-25 18:02:30 +08:00
|
|
|
position: relative;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
|
|
|
.total {
|
2024-04-25 18:02:30 +08:00
|
|
|
padding: 0 20rpx;
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
position: fixed;
|
|
|
|
top: var(--window-top);
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
2024-04-28 18:08:57 +08:00
|
|
|
background-color: #f6f6f6;
|
2024-04-25 18:02:30 +08:00
|
|
|
z-index: 100;
|
|
|
|
height: 60rpx;
|
|
|
|
line-height: 60rpx;
|
|
|
|
font-size: 26rpx;
|
|
|
|
color: #444;
|
|
|
|
}
|
2024-04-26 18:04:56 +08:00
|
|
|
|
|
|
|
.list {
|
2024-04-25 18:02:30 +08:00
|
|
|
margin: 20rpx;
|
|
|
|
border-radius: 20rpx;
|
|
|
|
overflow: hidden;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.shop-item {
|
|
|
|
padding: 20rpx;
|
2024-04-28 18:08:57 +08:00
|
|
|
border-bottom: 1rpx solid #f6f6f6;
|
2024-04-25 18:02:30 +08:00
|
|
|
background-color: #fff;
|
|
|
|
display: flex;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
|
|
|
.shop-check {
|
2024-04-25 18:02:30 +08:00
|
|
|
width: 60rpx;
|
|
|
|
height: 160rpx;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
|
|
|
image {
|
2024-04-25 18:02:30 +08:00
|
|
|
width: 40rpx;
|
|
|
|
height: 40rpx;
|
|
|
|
}
|
|
|
|
}
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.shop-img {
|
|
|
|
height: 160rpx;
|
|
|
|
width: 160rpx;
|
|
|
|
margin-right: 20rpx;
|
|
|
|
border-radius: 14rpx;
|
|
|
|
}
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.shop-content {
|
|
|
|
width: 430rpx;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: space-between;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.title {
|
|
|
|
.name {
|
|
|
|
font-size: 28rpx;
|
|
|
|
}
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.tip {
|
|
|
|
color: #999;
|
|
|
|
font-size: 24rpx;
|
|
|
|
margin: 12rpx 0;
|
|
|
|
}
|
|
|
|
}
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.price {
|
|
|
|
font-size: 30rpx;
|
|
|
|
font-weight: bold;
|
|
|
|
color: #F55726;
|
|
|
|
}
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.price-btn {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.btn {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2024-04-26 18:04:56 +08:00
|
|
|
|
2024-04-25 18:02:30 +08:00
|
|
|
.num {
|
|
|
|
width: 60rpx;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-26 18:04:56 +08:00
|
|
|
|
|
|
|
.cart-btn {
|
|
|
|
width: 100%;
|
|
|
|
height: 50px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
background-color: pink;
|
|
|
|
background-color: #fff;
|
|
|
|
position: fixed;
|
|
|
|
left: 0;
|
|
|
|
bottom: var(--window-bottom);
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: 0 20rpx;
|
|
|
|
|
|
|
|
.cart-check {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
image {
|
|
|
|
width: 40rpx;
|
|
|
|
height: 40rpx;
|
|
|
|
margin: 0 10rpx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-28 18:08:57 +08:00
|
|
|
.btn-boxs {
|
2024-04-26 18:04:56 +08:00
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.all-price {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin-right: 20rpx;
|
|
|
|
|
|
|
|
.price {
|
|
|
|
color: #20B128;
|
|
|
|
display: table-cell;
|
|
|
|
vertical-align: bottom;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-04-25 18:02:30 +08:00
|
|
|
}
|
|
|
|
</style>
|