更新记录
1.3.0(2024-12-06) 下载此版本
效果优化
1.1.0(2024-11-19) 下载此版本
优化样式
1.0.0(2024-03-23) 下载此版本
初始化
查看更多平台兼容性
uni-app
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | - | - | - | - | - |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | - | √ | √ | √ | √ |
其他
多语言 | 暗黑模式 | 宽屏模式 |
---|---|---|
× | × | √ |
支持扫码体验-见右侧二维码
<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唯一字段 |