<template name="button">
	<view class="button-template clearfix" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
		<!-- 底部按钮 -->
		<view class="btn btn-color" v-if="btnState.isDeliver"  @click.stop="btnConfirm('deliver')">发货</view>
		<view class="btn btn-cancel" @click.stop="onShareCode">
			<view class="tips" v-if="shareCode">分享码：{{shareCode}}</view>
			分享订单
		</view>	
		<view class="btn btn-cancel" @click.stop="btnConfirm('record')">发货记录</view>
	</view>
</template>

<script>
	export default{
		name:"button",
		props:{
			status:{
				type:Number
			},
			shareCode:{
				type:String,
				default: ''
			}
		},
		watch:{
			status:{
				handler:function(val){
					this.initData(val)
				},
				deep:true//对象内部的属性监听，也叫深度监听
			}
		},
		data() {
			return{
				btnState:this.initStatus(),
				isIphoneX:this.$store.state.isIphoneX,
				mapStateArr:[
					{label:'isDeliver',val:[1,2],status: true},
				]
			}
		},
		created(){
			this.initData(this.status)
		},
		computed: {

		},
		methods:{
			initData(resVal) {
				/**
				 * @分享按钮统一显示
				 * @按钮根据状态显示
				 * @(1,2)显示[发货]按钮
				 */
				this.btnState = this.initStatus()
				this.mapStateArr.forEach(el => {
					el.val.forEach(value => {
						if(resVal === value){
							this.btnState[el.label] = el.status
							//console.log(this.btnState[el.label]);
						}
					})
				})
			},
			initStatus(){
				let btnState= {
						isQuery: false,
						isDelete: false,
						isCancel: false,
						isConfirm: false,
					}
				return 	btnState
			},
			getShareCode(code){
				this.shareCode = code
			},
			onShareCode(){
				this.$parent.isShareModal = true
				this.$emit('shareConfirm')
			},
			btnConfirm(type){
				this.$emit('buttonConfirm',type)
			}
		}
	}
</script>

<style lang="scss">
	.button-template{
		width: 100%;
		padding:0 24rpx;
		height: auto;
		background-color: #FFF;
		-webkit-box-shadow: 0px 3px 10px rgba(51, 51, 51, 0.5);
		box-shadow: 0px 3px 10px rgba(51, 51, 51, 0.5);
		padding-bottom: 24rpx;
		z-index: 999;
		box-sizing: border-box;
		.share-code{
			width: 200rpx;
			height:  64rpx;
			line-height: 64rpx;
			color: #2A45FF;
			text-align: left;
			position: absolute;
			font-size: $font-size-28;
			font-weight: bold;
			left: 24rpx;
			top: 24rpx;
		}
		.btn{
			width: 160rpx;
			height:  64rpx;
			margin:22rpx;
			line-height: 64rpx;
			font-size:$font-size-26;
			color: #FFFFFF;
			text-align: center;
			border-radius: 34rpx;
			float: right;
		}
		.btn-color{
			background: #ff7a51;
		}
		.btn-cancel{
			background:#FFE6DC;
			color: #E15616;
			border: 1px solid #E15616;
			.tips{
				width: 160rpx;
				height: 34rpx;
				padding: 10rpx 10rpx;
				background:linear-gradient(45deg,rgba(0,0,0,1) 0%,rgba(87,87,87,1) 100%);
				box-shadow:0px 2px 4px 0px rgba(0,0,0,0.2);
				border-radius: 8rpx;
				position: absolute;
				color: #FFFFFF;
				line-height: 34rpx;
				font-size: $font-size-24;
				text-align: left;
				right: 24rpx;
				top: -45rpx;
				&:before{
					content: "";
					width: 25rpx;
					height: 25rpx;
					background:linear-gradient(45deg,rgba(0,0,0,1) 0%,rgba(87,87,87,1) 100%);
					position: absolute;
					bottom: -8rpx;
					right: 30rpx;
					z-index: -1;
					transform:rotate(45deg);
				}
			}
		}
		.btn-delete{
			background:linear-gradient(315deg,rgba(255,163,3,1) 0%,rgba(255,53,1,1) 100%);
		}
		.btn-query{
			background:linear-gradient(135deg,rgba(255,212,129,1) 0%,rgba(198,129,0,1) 100%);
		}
		.btn-confirm{
			background:linear-gradient(315deg,rgba(231,0,0,1) 0%,rgba(255,104,1,1) 100%);
		}
		.btn-share{
			background:linear-gradient(315deg,rgba(0,212,150,1) 0%,rgba(126,243,174,1) 100%);
			margin-right: 0;
			position: relative;
			.tips{
				width: 160rpx;
				height: 34rpx;
				padding: 10rpx 10rpx;
				background:linear-gradient(45deg,rgba(0,0,0,1) 0%,rgba(87,87,87,1) 100%);
				box-shadow:0px 2px 4px 0px rgba(0,0,0,0.2);
				border-radius: 8rpx;
				position: absolute;
				color: #FFFFFF;
				line-height: 34rpx;
				font-size: $font-size-24;
				text-align: left;
				right: 0;
				top: -65rpx;
				&:before{
					content: "";
					width: 25rpx;
					height: 25rpx;
					background:linear-gradient(45deg,rgba(0,0,0,1) 0%,rgba(87,87,87,1) 100%);
					position: absolute;
					bottom: -8rpx;
					right: 30rpx;
					z-index: -1;
					transform:rotate(45deg);
				}
			}
		}
	}
</style>
