|
@@ -5,7 +5,7 @@
|
|
|
<u-col span="3">
|
|
|
<view class="icon-container-l">
|
|
|
<uni-badge size="normal" :text="txts" absolute="rightTop">
|
|
|
- <u-icon :name="iconCooking" label="自提" labelPos="bottom" size="32" ></u-icon>
|
|
|
+ <u-icon :name="iconCooking" label="自提" labelPos="bottom" size="32"></u-icon>
|
|
|
</uni-badge>
|
|
|
</view>
|
|
|
</u-col>
|
|
@@ -39,10 +39,10 @@
|
|
|
<view class="padding-tb-sm" v-for="index in 8">分类{{index+1}}</view>
|
|
|
</view>
|
|
|
</u-popup> -->
|
|
|
- <view class="w-full dflex-b padding-sm box-sizing-b dflex-wrap-w">
|
|
|
- <view class="goods-item margin-bottom-sm" v-for="(item, index) in goods" :key="index">
|
|
|
+ <view class="w-full dflex-b padding-xs box-sizing-b dflex-wrap-w">
|
|
|
+ <view class="goods-item margin-bottom-sm" v-for="(item, gindex) in goods" :key="gindex">
|
|
|
<view class="img dflex-c" @click="toDetial">
|
|
|
- <image mode="aspectFit" :src="'../../static/x'+ index%2 +'.jpg'"></image>
|
|
|
+ <image mode="aspectFit" :src="'../../static/x'+ gindex%2 +'.jpg'"></image>
|
|
|
</view>
|
|
|
<view class="title">{{item.goods_name}}</view>
|
|
|
<view class="dflex padding-bottom-xs">
|
|
@@ -51,76 +51,104 @@
|
|
|
<view class="w-full dflex-b">
|
|
|
<view class="price">{{item.goods_price}}</view>
|
|
|
<view>
|
|
|
- <u-button type="primary" shape="circle" size='small' icon="shopping-cart-fill"
|
|
|
- color="linear-gradient(to right, #F54319, #FF6D20)" @click="goCart"></u-button>
|
|
|
+ <u-button type="primary" shape="circle" size="small"
|
|
|
+ color="linear-gradient(to right, #F54319, #FF6D20)" @click="goCart(item)">
|
|
|
+ <u-icon name="shopping-cart-fill" size="28" color="#fff"></u-icon>
|
|
|
+ </u-button>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
<my-gap :height="130" />
|
|
|
-
|
|
|
+ <specPopup class='spec-box' ref="specPopup" :cardMsg="cardMsg" @update-shopmsg="handleUpdateShopMsg">
|
|
|
+ </specPopup>
|
|
|
<view class="cart-bottom padding-sm dflex-b">
|
|
|
<view class="cart padding-lr">
|
|
|
<uni-badge size="small" :text="100" absolute="rightTop">
|
|
|
<u-icon name="shopping-cart-fill" size="28" color="#FF873D" @click="showCart"></u-icon>
|
|
|
</uni-badge>
|
|
|
- <text class="cart-total">¥35.60</text>
|
|
|
+ <text class="cart-total">总计:¥{{total}}</text>
|
|
|
</view>
|
|
|
<view class="balance dflex-c background-gradient">去结算</view>
|
|
|
</view>
|
|
|
- <cartPopupVue ref="cartPopup" />
|
|
|
+ <cartPopupVue ref="cartPopup" :carList="carList" @numChanged="numChanged" />
|
|
|
+
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import cartPopupVue from '../../components/cartPopup.vue'
|
|
|
+ import specPopup from '@/components/specPopup.vue'
|
|
|
import iconCooking from '../../static/cooking.png'
|
|
|
import iconPeople from '../../static/people.png'
|
|
|
+ import shoppingCart from '../../static/shoppingCart.png'
|
|
|
export default {
|
|
|
components: {
|
|
|
cartPopupVue,
|
|
|
+ specPopup
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
onIndex: 0,
|
|
|
show: false,
|
|
|
- iconCooking: iconCooking,
|
|
|
+ iconCooking: iconCooking,
|
|
|
iconPeople: iconPeople,
|
|
|
+ shoppingCart: shoppingCart,
|
|
|
tags: 1,
|
|
|
txts: 1,
|
|
|
goods: [ // 购物车数据列表
|
|
|
{
|
|
|
id: 1,
|
|
|
- goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
|
|
|
- goods_price: "520.00",
|
|
|
-
|
|
|
+ goods_name: "小乳酸菌牛奶酸奶",
|
|
|
+ goods_price: "5.20",
|
|
|
+ goods_type: '大份',
|
|
|
+ goods_num: 1,
|
|
|
+ src: '../../static/x0.jpg',
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
|
- goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
|
|
|
- goods_price: "520.00",
|
|
|
- },
|
|
|
+ goods_name: "饮料整箱饮品",
|
|
|
+ goods_price: "5.20",
|
|
|
+ goods_type: '大份',
|
|
|
+ goods_num: 1,
|
|
|
+ src: '../../static/x1.jpg',
|
|
|
+ },
|
|
|
{
|
|
|
id: 3,
|
|
|
- goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
|
|
|
- goods_price: "520.00",
|
|
|
+ goods_name: "饮品早餐酸乳益生菌",
|
|
|
+ goods_price: "5.20",
|
|
|
+ goods_type: '小份',
|
|
|
+ goods_num: 1,
|
|
|
+ src: '../../static/x0.jpg',
|
|
|
},
|
|
|
{
|
|
|
id: 4,
|
|
|
- goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
|
|
|
- goods_price: "520.00",
|
|
|
+ goods_name: "酸奶饮料",
|
|
|
+ goods_price: "5.20",
|
|
|
+ goods_type: '小份',
|
|
|
+ goods_num: 1,
|
|
|
+ src: '../../static/x1.jpg',
|
|
|
},
|
|
|
{
|
|
|
id: 5,
|
|
|
- goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
|
|
|
- goods_price: "520.00",
|
|
|
+ goods_name: "小乳酸菌",
|
|
|
+ goods_price: "5.20",
|
|
|
+ goods_type: '小份',
|
|
|
+ goods_num: 1,
|
|
|
+ src: '../../static/x0.jpg',
|
|
|
},
|
|
|
{
|
|
|
id: 6,
|
|
|
- goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
|
|
|
- goods_price: "520.00",
|
|
|
+ goods_name: "酸乳益生菌",
|
|
|
+ goods_price: "5.20",
|
|
|
+ goods_type: '大份',
|
|
|
+ goods_num: 1,
|
|
|
+ src: '../../static/x1.jpg',
|
|
|
}
|
|
|
- ]
|
|
|
+ ],
|
|
|
+ total: 0,
|
|
|
+ carList: [],
|
|
|
+ cardMsg: {}
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
@@ -128,8 +156,58 @@
|
|
|
},
|
|
|
methods: {
|
|
|
// 加购
|
|
|
- goCart() {
|
|
|
-
|
|
|
+ goCart(e) {
|
|
|
+ console.log('================', e)
|
|
|
+ this.cardMsg = e
|
|
|
+ this.$refs.specPopup.open();
|
|
|
+ //this.$refs.specPopup.change(true);
|
|
|
+ },
|
|
|
+ handleUpdateShopMsg(shopMsg) {
|
|
|
+ console.log('接收到的购物信息:', shopMsg);
|
|
|
+ const specString = shopMsg.spec + ',' + shopMsg.specs;
|
|
|
+ const item = this.goods.find(item => item.id === shopMsg.id);
|
|
|
+
|
|
|
+ if (item) {
|
|
|
+ // 检查购物车列表中是否已存在相同id和规格的商品
|
|
|
+ const existingCartItem = this.carList.find(cartItem => cartItem.id === item.id && cartItem.goods_type === specString);
|
|
|
+
|
|
|
+ if (existingCartItem) {
|
|
|
+ // 如果已存在,则增加商品数量
|
|
|
+ existingCartItem.goods_num += shopMsg.num;
|
|
|
+ } else {
|
|
|
+ // 如果不存在,则复制item并添加到购物车列表,同时设置商品数量和规格
|
|
|
+ const newItem = { ...item };
|
|
|
+ newItem.goods_num = shopMsg.num;
|
|
|
+ newItem.goods_type = specString;
|
|
|
+ this.carList.push(newItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 您可以在这里执行其他逻辑,比如保存到本地存储或发送到服务器
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('购物车列表更新:', this.carList);
|
|
|
+ this.totalPrice();
|
|
|
+ },
|
|
|
+ numChanged(value, index) {
|
|
|
+ console.log('更新后的数量????????????:', value, '索引:', index);
|
|
|
+ // 假设 carList 是一个 Map,其中 id 是键
|
|
|
+ const item = this.carList.find(item => item.id === index)
|
|
|
+ if (item) {
|
|
|
+ // 更新对应商品的 goods_num
|
|
|
+ item.goods_num = value;
|
|
|
+ // 您可以在这里执行其他逻辑,比如保存到本地存储或发送到服务器
|
|
|
+ console.log('更新后的数量:', value, '索引:', index);
|
|
|
+ }
|
|
|
+ this.totalPrice()
|
|
|
+ },
|
|
|
+ totalPrice() {
|
|
|
+ let total = 0;
|
|
|
+ for (let i = 0; i < this.carList.length; i++) {
|
|
|
+ total += this.carList[i].goods_price * this.carList[i].goods_num;
|
|
|
+ //goods_num += this.carList[i].goods_num
|
|
|
+ }
|
|
|
+ this.total = total
|
|
|
+ console.log('total', this.total);
|
|
|
},
|
|
|
showCart() {
|
|
|
this.$refs.cartPopup.setShow(true);
|
|
@@ -191,7 +269,7 @@
|
|
|
|
|
|
.img {
|
|
|
width: 100%;
|
|
|
- height: 350rpx;
|
|
|
+ height: 180rpx;
|
|
|
overflow: hidden;
|
|
|
background: #EEE;
|
|
|
}
|
|
@@ -241,6 +319,11 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ .spec-box {
|
|
|
+ position: relative;
|
|
|
+ z-index: 99999;
|
|
|
+ }
|
|
|
+
|
|
|
.classify-popup {
|
|
|
width: 400rpx;
|
|
|
}
|