更新记录

1.0.0(2024-03-23)

初始化


平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.6.8
钉钉小程序 快手小程序 飞书小程序 京东小程序
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
×
<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>

插件需要依赖插件

uni-icons

参数 类型 默认值 描述
cartList Array [] 购物车商品列表
selectCartList Array [] 购物车商品选中列表
selectKey String _id 购物车商品选中key唯一字段

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问