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,81 +1,90 @@
<script setup>
import { ref } from 'vue';
import { ref } from "vue";
import { cartListApi, cartDeleteApi, cartChangeApi } from "@/api/store.js";
const list = ref([])
const allPrice = ref(0) //
const list = ref([]);
const allPrice = ref(0); //
const clearAll = () => {
let cart_id = [];
list.value.map(item=>{
list.value.map((item) => {
cart_id.push(item.cart_id);
})
});
if (cart_id.length == 0) return;
deleteShop(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]);
}
};
const deleteShop = (arr) => {
cartDeleteApi({
cart_id: arr
}).then(res=>{
cart_id: arr,
}).then((res) => {
console.log(res);
getList();
})
}
});
};
const getList = () => {
allPrice.value = 0;
cartListApi({
source: 300
}).then(res=>{
source: 300,
}).then((res) => {
if (res.data?.list?.length > 0) {
list.value = res.data.list[0].list;
list.value.forEach(item=>{
allPrice.value += item.productAttr.price * item.cart_num
})
}
else list.value = []
})
}
list.value.forEach((item) => {
allPrice.value += item.productAttr.price * item.cart_num;
});
} else list.value = [];
});
};
getList();
const emit = defineEmits(['goPay'])
const emit = defineEmits(["goPay"]);
const goPay = () => {
emit('goPay')
}
emit("goPay");
};
const changeCartNum = (val)=>{
const changeCartNum = (val, old) => {
cartChangeApi(val.cart_id, {
cart_num: val.cart_num
}).then(res=>{
})
}
cart_num: val.cart_num,
}).then((res) => {
allPrice.value = 0;
list.value.forEach((item) => {
allPrice.value += item.productAttr.price * item.cart_num;
});
});
};
defineExpose({
getList,
list
})
list,
});
</script>
<template>
<div class="my-order">
<div class="header-nav">
<div class="nav-item">已选购 <span>{{ list.length }}</span> </div>
<div class="nav-item-clear" @click="clearAll"><el-icon><Delete /></el-icon></div>
<div class="nav-item">
已选购 <span>{{ list.length }}</span>
</div>
<div class="nav-item-clear" @click="clearAll">
<el-icon><Delete /></el-icon>
</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>
<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>
@ -83,8 +92,18 @@ defineExpose({
</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>
¥<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>
@ -92,13 +111,29 @@ defineExpose({
<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 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 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>
<el-button class="btn" type="primary" @click="goPay"
>立即结账</el-button
>
</div>
</div>
</div>