vue3.0实现购物车效果(多店铺)

效果展示

在这里插入图片描述

代码

初学vue3.0,大家多提意见

<template>
  <div class="content">
    <div v-for="(item, index) in data.shopList" :key="index" class="item_warp">
      <div class="flex_row">
        <div style="margin-right: 20px">
          <van-checkbox v-model="item.checked" icon-size="18" @click="storeCheck($event,index)"></van-checkbox>
        </div>

        <img
          src="../../static/icon/store_icon.png"
          class="store_icon"
          alt=""
          srcset=""
        />
        <span style="margin: 0 5px">{{ item.storeName }}</span>
        <van-icon name="arrow" />
      </div>
      <div class="shop_content flex" v-for="(item2,index2) in item.shop" :key="item2.id">
        <div style="margin-right: 20px">
          <van-checkbox v-model="item2.checked" icon-size="18" @click="shopCheck($event,index,index2)"></van-checkbox>
        </div>
        <div class="content_right flex">
          <van-image
            width="100px"
            height="100px"
            src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
          />
          <div style="margin-left:15px">
              <p>商品名称:{{item2.shopName}}</p>
              <van-stepper v-model="item2.num" min="1" max="999" />
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="fixed_warp flex">
       <van-checkbox v-model="allcheck" icon-size="18"></van-checkbox>
  </div>
</template>

<script lang="ts" setup>
import { computed, reactive, ref, watch } from "vue";
//模拟数据
const data = reactive({  
  shopList: [    
    {
      storeName: "广东威华旗舰店",      //店铺名称
      checked: false,
      shop: [
        {
          id: 1,
          shopName: "大豆油",      //商品名称
          brand: "宝华农业科技",
          specif: "50ml",
          price: "89.20",           //单价
          num: 1,              		//数量
          checked: false,
        },
        {
          id: 2,
          shopName: "大豆油2",
          brand: "宝华农业科技",
          specif: "50ml",
          price: "66.20",
          num: 1,
          checked: false,
        },
      ],
    },
    {
      storeName: "润斛生态农业",
      checked: false,
      shop: [
        {
          id: 3,
          shopName: "花生",
          brand: "宝华农业科技2",
          specif: "50ml",
          price: "89.20",
          num: 1,
          checked: false,
        },
        {
          id: 4,
          shopName: "花生2",
          brand: "宝华农业科技2",
          specif: "56ml",
          price: "61.20",
          num: 1,
          checked: false,
        },
      ],
    },
  ],
});
// const total = ref(false);
//全选按钮
const allcheck = computed({     
    set:(v)=>{
        data.shopList.forEach((item)=>{
            item.checked = v;
            item.shop.forEach((item2)=>{
                item2.checked = v;
            })
        })
    },
    get:()=>{
        return data.shopList.every((item)=>{
            return item.checked == true
        })
    }
})
//店铺全选
function storeCheck(e: any,index: any){
    console.log(e,index,"agreement");
    data.shopList[index].shop.forEach(item=>{
        item.checked = data.shopList[index].checked;
    })
}
//商品勾选
function shopCheck(e:any,index:any,index2:any){
        console.log(e,index,index2,"shopCheck");
        // data.shopList[index].checked = 
         console.log("shop",data.shopList[index].shop)
        data.shopList[index].checked =  data.shopList[index].shop.every(item=>{
            return item.checked ==true
         
        })
      
}

</script>
<style>
body {
  background: #f5f5f5;
}
</style>
<style scoped lang="scss">
.item_warp {
  margin-top: 20px;
  padding:24px;
  background: #ffffff;
}
.content {
  margin: 0 30px;
}
.store_icon {
  height: 30px;
  width: 30px;
}
.shop_content{
    margin: 20px 0;
}
.content_right {
  height: 200px;
}
.fixed_warp{
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 88px;
    padding:0 20px;
    background: #ffffff;
}
</style>

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笑一个吧*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值