<template name="button">
	<view class="button-template" :style="{paddingBottom :isIphoneX ? '68rpx' : '0rpx'}">
		<!-- 底部按钮 -->
		<view class="button-content">
			<view class="btn btn-cancel" v-if="btnState.isCancel" @click.stop="btnConfirm('editAddress',orderInfo)">修改收货人信息</view>
			<view class="btn btn-cancel" v-if="btnState.isCancel" @click.stop="btnConfirm('editMoney',orderInfo)">修改费用信息</view>
			<view class="btn btn-cancel" v-if="btnState.isCancel" @click.stop="btnConfirm('editMarke',orderInfo)">备注订单</view>
			<view class="btn btn-cancel" v-if="btnState.isCancel" @click.stop="btnConfirm('cancel',orderInfo)">关闭订单</view>
			<view class="btn btn-delete" v-if="btnState.isDelete" @click.stop="btnConfirm('delete',orderInfo)">删除订单</view>
			<view class="btn btn-query" v-if="btnState.isRefund" @click.stop="btnConfirm('refund',orderInfo)">订单发货</view>
			<view class="btn btn-confirm" v-if="btnState.isQuery" @click.stop="btnConfirm('query',orderInfo)">订单跟踪</view>
 		</view>
	</view>
</template>

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

		},
		methods:{
			initData(resVal) {
				/**
				 * @分享按钮统一显示
				 * @按钮根据状态显示
				 * @(4、5、7、12、22、23、32)显示[查看物流]按钮,其他隐藏
				 * @(6)显示[删除订单],其他隐藏
				 * @(0、111)显示[取消订单],其他隐藏
				 * @(21,31)只显示分享
				 * @(13,33)显示[确认收货]和[查看物流]
				 */
				this.btnState = this.initStatus()
				this.mapStateArr.forEach(el => {
					el.val.forEach(value => {
						if(resVal === value){
							this.btnState[el.label] = el.status
						}
					})
				})
			},
			initStatus(){
				let btnState= {
						isQuery: false,
						isDelete: false,
						isCancel: false,
						isConfirm: false,
						isRefund: false,
						isReturned: false,
						isConfirmation:false,
					}
				return 	btnState
			},
			btnConfirm(type,order){
				let data = {type:type,order:order}
				this.$emit('buttonConfirm',data)
			}
		}
	}
</script>

<style lang="scss">
	.button-template{
		width: 100%;
		height: auto;
		position: fixed;
		bottom: 0;
		left: 0;
		background: #FFFFFF;
		.button-content{
			width: 100%;
			padding:20rpx;
			height: auto;
			float: left;
			position: relative;
			.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{
				min-width: 160rpx;
				height:  64rpx;
				margin:22rpx;
				line-height: 64rpx;
				font-size:$font-size-26;
				text-align: center;
				border-radius: 6rpx;
				float: left;
				padding: 0 20rpx;
				margin-bottom: 0;
				margin-left:0;
			}
			.btn-cancel{
				background-color:#f6f6f6;
				color: #333333;
			}
			.btn-delete{
				background-color:#f6f6f6;
				color: #333333;
			}
			.btn-query{
				background-color:#FF5000;
				color: #FFFFFF;
			}
			.btn-confirm{
				background-color:#4688fa;
				color: #FFFFFF;
			}
			.btn-pay{
				background-color:#4688fa;
				color: #FFFFFF;
				margin-right: 0;
			}
		}
	}
</style>
