商品购物车

master
2812875475 2024-04-09 20:58:28 +08:00
parent b47cbef72f
commit 5831060879
7 changed files with 257 additions and 166 deletions

View File

@ -59,3 +59,31 @@ export function checkState(state) {
data:state data:state
}) })
} }
export function updSelected(state) {
return request({
url: '/shopCart/shop/updSelected',
method: 'post',
data:state
})
}
export function editShopNum(state) {
return request({
url: '/shopCart/shop/editShopNum',
method: 'post',
data:state
})
}
export function delShoppingMethod(state) {
return request({
url: '/shopCart/shop/delShop',
method: 'post',
data:state
})
}
export function shopDetail() {
return request({
url: '/shopCart/shop/detail',
method: 'get'
})
}

View File

@ -10,8 +10,17 @@
text-color="#fff" text-color="#fff"
active-text-color="#ffd04b"> active-text-color="#ffd04b">
<el-menu-item index="1">处理中心</el-menu-item> <el-menu-item index="1">
<el-submenu index="2" > <router-link :to="'/commodityMall' " class="link-type">
<span>商品商城</span>
</router-link>
</el-menu-item>
<el-menu-item index="2">
<router-link :to="'/orderShop' " class="link-type">
<span>购物车结算</span>
</router-link>
</el-menu-item>
<el-submenu index="3" >
<template slot="title">我的购物车</template> <template slot="title">我的购物车</template>
<el-table <el-table
:data="shop" :data="shop"
@ -40,8 +49,8 @@
<el-button type="info" style="margin-left: 400px" @click="toShopping"></el-button> <el-button type="info" style="margin-left: 400px" @click="toShopping"></el-button>
</el-submenu> </el-submenu>
<el-menu-item index="3" disabled>消息中心</el-menu-item> <el-menu-item index="4" disabled>消息中心</el-menu-item>
<el-menu-item index="4"><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>
</el-menu> </el-menu>
</el-header> </el-header>
<el-main> <el-main>

View File

@ -78,11 +78,11 @@ export const constantRoutes = [
{ {
path: '', path: '',
component: Layouttest, component: Layouttest,
redirect: 'test', redirect: 'commodity_mall',
children: [ children: [
{ {
path: '/test/:id', path: '/commodityMall',
component: () => import('@/views/a/index'), component: () => import('@/views/product/productInfo/commodityMall/commodity.vue'),
name: 'Test', name: 'Test',
meta: {title: "商品商城", icon: 'dashboard', affix: true} meta: {title: "商品商城", icon: 'dashboard', affix: true}
} }
@ -91,7 +91,7 @@ export const constantRoutes = [
{ {
path: '', path: '',
component: Layouttest, component: Layouttest,
redirect: 'test', redirect: 'product_details',
children: [ children: [
{ {
path: '/detailsComponent/:id', path: '/detailsComponent/:id',
@ -104,16 +104,29 @@ export const constantRoutes = [
{ {
path: '', path: '',
component: Layouttest, component: Layouttest,
redirect: 'test', redirect: 'shop_detail',
children: [ children: [
{ {
path: 'shopping', path: 'shopping',
component: () => import('@/views/product/productInfo/detail/shopping.vue'), component: () => import('@/views/shopCart/shop/detail/shopDetail.vue'),
name: 'Test', name: 'Test',
meta: {title: "购物车", icon: 'dashboard', affix: true} meta: {title: "购物车", icon: 'dashboard', affix: true}
} }
] ]
}, },
{
path: '',
component: Layouttest,
redirect: 'order_shop',
children: [
{
path: 'orderShop',
component: () => import('@/views/shopCart/shop/order/orderShop.vue'),
name: 'Test',
meta: {title: "购物车结算", icon: 'dashboard', affix: true}
}
]
},
{ {
path: '/user', path: '/user',
component: Layout, component: Layout,

View File

@ -3,7 +3,7 @@
<el-breadcrumb separator-class="el-icon-arrow-right"> <el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item> <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
<el-breadcrumb-item :to="{ path: '/test/:id' }">商城</el-breadcrumb-item> <el-breadcrumb-item :to="{ path: '/commodityMall' }">商城</el-breadcrumb-item>
<el-breadcrumb-item v-for="breadcrumb in breadcrumbList">{{ breadcrumb }}</el-breadcrumb-item> <el-breadcrumb-item v-for="breadcrumb in breadcrumbList">{{ breadcrumb }}</el-breadcrumb-item>
</el-breadcrumb> </el-breadcrumb>
@ -138,7 +138,7 @@ import rule from "@/views/product/rule/index.vue";
import {addShop} from "@/api/shopCart/shop"; import {addShop} from "@/api/shopCart/shop";
export default { export default {
name: 'Index', name: 'product_details',
data() { data() {
return { return {
/*加入购物车*/ /*加入购物车*/

View File

@ -2,12 +2,6 @@
<div> <div>
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
<el-breadcrumb-item :to="{ path: '/test/:id' }">商城</el-breadcrumb-item>
</el-breadcrumb>
{{ shop }}
<el-card> <el-card>
<el-table <el-table
ref="multipleTable" ref="multipleTable"
@ -24,9 +18,9 @@
width="300"> width="300">
<template slot-scope="scope"> <template slot-scope="scope">
<div class="cell-content"> <div class="cell-content">
<img :src="scope.row.projectSkuInfo.image" width="100px" height="100px" class="project-image"> <img :src="scope.row.image" width="100px" height="100px" class="project-image">
<div class="project-info"> <div class="project-info">
<h3 class="project-name">{{ scope.row.projectInfo.name }}</h3> <h3 class="project-name">{{ scope.row.name }}</h3>
<p class="project-description">{{ scope.row.detailSku }}</p> <p class="project-description">{{ scope.row.detailSku }}</p>
</div> </div>
</div> </div>
@ -46,22 +40,18 @@
<el-table-column property="num" label="购买数量" width="200"> <el-table-column property="num" label="购买数量" width="200">
<template slot-scope="scope"> <template slot-scope="scope">
<el-input-number v-model="scope.row.num" <el-input-number v-model="scope.row.num"
@change="handleNumChange(scope.$index,scope.row)" @change="handleNumChange(scope.row)"
:min="1" label="描述文字"></el-input-number> :min="1" label="描述文字"></el-input-number>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column property="sum" label="小计" width="120"> <el-table-column property="sum" label="小计" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row.num * scope.row.price }}</span> <span style="margin-left: 10px">{{ scope.row.subtotal }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作"> <el-table-column label="操作">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit( scope.row)">移入收藏夹
</el-button>
<el-button <el-button
size="mini" size="mini"
type="danger" type="danger"
@ -73,14 +63,15 @@
<el-divider></el-divider> <el-divider></el-divider>
<span style="color: #97a8be">失效商品</span> <span style="color: #97a8be">失效商品</span>
<el-table <el-table
:show-header="false"
:data="oldshop" :data="oldshop"
ref="multipleTableOld"
style="width: 100%" style="width: 100%"
@selection-change="handleSelectionChangeOld"
> >
<el-table-column <el-table-column
type="selection"
width="55"> width="55">
<template slot-scope="scope">
<el-checkbox disabled></el-checkbox>
</template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
width="300"> width="300">
@ -130,18 +121,37 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-card> <el-card style="margin-top: 20px">
<el-checkbox v-model="selectAll" @change="handleSelectionChangeAll"></el-checkbox> <div>
删除选中商品 移入到收藏夹 <el-row>
<h1 style="color: red"> {{ totalPrice +totalPriceOld}}</h1> <el-col :span="6">
<h1 style="color: red">Old {{ totalPriceOld }}</h1> <div style="padding-top: 8px">
<h1 style="color: red">选中商品个数 {{num+numOld}}</h1> <el-checkbox v-model="isAllCheck" @change="changeIsAllCheck"></el-checkbox>
<el-button <el-button type="text" style="margin-left: 10px" @click="handleDelete(undefined)">
size="mini"
type="danger"
style="margin-left: 600px"
>下单结算
</el-button> </el-button>
<el-button type="text">添加我的收藏</el-button>
</div>
</el-col>
<el-col :span="14">
<div style="margin-left: 80px;padding-top: 8px">
<span><span style="color: red;">{{ statisticsShop.total }}</span> 件商品
已选择 <span style="color: red;">{{ statisticsShop.selectTotal }}</span> </span>
<el-divider direction="vertical"></el-divider>
<span>商品合计 : <span style="color: red;">¥{{ statisticsShop.priceTotal }}</span></span>
<el-divider direction="vertical"></el-divider>
<span>商品合计 : <span style="color: red; font-size: 24px">¥{{
statisticsShop.priceTotal
}}</span></span>
</div>
</el-col>
<el-col :span="4">
<el-button style="float: right; " type="success" @click="orderShop"></el-button>
</el-col>
</el-row>
</div>
</el-card> </el-card>
</el-card> </el-card>
@ -150,35 +160,23 @@
</template> </template>
<script> <script>
import {listShop} from "@/api/product/shop"; import {listShop} from "@/api/product/shop";
import {checkState, testShop} from "@/api/shopCart/shop"; import {checkState, delShoppingMethod, editShopNum, shopDetail, testShop, updSelected} from "@/api/shopCart/shop";
import shop from "@/views/shopCart/shop/index.vue"; import shop from "@/views/shopCart/shop/index.vue";
import item from "@/layout/components/Sidebar/Item.vue"; import item from "@/layout/components/Sidebar/Item.vue";
export default { export default {
name: 'Index', name: 'shop_detail',
data() { data() {
return { return {
/**/
selectAll:false,
/*选中商品*/ /*选中商品*/
selectedProduct: [], selectedProduct: [],
num:0, /*生效商品对象*/
/*选中失效*/
selectedProductOld:[],
numOld:0,
/*每次选中的*/
selectedRows: [],
/*总价钱*/
totalPrice: 0,
/*失效总价*/
totalPriceOld:0,
/*购物车对象*/
shop: [], shop: [],
/*查询对象*/ /*查询对象*/
queryParams: {}, queryParams: {},
/*多选框id*/
ids: [], ids: [],
/*购物车状态为选中*/ /*失效商品*/
checkEd: [],
oldshop: [ oldshop: [
{ {
"id": 3, "id": 3,
@ -212,130 +210,154 @@ export default {
"price": 123, "price": 123,
"sumPrice": null "sumPrice": null
} }
] ],
isAllCheck: false,
/*统计*/
statisticsShop: {
/*商品总数*/
total: 0,
/*选中商品总数*/
selectTotal: 0,
/*商品总价*/
priceTotal: 0.00,
/*实际商品总价*/
actualTotal: 0.00
}
} }
}, },
created() { created() {
this.shopList() this.init();
}, },
watch: {
selectedRows: {
handler(newVal, oldVal) {
//
newVal.forEach(row => {
if (row.isselected === 1) {
} else if (row.isselected === 0) {
}
});
//
oldVal.forEach(row => {
if (!newVal.find(newRow => newRow.id === row.id)) {
// oldValnewVal
if (row.isselected === 1) {
// let state = {
// ids: []
// }
// state.ids=row.id
// state.flag = 0
// checkState(state).then(
// res => {
// this.$message.success("")
// this.shopList()
// }
// )
}
if (row.isselected === 0) {
// let state = {
// ids: []
// }
// state.ids=row.id
// state.flag = 1
// checkState(state).then(
// res => {
// this.$message.success("")
// this.shopList()
// }
// )
}
}
});
},
deep: true // selectedRow
}
},
methods: { methods: {
/*下单结算*/
orderShop() {
this.$router.push('/orderShop')
},
/*删除*/
handleDelete(row) {
console.log(row)
let dekShopReq = []
if (row) {
dekShopReq.push({
"projectId": row.projectId,
"projectSku": row.projectSku,
"id": row.shoppingId,
})
} else {
if (this.selectedProduct.length === 0) {
this.$message.error("请选择商品")
return
}
this.selectedProduct.forEach(item => {
dekShopReq.push({
"projectId": item.projectId,
"projectSku": item.projectSku,
"id": item.shoppingId,
})
})
}
delShoppingMethod(dekShopReq).then(
res => {
this.init()
}
)
},
/*初始化*/
init() {
this.shop = []
this.selectedProduct = []
shopDetail().then(
res => {
this.statisticsShop = res.data.statisticsShop
this.shop = res.data.shopSkuList
setTimeout(this.initShopSelected, 200)
}
)
},
/*默认选中*/
initShopSelected() {
this.shop.forEach(item => {
if (item.isselected === 1) {
this.$refs.multipleTable.toggleRowSelection(item, true);
}
})
},
/*多选框*/ /*多选框*/
handleSelectionChange(val) { handleSelectionChange(val) {
if (val.length === 0) { let selectShopList = []
this.selectedRows = [] let newSelect = val.filter(
} else { row => !this.selectedProduct.includes(row)
this.selectedRows = val.slice(0, 1); );
newSelect.forEach(item => {
selectShopList.push({
"projectId": item.projectId,
"projectSku": item.projectSku,
"isselected": 1,
})
})
let noSelect = this.selectedProduct.filter(
row => !val.includes(row)
);
noSelect.forEach(item => {
selectShopList.push({
"projectId": item.projectId,
"projectSku": item.projectSku,
"isselected": 0,
})
})
let cartProjectMap = {};
this.shop.map(item =>
cartProjectMap[`${item.projectId} + ${item.projectSku}`] = item.isselected)
let editCartProjectFilterList
= selectShopList.filter(item => item.isselected !==
cartProjectMap[`${item.projectId} + ${item.projectSku}`])
if (editCartProjectFilterList.length > 0) {
updSelected(selectShopList).then(
res => {
this.init();
} }
this.selectedProduct = val.map(item => ({...item})); )
this.num=this.selectedProduct.length }
this.selectAll=val.length
this.countTotalPrice() this.selectedProduct = val
}, this.isAllCheck = val.length === this.shop.length
/*失效商品*/ //this.countTotalPrice()
handleSelectionChangeOld(val){
this.selectedProductOld = val.map(item => ({...item}));
this.numOld=this.selectedProductOld.length
this.selectAll=val.length
this.countTotalPriceOld()
}, },
/*全选*/ /*全选*/
handleSelectionChangeAll(){ changeIsAllCheck() {
if (this.isAllCheck) {
if (this.selectAll) { this.$refs.multipleTable.toggleAllSelection();
this.$refs.multipleTable.toggleRowSelection(this.shop, true);
this.$refs.multipleTableOld.toggleRowSelection(this.oldshop, true);
}
},
/*多选选中*/
select() {
this.shop.forEach((item, index) => {
if (item.isselected === 1) {
this.$nextTick(() => {
this.$refs.multipleTable.toggleRowSelection(this.shop[index], true)
})
}
})
},
checkedd(rows) {
if (rows) {
rows.forEach(row => {
this.$refs.multipleTable.toggleRowSelection(row,true);
})
} else { } else {
this.$refs.multipleTable.clearSelection(); this.$refs.multipleTable.clearSelection();
} }
}, },
/*数量计数器*/ /*数量计数器*/
handleNumChange(index, row) { handleNumChange(row) {
this.shop[index].num = row.num; let shopNumEdit = {
this.countTotalPrice() "projectId": row.projectId,
"projectSku": row.projectSku,
"num": row.num,
}
editShopNum(shopNumEdit).then(
res => {
this.init()
}
)
// this.shop[index].num = row.num;
// this.countTotalPrice()
}, },
/*失效计数器*/
/*计算总价 选中个数*/ /*计算总价 选中个数*/
countTotalPrice() { countTotalPrice() {
this.totalPrice = this.selectedProduct.reduce((sum, shop) => { this.statisticsShop.priceTotal = this.selectedProduct.reduce((sum, shop) => {
if (shop.hasOwnProperty('num') && shop.hasOwnProperty('price')) {
return sum + shop.num * shop.price;
} else {
return sum;
}
}, 0);
},
countTotalPriceOld(){
this.totalPriceOld = this.selectedProductOld.reduce((sum, shop) => {
if (shop.hasOwnProperty('num') && shop.hasOwnProperty('price')) { if (shop.hasOwnProperty('num') && shop.hasOwnProperty('price')) {
return sum + shop.num * shop.price; return sum + shop.num * shop.price;
} else { } else {
@ -350,10 +372,7 @@ export default {
this.shop = res.data.rows this.shop = res.data.rows
}); });
} }
}, }
mounted() {
this.checkedd(this.oldshop)
},
} }
</script> </script>

View File

@ -0,0 +1,22 @@
<template>
<div>
哈哈哈
</div>
</template>
<script>
export default {
name: 'order_shop',
data() {
return {}
},
created() {
},
methods: {}
}
</script>
<style scoped>
</style>