更新记录
1.1.0(2024-11-19)
下载此版本
优化样式
1.0.0(2024-03-23)
下载此版本
初始化
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
× |
√ |
√ |
√ |
√ |
√ |
√ |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
√ |
√ |
√ |
√ |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
√ |
√ |
√ |
√ |
√ |
× |
√ |
√ |
√ |
插件需要依赖插件
uni-icons
tag-list
<template>
<view>
<shop-cart ref="shopCart" :selectKey="selectKey" :cart-list="cartList" :select-cart-list="selectCartList"
@operateCount="operateCount" @triggerSelect="triggerSelect" @triggerSelectAll="triggerSelectAll"
@toDetail="toDetail" @submit="submit" @cartDelete="cartDelete"></shop-cart>
</view>
</template>
<script>
export default {
data() {
return {
selectKey: "_id",
selectCartList: [],
cartList: [{
_id: '1',
count: 1,
shopName: '新款高端复古长袖国风棉麻衣裙',
shopTagList: [{
_id: '1',
category: "复古"
}],
price: 38000,
shopImage: "https://mp-26700ea2-c458-4911-a841-ced4a32d3d98.cdn.bspapp.com/component/WechatIMG8.png"
}, {
_id: '2',
count: 1,
shopName: '星诺满园秋光复古优雅气质长袖橘红色连衣裙',
shopTagList: [{
_id: '1',
category: "复古"
}, {
_id: '2',
category: "连衣裙"
}],
price: 27800,
shopImage: "https://mp-26700ea2-c458-4911-a841-ced4a32d3d98.cdn.bspapp.com/component/WechatIMG9.png"
}],
};
},
methods: {
submit() {
const selectList = this.cartList.filter((item) => this.selectCartList.includes(item[this.selectKey]))
console.log('-submit-', selectList)
},
toDetail(item) {
console.log('-toDetail-', item)
},
cartDelete(index) {
this.cartList.splice(index, 1)
this.$refs.shopCart.calculatePrice()
},
operateCount(params) {
const {
item,
type
} = params
if (type === 'add') {
item.count += 1
} else if (type === 'del' && item.count >= 2) {
item.count -= 1
}
this.$refs.shopCart.calculatePrice()
},
triggerSelect(item) {
const findIndex = this.selectCartList.findIndex(t => t === item[this.selectKey])
if (findIndex === -1) {
this.selectCartList.push(item[this.selectKey])
} else {
this.selectCartList.splice(findIndex, 1)
}
},
triggerSelectAll(selectAll) {
if (selectAll) {
this.selectCartList = []
} else {
this.selectCartList = this.cartList.map(item => item[this.selectKey])
}
}
}
}
</script>
<style lang="scss" scoped>
page {
background: rgb(246, 246, 246);
padding-bottom: 150rpx;
}
</style>
参数 |
类型 |
默认值 |
描述 |
cartList |
Array |
[] |
购物车商品列表 |
selectCartList |
Array |
[] |
购物车商品选中列表 |
selectKey |
String |
_id |
购物车商品选中key唯一字段 |