<template>
	<view class="shoppingBar">
		<view class="bars">
			<view class="left">
				<view class="icon">
					<sl-icon name="icon-service" color="#999" size="36rpx"></sl-icon>
					<view class="text">客服</view>
				</view>
				<view :class="isAnimationCart?'icon animationCart':'icon'">
					<sl-icon name="icon-shoppingCart" color="#999" size="40rpx"></sl-icon>
					<view class="text">购物车</view>
					<view class="shoppingCartNum">
						{{shoppingCartNum}}
					</view>
				</view>
			</view>
			<view class="right">
				<view class="btns" v-for="(item,index) in btns" :key="index" :style="'background:'+item.color" @click="onButtonClick(item.type)">{{item.name}}</view>
			</view>
		</view>
		<slBottomLift bgColor="#fff"/>
	</view>
</template>

<script>
import slBottomLift from "@/sdk/sl-bottomLift/index.vue"
import slIcon from "@/sdk/sl-icon/index.vue"
import buttonClick from "@/mixins/buttonClick.js"
import {mapGetters} from "vuex"
export default{
	components:{
		slBottomLift,
		slIcon
	},
	mixins:[buttonClick],
	mounted() {
		uni.setBackgroundColor({
		  backgroundColor: '#fff'
		})
	},
	computed: {
	  ...mapGetters(["shoppingCartNum"]),
	},
	watch:{
		shoppingCartNum(e){
			if(e){
				this.isAnimationCart=true
				setTimeout(e=>{
					this.isAnimationCart=false
				},500)
			}
		}
	},
	data(){
		return {
			btns:[
				{
					name:'加入购物车',
					type:'addCart',
					color:'#fa717f'
				},
				{
					name:'立即购买',
					type:'shopping',
					color:'#7cc6f1'
				}
			],
			isAnimationCart:false
		}
	}
}
</script>

<style lang="scss" scoped>
.shoppingBar{
	position: fixed;
	bottom: 0;
	left: 0;
	z-index: 99;
}
.bars{
	width: 100%;
	background: #fff;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 20rpx 20rpx 0;
	box-sizing: border-box;
	.left{
		display: flex;
		align-items: center;
		.icon{
			margin-right: 40rpx;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-wrap: wrap;
			.shoppingCartNum{
				height: 30rpx;
				background: $sl-theme-red;
				font-size: 20rpx;
				color: #fff;
				border-radius: 15rpx;
				position: absolute;
				top: -5rpx;
				left: 58rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 0 10rpx;
				line-height: 30rpx;
			}
			.text{
				color: #999;
				font-size: 22rpx;
				width: 100%;
				text-align: center;
				line-height: 32rpx;
			}
		}
	}
	.right{
		display: flex;
		align-items: center;
		.btns{
			margin-left: 10rpx;
			height: 60rpx;
			line-height: 60rpx;
			border-radius: 30rpx;
			font-size: 26rpx;
			color: #fff;
			width: 200rpx;
			text-align: center;
		}
	}
	.animationCart{
		animation-name: Cart;
		animation-duration: 0.5s;
		animation-iteration-count: none;
	}
	@keyframes Cart{
	   0%{
	    transform: scale(1,1);
	     }
	   50%{
		  transform: scale(0.6,1.2);
	     }
	   80%{
			transform: scale(1.2,0.6); 
	     }
		100%{
			transform: scale(0.6,1.2);
		  }
	}
}
</style>