<template>
	<view class="">
		<view class="cart u-flex u-row-center" @click="$u.route('/shopping/cart',{type:'reLaunch'})">
			<u-icon size="52rpx" class="icon" :name="staticUrl+'/img/cartico.png'"></u-icon>
			<u-badge type="error" max="99" :value="cartTotal" :absolute="true" :offset="[0,5]"></u-badge>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		name:'cartfixed',
		data() {
			return {
				cartTotal:0,
				staticUrl:this.$commonConfig.staticUrl,
			}
		},
		onShow() {
		},
		onLoad() {
		},
		mounted(){
			this.getCartList()
		},
		methods: {
			getCartList(isAdd){
				this.$u.api.cartList().then(res=>{
					if(isAdd){
						if(res.data.total==this.cartTotal){
							uni.showToast({
								title:'已在购物车',
								icon:'success'
							})
							
							// this.$refs.uToast.show({
							// 	type:"success",
							// 	message:'已在购物车'
							// });
						}else{
							uni.showToast({
								title:'加入成功',
								icon:'success'
							})
							// this.$refs.uToast.show({
							// 	type:"success",
							// 	message:'加入成功'
							// });
						}
					}
					this.cartTotal = res.data.total;
					console.log('getCartList',res);
					}).catch(err=>{
					console.log('getCartList',err.data);
				})
			},
			addToCart(num){
				this.getCartList()
				// this.cartTotal += num;
				console.log('addToCart',num);
			}
		}
	}
</script>

<style lang="scss" scoped>
.cart{
	position: fixed;
	width: 100rpx;
	height: 100rpx;
	border-radius: 50%;
	right: 20rpx;
	bottom: 300rpx;
	background: #FFFFFF;
	box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.12);
}
</style>
