This commit is contained in:
weipengfei 2024-04-02 18:48:27 +08:00
parent c31591c837
commit 176067a7bf
1 changed files with 221 additions and 186 deletions

View File

@ -1,219 +1,254 @@
<script setup> <script setup>
import { ref } from 'vue'; import { ref } from "vue";
import { cartListApi, cartDeleteApi, cartChangeApi } from "@/api/store.js"; import { cartListApi, cartDeleteApi, cartChangeApi } from "@/api/store.js";
const list = ref([]) const list = ref([]);
const allPrice = ref(0) // const allPrice = ref(0); //
const clearAll = ()=>{ const clearAll = () => {
let cart_id = []; let cart_id = [];
list.value.map(item=>{ list.value.map((item) => {
cart_id.push(item.cart_id); cart_id.push(item.cart_id);
}) });
if(cart_id.length==0) return; if (cart_id.length == 0) return;
deleteShop(cart_id); deleteShop(cart_id);
} };
const deleteOne = (cart_id)=>{ const deleteOne = (cart_id) => {
list.value = list.value.filter(item=>item.cart_id!=cart_id); list.value = list.value.filter((item) => item.cart_id != cart_id);
deleteShop([cart_id]); deleteShop([cart_id]);
} };
const deleteShop = (arr)=>{ const deleteShop = (arr) => {
cartDeleteApi({ cartDeleteApi({
cart_id: arr cart_id: arr,
}).then(res=>{ }).then((res) => {
console.log(res); console.log(res);
getList(); getList();
}) });
} };
const getList = ()=>{ const getList = () => {
allPrice.value = 0; allPrice.value = 0;
cartListApi({ cartListApi({
source: 300 source: 300,
}).then(res=>{ }).then((res) => {
if(res.data?.list?.length>0) { if (res.data?.list?.length > 0) {
list.value = res.data.list[0].list; list.value = res.data.list[0].list;
list.value.forEach(item=>{ list.value.forEach((item) => {
allPrice.value += item.productAttr.price * item.cart_num allPrice.value += item.productAttr.price * item.cart_num;
}) });
} } else list.value = [];
else list.value = [] });
}) };
}
getList(); getList();
const emit = defineEmits(['goPay']) const emit = defineEmits(["goPay"]);
const goPay = ()=>{ const goPay = () => {
emit('goPay') emit("goPay");
} };
const changeCartNum = (val)=>{ const changeCartNum = (val, old) => {
cartChangeApi(val.cart_id, { cartChangeApi(val.cart_id, {
cart_num: val.cart_num cart_num: val.cart_num,
}).then(res=>{ }).then((res) => {
allPrice.value = 0;
}) list.value.forEach((item) => {
} allPrice.value += item.productAttr.price * item.cart_num;
});
});
};
defineExpose({ defineExpose({
getList, getList,
list list,
}) });
</script> </script>
<template> <template>
<div class="my-order"> <div class="my-order">
<div class="header-nav"> <div class="header-nav">
<div class="nav-item">已选购 <span>{{ list.length }}</span> </div> <div class="nav-item">
<div class="nav-item-clear" @click="clearAll"><el-icon><Delete /></el-icon></div> 已选购 <span>{{ list.length }}</span>
</div> </div>
<div class="order-list"> <div class="nav-item-clear" @click="clearAll">
<el-empty v-if="list.length==0" description="请点击右侧添加商品" /> <el-icon><Delete /></el-icon>
<div v-else class="order-item" v-for="(item, index) in list" :key="index"> </div>
<el-image class="order-item-img" :src="(item.productAttr && item.productAttr.image) || item.product.image"></el-image>
<div class="order-item-info">
<div class="order-item-title">
<div class="title">{{ item.spu.store_name }}</div>
<div class="delete" @click="deleteOne(item.cart_id)">删除</div>
</div>
<div class="order-item-sku">设备规格</div>
<div class="order-item-price">
<div>¥<span>{{ item.productAttr.price }}</span></div>
<div><el-input-number v-model="item.cart_num" step-strictly :min="1" :step="1" @change="changeCartNum(item)"/></div>
</div>
</div>
</div>
</div>
<div class="order-footer">
<div class="order-total">
<div class="price">
<div class="total-item">实付: <span>¥<span style="font-size: 1.4rem;">{{ allPrice.toFixed(2) }}</span></span></div>
<div class="total-item">优惠: <span>¥<span>{{ 0 }}</span></span></div>
</div>
<div class="update-price"><el-button class="btn" type="primary">改价</el-button></div>
</div>
<div class="order-btn">
<el-button class="btn" type="primary" @click="goPay">立即结账</el-button>
</div>
</div>
</div> </div>
<div class="order-list">
<el-empty v-if="list.length == 0" description="请点击右侧添加商品" />
<div v-else class="order-item" v-for="(item, index) in list" :key="index">
<el-image
class="order-item-img"
:src="
(item.productAttr && item.productAttr.image) || item.product.image
"
></el-image>
<div class="order-item-info">
<div class="order-item-title">
<div class="title">{{ item.spu.store_name }}</div>
<div class="delete" @click="deleteOne(item.cart_id)">删除</div>
</div>
<div class="order-item-sku">设备规格</div>
<div class="order-item-price">
<div>
¥<span>{{ item.productAttr.price }}</span>
</div>
<div>
<el-input-number
v-model="item.cart_num"
step-strictly
:min="1"
:step="1"
@change="changeCartNum(item)"
/>
</div>
</div>
</div>
</div>
</div>
<div class="order-footer">
<div class="order-total">
<div class="price">
<div class="total-item">
实付:
<span
>¥<span style="font-size: 1.4rem">{{
allPrice.toFixed(2)
}}</span></span
>
</div>
<div class="total-item">
优惠:
<span
>¥<span>{{ 0 }}</span></span
>
</div>
</div>
<div class="update-price">
<el-button class="btn" type="primary">改价</el-button>
</div>
</div>
<div class="order-btn">
<el-button class="btn" type="primary" @click="goPay"
>立即结账</el-button
>
</div>
</div>
</div>
</template> </template>
<style scoped lang="scss"> <style scoped lang="scss">
.my-order{ .my-order {
border-radius: 1.2rem; border-radius: 1.2rem;
height: 100%; height: 100%;
background-color: #fff; background-color: #fff;
width: 30rem; width: 30rem;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
.header-nav{ .header-nav {
display: flex;
justify-content: space-between;
padding: 1rem;
height: 1.5rem;
border-bottom: 1px solid #eee;
span {
color: #ff4a00;
}
.nav-item-clear {
display: flex;
align-items: center;
font-size: 0.8rem;
cursor: pointer;
}
}
.order-list {
height: calc(100vh - 100px - 14rem);
overflow-y: auto;
.order-item {
display: flex;
padding: 1rem;
border-bottom: 1px solid #eee;
.order-item-img {
width: 5rem;
height: 5rem;
border-radius: 0.5rem;
}
.order-item-info {
flex: 1;
box-sizing: border-box;
padding-left: 12px;
display: flex; display: flex;
flex-direction: column;
justify-content: space-between; justify-content: space-between;
padding: 1rem; & > div {
height: 1.5rem; display: flex;
border-bottom: 1px solid #eee; align-items: center;
justify-content: space-between;
span{
color: #ff4a00;
} }
.nav-item-clear{ .order-item-title {
display: flex; .title {
align-items: center; width: 18rem;
font-size: 0.8rem; overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.delete {
color: #1890ff;
cursor: pointer; cursor: pointer;
}
} }
.order-item-sku {
font-size: 0.8rem;
color: #999;
}
}
} }
.order-list{ }
height: calc(100vh - 100px - 14rem); .order-footer {
overflow-y: auto; position: absolute;
.order-item{ bottom: 0;
display: flex; left: 0;
padding: 1rem; width: 100%;
border-bottom: 1px solid #eee; box-shadow: 0 -1px 10px #eee;
.order-item-img{ .order-total {
width: 5rem; height: 2.5rem;
height: 5rem; padding: 1rem 2rem;
border-radius: 0.5rem; display: flex;
} justify-content: space-between;
.order-item-info{ border-bottom: 1px solid #eee;
flex: 1; align-items: center;
box-sizing: border-box; .price {
padding-left: 12px; display: flex;
display: flex; align-items: center;
flex-direction: column; .total-item {
justify-content: space-between; padding-right: 1.5rem;
&>div{ span {
display: flex; color: #f5222d;
align-items: center; }
justify-content: space-between;
}
.order-item-title{
.title{
width: 18rem;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.delete{
color: #1890ff;
cursor: pointer;
}
}
.order-item-sku{
font-size: 0.8rem;
color: #999;
}
}
} }
}
.update-price {
.btn {
border-radius: 3rem;
}
}
} }
.order-footer{ .order-btn {
position: absolute; height: 3.2rem;
bottom: 0; padding: 1rem 1.5rem;
left: 0; .btn {
width: 100%; width: 100%;
box-shadow: 0 -1px 10px #eee; height: 100%;
font-size: 1.2rem;
.order-total{ border-radius: 3rem;
height: 2.5rem; }
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
border-bottom: 1px solid #eee;
align-items: center;
.price {
display: flex;
align-items: center;
.total-item{
padding-right: 1.5rem;
span{
color: #f5222d;
}
}
}
.update-price{
.btn{
border-radius: 3rem;
}
}
}
.order-btn{
height: 3.2rem;
padding: 1rem 1.5rem;
.btn{
width: 100%;
height: 100%;
font-size: 1.2rem;
border-radius: 3rem;
}
}
} }
}
} }
</style> </style>