You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
high-mini/components/shopcart.vue

303 lines
6.4 KiB

<template>
<view class="shopcart">
<!-- @click="toggleList" -->
<view class="cartBottom">
<view class="carIcon" @click="toggleList">
<view class="iconBox" :class="getAllCount ? 'active' : '' ">
<text class="allcount" v-if="getAllCount">{{getAllCount}}</text>
<image src="../qianzhu-KFC/static/imgs/kfcicon.png" mode="" class="img"></image>
</view>
</view>
<view class="middle" @click="toggleList">
<text class="price" :class="getAllCount ? 'active': ''">¥{{getAllPrice}}</text>
<text class="deliveryPrice" style="font-size: 12px;">免配送费|支持自取</text>
</view>
<view class="BtnRight" @click="buyList">
选好了
<!-- <button :type="buyType" style="border-radius: 20rpx;" :disabled="buyDis" @click="buyList"></button> -->
</view>
</view>
<!-- 选择的商品 -->
<view class="cartList" v-show="isShowList && getList.length">
<view class="title">
<text class="font15 fcor666">已选餐品</text>
<view class="font12 fcor999" @click="delShopcart">
清空
</view>
</view>
<scroll-view scroll-y style="max-height: 280px;">
<view class="list">
<view class="list-text alijusstart" v-for="(item,index) in getList" :key="index">
<view class="width40">
<image src="../qianzhu-KFC/static/imgs/kfc1.png" mode="widthFix" class="width100"></image>
</view>
<view class="width30 fotlt">
<view class="width100 fcor999 font14">
{{item.name}}
</view>
<view class="width100 fcoreb5 font16 mart10">
<text class="fontwig6">{{item.price}}</text>
</view>
</view>
<cartcontrol :food="item" @add="addCart" @dec="decreaseCart" @input="inputCart"></cartcontrol>
</view>
</view>
</scroll-view>
</view>
<view class="listMask" v-show="isShowList && getList.length" @click="toggleList"></view>
</view>
</template>
<script>
import cartcontrol from '@/components/cartcontrol.vue'
// import {mul} from '@/utils/lib'
export default {
props: {
buyType: 'default',
buyDis: true,
goods: {
type: Array
}
},
data() {
return {
isShowList: false,
};
},
components: {
cartcontrol
},
computed: {
getList() {
let result = [];
this.goods.forEach((good) => {
good.foods.forEach((food) => {
if (food.count) {
result.push(food)
// console.log('res', JSON.stringify(result))
}
})
})
return result
},
// 获得购物车所有商品数量
getAllCount() {
let result = 0;
this.getList.forEach((food) => {
result += food.count
})
return result
},
// 总价
getAllPrice() {
let result = 0;
let result1 = 0;
this.goods.forEach((good) => {
good.foods.forEach((food) => {
result1 += this.accMul(food.count, food.price)
result = result1.toFixed(2);
})
})
return result
}
},
methods: {
// 解决浮点数 运算出现多位小数
accMul(arg1, arg2) {
let m = 0,
s1 = '',
s2 = '';
if (arg1 && arg1 != null)
s1 = arg1.toString();
if (arg2 && arg2 != null)
s2 = arg2.toString();
// console.log('m1',s2.replace('.',''))
try {
m += s1.split('.')[1].length
} catch (e) {}
try {
m += s2.split('.')[1].length
} catch (e) {}
return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m);
},
toggleList() {
if (this.getList.length) {
this.isShowList = !this.isShowList;
}
},
buyList() {
// if (this.getList.length) {
// console.log("getAllPrice:" + this.getAllPrice)
// console.log('buyList:' + JSON.stringify(this.getList))
// uni.showToast({
// title: "总价格:" + this.getAllPrice
// })
// } else {
// }
uni.navigateTo({
// url:'/qianzhu-KFC/confirmOrder/confirmOrder'
url:'/qianzhu-KFC/order-details/order-details'
})
},
delShopcart() {
this.$emit('delAll');
},
addCart: function(item) {
this.$emit('add', item)
},
decreaseCart(item) {
this.$emit('dec', item)
},
inputCart(item) {
this.fcount = item.count
if (item.count >= 999) {
uni.showToast({
title: "该宝贝不能购买更多了~"
})
return false;
} else {
this.$emit('input', item)
}
}
},
}
</script>
<style scoped>
.list-text {
display: flex;
flex-direction: row;
}
.shopcart .cartBottom {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 54px;
z-index: 99;
display: flex;
background-color: #141d27;
}
.carIcon {
flex: 1;
}
.iconBox {
position: absolute;
bottom: 22px;
left: 18px;
z-index: 101;
background-color: rgb(70, 73, 75);
border-radius: 50%;
height: 48px;
width: 48px;
line-height: 55px;
/* border: 6px solid #141d27; */
}
.iconBox .allcount {
position: absolute;
right: -6px;
top: 0;
display: inline-block;
padding: 0 6px;
font-size: 9px;
line-height: 16px;
font-weight: 400;
border-radius: 10px;
background-color: #f01414;
color: #ffffff;
}
.img {
font-size: 24px;
line-height: 24px;
width: 30px;
height: 30px;
padding-left: 6px;
padding-top: 6px;
color: #cccccc;
border-radius: 50%;
}
.carIcon .active {
background-color: #00a0dc;
}
.middle {
display: flex;
flex-direction: column;
flex: 2;
color: #ffffff;
}
.BtnRight {
flex: 1;
border-radius: 26px;
margin: 18rpx;
z-index: 99999;
background-color: #c72a20;
color: #fff;
text-align: center;
line-height: 36px;
height: 36px;
font-size: 14px;
}
.cartList {
position: fixed;
bottom: 54px;
left: 0;
right: 0;
z-index: 90;
}
.cartList .title,
.cartList .list-text {
display: flex;
flex-direction: row;
}
.cartList .title {
background: #ffffff;
justify-content: space-between;
padding: 10px 14px;
border-radius: 15px 15px 0 0;
}
.cartList .list-text {
padding: 10px 6px 5px 8px;
text-align: center;
border-bottom: 1px solid #f4f4f4;
}
.list {
background: #ffffff;
padding-bottom: 10px;
}
/* 遮布 */
.listMask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 89;
opacity: 0.5;
background: #6a7076;
}
</style>