修复bug

This commit is contained in:
weipengfei 2024-05-27 18:07:07 +08:00
parent 31ee110122
commit d8ee89ff09
1 changed files with 391 additions and 389 deletions

View File

@ -1,438 +1,440 @@
<template> <template>
<view class="wrap"> <view class="wrap">
<up-navbar placeholder :autoBack="true"> <up-navbar placeholder :autoBack="true">
<template #center> <template #center>
<view <view style="display: flex;align-items: center;width: 100%;justify-content: flex-start;margin-left: 100rpx;">
style="display: flex;align-items: center;width: 100%;justify-content: flex-start;margin-left: 100rpx;"> <view class="tabs" :class="{'tabs-active': tabsActive==index}" v-for="(item, index) in list" :key="index"
<view class="tabs" :class="{'tabs-active': tabsActive==index}" v-for="(item, index) in list" @click="changeTab(index)">
:key="index" @click="changeTab(index)"> {{item}}
{{item}} </view>
</view> </view>
</view> </template>
</template> </up-navbar>
</up-navbar>
<swiper class="swiper-box" :current="swiperCurrent" @animationfinish="animationfinish"> <swiper class="swiper-box" :current="swiperCurrent" @animationfinish="animationfinish">
<swiper-item class="swiper-item"> <swiper-item class="swiper-item">
<scroll-view scroll-y style="height: 100%;width: 100%;"> <scroll-view scroll-y style="height: 100%;width: 100%;">
<view class="page-box1" style="padding-top: 60rpx;"> <view class="page-box1" style="padding-top: 60rpx;">
<view class="total"> <view class="total">
<view>共计<text style="color: #20B128;">{{cartList.length}}</text></view> <view>共计<text style="color: #20B128;">{{cartList.length}}</text></view>
<view v-if="!isAdmin" @click="isAdmin=true;">管理</view> <view v-if="!isAdmin" @click="isAdmin=true;">管理</view>
<view v-else @click="isAdmin=false;">完成</view> <view v-else @click="isAdmin=false;">完成</view>
</view> </view>
<view v-if="cartList.length>0" class="list"> <view v-if="cartList.length>0" class="list">
<view class="shop-item" v-for="(item, index) in cartList" :key="index" <view class="shop-item" v-for="(item, index) in cartList" :key="index" @click="openGoodPopup(item)">
@click="openGoodPopup(item)"> <view class="shop-check" @click.stop="checkItem(item, !item.check)">
<view class="shop-check" @click.stop="checkItem(item, !item.check)"> <image v-if="!item.check" src="@/static/icon/n-check.png"></image>
<image v-if="!item.check" src="@/static/icon/n-check.png"></image> <image v-else src="@/static/icon/check.png"></image>
<image v-else src="@/static/icon/check.png"></image> </view>
</view> <image class="shop-img" :src="item.imgs"></image>
<image class="shop-img" :src="item.imgs"></image> <view class="shop-content">
<view class="shop-content"> <view class="title">
<view class="title"> <view class="name u-line-2">{{item.goods_name}}</view>
<view class="name u-line-2">{{item.goods_name}}</view> <view class="tip u-line-1">{{item.unit_name}}</view>
<view class="tip u-line-1">{{item.unit_name}}</view> </view>
</view> <view class="price-btn">
<view class="price-btn"> <view class="price">{{item.sell}}</view>
<view class="price">{{item.sell}}</view> <view class="btn">
<view class="btn"> <view class="num">{{item.cart_num}}</view>
<view class="num">{{item.cart_num}}</view> <u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon>
<u--icon name="plus-circle-fill" size="20" color="#20b128"></u--icon> </view>
</view> </view>
</view> </view>
</view> </view>
</view> </view>
</view> <view v-else style="margin-top: 100rpx;">
<view v-else style="margin-top: 100rpx;"> <up-empty text="购物车空空如也"
<up-empty text="购物车空空如也" icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png">
icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png"> </up-empty>
</up-empty> </view>
</view> <view style="width: 100%;height: 200rpx;"></view>
<view style="width: 100%;height: 200rpx;"></view> </view>
</view> </scroll-view>
</scroll-view> </swiper-item>
</swiper-item> <swiper-item class="swiper-item">
<swiper-item class="swiper-item"> <scroll-view scroll-y style="height: 100%;width: 100%;">
<scroll-view scroll-y style="height: 100%;width: 100%;"> <view class="page-box1">
<view class="page-box1"> <view v-if="frequentlyList.length>0" class="list">
<view v-if="frequentlyList.length>0" class="list"> <view class="shop-item" v-for="(item, index) in frequentlyList" :key="index" @click="openGoodPopup(item)">
<view class="shop-item" v-for="(item, index) in frequentlyList" :key="index" <image class="shop-img" :src="item.imgs"></image>
@click="openGoodPopup(item)"> <view class="shop-content" style="width: 490rpx;">
<image class="shop-img" :src="item.imgs"></image> <view class="title">
<view class="shop-content" style="width: 490rpx;"> <view class="name u-line-2">{{item.name}}</view>
<view class="title"> <!-- <view class="tip u-line-1">{{item.spec}}</view> -->
<view class="name u-line-2">{{item.name}}</view> <view class="tip u-line-1">{{item.unit_name}}</view>
<!-- <view class="tip u-line-1">{{item.spec}}</view> --> </view>
<view class="tip u-line-1">{{item.unit_name}}</view> <view class="price-btn">
</view> <view class="price">{{item.sell}}</view>
<view class="price-btn"> <view class="btn">
<view class="price">{{item.sell}}</view> <up-button size="small" plain color="#20b128" shape="circle">加入购物车</up-button>
<view class="btn"> </view>
<up-button size="small" plain color="#20b128" </view>
shape="circle">加入购物车</up-button> </view>
</view> </view>
</view> </view>
</view> <view v-else style="margin-top: 100rpx;">
</view> <up-empty text="没有常买的商品"
</view> icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png">
<view v-else style="margin-top: 100rpx;"> </up-empty>
<up-empty text="没有常买的商品" </view>
icon="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/29955202404260944367594.png"> <view style="width: 100%;height: 200rpx;"></view>
</up-empty> </view>
</view> </scroll-view>
<view style="width: 100%;height: 200rpx;"></view> </swiper-item>
</view> </swiper>
</scroll-view>
</swiper-item>
</swiper>
</view> </view>
<up-transition :show="tabsActive==0"> <up-transition :show="tabsActive==0">
<view class="fiexd-btn-box cart-btn"> <view class="fiexd-btn-box cart-btn">
<view class="cart-check" @click="changeAll(checkAll===cartInfo.count)"> <view class="cart-check" @click="changeAll(checkAll===cartInfo.count)">
<image v-if="checkAll!=cartInfo.count" src="@/static/icon/n-check.png"></image> <image v-if="checkAll!=cartInfo.count" src="@/static/icon/n-check.png"></image>
<image v-else src="@/static/icon/check.png"></image> <image v-else src="@/static/icon/check.png"></image>
<text style="font-size: 24rpx;">全选</text> <text style="font-size: 24rpx;">全选</text>
<text style="font-size: 24rpx;" v-if="checkAll">({{checkAll}})</text> <text style="font-size: 24rpx;" v-if="checkAll">({{checkAll}})</text>
</view> </view>
<view v-if="!isAdmin" class="btn-boxs"> <view v-if="!isAdmin" class="btn-boxs">
<view class="all-price"> <view class="all-price">
<view style="width: 80rpx;">合计:</view> <view style="width: 80rpx;">合计:</view>
<view class="price"> <view class="price">
<text style="font-size: 24rpx;">¥</text> <text style="font-size: 24rpx;">¥</text>
<text style="font-size: 34rpx;">{{c_price0}}</text> <text style="font-size: 34rpx;">{{c_price0}}</text>
<text style="font-size: 24rpx;">.{{c_price1}}</text> <text style="font-size: 24rpx;">.{{c_price1}}</text>
</view> </view>
</view> </view>
<view style="width: 200rpx;"> <view style="width: 200rpx;">
<up-button color="#20b128" shape="circle" :disabled="!checkAll" @click="settleAccounts">去结算<text <up-button color="#20b128" shape="circle" :disabled="!checkAll" @click="settleAccounts">去结算<text
v-if="checkAll">({{checkAll}})</text></up-button> v-if="checkAll">({{checkAll}})</text></up-button>
</view> </view>
</view> </view>
<view v-else class="btn-boxs"> <view v-else class="btn-boxs">
<!-- <view style="width: 100px;margin-right: 20rpx;"><up-button size="small" plain color="#989898" shape="circle">移入收藏夹</up-button></view> --> <!-- <view style="width: 100px;margin-right: 20rpx;"><up-button size="small" plain color="#989898" shape="circle">移入收藏夹</up-button></view> -->
<view style="width: 100px;"><up-button @click="deleteCartList()" size="small" plain color="#989898" <view style="width: 100px;"><up-button @click="deleteCartList()" size="small" plain color="#989898"
shape="circle">删除</up-button></view> shape="circle">删除</up-button></view>
</view> </view>
</view> </view>
</up-transition> </up-transition>
<goodPopup ref="goodRef" :show="showGoodPopup" @close="showGoodPopup=false" @change="changeGood" /> <goodPopup ref="goodRef" :show="showGoodPopup" @close="showGoodPopup=false" @change="changeGood" />
</template> </template>
<script setup> <script setup>
import { import {
onShow onShow
} from "@dcloudio/uni-app" } from "@dcloudio/uni-app"
import { import {
computed, computed,
ref, ref,
watch watch
} from 'vue'; } from 'vue';
import { import {
cartListApi, cartListApi,
cartChangeApi, cartChangeApi,
cartCreateApi, cartCreateApi,
cartDeleteApi, cartDeleteApi,
frequentlyPurchaseApi frequentlyPurchaseApi
} from "@/api/cart.js" } from "@/api/cart.js"
import goodPopup from "@/components/goodPopup.vue" import goodPopup from "@/components/goodPopup.vue"
import useCartStore from "@/store/cart.js" import useCartStore from "@/store/cart.js"
const cartStore = useCartStore(); const cartStore = useCartStore();
// //
const list = ref(['购物车', '常买']); const list = ref(['购物车', '常买']);
const tabsActive = ref(0) const tabsActive = ref(0)
// //
const changeTab = (e) => { const changeTab = (e) => {
tabsActive.value = e; tabsActive.value = e;
swiperCurrent.value = e; swiperCurrent.value = e;
} }
const swiperCurrent = ref(0); const swiperCurrent = ref(0);
const animationfinish = ({ const animationfinish = ({
detail: { detail: {
current current
} }
}) => { }) => {
swiperCurrent.value = current; swiperCurrent.value = current;
tabsActive.value = current; tabsActive.value = current;
if (swiperCurrent.value == 1) getFrequentlyPurchase(); if (swiperCurrent.value == 1) getFrequentlyPurchase();
} }
// //
const settleAccounts = () => { const settleAccounts = () => {
let list = []; let list = [];
cartList.value.forEach(item => { cartList.value.forEach(item => {
if (item.check) list.push(item.cart_id); if (item.check) list.push(item.cart_id);
}) })
cartStore.setCartList(list); cartStore.setCartList(list);
uni.navigateTo({ uni.navigateTo({
url: '/pagesOrder/settle/settle' url: '/pagesOrder/settle/settle'
}) })
} }
// //
const deleteCartList = () => { const deleteCartList = () => {
let list = []; let list = [];
cartList.value.forEach(item => { cartList.value.forEach(item => {
if (item.check) list.push(item.cart_id); if (item.check) list.push(item.cart_id);
}) })
cartDeleteApi({ cartDeleteApi({
cart_id: list cart_id: list
}).then(() => { }).then(() => {
getcartList(false); getcartList(false);
}) })
} }
// //
const addCart = (id, cart_num) => { // const addCart = (id, cart_num) => { //
cartCreateApi({ cartCreateApi({
cart_num: +cart_num, cart_num: +cart_num,
goods_id: id goods_id: id
}).then(res => { }).then(res => {
getcartList(); getcartList();
}) })
} }
const isAdmin = ref(false); // const isAdmin = ref(false); //
// //
const showGoodPopup = ref(false); const showGoodPopup = ref(false);
const goodRef = ref(null); const goodRef = ref(null);
const goodData = ref({}); const goodData = ref({});
const openGoodPopup = (item) => { // / const openGoodPopup = (item) => { // /
goodData.value = JSON.parse(JSON.stringify(item)); goodData.value = JSON.parse(JSON.stringify(item));
goodRef.value.setData(goodData.value); goodRef.value.setData(goodData.value);
showGoodPopup.value = true; showGoodPopup.value = true;
}; };
const changeGood = (data) => { // const changeGood = (data) => { //
showGoodPopup.value = false; showGoodPopup.value = false;
addCart(data.goods_id || data.id, data.cart_num); addCart(data.goods_id || data.id, data.cart_num);
} }
const cartList = ref([]); const cartList = ref([]);
const cartInfo = ref({}); const cartInfo = ref({});
const getcartList = (check = true) => { const getcartList = (check = true) => {
cartListApi().then(res => { cartListApi().then(res => {
if (check) { if (check) {
res.data.lists = res.data.lists.map(item => { res.data.lists = res.data.lists.map(item => {
item.check = true; item.check = true;
return item; return item;
}) })
checkAll.value = res.data?.count || 0 checkAll.value = res.data?.count || 0
} else { } else {
checkAll.value = 0 checkAll.value = 0
} }
cartList.value = res.data.lists; cartList.value = res.data.lists;
cartInfo.value = { cartInfo.value = {
total_price: res.data?.extend.total_price || '0.00', total_price: res.data?.extend.total_price || '0.00',
count: res.data?.count || 0 count: res.data?.count || 0
} }
}) })
} }
const c_price0 = computed(() => { const c_price0 = computed(() => {
let price = cartInfo.value.total_price + ''; let price = cartInfo.value.total_price + '';
return price.split('.')[0] || '0'; return price.split('.')[0] || '0';
}) })
const c_price1 = computed(() => { const c_price1 = computed(() => {
let price = cartInfo.value.total_price + ''; let price = cartInfo.value.total_price + '';
return price.split('.')[1] || '00'; return price.split('.')[1] || '00';
}) })
// //
let checkAll = ref(0) let checkAll = ref(0)
const checkItem = (item, type) => { const checkItem = (item, type) => {
item.check = type; item.check = type;
let price = Number(cartInfo.value.total_price); let price = Number(cartInfo.value.total_price);
if (type) { if (type) {
price += item.sell * item.cart_num; price += item.sell * item.cart_num;
checkAll.value++; checkAll.value++;
} else { } else {
price -= item.sell * item.cart_num; price -= item.sell * item.cart_num;
checkAll.value--; checkAll.value--;
} }
cartInfo.value.total_price = price.toFixed(2); cartInfo.value.total_price = price.toFixed(2);
} }
const changeAll = (flag = false) => { const changeAll = (flag = false) => {
cartList.value.forEach(item => { let count = 0;
item.check = !flag; cartList.value.forEach(item => {
}) item.check = !flag;
if (!flag) checkAll.value = cartInfo.value.count; if (!flag) count += item.sell * item.cart_num;
else checkAll.value = 0; })
} if (!flag) {
checkAll.value = cartInfo.value.count;
} else {
checkAll.value = 0;
}
cartInfo.value.total_price = count.toFixed(2);
}
// //
const frequentlyList = ref([]); const frequentlyList = ref([]);
const where = ref({ const where = ref({
page_no: 1, page_no: 1,
page_size: 25 page_size: 25
}) })
const getFrequentlyPurchase = () => { const getFrequentlyPurchase = () => {
frequentlyPurchaseApi({ frequentlyPurchaseApi({
...where.value ...where.value
}).then(res => { }).then(res => {
frequentlyList.value = res.data; frequentlyList.value = res.data;
}) })
} }
onShow(() => { onShow(() => {
getcartList(); getcartList();
}) })
</script> </script>
<style lang="scss"> <style lang="scss">
.tabs { .tabs {
color: #444444; color: #444444;
font-size: 32rpx; font-size: 32rpx;
margin-right: 30rpx; margin-right: 30rpx;
} }
.tabs-active { .tabs-active {
color: #20B128; color: #20B128;
// font-size: 34rpx; // font-size: 34rpx;
transition: 300ms; transition: 300ms;
} }
.wrap { .wrap {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: calc(100vh - var(--window-top)); height: calc(100vh - var(--window-top));
width: 100%; width: 100%;
} }
.swiper-box { .swiper-box {
flex: 1; flex: 1;
} }
.swiper-item { .swiper-item {
height: 100%; height: 100%;
} }
.page-box1 { .page-box1 {
position: relative; position: relative;
.total { .total {
padding: 0 20rpx; padding: 0 20rpx;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
position: fixed; position: fixed;
top: var(--window-top); top: var(--window-top);
left: 0; left: 0;
right: 0; right: 0;
background-color: #f6f6f6; background-color: #f6f6f6;
z-index: 100; z-index: 100;
height: 60rpx; height: 60rpx;
line-height: 60rpx; line-height: 60rpx;
font-size: 26rpx; font-size: 26rpx;
color: #444; color: #444;
} }
.list { .list {
margin: 20rpx; margin: 20rpx;
border-radius: 20rpx; border-radius: 20rpx;
overflow: hidden; overflow: hidden;
.shop-item { .shop-item {
padding: 20rpx; padding: 20rpx;
border-bottom: 1rpx solid #f6f6f6; border-bottom: 1rpx solid #f6f6f6;
background-color: #fff; background-color: #fff;
display: flex; display: flex;
.shop-check { .shop-check {
width: 60rpx; width: 60rpx;
height: 120rpx; height: 120rpx;
display: flex; display: flex;
align-items: center; align-items: center;
image { image {
width: 40rpx; width: 40rpx;
height: 40rpx; height: 40rpx;
} }
} }
.shop-img { .shop-img {
height: 120rpx; height: 120rpx;
width: 120rpx; width: 120rpx;
margin-right: 20rpx; margin-right: 20rpx;
border-radius: 14rpx; border-radius: 14rpx;
} }
.shop-content { .shop-content {
width: 430rpx; width: 430rpx;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
.title { .title {
.name { .name {
font-size: 28rpx; font-size: 28rpx;
} }
.tip { .tip {
color: #999; color: #999;
font-size: 24rpx; font-size: 24rpx;
margin: 12rpx 0; margin: 12rpx 0;
} }
} }
.price { .price {
font-size: 30rpx; font-size: 30rpx;
font-weight: bold; font-weight: bold;
color: #F55726; color: #F55726;
} }
.price-btn { .price-btn {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
.btn { .btn {
display: flex; display: flex;
align-items: center; align-items: center;
.num { .num {
margin: 0 20rpx; margin: 0 20rpx;
text-align: center; text-align: center;
} }
} }
} }
} }
} }
} }
} }
.cart-btn { .cart-btn {
.cart-check { .cart-check {
display: flex; display: flex;
align-items: center; align-items: center;
image { image {
width: 40rpx; width: 40rpx;
height: 40rpx; height: 40rpx;
margin: 0 10rpx; margin: 0 10rpx;
} }
} }
.btn-boxs { .btn-boxs {
display: flex; display: flex;
.all-price { .all-price {
display: flex; display: flex;
align-items: center; align-items: center;
margin-right: 20rpx; margin-right: 20rpx;
.price { .price {
color: #20B128; color: #20B128;
display: table-cell; display: table-cell;
vertical-align: bottom; vertical-align: bottom;
font-weight: bold; font-weight: bold;
} }
} }
} }
} }
</style> </style>